├── LICENSE ├── README.md └── php ├── inc ├── class │ └── class.scheduled.php ├── interface │ ├── scheduled-list.inc.php │ ├── scheduled.inc.php │ └── scripts.inc.php └── scheduled.cron.php └── scheduled.php /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ScheduledTickets 2 | ================ 3 | 4 | Scripts to have Tickets be scheduled for sometime in the future or recur every so often. To have tickets recur run the script at php/inc/scheduled.cron.php every 30 minutes using cron with the following syntax: 5 | 6 | 0,30 * * * * php {PATH TO SCHEDULED.CRON.PHP} > /tmp/phpjob.txt 2>&1 7 | 8 | This will run through all the scheduled tickets and determine if they should be ran and then handle them accordingly. 9 | 10 |

Client and Staff Reqs

11 | 12 | add these functions to your class.client.php: 13 | 14 | static function lookupClientByEmail($email){ 15 | 16 | $clientQuery = 'SELECT client_id FROM ' . CLIENT_TABLE . ' WHERE email='.db_input($email); 17 | 18 | // IF we can find the ID 19 | if(($res=db_query($clientQuery)) && db_num_rows($res)) { 20 | 21 | // there should only be one row 22 | list($id)=db_fetch_row($res); 23 | 24 | // construct the client 25 | return new Client($id); 26 | 27 | } 28 | // ELSE we can't find the client's ticket 29 | else { 30 | return FALSE; 31 | } 32 | } 33 | 34 | static function getAllClients($isActive=true){ 35 | 36 | // make the query 37 | $sql = 'SELECT client_id, CONCAT_WS(", ",lastName,firstName) as name 38 | FROM '. CLIENT_TABLE . 39 | (($isActive) ? ' WHERE is_active=1' : '') . ' 40 | ORDER BY name'; 41 | 42 | $clients = db_query($sql); 43 | $returnArray = new ArrayObject(); 44 | 45 | // WHILE we still have more clients 46 | while (list($client_id,$client_name) = db_fetch_row($clients)){ 47 | $returnArray->append(array('client_id' => $client_id, 'name' => $client_name)); 48 | } 49 | 50 | return $returnArray; 51 | } 52 | 53 | 54 | 55 | Here are supported variables for both the subject line of the ticket and Body part of the ticket: 56 | 57 |
58 |

Scheduled Ticket Variables

59 | Listed are variables used in Scheduled Tickets 60 |
61 | 62 | 63 | 64 | 72 | 73 |
Base Variables
65 | 66 | 67 | 68 | 69 | 70 |
%{assigned}Staff or team name
%{recipient}Full name on ticket
%{date}Date created
%{due}Due date
71 |
74 |
75 | 76 | p.s. you can have ajax.content.php return the above HTML code to have a pop over in the scheduled.inc.php Supported Variables link. 77 | 78 |

File Placement

79 | 80 | Here is where all the files in this project should be placed in your osTicket installation: 81 | 82 | /php/scheduled.php -> /scp/scheduled.php
83 | /php/inc/class/class.scheduled.php -> /include/class.scheduled.php
84 | /php/inc/interface/scheduled-list.inc.php -> /include/staff/scheduled-list.inc.php
85 | /php/inc/interface/scheduled.inc.php -> /include/staff/scheduled.inc.php
86 | /php/inc/interface/scripts.inc.php -> /include/staff/footer.inc.php (PUT AT BOTTOM)
87 | /php/inc/scheduled.cron.php -> /api/scheduled.cron.php 88 | 89 | this line needs to be placed in nav to make a link in your nav bar: 90 | 91 | $subnav[]=array('desc'=>'Scheduled Tickets','href'=>'scheduled.php','iconclass'=>'scheduled'); 92 | 93 |

Table Structure

94 | 95 | Here is the table structure for the scheduled tickets table: 96 | 97 |
 98 | CREATE TABLE IF NOT EXISTS `ost_scheduled_tickets` (
 99 |   `scheduled_id` int(11) NOT NULL AUTO_INCREMENT,
100 |   `priority_id` int(10) NOT NULL,
101 |   `topic_id` int(10) NOT NULL,
102 |   `staff_id` int(10) NOT NULL,
103 |   `team_id` int(10) NOT NULL,
104 |   `username` varchar(128) NOT NULL,
105 |   `source` varchar(20) NOT NULL,
106 |   `url` varchar(255) NOT NULL,
107 |   `subject` varchar(64) NOT NULL,
108 |   `body` text NOT NULL,
109 |   `notifications` enum('all','assigned','none') NOT NULL,
110 |   `startdate` datetime NOT NULL,
111 |   `duedate` datetime NOT NULL,
112 |   `isrecurring` int(1) NOT NULL DEFAULT '0',
113 |   `granularity_interval` enum('hour','day','week','month','year') NOT NULL,
114 |   `time_interval` int(11) NOT NULL,
115 |   `updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
116 |   `created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
117 |   PRIMARY KEY (`scheduled_id`)
118 | ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
119 | -------------------------------------------------------------------------------- /php/inc/class/class.scheduled.php: -------------------------------------------------------------------------------- 1 | scheduled_id = 0; 72 | // load the scheduled 73 | $this -> load($scheduled_id); 74 | 75 | } 76 | 77 | return $this; 78 | } 79 | 80 | /** 81 | * @param $assocArray associative array representation of a scheduled 82 | * 83 | */ 84 | public static function ScheduledFromArray($assocArray){ 85 | 86 | // make a new scheduled 87 | $sched = new Scheduled(); 88 | // load the data from the array 89 | $sched->loadFromArray($assocArray); 90 | 91 | return $sched; 92 | } 93 | 94 | /******************************************* MEMBER METHODS *******************************************/ 95 | 96 | /** 97 | * @param $id primary key id 98 | * 99 | * loads the scheduled ticket 100 | */ 101 | private function load($id) { 102 | 103 | // IF we don't have an id 104 | if (!$id && !($id = $this->getScheduledId())) 105 | return false; 106 | 107 | $loadQuery = " 108 | SELECT 109 | * 110 | FROM 111 | ".SCHEDULED_TABLE." 112 | WHERE 113 | scheduled_id=".db_input($id); 114 | 115 | // IF the query fails 116 | if (!($res = db_query($loadQuery)) || !db_num_rows($res)) 117 | return false; 118 | 119 | $array = db_assoc_array($res); 120 | 121 | // get the associative array 122 | $this->loadFromArray($array[0]); 123 | 124 | return true; 125 | 126 | } 127 | 128 | /** 129 | * @param $assocArray loads the ticket from its corresponding associative array 130 | */ 131 | private function loadFromArray($assocArray){ 132 | 133 | // assign the instance variables 134 | $this->scheduled_id = $assocArray['scheduled_id']; 135 | $this->priority_id = $assocArray['priority_id']; 136 | $this->topic_id = $assocArray['topic_id']; 137 | $this->staff_id = $assocArray['staff_id']; 138 | $this->team_id = $assocArray['team_id']; 139 | $this->username = $assocArray['username']; 140 | $this->source = $assocArray['source']; 141 | $this->url = $assocArray['url']; 142 | $this->subject = $assocArray['subject']; 143 | $this->body = $assocArray['body']; 144 | $this->startdate = $assocArray['startdate']; 145 | $this->starttime = Format::userdate('G:i', Misc::db2gmtime($assocArray['startdate'])); 146 | $this->duedate = $assocArray['duedate']; 147 | $this->duetime = Format::userdate('G:i', Misc::db2gmtime($assocArray['duedate'])); 148 | $this->notifications = $assocArray['notifications']; 149 | $this->isrecurring = $assocArray['isrecurring']; 150 | $this->interval = $assocArray['granularity_interval']; 151 | $this->time_interval = $assocArray['time_interval']; 152 | $this->updated = $assocArray['updated']; 153 | $this->created = $assocArray['created']; 154 | 155 | } 156 | 157 | /** 158 | * @return $array an array representation of this scheduled ticket 159 | */ 160 | public function getInfo(){ 161 | 162 | // make a new array 163 | $assocArray = array(); 164 | 165 | // set the variables 166 | $assocArray['scheduled_id'] = $this->scheduled_id; 167 | $assocArray['priority_id'] = $this->priority_id; 168 | $assocArray['topic_id'] = $this->topic_id; 169 | $assocArray['staff_id'] = $this->staff_id; 170 | $assocArray['team_id'] = $this->team_id; 171 | $assocArray['username'] = $this->username; 172 | $assocArray['source'] = $this->source; 173 | $assocArray['url'] = $this->url; 174 | $assocArray['subject'] = $this->subject; 175 | $assocArray['body'] = $this->body; 176 | $assocArray['startdate'] = $this->startdate?(Format::userdate('m/d/Y', Misc::db2gmtime($this->startdate))):''; 177 | $assocArray['starttime'] = $this->startdate?(Format::userdate('G:i', Misc::db2gmtime($this->startdate))):''; 178 | $assocArray['duedate'] = $this->duedate?(Format::userdate('m/d/Y', Misc::db2gmtime($this->duedate))):''; 179 | $assocArray['duetime'] = $this->duedate?(Format::userdate('G:i', Misc::db2gmtime($this->duedate))):''; 180 | $assocArray['notifications'] = $this->notifications; 181 | $assocArray['isrecurring'] = $this->isrecurring; 182 | $assocArray['interval'] = $this->interval; 183 | $assocArray['time_interval'] = $this->time_interval; 184 | $assocArray['updated'] = $this->updated; 185 | $assocArray['created'] = $this->created; 186 | 187 | return $assocArray; 188 | } 189 | 190 | /** 191 | * reloads the object 192 | */ 193 | public function reload(){ 194 | $this->load($this->scheduled_id); 195 | } 196 | 197 | /** 198 | * @param $id primary key id 199 | * @param $vars variables for saving the organization 200 | * @param &$errors error reporting 201 | * 202 | * @return boolean 203 | * 204 | * Saves an organization to the database 205 | */ 206 | private function save($id, $vars, &$errors) { 207 | 208 | // IF there isn't an id 209 | if ($id && $id != $vars['scheduled_id']) 210 | $errors['err'] = 'Internal error. Try again'; 211 | 212 | // IF one of the parameters is not there 213 | if(!$vars['source']){ $errors['source'] = 'Invalid Source'; } 214 | if(!$vars['priority_id']){ $errors['priority_id'] = 'Invalid priority'; } 215 | if(!$vars['topic_id']){ $errors['topic_id'] = 'Invalid site'; } 216 | if(!$vars['username']){ $errors['username'] = 'Invalid username'; } 217 | if(!$vars['url']){ $errors['url'] = 'Invalid url'; } 218 | if(!$vars['subject']){ $errors['subject'] = 'Invalid subject'; } 219 | if(!$vars['body']){ $errors['body'] = 'Invalid issue'; } 220 | if(!$vars['startdate'] || !$vars['starttime']){ $errors['startdate'] = 'Invalid start date'; } 221 | if(!$vars['duedate'] || !$vars['time']){ $errors['duedate'] = 'Invalid due date'; } 222 | if(!$vars['notifications']){ $errors['notifications'] = 'Invalid notification type'; } 223 | if(!($vars['isrecurring'] == 0 224 | || $vars['isrecurring'] == 1)){ $errors['recurring'] = 'Invalid recurring value'; } 225 | 226 | // IF this is a non recurring ticket 227 | if($vars['isrecurring'] == 0){ 228 | 229 | // set defaults for non-recurring tickets 230 | $vars['interval'] = -1; 231 | $vars['time_interval'] = -1; 232 | 233 | } 234 | // ELSE IF this is a recurring ticket and we don't have an interval 235 | elseif($vars['isrecurring'] == 1 && 236 | !$vars['interval']){ 237 | 238 | $errors['interval'] = 'Invalid Interval type'; 239 | 240 | } 241 | // ELSE IF this is a recurring ticket and we don't have a time 242 | elseif($vars['isrecurring'] == 1 && 243 | !$vars['time_interval']){ 244 | 245 | $errors['time_interval'] = 'Invalid time interval'; 246 | 247 | } 248 | 249 | // IF there is no assigned but we should notify them? 250 | if(!$vars['assignId'] && ($vars['notifications'] == "assigned")){ 251 | $errors['notifications'] = 'Cannot have notify assigned if none assigned'; 252 | } 253 | 254 | // IF there is errors 255 | if ($errors) 256 | return false; 257 | 258 | $rv=0; 259 | $assignId=preg_replace("/[^0-9]/", "", $vars['assignId']); 260 | if($vars['assignId'][0]=='t') { 261 | $vars['team_id'] = $assignId; 262 | } elseif($vars['assignId'][0]=='s' || is_numeric($vars['assignId'])) { 263 | //We don't care if a team is already assigned to the ticket - staff assignment takes precedence 264 | $vars['staff_id'] = $assignId; 265 | } 266 | 267 | // set the attributes 268 | $attributes = " 269 | priority_id = " . db_input($vars['priority_id']) . " 270 | ,topic_id = " . db_input($vars['topic_id']) . " 271 | ,staff_id = " . db_input($vars['staff_id']) . " 272 | ,team_id = " . db_input($vars['team_id']) . " 273 | ,username = " . db_input($vars['username']) . " 274 | ,source = " . db_input($vars['source']) . " 275 | ,url = " . db_input($vars['url']) . " 276 | ,subject = " . db_input($vars['subject']) . " 277 | ,body = " . db_input($vars['body']) . " 278 | ,startdate = " . ($vars['startdate']?db_input(date('Y-m-d G:i',Misc::dbtime($vars['startdate'].' '.$vars['starttime']))):'NULL') . " 279 | ,duedate = " . ($vars['duedate']?db_input(date('Y-m-d G:i',Misc::dbtime($vars['duedate'].' '.$vars['time']))):'NULL') . " 280 | ,notifications = " . db_input($vars['notifications']) . " 281 | ,isrecurring = " . db_input($vars['isrecurring']) . " 282 | ,granularity_interval = " . db_input($vars['interval']) . " 283 | ,time_interval = " . db_input($vars['time_interval']) . " 284 | ,updated = NOW() 285 | "; 286 | 287 | // IF this is an existing scheduled 288 | if ($id) { 289 | 290 | $sql = "UPDATE 291 | " . SCHEDULED_TABLE . " 292 | SET 293 | ". $attributes ." 294 | WHERE 295 | " . SCHEDULED_TABLE . ".scheduled_id = " . db_input($id); 296 | 297 | // IF we're able to execute the query 298 | if($res = db_query($sql) && db_affected_rows($res) == 1){ 299 | return true; 300 | } 301 | // ELSE there was an error 302 | else{ 303 | $errors['err'] = 'Unable to update scheduled ticket. Internal error'; 304 | } 305 | 306 | } 307 | // ELSE we're creating a new scheduled 308 | else { 309 | 310 | $sql = "INSERT INTO 311 | " . SCHEDULED_TABLE . " 312 | SET 313 | " . $attributes . " 314 | ,created = NOW()"; 315 | 316 | // IF we're able to execute the query 317 | if(db_query($sql)){ 318 | return true; 319 | } 320 | // ELSE there was an error 321 | else{ 322 | $errors['err'] = 'Unable to create scheduled ticket. Internal error'; 323 | } 324 | 325 | } 326 | 327 | return false; 328 | } 329 | 330 | /** 331 | * @param $vars the orgainzations's information 332 | * @param &$errors error reporting 333 | * 334 | * @return boolean 335 | * 336 | * returns true or false based on success or failure 337 | */ 338 | public function update($vars, &$errors) { 339 | 340 | // IF the update fails 341 | if (!$this->save($this->getScheduledId(), $vars, $errors)) 342 | return false; 343 | 344 | $this->reload(); 345 | return true; 346 | } 347 | 348 | /** 349 | * @param $vars the vars that contain the client informationg 350 | * @param &$errors error reporting 351 | * 352 | * @return boolean 353 | * 354 | * returns true or false based on success or failure 355 | */ 356 | public static function create($vars, &$errors) { 357 | 358 | return self::save(NULL, $vars, &$errors); 359 | 360 | } 361 | 362 | /** 363 | * deletes the scheduled ticket 364 | */ 365 | public function delete() { 366 | 367 | $delQuery = "DELETE FROM 368 | " . SCHEDULED_TABLE . " 369 | WHERE 370 | " . SCHEDULED_TABLE . ".scheduled_id = " . $this->getScheduledId(); 371 | 372 | return (db_query($delQuery)); 373 | } 374 | 375 | /** 376 | * @return $interval the recurrance interval expressed as DateInterval 377 | */ 378 | public function recurranceInterval(){ 379 | 380 | // make a new date interval 381 | $interval = new DateInterval('PT1S'); 382 | $interval->s = 0; 383 | 384 | // SWITCH on the interval 385 | switch($this->getInterval()){ 386 | 387 | case "hour": 388 | // set the interval in hours 389 | $interval->h = $this->getTimeInterval(); 390 | break; 391 | 392 | case "day": 393 | // set the interval in days 394 | $interval->d = $this->getTimeInterval(); 395 | break; 396 | 397 | case "week": 398 | // set the interval in weeks 399 | $interval->d = $this->getTimeInterval() * 7; 400 | break; 401 | 402 | case "month": 403 | // set the interval in months 404 | $interval->m = $this->getTimeInterval(); 405 | break; 406 | 407 | case "year": 408 | // set the interval in years 409 | $interval->y = $this->getTimeInterval(); 410 | break; 411 | 412 | } 413 | 414 | return $interval; 415 | } 416 | 417 | /** 418 | * @return $interval returns the time between original start date 419 | * and due date as a DateInterval 420 | */ 421 | public function dueDateInterval(){ 422 | 423 | // make a new date interval 424 | $start = new DateTime($this->getStartDate()); 425 | $due = new DateTime($this->getDueDate()); 426 | 427 | return $start->diff($due); 428 | } 429 | 430 | /** 431 | * @return boolean returns true or false whether the scheduled ticket should run now 432 | */ 433 | public function runNow(){ 434 | 435 | // reference now 436 | $now = new DateTime(); 437 | // get the start time 438 | $start = new DateTime($this->getStartDate()); 439 | 440 | // IF this is a non recurring ticket 441 | if($this->isRecurring() == 0){ 442 | 443 | // determine the interval between the two times 444 | $difference = $now->diff($start); 445 | 446 | // return if the time is within the minute 447 | return $this->withinMinute($difference); 448 | 449 | } 450 | // ELSE this is a recurring ticket 451 | else{ 452 | 453 | // reference now 454 | $now = new DateTime(); 455 | 456 | // determine the interval between the two times 457 | $difference = $now->diff($start); 458 | 459 | // IF we're before the start date 460 | if($difference->invert == 0){ 461 | 462 | // too early 463 | return false; 464 | 465 | } 466 | // IF we're on the start date 467 | elseif($this->withinMinute($difference)){ 468 | 469 | // we're on 470 | return true; 471 | 472 | } 473 | // ELSE we're past the start date 474 | else{ 475 | 476 | // clone the start time 477 | $recurrance = clone $start; 478 | 479 | // get the recurrance interval 480 | $interval = $this->recurranceInterval(); 481 | 482 | // furture flag 483 | $future = false; 484 | 485 | // WHILE we're not past a date it should run 486 | while(!$future){ 487 | 488 | // add the interval to the date time 489 | $recurrance->add($interval); 490 | 491 | // reference now 492 | $now = new DateTime(); 493 | 494 | // difference between now and recurrance 495 | $difference = $now->diff($recurrance); 496 | 497 | // IF we're on the start date 498 | if($this->withinMinute($difference)){ 499 | 500 | // run 501 | return true; 502 | 503 | } 504 | // ELSE IF we're past the date 505 | else if($difference->invert == 0){ 506 | 507 | // don't run 508 | return false; 509 | } 510 | } 511 | } 512 | } 513 | } 514 | 515 | /** 516 | * @return boolean returns true or false if the interval is within the minute 517 | * 518 | * It is important to note when computing differences with now and and a date, 519 | * You should always "refresh" now because of the invert property has a lot of 520 | * meaning to the above function. 521 | */ 522 | private function withinMinute($difference){ 523 | return ($difference->y == 0 && 524 | $difference->m == 0 && 525 | $difference->d == 0 && 526 | $difference->h == 0 && 527 | $difference->i == 0 && 528 | $difference->s <= 59); 529 | } 530 | 531 | /** 532 | * @return $output puts the template variables in the input accordingly 533 | */ 534 | private function replaceVariables($input, $variables){ 535 | 536 | // replace the variables 537 | $input = str_replace('%{assigned}', ($variables['assigned'] ? $variables['assigned'] : ''), $input); 538 | $input = str_replace('%{recipient}', ($variables['recipient'] ? $variables['recipient'] : ''), $input); 539 | $input = str_replace('%{date}', ($variables['date'] ? $variables['date'] : ''), $input); 540 | $input = str_replace('%{due}', ($variables['due'] ? $variables['due'] : ''), $input); 541 | 542 | return $input; 543 | } 544 | 545 | /** 546 | * puts a copy of the ticket into the database 547 | */ 548 | public function putTicketIntoDatabse(){ 549 | 550 | // reference the email address 551 | $email = $this->getUsername()."@example.com"; 552 | 553 | // IF we can get the staff ID by username 554 | if(Staff::isCreated($email)){ 555 | 556 | // lookup the opening staff by email 557 | $staff = Staff::lookupStaffByEmail($email); 558 | // get the staff info 559 | $name = $staff->getName(); 560 | 561 | } 562 | // ELSE IF we can get the client's ID 563 | else if(Client::isCreated($email)){ 564 | 565 | // lookup the client by email 566 | $client = Client::lookupClientByEmail($email); 567 | // get the client info 568 | $name = $client->getName(); 569 | $phone = $client->getPhone(); 570 | 571 | } 572 | 573 | // get the due date 574 | $now = new DateTime(); 575 | $due = clone $now; 576 | $due->add($this->dueDateInterval()); 577 | 578 | // put the varaiables 579 | $variables['recipient'] = $name; 580 | $variables['email'] = $email; 581 | $variables['date'] = $now->format(DATE_FORMAT_STRING); 582 | $variables['due'] = $due->format(DATE_FORMAT_STRING); 583 | 584 | // IF this ticket should be assigned to a staff memeber 585 | if($this->getStaffId() > 0){ 586 | 587 | // get the staff member 588 | $staff = new Staff($this->getStaffId()); 589 | // assigned variable 590 | $variables['assigned'] = $staff->getName(); 591 | 592 | } 593 | // ELSEIF this ticket should be assigned to a team 594 | elseif($this->getTeamId() > 0){ 595 | 596 | // get the team 597 | $team = new Team($this->getTeamId()); 598 | // assigned variable 599 | $variables['assigned'] = $team->getName(); 600 | 601 | } 602 | 603 | // replace the variables 604 | $body = $this->replaceVariables($this->getBody(), $variables); 605 | $subject = $this->replaceVariables($this->getSubject(), $variables); 606 | 607 | // write the query to put into the ticket table 608 | $ticketquery = " 609 | INSERT INTO 610 | ".TICKET_TABLE." 611 | SET 612 | ticketID = ".db_input(self::genExtRandID())." 613 | ,dept_id = ".db_input(DEPT_ID)." 614 | ,sla_id = ".db_input(SLA_ID)." 615 | ,priority_id = ".db_input($this->getPriorityId())." 616 | ,topic_id = ".db_input($this->getTopicId())." 617 | ,staff_id = ".db_input($this->getStaffId())." 618 | ,team_id = ".db_input($this->getTeamId())." 619 | ,email = ".db_input($email)." 620 | ,name = ".db_input($name)." 621 | ,subject = ".db_input($subject)." 622 | ,status = ".db_input('open')." 623 | ,source = ".db_input($this->getSource())." 624 | ,isoverdue = ".db_input(0)." 625 | ,isanswered = ".db_input(0)." 626 | ,duedate = ".db_input($due->format('Y-m-d H:i:s'))." 627 | ,created = NOW() 628 | ,updated = NOW() 629 | ,url = ".db_input($this->getUrl()); 630 | 631 | // IF the query was successful 632 | if(($res = db_query($ticketquery) && db_affected_rows() == 1)){ 633 | 634 | // get the Id inserted 635 | $id = db_insert_id(); 636 | 637 | // put the first entry in 638 | $threadquery = " 639 | INSERT INTO 640 | ".TICKET_THREAD_TABLE." 641 | SET 642 | ticket_id = ".db_input(db_insert_id())." 643 | ,staff_id = ".db_input(0)." 644 | ,thread_type = ".db_input('M')." 645 | ,poster = ".db_input($name)." 646 | ,title = ".db_input($subject)." 647 | ,body = ".db_input($body)." 648 | ,created = NOW() 649 | ,updated = NOW() 650 | "; 651 | 652 | // put the autocreated event in 653 | $evenquery = " 654 | INSERT INTO 655 | ".TICKET_EVENT_TABLE." 656 | SET 657 | ticket_id = ".db_input($id)." 658 | ,staff_id = ".db_input($this->getStaffId())." 659 | ,team_id = ".db_input($this->getTeamId())." 660 | ,dept_id = ".db_input(WEB_SERVICES_DEPT_ID)." 661 | ,topic_id = ".db_input($this->getTopicId())." 662 | ,state = 'created' 663 | ,staff = 'SYSTEM' 664 | ,annulled = 0 665 | ,timestamp = NOW() 666 | "; 667 | 668 | // IF the query wasn't successful 669 | if(!($res = db_query($threadquery) && db_affected_rows() == 1)){ 670 | throw new Exception('Unable to put thread entry into databse'); 671 | } 672 | 673 | // IF the query wasn't successful 674 | if(!($res = db_query($evenquery) && db_affected_rows() == 1)){ 675 | throw new Exception('Unable to put event into databse'); 676 | } 677 | 678 | } 679 | // ELSE something went wrong 680 | else{ 681 | throw new Exception('Unable to put ticket into databse'); 682 | } 683 | 684 | // get the ID that was inserted 685 | $this->sendEmails($id, $subject, $body); 686 | 687 | return $id; 688 | } 689 | 690 | /** 691 | * sends out the appropriate emails if 692 | */ 693 | public function sendEmails($id, $ticketSubject, $ticketBody){ 694 | 695 | // reference the time 696 | $now = new DateTime(); 697 | 698 | // reference email components 699 | $subj = "Auto Ticket Generator"; 700 | $body = " 701 | Auto Ticket Generator Cron- 702 | 703 | A new ticket has been created. See the following information below: 704 | 705 | DateTime: 706 | ".$now->format(DATE_FORMAT_STRING)." 707 | Username: 708 | ".$this->getUsername()." 709 | Subject: 710 | ".$ticketSubject." 711 | Body: 712 | ".$ticketBody." 713 | 714 | 715 | To view more about this ticket please click the following link: 716 | 717 | ".HOME_URL."scp/tickets.php?id=".$id; 718 | $from = "AutoTicketGenerator@example.com"; 719 | 720 | // SWITCH on the notifications 721 | switch($this->getNotifications()){ 722 | 723 | // assigned staff members 724 | case "assigned": 725 | 726 | // IF this ticket should be assigned to a staff memeber 727 | if($this->getStaffId() > 0){ 728 | 729 | // get the staff member 730 | $staff = new Staff($this->getStaffId()); 731 | // send them an email 732 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 733 | 734 | } 735 | // ELSEIF this ticket should be assigned to a team 736 | elseif($this->getTeamId() > 0){ 737 | 738 | // get the team 739 | $team = new Team($this->getTeamId()); 740 | // get the team members 741 | $members = $team->getMembers(); 742 | 743 | // FOREACH of the members 744 | foreach($members as $num => $id){ 745 | 746 | // get the staff member 747 | $staff = new Staff($id); 748 | // send them an email 749 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 750 | } 751 | } 752 | 753 | break; 754 | 755 | // all staff members 756 | case "all": 757 | 758 | // get all of the staff members 759 | $allStaff = Staff::getAvailableStaffMembers(); 760 | 761 | // FOREACH of the staff 762 | foreach($allStaff as $num => $id){ 763 | 764 | // get the staff member 765 | $staff = new Staff($id); 766 | // send them an email 767 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 768 | } 769 | 770 | break; 771 | 772 | // no staff members 773 | case "none": 774 | // don't send any emails 775 | break; 776 | 777 | } 778 | 779 | } 780 | 781 | /** 782 | * @return $array an array of all the scheduled objects 783 | */ 784 | public static function getAllScheduled(){ 785 | 786 | // get all scheduled 787 | $query = " 788 | SELECT 789 | * 790 | FROM " 791 | .SCHEDULED_TABLE; 792 | 793 | // perform the query 794 | $array = db_assoc_array(db_query($query)); 795 | // make a new array object 796 | $ret = array(); 797 | 798 | // FOREACH of the scheduled 799 | foreach($array as $num => $assoc){ 800 | 801 | // push the object onto the array 802 | array_push($ret, self::ScheduledFromArray($assoc)); 803 | 804 | } 805 | 806 | return $ret; 807 | } 808 | 809 | /** 810 | * generates a random ticket ID. See from Ticket::genExtRandID() 811 | */ 812 | private static function genExtRandID() { 813 | global $cfg; 814 | 815 | //We can allow collissions...extId and email must be unique ...so same id with diff emails is ok.. 816 | // But for clarity...we are going to make sure it is unique. 817 | $id=Misc::randNumber(EXT_TICKET_ID_LEN); 818 | if(db_num_rows(db_query('SELECT ticket_id FROM '.TICKET_TABLE.' WHERE ticketID='.db_input($id)))) 819 | return self::genExtRandID(); 820 | 821 | return $id; 822 | } 823 | 824 | /******************************************* ACCESSORS AND MUTATORS *******************************************/ 825 | 826 | public function getScheduledId(){ 827 | return $this->scheduled_id; 828 | } 829 | 830 | public function setScheduledId($scheduled_id){ 831 | $this->scheduled_id = $scheduled_id; 832 | } 833 | 834 | public function getPriorityId(){ 835 | return $this->priority_id; 836 | } 837 | 838 | public function setPriorityId($priority_id){ 839 | $this->priority_id = $priority_id; 840 | } 841 | 842 | public function getTopicId(){ 843 | return $this->topic_id; 844 | } 845 | 846 | public function setTopicId($topic_id){ 847 | $this->topic_id = $topic_id; 848 | } 849 | 850 | public function getStaffId(){ 851 | return $this->staff_id; 852 | } 853 | 854 | public function setStaffId($staff_id){ 855 | $this->staff_id = $staff_id; 856 | } 857 | 858 | public function getTeamId(){ 859 | return $this->team_id; 860 | } 861 | 862 | public function setTeamId($team_id){ 863 | $this->team_id = $team_id; 864 | } 865 | 866 | public function getUsername(){ 867 | return $this->username; 868 | } 869 | 870 | public function setUsername($username){ 871 | $this->username = $username; 872 | } 873 | 874 | public function getSource(){ 875 | return $this->source; 876 | } 877 | 878 | public function setSource($source){ 879 | $this->source = $source; 880 | } 881 | 882 | public function getUrl(){ 883 | return $this->url; 884 | } 885 | 886 | public function setUrl($url){ 887 | $this->url = $url; 888 | } 889 | 890 | public function getSubject(){ 891 | return $this->subject; 892 | } 893 | 894 | public function setSubject($subject){ 895 | $this->subject = $subject; 896 | } 897 | 898 | public function getBody(){ 899 | return $this->body; 900 | } 901 | 902 | public function setBody($body){ 903 | $this->body = $body; 904 | } 905 | 906 | public function getStartDate(){ 907 | return $this->startdate; 908 | } 909 | 910 | public function setStartDate($startdate){ 911 | $this->startdate = $startdate; 912 | } 913 | 914 | public function getStartTime(){ 915 | return $this->starttime; 916 | } 917 | 918 | public function setStartTime($starttime){ 919 | $this->starttime = $starttime; 920 | } 921 | 922 | public function getDueDate(){ 923 | return $this->duedate; 924 | } 925 | 926 | public function setDueDate($duedate){ 927 | $this->duedate = $duedate; 928 | } 929 | 930 | public function getDueTime(){ 931 | return $this->duetime; 932 | } 933 | 934 | public function setDueTime($duetime){ 935 | $this->duetime = $duetime; 936 | } 937 | 938 | public function getNotifications(){ 939 | return $this->notifications; 940 | } 941 | 942 | public function setNotifications($notifications){ 943 | $this->notifications = $notifications; 944 | } 945 | 946 | public function isRecurring(){ 947 | return $this->isrecurring; 948 | } 949 | 950 | public function setReccuring($isrecurring){ 951 | $this->isrecurring = $isrecurring; 952 | } 953 | 954 | public function getInterval(){ 955 | return $this->interval; 956 | } 957 | 958 | public function setInterval($interval){ 959 | $this->interval = $interval; 960 | } 961 | 962 | public function getTimeInterval(){ 963 | return $this->time_interval; 964 | } 965 | 966 | public function setTimeInterval($time_interval){ 967 | $this->time_interval = $time_interval; 968 | } 969 | 970 | public function getUpdated(){ 971 | return $this->updated; 972 | } 973 | 974 | public function setUpdated($updated){ 975 | $this->updated = $updated; 976 | } 977 | 978 | public function getCreated(){ 979 | return $this->created; 980 | } 981 | 982 | public function setCreated($created){ 983 | $this->created = $created; 984 | } 985 | 986 | } 987 | ?> 988 | -------------------------------------------------------------------------------- /php/inc/interface/scheduled-list.inc.php: -------------------------------------------------------------------------------- 1 | 'startdate','username'=>'username','subject'=>'subject','recurring'=>'recurring'); 3 | $orderWays=array('DESC'=>'DESC','ASC'=>'ASC'); 4 | 5 | if($_REQUEST['sort']) { 6 | $order_by =$sortOptions[$_REQUEST['sort']]; 7 | } 8 | if($_REQUEST['order']) { 9 | $order=$orderWays[$_REQUEST['order']]; 10 | } 11 | $order_by =$order_by?$order_by:'startdate'; 12 | $order=$order?$order:'ASC'; 13 | $negorder=$order=='DESC'?'ASC':'DESC'; 14 | 15 | $total=db_count('SELECT count(*) FROM '.SCHEDULED_TABLE.' scheduled '); 16 | $page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1; 17 | $pageNav=new Pagenate($total, $page, PAGE_LIMIT); 18 | $pageNav->setURL('scheduled.php',$qstr.'&sort='.urlencode($_REQUEST['sort']).'&order='.urlencode($_REQUEST['order'])); 19 | //Ok..lets roll...create the actual query 20 | $qstr.='&order='.($order=='DESC'?'ASC':'DESC'); 21 | 22 | $query=" 23 | SELECT 24 | * 25 | FROM 26 | ".SCHEDULED_TABLE." 27 | ORDER BY 28 | $order_by 29 | $order 30 | LIMIT 31 | ".$pageNav->getStart()." 32 | ,".$pageNav->getLimit(); 33 | 34 | $res=db_query($query); 35 | if($res && ($num=db_num_rows($res))) 36 | $showing=$pageNav->showing().' scheduled tickets'; 37 | else 38 | $showing='No scheduled tickets found!'; 39 | 40 | $results = db_query($query); 41 | $rows = db_num_rows($results); 42 | 43 | ?> 44 | 45 | 46 | 47 | 48 |
49 |

Scheduled Tickets

50 |
51 |
52 | Add New Scheduled Ticket 53 |
54 |
55 |
56 |
57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 95 | 96 | 99 | 100 | 101 | 102 | 103 | 108 | 109 | 110 | 111 | 112 | 0){?> 113 | 114 | 115 | 116 | 117 | 118 | 119 | 125 | 126 | 127 | 128 | 129 | 130 |
 Scheduled Tickets
 ">Username">Subject">Recurring">Created
97 | onClick="highLight(this.value,this.checked);"> 98 |     
No Scheduled Tickets Found
120 | Select:  121 | All   122 | None   123 | Toggle   124 |
131 |  Page:'.$pageNav->getPageLinks().' '; 134 | ?> 135 |

136 | 137 |

138 | 141 |
142 | 143 | 144 | 145 | 146 | 172 | -------------------------------------------------------------------------------- /php/inc/interface/scheduled.inc.php: -------------------------------------------------------------------------------- 1 | isAdmin()) die('Access Denied'); 5 | $info=array(); 6 | $qstr=''; 7 | if($scheduled && $_REQUEST['a']!='add') { 8 | $title='Update Scheduled Ticket'; 9 | $action='update'; 10 | $submit_text='Save Changes'; 11 | $info = $scheduled->getInfo(); 12 | $qstr.='&id='.$scheduled->getScheduledId(); 13 | } else { 14 | $title='Add New Scheduled Ticket'; 15 | $action='create'; 16 | $submit_text='Add Scheduled Ticket'; 17 | $qstr.='&a='.$_REQUEST['a']; 18 | } 19 | $info=Format::htmlchars(($errors && $_POST)?$_POST:$info); 20 | 21 | ?> 22 | 23 |
24 | 25 | 26 | 27 | 28 |

getSubject() : 'New Scheduled Ticket')?>

