Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/statistiques/Billing_plan_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'";


$search="SELECT BillingPlan.Id,NameBp From BillingPlan,userinfo WHERE userinfo.BillingPlan=BillingPlan.ID $locstr GROUP BY NameBp";

//print '<br>'.$search;

$result=  $oreon->database->database->query($search);


$stab=Array();
$i=0;
$sumsession=0;
$sumin=0;
$sumout=0;
$sumact=0;
$total=0;
$totalu=0;
$res="SELECT * FROM userinfo WHERE (BillingPlan='0' OR BillingPlan='') $locstr GROUP BY UserName";
$res2="SELECT userinfo.UserName AS val FROM userinfo,radacct WHERE radacct.UserName=userinfo.UserName AND BillingPlan='0' AND activated='1' $locstr  $search_attribute GROUP BY userinfo.UserName";
$res4 = "SELECT userinfo.UserName,Type from userinfo,radacct where  radacct.UserName=userinfo.UserName AND (BillingPlan='0' or BillingPlan='')  $search_attribute $locstr GROUP BY userinfo.UserName ;";
$res3 = "SELECT acctsessiontime AS sum_sess_time,$acctinputoctetsattr AS sum_in_octets,$acctoutputoctetsattr AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND (BillingPlan='0' or BillingPlan='') $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan;";
//print '<br>'.$res3;
$resq1= $oreon->database->database->query($res);

$resq2=  $oreon->database->database->query($res2);
$resq3=  $oreon->database->database->query($res3);
$r2= $oreon->database->database->result_num_rows($resq2); 
$r1= $oreon->database->database->result_num_rows($resq1);
$res1f=0;
$res2f=0;
$res3f=0;
while ($r3=$oreon->database->database->fetch_object($resq3))
{
	
	$res1f+=$r3->sum_sess_time;
	$res2f+=$r3->sum_in_octets;
	$res3f+=$r3->sum_out_octets;
	$cnt++;
}

$sumsession+=$res1f;
$sumin+=$res2f;
$sumout+=$res3f;
$sumact+=$r2;
$total+=$cnt;
$totalu+=$r1;
$res1=$res1f;
$res2=$res2f;
$res3=$res3f;
$array=expiredUser("",$res4);
$eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
$teu+=$eu;
$i=0;
$div=1;
	if ($stype=="ausers") 
	{
	$stab[$i]=array($row->NameBp,$r2);
        $ord_text="Account number";
	}
	if ($stype=="eusers") 
	{
		$stab[$i]=array($row->NameBp,$eu);
        $ord_text="Account number";
	}
	if ($stype=="aeusers") 
	{
		$stab[$i]=array($row->NameBp,$r2,$eu);
        $ord_text="Account number";
	}
    
    if ($stype=="stime") 
	{
        $div=3600;
        $stab[$i]=array($row->NameBp,round($res1/$div,2));
        $ord_text="Hours";
	}

    
	if ($stype=="uload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row->NameBp,round($res2/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="dload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row->NameBp,round($res3/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="udload") 
	{
        $div=1000*1000;
        $stab[$i]=array($row->NameBp,round($res2/$div,2),round($res3/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
    }


$i++;
while ($row = $oreon->database->database->fetch_object($result)) {
    //print '<br> BP '.$row->Id;	
    $rid=$row->Id;
	$res="SELECT COUNT(*) AS val FROM userinfo WHERE  BillingPlan='$rid'  $locstr GROUP BY UserName";
	$res2="SELECT userinfo.UserName AS val FROM userinfo,radacct WHERE radacct.UserName=userinfo.UserName AND BillingPlan='$rid' AND activated='1' $locstr $search_attribute GROUP BY userinfo.UserName";
	$res4 = "SELECT userinfo.UserName,Type FROM userinfo,radacct where  radacct.UserName=userinfo.UserName AND BillingPlan='$rid' $locstr $search_attribute GROUP BY userinfo.UserName ;";
	$res3 = "SELECT acctsessiontime AS sum_sess_time,$acctinputoctetsattr AS sum_in_octets,$acctoutputoctetsattr AS sum_out_octets FROM radacct,userinfo WHERE BillingPlan='$rid' AND  radacct.UserName=userinfo.UserName $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan";
//print '<br>'.$res3;
	$resq2= $oreon->database->database->query($res2);
	$resq1=  $oreon->database->database->query($res);
	$resq3= $oreon->database->database->query($res3);
	
$r2=$oreon->database->database->result_num_rows($resq2);  
$r1=$oreon->database->database->result_num_rows($resq1);
	$res1f=0;
	$res2f=0;
	$res3f=0;
	$cnt=0;
	
	while ($r3=$oreon->database->database->fetch_object($resq3))
	{
		
		$res1f+=$r3->sum_sess_time;
		$res2f+=$r3->sum_in_octets;
		$res3f+=$r3->sum_out_octets;
		$cnt++;
	}
 
	$sumsession+=$res1f;
	$sumin+=$res2f;
	$sumout+=$res3f;
	$sumact+=$r2;
	$total+=$cnt;
	$totalu+=$r1;
	$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($row->NameBp,$r2);
        $ord_text="Account number";
	}
	if ($stype=="eusers") 
	{
		$stab[$i]=array($row->NameBp,$eu);
        $ord_text="Account number";
	}
	if ($stype=="aeusers") 
	{
		$stab[$i]=array($row->NameBp,$r2,$eu);
        $ord_text="Account number";
	}
    
    if ($stype=="stime") 
	{
        $div=3600;
        $stab[$i]=array($row->NameBp,round($res1/$div,2));
        $ord_text="Hours";
	}

    
	if ($stype=="uload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row->NameBp,round($res2/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="dload") 
	{
        $div=1000*1000;
		$stab[$i]=array($row->NameBp,round($res3/$div,2),round(($res2+$res3)/$div,2));
        $ord_text="Mega octets";
	}
	if ($stype=="udload") 
	{
        $div=1000*1000;
        $stab[$i]=array($row->NameBp,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->SetPlotAreaWorld(NULL, 0, NULL, NULL);
	$plot->SetYDataLabelPos('plotin');
	$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