Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_stats_gt.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;
$arrT = array();
$arrM = array();
$arrU = array();
$arrT[$intYear] = array();        $arrT[$intYear-1] = array();        
$arrM[$intYear] = array();        $arrM[$intYear-1] = array();        
$arrU[$intYear] = array();        $arrU[$intYear-1] = array();        
$arrT[$intYear][$intMaxBt+1] = 0; $arrT[$intYear-1][$intMaxBt+1] = 0; 
$arrM[$intYear][$intMaxBt+1] = 0; $arrM[$intYear-1][$intMaxBt+1] = 0; 
$arrU[$intYear][$intMaxBt+1] = 0; $arrU[$intYear-1][$intMaxBt+1] = 0; 
$arrGraphT = array();
$arrGraphM = array();
$arrGraphU = array();
foreach (array($intCurrentYear-1,$intCurrentYear) as $intYear)
{
  $arrGraphT[$intYear] = array();
  switch($bt)
  {
  case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT[$intYear]['Q'.$i]=0; $arrGraphM[$intYear]['Q'.$i]=0; $arrGraphU[$intYear]['Q'.$i]=0; } break;
  case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT[$intYear][$L['dateMMM'][$i]]=0; $arrGraphM[$intYear][$L['dateMMM'][$i]]=0; $arrGraphU[$intYear][$L['dateMMM'][$i]]=0; } break;
  case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $arrGraphT[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; $arrGraphM[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)]=0; $arrGraphU[$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 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 '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'pg':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ibase':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate FROM 1 FOR 6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'sqlit':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'acces':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ifx':   
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type="P" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrT[$intYear][$intBt] = intval($row['countid']);
  $arrT[$intYear][$intMaxBt+1] += $arrT[$intYear][$intBt]; // total
  if ( $bt=='m') $arrGraphT[$intYear][$L['dateMMM'][$intBt]] = $arrT[$intYear][$intBt];
  if ( $bt=='q') $arrGraphT[$intYear]['Q'.$intBt] = $arrT[$intYear][$intBt];
  if ( $bt=='d') $arrGraphT[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrT[$intYear][$intBt]; 
}

// COUNT REPLIES

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 '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'mssql':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'pg':    
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ibase': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate FROM 1 FOR 6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'sqlit': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'acces': 
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ifx':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABPOST.' WHERE '.$strSection.' type<>"D" AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrM[$intYear][$intBt] = intval($row['countid']);
  $arrM[$intYear][$intMaxBt+1] += $arrM[$intYear][$intBt]; // total
  if ( $bt=='m') $arrGraphM[$intYear][$L['dateMMM'][$intBt]] = $arrM[$intYear][$intBt];
  if ( $bt=='q') $arrGraphM[$intYear]['Q'.$intBt] = $arrM[$intYear][$intBt];
  if ( $bt=='d') $arrGraphM[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrM[$intYear][$intBt];  
}

// COUNT USERS

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(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'mssql': 
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)="'.($intYear*100+$intBt).'"' ); 
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'"' ); 
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' ); 
    break;
  case 'pg':    
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'ibase':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 6)="'.($intYear*100+$intBt).'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate FROM 1 FOR 6)<="'.($intYear*100+($intBt*3)).'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    break;
  case 'sqlit':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'acces':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,6)>"'.($intYear*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'ifx':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)="'.($intYear*100+$intBt).'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,6)>"'.($intYear*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($intYear*100+($intBt*3)).'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'")' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $row = $oDB->Getrow();
  $arrU[$intYear][$intBt] = intval($row['countid']);
  if ( $bt=='m') $arrGraphU[$intYear][$L['dateMMM'][$intBt]] = $arrU[$intYear][$intBt];
  if ( $bt=='q') $arrGraphU[$intYear]['Q'.$intBt] = $arrU[$intYear][$intBt];
  if ( $bt=='d') $arrGraphU[$intYear][substr(DateAdd($strTendaysago,$i,'day'),-2,2)] = $arrU[$intYear][$intBt];  
}

  // compute total

  switch(substr($oDB->type,0,5))
  {
  case 'mysql': 
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)>="'.$strTendaysago.'"' );
    break;
  case 'mssql': 
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'"' ); 
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'"' ); 
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)>="'.$strTendaysago.'"' ); 
    break;
  case 'pg':    
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,4)="'.$intYear.'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,4)="'.$intYear.'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,8)>="'.$strTendaysago.'"' );
    break;
  case 'ibase':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 4)="'.$intYear.'"' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 4)="'.$intYear.'"' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(DISTINCT userid) as countid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate FROM 1 FOR 8)>="'.$strTendaysago.'"' );
    break;
  case 'sqlit':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'acces':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' LEFT(issuedate,8)>="'.$strTendaysago.'")' );
    break;
  case 'db2':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'ifx':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTRING(issuedate,1,8)>="'.$strTendaysago.'")' );
    break;
  case 'oci':
    if ( $bt=='m') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='q') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,4)="'.$intYear.'")' );
    if ( $bt=='d') $oDB->Query( 'SELECT COUNT(*) as countid FROM (SELECT DISTINCT userid FROM '.TABPOST.' WHERE '.$strSection.' SUBSTR(issuedate,1,8)>="'.$strTendaysago.'")' );
    break;
  default: die('Unknown db type '.$oDB->type);
  }  
  $row = $oDB->Getrow();
  $arrU[$intYear][$intMaxBt+1] = intval($row['countid']);

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

