Add Signature to Ticket Replies
It looks like many people were having trouble. It's a simple fix:
Open /include/class.ticket.php
Go to line 574 or so, you're looking for
$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());
Which should appear after the "function PostResponse".
Right before that line, 574 or so, insert this:
$dept=$this->getDept();
//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;
if($signature != 'none') $response .= "\n\n" . $signature;
Scroll down a little bit and you are going to see the same pieces of code, just later in the function. They should be removed.
$dept=$this->getDept();
Will be by itself, remove it.
//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;
Also needs to be removed. The other part I added in.
Sorry if this is a confusing post... essentially moving some things around in the function and adding one line of code.
In the end, this is what my function looked like:
Starting line 568
function postResponse($msgid,$response,$signature='none',$attachment=false,$canalert=true){
global $thisuser,$cfg;
if(!$thisuser || !$thisuser->getId() || !$thisuser->isStaff()) //just incase
return 0;
$dept=$this->getDept();
//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;
if($signature != 'none') $response .= "\n\n" . $signature;
$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;
//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)){
$subj = str_replace("%ticket", $this->getExtId(),$subj);
$subj = str_replace("%subject", $this->getSubject(),$subj);
$body = str_replace("%ticket", $this->getExtId(),$body);
$body = str_replace("%name", $this->getName(),$body);
$body = str_replace("%email", $this->getEmail(),$body);
$body = str_replace("%url", $cfg->getBaseUrl(),$body);
$body = str_replace("%message",$response,$body);
$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/plain; 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";
}
$email=$from=$fromNamenull;
if(($email=$dept->getEmail())) { //Dept email if set!
$from=$email->getEmail();
$fromName=$email->getName();
//Reply separator tag.
if($cfg->stripQuotedReply() && ($tag=$cfg->getReplySeparator()))
$body ="\n$tag\n\n".$body;
}else{//No emails means it is a noreply...
$from=$cfg->getNoReplyEmail();
}
Misc:($this->getEmail(),$subj,$body,$from,$fromName,$headers);
}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;
}
Ending line 667
Again, I apologize about the confusion.
-Kerry
P.S. Anyone know what's happening with the development? There was talk of osTicket 2.0, etc. Nothing's been updated for over a year.