<?php
/**
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package QuickTalk Guestbook
* @author Philippe Vandenberghe <hide@address.com>
* @copyright 2009-2012 The PHP Group
* @version 2.5 build:20100731
*/
session_start();
require_once('bin/qtg_init.php');
include(GetLang().'qtg_adm.php');
$qtg_skin = 'admin';
$intYear = intval(date('Y')); if ( intval(date('n'))<2 ) $intYear--; // year filter
$ch = array('time'=>'m','type'=>'b','value'=>'a','trend'=>'a'); // chart parameters
// blocktime: m=month, q=quarter, d=10days
// graph type: b=bar, l=line, B=bar+variation, L=line+variation
// graphics reals: a=actual, p=percent
// trends reals: a=actual, p=percent
$pg_name=$L['Statistics'];
$pg_url='qtg_adm_stat.php';
// --------
// SUBMITTED
// --------
if ( isset($_GET['y']) )
{
$y = intval(strip_tags($_GET['y']));
if ( !QTisbetween($y,2000,$intYear+1) ) die('Invalid target year');
$intYear=$y;
}
if ( isset($_GET['ch']) )
{
$str = strip_tags($_GET['ch']);
if ( strlen($str)>0 ) $ch['time'] = substr($str,0,1); // blocktime
if ( strlen($str)>1 ) $ch['type'] = substr($str,1,1); // graph type
if ( strlen($str)>2 ) $ch['value'] = substr($str,2,1); // value type
if ( strlen($str)>3 ) $ch['trend'] = substr($str,3,1); // trends value type
}
// --------
// STATS
// --------
$arrYears = array($intYear-1=>$intYear-1,$intYear=>$intYear);
include('qtg_adm_stat_inc.php');
// --------
// HTML START
// --------
$arrCss[] = 'qtg_graph.css';
include('qtg_p_header.php');
include('qtg_adm_menu.php');
echo '
<h2>',$L['General_stats'],'</h2>
<table cellspacing="0" class="admin">
<tr>
<td class="admin_top" width="180">',$L['Messages'],'</td>
<td class="admin">',$intTotalPost,'</td>
</tr>
<tr>
<td class="admin_top">',$L['Hidden_messages'],'</td>
<td class="admin">',$intHiddenPost,'</td>
</tr>
<tr>
<td class="admin_top">',$L['First_message'],'</td>
<td class="admin">',$strFirstdate,'</td>
</tr>
<tr>
<td class="admin_top">',$L['Last_message'],'</td>
<td class="admin">',$strLastdate,'</td>
</tr>
</table>
';
$arrMenuTime = array(); // Block time: q=quarter, m=month, d=10days
if ( $ch['time']=='q' ) { $arrMenuTime[]=$L['Per_q']; } else { $arr=$ch; $arr['time']='q'; $arrMenuTime[]='<a href="qtg_adm_stat.php?y='.$intYear.'&ch='.implode('',$arr).'" class="small">'.$L['Per_q'].'</a>'; }
if ( $ch['time']=='m' ) { $arrMenuTime[]=$L['Per_m']; } else { $arr=$ch; $arr['time']='m'; $arrMenuTime[]='<a href="qtg_adm_stat.php?y='.$intYear.'&ch='.implode('',$arr).'" class="small">'.$L['Per_m'].'</a>'; }
if ( $ch['time']=='d' ) { $arrMenuTime[]=$L['Per_d']; } else { $arr=$ch; $arr['time']='d'; $arrMenuTime[]='<a href="qtg_adm_stat.php?y='.$intYear.'&ch='.implode('',$arr).'" class="small">'.$L['Per_d'].'</a>'; }
echo '<table width="100%" class="hidden" cellspacing="0">
<tr>
<td class="hidden"><h2>',$L['Messages_per_'.$ch['time']],'</h2></td>
<td class="hidden small" style="text-align:right; vertical-align:middle">',implode(' · ',$arrMenuTime),'</td>
</tr>
';
// Display table header
echo '<table class="admin" cellspacing="0">',N;
echo '<tr>',N;
echo '<td class="admin_top" style="width:50px"> </td>',N;
switch($ch['time'])
{
case 'q': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="admin_top" style="text-align:center;">Q',$i,'</td>'; } break;
case 'm': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="admin_top" style="text-align:center;">',$L['dateMM'][$i],'</td>'; } break;
case 'd': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="admin_top" style="text-align:center;">',str_replace(' ','<br/>',QTdatestr(DateAdd($strTendaysago,$i,'day'),'d M','')),'</td>'; } break;
}
echo '<td class="admin_top" style="text-align:center;"><b>',($ch['time']=='d' ? '10 '.strtolower($L['Days']) : $L['Total']),'</b></td>
</tr>';
// DISPLAY MESSAGES
foreach($arrYears as $y)
{
echo '<tr>',N;
echo '<td class="admin_top">',$y,'</td>',N;
for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
echo '<td class="admin" style="text-align:center;">',(isset($arrT[$y][$intBt]) ? $arrT[$y][$intBt] : '·'),'</td>',N;
}
echo '<td class="admin" style="text-align:center;padding:5px;"><b>',$arrTs[$y],'</b></td>',N;
echo '</tr>';
}
echo '</table>',N;
// After values display, change the null values to zero to be able to make charts
foreach($arrYears as $y) $arrT[$y]=QTarrayzero($arrT[$y]);
// GRAPH
if ( file_exists('bin/qt_lib_graph.php') && file_exists('admin/qtg_graph.css') )
{
$y = intval(date('Y')); // add current year if not in $arrYears
if ( !in_array($y,$arrYears) ) $arrYears[$y]=$y;
echo '<table class="admin" cellspacing="0">',N;
echo '<tr class="admin graph">',N;
echo '<td class="admin_top" colspan="2" style="text-align:right">';
echo '<form method="get" action="',Href('qtg_adm_stat.php'),'?ch=',implode('',$ch),'"><select name="y" id="y" class="small">',QTasTag($arrYears,$intYear),'</select> <input type="submit" name="ok" id="ok" class="small" value="',$L['Ok'],'"/></form>',N;
echo '</td>',N;
echo '</tr>',N;
echo '<tr class="admin">',N;
echo '<td class="admin graph">',N,N;
QTbarchart(QTarraymerge($arrA,$arrT[$intYear]),320,100,QTroof($arrT[$intYear]),2,true,$L['Items_per_'.$ch['time']],'','1');
echo '</td>',N;
echo '<td class="admin graph" style="vertical-align:top">',N,N;
QTbarchart(QTarraymerge($arrA,QTpercent($arrT[$intYear])),350,100,100,2,'P',$L['Items_per_'.$ch['time']].' (%)','','1');
echo '</td>',N;
echo '</tr>',N;
echo '<tr class="admin">',N;
echo '<td class="admin graph">',N,N;
QTbarchart(QTarraymerge($arrA,QTcumul($arrT[$intYear])),320,100,QTroof($arrT[$intYear]),2,true,$L['Items_per_'.$ch['time'].'_cumul'],'','1');
echo '</td>',N;
echo '<td class="admin graph" style="vertical-align:top">',N,N;
QTbarchart(QTarraymerge($arrA,QTcumul(QTpercent($arrT[$intYear],2))),350,100,100,2,'P',$L['Items_per_'.$ch['time'].'_cumul'].' (%)','','1');
echo '</td>',N;
echo '</tr>',N;
echo '</table>',N;
}
else
{
echo '<p class="small">Graphs cannot be displayed because one of these files is missing: bin/qt_lib_graph.php, ',$qtg_skin.'/qtg_graph.css</p>';
}
// IP STATS
if ( $oDB->type!='file' )
{
$oDB->Query('SELECT ip,count(ip) as countip FROM '.TABMESSAGE.' WHERE id>=0 GROUP BY ip ORDER BY countip DESC');
$ips='';
$i=1;
while($row=$oDB->Getrow())
{
$ip = $row['ip'];
if ($ip=='') $ip='?.?.?.?';
$ips .= "<b>{$row['countip']}</b> - $ip<br/>";
$i++;
if ($i>5) break;
}
echo '
<h2>',$L['Advenced_stats'],'</h2>
<table cellspacing="0" class="admin">
<tr valign="top">
<td class="admin_top" width="180">Top 5 IPs</td>
<td class="admin">',$ips,'</td>
</tr>
</table>
<br/>
';
}
// --------
// HTML END
// --------
include('qtg_p_footer.php');
?>