Added tabs at statistics page

This commit is contained in:
Dmitriy Simushev 2012-03-13 20:09:37 +00:00
parent 0fc5beb17a
commit 5016eceae8
3 changed files with 85 additions and 17 deletions

View File

@ -0,0 +1,46 @@
<?php
/*
* This file is part of Mibew Messenger project.
*
* Copyright (c) 2005-2011 Mibew Messenger Community
* All rights reserved. The contents of this file are subject to the terms of
* the Eclipse Public License v1.0 which accompanies this distribution, and
* is available at http://www.eclipse.org/legal/epl-v10.html
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU General Public License Version 2 or later (the "GPL"), in which case
* the provisions of the GPL are applicable instead of those above. If you wish
* to allow use of your version of this file only under the terms of the GPL, and
* not to allow others to use your version of this file under the terms of the
* EPL, indicate your decision by deleting the provisions above and replace them
* with the notice and other provisions required by the GPL.
*
* Contributors:
* Evgeny Gryaznov - initial API and implementation
*/
function get_statistics_query($type)
{
$query = $_SERVER['QUERY_STRING'];
if (! empty($query)) {
$query = '?'.$query;
$query = preg_replace("/\?type=\w+\&/", "?", $query);
$query = preg_replace("/(\?|\&)type=\w+/", "", $query);
}
$query .= strstr($query, "?") ? "&type=$type" : "?type=$type";
return $query;
}
function setup_statistics_tabs($active)
{
global $settings, $page, $webimroot;
$page['tabs'] = array(
getlocal("report.bydate.title") => $active != 0 ? "$webimroot/operator/statistics.php".get_statistics_query('bydate') : "",
getlocal("report.byoperator.title") => $active != 1 ? "$webimroot/operator/statistics.php".get_statistics_query('byagent') : ""
);
if ($settings['enabletracking']) {
$page['tabs'][getlocal("report.bypage.title")] = ($active != 2 ? "$webimroot/operator/statistics.php".get_statistics_query('bypage') : "");
}
}
?>

View File

@ -22,6 +22,7 @@
require_once('../libs/common.php'); require_once('../libs/common.php');
require_once('../libs/chat.php'); require_once('../libs/chat.php');
require_once('../libs/operator.php'); require_once('../libs/operator.php');
require_once('../libs/statistics.php');
$operator = check_login(); $operator = check_login();
force_password($operator); force_password($operator);
@ -33,6 +34,11 @@ $page['operator'] = topage(get_operator_name($operator));
$page['availableDays'] = range(1, 31); $page['availableDays'] = range(1, 31);
$page['availableMonth'] = get_month_selection(time() - 400 * 24 * 60 * 60, time() + 50 * 24 * 60 * 60); $page['availableMonth'] = get_month_selection(time() - 400 * 24 * 60 * 60, time() + 50 * 24 * 60 * 60);
$page['showresults'] = false; $page['showresults'] = false;
$statisticstype = verifyparam("type", "/^(bydate|byagent|bypage)$/", "bydate");
$page['type'] = $statisticstype;
$page['showbydate'] = ($statisticstype == 'bydate');
$page['showbyagent'] = ($statisticstype == 'byagent');
$page['showbypage'] = ($statisticstype == 'bypage');
$errors = array(); $errors = array();
if (isset($_GET['startday'])) { if (isset($_GET['startday'])) {
@ -68,29 +74,34 @@ if ($start > $end) {
$errors[] = getlocal("statistics.wrong.dates"); $errors[] = getlocal("statistics.wrong.dates");
} }
$activetab = 0;
$link = connect(); $link = connect();
if ($statisticstype == 'bydate') {
$page['reportByDate'] = select_multi_assoc("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
"from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " .
"where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end group by DATE(m.dtmcreated) order by m.dtmcreated desc", $link);
$page['reportByDate'] = select_multi_assoc("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " . $page['reportByDateTotal'] = select_one_row("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " .
"from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " . "from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " .
"where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end group by DATE(m.dtmcreated) order by m.dtmcreated desc", $link); "where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end", $link);
$activetab = 0;
$page['reportByDateTotal'] = select_one_row("select DATE(t.dtmcreated) as date, COUNT(distinct t.threadid) as threads, SUM(m.ikind = $kind_agent) as agents, SUM(m.ikind = $kind_user) as users, ROUND(AVG(unix_timestamp(t.dtmchatstarted)-unix_timestamp(t.dtmcreated)),1) as avgwaitingtime, ROUND(AVG(tmp.lastmsgtime - unix_timestamp(t.dtmchatstarted)),1) as avgchattime " . } elseif($statisticstype == 'byagent') {
"from ${mysqlprefix}chatmessage m, ${mysqlprefix}chatthread t, (SELECT i.threadid, unix_timestamp(MAX(i.dtmcreated)) AS lastmsgtime FROM ${mysqlprefix}chatmessage i WHERE (ikind = $kind_user OR ikind = $kind_agent) GROUP BY i.threadid) tmp " . $page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " .
"where m.threadid = t.threadid AND tmp.threadid = t.threadid AND unix_timestamp(t.dtmchatstarted) <> 0 AND unix_timestamp(m.dtmcreated) >= $start AND unix_timestamp(m.dtmcreated) < $end", $link); "from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " .
"where agentId = operatorid AND unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by operatorid", $link);
$page['reportByAgent'] = select_multi_assoc("select vclocalename as name, COUNT(distinct threadid) as threads, SUM(ikind = $kind_agent) as msgs, AVG(CHAR_LENGTH(tmessage)) as avglen " . $activetab = 1;
"from ${mysqlprefix}chatmessage, ${mysqlprefix}chatoperator " . } elseif($statisticstype == 'bypage') {
"where agentId = operatorid AND unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by operatorid", $link); $page['reportByPage'] = select_multi_assoc("SELECT COUNT(DISTINCT p.pageid) as visittimes, p.address, COUNT(DISTINCT t.threadid) as chattimes " .
"FROM ${mysqlprefix}visitedpagestatistics p LEFT OUTER JOIN ${mysqlprefix}chatthread t ON (p.address = t.referer AND DATE(p.visittime) = DATE(t.dtmcreated)) " .
$page['reportByPage'] = select_multi_assoc("SELECT COUNT(DISTINCT p.pageid) as visittimes, p.address, COUNT(DISTINCT t.threadid) as chattimes " . "WHERE unix_timestamp(p.visittime) >= $start AND unix_timestamp(p.visittime) < $end GROUP BY p.address", $link);
"FROM ${mysqlprefix}visitedpagestatistics p LEFT OUTER JOIN ${mysqlprefix}chatthread t ON (p.address = t.referer AND DATE(p.visittime) = DATE(t.dtmcreated)) " . $activetab = 2;
"WHERE unix_timestamp(p.visittime) >= $start AND unix_timestamp(p.visittime) < $end GROUP BY p.address", $link); }
$page['showresults'] = count($errors) == 0; $page['showresults'] = count($errors) == 0;
close_connection($link); close_connection($link);
prepare_menu($operator); prepare_menu($operator);
setup_statistics_tabs($activetab);
start_html_output(); start_html_output();
require('../view/statistics.php'); require('../view/statistics.php');
?> ?>

