Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

osTicket v1.10 (stable) and Maintenance Release v1.9.15 are now available! Go get it now

[MOD] Show ticket thread on email

I've been tinkering with showing the full thread on emails and thought I'd share. Please feel free to add any comments etc

Class.ticket.php
Added a new %thread template variable



function replaceTemplateVars($text){
global $cfg;

$dept = $this->getDept();
$staff= $this->getStaff();

$search = array('/%id/','/%ticket/','/%email/','/%name/','/%subject/','/%topic/','/%phone/','/%status/','/%priority/',
'/%dept/','/%assigned_staff/','/%createdate/','/%duedate/','/%closedate/','/%url/','/%thread/');
$replace = array($this->getId(),
$this->getExtId(),
$this->getEmail(),
$this->getName(),
$this->getSubject(),
$this->getHelpTopic(),
$this->getPhoneNumber(),
$this->getStatus(),
$this->getPriority(),
($dept?$dept->getName():''),
($staff?$staff->getName():''),
Format::db_daydatetime($this->getCreateDate()),
Format::db_daydatetime($this->getDueDate()),
Format::db_daydatetime($this->getCloseDate()),
$cfg->getBaseUrl(),
$this->ticketThread());
return preg_replace($search,$replace,$text);
}


New function for ticketThread in class.ticket.php


function ticketThread(){
$thread=\"\n\n\n ---------------------------------------------------- \nFull Message Information\n ---------------------------------------------------- \n\n\";

$sql='SELECT msg.msg_id,msg.created,msg.message,count(attach_id) as attachments FROM '.TICKET_MESSAGE_TABLE.' msg '.
' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.\" attach ON msg.ticket_id=attach.ticket_id AND msg.msg_id=attach.ref_id AND ref_type='M' \".
' WHERE msg.ticket_id='.db_input($this->id).
' GROUP BY msg.msg_id ORDER BY created';

$msgres =db_query($sql);
while ($msg_row = db_fetch_array($msgres)) {
$thread=$thread . Format::db_daydatetime($msg_row['created']);

if($msg_row['attachments']>0){
$thread=$thread . \"(Attachments\" . $ticket->getAttachmentStr($msg_row['msg_id'],'M') .\")\";
}
$thread=$thread . \"\n\";
$thread=$thread . Format::display(Format::striptags($msg_row['message']));
$thread=$thread . \"\n\n\";
$thread=$thread . \"-----------------------------------------------------------------------\";
$thread=$thread . \"\n\n\";


$sql='SELECT resp.*,count(attach_id) as attachments FROM '.TICKET_RESPONSE_TABLE.' resp '.
' LEFT JOIN '.TICKET_ATTACHMENT_TABLE.\" attach ON resp.ticket_id=attach.ticket_id AND resp.response_id=attach.ref_id AND ref_type='R' \".
' WHERE msg_id='.db_input($msg_row['msg_id']).' AND resp.ticket_id='.db_input($this->id).
' GROUP BY resp.response_id ORDER BY created';

$resp =db_query($sql);
while ($resp_row = db_fetch_array($resp)) {
$respID=$resp_row['response_id'];

$thread=$thread . Format::db_daydatetime($resp_row['created']) . \"-\" . $resp_row['staff_name'];

if($resp_row['attachments']>0){
$thread=$thread . \"( With attachments \" . $ticket->getAttachmentStr($respID,'R') . \")\";
}
$thread=$thread . \"\n\";

$thread=$thread . Format::display(Format::striptags($resp_row['response']));
$thread=$thread . \"\n\";
$thread=$thread . \"\n\";

}
// $msgid =$msg_row['msg_id'];

}
$thread=$thread . \"-------------------------End of Message---------------------------\";
$thread=$thread . \"\n\n\";

return $thread;

}



Add a new prompt to staff/template.inc.php for %thread



<tr><td>%url</td><td>osTicket's base url (FQDN)</td></tr>
<tr><td>%thread</td><td>Message thread</td></tr>



Think that is everything.

Comments

  • How to get this working in OST 1.7

    HI folks,
    Does anyone know how to get this working in version 1.7. My Class.ticket.php file does not have any of the same code as the examples listed above. I am determined to get email threads (history) shown in our replies to customers. Any help is greatly appreciated.
Sign In or Register to comment.