Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/scrape/Type.php
<?php

echo "<form  action=\"phpmyprepaid.php\" method=\"post\">";
echo "<span style=\"font-weight: bold; font-family: Arial;\"></span>
	<hr><small>";
$resultloc = getLocationName($oreon->user);
echo '<table><tr><td>Choose your Locations : </td><td>';
echo ('<select name="lsid" onchange="this.form.submit()">');
$loctmp=$loc;
if ($oreon->user->get_status()=='3') {
	if ($_GET['lsid']=="All")
	{
		echo ("<option  selected value=\"All\">All");
		$loctmp="-1";
	}
	else
		echo ("<option  value=\"All\">All");
	
}
while ($row = mysql_fetch_object($resultloc)) {
	if($loctmp==$row->ID )
	      echo ("<option selected=\"selected\" value=\"".$row->LocationName."\">".$row->LocationName);
	else
		echo ("<option  value=\"".$row->LocationName."\">".$row->LocationName);
}
echo "</td></tr></table></select><br>";
echo "<table style=\"text-align: left; height: 85px; width: 350px;\"
	border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
  <tbody><tr>";
echo "<td class=\"statcell\" style=\"width: 85px;\"><span
	style=\"font-weight: bold; font-family: Arial;\"><small>Total users :&nbsp;</small></span></td>
	<td class=\"statresult\" style=\"width: 28px;\"><small>$rnbaccount</small></td></tr><tr>
	<td class=\"statcell\"  style=\"width: 155px; \"><span
	style=\"font-weight: bold; font-family: Arial;\"><small>Total Activate
	users &nbsp; &nbsp; :&nbsp;</span></small></td>
	<td class=\"statresult\" style=\"width: 128px;\"><small>$rnbactivateaccount</small></td></tr><tr>
	<td class=\"statcell\" style=\"width: 145px;\"><span
	style=\"font-weight: bold; font-family: Arial;\"><small>Total Expired Users
	&nbsp; &nbsp; :</span>&nbsp;<small></td>
	<td class=\"statresult\" style=\"width: 128px;\"><small>$expu</small></td></tr><tr></table><br>";

echo "<table style=\"text-align: left; height: 85px; width: 650px;\"
	border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
	<tbody><tr>
	<td><span style=\"font-weight: bold; font-family: Arial;\"><small>From Date<small></span></td>
	<td><span style=\"font-weight: bold; font-family: Arial;\">";
		echo '<input type="text"  width="15" name="fromdate" id="fromdate" size="15" value="'.$startf.'"/><button type="reset" id="f_trigger_b1">...</button>
			</span></td>';