29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 51 | 57 | 58 | 59 | 62 | 63 | 64 | 67 | 76 | 77 | 78 | 81 | 95 | 96 | 97 | 100 | 105 | 106 | 107 | 110 | 123 | 124 | 125 | 128 | 141 | 142 | 143 | 146 | 165 | 166 | 167 | 168 | 194 | 195 | 196 | 197 | 198 | 199 | 202 | 203 | 204 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 222 | 223 | 224 | 227 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 243 | 244 | 245 | 248 | 254 | 255 | 256 | 259 | 270 | 271 | 272 | 275 | 327 | 328 | 329 |
37 |

Scheduled Ticket

38 | User Information: 39 |
49 | Username 50 | 52 | 53 |  *  54 | 55 | 56 |
60 | Ticket Information & Options: 61 |
65 | Ticket Source: 66 | 68 | 74 |  *  75 |
79 | Site: 80 | 82 | 93 |  *  94 |
98 | URL: 99 | 101 | 103 |   104 |
108 | Creation Date: 109 | 111 | 112 |    113 | 120 | *  121 |   122 |
126 | Priority: 127 | 129 | 139 |  *  140 |
144 | Due Date:  145 | 147 | 148 |    149 | 156 |
4:00 PM 
157 |
158 | (Due dates will be relative for recurring tickets)  159 |
160 | 161 | *  162 |   163 | 164 |
Assign To: 169 |    193 |
200 | Issue: The user will be able to see the issue summary below and any associated responses. Supported Variables 201 |
205 |
206 | Subject: Issue summary  
207 | 208 |
209 |
Issue: Details on the reason(s) for opening the ticket.
210 | 211 |
220 | Email Notifications: 221 |
225 | Notifications: 226 | 228 | >Notfiy All     229 | >Notify Assigned     230 | >No Notifications 231 | *  232 | 233 |
241 | Scheduling: Defines how the ticket recurs 242 |
246 | Is Reccuring: 247 | 249 | >One Time Ticket     250 | >Recurring Ticket 251 | *  252 | 253 |
257 | Interval: 258 | 260 | 268 |  *  269 |
273 | Recur Every: 274 | 276 | 325 |  *  326 |
330 | 331 | 332 | 333 | 334 |

