Sorry I haven't been on in awhile and I'll have to reconstruct the mod somewhat from memory. The SQL queries can be trimmed down, there is some unused info they are also pulling:
file: class.ticket.php
add:
function getThread() {
//get messages
$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->getId()).
' GROUP BY msg.msg_id ORDER BY created';
$msgres =db_query($sql);
$threadtext = "";
$messagecount = 0;
$responsecount = 0;
while ($msg_row = db_fetch_array($msgres)) {
$messagecount = $messagecount + 1;
$threadtext = $threadtext."\nMessage #".$messagecount." (".Format:($msg_row).") - ".Format:($msg_row)."\n";
//get answers for messages
$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).' AND resp.ticket_id='.db_input($this->getId()).
' GROUP BY resp.response_id ORDER BY created';
$resp =db_query($sql);
while ($resp_row = db_fetch_array($resp)) {
$responsecount = $responsecount + 1;
$respID=$resp_row;
$threadtext = $threadtext."\nResponse #".$responsecount." (".Format:($resp_row)." by ".$resp_row.") - ".Format:($resp_row)."\n";
}
$msgid =$msg_row;
}
return Format:($threadtext);
}
In function replaceTemplateVars($text), change the $search and $replace assignments to:
$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:($this->getCreateDate()),
Format:($this->getDueDate()),
Format:($this->getCloseDate()),
$cfg->getBaseUrl(),
$this->getThread());
Now in your e-mail templates you can use the %thread tag. Example of the "%thread" text in a new "Ticket %ticket Assigned to you" e-mail:
Message #1 (Thu, Feb 3 2011 10) - Ticket created by staff
Response #1 (Thu, Feb 3 2011 10 by xxxxxxxxxx) -
User needs to have their home drive assignment updated in AD