Location: PHPKode > projects > QT-registrations > qtregistrations/qtr_stats_n.php
<?php

// QT-registrations 2.4 build:20100313

if ( !isset($_SESSION[QT]['statS']) ) $_SESSION[QT]['statS']=false;
if ( !isset($_SESSION[QT]['statC']) ) $_SESSION[QT]['statC']=false;
if ( !isset($_SESSION[QT]['statF']) ) $_SESSION[QT]['statF']=array();

include('qtr_stats_inc_n.php');

// ------
// SUBMITTED
// ------

if ( isset($_GET['add']) )
{
  $str = strip_tags($_GET['field']);
  if ( substr($str,0,1)!='-' )
  {
    if ( $str=='S' ) { $_SESSION[QT]['statS']=true; }
    elseif ( $str=='C' ) { $_SESSION[QT]['statC']=true; }
    else { $_SESSION[QT]['statF'][]=$str; }
  }
  $_SESSION[QT]['statF'] = array_unique($_SESSION[QT]['statF']);
}
if ( isset($_GET['rem']) )
{
  $str = strip_tags($_GET['field']);
  if ( substr($str,0,1)!='-' )
  {
    if ( $str=='S' ) $_SESSION[QT]['statS']=false;
    if ( $str=='C' ) $_SESSION[QT]['statC']=false;
    if ( in_array($str,$_SESSION[QT]['statF']) ) unset($_SESSION[QT]['statF'][array_search($str,$_SESSION[QT]['statF'])]);
  }
}

// maximum 4 fields and rearrange

if ( !isset($_SESSION[QT]['statF'][0]) && isset($_SESSION[QT]['statF'][1]) ) { $_SESSION[QT]['statF'][0]=$_SESSION[QT]['statF'][1]; unset($_SESSION[QT]['statF'][1]); }
if ( !isset($_SESSION[QT]['statF'][1]) && isset($_SESSION[QT]['statF'][2]) ) { $_SESSION[QT]['statF'][1]=$_SESSION[QT]['statF'][2]; unset($_SESSION[QT]['statF'][2]); }
if ( !isset($_SESSION[QT]['statF'][2]) && isset($_SESSION[QT]['statF'][3]) ) { $_SESSION[QT]['statF'][2]=$_SESSION[QT]['statF'][3]; unset($_SESSION[QT]['statF'][3]); }
if ( isset($_SESSION[QT]['statF'][4]) ) { unset($_SESSION[QT]['statF'][4]); $error='Maximum 4 fields'; }
if ( count($_SESSION[QT]['statF'])<2 ) $_SESSION[QT]['statS']=false;

// ------
// HTML START
// ------

  $arrNumFields = array();
  $oDB->Query( 'SELECT fieldid FROM '.TABFIELD.' WHERE fieldtype="N" OR fieldtype="R" ORDER BY fieldid' );
  while($row=$oDB->Getrow()) { $arrNumFields[$row['fieldid']] = ObjTrans('field',$row['fieldid']); }
  
  if ( count($arrNumFields)==0 ) echo '<p>',$L['E_no_numeric_field'],'</p>';

if ( $oVIP->output=='screen' && count($arrNumFields)!=0 ) 
{
echo '<div class="legendbox" style="width:400px;padding:4px">
<form method="get" action="',Href(),'">
<label for="field">Fields </label><select name="field" id="field" class="small">';
echo QTasTag($arrNumFields);
if ( count($arrNumFields)>1 )
{
echo '<option value="-"',QDIS,'>----------</option>';
echo '<option value="S">',$L['Total'],'</option>';
}
echo '<option value="--"',QDIS,'>----------</option>';
echo '<option value="C">',$L['Count_tickets'],'</option>';
echo '</select>
<input type="hidden" name="tt" value="',$tt,'"/>
<input type="hidden" name="s" value="',$s,'"/>
<input type="hidden" name="y" value="',$y,'"/>
<input type="hidden" name="tag" value="',$tag,'"/>
<input type="hidden" name="ch" value="',implode('',$ch),'"/>
<input type="submit" name="add" class="small" value="',$L['Add'],'"/>&nbsp;
<input type="submit" name="rem" class="small" value="',$L['Remove'],'"/>
';
if ( !empty($error) ) echo ' <span class="error">',$error,' </span>'; 
echo '</form>
</div>
';
}

