Location: PHPKode > projects > phpMyPrepaid > phpmyprepaid/www/include/tabs/c.php
<?php
$date = strftime('%A, %e %B %Y, %T %Z');

$remaining = 'unlimited time';
$log_color = 'green';
$logged_now=0;
$now = time();
$week = $now - 604800;
$now_str = date("$sql_date_format",$now + 86400);
$week_str = date("$sql_date_format",$week);
$day = date('w');
$week_start = date($sql_date_format,$now - ($day)*86400);
$month_start = date($sql_date_format,$now - date('j')*86400);
$today = $day;
$now_tmp = $now;
for ($i = $day; $i >-1; $i--){
	$days[$i] = date($sql_date_format,$now_tmp);
	$now_tmp -= 86400;
}
$day++;
//$now -= ($day * 86400);
$now -= 604800;
$now += 86400;
for ($i = $day; $i <= 6; $i++){
	$days[$i] = date($sql_date_format,$now);
//	$now -= 86400;
	$now += 86400;
}

$daily_used = $weekly_used = $monthly_used = $lastlog_session_time = '-';
$extra_msg = '';
$used = array('-','-','-','-','-','-','-');
//WEEKKKKK SEARCH
$search = "SELECT sum(acctsessiontime) AS sum_sess_time,
	sum($acctinputoctetsattr) AS sum_in_octets,
	sum($acctoutputoctetsattr) AS sum_out_octets,
	avg(acctsessiontime) AS avg_sess_time,
	avg($acctinputoctetsattr) AS avg_in_octets,
	avg($acctoutputoctetsattr) AS avg_out_octets,
	COUNT(*) as counter FROM $sql_accounting_table WHERE username = '$pullUser' AND acctstarttime >= '$week_str' AND acctstarttime <= '$now_str';";
	
	$result = $oreon->database->database->query($search) or die("Query database error !");
	
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$sum_time=$row['sum_sess_time'];
		$tot_time = time2str($row['sum_sess_time']);
		$tot_input = octets2str($row['sum_in_octets']);
		$tot_output = octets2str($row['sum_out_octets']);
		$avg_time = time2str($row['avg_sess_time']);
		$avg_input = octets2str($row['avg_in_octets']);
		$avg_output = octets2str($row['avg_out_octets']);
		$tot_conns = $row['counter'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";
	
//MONTH SEARCH
$search = "SELECT sum(acctsessiontime) AS sum_sess_time,
	sum($acctinputoctetsattr) AS sum_in_octets,
	sum($acctoutputoctetsattr) AS sum_out_octets,
	avg(acctsessiontime) AS avg_sess_time,
	avg($acctinputoctetsattr) AS avg_in_octets,
	avg($acctoutputoctetsattr) AS avg_out_octets,
	COUNT(*) as counter FROM $sql_accounting_table WHERE username = '$pullUser' AND acctstarttime >= '$month_start' AND acctstarttime <= '$now_str';";
	
	$result = $oreon->database->database->query($search) or die("Query database error !");
	
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$sum_timem=$row['sum_sess_time'];
		$tot_timem = time2str($row['sum_sess_time']);
		$tot_inputm = octets2str($row['sum_in_octets']);
		$tot_outputm = octets2str($row['sum_out_octets']);
		$avg_timem = time2str($row['avg_sess_time']);
		$avg_inputm = octets2str($row['avg_in_octets']);
		$avg_outputm = octets2str($row['avg_out_octets']);
		$tot_connsm = $row['counter'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";


//GLOBAL SEARCH
$search = "SELECT sum(acctsessiontime) AS sum_sess_time,
	sum($acctinputoctetsattr) AS sum_in_octets,
	sum($acctoutputoctetsattr) AS sum_out_octets,
	avg(acctsessiontime) AS avg_sess_time,
	avg($acctinputoctetsattr) AS avg_in_octets,
	avg($acctoutputoctetsattr) AS avg_out_octets,
	COUNT(*) as counter FROM $sql_accounting_table WHERE username = '$pullUser';";
	
	$result = $oreon->database->database->query($search) or die("Query database error !");
	
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$sum_timeg=$row['sum_sess_time'];
		$tot_timeg = time2str($row['sum_sess_time']);
		$tot_inputg = octets2str($row['sum_in_octets']);
		$tot_outputg = octets2str($row['sum_out_octets']);
		$tot_outputgb = $row['sum_out_octets'];
		$avg_timeg = time2str($row['avg_sess_time']);
		$avg_inputg = octets2str($row['avg_in_octets']);
		$avg_outputg = octets2str($row['avg_out_octets']);
		$tot_connsg = $row['counter'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";


	$search ="SELECT sum(acctsessiontime) AS sum_sess_time FROM $sql_accounting_table WHERE username = '$pullUser'
	AND acctstarttime >= '$week_start' AND acctstarttime <= '$now_str';";

	$result = $oreon->database->database->query($search) or die("Query database error !");
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$weekly_used = $row['sum_sess_time'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";
	

//WEEK BAD LOGINS
	$search = "SELECT COUNT(*) AS counter FROM $sql_accounting_table WHERE username = '$pullUser'
	AND acctstoptime >= '$week_str' AND acctstoptime <= '$now_str'
	AND (acctterminatecause LIKE 'Login-Incorrect%' OR
	acctterminatecause LIKE 'Invalid-User%' OR
	acctterminatecause LIKE 'Multiple-Logins%');";


	$result = $oreon->database->database->query($search) or die("Query database error !");
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$tot_badlogins = $row['counter'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";

//GLOBAL BAD LOGINS
	$search = "SELECT COUNT(*) AS counter FROM $sql_accounting_table WHERE username = '$pullUser'
	AND (acctterminatecause LIKE 'Login-Incorrect%' OR
	acctterminatecause LIKE 'Invalid-User%' OR
	acctterminatecause LIKE 'Multiple-Logins%');";


	$result = $oreon->database->database->query($search) or die("Query database error !");
	if ($search){
		$row = array_change_key_case($oreon->database->database->fetch_array($result));
		$tot_badloginsg = $row['counter'];
	}
	else
		echo "<b>Database query failed: </b><br>\n";


	$search = "SELECT * FROM $sql_accounting_table
	WHERE username = '$pullUser' AND acctstoptime IS NULL
	ORDER BY acctstarttime DESC LIMIT 1;";

$lastlog_time=0;
$not_known=0;
	$result = $oreon->database->database->query($search) or die("Query database error !");
	if ($result){
			
		if ($oreon->database->database->result_num_rows($result)){
			$logged_now = 1;
			$row =array_change_key_case($oreon->database->database->fetch_array($result)); 
			$lastlog_time = $row['acctstarttime'];
			$lastlog_server_ip = $row['nasipaddress'];
			$lastlog_server_port = $row['nasportid'];
			$lastlog_session_time = date2timediv($lastlog_time,0);
			$lastlog_session_time_jvs = 1000 * $lastlog_session_time;
			$lastlog_session_time = time2strclock($lastlog_session_time);
			$lastlog_client_ip = $row['framedipaddress'];	
			$lastlog_server_name = @gethostbyaddr($lastlog_server_ip);
			$lastlog_client_name = @gethostbyaddr($lastlog_client_ip);
			$lastlog_callerid = $row['callingstationid'];
			if ($lastlog_callerid == '')
				$lastlog_callerid = 'not available';
			$lastlog_input = $row[$acctinputoctetsattr];
			if ($lastlog_input)
				$lastlog_input = octets2str($lastlog_input);
			else
				$lastlog_input = 'not available';
			$lastlog_output = $row[$acctoutputoctetsattr];
			if ($lastlog_output)
				$lastlog_input = octets2str($lastlog_output);
			else
				$lastlog_output = 'not available';
		}
	}
	else
		echo "<b>Database query failed: </b><br>\n";
	if (! $logged_now){
		$search = "SELECT * FROM $sql_accounting_table
		WHERE username = '$pullUser' AND acctsessiontime != '0'
		ORDER BY acctstoptime DESC LIMIT 1;";
	
		$result = $oreon->database->database->query($search) or die("Query database error !");
		if ($search){
			if ($oreon->database->database->result_num_rows($result)){
				$row = array_change_key_case($oreon->database->database->fetch_array($result));
				$lastlog_time = $row['acctstarttime'];
				$lastlog_server_ip = $row['nasipaddress'];
				$lastlog_server_port = $row['nasportid'];
				$lastlog_session_time = time2str($row['acctsessiontime']);
				$lastlog_client_ip = $row['framedipaddress'];	
				$lastlog_server_name = ($lastlog_server_ip != '') ? gethostbyaddr($lastlog_server_ip) : '-';
				$lastlog_client_name = ($lastlog_client_ip != '') ? gethostbyaddr($lastlog_client_ip) : '-';
				$lastlog_callerid = $row['callingstationid'];
				if ($lastlog_callerid == '')
					$lastlog_callerid = 'not available';
				$lastlog_input = $row[$acctinputoctetsattr];
				$lastlog_input = octets2str($lastlog_input);
				$lastlog_output = $row[$acctoutputoctetsattr];
				$lastlog_output = octets2str($lastlog_output);
			}
			else
				$not_known = 1;
		}
		else
			echo "<b>Database query failed: </b><br>\n";
	}
//echo "MAX ".$Max;
if ($Type=="Hourly" or $Type=="Subscription Time") {
	if ((($Max)-$sum_timeg)>0){
       		$remaining=(time2str(($Max)-$sum_timeg));
	      	$extra_msg=" !!!!!!!";
		}
	     
       if ($remaining<=0)
        echo "The user account is expired !!!! ";
	  else
	  {	
           echo "The user can login for <font color=\"$log_color\"> <b>$remaining  $extra_msg</font>";
	   }
	 }
	       
else if ($Type=="Octets" or $Type=="Subscription Octets")
     {
       $remaining=(($Max)-$tot_outputgb);
       if ($remaining<=0)
        echo "The user account is expired !!!! ";
        else
	{
        $remaining=octets2str($remaining); 
        echo "The user can Download for <font color=\"$log_color\"> <b>$remaining  $extra_msg</font>";
	}
      }
else if ($Type=="Subscription Expiration" or $Type=="Expiration")
     {
     if (date_compare(date($dateFormat),$Max)>0)
      $msg=0;
     else
      $msg=date_display(strtotime($Max));
      //$msg=date_from_attribute($Max,$dateFormat); 
      
     if ($msg=='0')
	echo "The user account is expired !!!! ";
	else		
	echo "The user account will expire in  <font color=\"$log_color\"> <b>$msg</font>";
     }

include("c_html.php");     
?>
Return current item: phpMyPrepaid