<?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
* @author Philippe Vandenberghe <hide@address.com>
* @copyright 2008-2012 The PHP Group
* @version 2.5.1 build:20101027
*/
session_start();
require_once('bin/qtf_init.php');
if ( !$oVIP->CanView('V4') ) HtmlPage(11);
include(Translate('qtf_stat.php'));
include('bin/qtf_fn_sql.php');
include('bin/qtf_fn_stat.php');
// --------
// INITIALISE
// --------
$oVIP->selfurl = 'qtf_stats.php';
$oVIP->selfname = $L['Statistics'];
$s = -1; // section filter
$y = date('Y'); if ( intval(date('n'))<2 ) $y--; // year filter
$type = ''; // type filter
$tag = ''; // tags filter
$tt = 'g'; // tab: g=global, gt=globaltrend, d=detail, dt=detailtrend
$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
$lang = GetIso();
$arrSeries = array();
// --------
// SUBMITTED
// --------
QThttpvar('y s type tag tt','int int str str str',true,true,false);
if ( $s>=0 ) { $strSection = 'forum='.$s.' AND '; } else { $strSection=''; }
if ( !empty($type) ) { $strType='type="'.strtoupper(substr($type,0,1)).'" AND '; } else { $strType=''; }
$strTags = '';
if ( !empty($tag) )
{
if ( substr($tag,-1,1)==';' ) $tag = substr($tag,0,-1);
$arrTags = explode(';',$tag);
$str = '';
foreach($arrTags as $strTag)
{
if ( !empty($str) ) $str .= ' OR ';
$str .= 'UPPER(tags) LIKE "%'.strtoupper($strTag).'%"';
}
if ( !empty($str) ) $strTags = ' ('.$str.') AND ';
}
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
}
if ( $tt=='g' || $tt=='d' ) $ch['type'] = strtolower($ch['type']);
// --------
// INITIALISE RANGES
// --------
if ( $tt=='gt' || $tt=='dt' )
{
$arrYears = array($y-1,$y); // Normal is 1 year but for Trends analysis, 2 years
}
else
{
$arrYears = array($y);
}
$oDB->Query( 'SELECT count(id) as countid, min(firstpostdate) as startdate, max(firstpostdate) as lastdate FROM '.TABTOPIC );
$row = $oDB->Getrow();
if ( empty($row['startdate']) ) $row['startdate']=strval($y-1).'0101';
if ( empty($row['lastdate']) ) $row['lastdate']=strval($y).'1231';
$intTopics = intval($row['countid']);
$strLastdaysago = substr($row['lastdate'],0,8);
$strTendaysago = DateAdd($strLastdaysago,-10,'day');
$intStartyear = intval(substr($row['startdate'],0,4));
$intStartmonth = intval(substr($row['startdate'],4,2));
$intEndyear = intval(date('Y'));
$intEndmonth = intval(date('n'));
// --------
// HTML START
// --------
$strFilter = 's='.$s.'&y='.$y.'&type='.$type.'&tag='.$tag;
$arrTags = cSection::GetTagsUsed(-1);
$str = '';
foreach($arrTags as $strName=>$strDesc) { $str .= '{n:"'.$strName.'",d:"'.($strName==$strDesc ? ' ' : substr($strDesc,0,64)).'"},'; }
$str = substr($str,0,-1);
$strHeadScript = '
<link rel="stylesheet" type="text/css" href="bin/css/qt_jquery.css"/>
<script type="text/javascript" src="bin/qt_jquery.js"></script>
<script type="text/javascript" src="bin/qt_jquery_auto.js"></script>
<script type="text/javascript">
<!--
function FlushTag() { $("#tag").flushCache(); }
$(document).ready(function() {
var arrData = ['.$str.'];
$("#tag").autocomplete(arrData,{
minChars:0,
width:190,
multiple:true,
multipleSeparator:";",
formatItem: function(row) { return (row.d==" ") ? row.n : (row.n + "<span class=small> - " + row.d + "</span>"); },
formatResult: function(row) { return row.n; }
});
});
-->
</script>
';
$oVIP->arrJava=null;
$oVIP->arrCss[] = '../bin/css/qt_jquery.css';
$oVIP->arrCss[] = 'qtf_main2.css';
include('qtf_p_header.php');
// TITLE and OPTIONS
if ( $intTopics>2 )
{
echo '
<form method="get" action="',Href(),'">
';
$arrY = array(); // all possible years
for ($i=$intStartyear;$i<=$intEndyear;$i++) $arrY[$i]=$i;
$arrT = array('0'=>$L['All'],'T'=>$L['Topic'],'A'=>$L['News']); // all possible types
echo '<table class="searchoptions">
<tr class="hidden">
<td class="hidden" colspan="5"><p class="legendtitle">',$L['Options'],'</p></td>
</tr>
<tr class="hidden">
<td class="hidden">',$L['Year'],'</td>
<td class="hidden">',(count($_SESSION[QT]['sys_sections'])>0 ? $L['Section'] : ' '),'</td>
<td class="hidden">',$L['Type'],'</td>
<td class="hidden">',( $_SESSION[QT]['tags']=='0' ? S : $L['Tag']),'</td>
<td class="hidden"> </td>
</tr>
<tr class="hidden">
<td class="hidden"><input type="hidden" name="tt" value="',$tt,'"/><select class="small" name="y" id="y">',QTasTag($arrY,$y),'</select></td>
<td class="hidden">',(count($_SESSION[QT]['sys_sections'])>0 ? '<select class="small" name="s" id="s"><option value="-1">'.$L['In_all_sections'].'</option>'.Gotolist($s).'</select>' : ' '),'</td>
<td class="hidden"><select class="small" name="type" id="type">',QTasTag($arrT,$type),'</select></td>
<td class="hidden">',( $_SESSION[QT]['tags']=='0' ? S : '<input class="small" type="text" id="tag" name="tag" size="18" value="'.$tag.'"/>'),'</td>
<td class="hidden"><input type="hidden" name="ch" value="',implode('',$ch),'"/><input type="submit" name="ok" class="small" value="',$L['Ok'],'"/></td>
</tr>
</table>
</form>
';
}
echo '<h1>',$L['Statistics'],'</h1>',N;
// STATISTIC TABS and GRAPHIC MENUS definition
$arrTabs = array();
$arrTabs['g'] = array('tabname'=>$L['Global'],'tabdesc'=>$L['H_Global']);
$arrTabs['gt'] = array('tabname'=>$L['Global_trends'],'tabdesc'=>$L['H_Global_trends']);
$arrTabs['d'] = array('tabname'=>$L['Details'],'tabdesc'=>$L['H_Details']);
$arrTabs['dt'] = array('tabname'=>$L['Details_trends'],'tabdesc'=>$L['H_Details_trends']);
$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="'.$oVIP->selfurl.'?tt='.$tt.'&'.$strFilter.'&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="'.$oVIP->selfurl.'?tt='.$tt.'&'.$strFilter.'&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="'.$oVIP->selfurl.'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Per_d'].'</a>'; }
$arrMenuType = array(); // Chart tyle: b=bar, l=line, B=bar+variation labels, L=line+variation labels
if ( $ch['type']=='b' ) { $arrMenuType[]=$L['Chart_bar']; } else { $arr=$ch; $arr['type']='b'; $arrMenuType[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Chart_bar'].'</a>'; }
if ( $ch['type']=='l' ) { $arrMenuType[]=$L['Chart_line']; } else { $arr=$ch; $arr['type']='l'; $arrMenuType[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Chart_line'].'</a>'; }
if ( $tt=='gt' || $tt=='dt' )
{
if ( $ch['type']=='B' ) { $arrMenuType[]=$L['Chart_bar_var']; } else { $arr=$ch; $arr['type']='B'; $arrMenuType[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Chart_bar_var'].'</a>'; }
if ( $ch['type']=='L' ) { $arrMenuType[]=$L['Chart_line_var']; } else { $arr=$ch; $arr['type']='L'; $arrMenuType[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Chart_line_var'].'</a>'; }
}
$arrMenuValue = array(); // Value type: a=actual, p=percent
if ( $ch['value']=='a' ) { $arrMenuValue[]=$L['Per_a']; } else { $arr=$ch; $arr['value']='a'; $arrMenuValue[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Per_a'].'</a>'; }
if ( $ch['value']=='p' ) { $arrMenuValue[]=$L['Per_p']; } else { $arr=$ch; $arr['value']='p'; $arrMenuValue[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Per_p'].'</a>'; }
$arrMenuTrend = array(); // Trend value type: a=actual, p=percent
if ( $ch['trend']=='a' ) { $arrMenuTrend[]=$L['Per_a']; } else { $arr=$ch; $arr['trend']='a'; $arrMenuTrend[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Per_a'].'</a>'; }
if ( $ch['trend']=='p' ) { $arrMenuTrend[]=$L['Per_p']; } else { $arr=$ch; $arr['trend']='p'; $arrMenuTrend[]='<a href="'.Href().'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$arr).'" class="small">'.$L['Per_p'].'</a>'; }
echo HtmlTabs($arrTabs, $oVIP->selfurl.'?'.$strFilter.'&ch='.implode('',$ch), $tt);
echo '<table class="pan" cellspacing="0" summary="tabs">
<tr class="pan">
<td class="pan">
<div class="pan_top">',$arrTabs[$tt]['tabdesc'],'</div>
';
// Statistic computation
include('qtf_stats_inc.php');
// Table header definition
$arrHeader = array();
switch($ch['time'])
{
case 'q': for ($i=1;$i<=$intMaxBt;$i++) $arrHeader[$i]='Q'.$i; break;
case 'm': for ($i=1;$i<=$intMaxBt;$i++) $arrHeader[$i]=$L['dateMM'][$i]; break;
case 'd': for ($i=1;$i<=$intMaxBt;$i++) $arrHeader[$i]=str_replace(' ','<br/>',QTdatestr(DateAdd($strTendaysago,$i,'day'),'d M','')); break;
}
$arrHeader[$intMaxBt+1] = '<span class="bold">'.($ch['time']=='d' ? '10 '.strtolower($L['Days']) : $L['Year']).'</span>';
// DISPLAY title & option
echo '<table class="hidden" cellspacing="0">';
echo '<tr class="hidden" style="vertical-align:middle;">';
$str = $y; if ($tt=='gt' || $tt=='dt' ) $str = ($y-1).'-'.$str;
echo '<td><h2>',$str,($s>=0 ? ' '.$_SESSION[QT]['sys_sections'][$s] : ''),($type=='A' ? ' '.$L['Newss'] : ''),(empty($tag) ? '' : ', '.$L['With_tag'].' '.str_replace(';',' '.$L['or'].' ',$tag)),'</h2></td>',N;
echo '<td class="small" style="text-align:right">',implode(' · ',$arrMenuTime),'</td>';
echo '</tr></table>
';
// Display panel content
include('qtf_stats_out.php');
echo '
</td>
</tr>
</table>
';
// CSV
if ( file_exists('qtf_stats_csv.php') )
{
echo '<p style="margin:2px;text-align:right"><a class="csv" href="',Href('qtf_stats_csv.php'),'?tt='.$tt.'&'.$strFilter.'&ch='.implode('',$ch).'" title="'.$L['H_Csv'].'">',$L['Csv'],'</a></p>';
}
// HTML END
include('qtf_p_footer.php');
?>