... continued from the previous post above ...
REPLACE WITH:
<div align="left">
<a class="Icon thread" href="#" onClick="toggleLayer('ticketthread'); return false;"><?php echo (I_S_V_TICKET_THREAD); ?></a>
<div id="ticketthread">
<?php
//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 resp.ticket_id='.db_input($id).
' GROUP BY resp.response_id ORDER BY created DESC';
$resp =db_query($sql);
$i=1;
while ($resp_row = db_fetch_array($resp)) {
if ($i==1) {
$dateend = date("Y-m-d H");
$datebegin = $resp_row;
$lastdate = $datebegin;
} else if ($i!=2) {
$datebegin = $resp_row;
}
$datediff = new Duration($datebegin,$dateend);
$resultdiff=$datediff->Duration($datebegin,$dateend);
$dateend = $datebegin;
?>
<table align="center" class="response" cellspacing="0" cellpadding="1" width="100%" border=0>
<tr><th><?php echo "(#".$i.") "; echo Format:($resp_row)?> - <?php echo $resp_row?></th>
</tr>
<?php if($resp_row>0){ ?>
<tr class="header">
<td><?php echo $ticket->getAttachmentStr($respID,'R')?></td></tr>
<?php }?>
<tr><td><?php echo Format:($resp_row); ?></td></tr>
<tr class="header"><td align="right"><?php echo "Duration: ".$resultdiff."<br />"; ?></td></tr>
</table>
<?php
//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_id='.db_input($resp_row).' AND msg.ticket_id='.db_input($id).
' GROUP BY msg.msg_id ORDER BY created DESC';
$msgres =db_query($sql);
while ($msg_row = db_fetch_array($msgres)) {
$i++;
$dateend = $msg_row;
$firstdate = $dateend;
$datediff = new Duration($dateend,$datebegin);
$resultdiff2=$datediff->Duration($dateend,$datebegin);
?>
<table align="center" class="message" cellspacing="0" cellpadding="1" width="100%" border=0>
<tr><th><?php echo "(#".$i.") "; echo Format:($msg_row); echo " - ".Format:($ticket->getName()); ?></th>
</tr>
<?php if($msg_row>0){ ?>
<tr class="header"><td><?php echo $ticket->getAttachmentStr($msg_row,'M')?></td></tr>
<?php }?>
<tr><td>
<?php echo Format:($msg_row); ?>
</td></tr>
<tr class="header"><td align="right"><?php echo "Duration: ".$resultdiff2."<br />"; ?></td></tr>
</table>
<?php
}
$msgid =$msg_row;
$i++;
$datebegin = $dateend;
}
if ($i==1) { // in case: only one message from client!!!
//get messages from client
$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($id).
' GROUP BY msg.msg_id ORDER BY created DESC';
$msgres =db_query($sql);
while ($msg_row = db_fetch_array($msgres)) {
if ($i==1) {
$dateend = date("Y-m-d H");
$datebegin = $resp_row;
$firstdate = $datebegin;
} else if ($i!=1) {
$datebegin = $resp_row;
$firstdate = $datebegin;
}
$lastdate = $dateend;
$datediff = new Duration($datebegin,$dateend);
$resultdiff=$datediff->Duration($datebegin,$dateend);
$dateend = $dateend;
?>
<table align="center" class="message" cellspacing="0" cellpadding="1" width="100%" border=0>
<tr><th><?php echo "(#".$i.") "; echo Format:($msg_row); echo " - ".Format:($ticket->getName()); ?></th>
</tr>
<?php if($msg_row>0){ ?>
<tr class="header"><td><?php echo $ticket->getAttachmentStr($msg_row,'M')?></td></tr>
<?php }?>
<tr><td>
<?php echo Format:($msg_row); ?>
</td></tr>
<tr class="header"><td align="right"><?php echo "Duration: ".$resultdiff."<br />"; ?></td></tr>
</table>
<?php
$i++;
}
}
$datediff = new Duration($firstdate,$lastdate);
$resultdiff=$datediff->Duration($firstdate,$lastdate);
?>
</div>
</div>
<?php
$totalpost = $i-1;
if ($ticket->getStatus()=='open') {
echo "<div align='right'><br /><b>Total: ".$totalpost." post(s), Duration: ".$resultdiff."</b></div>";
$lastdate = date("Y-m-d H"); //userdate(); //date("Y-m-d H");
$datediff = new Duration($firstdate,$lastdate);
$resultdiff=$datediff->Duration($firstdate,$lastdate);
echo "<div align='right'><br /><b>Ticket still opened, Total Duration: ".$resultdiff."</b></div>";
} else {
echo "<div align='right'><br /><b>Total: ".$totalpost." post(s), Duration: ".$resultdiff."</b></div>";
}
?>
Best regards,
Masino Sinaga