doubi7346 2012-10-12 10:14
浏览 30

PHP / mySQL日期/时间计算(OTRS)

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 escalation_update_time (Unix) 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

This isn't specific to OTRS I guess, and applies to any mySQL/PHP environment, so hopefully there's a whizz kid out there that understands this stuff!

Thank you in advance for any guidance or help anyone may be able to offer :)

<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>
";
// 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>
";
}
mysql_free_result($result);
?>
</body></html>
  • 写回答

2条回答 默认 最新

  • doupao3662 2012-10-12 10:37
    关注

    You should try php date() and strtotime() functions. For countdown option http://keith-wood.name/countdown.html

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100