2009-03-22 05:22:34 +03:00
< ? php
/*
2009-06-04 02:44:32 +04:00
* This file is part of Mibew Messenger project .
2009-08-04 20:30:39 +04:00
*
2011-02-16 03:22:22 +03:00
* Copyright ( c ) 2005 - 2011 Mibew Messenger Community
2009-08-04 19:03:27 +04:00
* 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
2009-08-04 20:30:39 +04:00
*
2009-08-04 17:38:37 +04:00
* 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 .
2009-08-04 20:30:39 +04:00
*
2009-03-22 05:22:34 +03:00
* Contributors :
* Evgeny Gryaznov - initial API and implementation
*/
require_once ( '../libs/common.php' );
require_once ( '../libs/chat.php' );
require_once ( '../libs/operator.php' );
$operator = check_login ();
2009-06-04 05:14:26 +04:00
setlocale ( LC_TIME , getstring ( " time.locale " ));
2009-03-22 05:22:34 +03:00
$page = array ();
$page [ 'operator' ] = topage ( get_operator_name ( $operator ));
$page [ 'availableDays' ] = range ( 1 , 31 );
$page [ 'availableMonth' ] = get_month_selection ( time () - 400 * 24 * 60 * 60 , time () + 50 * 24 * 60 * 60 );
$page [ 'showresults' ] = false ;
$errors = array ();
if ( isset ( $_GET [ 'startday' ])) {
$startday = verifyparam ( " startday " , " /^ \ d+ $ / " );
$startmonth = verifyparam ( " startmonth " , " /^ \ d { 2}. \ d { 2} $ / " );
$endday = verifyparam ( " endday " , " /^ \ d+ $ / " );
$endmonth = verifyparam ( " endmonth " , " /^ \ d { 2}. \ d { 2} $ / " );
$start = get_form_date ( $startday , $startmonth );
$end = get_form_date ( $endday , $endmonth ) + 24 * 60 * 60 ;
} else {
$curr = getdate ( time ());
if ( $curr [ 'mday' ] < 7 ) {
// previous month
if ( $curr [ 'mon' ] == 1 ) {
$month = 12 ;
$year = $curr [ 'year' ] - 1 ;
} else {
$month = $curr [ 'mon' ] - 1 ;
$year = $curr [ 'year' ];
}
$start = mktime ( 0 , 0 , 0 , $month , 1 , $year );
$end = mktime ( 0 , 0 , 0 , $month , date ( " t " , $start ), $year ) + 24 * 60 * 60 ;
} else {
$start = mktime ( 0 , 0 , 0 , $curr [ 'mon' ], 1 , $curr [ 'year' ]);
$end = time () + 24 * 60 * 60 ;
}
}
set_form_date ( $start , " start " );
set_form_date ( $end - 24 * 60 * 60 , " end " );
if ( $start > $end ) {
$errors [] = getlocal ( " statistics.wrong.dates " );
}
$link = connect ();
2011-02-26 16:13:16 +03:00
$page [ 'reportByDate' ] = select_multi_assoc ( " select DATE(dtmcreated) as date, COUNT(distinct threadid) as threads, SUM( ${ mysqlprefix } chatmessage.ikind = $kind_agent ) as agents, SUM( ${ mysqlprefix } chatmessage.ikind = $kind_user ) as users " .
" from ${ mysqlprefix } chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by DATE(dtmcreated) order by dtmcreated desc " , $link );
2009-03-22 05:22:34 +03:00
2011-02-26 16:13:16 +03:00
$page [ 'reportByDateTotal' ] = select_one_row ( " select COUNT(distinct threadid) as threads, SUM( ${ mysqlprefix } chatmessage.ikind = $kind_agent ) as agents, SUM( ${ mysqlprefix } chatmessage.ikind = $kind_user ) as users " .
" from ${ mysqlprefix } chatmessage where unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end " , $link );
2009-03-22 05:22:34 +03:00
$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 " .
2011-02-26 16:13:16 +03:00
" from ${ mysqlprefix } chatmessage, ${ mysqlprefix } chatoperator " .
2009-03-22 05:22:34 +03:00
" where agentId = operatorid AND unix_timestamp(dtmcreated) >= $start AND unix_timestamp(dtmcreated) < $end group by operatorid " , $link );
$page [ 'showresults' ] = count ( $errors ) == 0 ;
mysql_close ( $link );
prepare_menu ( $operator );
start_html_output ();
require ( '../view/statistics.php' );
?>