Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/statistiques/Type_script.php
<?php

include_once('../../config.inc.php');
require_once("../phplot/phplot.php");
if (!isset($_SESSION['oreon'])) Session::Start();
include("../configuration/".$_SESSION['gatewayType'].".attr");
$oreon=$_SESSION['oreon'];

$stype="";
$year=date("y");
$week = 0;
$day = 0;
$mo = 1;

if (isset($_GET['lsid']) and $_GET['lsid']!='') {
	
	$locstr=" AND userinfo.LocationID='".$_GET['lsid']."'";
	$locstrwa=" WHERE userinfo.LocationID='".$_GET['lsid']."'";
}
else
	$locstr="";

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

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

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

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


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

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

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

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

if ($date_search=="Creation Date")
	$search_attribute="AND CrDate>='$start' AND CrDate<='$stop'";
if ($date_search=="Accounting Date" or $date_search=='')
	$search_attribute="AND AcctStopTime>='$start' AND AcctStopTime<='$stop'";
if ($date_search=="Login Date")
	$search_attribute="AND activeDate>='$start' AND activeDate<='$stop'";



$search2="SELECT Type,COUNT(Username) AS cuser From userinfo $locstrwa GROUP BY Type";
$result2=  $oreon->database->database->query($search2);

$stab=Array();
$i=0;

$sumsession=0;
$sumin=0;
$sumout=0;
$sumact=0;
$total=0;
$totalu=0;
$count=0;
$teu=0;
$resq2=0;
while ($row2 =  $oreon->database->database->fetch_object($result2)) {
	if ($date_search=="Login Date" OR $date_search=="Creation Date")
	{
		$res2="SELECT COUNT(*) AS val FROM userinfo WHERE Type='$row2->Type' AND activated='1' $locstr $search_attribute GROUP BY UserName";
		$resq2= $oreon->database->database->query($res2);
		
		$res4 = "SELECT userinfo.UserName,Type from userinfo where Type='$row2->Type' $locstr $search_attribute GROUP BY UserName";
	}
	else
	{
		$res2="SELECT userinfo.UserName AS val FROM userinfo,radacct WHERE radacct.UserName=userinfo.UserName AND Type='$row2->Type' AND activated='1' $locstr $search_attribute GROUP BY userinfo.UserName";
		
		$resq2= $oreon->database->database->query($res2);
		$res4 = "SELECT userinfo.UserName,Type from userinfo,radacct where  radacct.UserName=userinfo.UserName AND Type='$row2->Type' $locstr $search_attribute GROUP BY userinfo.UserName ;";
	} 
	$res3 = "SELECT userinfo.*,acctsessiontime AS sum_sess_time,
		$acctinputoctetsattr AS sum_in_octets,
		$acctoutputoctetsattr AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND Type='$row2->Type' $locstr $search_attribute GROUP BY AcctSessionId,Type";
	
    //print '<br>'.$res3;
    $resq3= $oreon->database->database->query($res3);
	$r2=$oreon->database->database->result_num_rows($resq2);  
	$res1f=0;
	$res2f=0;
	$res3f=0;
	$count=0;
	while ($r3=$oreon->database->database->fetch_object($resq3))
	{
		
		$res1f+=$r3->sum_sess_time;
		$res2f+=$r3->sum_in_octets;
		$res3f+=$r3->sum_out_octets;
		$count+=1;
	}
	$totalu+=$row2->cuser;
	$sumsession+=$res1f;
	$sumin+=$res2f;
	$sumout+=$res3f;
	$sumact+=$r2;
	$total+=$count;
	
	$res1=$res1f;
	$res2=$res2f;
	$res3=$res3f;
	$array=expiredUser("",$res4);
	$eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
	$teu+=$eu;

$div=1;
	if ($stype=="ausers") 
	{
	$stab[$i]=array($row2->Type,$r2);
        $ord_text="Account number";
	}
	if ($stype=="eusers") 
	{
		$stab[$i]=array($row2->Type,$eu);
        $ord_text="Account number";
	}
	if ($stype=="aeusers") 
	{
		$stab[$i]=array($row2->Type,$r2,$eu);
        $ord_text="Account number";
	}
    
    if ($stype=="stime") 
	{
        $div=3600;
        $stab[$i]=array($row2->Type,round($res1/$div,2));
        $ord_text="Hours";
	}

    
	if ($stype=="uload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row2->Type,round($res2/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="dload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row2->Type,round($res3/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="udload") 
	{
        $div=1000*1000;
        $stab[$i]=array($row2->Type,round($res2/$div,2),round($res3/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	$i++;
}
$plot =& new PHPlot($width, $height);
$plot->SetImageBorderType('plain');
$plot->SetDataValues($stab);
$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 ($stab as $row)
		$plot->SetLegend(implode(': ', $row));
}
else {
	# Let's use a new color for these bars:
	$plot->SetDataType('text-data');
	$plot->SetDataColors('#1b7eff');
	# Force bottom to Y=0 and set reasonable tick interval:
	$plot->SetYDataLabelPos('plotin');
	$plot->SetPlotAreaWorld(NULL, 0, NULL, NULL);
	$plot->SetYTickIncrement(10);
	# 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