Getting all the thread messages
The code below fills three variables: %quote, %quotedate and %thread. The first two are for just the last message posted, and the last one contains the full thread. With some help from the posts above.
Add to class.ticket.php about line 760 just before the "//Figure out the signature..." part:
// get message poster name
$sql='SELECT name FROM '.TICKET_TABLE.' WHERE ticket_id='.$this->getId().' LIMIT 1';
if (($resp=db_query($sql)) && db_num_rows($resp) && list($messagename)=db_fetch_row($resp))
{ $messagename = $messagename; }
// get all thread messages and responses
$fullthread = '';
$sql='SELECT msg_id,message,created FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.$this->getId().' ORDER BY created DESC';
$resp=db_query($sql);
if (db_num_rows($resp) > 0)
{
// get all the messages
while (list($threadmsgid,$threadmsg,$threadmsgdate) = db_fetch_row($resp))
{
// and all the responses for each message
$sql2='SELECT staff_name,response,created FROM '.TICKET_RESPONSE_TABLE.' WHERE ticket_id='.$this->getId().' AND msg_id='.$threadmsgid.' ORDER BY created DESC';
$resp2=db_query($sql2);
if (db_num_rows($resp2) > 0)
{
while (list($responsestaffname,$responseresponse,$responsecreated) = db_fetch_row($resp2))
{
// don't want the very first or last responses
if (strpos($responseresponse,"Your ticket #") === false && // yes, 3 equal signs apparently
strpos($responseresponse,$response) === false)
{
// output each reponse
$fullthread .= '--------------------------------------------------------'."\r\n";
$fullthread .= 'On '.$responsecreated.', '.$responsestaffname.' wrote:'."\r\n";
$fullthread .= $responseresponse;
$fullthread .= "\r\n";
$fullthread .= "\r\n";
}
}
}
// output each message
$fullthread .= '--------------------------------------------------------'."\r\n";
$fullthread .= 'On '.$threadmsgdate.', '.$messagename.' wrote:'."\r\n";
$fullthread .= $threadmsg;
$fullthread .= "\r\n";
$fullthread .= "\r\n";
}
}
$body = str_replace("%thread", $fullthread,$body);