// 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:85px">',$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 TOPICS

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

// DISPLAY MESSAGES

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

// DISPLAY USERS

echo '<tr class="tr_t">',N;
echo '<th class="th_o">',$L['Users'],'*</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($arrU[$intYear][$intBt]) ? $arrU[$intYear][$intBt] : '&middot;'),'</td>',N;
}
echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrU[$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:85px">',$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['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($arrT[$intCurrentYear][$intBt]) && isset($arrT[$intCurrentYear-1][$intBt]) )
  {
    $i = $arrT[$intCurrentYear][$intBt]-$arrT[$intCurrentYear-1][$intBt];
    if ( $tr=='p' && $i!=0 )
    {
      if ( $arrT[$intCurrentYear-1][$intBt]==0 ) $arrT[$intCurrentYear-1][$intBt]=1;
      $i = intval(($i/$arrT[$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($arrT[$intCurrentYear][$intMaxBt+1]) && isset($arrT[$intCurrentYear-1][$intMaxBt+1]) )
{
  $i = $arrT[$intCurrentYear][$intMaxBt+1]-$arrT[$intCurrentYear-1][$intMaxBt+1];
  if ( $tr=='p' && $i!=0 )
  {
    if ( $arrT[$intCurrentYear-1][$intMaxBt+1]==0 ) $arrT[$intCurrentYear-1][$intMaxBt+1]=1;
    $i = intval(($i/$arrT[$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['Messages'],'</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($arrM[$intCurrentYear][$intBt]) && isset($arrM[$intCurrentYear-1][$intBt]) )
  {
    $i = $arrM[$intCurrentYear][$intBt]-$arrM[$intCurrentYear-1][$intBt];
    if ( $tr=='p' && $i!=0 )
    {
      if ( $arrM[$intCurrentYear-1][$intBt]==0 ) $arrM[$intCurrentYear-1][$intBt]=1;
      $i = intval(($i/$arrM[$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($arrM[$intCurrentYear][$intMaxBt+1]) && isset($arrM[$intCurrentYear-1][$intMaxBt+1]) )
{
  $i = $arrM[$intCurrentYear][$intMaxBt+1]-$arrM[$intCurrentYear-1][$intMaxBt+1];
  if ( $tr=='p' && $i!=0 )
  {
    if ( $arrM[$intCurrentYear-1][$intMaxBt+1]==0 ) $arrM[$intCurrentYear-1][$intMaxBt+1]=1;
    $i = intval(($i/$arrM[$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 users

echo '<tr class="tr_t">',N;
echo '<th class="th_o">',$L['Users'],'*</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++) 
{
  $i = 0;
  if ( isset($arrU[$intCurrentYear][$intBt]) && isset($arrU[$intCurrentYear-1][$intBt]) )
  {
    $i = $arrU[$intCurrentYear][$intBt]-$arrU[$intCurrentYear-1][$intBt];
    if ( $tr=='p' && $i!=0 )
    {
      if ( $arrU[$intCurrentYear-1][$intBt]==0 ) $arrU[$intCurrentYear-1][$intBt]=1;
      $i = intval(($i/$arrU[$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($arrU[$intCurrentYear][$intMaxBt+1]) && isset($arrU[$intCurrentYear-1][$intMaxBt+1]) )
{
  $i = $arrU[$intCurrentYear][$intMaxBt+1]-$arrU[$intCurrentYear-1][$intMaxBt+1];
  if ( $tr=='p' && $i!=0 )
  {
    if ( $arrU[$intCurrentYear-1][$intMaxBt+1]==0 ) $arrU[$intCurrentYear-1][$intMaxBt+1]=1;
    $i = intval(($i/$arrU[$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>';

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

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

  // TOPIC second serie

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

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

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

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

  // MESSAGE second serie

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

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

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

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

  // USER second serie

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

  echo '</td>',N;
  echo '</tr></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>';
}

// LEGEND

echo '<p>*  <span class="small">',$L['Distinct_users'],'</span></p>
';

?>
Return current item: QuickTicket