<?php
// QT-registrations 2.4 build:20100313
// GLOBAL STATISTICS included in:
// qtr_stats_{g|d|gt|dt|n}.php and
// qtr_stats_{g|d|gt|dt|n}_{csv|pdf}.php
include('bin/qt_lib_graph.php');
// Initialise array values. When a value is missing the display will show ·
if ( !isset($intStartyear) )
{
$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'));
}
switch($ch['time'])
{
case 'q': $intMaxBt=4; break;
case 'm': $intMaxBt=12; break;
case 'd': $intMaxBt=10; break;
default: die('Invalid blocktime');
}
$intCurrentYear = $y;
$strCurrentTendaysago = $strTendaysago;
$arrA = array(); // Abscise
$arrN = array(); $arrNs = array();
$arrC = array(); $arrCs = array();
$arrT = array(); $arrTs = array();
foreach($arrYears as $intYear)
{
$arrN[$intYear] = array();
$arrC[$intYear] = array();
$arrT[$intYear] = array();
switch($ch['time'])
{
case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]='Q'.$i; $arrT[$intYear][$i]=null; $arrN[$intYear][$i]=null; $arrC[$intYear][$i]=null; } break;
case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]=$L['dateMM'][$i]; $arrT[$intYear][$i]=null; $arrN[$intYear][$i]=null; $arrC[$intYear][$i]=null; } break;
case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]=substr(DateAdd($strTendaysago,$i,'day'),-2,2); $arrT[$intYear][$i]=null; $arrN[$intYear][$i]=null; $arrC[$intYear][$i]=null; } break;
}
$arrNs[$intYear] = 0;
$arrCs[$intYear] = 0;
$arrTs[$intYear] = 0;
}
// -----
foreach($arrYears as $intYear) {
// -----
if ( $intCurrentYear==$intYear ) { $strTendaysago = $strCurrentTendaysago; } else { $strTendaysago = DateAdd(substr($strTendaysago,0,8),-1,'year'); }
// COUNT NEW TOPICS
for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
// check limits (startdate/enddate)
if ( $intYear<$intStartyear ) continue;
if ( $intYear==$intStartyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt<$intStartmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
continue;
}}
}
if ( $intYear>=$intEndyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt>$intEndmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
continue;
}}
}
// compute per blocktime
if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.SqlDateCondition(($intYear*100+$intBt),'firstpostdate',6) );
if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.SqlDateCondition(($intYear*100+($intBt-1)*3),'firstpostdate',6,'>').' AND '.SqlDateCondition(($intYear*100+($intBt*3)),'firstpostdate',6,'<=') );
if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.SqlDateCondition((DateAdd($strTendaysago,$intBt,'day')),'firstpostdate',8) );
$row = $oDB->Getrow();
$arrN[$intYear][$intBt] = intval($row['countid']);
$arrNs[$intYear] += $arrN[$intYear][$intBt]; // total
}
// COUNT CLOSED TOPICS
for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
// check limits (startdate/enddate)
if ( $intYear<$intStartyear ) continue;
if ( $intYear==$intStartyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt<$intStartmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
continue;
}}
}
if ( $intYear>=$intEndyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt>$intEndmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
continue;
}}
}
// compute per blocktime
if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.' status="Z" AND '.SqlDateCondition(($intYear*100+$intBt),'statusdate',6) );
if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.' status="Z" AND '.SqlDateCondition(($intYear*100+($intBt-1)*3),'statusdate',6,'>').' AND '.SqlDateCondition(($intYear*100+($intBt*3)),'statusdate',6,'<=') );
if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.$strTags.$strType.' status="Z" AND '.SqlDateCondition((DateAdd($strTendaysago,$intBt,'day')),'statusdate',8) );
$row = $oDB->Getrow();
$arrC[$intYear][$intBt] = intval($row['countid']);
$arrCs[$intYear] += $arrC[$intYear][$intBt]; // total
}
// COUNT BACKLOG
for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
// check limits (startdate/enddate)
if ( $intYear<$intStartyear ) continue;
if ( $intYear==$intStartyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt<$intStartmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
continue;
}}
}
if ( $intYear>=$intEndyear )
{
if ( $ch['time']=='m' ) {
if ( $intBt>$intEndmonth ) {
continue;
}}
if ( $ch['time']=='q' ) {
if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
continue;
}}
}
// compute per blocktime
if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition(($intYear*100+$intBt),'firstpostdate',6).' OR '.SqlDateCondition(($intYear*100+$intBt),'lastpostdate',6).')' );
if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition(($intYear*100+($intBt-1)*3),'firstpostdate',6,'>').' AND '.SqlDateCondition(($intYear*100+($intBt*3)),'lastpostdate',6,'<=').')' );
if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition((DateAdd($strTendaysago,$intBt,'day')),'firstpostdate',8).' OR '.SqlDateCondition((DateAdd($strTendaysago,$intBt,'day')),'lastpostdate',8).')' );
$row = $oDB->Getrow();
$arrT[$intYear][$intBt] = intval($row['countid']);
}
// count total
if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition($intYear,'firstpostdate',4).' OR '.SqlDateCondition($intYear,'lastpostdate',4).')' );
if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition($intYear,'firstpostdate',4).' OR '.SqlDateCondition($intYear,'lastpostdate',4).')' );
if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.'('.SqlDateCondition($strTendaysago,'firstpostdate',8).' OR '.SqlDateCondition($strTendaysago,'lastpostdate',8).')' );
$row = $oDB->Getrow();
$arrTs[$intYear] = intval($row['countid']);
// -----
}
// -----
?>