Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/statistiques/GenerateStat.php
<?php
include_once('../../config.inc.php');
require_once("../phplot/phplot.php");
if (!isset($_SESSION['oreon'])) Session::Start();
$oreon=$_SESSION['oreon'];

$lid=$_SESSION['locID'];
$year=date("y");
$week = 0;
$day = 0;
$mo = 1;
$basetime="Week";

if (isset($_GET['plot_type'])) 
	$plot_type=$_GET['plot_type'];
else
	$plot_type="bars";

if (isset($_GET['width'])) 
	$width=$_GET['width'];
else
	$width=430;

if (isset($_GET['title'])) 
	$title=$_GET['title'];
else
	$title="";

if (isset($_GET['crdate']) and $_GET['crdate']!='All') 
	$crdate=" AND CrDate='".$_GET['crdate']."'";
else
	$crdate="";

if (isset($_GET['nasip']) and $_GET['nasip']!='All') 
	$nasip=" AND NASIPAddress='".$_GET['nasip']."'";
else
	$nasip="";

if (isset($_GET['naspt']) and $_GET['naspt']!='All') 
	$naspt=" AND NASPortType='".$_GET['naspt']."'";
else
	$naspt="";
if (isset($_GET['realm']) and $_GET['realm']!='All') 
	$realm=" AND Realm='".$_GET['realm']."'";
else
	$realm="";



if (isset($_GET['type']) and $_GET['type']!='All') 
	$type_acct=" AND Type='".$_GET['type']."'";
else
	$type_acct="";

if (isset($_GET['bpname']) and $_GET['bpname']!='All') 
	$bpname=" AND BillingPlan='".get_plan_Id($_GET['bpname'])."'";
else
	$bpname="";

if (isset($_GET['height'])) 
	$height=$_GET['height'];
else
	$height=250;

if (isset($_GET['height'])) 
	$height=$_GET['height'];
else
	$height=250;


if (isset($_GET['typegr'])) 
	$type=$_GET['typegr'];
else
	$type="Time";

if (isset($_GET['basetime'])) 
	$basetime=$_GET['basetime'];
else
	$basetime="Week";

if (isset($_GET['puser'])) 
	$puser=" AND radacct.UserName='".$_GET['puser']."'";
else
	$puser="";


if ($basetime=="Week") {
	$ord=array('Mon','Tue','Wed','Thu','Fri','Sat','Sun');

	$abc_text="Days";
	$mo=date("m");
	$d=date("d")-weekday($year,$mo,date("d"));
	$tsize=sizeof($ord);
	$esi="<";
}


if ($basetime=="Months") {

	$ord= array("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31");
        $abc_text="Days";
	$mo=date("m");
	$d=1;
	$tsize=date('t')+1;
	$esi="<=";
}

if ($basetime=="Hours") {
	$ord= array("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24");
        $abc_text="Hours";
	$mo=date("m");
	$d=date("d");
	$tsize=sizeof($ord)-1;
	$esi="<=";
}

if ($basetime=="Years")
{
   $year=date("Y");
   $ord= array($year-5,$year-4,$year-3,$year-2,$year-1,$year);
   $abc_text="Years";
   $tsize=sizeof($ord);
   $year=$year-5;
   $esi="<=";
}



if ($basetime=="Year")
{
   $ord= array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sept","Oct","Nov","Dec");
   $abc_text="Year";
   $tsize=sizeof($ord);
   $esi="<=";
}


