Closed Ticket Alert for All Department Members in osTicket v1.6 ST (Stable)
It does make sense when a ticket is closed by your customer or client, then all department members will be automatically notified by your ticketing system via email. I made the modification to implement this requirement into osTicket v1.6 ST (Stable), including the related setting in order to enable or disable this feature, just in case whether this feature is necessary to be implemented, and sometimes it is not. Besides that, you will be able to define the email template for the notification that sent to your customer via Admin Panel. This modification also will answer the related question in osTicket Discussion Forum.
-
First of all, you have to alter your ost_config table by adding four additional new fields into it, simply by executing this following SQL script into your osTicket database. Please note that in this example, I use ost_ as the table prefix. Adjust it in case it differs with yours:
ALTER TABLE ost_config ADD COLUMN `closed_alert_active` tinyint(1) default 0 NOT NULL, ADD COLUMN `closed_alert_assigned` tinyint(1) default 0 NOT NULL, ADD COLUMN `closed_alert_dept_manager` tinyint(1) default 0 NOT NULL, ADD COLUMN `closed_alert_dept_members` tinyint(1) default 0 NOT NULL;
-
You also have to alter the ost_email_template by adding two new fields in order to create new email template for closing alert ticket. Simply run this following SQL script to your osTicket database as well as the first step above:
ALTER TABLE ost_email_template ADD COLUMN `ticket_closed_subj` varchar(255) default '' NOT NULL, ADD COLUMN `ticket_closed_body` text NOT NULL;
- Open your /include/staff/preference.inc.php file, and find this code:
478 479 480
<input type="checkbox" name="overdue_alert_dept_members" <?=$config['overdue_alert_dept_members']?'checked':''?>> Department Members (spammy) </td> </tr>
after that line, please insert this following code:
482 483 484 485 486 487 488 489 490 491 492 493
<?php // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ?> <tr><th valign="top">Closed Ticket Alert:</th> <td> <input type="radio" name="closed_alert_active" value="1" <?=$config['closed_alert_active']?'checked':''?> />Enable <input type="radio" name="closed_alert_active" value="0" <?=!$config['closed_alert_active']?'checked':''?> />Disable <br><i>Admin Email gets an alert by default. Select additional recipients below</i> <font class="error"> <?=$errors['closed_alert_active']?></font><br> <input type="checkbox" name="closed_alert_assigned" <?=$config['closed_alert_assigned']?'checked':''?>> Assigned Staff <input type="checkbox" name="closed_alert_dept_manager" <?=$config['closed_alert_dept_manager']?'checked':''?>> Department Manager <input type="checkbox" name="closed_alert_dept_members" <?=$config['closed_alert_dept_members']?'checked':''?>> Department Members (spammy) </td> </tr> <?php // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ?>
- Open your /include/class.config.php file, and find this code:
376 377 378
function alertDeptMembersONOverdueTicket() { return $this->config['overdue_alert_dept_members']?true:false; }
after the last line of that code, please insert this following code:
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
// Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 function alertONClosedTicket() { return $this->config['closed_alert_active']?true:false; } function alertAssignedONClosedTicket() { return $this->config['closed_alert_assigned']?true:false; } function alertDeptManagerONClosedTicket() { return $this->config['closed_alert_dept_manager']?true:false; } function alertDeptMembersONClosedTicket() { return $this->config['closed_alert_dept_members']?true:false; } // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
Find again this code:
511 512 513 514 515 516
if($var['note_alert_active'] && (!isset($var['note_alert_laststaff']) && !isset($var['note_alert_assigned']) && !isset($var['note_alert_dept_manager']))){ $errors['note_alert_active']='No target recipient(s) selected'; }
after the last line of that code, please insert this following code:
518 519 520 521 522 523 524 525
// Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 if($var['closed_alert_active'] && (!isset($var['closed_alert_assigned']) && !isset($var['closed_alert_dept_manager']) && !isset($var['closed_alert_dept_members']))){ $errors['closed_alert_active']='No target recipient(s) selected'; } // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
Find again this code:
599
',overdue_alert_dept_members='.db_input(isset($var['overdue_alert_dept_members'])?1:0).
replace with this following code:
599 600 601 602 603 604 605
',overdue_alert_dept_members='.db_input(isset($var['overdue_alert_dept_members'])?1:0). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ',closed_alert_active='.db_input($var['closed_alert_active']). ',closed_alert_assigned='.db_input(isset($var['closed_alert_assigned'])?1:0). ',closed_alert_dept_manager='.db_input(isset($var['closed_alert_dept_manager'])?1:0). ',closed_alert_dept_members='.db_input(isset($var['closed_alert_dept_members'])?1:0). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
- Open /include/class.ticket.php file, and find this code:
385 386 387 388 389 390 391
//Close the ticket function close(){ $sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('closed').',staff_id=0,isoverdue=0,duedate=NULL,updated=NOW(),closed=NOW() '. ' WHERE ticket_id='.db_input($this->getId()); return (db_query($sql) && db_affected_rows())?true:false; }
then replace with this following code:
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
//Close the ticket function close(){ global $cfg; $sql= 'UPDATE '.TICKET_TABLE.' SET status='.db_input('closed').',staff_id=0,isoverdue=0,duedate=NULL,updated=NOW(),closed=NOW() '. ' WHERE ticket_id='.db_input($this->getId()); //return (db_query($sql) && db_affected_rows())?true:false; // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 NOT FINISHED YET if(db_query($sql) && db_affected_rows()) { //echo $sql; $dept=$this->getDept(); if(!$dept || !($tplId=$dept->getTemplateId())) $tplId=$cfg->getDefaultTemplateId(); //if requested && enabled fire nasty alerts. if($cfg->alertONClosedTicket()){ $sql='SELECT ticket_closed_subj,ticket_closed_body FROM '.EMAIL_TEMPLATE_TABLE. ' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($tplId); if(($resp=db_query($sql)) && db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){ $body=$this->replaceTemplateVars($body); $subj=$this->replaceTemplateVars($subj); if(!($email=$cfg->getAlertEmail())) $email=$cfg->getDefaultEmail(); if($email && $email->getId()) { //Fire and email to admin. No questions asked. $alert = str_replace("%staff",'Admin',$body); $email->send($cfg->getAdminEmail(),$subj,$alert); /*** Build list of recipients and fire the alerts ***/ $recipients=array(); //Assigned staff... if any if($this->isAssigned() && $cfg->alertAssignedONClosedTicket()){ $recipients[]=$this->getStaff(); }elseif($cfg->alertDeptMembersONClosedTicket()){ //Alert assigned or dept members not both //All dept members. $sql='SELECT staff_id FROM '.STAFF_TABLE.' WHERE dept_id='.db_input($dept->getId()); if(($users=db_query($sql)) && db_num_rows($users)) { while(list($id)=db_fetch_row($users)) $recipients[]= new Staff($id); //possible mem issues with a large number of staff? } } //Always blame the manager if($cfg->alertDeptManagerONClosedTicket() && $dept) { $recipients[]=$dept->getManager(); } //Ok...we are ready to go.... $sentlist=array(); foreach( $recipients as $k=>$staff){ if(!$staff || !is_object($staff) || !$staff->isAvailable()) continue; if(in_array($staff->getEmail(),$sentlist)) continue; //avoid duplicate emails. $alert = str_replace("%staff",$staff->getFirstName(),$body); $email->send($staff->getEmail(),$subj,$alert); } } }else { Sys::log(LOG_WARNING,'Template Fetch Error',"Unable to fetch 'closed' alert template #$tplId"); } } return true; } return false; // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 NOT FINISHED YET }
-
Open your /include/staff/template.inc.php file, and find this code:
173 174 175 176 177
<tr> <th>Message Body:</th> <td><textarea rows="7" cols="75" name="ticket_overdue_body"><?=$tpl['ticket_overdue_body']?></textarea> <font class="error"> <?=$errors['ticket_overdue_body']?></font></td> </tr>after the last line of that code, please insert this following code:
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
<?php // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ?> <tr class="header"><td colspan=2 >Closed Ticket Alert/Notice</td></tr> <tr class="subheader"><td colspan=2 >Alert sent to staff on closed tickets.</td></tr> <tr> <th>Subject</th> <td> <input type="text" size="65" name="ticket_closed_subj" value="<?=$tpl['ticket_closed_subj']?>"> <font class="error"> <?=$errors['ticket_closed_subj']?></font></td> </tr> <tr> <th>Message Body:</th> <td><textarea rows="7" cols="75" name="ticket_closed_body"><?=$tpl['ticket_closed_body']?></textarea> <font class="error"> <?=$errors['ticket_closed_body']?></font></td> </tr> <?php // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ?>
-
Open your /include/class.msgtpl.php file, and find this code:
104 105
$fields['ticket_overdue_subj'] = array('type'=>'string', 'required'=>1, 'error'=>'Subject required'); $fields['ticket_overdue_body'] = array('type'=>'string', 'required'=>1, 'error'=>'Template message required');
after the last line of that code, please insert this following code:
107 108 109 110
// Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 $fields['ticket_closed_subj'] = array('type'=>'string', 'required'=>1, 'error'=>'Subject required'); $fields['ticket_closed_body'] = array('type'=>'string', 'required'=>1, 'error'=>'Template message required'); // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
Find again this code:
143
',ticket_overdue_body='.db_input(Format::striptags($var['ticket_overdue_body'])).
then replace with this following code:
143 144 145 146 147
',ticket_overdue_body='.db_input(Format::striptags($var['ticket_overdue_body'])). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ',ticket_closed_subj='.db_input(Format::striptags($var['ticket_closed_subj'])). ',ticket_closed_body='.db_input(Format::striptags($var['ticket_closed_body'])). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
Find again this code:
213
',ticket_overdue_body='.db_input(Format::striptags($info['ticket_overdue_body'])).
then replace with this following code:
213 214 215 216 217
',ticket_overdue_body='.db_input(Format::striptags($info['ticket_overdue_body'])). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010 ',ticket_closed_subj='.db_input(Format::striptags($info['ticket_closed_subj'])). ',ticket_closed_body='.db_input(Format::striptags($info['ticket_closed_body'])). // Closed Ticket Alert for Department Members, modified by Masino Sinaga, February 27, 2010
That’s all for the modification!
After you completed doing that modification, now you HAVE TO define the email template that will be sent to the staff when a ticket is closed. You can set it up via: Admin Panel -> Emails -> Templates, and then fill in the Closed Ticket Alert: directive.
For instance, in the Subject: directive, please fill ini with this:
Closed Ticket Alert
and in the Body: directive, fill in with this template:
A ticket, #%ticket assigned to you or in your department has been closed. %url/scp/tickets.php?id=%id Thank you for your kindly cooperation so far. - Support Ticket System - powered by osTicket.
Print This Post
Recent Comments