Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_stats_d.php
<?php

// DETAIL STATISTICS

switch($bt)
{
case 'q': $intMaxBt=4; break;
case 'd': $intMaxBt=10; break;
case 'm': $intMaxBt=12; break;
default: die('Invalid blocktime');
}

// Initialise array values. When a value is missing the display will show &middot;

$arrT = array();
$arrN = array();
$arrC = array();
$arrT[$intMaxBt+1] = 0;
$arrN[$intMaxBt+1] = 0;
$arrC[$intMaxBt+1] = 0;

$arrGraphT = array();
$arrGraphN = array();
$arrGraphC = array();
switch($bt)
{
case 'q': $intMaxBt=4; for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT['Q'.$i]=0; $arrGraphN['Q'.$i]=0; $arrGraphC['Q'.$i]=0; } break;
case 'm': $intMaxBt=12; for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT[$L['dateMMM'][$i]]=0; $arrGraphN[$L['dateMMM'][$i]]=0; $arrGraphC[$L['dateMMM'][$i]]=0; } break;
case 'd': $intMaxBt=10; for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT[substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; $arrGraphN[substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; $arrGraphC[substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; } break;
}

// Display title & option

echo '<table class="ta_hidden" cellspacing="0">';
echo '<tr class="tr_hidden" style="vertical-align:middle;">';
echo '<td class="td_hidden"><h2>',$intYear,S,($s>=0 ? '('.$arrSections[$s].')' : ''),'</h2></td>',N;
if ( !isset($bToPrint) ) echo '<td class="td_hidden small" style="text-align:right">',implode(' &middot; ',$arrTimeblocks),'</td>';
echo '</tr></table>
';

// Display table header
echo '<table class="ta ta_t" cellspacing="0">
<tr class="tr_t">
<th class="th_o" style="width:100px">&nbsp;</th>
<th class="th_o" style="width:14px">&nbsp;</th>
';
switch($bt)
{
case 'q': for ($i=1;$i<=$intMaxBt;$i++) { echo '<th class="th_o" style="text-align:center;">Q',$i,'</th>'; } break;
case 'm': for ($i=1;$i<=$intMaxBt;$i++) { echo '<th class="th_o" style="text-align:center;">',$L['dateMM'][$i],'</th>'; } break;
case 'd': for ($i=1;$i<=$intMaxBt;$i++) { echo '<th class="th_o" style="text-align:center;">',str_replace(' ','<br/>',QTdate(DateAdd($strTendaysago,$i,'day'),array('n','date','d M'))),'</th>'; } break;
}
echo '<th class="th_o" style="text-align:center;"><b>',($bt=='d' ? '10 days' : $L['Year']),'</b></th>
</tr>';

// COUNT NEW TOPIC

for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
  // check limits (startdate/enddate)

  if ( $intYear<$intStartyear ) continue;
  if ( $intYear==$intStartyear )
  {
    if ( $bt=='m' ) {
    if ( $intBt<$intStartmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
    continue;
    }}
  }
  if ( $intYear>=$intEndyear ) 
  {
    if ( $bt=='m' ) {
    if ( $intBt>$intEndmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
    continue;
    }}
  }

  // compute per blocktime

  switch(substr($oDB->type,0,5))
  {
  case 'mysql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(firstpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(firstpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'pg':    
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(firstpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ibase': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate FROM 1 FOR 6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(firstpostdate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'sqlit':                                                             
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(firstpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'acces': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(firstpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(firstpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ifx':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(firstpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTRING(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(firstpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrN[$intBt] = intval($row['countid']);
  $arrN[$intMaxBt+1] += $arrN[$intBt];
  if ( $bt=='m') $arrGraphN[$L['dateMMM'][$intBt]] = $arrN[$intBt];
  if ( $bt=='q') $arrGraphN['Q'.$intBt] = $arrN[$intBt];
  if ( $bt=='d') $arrGraphN[substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrN[$intBt]; 
}

// DISPLAY NEW TOPIC

echo '<tr class="tr_t">',N;
echo '<th class="th_o">',$L['New_topics'],'</th>',N;
echo '<th class="th_o"><div style="margin:0 auto;background-color:#000066;width:8px;height:10px">&nbsp;</div></th>',N;
for ($intBt=1;$intBt<=$intMaxBt;$intBt++) 
{
  echo '<td class="td_o" style="text-align:center;">',(isset($arrN[$intBt]) ? $arrN[$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrN[$intMaxBt+1],'</b></td></tr>',N;

// COUNT CLOSED TOPICS

for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
  // check limits (startdate/enddate)

  if ( $intYear<$intStartyear ) continue;
  if ( $intYear==$intStartyear )
  {
    if ( $bt=='m' ) {
    if ( $intBt<$intStartmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
    continue;
    }}
  }
  if ( $intYear>=$intEndyear ) 
  {
    if ( $bt=='m' ) {
    if ( $intBt>$intEndmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
    continue;
    }}
  }

  // compute per blocktime

  switch(substr($oDB->type,0,5))
  {
  case 'mysql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(lastpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(lastpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'pg':    
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ibase': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate FROM 1 FOR 6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'sqlit':                                                             
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'acces': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(lastpostdate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ifx':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTRING(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' status="Z" AND SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrC[$intBt] = intval($row['countid']);
  $arrC[$intMaxBt+1] += $arrC[$intBt];
  if ( $bt=='m') $arrGraphC[$L['dateMMM'][$intBt]] = $arrC[$intBt];
  if ( $bt=='q') $arrGraphC['Q'.$intBt] = $arrC[$intBt];
  if ( $bt=='d') $arrGraphC[substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrC[$intBt]; 
}

// DISPLAY CLOSED TOPICS

echo '<tr class="tr_t">',N;
echo '<th class="th_o">',$L['Closed_topics'],'</th>',N;
echo '<th class="th_o"><div style="margin:0 auto;background-color:#990099;width:8px;height:10px">&nbsp;</div></th>',N;
for ($intBt=1;$intBt<=$intMaxBt;$intBt++) 
{
  echo '<td class="td_o" style="text-align:center;">',(isset($arrC[$intBt]) ? $arrC[$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrC[$intMaxBt+1],'</b></td></tr>',N;

// COUNT BACKLOG

for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
{
  // check limits (startdate/enddate)

  if ( $intYear<$intStartyear ) continue;
  if ( $intYear==$intStartyear )
  {
    if ( $bt=='m' ) {
    if ( $intBt<$intStartmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
    continue;
    }}
  }
  if ( $intYear>=$intEndyear ) 
  {
    if ( $bt=='m' ) {
    if ( $intBt>$intEndmonth ) {
    continue;
    }}
    if ( $bt=='q' ) {
    if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<8) || ($intBt==4 && $intEndmonth<12) ) {
    continue;
    }}
  }

  // compute per blocktime

  switch(substr($oDB->type,0,5))
  {
  case 'mysql': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'" OR LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(lastpostdate,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'" OR LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(lastpostdate,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'pg':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,6)="'.($intYear*100+$intBt).'" OR SUBSTRING(lastpostdate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTRING(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'ibase':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 6)="'.($intYear*100+$intBt).'" OR SUBSTRING(lastpostdate FROM 1 FOR 6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTRING(lastpostdate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'sqlit':                                                                                      
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'" OR SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'acces':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)="'.($intYear*100+$intBt).'" OR LEFT(lastpostdate,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(firstpostdate,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR LEFT(lastpostdate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'" OR SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'ifx':   
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,6)="'.($intYear*100+$intBt).'" OR SUBSTRING(lastpostdate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTRING(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)="'.($intYear*100+$intBt).'" OR SUBSTR(lastpostdate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(lastpostdate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'" OR SUBSTR(lastpostdate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrT[$intBt] = intval($row['countid']);
  if ( $bt=='m') $arrGraphT[$L['dateMMM'][$intBt]] = $arrT[$intBt];
  if ( $bt=='q') $arrGraphT['Q'.$intBt] = $arrT[$intBt];
  if ( $bt=='d') $arrGraphT[substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrT[$intBt]; 
}

  // count total
  
  switch(substr($oDB->type,0,5))
  {
  case 'mysql': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)>="'.$strTendaysago.'" OR LEFT(lastpostdate,8)>="'.$strTendaysago.'")' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)>="'.$strTendaysago.'" OR LEFT(lastpostdate,8)>="'.$strTendaysago.'")' );
    break;
  case 'pg':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,4)="'.$intYear.'" OR SUBSTRING(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,4)="'.$intYear.'" OR SUBSTRING(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,8)>="'.$strTendaysago.'" OR SUBSTRING(lastpostdate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'ibase':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 4)="'.$intYear.'" OR SUBSTRING(lastpostdate FROM 1 FOR 4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 4)="'.$intYear.'" OR SUBSTRING(lastpostdate FROM 1 FOR 4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate FROM 1 FOR 8)>="'.$strTendaysago.'" OR SUBSTRING(lastpostdate FROM 1 FOR 8)>="'.$strTendaysago.'")' );
    break;
  case 'sqlit':                                                                                      
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)>="'.$strTendaysago.'" OR SUBSTR(lastpostdate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'acces':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,4)="'.$intYear.'" OR LEFT(lastpostdate,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (LEFT(firstpostdate,8)>="'.$strTendaysago.'" OR LEFT(lastpostdate,8)>="'.$strTendaysago.'")' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)>="'.$strTendaysago.'" OR SUBSTR(lastpostdate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'ifx':   
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,4)="'.$intYear.'" OR SUBSTRING(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,4)="'.$intYear.'" OR SUBSTRING(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTRING(firstpostdate,1,8)>="'.$strTendaysago.'" OR SUBSTRING(lastpostdate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,4)="'.$intYear.'" OR SUBSTR(lastpostdate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE '.$strSection.' (SUBSTR(firstpostdate,1,8)>="'.$strTendaysago.'" OR SUBSTR(lastpostdate,1,8)>="'.$strTendaysago.'")' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrT[$intMaxBt+1] = intval($row['countid']);

// DISPLAY BACKLOG

echo '<tr class="tr_t">',N;
echo '<th class="th_o">',$L['Backlog'],'</th>',N;
echo '<th class="th_o"><div style="margin:0 auto;background-color:#009999;width:8px;height:10px">&nbsp;</div></th>',N;
for ($intBt=1;$intBt<=$intMaxBt;$intBt++) 
{
  echo '<td class="td_o" style="text-align:center;">',(isset($arrT[$intBt]) ? $arrT[$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrT[$intMaxBt+1],'</b></td></tr>',N;

echo '</table>
';


// GRAPH

if ( file_exists('bin/qt_lib_graph.php') && file_exists($_SESSION[QT]['skin_dir'].'/qti_graph.css') )
{
  include('bin/qt_lib_graph.php');
    
  $arr = array();
  $arr[] = ($gr=='a' ? $L['Per_a'] : '<a href="'.$oVIP->selfurl.'?s='.$s.'&year='.$intYear.'&tt='.$tt.'&bt='.$bt.'&gr=a" class="small">'.$L['Per_a'].'</a>');
  $arr[] = ($gr=='p' ? $L['Per_p'] : '<a href="'.$oVIP->selfurl.'?s='.$s.'&year='.$intYear.'&tt='.$tt.'&bt='.$bt.'&gr=p" class="small">'.$L['Per_p'].'</a>');

  if ( !isset($bToPrint) ) echo '<p class="small" style="text-align:right">',implode(' &middot; ',$arr),'</p>';
  
  echo '<table class="ta ta_t" cellspacing="0">',N;

  echo '<tr class="tr_t">',N;
  echo '<td class="td_o" style="width:355px">',N;

  $intTopValue = 5; $i = max($arrGraphN);
  if ( $i>5 ) $intTopValue = 10;
  if ( $i>10 ) $intTopValue = 20;
  if ( $i>20 ) $intTopValue = 30;
  if ( $i>30 ) $intTopValue = 50;
  if ( $i>50 ) $intTopValue = $i;

  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphN,false,320,100,$intTopValue,2,true,$L['New_topics']);
  }
  else
  {
  QTsimplegraph($arrGraphN,false,350,100,$intTopValue,2,'P',$L['New_topics'].' (%)');
  }

  echo '</td>',N;  
  echo '<td class="td_o">&nbsp;</td>',N;
  echo '<td class="td_o" style="width:355px">',N;

  $intTopValue = 5; $i = max($arrGraphC);
  if ( $i>5 ) $intTopValue = 10;
  if ( $i>10 ) $intTopValue = 20;
  if ( $i>20 ) $intTopValue = 30;
  if ( $i>30 ) $intTopValue = 50;
  if ( $i>50 ) $intTopValue = $i;
  
  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphC,false,320,100,$intTopValue,2,true,$L['Closed_topics'],'','2');
  }
  else
  {
  QTsimplegraph($arrGraphC,false,350,100,$intTopValue,2,'P',$L['Closed_topics'].' (%)','','2');
  }

  echo '</td>',N;
  echo '</tr>',N;  

  echo '<tr class="tr_t">',N;
  echo '<td class="td_o" style="width:355px">',N;
  
  $intTopValue = 5; $i = max($arrGraphT);
  if ( $i>5 ) $intTopValue = 10;
  if ( $i>10 ) $intTopValue = 20;
  if ( $i>20 ) $intTopValue = 30;
  if ( $i>30 ) $intTopValue = 50;
  if ( $i>50 ) $intTopValue = $i;

  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphT,false,320,100,$intTopValue,2,true,$L['Backlog'],'','3');
  }
  else
  {
  QTsimplegraph($arrGraphT,false,350,100,$intTopValue,2,'P',$L['Backlog'].' (%)','','3');
  }
  
  echo '</td>',N;
  echo '<td class="td_o">&nbsp;</td>',N;
  echo '<td class="td_o" style="width:355px">',N;

  $intTopValue = 5; $i = array_sum($arrGraphT);
  if ( $i>5 ) $intTopValue = 10;
  if ( $i>10 ) $intTopValue = 20;
  if ( $i>20 ) $intTopValue = 30;
  if ( $i>30 ) $intTopValue = 50;
  if ( $i>50 ) $intTopValue = $i;
  
  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphT,true,320,100,$intTopValue,2,true,$L['Backlog_cumul'],'','3');
  }
  else
  {
  QTsimplegraph($arrGraphT,true,350,100,$intTopValue,2,'P',$L['Backlog_cumul'].' (%)','','3');
  }
  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, ',$_SESSION[QT]['skin_dir'].'/qti_graph.css</p>';
}

?>
Return current item: QuickTicket