View File

@ -19,7 +19,9 @@
* Evgeny Gryaznov - initial API and implementation * Evgeny Gryaznov - initial API and implementation
*/ */
require_once("inc_tabbar.php");
require_once("inc_menu.php"); require_once("inc_menu.php");
$page['title'] = getlocal("statistics.title"); $page['title'] = getlocal("statistics.title");
$page['menuid'] = "statistics"; $page['menuid'] = "statistics";
@ -34,8 +36,11 @@ require_once('inc_errors.php');
?> ?>
<form name="statisticsForm" method="get" action="<?php echo $webimroot ?>/operator/statistics.php"> <form name="statisticsForm" method="get" action="<?php echo $webimroot ?>/operator/statistics.php">
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner"> <input type="hidden" name="type" value="<?php echo $page['type'] ?>" />
<?php print_tabbar(); ?>
<div class="mform"><div class="formtop"><div class="formtopi"></div></div><div class="forminner">
<div class="fieldForm"> <div class="fieldForm">
<div class="field"> <div class="field">
@ -66,6 +71,7 @@ require_once('inc_errors.php');
<?php if( $page['showresults'] ) { ?> <?php if( $page['showresults'] ) { ?>
<?php if($page['showbydate']) { ?>
<br/> <br/>
<br/> <br/>
@ -117,7 +123,9 @@ require_once('inc_errors.php');
<?php } ?> <?php } ?>
</tbody> </tbody>
</table> </table>
<?php } ?>
<?php if($page['showbyagent']) { ?>
<br/> <br/>
<br/> <br/>
@ -153,7 +161,9 @@ require_once('inc_errors.php');
<?php } ?> <?php } ?>
</tbody> </tbody>
</table> </table>
<?php } ?>
<?php if($page['showbypage']) { ?>
<br/> <br/>
<br/> <br/>
@ -186,6 +196,7 @@ require_once('inc_errors.php');
<?php } ?> <?php } ?>
</tbody> </tbody>
</table> </table>
<?php } ?>
<?php } ?> <?php } ?>