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

// QuickTicket 2.3 build:20091102

// --------
// INITIALISE
// --------

$oVIP->output='print';

$s = -1;   // section filter
$y = date('Y'); if ( intval(date('n'))<2 ) $y--; // year filter
$tag = ''; // tags filter
$tt = 'dt'; // tab: g=global, gt=globaltrend, d=detail, dt=detailtrend
$ch = array('m','b','a','a'); // chart parameters
// [0] blocktime: m=month, q=quarter, d=10days 
// [1] graph type: b=bar, l=line, B=bar+variation, L=line+variation
// [2] graphics reals: a=actual, p=percent
// [3] trends reals: a=actual, p=percent

// --------
// SUBMITTED
// --------
  
if ( isset($_GET['y']) ) $y = intval($_GET['y']);
if ( isset($_GET['s']) ) $s = intval($_GET['s']);
if ( $s>=0 ) { $strSection = 'forum='.$s.' AND'; } else { $strSection=''; }
if ( isset($_GET['tag']) ) $tag = strip_tags($_GET['tag']);
  $strTags = '';
  if ( !empty($tag) )
  {
    if ( substr($tag,-1,1)==';' ) $tag = substr($tag,0,-1); 
    $arrTags = explode(';',$tag);
    $str = '';
    foreach($arrTags as $strTag)
    {
    if ( !empty($str) ) $str .= ' OR ';
    $str .= 'UPPER(tags) LIKE "%'.strtoupper($strTag).'%"';
    }
    if ( !empty($str) ) $strTags = ' ('.$str.') AND';
  }
if ( isset($_GET['tt']) ) $tt = strip_tags($_GET['tt']);
if ( isset($_GET['ch']) )
{
  $str = strip_tags($_GET['ch']);
  if ( str_len($str)>0 ) $ch['time'] = substr($str,0,1); // blocktime
  if ( str_len($str)>1 ) $ch['type'] = substr($str,1,1); // graph type
  if ( str_len($str)>2 ) $ch['value'] = substr($str,2,1); // value type
  if ( str_len($str)>3 ) $ch['trend'] = substr($str,3,1); // trends value type
}

// ------
// OUTPUT
// ------

$arrYears = array($y-1,$y); // Normal is 1 year but for Trends analysis, 2 years

include('qti_stats_inc.php');

if ( $ch['time']=='q' ) { $intWidth=16; } else { $intWidth=11; }

// PDF START

$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetTitle( PdfClean($L['Statistics']) );
$pdf->SetAuthor( PdfClean($_SESSION[QT]['site_name']) );
$pdf->SetSubject( PdfClean(PdfClean($L['H_Details_trends']) );

$pdf->SetFont('Arial','B',14);
$pdf->SetTextColor(150);
$pdf->Ln();
$pdf->Cell(0, 10, PdfClean($L['H_Details_trends']), 'T', 1, 'R');
$pdf->SetTextColor(0);

$pdf->SetFont('Arial','B',10);
$arr = QTarrget(GetSections($oVIP->role));
$pdf->Cell(0, 8, PdfClean( ($y-1).' '.$y.($s>=0 ? ' ('.$arr[$s].')' : '').(empty($tag) ? '' : ', '.$L['With_tag'].' '.str_replace(';',' '.$L['or'].' ',$tag)) ), '', 1);

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

$arrTable = array();

// Table header

  $arrRow = array();
  $oCell = new cPdfCell($y,28,5,'',true); $oCell->font=array('Arial','B',8); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true); $arrRow[]=$oCell;
  switch($ch['time'])
  {
  case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( 'Q'.$i,                                              $intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( $L['dateMM'][$i],                                    $intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( QTdatestr(DateAdd($strTendaysago,$i,'day'),'d/n',''),$intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  }
  $oCell = new cPdfCell(($ch['time']=='d' ? '10 '.strtolower($L['Days']) : PdfClean($L['Year'])),$intWidth+3,5,'C',true); $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// Table body new topics

  $arrRow = array();
  $oCell = new cPdfCell($L['New_topics'],28,5,'',true); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true,array(0,0,102)); $arrRow[]=$oCell;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
  $oCell = new cPdfCell((isset($arrN[$y][$intBt]) ? $arrN[$y][$intBt] : '.'),$intWidth); $arrRow[]=$oCell;
  }
  $oCell = new cPdfCell($arrNs[$y],$intWidth+3,5,'C');$oCell->font=array('Arial','B',8); $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// Table body closed topics

  $arrRow = array();
  $oCell = new cPdfCell($L['Closed_topics'],28,5,'',true); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true,array(153,0,153)); $arrRow[]=$oCell;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
  $oCell = new cPdfCell((isset($arrC[$y][$intBt]) ? $arrC[$y][$intBt] : '.'),$intWidth); $arrRow[]=$oCell;
  }
  $oCell = new cPdfCell($arrCs[$y],$intWidth+3,5,'C');$oCell->font=array('Arial','B',8); $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// End table
 