335 | 336 | 337 | 338 |

339 |
340 | 341 | -------------------------------------------------------------------------------- /php/inc/interface/scripts.inc.php: -------------------------------------------------------------------------------- 1 | 2 | 21 | 22 | 42 | 43 | 100 | -------------------------------------------------------------------------------- /php/inc/scheduled.cron.php: -------------------------------------------------------------------------------- 1 | "; 97 | print_r($var); 98 | echo ""; 99 | exit; 100 | } 101 | 102 | /** 103 | * reports errors for inserting $scheduledObj into the database 104 | */ 105 | function scheduledError($scheduledObj){ 106 | 107 | // reference the time 108 | $now = new DateTime(); 109 | 110 | // reference email components 111 | $subj = "Auto Ticket Generator Failed"; 112 | $body = " 113 | Auto Ticket Generator Cron- 114 | 115 | Unable to put the following ticket into the database: 116 | 117 | DateTime: 118 | ".$now->format(DATE_FORMAT_STRING)." 119 | Username: 120 | ".$scheduledObj->getUsername()." 121 | Subject: 122 | ".$scheduledObj->getSubject()." 123 | Body: 124 | ".$scheduledObj->getSubject()." 125 | 126 | Please check the scheduled ticket, and also check the auto cron script if necessary. 127 | "; 128 | $from = "AutoTicketGenerator@example.com"; 129 | 130 | // IF this ticket should be assigned to a staff memeber 131 | if($scheduledObj->getStaffId() > 0){ 132 | 133 | // get the staff member 134 | $staff = new Staff($scheduledObj->getStaffId()); 135 | // send them an email 136 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 137 | 138 | } 139 | // ELSEIF this ticket should be assigned to a team 140 | elseif($scheduledObj->getTeamId() > 0){ 141 | 142 | // get the team 143 | $team = new Team($scheduledObj->getTeamId()); 144 | // get the team members 145 | $members = $team->getMembers(); 146 | 147 | // FOREACH of the members 148 | foreach($members as $num => $id){ 149 | 150 | // get the staff member 151 | $staff = new Staff($id); 152 | // send them an email 153 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 154 | } 155 | } 156 | // ELSE we need to notify everyone 157 | else{ 158 | 159 | // get all of the staff members 160 | $allStaff = Staff::getAvailableStaffMembers(); 161 | 162 | // FOREACH of the staff 163 | foreach($allStaff as $num => $id){ 164 | 165 | // get the staff member 166 | $staff = new Staff($id); 167 | // send them an email 168 | Mailer::sendmail($staff->getEmail(), $subj, $body, $from); 169 | } 170 | } 171 | } 172 | 173 | /************************************************************************************************************************************/ 174 | 175 | // get all scheduled 176 | $all = Scheduled::getAllScheduled(); 177 | 178 | // FOREACH of the scheduled tickets 179 | foreach($all as $num => $scheduledObj){ 180 | 181 | // IF we should run the scheduled ticket now 182 | if($scheduledObj->runNow()){ 183 | 184 | try{ 185 | 186 | // put a copy into the database 187 | $scheduledObj->putTicketIntoDatabse(); 188 | 189 | // IF the scheduled ticket is non recurring 190 | if($scheduledObj->isRecurring() == 0){ 191 | 192 | // delete the scheduled ticket 193 | $scheduledObj->delete(); 194 | 195 | } 196 | 197 | }catch(Exception $e){ 198 | 199 | // handle the error 200 | scheduledError($scheduledObj); 201 | 202 | } 203 | } 204 | } 205 | 206 | ?> 207 | -------------------------------------------------------------------------------- /php/scheduled.php: -------------------------------------------------------------------------------- 1 | update($_POST,$errors)){ 32 | 33 | // modified successfully 34 | $msg = 'Successfully modified Scheduled ticket'; 35 | 36 | }else{ 37 | // report an error 38 | $errors['err']='Error updating Scheduled ticket. Try again!'; 39 | return false; 40 | } 41 | 42 | break; 43 | 44 | case 'create': 45 | if(Scheduled::create($_POST,$errors)){ 46 | $msg='Scheduled added successfully'; 47 | $_REQUEST['a']=null; 48 | }elseif(!$errors['err']){ 49 | $errors['err']='Unable to add Scheduled. Correct error(s) below and try again.'; 50 | } 51 | break; 52 | 53 | case 'mass_process': 54 | if(!$_POST['ids'] || !is_array($_POST['ids']) || !count($_POST['ids'])) { 55 | $errors['err'] = 'You must select at least one Scheduled'; 56 | } else { 57 | $count=count($_POST['ids']); 58 | 59 | switch(strtolower($_POST['a'])) { 60 | case 'delete': 61 | 62 | $i=0; 63 | foreach($_POST['ids'] as $k=>$v) { 64 | if(($t= new Scheduled($v)) && $t->delete()) 65 | $i++; 66 | } 67 | 68 | if($i && $i==$count) 69 | $msg = 'Selected Scheduled deleted successfully'; 70 | elseif($i>0) 71 | $warn = "$i of $count selected Scheduled deleted"; 72 | elseif(!$errors['err']) 73 | $errors['err'] = 'Unable to delete selected Scheduled ticket'; 74 | 75 | break; 76 | default: 77 | $errors['err']='Unknown action - get technical help.'; 78 | } 79 | } 80 | break; 81 | 82 | default: 83 | $errors['err']='Unknown command/action'; 84 | break; 85 | } 86 | } 87 | 88 | $page='scheduled-list.inc.php'; 89 | if($scheduled || ($_REQUEST['a'] && $_REQUEST['a'] == 'add')) 90 | $page='scheduled.inc.php'; 91 | 92 | $nav->setTabActive('manage'); 93 | require(STAFFINC_DIR.'header.inc.php'); 94 | require(STAFFINC_DIR.$page); 95 | include(STAFFINC_DIR.'footer.inc.php'); 96 | 97 | ?> 98 | --------------------------------------------------------------------------------