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

// GLOBAL 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;

$intCurrentYear = $intYear;
$strCurrentTendaysago = $strTendaysago;
$arrN = array();
$arrC = array();
$arrN[$intYear] = array();        $arrN[$intYear-1] = array();
$arrC[$intYear] = array();        $arrC[$intYear-1] = array();
$arrN[$intYear][$intMaxBt+1] = 0; $arrN[$intYear-1][$intMaxBt+1] = 0;
$arrC[$intYear][$intMaxBt+1] = 0; $arrC[$intYear-1][$intMaxBt+1] = 0;
$arrGraphN = array();
$arrGraphC = array();
foreach (array($intCurrentYear-1,$intCurrentYear) as $intYear)
{
  $arrGraphN[$intYear] = array();
  $arrGraphC[$intYear] = array();
  switch($bt)
  {
  case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphN[$intYear]['Q'.$i]=0; $arrGraphC[$intYear]['Q'.$i]=0; } break;
  case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphN[$intYear][$L['dateMMM'][$i]]=0; $arrGraphC[$intYear][$L['dateMMM'][$i]]=0; } break;
  case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphN[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; $arrGraphC[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; } break;
  }
}

// COUNT

// -----
foreach (array($intCurrentYear-1,$intCurrentYear) 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 ( $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[$intYear][$intBt] = intval($row['countid']);
  $arrN[$intYear][$intMaxBt+1] += $arrN[$intYear][$intBt]; // total
  if ( $bt=='m') $arrGraphN[$intYear][$L['dateMMM'][$intBt]] = $arrN[$intYear][$intBt];
  if ( $bt=='q') $arrGraphN[$intYear]['Q'.$intBt] = $arrN[$intYear][$intBt];
  if ( $bt=='d') $arrGraphN[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrN[$intYear][$intBt]; 
}

// 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[$intYear][$intBt] = intval($row['countid']);
  $arrC[$intYear][$intMaxBt+1] += $arrC[$intYear][$intBt]; // total
  if ( $bt=='m') $arrGraphC[$intYear][$L['dateMMM'][$intBt]] = $arrC[$intYear][$intBt];
  if ( $bt=='q') $arrGraphC[$intYear]['Q'.$intBt] = $arrC[$intYear][$intBt];
  if ( $bt=='d') $arrGraphC[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrC[$intYear][$intBt]; 
}

// -----
}
// -----

// 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-1,' - ',$intYear,' ',($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 VALUES

// -----
foreach (array($intCurrentYear-1,$intCurrentYear) as $intYear) {
// -----

// Display table header

echo '<table class="ta ta_t" cellspacing="0">
<tr class="tr_t">
<th class="th_o" style="width:100px">',$intYear,'</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>';

// DISPLAY NEW TOPICS

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[$intYear][$intBt]) ? $arrN[$intYear][$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrN[$intYear][$intMaxBt+1],'</b></td></tr>',N;

// 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[$intYear][$intBt]) ? $arrC[$intYear][$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrC[$intYear][$intMaxBt+1],'</b></td></tr>',N;

echo '</table>
';

// -----
}
// -----

// DISPLAY TRENDS

// Display table header

if ( !isset($bToPrint) ) echo '<p class="small" style="text-align:right">',implode(' &middot; ',$arrTrendtypes),'</p>';

echo '<table class="ta ta_t" cellspacing="0">
<tr class="tr_t">
<th class="th_o" style="width:100px">',$L['Trends'],'</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>';

// Display topics trends

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++) 
{
  $i = 0;
  if ( isset($arrN[$intCurrentYear][$intBt]) && isset($arrN[$intCurrentYear-1][$intBt]) )
  {
    $i = $arrN[$intCurrentYear][$intBt]-$arrN[$intCurrentYear-1][$intBt];
    if ( $tr=='p' && $i!=0 )
    {
      if ( $arrN[$intCurrentYear-1][$intBt]==0 ) $arrN[$intCurrentYear-1][$intBt]=1;
      $i = intval(($i/$arrN[$intCurrentYear-1][$intBt])*100);
    }
  }
  if ( $i>0 ) $str = '<span style="color:red">+'.$i.($tr=='p' ? '%' : '').'</span>';
  if ( $i<0 ) $str = '<span style="color:green">'.$i.($tr=='p' ? '%' : '').'</span>';
  if ( $i==0 ) $str = '&middot;';
  echo '<td class="td_o" style="text-align:center;">',$str,'</td>',N;
}
$i = 0;
if ( isset($arrN[$intCurrentYear][$intMaxBt+1]) && isset($arrN[$intCurrentYear-1][$intMaxBt+1]) )
{
  $i = $arrN[$intCurrentYear][$intMaxBt+1]-$arrN[$intCurrentYear-1][$intMaxBt+1];
  if ( $tr=='p' && $i!=0 )
  {
    if ( $arrN[$intCurrentYear-1][$intMaxBt+1]==0 ) $arrN[$intCurrentYear-1][$intMaxBt+1]=1;
    $i = intval(($i/$arrN[$intCurrentYear-1][$intMaxBt+1])*100);
  }
}
if ( $i>0 ) $str = '<span style="color:red">+'.$i.($tr=='p' ? '%' : '').'</span>';
if ( $i<0 ) $str = '<span style="color:green">'.$i.($tr=='p' ? '%' : '').'</span>';
if ( $i==0 )  $str = '&middot;';
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$str,'</b></td></tr>',N;