$pdf->BasicTable($arrTable);
$pdf->Ln(1);

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

$arrTable = array();

// Table header

  $arrRow = array();
  $oCell = new cPdfCell($L['Trends'],28,5,'',true); $oCell->font=array('Arial','B',8); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true); $arrRow[]=$oCell;
  switch($ch['time'])
  {
  case 'q': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( 'Q'.$i,                                              $intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  case 'm': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( $L['dateMM'][$i],                                    $intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  case 'd': for ($i=1;$i<=$intMaxBt;$i++) { $oCell = new cPdfCell( QTdatestr(DateAdd($strTendaysago,$i,'day'),'d/n',''),$intWidth,5,'C',true); $arrRow[]=$oCell; } break;
  }
  $oCell = new cPdfCell(($ch['time']=='d' ? '10 '.strtolower($L['Days']) : PdfClean($L['Year'])),$intWidth+3,5,'C',true); $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// Table new topics

  $arrRow = array();
  $oCell = new cPdfCell($L['New_topics'],28,5,'',true); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true,array(0,0,102)); $arrRow[]=$oCell;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
    $oCell = new cPdfCell('0',$intWidth);
    $i = QTtrend((isset($arrN[$y][$intBt]) ? $arrN[$y][$intBt] : 0),(isset($arrN[$y-1][$intBt]) ? $arrN[$y-1][$intBt] : 0),$ch['trend']=='p');
    if ( isset($i) )
    {
      $oCell->s = $i.($ch['trend']=='p' ? '%' : '');
      if ( $i>0 ) { $oCell->color=array(255,0,0); $oCell->s = '+'.$oCell->s; }
      if ( $i<0 ) { $oCell->color=array(0,255,0); $oCell->s = $oCell->s; }
    }
    else
    {
      $oCell->s = '.';
    }
    $arrRow[]=$oCell;
  }
  $oCell = new cPdfCell('0',$intWidth); $oCell->font=array('Arial','B',8);
  $i = QTtrend($arrNs[$y],$arrNs[$y-1],$ch['trend']=='p');
  if ( isset($i) )
  {
    $oCell->s = $i.($ch['trend']=='p' ? '%' : '');
    if ( $i>0 ) { $oCell->color=array(255,0,0); $oCell->s = '+'.$oCell->s; }
    if ( $i<0 ) { $oCell->color=array(0,255,0); $oCell->s = $oCell->s; }
  }
  else
  {
    $oCell->s = '.';
  }
  $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// Table closed topics

  $arrRow = array();
  $oCell = new cPdfCell($L['Closed_topics'],28,5,'',true); $arrRow[]=$oCell;
  $oCell = new cPdfCell(' ',4, 5,'',true,array(153,0,153)); $arrRow[]=$oCell;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
    $oCell = new cPdfCell('0',$intWidth);
    $i = QTtrend((isset($arrC[$y][$intBt]) ? $arrC[$y][$intBt] : 0),(isset($arrC[$y-1][$intBt]) ? $arrC[$y-1][$intBt] : 0),$ch['trend']=='p');
    if ( isset($i) )
    {
      $oCell->s = $i.($ch['trend']=='p' ? '%' : '');
      if ( $i>0 ) { $oCell->color=array(255,0,0); $oCell->s = '+'.$oCell->s; }
      if ( $i<0 ) { $oCell->color=array(0,255,0); $oCell->s = $oCell->s; }
    }
    else
    {
      $oCell->s = '.';
    }
    $arrRow[]=$oCell;
  }
  $oCell = new cPdfCell('0',$intWidth); $oCell->font=array('Arial','B',8);
  $i = QTtrend($arrCs[$y],$arrCs[$y-1],$ch['trend']=='p');
  if ( isset($i) )
  {
    $oCell->s = $i.($ch['trend']=='p' ? '%' : '');
    if ( $i>0 ) { $oCell->color=array(255,0,0); $oCell->s = '+'.$oCell->s; }
    if ( $i<0 ) { $oCell->color=array(0,255,0); $oCell->s = $oCell->s; }
  }
  else
  {
    $oCell->s = '.';
  }
  $arrRow[]=$oCell;
  $arrTable[] = $arrRow;