echo '<script type="text/javascript">
	Calendar.setup({
		inputField     :    "fromdate",      // 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 "</tr>
	<tr>
	<td><span style=\"font-weight: bold; font-family: Arial;\"><small>To Date</small></span></td>
	<td><span
	style=\"font-weight: bold; font-family: Arial;\">";
echo '
	<input type="text"  width="15" name="todate" id="todate" size="15" value="'.$stopf.'"/><button type="reset" id="f_trigger_b2">...</button>
	</span></td>';
echo '<script type="text/javascript">
	Calendar.setup({
		inputField     :    "todate",      // 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 "</tr>

	    <tr>
	    <td style=\"width: 103px;\">
	    <select name=\"date_search\">";
if ($date_search=="Accounting Date")
	echo "<option selected=\"selected\" >Accounting Date</option>";
else
	echo "<option >Accounting Date</option>";
if ($date_search=="Login Date")
	echo "<option  selected=\"selected\" >Login Date</option>";
else 
	echo "<option>Login Date</option>";
if ($date_search=="Creation Date")
	echo "<option  selected=\"selected\" >Creation Date</option>";
else
	echo "<option>Creation Date</option>";

     echo "/select>
	     </td>
	     <td style=\"width: 155px;\"><span
	     style=\"font-weight: bold; font-family: Arial;\"><input
	     class=\"smallButton\" type=\"submit\" name=\"stat_boutton\" value=\"Search\"></span></td>
	     <input type=\"hidden\" name=\"buttonID\" value=\"stat_button\">
	     </tr>
	     
	     </tbody>
	     </table>";

echo '<table cellpadding="7" cellspacing="10"><tr>';
echo('<td> Use graphics view :</td><td>');
if ($check_graphic)
	echo ('<input type="checkbox" checked name="check_graphic" onChange=\'this.form.submit()\'>');
else
	echo ('<input type="checkbox" name="check_graphic" onChange=\'this.form.submit()\'>');
echo('</td>');
echo('<td style="margin-left: 390px;">Plot : </td><td>');
echo ('<select name="plot_graphic" id="plot_graphic" onChange=\'this.form.submit()\' >');

if ($plot_graphic=="bars") 
	echo ("<option selected value=\"bars\">Bars</option>");
else  
	echo ("<option value=\"bars\">Bars</option>");

if ($plot_graphic=="lines") echo ("<option selected value=\"lines\">Lines</option>");
else echo ("<option value=\"lines\">Lines</option>");

if ($plot_graphic=="linepoint") echo ("<option selected value=\"linepoint\">Lines point</option>");
else echo ("<option value=\"linepoint\">Lines point</option>");

if ($plot_graphic=="area") echo ("<option selected value=\"area\">Area</option>");
else echo ("<option value=\"area\">Area</option>");

if ($plot_graphic=="points") echo ("<option selected value=\"points\">Points</option>");
else echo ("<option value=\"points\">Points</option>");

if ($plot_graphic=="pie") echo ("<option selected value=\"pie\">Pie</option>"); 
else echo ("<option value=\"pie\">Pie</option>");

if ($plot_graphic=="thinbarline") echo ("<option selected value=\"thinbarline\">Thinbarline</option>");
else echo ("<option value=\"thinbarline\">Thinbarline</option>");

if ($plot_graphic=="squared") echo ("<option selected value=\"squared\">Squared</option>");
else echo ("<option value=\"squared\">Squared</option>");

if ($plot_graphic=="stackedbars") echo ("<option selected value=\"stackedbars\">Stacked bars</option>");
else echo ("<option value=\"stackedbars\">Stacked bars</option>");

echo '</select></td>';
echo ('</tr></table></form>');

echo "<hr>
	<br>";

//CHECK GRAPHIC IS ON, WE DISPLAY
if($check_graphic) {
	

	$sumsession=0;
	$sumin=0;
	$sumout=0;
	$sumact=0;
	$total=0;
	$totalu=0;
	$res="SELECT * FROM userinfo WHERE BillingPlan='0' $locstr GROUP BY UserName";
	if ($date_search=="Login Date" OR $date_search=="Creation Date")
	{
		$res2="SELECT userinfo.UserName AS val FROM userinfo WHERE BillingPlan='0' OR BillingPlan='' AND activated='1' $locstr $search_attribute GROUP BY UserName";
		$resq2= mysql_query($res2) or die(mysql_error());
		$res4 = "SELECT userinfo.UserName,Type FROM userinfo WHERE BillingPlan='$row->Id' $locstr  $search_attribute GROUP BY UserName ;";
	}
	else
	{
		$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";
		$resq2= mysql_query($res2) or die(mysql_error());
		$res4 = "SELECT userinfo.UserName,Type from userinfo,radacct where  radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' $search_attribute $locstr GROUP BY userinfo.UserName ;";
	}
	$res3 = "SELECT acctsessiontime AS sum_sess_time,
		acctinputoctets AS sum_in_octets,
		acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan;";
	$resq1= mysql_query($res) or die(mysql_error());
	$resq3= mysql_query($res3) or die(mysql_error());
	$r2=mysql_num_rows($resq2); 
	$r1=mysql_num_rows($resq1);
	$res1f=0;
	$res2f=0;
	$res3f=0;
	while ($r3=mysql_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=time2str($res1f);
	$res2=bytes2str($res2f);
	$res3=bytes2str($res3f);
	$array=expiredUser("",$res4);
	$eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
	$teu+=$eu;
/*
	echo "<tr>
	<td class=\"statcell\" ><small>None</small></td>
	<td class=\"statresult\"  style=\"width: 9px;\"><small>$r2</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$eu</small></td>
	<td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
	<td class=\"statresult\" style=\"width: 70px;\"><small>$res2</small></td>
	<td class=\"statresult\" style=\"width: 70px;\"><small>$res3</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$cnt</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$r1</small></td>
	</tr>";
 */
	
	while ($row = mysql_fetch_object($result)) {
		
		$res="SELECT COUNT(*) AS val FROM userinfo WHERE  BillingPlan='$row->Id'  $locstr GROUP BY UserName";
		if ($date_search=="Login Date" OR $date_search=="Creation Date")
		{
			$res2="SELECT COUNT(*) AS val FROM userinfo WHERE BillingPlan='$row->Id' AND activated='1' $locstr $search_attribute GROUP BY UserName";
			$resq2= mysql_query($res2) or die(mysql_error());
			$res4 = "SELECT userinfo.UserName,Type FROM userinfo WHERE BillingPlan='$row->Id' $locstr $search_attribute GROUP BY userinfo.UserName ;";
		}
		else
		{
			$res2="SELECT userinfo.UserName AS val FROM userinfo,radacct WHERE radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' AND activated='1' $locstr $search_attribute GROUP BY userinfo.UserName";
			$resq2= mysql_query($res2) or die(mysql_error());
			$res4 = "SELECT userinfo.UserName,Type FROM userinfo,radacct where  radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id'$locstr $search_attribute GROUP BY userinfo.UserName ;";
		}
		$res3 = "SELECT acctsessiontime AS sum_sess_time,
			acctinputoctets AS sum_in_octets,
			acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE BillingPlan='$row->Id' AND  radacct.UserName=userinfo.UserName $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan";
		
		
		$resq1= mysql_query($res) or die(mysql_error());
		$resq3= mysql_query($res3) or die(mysql_error());
		
		$r2=mysql_num_rows($resq2);  
		$r1=mysql_num_rows($resq1);
		$res1f=0;
		$res2f=0;
		$res3f=0;
		$cnt=0;
		
		while ($r3=mysql_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=time2str($res1f);
		$res2=bytes2str($res2f);
		$res3=bytes2str($res3f);
		
		$array=expiredUser("",$res4);
		$eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
		$teu+=$eu;
/*
	echo "<tr>
	<td class=\"statcell\" style=\"width: 91px;\"><small>$row->NameBp</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$r2</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$eu</small></td>
	<td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
	<td class=\"statresult\" style=\"width: 70px;\"><small>$res2</small></td>
	<td class=\"statresult\" style=\"width: 70px;\"><small>$res3</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$cnt</small></td>
	<td class=\"statresult\" style=\"width: 9px;\"><small>$r1</small></td>
	</tr>";
 */
	}		
$sumsession=time2str($sumsession);
$sumout=bytes2str($sumout);
$sumin=bytes2str($sumin);
/*
echo "<tr style=\"font-family: Arial; font-weight: bold;\">
<td class=\"statcell\" style=\"width: 91px;\"><small>Total</small> </td>
      <td style=\"width: 9px;\"><small>$sumact</small></td>
      <td style=\"width: 9px;\"><small>$teu</small></td>
      <td style=\"width: 233px;\"><small>$sumsession</small></td>
      <td style=\"width: 70px;\"><small>$sumin</small></td>
      <td style=\"width: 70px;\"><small>$sumout</small></td>
      <td style=\"width: 9px;\"><small>$total</small></td>
      <td style=\"width: 9px;\"><small>$totalu</small></td>
      </tr>";

echo "</tbody>
</table>
<br>
<br>
<span style=\"font-family: Times; font-size: 18px; font-weight: bold;\">Stat for user of type&nbsp; :</span><br>
";

echo "<table
	style=\"text-align: left; font-family: Arial; width: 650px; height: 58px;\"
	border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
	<tbody>
	<tr style=\"font-weight: bold;\">
	<td class=\"statcell\" tyle=\"width: 200px;\"><small>Type</small></td>
	<td class=\"statcell\" style=\"width: 9px;\"><small>Activate Users</small></td>
	<td class=\"statcell\" style=\"width: 9px;\"><small>Expired Users</small></td>
	<td class=\"statcell\" style=\"width: 233x;\"><small>Session Time</small></td>
	<td class=\"statcell\" style=\"width: 70px;\"><small>Upload</small></td>
	<td class=\"statcell\" style=\"width: 70px;\"><small>Download</small></td>
	<td class=\"statcell\" style=\"width: 9px;\"><small>Session</small></td>
	<td class=\"statcell\" style=\"width: 9px;\"><small>User Number</small></td>
	</tr>
	";
*/
$sumsession=0;
$sumin=0;
$sumout=0;
$sumact=0;
$total=0;
$totalu=0;
$count=0;
$teu=0;
$resq2=0;
while ($row2 = mysql_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= mysql_query($res2) or die(mysql_error());
  
   $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= mysql_query($res2) or die(mysql_error());
 $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 acctsessiontime AS sum_sess_time,
         acctinputoctets AS sum_in_octets,
        acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND Type='$row2->Type' $locstr $search_attribute GROUP BY AcctSessionId,Type";

$resq3= mysql_query($res3) or die(mysql_error());
$r2=mysql_num_rows($resq2);  
$res1f=0;
$res2f=0;
$res3f=0;
$count=0;
while ($r3=mysql_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=time2str($res1f);
  $res2=bytes2str($res2f);
  $res3=bytes2str($res3f);
  $array=expiredUser("",$res4);
  $eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
  $teu+=$eu;
/*
echo "<tr>
<td class=\"statcell\" style=\"width: 101px;\"><small>$row2->Type</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$r2</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$eu</small></td>
      <td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
      <td class=\"statresult\" style=\"width: 65px;\"><small>$res2</small></td>
      <td class=\"statresult\" style=\"width: 65px;\"><small>$res3</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$count</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$row2->cuser</small></td>
      </tr>";
 */
}

$sumsession=time2str($sumsession);
$sumout=bytes2str($sumout);
$sumin=bytes2str($sumin);
/*
echo "<tr style=\"font-family: Arial; font-weight: bold;\">
<td class=\"statcell\" style=\"width: 101px;\"><small>Total</small> </td>
      <td style=\"width: 19px;\"><small>$sumact</small></td>
      <td style=\"width: 19px;\"><small>$teu</small></td>
      <td style=\"width: 233px;\"><small>$sumsession</small></td>
      <td style=\"width: 65px;\"><small>$sumin</small></td>
      <td style=\"width: 65px;\"><small>$sumout</small></td>
      <td style=\"width: 19px;\"><small>$total</small></td>
      <td style=\"width: 19px;\"><small>$totalu</small></td>
      </tr>";*/
echo"</tbody>
</table>
<br style=\"font-family: Arial;\">";
	echo '<table><tr><td>';
	echo '<img src="include/statistiques/GenerateStat.php?width=330&&height=250&&plot_type='.$plot_graphic.'&&typegr=\'Time\'&&basetime=Year&&puser=" alt="User statistiques">';

echo '</td><td>';
	echo '<img src="include/statistiques/GenerateStat.php?width=330&&height=250&&plot_type='.$plot_graphic.'&&typegr=\'Octet\'&&basetime=Year&&puser=" alt="User statistiques">';
echo '</tr></td></table>';
}
else
{	
echo "<span style=\"font-family: Times; font-size: 18px; font-weight: bold;\">Stat for billing plan :</span><br>
<table
 style=\"text-align: left; width: 650px; height: 58px; font-family: Arial;\"
 border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
 <tbody>    <tr style=\"font-weight: bold;\">
 <td class=\"statcell\" style= width: 200px; \"font-weight: bold;\"><small>Billing Plan</small></td>	
 <td class=\"statcell\" style=\"width: 19px; font-weight: bold;\"><small>Activate Users<small></td>
 <td class=\"statcell\" style=\"width: 19px; font-weight: bold;\"><small>Expired Users<small></td>
<td class=\"statcell\" style=\"width: 233px; style=\"font-weight: bold;\"><small>Session Time</small></td>
<td class=\"statcell\" style=\"width: 70px; style=\"font-weight: bold;\"><small>Upload</small></td>
<td class=\"statcell\" style=\"width: 70px; style=\"font-weight: bold;\"><small>Download</small></td>
<td class=\"statcell\" style=\"width: 19px;\"><span style=\"font-weight: bold;\"><small>Session</small></span></td>
<td class=\"statcell\" style=\"width: 19px;\"><span style=\"font-weight: bold;\"><small>User Number</small></span></td>
</tr>";

$sumsession=0;
$sumin=0;
$sumout=0;
$sumact=0;
$total=0;
$totalu=0;
$res="SELECT * FROM userinfo WHERE BillingPlan='0' $locstr GROUP BY UserName";
if ($date_search=="Login Date" OR $date_search=="Creation Date")
{
 $res2="SELECT userinfo.UserName AS val FROM userinfo WHERE BillingPlan='0' OR BillingPlan='' AND activated='1' $locstr $search_attribute GROUP BY UserName";
 $resq2= mysql_query($res2) or die(mysql_error());
 $res4 = "SELECT userinfo.UserName,Type FROM userinfo WHERE BillingPlan='$row->Id' $locstr  $search_attribute GROUP BY UserName ;";
 }
 else
 {
   $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";
   $resq2= mysql_query($res2) or die(mysql_error());
   $res4 = "SELECT userinfo.UserName,Type from userinfo,radacct where  radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' $search_attribute $locstr GROUP BY userinfo.UserName ;";
   }
$res3 = "SELECT acctsessiontime AS sum_sess_time,
         acctinputoctets AS sum_in_octets,
         acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan;";
$resq1= mysql_query($res) or die(mysql_error());
$resq3= mysql_query($res3) or die(mysql_error());
$r2=mysql_num_rows($resq2); 
$r1=mysql_num_rows($resq1);
$res1f=0;
$res2f=0;
$res3f=0;
while ($r3=mysql_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=time2str($res1f);
 $res2=bytes2str($res2f);
 $res3=bytes2str($res3f);
 $array=expiredUser("",$res4);
 $eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
$teu+=$eu;

echo "<tr>
<td class=\"statcell\" ><small>None</small></td>
      <td class=\"statresult\"  style=\"width: 9px;\"><small>$r2</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$eu</small></td>
      <td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
      <td class=\"statresult\" style=\"width: 70px;\"><small>$res2</small></td>
      <td class=\"statresult\" style=\"width: 70px;\"><small>$res3</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$cnt</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$r1</small></td>
    </tr>";


while ($row = mysql_fetch_object($result)) {
  
  $res="SELECT COUNT(*) AS val FROM userinfo WHERE  BillingPlan='$row->Id'  $locstr GROUP BY UserName";
  if ($date_search=="Login Date" OR $date_search=="Creation Date")
  {
  $res2="SELECT COUNT(*) AS val FROM userinfo WHERE BillingPlan='$row->Id' AND activated='1' $locstr $search_attribute GROUP BY UserName";
   $resq2= mysql_query($res2) or die(mysql_error());
 $res4 = "SELECT userinfo.UserName,Type FROM userinfo WHERE BillingPlan='$row->Id' $locstr $search_attribute GROUP BY userinfo.UserName ;";
  }
  else
  {
   $res2="SELECT userinfo.UserName AS val FROM userinfo,radacct WHERE radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id' AND activated='1' $locstr $search_attribute GROUP BY userinfo.UserName";
   $resq2= mysql_query($res2) or die(mysql_error());
$res4 = "SELECT userinfo.UserName,Type FROM userinfo,radacct where  radacct.UserName=userinfo.UserName AND BillingPlan='$row->Id'$locstr $search_attribute GROUP BY userinfo.UserName ;";
  }
   $res3 = "SELECT acctsessiontime AS sum_sess_time,
         acctinputoctets AS sum_in_octets,
       acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE BillingPlan='$row->Id' AND  radacct.UserName=userinfo.UserName $locstr $search_attribute  GROUP BY AcctUniqueId,BillingPlan";
 
    	
  $resq1= mysql_query($res) or die(mysql_error());
  $resq3= mysql_query($res3) or die(mysql_error());
  
  $r2=mysql_num_rows($resq2);  
  $r1=mysql_num_rows($resq1);
$res1f=0;
$res2f=0;
$res3f=0;
$cnt=0;

while ($r3=mysql_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=time2str($res1f);
  $res2=bytes2str($res2f);
  $res3=bytes2str($res3f);

  $array=expiredUser("",$res4);
  $eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
  $teu+=$eu;
echo "<tr>
<td class=\"statcell\" style=\"width: 91px;\"><small>$row->NameBp</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$r2</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$eu</small></td>
      <td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
      <td class=\"statresult\" style=\"width: 70px;\"><small>$res2</small></td>
      <td class=\"statresult\" style=\"width: 70px;\"><small>$res3</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$cnt</small></td>
      <td class=\"statresult\" style=\"width: 9px;\"><small>$r1</small></td>
    </tr>";
}
$sumsession=time2str($sumsession);
$sumout=bytes2str($sumout);
$sumin=bytes2str($sumin);

echo "<tr style=\"font-family: Arial; font-weight: bold;\">
<td class=\"statcell\" style=\"width: 91px;\"><small>Total</small> </td>
      <td style=\"width: 9px;\"><small>$sumact</small></td>
      <td style=\"width: 9px;\"><small>$teu</small></td>
      <td style=\"width: 233px;\"><small>$sumsession</small></td>
      <td style=\"width: 70px;\"><small>$sumin</small></td>
      <td style=\"width: 70px;\"><small>$sumout</small></td>
      <td style=\"width: 9px;\"><small>$total</small></td>
      <td style=\"width: 9px;\"><small>$totalu</small></td>
      </tr>";

echo "</tbody>
</table>
<br>
<br>
<span style=\"font-family: Times; font-size: 18px; font-weight: bold;\">Stat for user of type&nbsp; :</span><br>

<table
 style=\"text-align: left; font-family: Arial; width: 650px; height: 58px;\"
 border=\"1\" cellpadding=\"2\" cellspacing=\"2\">
  <tbody>
    <tr style=\"font-weight: bold;\">
    <td class=\"statcell\" tyle=\"width: 200px;\"><small>Type</small></td>
      <td class=\"statcell\" style=\"width: 9px;\"><small>Activate Users</small></td>
      <td class=\"statcell\" style=\"width: 9px;\"><small>Expired Users</small></td>
      <td class=\"statcell\" style=\"width: 233x;\"><small>Session Time</small></td>
      <td class=\"statcell\" style=\"width: 70px;\"><small>Upload</small></td>
      <td class=\"statcell\" style=\"width: 70px;\"><small>Download</small></td>
      <td class=\"statcell\" style=\"width: 9px;\"><small>Session</small></td>
      <td class=\"statcell\" style=\"width: 9px;\"><small>User Number</small></td>
    </tr>
";

$sumsession=0;
$sumin=0;
$sumout=0;
$sumact=0;
$total=0;
$totalu=0;
$count=0;
$teu=0;
$resq2=0;
while ($row2 = mysql_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= mysql_query($res2) or die(mysql_error());
  
   $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= mysql_query($res2) or die(mysql_error());
 $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 acctsessiontime AS sum_sess_time,
         acctinputoctets AS sum_in_octets,
        acctoutputoctets AS sum_out_octets FROM radacct,userinfo WHERE radacct.UserName=userinfo.UserName AND Type='$row2->Type' $locstr $search_attribute GROUP BY AcctSessionId,Type";

$resq3= mysql_query($res3) or die(mysql_error());
$r2=mysql_num_rows($resq2);  
$res1f=0;
$res2f=0;
$res3f=0;
$count=0;
while ($r3=mysql_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=time2str($res1f);
  $res2=bytes2str($res2f);
  $res3=bytes2str($res3f);
  $array=expiredUser("",$res4);
  $eu=count($array['time'])+count($array['octet'])+count($array['expiration']);
  $teu+=$eu;
echo "<tr>
<td class=\"statcell\" style=\"width: 101px;\"><small>$row2->Type</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$r2</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$eu</small></td>
      <td class=\"statresult\" style=\"width: 233px;\"><small>$res1</small></td>
      <td class=\"statresult\" style=\"width: 65px;\"><small>$res2</small></td>
      <td class=\"statresult\" style=\"width: 65px;\"><small>$res3</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$count</small></td>
      <td class=\"statresult\" style=\"width: 19px;\"><small>$row2->cuser</small></td>
    </tr>";
}
$sumsession=time2str($sumsession);
$sumout=bytes2str($sumout);
$sumin=bytes2str($sumin);

echo "<tr style=\"font-family: Arial; font-weight: bold;\">
<td class=\"statcell\" style=\"width: 101px;\"><small>Total</small> </td>
      <td style=\"width: 19px;\"><small>$sumact</small></td>
      <td style=\"width: 19px;\"><small>$teu</small></td>
      <td style=\"width: 233px;\"><small>$sumsession</small></td>
      <td style=\"width: 65px;\"><small>$sumin</small></td>
      <td style=\"width: 65px;\"><small>$sumout</small></td>
      <td style=\"width: 19px;\"><small>$total</small></td>
      <td style=\"width: 19px;\"><small>$totalu</small></td>
      </tr>";
echo"</tbody>
</table>
<br style=\"font-family: Arial;\">";
}
echo "<br style=\"font-family: Arial;\"><small><b>Note</b> If you choose Accounting Date, only users who have been connected are shown in this table";
?>

Return current item: phpMyPrepaid