// -----------
if ( isset($_SESSION[QT]['statF'][0]) ) {
// -----------

// Display title & option

echo '<table class="hidden" cellspacing="0">';
echo '<tr class="hidden" style="vertical-align:middle;">';
echo '<td><h2>',$y,($s>=0 ? ' '.$arrSections[$s] : ''),(empty($tag) ? '' : ', '.$L['Tag_only'].' "'.str_replace(';','" '.$L['or'].' "',$tag).'"'),'</h2></td>',N;
if ( $oVIP->output=='screen' ) echo '<td class="small" style="text-align:right">',implode(' &middot; ',$arrMenuTime),'</td>';
echo '</tr></table>
';

// DISPLAY

echo '<table class="data_t" cellspacing="0">
<tr class="data_t">
<td class="th_o" style="width:85px">&nbsp;</td>
<td class="th_o" style="width:14px">&nbsp;</td>
';
switch($ch['time'])
{
case 'q': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="th_o" style="text-align:center;">Q',$i,'</td>'; } break;
case 'm': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="th_o" style="text-align:center;">',$L['dateMM'][$i],'</td>'; } break;
case 'd': for ($i=1;$i<=$intMaxBt;$i++) { echo '<td class="th_o" style="text-align:center;">',str_replace(' ','<br/>',QTdatestr(DateAdd($strTendaysago,$i,'day'),'d M','')),'</td>'; } break;
}
echo '<td class="th_o" style="text-align:center;"><b>',($ch['time']=='d' ? '10 '.strtolower($L['Days']) : $L['Year']),'</b></td>
</tr>';

foreach($_SESSION[QT]['statF'] as $intKey=>$strNumericField)
{
  echo '<tr class="data_o">',N;
  echo '<td class="th_o">',ObjTrans('field',$strNumericField),'</td>',N;
  echo '<td class="th_o"><div style="margin:0 auto;background-color:#000066;width:8px;height:10px">&nbsp;</div></td>',N;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
  echo '<td class="td_o" style="text-align:center;">',(isset($arrT[$intKey][$intBt]) ? $arrT[$intKey][$intBt] : '&middot;'),'</td>',N;
  }
  echo '<td class="td_o" style="text-align:center;padding:5px;"><b>',$arrTs[$intKey],'</b></td>',N;
  echo '</tr>';
}

if ( $_SESSION[QT]['statS'] )
{
  echo '<tr class="data_o">',N;
  echo '<td class="th_o">',$L['Total'],'</td>',N;
  echo '<td class="th_o"><div style="margin:0 auto;background-color:#990099;width:8px;height:10px">&nbsp;</div></td>',N;
  for ($intBt=1;$intBt<=$intMaxBt;$intBt++)
  {
  echo '<td class="td_o" style="text-align:center; background-color:#eeeeee">',(isset($arrT['S'][$intBt]) ? $arrT['S'][$intBt] : '&middot;'),'</td>',N;
  }
  echo '<td class="td_o" style="text-align:center;padding:5px; background-color:#eeeeee"><b>',$arrTs['S'],'</b></td>',N;
  echo '</tr>';
}

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

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

foreach(array(0,1,2,3,'S','C') as $intSerie)
{
$arrT[$intSerie] = QTarrayzero($arrT[$intSerie]);
}

// PCHART OR CHART

