Location: PHPKode > projects > QuickTicket > quickticket/qti_stats_prt.php
<?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    QuickTicket
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.3 build:20091102
*/

session_start();
require_once('bin/qti_init.php');
if ( !$oVIP->CanView('V4') ) HtmlPage(11);
$oVIP->output='print';
include(Translate('qti_stat.php'));

// --------
// INITIALISE
// --------

$oVIP->selfurl = 'qti_stats.php';
$oVIP->selfname = $L['Statistics'];

$s = -1;   // section filter
$y = date('Y'); if ( intval(date('n'))<2 ) $y--; // year filter
$tag = ''; // tags filter
$tt = 'g'; // tab: g=global, gt=globaltrend, d=detail, dt=detailtrend
$ch = array('m','b','a','a'); // chart parameters
// [0] blocktime: m=month, q=quarter, d=10days 
// [1] graph type: b=bar, l=line, B=bar+variation, L=line+variation
// [2] graphics reals: a=actual, p=percent
// [3] trends reals: a=actual, p=percent

// --------
// SUBMITTED
// --------
  
if ( isset($_GET['y']) ) $y = intval($_GET['y']);
if ( isset($_GET['s']) ) $s = intval($_GET['s']);
if ( $s>=0 ) { $strSection = 'forum='.$s.' AND'; } else { $strSection=''; }
if ( isset($_GET['tag']) ) $tag = strip_tags($_GET['tag']);
  $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['tt']) ) $tt = strip_tags($_GET['tt']);
if ( isset($_GET['ch']) )
{
  $str = strip_tags($_GET['ch']);
  if ( str_len($str)>0 ) $ch['time'] = substr($str,0,1); // blocktime
  if ( str_len($str)>1 ) $ch['type'] = substr($str,1,1); // graph type
  if ( str_len($str)>2 ) $ch['value'] = substr($str,2,1); // value type
  if ( str_len($str)>3 ) $ch['trend'] = substr($str,3,1); // trends value 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 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';
$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
// --------

$bJava = false;

include('qti_p_header.php');

$iTotalPost = 0;

echo '
<table class="hidden" cellspacing="0">
<tr class="hidden">
<td class="hidden"><h1>',$L['Statistics'],'</h1></td>
<td class="hidden">&nbsp;</td>
</tr>
</table>
';

// --------
// STATISTIC TABS
// --------

$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[0]='q'; $arrMenuTime[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_q'].'</a>'; }
if ( $ch['time']=='m' ) { $arrMenuTime[]=$L['Per_m']; } else { $arr=$ch; $arr[0]='m'; $arrMenuTime[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_m'].'</a>'; }
if ( $ch['time']=='d' ) { $arrMenuTime[]=$L['Per_d']; } else { $arr=$ch; $arr[0]='d'; $arrMenuTime[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.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[]='Bar'; }  else { $arr=$ch; $arr[1]='b'; $arrMenuType[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.$strFilter.'&amp;ch='.implode('',$arr).'" class="small">'.$L['Chart_bar'].'</a>'; }
if ( $ch['type']=='l' ) { $arrMenuType[]='Line'; } else { $arr=$ch; $arr[1]='l'; $arrMenuType[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.$strFilter.'&amp;ch='.implode('',$arr).'" class="small">'.$L['Chart_line'].'</a>'; }
if ( $tt=='gt' || $tt=='gt' )
{
if ( $ch['type']=='B' ) { $arrMenuType[]='Bar with variations'; }  else { $arr=$ch; $arr[1]='B'; $arrMenuType[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.$strFilter.'&amp;ch='.implode('',$arr).'" class="small">'.$L['Chart_bar_var'].'</a>'; }
if ( $ch['type']=='L' ) { $arrMenuType[]='Line with variations'; } else { $arr=$ch; $arr[1]='L'; $arrMenuType[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.$strFilter.'&amp;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[1]='b'; $arrMenuValue[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_a'].'</a>'; }
if ( $ch['value']=='p' ) { $arrMenuValue[]=$L['Per_p']; } else { $arr=$ch; $arr[1]='l'; $arrMenuValue[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_p'].'</a>'; }

$arrMenuTrend = array(); // Trend value type: a=actual, p=percent
if ( $ch['value']=='a' ) { $arrMenuTrend[]=$L['Per_a']; }  else { $arr=$ch; $arr[1]='b'; $arrMenuTrend[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_a'].'</a>'; }
if ( $ch['value']=='p' ) { $arrMenuTrend[]=$L['Per_p']; } else { $arr=$ch; $arr[1]='l'; $arrMenuTrend[]='<a href="'.$oVIP->selfurl.'?tt='.$tt.'&amp;'.implode('',$arr).'" class="small">'.$L['Per_p'].'</a>'; }

echo '<table class="pan" cellspacing="0">
<tr class="pan">
<td class="pan">
<div class="pan_top">',$arrTabs[$tt]['tabdesc'],'</div>
';

switch($tt)
{
case 'g': include('qti_stats_g.php'); break;
case 'gt': include('qti_stats_gt.php'); break;
case 'd': include('qti_stats_d.php'); break;
case 'dt': include('qti_stats_dt.php'); break;
default: die('Invalid tab');
}

echo '
</td>
</tr>
</table>
';

// HTML END

include('qti_p_footer.php');

?>
Return current item: QuickTicket