// Display messages

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++) 
{
  $i = 0;
  if ( isset($arrC[$intCurrentYear][$intBt]) && isset($arrC[$intCurrentYear-1][$intBt]) )
  {
    $i = $arrC[$intCurrentYear][$intBt]-$arrC[$intCurrentYear-1][$intBt];
    if ( $tr=='p' && $i!=0 )
    {
      if ( $arrC[$intCurrentYear-1][$intBt]==0 ) $arrC[$intCurrentYear-1][$intBt]=1;
      $i = intval(($i/$arrC[$intCurrentYear-1][$intBt])*100);
    }
  }
  if ( $i>0 ) $str = '<span style="color:red">+'.$i.($tr=='p' ? '%' : '').'</span>';
  if ( $i<0 ) $str = '<span style="color:green">'.$i.($tr=='p' ? '%' : '').'</span>';
  if ( $i==0 ) $str = '&middot;';
  echo '<td class="td_o" style="text-align:center;">',$str,'</td>',N;
}
$i = 0;
if ( isset($arrC[$intCurrentYear][$intMaxBt+1]) && isset($arrC[$intCurrentYear-1][$intMaxBt+1]) )
{
  $i = $arrC[$intCurrentYear][$intMaxBt+1]-$arrC[$intCurrentYear-1][$intMaxBt+1];
  if ( $tr=='p' && $i!=0 )
  {
    if ( $arrC[$intCurrentYear-1][$intMaxBt+1]==0 ) $arrC[$intCurrentYear-1][$intMaxBt+1]=1;
    $i = intval(($i/$arrC[$intCurrentYear-1][$intMaxBt+1])*100);
  }
}
if ( $i>0 ) $str = '<span style="color:red">+'.$i.($tr=='p' ? '%' : '').'</span>';
if ( $i<0 ) $str = '<span style="color:green">'.$i.($tr=='p' ? '%' : '').'</span>';
if ( $i==0 ) $str = '&middot;';
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$str,'</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.'&tr='.$tr.'&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.'&tr='.$tr.'&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;

  // first serie
  
  $intYear = $intCurrentYear-1;
  $intTopValue = 5; $i = max(max($arrGraphN[$intYear]),max($arrGraphN[$intCurrentYear]));
  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;
  
  echo '<tr class="tr_t">',N;
  echo '<td class="td_o" style="width:355px">',N;
  
  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphN[$intYear],false,320,100,$intTopValue,2,true,$L['New_topics'].' '.$intYear);
  }
  else
  {
  QTsimplegraph($arrGraphN[$intYear],false,350,100,$intTopValue,2,'P',$L['New_topics'].' (%) '.$intYear);
  }

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

  // second serie

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

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

  // 3d serie
  
  $intYear = $intCurrentYear-1;
  $intTopValue = 5; $i = max(max($arrGraphC[$intYear]),max($arrGraphC[$intCurrentYear]));
  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;
  
  echo '<tr class="tr_t">',N;
  echo '<td class="td_o" style="width:355px">',N;
  
  if ( $gr=='a' ) 
  {
  QTsimplegraph($arrGraphC[$intYear],false,320,100,$intTopValue,2,true,$L['Closed_topics'].' '.$intYear,'','2');
  }
  else
  {
  QTsimplegraph($arrGraphC[$intYear],false,350,100,$intTopValue,2,'P',$L['Closed_topics'].' (%) '.$intYear,'','2');
  }

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

  // 4th serie

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

  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