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

if  (isset($_GET['lsid'])) 
{
	$loc=getLocationID($_GET['lsid']);
	$LocName=$_GET['lsid'];
}
else
	$LocName = $_SESSION['LocName'];

$LocName = $_SESSION['LocName'];

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


if(!isset($buttonID)) {
	$msg= "$msg <p class=\"error\">No button ID was sent</p>"; // this shouldn't happen
}

if(!isset($msg)){  // no errors? ...  hit it.  Need to reset button id
	
	$y=date('Y');
$m=date('m');
if  (isset($_POST['after'])) $fromdate=$_POST['after']; 
if  (isset($_POST['before'])) $todate=$_POST['before'];

if ($fromdate=='')  {
	 $after=$y."-".$m."-01 00:00:00";
	$startf=date($dateFormat,strtotime($after));
	}
	 else
	{ 
	 $after=date_to_attribute($fromdate,"mysql");
	$startf=$fromdate;
	}

if ($todate=='') 
	{
	$before=date("Y-m-d")." 23:59:59";
	 $stopf=date($dateFormat,strtotime($before));
	}
else
	{
	 $before=date_to_attribute($todate,"mysql");
	$stopf=$todate; 
	} 


$after_time = date2time($after);
$before_time = date2time($before);
$days[0] = $after;
$counter = $after_time + 86400;
$i = 1;
while($counter < $before_time){
	$days[$i++] = date($sql_date_format,$counter);	
	$counter += 86400;
}
$days[$i] = $before;
$num_days = $i;

$column1 = ($column1 != '') ? "$column1" : 'sessions';
$column2 = ($column2 != '') ? "$column2" : 'usage';
$column3 = ($column3 != '') ? "$column3" : 'download';
$column[1] = "$column1";
$column[2] = "$column2";
$column[3] = "$column3";
$selected1["$column1"] = 'selected';
$selected2["$column2"] = 'selected';
$selected3["$column3"] = 'selected';

$message['sessions'] = 'sessions';
$message['usage'] = 'total usage time';
$message['upload'] = 'uploads';
$message['download'] = 'downloads';
$sql_val['usage'] = 'acctsessiontime';
$sql_val['upload'] = $acctinputoctetsattr;
$sql_val['download'] = $acctoutputoctetsattr;
$fun['sessions'] = nothing;
$fun['usage'] = time2strclock;
$fun['upload'] = octets2str;
$fun['download'] = octets2str;
$sql_val['user'] = ($login == '') ? "WHERE radacct.UserName=userinfo.UserName AND radacct.username LIKE '%'" : "WHERE radacct.UserName=userinfo.UserName AND radacct.username = '$login'";
for ($j = 1; $j <= 3; $j++){
	$tmp = "{$sql_val[$column[$j]]}";
	$res[$j] = ($tmp == "") ? "COUNT(radacctid) AS res_$j" : "sum($tmp) AS res_$j";
}


$i = 1;

for ($i = $num_days;$i > -1; $i--){
		$day = "$days[$i]";
		$search = "SELECT $res[1],$res[2],$res[3] FROM radacct,userinfo
		$sql_val[user] AND acctstoptime >= '$day 00:00:00' AND acctstoptime <= '$day 23:59:59' $locstr $s;";
  			$result = $oreon->database->database->query($search) or die("Query database error !");
			$row = $oreon->database->database->fetch_array($result);
			$data[$day][1] = $row['res_1'];
			$data['sum'][1] += $row['res_1'];
			$num[1] = ($data[$day][1]) ? $num[1] + 1 : $num[1];
			$data[$day][2] = $row['res_2'];
			$data['sum'][2] += $row['res_2'];
			$num[2] = ($data[$day][2]) ? $num[2] + 1 : $num[2];
			$data[$day][3] = $row['res_3'];
			$data['sum'][3] += $row['res_3'];
			$num[3] = ($data[$day][3]) ? $num[3] + 1 : $num[3];
}

$num[1] = ($num[1]) ? $num[1] : 1;
$num[2] = ($num[2]) ? $num[2] : 1;
$num[3] = ($num[3]) ? $num[3] : 1;

$data['avg'][1] = ceil($data['sum'][1] / $num[1]);
$data['avg'][2] = ceil($data['sum'][2] / $num[2]);
$data['avg'][3] = ceil($data['sum'][3] / $num[3]);

$data['avg'][1] = $fun[$column[1]]($data['avg'][1]);
$data['avg'][2] = $fun[$column[2]]($data['avg'][2]);
$data['avg'][3] = $fun[$column[3]]($data['avg'][3]);

$data['sum'][1] = $fun[$column[1]]($data['sum'][1]);
$data['sum'][2] = $fun[$column[2]]($data['sum'][2]);
$data['sum'][3] = $fun[$column[3]]($data['sum'][3]);

$maf['tab'][1]=$maf['tab'][2]=$maf['tab'][3]=0;
for ($i = 0; $i <= $num_days; $i++){
	$day = $days[$i];
	$maf['tab'][1] = ($maf['tab'][1] > $data[$day][1] ) ? $maf['tab'][1] : $data[$day][1];
	$maf['tab'][2] = ($maf['tab'][2] > $data[$day][2] ) ? $maf['tab'][2] : $data[$day][2];
	$maf['tab'][3] = ($maf['tab'][3] > $data[$day][3] ) ? $maf['tab'][3] : $data[$day][3];
}
for ($i = 0; $i <= $num_days; $i++){
	$day = $days[$i];
	for ($j = 1; $j <= 3; $j++){
		$tmp = $data[$day][$j];
		if (!$maf['tab'][$j])
			$p = $w = $c = 0;
		else{
			$p = floor(100 * ($tmp / $maf['tab'][$j]));
			$w = floor(70 * ($tmp / $maf['tab'][$j]));
			$c = hexdec('f999e2') - (258 * $p);
			$c = dechex($c);
		}
		if (!$w)
			$w++;
		$perc[$day][$j] = $p . "%";
		$width[$day][$j] = $w;
		$color[$day][$j] = $c;
	}

	$data[$day][1] = $fun[$column[1]]($data[$day][1]);
	$data[$day][2] = $fun[$column[2]]($data[$day][2]);
	$data[$day][3] = $fun[$column[3]]($data[$day][3]);
}

$data['max'][1] = $fun[$column[1]]($maf['tab'][1]);
$data['max'][2] = $fun[$column[2]]($maf['tab'][2]);
$data['max'][3] = $fun[$column[3]]($maf['tab'][3]);

require('AccessStats_html.php');
}
echo $msg;
?>
Return current item: phpMyPrepaid