// End table
 
$pdf->BasicTable($arrTable);
$pdf->Ln(3);

$pdf->SetTextColor(0);

// After values display change the null values to zero to be able to make charts

foreach($arrYears as $y)
{
$arrT[$y] = QTarrayzero($arrT[$y]);
$arrN[$y] = QTarrayzero($arrN[$y]);
$arrC[$y] = QTarrayzero($arrC[$y]);
}

// GRAPH

if ( file_exists('bin/qt_lib_graph.php') && file_exists($_SESSION[QT]['skin_dir'].'/qti_main2.css') )
{

  $y = $pdf->GetY();
  $x = $pdf->GetX();

  // NEW TOPICS first serie
  
  $intTopValue = QTroof( array(max($arrN[$y-1]),max($arrN[$y-1])) );
  if ( $ch['value']=='a' ) 
  {
  $pdf = QTbarchartpdf($pdf,$arrN[$y-1],92,30,$intTopValue,2,true,$L['New_topics'].' '.($y-1),'','1');
  }
  else
  {
  $pdf = QTbarchartpdf($pdf,$arrN[$y-1],92,30,$intTopValue,2,'P',$L['New_topics'].' (%)'.' '.($y-1),'','1');
  }

  $pdf->SetXY($x+94,$y);

  // NEW TOPICS second serie

  if ( $ch['value']=='a' ) 
  {
  $pdf = QTbarchartpdf($pdf,$arrN[$y],92,30,$intTopValue,2,true,$L['New_topics'].' '.$y,'','1');
  }
  else
  {
  $pdf = QTbarchartpdf($pdf,$arrN[$y],92,30,$intTopValue,2,'P',$L['New_topics'].' (%)'.' '.$y,'','1');
  }
  
  $pdf->SetXY($x,$y+47);

  // CLOSED TOPICS first serie
  
  $intTopValue = QTroof( array(max($arrC[$y-1]),max($arrC[$y-1])) );
  if ( $ch['value']=='a' ) 
  {
  $pdf = QTbarchartpdf($pdf,$arrC[$y-1],92,30,$intTopValue,2,true,$L['Closed_topics'].' '.($y-1),'','2');
  }
  else
  {
  $pdf = QTbarchartpdf($pdf,$arrC[$y-1],92,30,$intTopValue,2,'P',$L['Closed_topics'].' (%)'.' '.($y-1),'','2');
  }

  $pdf->SetXY($x+94,$y+47);

  // CLOSED TOPICS second serie

  if ( $ch['value']=='a' ) 
  {
  $pdf = QTbarchartpdf($pdf,$arrC[$y],92,30,$intTopValue,2,true,$L['Closed_topics'].' '.$y,'','2');
  }
  else
  {
  $pdf = QTbarchartpdf($pdf,$arrC[$y],92,30,$intTopValue,2,'P',$L['Closed_topics'].' (%)'.' '.$y,'','2');
  }
  
  $pdf->SetXY($x,$y+94);

}
else
{
  $pdf->SetFont('Arial','',8);
  $pdf->Cell(0, 10, PdfClean('Graphs cannot be displayed because one of these files is missing: bin/qt_lib_graph.php, '.$_SESSION[QT]['skin_dir'].'/qti_main2.css'), 'T', 1);
}

// --------
// PDF END
// --------

$pdf->Output();

?>
Return current item: QuickTicket