if ( file_exists('pChart/pChart.class') && file_exists('pChart/pData.class') && file_exists('pChart/pCache.class')  && !isset($_GET['oldgraph']) )
{
  // Standard inclusions and prepare CACHE
  include('pChart/pData.class');
  include('pChart/pChart.class');

  // -------
  // Graphs
  // -------
  
  // charttitle,abscise,dataset,datasetname,graphoptions,filename,color,cumul
  $strChart = array();
  foreach($_SESSION[QT]['statF'] as $intSerie=>$strNumericField)
  {
  $strChart[] = QTpchart(
    ObjTrans('field',$strNumericField).($ch['value']=='p' ? ' (%)' : ''),
    $arrA,
    array( 'Serie1'=>$arrT[$intSerie] ),
    array( 'Serie1'=>$y ),
    $ch,
    $tt.$intSerie.$y.implode('',$ch),
    1);
  }
  if ( $_SESSION[QT]['statS'] )
  {  
  $strChart['S'] = QTpchart(
    $L['Total'].($ch['value']=='p' ? ' (%)' : ''),
    $arrA,
    array( 'Serie1'=>$arrT['S'] ),
    array( 'Serie1'=>$y ),
    $ch,
    $tt.'S'.$y.implode('',$ch),
    2);
  }
  if ( $_SESSION[QT]['statC'] )
  {
  $strChart['C'] = QTpchart(
    $L['Count'].($ch['value']=='p' ? ' (%)' : ''),
    $arrA,
    array( 'Serie1'=>$arrT['C'] ),
    array( 'Serie1'=>$y ),
    $ch,
    $tt.'C'.$y.implode('',$ch),
    3);
  }

  // -------
  // DISPLAY
  // -------

  if ( $oVIP->output=='screen' ) echo '<p class="small" style="text-align:right">',implode(' &middot; ',$arrMenuType),' | ',implode(' &middot; ',$arrMenuValue),'</p>';
  
  echo '<table class="hidden" cellspacing="0">',N;
  echo '<tr class="hidden">',N;
  echo '<td class="hidden">'.(isset($_SESSION[QT]['statF'][0]) ? '<img src="'.$strChart[0].'"/>' : '&nbsp;').'</td>',N;
  echo '<td class="hidden" style="text-align:right">'.(isset($_SESSION[QT]['statF'][1]) ? '<img src="'.$strChart[1].'"/>' : '&nbsp;').'</td>',N;
  echo '</tr>';
  echo '<tr class="hidden">',N;
  echo '<td class="hidden">'.(isset($_SESSION[QT]['statF'][2]) ? '<img src="'.$strChart[2].'"/>' : '&nbsp;').'</td>',N;
  echo '<td class="hidden" style="text-align:right">'.(isset($_SESSION[QT]['statF'][3]) ? '<img src="'.$strChart[3].'"/>' : '&nbsp;').'</td>',N;
  echo '</tr>';
  echo '<tr class="hidden">',N;
  echo '<td class="hidden">'.($_SESSION[QT]['statS'] ? '<img src="'.$strChart['S'].'"/>' : '&nbsp;').'</td>',N;
  echo '<td class="hidden" style="text-align:right">'.($_SESSION[QT]['statC'] ? '<img src="'.$strChart['C'].'"/>' : '&nbsp;').'</td>',N;
  echo '</tr>';
  echo '</table>';
  
}
elseif ( file_exists('bin/qt_lib_graph.php') && file_exists($_SESSION[QT]['skin_dir'].'/qtr_main2.css') )
{

  if ( $oVIP->output=='screen' ) echo '<p class="small" style="text-align:right">',implode(' &middot; ',$arrMenuValue),'</p>';
  
  echo '<table class="data_t" cellspacing="0">',N;
  echo '<tr class="data_t">',N;
  echo '<td class="td_o" style="width:355px">',N;

  if ( isset($_SESSION[QT]['statF'][0]) )
  {
    $intSerie = 0;
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,$arrT[$intSerie]),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time']],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTpercent($arrT[$intSerie])),350,100,100,2,'P',$L['Topics_per_'.$ch['time']].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }

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

  if ( isset($_SESSION[QT]['statF'][1]) )
  {
    $intSerie = 1;
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,QTcumul($arrT[$intSerie])),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time'].'_cumul'],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTcumul(QTpercent($arrT[$intSerie],2))),350,100,100,2,'P',$L['Topics_per_'.$ch['time'].'_cumul'].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }
  echo '</td>',N;
  echo '</tr>',N;
  echo '<tr class="data_t">',N;
  echo '<td class="td_o" style="width:355px">',N;

  if ( isset($_SESSION[QT]['statF'][2]) )
  {
    $intSerie = 2;
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,$arrT[$intSerie]),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time']],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTpercent($arrT[$intSerie])),350,100,100,2,'P',$L['Topics_per_'.$ch['time']].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }

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

  if ( isset($_SESSION[QT]['statF'][3]) )
  {
    $intSerie = 3;
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,QTcumul($arrT[$intSerie])),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time'].'_cumul'],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTcumul(QTpercent($arrT[$intSerie],2))),350,100,100,2,'P',$L['Topics_per_'.$ch['time'].'_cumul'].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }
  echo '</td>',N;
  echo '</tr>',N;
  echo '<tr class="data_t">',N;
  echo '<td class="td_o" style="width:355px">',N;

  if ( $_SESSION[QT]['statS'] )
  {
    $intSerie = 'S';
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,$arrT[$intSerie]),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time']],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTpercent($arrT[$intSerie])),350,100,100,2,'P',$L['Topics_per_'.$ch['time']].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }

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

  if ( $_SESSION[QT]['statC'] )
  {
    $intSerie = 'C';
    if ( $ch['value']=='a' ) 
    {
    QTbarchart(QTarraymerge($arrA,QTcumul($arrT[$intSerie])),320,100,QTroof($arrT[$intSerie]),2,true,$L['Topics_per_'.$ch['time'].'_cumul'],'','1');
    }
    else
    {
    QTbarchart(QTarraymerge($arrA,QTcumul(QTpercent($arrT[$intSerie],2))),350,100,100,2,'P',$L['Topics_per_'.$ch['time'].'_cumul'].' (%)','','1');
    }
  }
  else
  {
    echo '&nbsp;';
  }
  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'].'/qtr_main2.css</p>';
}

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

?>
Return current item: QT-registrations