Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/statistiques/UserStats.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['start'])) $start=$_POST['start'];
if (isset($_POST['stop'])) $stop=$_POST['stop'];
if (isset($_POST['order'])) $order=$_POST['order'];
if (isset($_POST['sortby'])) $sortby=$_POST['sortby'];
if (isset($_POST['server'])) $server=$_POST['server'];
if (isset($_POST['login'])) $login=$_POST['login'];
if (isset($_POST['pagesize'])) $pagesize=$_POST['pagesize'];

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

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


$pagesize = ($pagesize) ? $pagesize : 10;
if (!is_numeric($pagesize) && $pagesize != 'all')
	$pagesize = 10;
$limit = ($pagesize == 'all') ? '' : "LIMIT $pagesize";
$selected[$pagesize] = 'selected';
$order = ($order) ? $order : 'desc';
if ($order != 'desc' && $order != 'asc')
	$order = 'desc';
if ($sortby != '')
	$order_attr = ($sortby == 'num') ? 'connnum' : 'conntotduration';
else
	$order_attr = 'connnum';
if ($server != '' && $server != 'all'){
	$server = $oreon->database->database->escape_string($server);
	$server_str = "AND nasipaddress = '$server'";
}
$login_str = ($login) ? "AND username = '$login' " : '';

$selected[$order] = 'selected';
$selected[$sortby] = 'selected';


?>

 
<table border=0 width=640 cellpadding=1 cellspacing=1>
<tr valign=top>
<td width=65%></td>
<td bgcolor="888888" width=35%>
	<table border=0 width=100% cellpadding=2 cellspacing=0>
	<tr bgcolor="#aaaaaa" align=right valign=top><th>
	<font color="white">User Statistics</font>&nbsp;
	</th></tr>
	</table>
</td></tr>
<tr bgcolor="888888" valign=top><td colspan=2>
	<table border=0 width=100% cellpadding=12 cellspacing=0 bgcolor="#e6e6e6" valign=top>
	<tr><td>
<?php
print "<b><small>$startf</small></b> up to <b><small>$stopf</small></b>";
?>

<p>
	<table border=0 bordercolordark=#e6e6e6 bordercolorlight=#000000 width=600px cellpadding=2 cellspacing=0 bgcolor="#e6e6e6" valign=top>
	<tr bgcolor="#e6e6e6">
	<small><th>#</th><th>login</th><th>date</th><th>server</th><th>connections number</th><th>connections duration</th><th>upload</th><th>download</th>
	</tr>

<?php
$search =$oreon->database->database->query("SELECT * FROM mtotacct,userinfo
	WHERE mtotacct.username=AcctDate >= '$start' AND AcctDate <= '$stop' $server_str $login_str $sql_extra_query
	ORDER BY $order_attr $order $limit;");

	if ($search){
		while( $row = $oreon->database->database->fetch_array($search) ){
			$num++;
			$acct_login = $row['username'];
			if ($acct_login == '')
				$acct_login = '-';
			else
			     $acct_login=('<input type="button" class="smallButton" name="UserSelected" value="'.$acct_login.'" onClick="window.open(\'include/divers/sexyTabs.php?phpmyprepaid='.session_id.'&usr='.$acct_login.'\',\'User informations\',\'width=800,height=600,status=yes,resizable=yes,menubar=yes,scrollbars=yes\');" >');
			$acct_time = $row['conntotduration'];
			$acct_time = time2str($acct_time);
			$acct_conn_num = $row['connnum'];
			$acct_date = $row['acctdate'];
			$acct_upload = $row['inputoctets'];
			$acct_download = $row['outputoctets'];
			$acct_upload = octets2str($acct_upload);
			$acct_download = octets2str($acct_download);
			$acct_server = $row['nasipaddress'];
			if (!isset($acct_server)){
				$acct_server = @gethostbyaddr($row['nasipaddress']);
			}
			if ($acct_server == '')
				$acct_server = '-';
			print "<tr align=center bgcolor=\"white\">
				<td>$num</td>
				<td>$acct_login</td>
				<td>$acct_date</td>
				<td>$acct_server</td>
				<td>$acct_conn_num</td>
				<td>$acct_time</td>
				<td>$acct_upload</td>
				<td>$acct_download</td>
			</tr>";
		}
	}
}
print '</table>
<hr>';

