Hi all,
this is my first post and the forum somewhat helped me find the correct files to edit etc. so I thought I'll give something back :)
I needed an additional template replacement to include the conversation history... said and done I dove into some coding...
in /include/class.ticket.php @ line ~220ish (among all other getters) I added a function to retreive what I wanted and some formatting.
BEFORE ADDING THE CODE STRAIGHT OFF, be sure to check the creation of the $c array when looping in messages and responses, I hardcoded some prefixes to be able to distinguish messages from responses in the final output
// own function added for the added %history template substitution
function getMessageHistory(){
// build an array of both messages and responses (conversion history = $c)
//$c = array;
$i = 0; // start from the beginning...
// first we get the messages
$sql ='SELECT created, message FROM '.TICKET_MESSAGE_TABLE.' WHERE ticket_id='.db_input($this->id);
if(($res=db_query($sql)) && db_num_rows($res))
{
while($row=db_fetch_array($res))
{
$c=$row;
$c="Message: ".$row;
}
}
// then we get the response history
$sql ='SELECT created, response FROM '.TICKET_RESPONSE_TABLE.' WHERE ticket_id='.db_input($this->id);
if(($res=db_query($sql)) && db_num_rows($res))
{
while($row=db_fetch_array($res))
{
$c=$row;
$c="Response: ".$row;
}
}
// sort the array on the date field
// first we need to alter the arrays from rows to columns to make array_multisort work properly...
foreach($c as $k => $r)
{
$create = $r;
$text = $r;
}
// reorder the arrays in tandem...
array_multisort($create, SORT_ASC, $text);
// turn everything into a string and return it.. (we counted $i upwards the last time and it should contain the nr of elements...)
$output='';
for($x=0; $x <= $i; $x++)
{
$output .= $create.' - '.$text."\n";
$output .= "-----------------------------------------------------------------\n";
}
return($output);
}
// end modification
Then a little further down my modified replacement function looks like this:
function replaceTemplateVars($text){
global $cfg;
$dept = $this->getDept();
$staff= $this->getStaff();
// add the %history replacement
$search = array('/%id/','/%ticket/','/%email/','/%name/','/%subject/','/%topic/','/%phone/','/%status/','/%priority/',
'/%dept/','/%assigned_staff/','/%createdate/','/%duedate/','/%closedate/','/%url/','/%history/');
$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->getMessageHistory()); // added for %history
return preg_replace($search,$replace,$text);
}
I hope this helps someone !