index.php
上传用户:gzy2002
上传日期:2010-02-11
资源大小:1785k
文件大小:16k
- <?php
- // +-------------------------------------------------------------+
- // | DeskPRO v [2.0.1 Production]
- // | Copyright (C) 2001 - 2004 Headstart Solutions Limited
- // | Supplied by WTN-WDYL
- // | Nullified by WTN-WDYL
- // | Distribution via WebForum, ForumRU and associated file dumps
- // +-------------------------------------------------------------+
- // | DESKPRO IS NOT FREE SOFTWARE
- // +-------------------------------------------------------------+
- // | License ID : Full Enterprise License =) ...
- // | License Owner : WTN-WDYL Team
- // +-------------------------------------------------------------+
- // | $RCSfile: index.php,v $
- // | $Date: 2004/02/10 01:34:30 $
- // | $Revision: 1.40 $
- // +-------------------------------------------------------------+
- // | File Details:
- // | - Technician performance and statistics page.
- // +-------------------------------------------------------------+
- error_reporting(E_ALL ^ E_NOTICE);
- include "./../global.php";
- require_once(INCLUDE_PATH.'functions/calendar_functions.php');
- if (function_exists('gd_info')) {
- $graphing = 1;
- } else {
- $graphing = 0;
- }
- tech_nav('Reports & Statistics');
- /************************************
- * QUICK STATS
- ************************************/
- if (!$graphing) {
- echo "<center><b>Warning:</b> Graphing is not enabled, you will not see the graphs that should be displayed.</center><br /><br />";
- }
- $first_entry = $db->query_return("SELECT min(timestamp) AS early FROM ticket_log");
- $first_entry = our_date($first_entry['early'], 'day');
- // Grab ticket counts (closed and customers helped)
- $total = $db->query_return("SELECT COUNT(distinct ticket_log.ticketid) AS total FROM ticket_log WHERE techid = '$user[id]' AND actionid = '14'");
- $total = number_format($total['total']);
- $reps = $db->query_return("SELECT COUNT(id) AS total FROM ticket_message WHERE techid = '$user[id]'");
- $reps = number_format($reps['total']);
- $db->query("SELECT DISTINCT ticketid FROM ticket_message WHERE techid = '$user[id]'", 'ticketid');
- while ($res = $db->row_array()) {
- $custs[] = $res['ticketid'];
- }
- $custs = $db->query_return("SELECT COUNT(DISTINCT userid) AS total FROM ticket WHERE id in " . array2sql($custs));
- $custs = number_format($custs['total']);
- $simple_stats[] = "Sent $reps response(s)";
- $simple_stats[] = "Closed a total of $total ticket(s)";
- $simple_stats[] = "Helped $custs customer(s)";
- /************************************
- * AVERAGE RESOLUTION TIME
- ************************************/
- // CATEGORY
- $db->query("SELECT (min(ticket_message.date) - ticket.date_opened) AS life, ticket_cat.name AS category
- FROM ticket, ticket_message
- LEFT JOIN ticket_cat ON ticket_cat.id = ticket.category
- WHERE ticket_message.ticketid = ticket.id
- AND techid = '$user[id]'
- GROUP by ticketid
- ORDER BY ticket_cat.name
- ");
- $speed = array();
- $speed_tot = array();
- $cat_data = array();
- while ($result = $db->row_array()) {
- $speed[$result['category']]['count']++;
- $speed[$result['category']]['time'] += $result['life'];
- $speed_tot['count']++;
- $speed_tot['time'] += $result['life'];
- }
- foreach ($speed AS $category => $data) {
- $cat_data[] = array('category' => $category, 'life' => ($data['time'] / $data['count']));
- }
- if ($speed_tot['count']) {
- $cat_data[] = array('category' => '<B><I>Average</I></B>', 'life' => ($speed_tot['time'] / $speed_tot['count']));
- } else {
- $cat_data[] = array('category' => '<B><I>Average</I></B>', 'life' => 'None');
- }
- foreach ($cat_data AS $key => $val) {
- $catspeeds = 1;
- if (!$val[category]) {
- $val[category] = "<I>Uncategorized</I>";
- }
- $val['life'] = clean_time($val['life'], 1);
- $avg_response_category[] = array($val[category], $val[life]);
- }
- if (!$catspeeds) {
- $avg_response_category[] = 'None';
- }
- // PRIORITY
- $db->query("SELECT (min(ticket_message.date) - ticket.date_opened) AS life, ticket_pri.name AS priority
- FROM ticket, ticket_message
- LEFT JOIN ticket_pri ON ticket_pri.id = ticket.priority
- WHERE ticket_message.ticketid = ticket.id
- AND techid = '$user[id]'
- GROUP by ticketid
- ORDER BY ticket_pri.name
- ");
- $speed = array();
- $speed_tot = array();
- $pri_data = array();
- while ($result = $db->row_array()) {
- $speed[$result['priority']]['count']++;
- $speed[$result['priority']]['time'] += $result['life'];
- $speed_tot['count']++;
- $speed_tot['time'] += $result['life'];
- }
- foreach ($speed AS $priority => $data) {
- $pri_data[] = array('priority' => $priority, 'life' => ($data['time'] / $data['count']));
- }
- if ($speed_tot['count']) {
- $pri_data[] = array('priority' => '<B><I>Average</I></B>', 'life' => ($speed_tot['time'] / $speed_tot['count']));
- } else {
- $pri_data[] = array('priority' => '<B><I>Average</I></B>', 'life' => 'None');
- }
- foreach ($pri_data AS $key => $val) {
- $prispeeds = 1;
- if (!$val[priority]) {
- $val[priority] = "<I>Unprioritized</I>";
- }
- $val['life'] = clean_time($val['life'], 1);
- $avg_response_pri[] = array($val[priority], $val[life]);
- }
- if (!$prispeeds) {
- $avg_response_pri[] = 'None';
- }
- // OTHER TECHS (TODAY)
- $time = strtotime(date('Y-m-d'));
- $techs = $db->query_return_array("SELECT (min(ticket_message.date) - ticket.date_opened) AS life, username
- FROM ticket, ticket_message
- LEFT JOIN tech ON ticket.tech = tech.id
- WHERE ticket_message.ticketid = ticket.id
- AND ticket.tech != '$user[id]'
- AND ticket_message.techid
- AND ticket_message.date >= '$time'
- GROUP by ticketid
- ");
- if (is_array($techs)) {
- foreach ($techs AS $tech) {
- $avg_resp_other[$tech['username']]['sum'] += $tech['life'];
- $avg_resp_other[$tech['username']]['count']++;
- }
- foreach($avg_resp_other AS $techname => $val) {
- if ($techname) {
- $avg_resp_tech_today[] = array($techname, clean_time($val['sum'] / $val['count']));
- }
- }
- } else {
- $avg_resp_tech_today[] = array("No data available.");
- }
- // OTHER TECHS (THIS WEEK)
- $time = strtotime(date('Y-m-d') . " - 1 week");
- $techs = $db->query_return_array("SELECT (min(ticket_message.date) - ticket.date_opened) AS life, username
- FROM ticket, ticket_message
- LEFT JOIN tech ON ticket.tech = tech.id
- WHERE ticket_message.ticketid = ticket.id
- AND ticket.tech != '$user[id]'
- AND ticket_message.techid
- AND ticket_message.date >= '$time'
- GROUP by ticketid
- ");
- if (is_array($techs)) {
- foreach ($techs AS $tech) {
- $avg_resp_other[$tech['username']]['sum'] += $tech['life'];
- $avg_resp_other[$tech['username']]['count']++;
- }
- foreach($avg_resp_other AS $techname => $val) {
- if ($techname) {
- $avg_resp_tech_week[] = array($techname, clean_time($val['sum'] / $val['count']));
- }
- }
- } else {
- $avg_resp_tech_week[] = array("No data available.");
- }
- /************************************
- * YOUR OPEN TICKETS
- ************************************/
- // CATEGORY
- $db->query("
- SELECT COUNT(*) AS total, ticket_cat.name AS category
- FROM ticket, ticket_cat
- WHERE tech = '$user[id]'
- AND ticket.category = ticket_cat.id
- AND ticket.is_open
- AND ticket.awaiting_tech
- GROUP BY category
- ");
- unset($cats);
- while ($result = $db->row_array()) {
- $cats++;
- $awaiting_response_category[] = array($result[category], $result[total]);
- }
- $awaiting_response_category[] = array('<b>Total</b>', '<b>' . $cats . '</b>');
- // add graph
- if (!$cats) {
- $awaiting_response_category[] = 'None';
- } elseif ($graphing) {
- $awaiting_response_category[] = "<img src="graph.php?type=category">";
- }
- // PRIORITY
- $db->query("
- SELECT COUNT(*) AS total, ticket_pri.name AS priority
- FROM ticket, ticket_pri
- WHERE tech = '$user[id]'
- AND ticket.priority = ticket_pri.id
- AND ticket.is_open
- AND ticket.awaiting_tech
- GROUP BY priority
- ");
- unset($pris);
- while ($result = $db->row_array()) {
- $pris++;
- $awaiting_response_priority[] = array($result[priority], $result[total]);
- }
- $awaiting_response_priority[] = array('<b>Total</b>', '<b>' . $pris . '</b>');
- if (!$pris) {
- $awaiting_response_priority[] = 'None';
- } elseif ($graphing) {
- $awaiting_response_priority[] = "<img src="graph.php?type=priority">";
- }
- /*****************************************************
- TICKETS CLOSED BY THIS TECH
- *****************************************************/
- // CATEGORY
- $stats = $db->query_return_array("
- SELECT COUNT(*) AS total,
- ticket_cat.name AS category
- FROM ticket
- LEFT JOIN ticket_cat ON ticket_cat.id = ticket.category
- WHERE tech = '$user[id]'
- GROUP BY category
- ");
- $stat_tot = 0;
- if (is_array($stats)) {
- foreach ($stats AS $stat) {
- if (!$stat['category']) {
- $stat['category'] = '<I>Uncategorized</I>';
- }
- $your_close_category[] = array($stat[category], $stat[total]);
- $stat_tot += $stat['total'];
- }
- }
- if ($stat_tot) {
- $your_close_category[] = array('<b>Total</b>', '<b>' . $stat_tot . '</b>');
- } else {
- $your_close_category[] = 'No tickets closed';
- }
- // PRIORITY
- if ($stat_tot) {
- $stats = $db->query_return_array("
- SELECT COUNT(*) AS total,
- ticket_pri.name AS priority
- FROM ticket
- LEFT JOIN ticket_pri ON ticket_pri.id = ticket.priority
- WHERE tech = '$user[id]'
- GROUP BY priority
- ");
- foreach ($stats AS $stat) {
- if (!$stat['priority']) {
- $stat['priority'] = '<I>Unprioritized</I>';
- }
- $your_close_priority[] = array($stat[priority], $stat[total]);
- }
- $your_close_priority[] = array('<b>Total</b>', '<b>' . $stat_tot . '</b>');
- } else {
- $your_close_priority[] = 'No tickets closed';
- }
- /************************************
- * TECH RANKING
- ************************************/
- // TECHS
- $db->query("
- SELECT COUNT(ticket_log.id) AS total, tech.username
- FROM ticket_log, tech
- WHERE ticket_log.techid = tech.id
- GROUP BY techid
- ORDER BY 'total'
- DESC LIMIT 5
- ");
- while ($result = $db->row_array()) {
- $techscount += $result[total];
- $top_tech_ticket_closed[] = array($result[username], $result[total]);
- }
- // totals
- $top_tech_ticket_closed[] = array('<b>Total</b>', '<b>' . $techscount . '</b>');
- // no results
- if (!is_array($top_tech_ticket_closed)) {
- $top_tech_ticket_closed[] = "No closed tickets";
- }
- // MOST CUSTOMERS HELPED
- $custs = $db->query_return_array("
- SELECT COUNT(ticket.id) AS total,
- user.username
- FROM ticket,
- user
- WHERE tech = '$user[id]'
- AND !is_open
- AND ticket.userid = user.id
- GROUP BY userid
- ORDER BY total DESC LIMIT 10
- ");
- if (is_array($custs)) {
- foreach ($custs AS $cust) {
- $top_tech_customer_helped[] = array($cust[username], $cust[total]);
- $cust_total += $cust[total];
- }
- $top_tech_customer_helped[] = array('Total', '<b>' . $cust_total . '</b>');
- } else {
- $top_tech_customer_helped[] = 'None';
- }
- /************************************
- * USER RANKING
- ************************************/
- $topusers = $db->query_return_array("
- SELECT COUNT(ticket.id) AS total, user.username, user.id AS userid
- FROM ticket
- LEFT JOIN user ON (ticket.userid = user.id)
- GROUP BY ticket.userid
- ORDER BY 'total'
- DESC LIMIT 5
- ");
- if ($db->num_rows()) {
- foreach ($topusers AS $val) {
- $users++;
- $top_users_tickets[] = array($val[username], $val[total]);
- }
- }
- /************************************
- * TECH TIME ACTIVITY
- ************************************/
- $from = strtotime(date('Y-n-d') . ' -2 weeks');
- if ($_REQUEST['all']) {
- $techlog = $db->query_return_array("SELECT * FROM tech_timelog WHERE techid = '$user[id]' ORDER BY stamp");
- $time_link = "Total Logged Time (all logged events) <A HREF="index.php">View Last Two Weeks</A></CENTER>";
- } else {
- $techlog = $db->query_return_array("SELECT * FROM tech_timelog WHERE techid = '$user[id]' AND stamp >= '$from' ORDER BY stamp");
- $time_link = "Total Logged Time (past two weeks) <A HREF="index.php?all=1">View All Entries</A>";
- }
- foreach ($techlog AS $val) {
- if ($last) {
- if (($diff = $val['stamp'] - $last) <= $settings['max_log_duration']) {
- $techtime[date('Y-m-d', $val['stamp'])] += $diff;
- $total += $diff;
- }
- }
- $last = $val['stamp'];
- }
- if (is_array($techtime)) {
- foreach ($techtime AS $key => $data) {
- $time_log[] = array(date('D, M jS Y', strtotime($key)), clean_time($data));
- }
- }
- $time_log[] = array('<b>Total</b>', '<b>' . clean_time($total) . '</b>');
- /************************************
- * LETS DISPLAY EVERYTHING
- ************************************/
- // basic stats
- echo table_list("Since $first_entry you have:", $simple_stats, '95%');
- echo "<br /><br />";
- // open tickets awaiting response (category / priority)
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Your Open Tickets Awaiting Your Response (by Category):", $awaiting_response_category, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo table_list("Your Open Tickets Awaiting Your Response (by Priority):", $awaiting_response_priority, '100%');
- echo "</td></tr></table>";
- echo "<br /><br />";
- // avg response times
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Your Avg. Response Time</B> (by Category):", $avg_response_category, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo table_list("Your Avg. Response Time</B> (by Priority)", $avg_response_pri, '100%');
- echo "</td></tr></table>";
- echo "<br /><br />";
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Others' Avg. Response Time (Today)", $avg_resp_tech_today, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo table_list("Others' Avg. Response Time (Week)", $avg_resp_tech_week, '100%');
- echo "</td></tr></table>";
- echo "<br /><br />";
- // tickets you have closed (category / priority)
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Your Closed Tickets (by Category):", $your_close_category, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo table_list("Your Closed Tickets (by Priority):", $your_close_priority, '100%');
- echo "</td></tr></table>";
- echo "<br /><br />";
- // list of techs by number of tickets closed and number of customers helped
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Top Techs</B> (by tickets closed):", $top_tech_ticket_closed, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo table_list("Customers Most Helped</B> (Tickets Closed):", $top_tech_customer_helped, '100%');
- echo "</td></tr></table>";
- echo "<br /><br />";
- // users by number of tickets created
- echo "<table cellpadding="3" align="center" width="95%" cellspacing="0"><tr><td valign="top" width="50%">";
- echo table_list("Top User Ticket Submitters</B> (by tickets opened)", $top_users_tickets, '100%');
- echo "</td><td><td width="40"> </td><td valign="top" width="50%">";
- echo "</td></tr></table>";
- echo "<br /><br />";
- // basic stats
- echo table_list($time_link, $time_log, '95%');
- tech_footer();
- ?>