$attr="AcctSessionTime"; 
$attrin="$acctinputoctetsattr";
$attrout="$acctoutputoctetsattr";
if ($type=='Time') {
	$ord_text="Hours";
	$inc="1";
	$ymax="24";
}
else if ($type=='Octet') {
        $ord_text="Mega octets";
	$inc="20";
	$ymax="1000";
}
$finaltab=array();
for ($i=0;$i<$tsize;$i++) {
	if ($basetime=="Year") {
	
	    $sdate=date('Y-m-d H:i:s',mktime(23,59,59,$mo,$d,$year));
	    $edate=date('Y-m-d H:i:s',mktime(23,59,59,$mo+1,$d,$year));
	    $mo++;
	}
	if ($basetime=="Hours") {
	    $sdate=date('Y-m-d H:i:s',mktime($ord[$i],0,0,$mo,$d,$year));
	    $edate=date('Y-m-d H:i:s',mktime($ord[$i]+1,0,0,$mo,$d,$year));
	
	}
	if ($basetime=="Week") {
	    $sdate=date('Y-m-d H:i:s',mktime(0,0,0,$mo,$d,$year));
	    $edate=date('Y-m-d H:i:s',mktime(0,0,0,$mo,$d+1,$year));
            $d++;
	}
	if ($basetime=="Months") {
	    $sdate=date('Y-m-d H:i:s',mktime(0,0,0,$mo,$d,$year));
	    $edate=date('Y-m-d H:i:s',mktime(0,0,0,$mo,$d+1,$year));
	    $d++;
	}

	 if ($basetime=="Years") {
	     $sdate=date('Y-m-d H:i:s',mktime(0,0,0,01,01,$year));
	     $edate=date('Y-m-d H:i:s',mktime(23,59,59,12,31,$year));
	     $year++;
	 }

	$q1="SELECT SUM($attr) AS sumsessiontime,SUM($attrin) AS inputoct,SUM($attrout) AS outputoct FROM radacct,userinfo WHERE radacct.UserName=userinfo.Username and AcctStartTime >'$sdate' AND AcctStopTime $esi '$edate' $crdate $bpname $type_acct $realm $naspt $nasip $puser";
	$results=$oreon->database->database->query($q1);
	$row = $oreon->database->database->fetch_array($results);
//print $q1;

    
    if ($type=='Octet') { 
  //      print " <br> INT ".$row['inputoct']."<br>";
		$in=(round(($row['inputoct'])/(1000*1000),2));
		$out=(round(($row['outputoct'])/(1000*1000),2));
        $tot=$in + $out;
    //    print " <br> TOTOTT ".$tot."<br>";
		$finaltab[$i]=array($ord[$i],$in,$out,$tot);
	
	}
	else if ($type='Time')  {
		$res=round($row['sumsessiontime']/3600,2);
		//echo '<br>'.$res.'<br>';
		$finaltab[$i]=array($ord[$i],$res);
    }
    if ($tot>1000) $incy='1000';
}

$plot =& new PHPlot($width, $height);
$plot->SetImageBorderType('plain');

$plot->SetDataValues($finaltab);
$plot->SetPlotType($plot_type);

if ($plot_type=='pie') {
	$plot->SetDataType('text-data-single');
	$plot->SetDataColors(array('red', 'green', 'blue', 'yellow', 'cyan',
		                        'magenta', 'brown', 'lavender', 'pink',
					'gray', 'orange'));
	foreach ($finaltab as $row)
		  $plot->SetLegend(implode(': ', $row));
}
else {
	# Let's use a new color for these bars:
	$plot->SetDataType('text-data');
	$plot->SetDataColors(array('#1b7eff','red', 'green', 'blue', 'yellow', 'cyan', 'magenta'));
	# Force bottom to Y=0 and set reasonable tick interval:
	$plot->SetYDataLabelPos('plotin');
    $plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
    if ($incy=='')
        $plot->SetYTickIncrement('20');
    else
        $plot->SetYTickIncrement($incy);

	if ($type=='Octet') {
         $plot->SetLegend(array('Input', 'Ouput', 'Total'));	
	}
	# Format the Y tick labels as numerics to get thousands separators:
	$plot->SetYLabelType('data');
	$plot->SetPrecisionY(0);
	# Main plot title:
	$plot->SetTitle($title);
	$plot->SetXTitle($abc_text);
	# Y Axis title:
	$plot->SetYTitle($ord_text);
	# Turn off X tick labels and ticks because they don't apply here:
	$plot->SetXTickLabelPos('none');
	$plot->SetXTickPos('none');

}



$plot->DrawGraph();


function weekday($fyear, $fmonth, $fday) //0 is monday
 {
	   return (((mktime ( 0, 0, 0, $fmonth, $fday, $fyear) - mktime ( 0, 0, 0, 7, 17, 2006))/(60*60*24))+700000) % 7;
 }

?>
Return current item: phpMyPrepaid