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

时间:2012-10-12 10:14:33

标签: php mysql otrs

我正在尝试将几个PHP页面组合起来作为OTRS的仪表板。我们的想法是在办公室的显示器上输出它,以显示接近第一个响应和更新升级的票证。到目前为止,我不是一个如此挣扎的开发者。我设法让它只输出设置了升级时间的门票......太棒了!但是我想显示升级之前的时间。这是我绝对无能为力的地方。我已经尝试通过php / mysql指南混淆我的方式而没有太多运气。

到目前为止,我已经包含了我的代码......不仅希望有人能指出我为升级列添加时间的方向(我猜测它涉及按照操作升级update_update_time(Unix)当前的日期/时间?),但它也可以帮助别人做我想要实现的同样的事情......这将是非常有用的! (obv更改了IP /用户名/密码)。

总结一下;理想情况下,我想要添加到下面脚本的内容是:

以标准日期/时间格式显示升级时间的能力(而不是Unix) 能够在升级之前显示倒计时,例如每张票3小时15分钟,或2天3小时14分钟等

这不是OTRS所特有的,并且适用于任何mySQL / PHP环境,所以希望有一个聪明的孩子能够理解这些东西!

提前感谢任何人可能提供的任何指导或帮助:)

<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>

2 个答案:

答案 0 :(得分:0)

你应该尝试php date()和strtotime()函数。对于倒计时选项http://keith-wood.name/countdown.html

答案 1 :(得分:0)

我认为你应该改变你的方法:如果你使用Perl和OTRS API,你可以使用Ticket Search对象,它允许你搜索Escalation时间:

    # you can use all following escalation options with this four different ways of escalations
    # TicketEscalationTime...
    # TicketEscalationUpdateTime...
    # TicketEscalationResponseTime...
    # TicketEscalationSolutionTime...

    # ticket escalation time of more than 60 minutes ago (optional)
    TicketEscalationTimeOlderMinutes => -60,
    # ticket escalation time of less than 120 minutes ago (optional)
    TicketEscalationTimeNewerMinutes => -120,

    # tickets with escalation time after ... (optional)
    TicketEscalationTimeNewerDate => '2006-01-09 00:00:01',
    # tickets with escalation time before ... (optional)
    TicketEscalationTimeOlderDate => '2006-01-09 23:59:59',