PHP Dashboard - First Response Escalation

Moderator: crythias

Post Reply
mbuk2k
Znuny newbie
Posts: 2
Joined: 19 Apr 2012, 17:39
Znuny Version: 3.1.3
Real Name: Myles

PHP Dashboard - First Response Escalation

Post by mbuk2k »

Hi all,

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>
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

Re: PHP Dashboard - First Response Escalation

Post by crythias »

mbuk2k wrote:The ability to display the escalation time in standard date/time format (rather than Unix)
read the php manual for date format
mbuk2k wrote:The ability to display a countdown until escalation, e.g. 3 hours 15 mins, or 2 days 3 hours 14mins, etc for each ticket
read the php manual for date difference.
OTRS 6.0.x (private/testing/public) on Linux with MySQL database.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask
rey90
Znuny newbie
Posts: 70
Joined: 16 Aug 2012, 15:56
Znuny Version: 4.0.10

Re: PHP Dashboard - First Response Escalation

Post by rey90 »

maybe some of this functions could help you:

Code: Select all

´function date_mysql2german($date) {
	if($date == "NULL")
	{
		return "NULL";
	}
	$d    =    explode("-",$date);
	return    sprintf("%02d.%02d.%04d", $d[2], $d[1], $d[0])." ".substr($d[2],2,10);
}

function date_german2mysql($date) {
	$d    =    explode(".",$date);	    
	return    sprintf("%04d-%02d-%02d", $d[2], $d[1], $d[0]);
}

function date_mysql2german_hour($date) {
	if($date == "NULL")
	{
		return "NULL";
	}
	$d    =    explode(":",$date);
	return $d[0]."h ".$d[1]."m ".$d[2]."s";
}


// as timestamp
function time_diff($endtart, $end) {
    $t = array( //suffixes
        'd' => 86400,
        'h' => 3600,
        'm' => 60,
    );
    $end = abs($end - $endtart);
    foreach($t as $key => &$val) {
        $$key = floor($end/$val);
        $end -= ($$key*$val);
        $endtring .= ($$key==0) ? '' : $$key . "$key ";
    }
    return $endtring . $end. 's';
}
Produktiv: OTRS: 4.0.10
Testing": OTRS: 5
OS: Debian 7
Apache2/MySQL 5
Post Reply