Location: PHPKode > projects > Quick Guestbook > quicktalk/qtg_adm_stat_inc.php
<?php

// QuickTalk guestbook 2.5 build:20100731

// GLOBAL STATISTICS included in qtg_stats and qtg_stats_prt

include('bin/qt_lib_graph.php');

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

$intTotalPost = 0;
if ( is_a($oDB,'cDT') )
{  
  $intTotalPost = $oDB->FilesCount('',0,date('Ym'),'0',true); // this uses GetFiles(), thus $oDT->arrFiles is created!
}
else
{
  $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0' );
  $row = $oDB->Getrow();
  $intTotalPost = intval($row['countid']);
}
$intHiddenPost = 0;
$strFirstdate = '';
$strLastdate ='';
$intStartyear = 0;
$intStartmonth = 0;
$intEndyear = 0;
$intEndmonth = 0;
$strLastdaysago = date('Ymd');
$strTendaysago = DateAdd($strLastdaysago,-10,'day');

if ($intTotalPost>0)
{
  if ( is_a($oDB,'cDT') )
  {  
    $intHiddenPost = $oDB->FilesCount('n',0,date('Ym')); // this uses GetFiles(), thus $oDT->arrFiles is created!
    // firstdate and lastdate are genarated during FilesCount()
    $row = array();
    $row['firstdate'] = substr($oDB->firstfile,0,8).substr($oDB->firstfile,9,6);
    $row['lastdate'] = substr($oDB->lastfile,0,8).substr($oDB->lastfile,9,6);
  }
  else
  {
    $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND visible="N"' );
    $row = $oDB->Getrow();
    $intHiddenPost = intval($row['countid']);
    $oDB->Query( 'SELECT MIN(issuedate) as firstdate,MAX(issuedate) as lastdate FROM '.TABMESSAGE.' WHERE id>=0 AND issuedate>="2000"' );
    $row = $oDB->Getrow();
  }
  if ( empty($row['firstdate']) ) $row['firstdate']=date('Ymd');
  if ( empty($row['lastdate']) ) $row['lastdate']=date('Ymd');
  $strLastdaysago = substr($row['lastdate'],0,8);
  $strTendaysago = DateAdd($strLastdaysago,-10,'day');
  $strFirstdate = QTdatestr($row['firstdate'],'$','$');
  $strLastdate = QTdatestr($row['lastdate'],'$','$');
  $intStartyear = intval(substr($row['firstdate'],0,4));
  $intStartmonth = intval(substr($row['firstdate'],4,2));
  $intEndyear = intval(date('Y'));
  $intEndmonth = intval(date('n'));
}

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

$intCurrentYear = $intYear;
$strCurrentTendaysago = $strTendaysago;

$arrA = array(); // Abscise
$arrT = array(); // Topics,
$arrTs = array(); // Topics sum ($arrT can have null)

foreach($arrYears as $y) // GLOBAL works on 2 years
{
  $arrT[$y] = array();
  switch($ch['time'])
  {
  case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]='Q'.$i;                                        $arrT[$y][$i]=null; } break;
  case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]=$L['dateMM'][$i];                              $arrT[$y][$i]=null; } break;
  case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $arrA[$i]=substr(DateAdd($strTendaysago,$i,'day'),-2,2); $arrT[$y][$i]=null; } break;
  }
  $arrTs[$y] = 0;
}

// COUNT MESSAGES

// -----
foreach($arrYears as $y) {
// -----

if ( $intCurrentYear==$y ) { $strTendaysago = $strCurrentTendaysago; } else { $strTendaysago = DateAdd(substr($strTendaysago,0,8),-1,'year'); }

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

  if ( $y<$intStartyear ) continue;
  if ( $y==$intStartyear )
  {
    if ( $ch['time']=='m' ) {
    if ( $intBt<$intStartmonth ) {
    continue;
    }}
    if ( $ch['time']=='q' ) {
    if ( ($intBt==1 && $intStartmonth>3) || ($intBt==2 && $intStartmonth>6) || ($intBt==3 && $intStartmonth>9) ) {
    continue;
    }}
  }
  if ( $y>=$intEndyear ) 
  {
    if ( $ch['time']=='m' ) {
    if ( $intBt>$intEndmonth ) {
    continue;
    }}
    if ( $ch['time']=='q' ) {
    if ( ($intBt==2 && $intEndmonth<4) || ($intBt==3 && $intEndmonth<7) || ($intBt==4 && $intEndmonth<10) ) {
    continue;
    }}
  }

  switch(substr($oDB->type,0,5))
  {
  case 'mysql': 
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,6)>"'.($y*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'mssql':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,6)>"'.($y*100+($intBt-1)*3).'" AND LEFT(issuedate,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND LEFT(issuedate,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'pg':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate,1,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate,1,6)>"'.($y*100+($intBt-1)*3).'" AND SUBSTRING(issuedate,1,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'ibase':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate FROM 1 FOR 6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate FROM 1 FOR 6)>"'.($y*100+($intBt-1)*3).'" AND SUBSTRING(issuedate FROM 1 FOR 6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTRING(issuedate FROM 1 FOR 8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'sqlit':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)>"'.($y*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'db2':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)>"'.($y*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'oci':
    if ( $ch['time']=='m') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)="'.($y*100+$intBt).'"' );
    if ( $ch['time']=='q') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,6)>"'.($y*100+($intBt-1)*3).'" AND SUBSTR(issuedate,1,6)<="'.($y*100+($intBt*3)).'"' );
    if ( $ch['time']=='d') $oDB->Query( 'SELECT count(id) as countid FROM '.TABMESSAGE.' WHERE id>=0 AND SUBSTR(issuedate,1,8)="'.(DateAdd($strTendaysago,$intBt,'day')).'"' );
    $row = $oDB->Getrow();
    break;
  case 'file':
    $row = array();
    if ( $ch['time']=='m') $row['countid'] = $oDB->FilesCount('',0,strval($y*100+$intBt),strval($y*100+$intBt));
    if ( $ch['time']=='q') 
    {
    $row['countid'] = $oDB->FilesCount('',0,strval($y*100+($intBt*3)),strval($y*100+($intBt-1)*3+1));
    }
    if ( $ch['time']=='d') $row['countid'] = $oDB->FilesCount(DateAdd($strTendaysago,$intBt,'day'),0,DateAdd($strTendaysago,$intBt,'day'),$strTendaysago);
    break;
  default: die('Unknown db type '.$oDB->type);
  }
  $arrT[$y][$intBt] = intval($row['countid']);
  $arrTs[$y] += $arrT[$y][$intBt]; // total
}

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

?>
Return current item: Quick Guestbook