I'm trying to put together a couple of PHP pages to act as a dashboard for OTRS. The idea is to output it on a display in the office to show tickets that are approaching first response and update escalations. I'm not a dev so struggling through this so far. I've managed to get it outputting only tickets that have an escalation time set...great! however I want to show the time until escalation. This is where I'm absolutely clueless. I've tried muddling my way through php/mysql guides without a great deal of luck.
I've included my code so far...in not only a hope that someone could point me in the direction for adding a time to escalation column (which I'm guessing involves manipulating the time to escalation value in accordance with the current date/time?), but also that it may help someone do the same thing I'm trying to achieve...which would be pretty useful! (obv changed IP/username/pass).
So to summarize; ideally the things I want to add to the script below are:
The ability to display the escalation time in standard date/time format (rather than Unix)
The ability to display a countdown until escalation, e.g. 3 hours 15 mins, or 2 days 3 hours 14mins, etc for each ticket
Thank you in advance for any guidance or help anyone may be able to offer
Code: Select all
<html><head><title>OTRS - First Contact</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head><body>
<?php
$db_host = '192.168.1.254';
$db_user = 'myuser';
$db_pwd = 'mypassword';
$database = 'otrs';
$table = 'users';
if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");
if (!mysql_select_db($database))
die("Can't select database");
// sending query
$result = mysql_query("SELECT q.name AS queue_name, t.tn, t.customer_id,a .a_from, t.title, a.create_time, create_time_unix, escalation_update_time
FROM queue AS q, ticket AS t, article AS a, (
SELECT _a.ticket_id, MAX(_a.create_time) AS create_time
FROM ticket AS _t, ticket_state AS _t_s, article AS _a
WHERE _t_s.name IN ('new', 'open')
AND _t.ticket_state_id = _t_s.id
AND _a.ticket_id = _t.id
GROUP BY _a.ticket_id
) a_max
WHERE q.id = t.queue_id
AND t.id = a_max.ticket_id
AND a.create_time = a_max.create_time
AND q.name = 'Service Desk'
AND escalation_response_time >0
GROUP BY t.id
ORDER BY a.create_time ASC");
if (!$result) {
die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<h1>Ticket Escalations (First Contact)</h1>";
echo "<table border='1'><tr>";
// printing table headers
echo "<td>Queue</td>";
echo "<td>Ticket#</td>";
echo "<td>Store</td>";
echo "<td>Customer</td>";
echo "<td>Subject</td>";
echo "<td>Last Update</td>";
echo "<td>Created Time (Unix)</td>";
echo "<td>Escalation Time</td>";
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>