echo '<tr><td >
	<form action="phpmyprepaid" method="post" name="master">
	<table  border=0 cellspacing=0 cellpadding=2>
	<tr valign=bottom>
		<td><small><b>start date</td>
		<td><small><b>stop date</td>
		<td><small><b>user</td>
		<td>&nbsp;</td>
		</tr>
	<tr valign=middle>
	<td valign=middle>';

	echo '
		<input type="text"  width="13" name="start" id="start" size="15" value="'.$startf.'"/><button type="reset" id="f_trigger_b1">...</button>
		</span></td>';
	echo '<script type="text/javascript">
		Calendar.setup({
			inputField     :    "start",      // id of the input field
				ifFormat       :    "'.cdateformat_calendar($dateFormat).'",       // format of the input field
				showsTime      :    true,            // will display a time selector
				button         :    "f_trigger_b1",   // trigger for the calendar (button ID)
				singleClick    :    true,           // double-click mode
				step           :    1                // show all years in drop-down boxes (instead of every other year as default)
});
</script>';
		echo "<td valign=middle>";
	echo '
		<input type="text"  width="13" name="stop" id="stop" size="15" value="'.$stopf.'"/><button type="reset" id="f_trigger_b2">...</button>
		</span></td>';
	echo '<script type="text/javascript">
		Calendar.setup({
			inputField     :    "stop",      // id of the input field
				ifFormat       :    "'.cdateformat_calendar($dateFormat).'",       // format of the input field
				showsTime      :    true,            // will display a time selector
				button         :    "f_trigger_b2",   // trigger for the calendar (button ID)
				singleClick    :    true,           // double-click mode
				step           :    1                // show all years in drop-down boxes (instead of every other year as default)
});
</script>';
echo "</td>";
	
echo "<td valign=middle><input type=\"text\" name=\"login\" class=\"fieldcell\"  size=\"12\" value=$login ></td>
         </tr>
	 </tr></table><br><table width=100%>";
echo '<tr><td> Page size :	</td>';
echo "<td><select name=\"pagesize\">
<option $selected[5] value=\"5\" >05
<option $selected[10] value=\"10\">10
<option $selected[15] value=\"15\">15
<option $selected[20] value=\"20\">20
<option $selected[40] value=\"40\">40
<option $selected[80] value=\"80\">80
<option $selected[all] value=\"all\">all
</select>
</td>
<td> Sort by</td>
<td>
<select name=\"sortby\">
<option $selected[num] value=\"num\">connections number
<option $selected[time] value=\"time\">connections duration
</select>
</td>
<td> Order by</td>
<td><select name=\"order\">
<option $selected[asc] value=\"asc\">ascending
<option $selected[desc] value=\"desc\">descending
</select>
</td></tr></table><br><table><tr>";

?>

<tr><td>On Access Server:
</td>
<td>
<select name="server">
<?php
$nas_list=get_naslist($_SESSION['locID']);
foreach ($nas_list as $nas){
	$name = $nas[name];
	$servers[$name] = $nas[ip];
}
ksort($servers);
foreach ($servers as $name => $ip){
	if ($server == $ip)
		echo "<option selected value=\"$ip\">$name\n";
	else
		echo "<option value=\"$ip\">$name\n";
}
if ($server == '' || $server == 'all')
	echo "<option selected value=\"all\">all\n";
else
	echo "<option value=\"all\">all\n";
?>
</select>
</td><td align=right><input type="submit" class="smallButton" value="show"></td></tr>
</table></td></tr></form>
</table>
</tr>
</table>
Return current item: phpMyPrepaid