This will allow for %ticket, %name, %email, %subject, %dept, %status, %name, %firstname, and %lastname in the subject line.
It will also allow %ticket, %name, %email, %message, %quote, %subject, %signature, %dept, %status, %name, %firstname, and %lastname in the body.
It also changes the way %url works. I wanted the url to work like a real link, so now the %url opens the link and %/url closes it. (%urlClick Here to View Ticket%/url)
After modifying the code for this, you will need to change the template in the admin panel to be HTML. I haven't used this with attachments or the mail fetching part of osTicket.
REPLACE scp/tickets.php ~ line 86
//If no error...do the do.
if(!$errors && ($respId=$ticket->postResponse($_POST,$_POST,$_POST,$_FILES,$_POST))){
REPLACE include/class.ticket.php ~ line 550 this part
//Insert Staff Reply
function postResponse($msgid,$response,$signature='none',$attachment=false,$ticket_status,$canalert=true){
global $thisuser,$cfg;
if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;
$sql= 'INSERT INTO '.TICKET_RESPONSE_TABLE.' SET created=NOW() '.
',ticket_id='.db_input($this->getId()).
',msg_id='.db_input($msgid).
',response='.db_input(Format:($response)).
',staff_id='.db_input($thisuser->getId()).
',staff_name='.db_input($thisuser->getName()).
',ip_address='.db_input($thisuser->getIP());
$resp_id=0;
//echo $sql;
if(db_query($sql) && ($resp_id=db_insert_id())):
if(!$canalert) //No alert/response
return $resp_id;
$dept=$this->getDept();
//Send Response to client...based on the template...
//TODO: check department level templates...if set.
$sql='SELECT ticket_reply_subj,ticket_reply_body FROM '.EMAIL_TEMPLATE_TABLE.
' WHERE cfg_id='.db_input($cfg->getId()).' AND tpl_id='.db_input($cfg->getDefaultTemplateId());
$resp=db_query($sql);
if(db_num_rows($resp) && list($subj,$body)=db_fetch_row($resp)){
if(strtolower($ticket_status)=="close"||strtolower($ticket_status)=="closed") {
$ticket_status = "Closed"; }
else { $ticket_status = "Open"; }
$subj = str_replace("%ticket", $this->getExtId(),$subj);
$subj = str_replace("%name", $this->getName(),$subj);
$subj = str_replace("%email", $this->getEmail(),$subj);
$subj = str_replace("%subject", $this->getSubject(),$subj);
$subj = str_replace("%dept", $dept?$dept->getName():'',$subj);
$subj = str_replace("%status", $_POST, $subj);
$seperate_names = explode(" ",$this->getName(),2);
$subj = str_replace("%firstname", $seperate_names, $subj);
$body = str_replace("%firstname", $seperate_names, $body);
$subj = str_replace("%lastname", $seperate_names, $subj);
$body = str_replace("%lastname", $seperate_names, $body);
$body = str_replace("%ticket", $this->getExtId(),$body);
$body = str_replace("%name", $this->getName(),$body);
$body = str_replace("%email", $this->getEmail(),$body);
$body = str_replace("%subject", $this->getSubject(),$body);
$body = str_replace("%dept", $dept?$dept->getName():'',$body);
$body = str_replace("%status", $_POST,, $body);
$body_response = $response;
$body_response = str_replace(chr(10), "<br />", $body_response);
$body = str_replace("%message",$body_response,$body);
$body = str_replace('\"', '"', $body);
$body = str_replace("\'", "'", $body);
$url = '<a target="_blank" href="'.$cfg->getBaseUrl().'/view.php?e='.$this->getEmail().'&t='.$this->getExtId().'">';
$body = str_replace("%url", $url, $body);
$body = str_replace("%/url", "</a>", $body);
$ticket_number = $msgid;
$sql2 = 'SELECT `message` FROM `ost_ticket_message` WHERE `msg_id` LIKE $ticket_number LIMIT 0, 1 ';
$services= mysql_query("SELECT message FROM ".TICKET_MESSAGE_TABLE." WHERE msg_id LIKE '$ticket_number'");
list($original_message) = db_fetch_row($services);
if($original_message == "Ticket created by staff") {
$services= mysql_query("SELECT response FROM ".TICKET_RESPONSE_TABLE." WHERE msg_id LIKE '$ticket_number' ORDER BY response_id ASC");
list($original) = db_fetch_row($services);
$original_message = $original;
}
$original_message = str_replace(chr(10), "<br />", $original_message);
$body = str_replace("%quote", $original_message,$body);
//Figure out the signature to use...if any.
switch(strtolower($signature)):
case 'mine';
$signature=$thisuser->getSignature();
break;
case 'dept':
$signature=$dept->isPublic()?$dept->getSignature():''; //make sure it is public
break;
case 'none';
default:
$signature='';
break;
endswitch;
$body = str_replace("%signature",$signature,$body);
//Email attachment when attached AND if emailed.
if(($attachment && is_file($attachment)) && $cfg->emailAttachments()) {
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers="MIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$body = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n".
$body . "\n\n";
$body.= "--{$mime_boundary}\n" .
"Content-Type: " . $attachment . ";\n" .
" name=\"" . $attachment . "\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"" . $attachment . "\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
chunk_split(base64_encode(file_get_contents($attachment))). "\n\n" .
"--{$mime_boundary}--\n";
}
else {
$headers = "MIME-Version: 1.0\n"."Content-type: text/html; charset=iso-8859-1";
}
if($dept->noreplyAutoResp()){
$from=$cfg->getNoReplyEmail();
}else {
$deptemail=$dept->getEmail();
if(!$deptemail || !($from=$deptemail->getAddress()))
$from=$cfg->getDefaultEmailAddress();
//Reply separator tag.
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
$body ="\n$tag\n\n".$body;
}
Misc:($this->getEmail(),$subj,$body,$from,$fromName,$headers);
Misc:($cfg->getAdminEmail(),$subj,$body,$from,$fromName,$headers); /* admin wants a copy of every response to clients as well, delete this line if you don't want it */
}else{
//We have a big problem...alert admin...
$msg='Problems fetching response template for ticket#'.$this->getId().' Possible config error';
Misc:('System Error',$msg);
}
return $resp_id;
endif;
return 0;
}
And because we changed the function we need to change in scp/tickets.php ~ line 336
$ticket->postResponse($msgId,$_POST,'none',null,false);
to be
$ticket->postResponse($msgId,$_POST,'none',null,null,false);