From 74c700c2e8559bb13eb5bf1e9cc8cef36b488477 Mon Sep 17 00:00:00 2001
From: Robert Anderson <randerson@lbsd.net>
Date: Wed, 4 Nov 2009 11:26:55 +0000
Subject: [PATCH] Use ceil while calculating instead of using it on the total

---
 .../include/ajax/functions/AdminUserLogs.php  | 45 +++++++------------
 .../include/ajax/functions/WiSPUserLogs.php   | 45 +++++++------------
 2 files changed, 30 insertions(+), 60 deletions(-)

diff --git a/webgui/include/ajax/functions/AdminUserLogs.php b/webgui/include/ajax/functions/AdminUserLogs.php
index 66019395..857eda47 100644
--- a/webgui/include/ajax/functions/AdminUserLogs.php
+++ b/webgui/include/ajax/functions/AdminUserLogs.php
@@ -168,41 +168,30 @@ function getAdminUserLogsSummary($params) {
 	while ($row = $res->fetchObject()) {
 
 		# Traffic in
-		$inputDataItem = 0;
 		if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
-			$inputDataItem += ($row->acctinputoctets / 1024) / 1024;
+			$totalTraffic += ceil($row->acctinputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
-			$inputDataItem += ($row->acctinputgigawords * 4096);
+			$totalTraffic += ceil($row->acctinputgigawords * 4096);
 		}
-		$totalTraffic += $inputDataItem;
-
 		# Traffic out
-		$outputDataItem = 0;
 		if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
-			$outputDataItem += ($row->acctoutputoctets / 1026) / 1024;
+			$totalTraffic += ceil($row->acctoutputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
-			$outputDataItem += ($row->acctoutputgigawords * 4096);
+			$totalTraffic += ceil($row->acctoutputgigawords * 4096);
 		}
-		$totalTraffic += $outputDataItem;
 
 		# Uptime
 		$sessionTimeItem = 0;
 		if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
-			$sessionTimeItem += $row->acctsessiontime;
+			$totalUptime += ceil($row->acctsessiontime / 60);
 		}
-
-		$totalUptime += $sessionTimeItem;
 	}
 
-	# Round up usage
-	$totalTraffic = (int)ceil($totalTraffic);
-	$totalUptime = (int)ceil($totalUptime / 60);
-
 	# Add usage to our return array
-	$resultArray['trafficUsage'] = $totalTraffic;
-	$resultArray['uptimeUsage'] = $totalUptime;
+	$resultArray['trafficUsage'] = (int)$totalTraffic;
+	$resultArray['uptimeUsage'] = (int)$totalUptime;
 
 	# Loop through topups and add to return array
 	$resultArray['trafficTopups'] = 0;
@@ -278,30 +267,26 @@ function getAdminUserLogs($params) {
 
 		# Input
 		$acctInputMbyte = 0;
-
 		if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
-			$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
+			$acctInputMbyte += ceil($row->acctinputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
-			$acctInputMbyte += ($row->acctinputgigawords * 4096);
+			$acctInputMbyte += ceil($row->acctinputgigawords * 4096);
 		}
-
 		# Output
 		$acctOutputMbyte = 0;
-
 		if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
-			$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
+			$acctOutputMbyte += ceil($row->acctoutputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
-			$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
+			$acctOutputMbyte += ceil($row->acctoutputgigawords * 4096);
 		}
 
 		# Uptime
 		$acctSessionTime = 0;
 		if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
-			$acctSessionTime += ($row->acctsessiontime / 60);
+			$acctSessionTime += ceil($row->acctsessiontime / 60);
 		}
-		ceil($acctSessionTime);
 
 		# Build array for this row
 		$item = array();
@@ -320,9 +305,9 @@ function getAdminUserLogs($params) {
 		$item['CalledStationID'] = $row->calledstationid;
 		$item['AcctSessionID'] = $row->acctsessionid;
 		$item['FramedIPAddress'] = $row->framedipaddress;
-		$item['AcctInputMbyte'] = $acctInputMbyte;
-		$item['AcctOutputMbyte'] = $acctOutputMbyte;
-		$item['AcctSessionTime'] = $acctSessionTime;
+		$item['AcctInputMbyte'] = (int)$acctInputMbyte;
+		$item['AcctOutputMbyte'] = (int)$acctOutputMbyte;
+		$item['AcctSessionTime'] = (int)$acctSessionTime;
 		$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
 
 		# Push this row onto main array
diff --git a/webgui/include/ajax/functions/WiSPUserLogs.php b/webgui/include/ajax/functions/WiSPUserLogs.php
index 90287a59..a67e775d 100644
--- a/webgui/include/ajax/functions/WiSPUserLogs.php
+++ b/webgui/include/ajax/functions/WiSPUserLogs.php
@@ -168,41 +168,30 @@ function getWiSPUserLogsSummary($params) {
 	while ($row = $res->fetchObject()) {
 
 		# Traffic in
-		$inputDataItem = 0;
 		if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
-			$inputDataItem += ($row->acctinputoctets / 1024) / 1024;
+			$totalTraffic += ceil($row->acctinputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
-			$inputDataItem += ($row->acctinputgigawords * 4096);
+			$totalTraffic += ceil($row->acctinputgigawords * 4096);
 		}
-		$totalTraffic += $inputDataItem;
-
 		# Traffic out
-		$outputDataItem = 0;
 		if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
-			$outputDataItem += ($row->acctoutputoctets / 1024) / 1024;
+			$totalTraffic += ceil($row->acctoutputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
-			$outputDataItem += ($row->acctoutputgigawords * 4096);
+			$totalTraffic += ceil($row->acctoutputgigawords * 4096);
 		}
-		$totalTraffic += $outputDataItem;
 
 		# Uptime
 		$sessionTimeItem = 0;
 		if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
-			$sessionTimeItem += $row->acctsessiontime;
+			$totalUptime += ceil($row->acctsessiontime / 60);
 		}
-
-		$totalUptime += $sessionTimeItem;
 	}
 
-	# Round up usage
-	$totalTraffic = (int)ceil($totalTraffic);
-	$totalUptime = (int)ceil($totalUptime / 60);
-
 	# Add usage to our return array
-	$resultArray['trafficUsage'] = $totalTraffic;
-	$resultArray['uptimeUsage'] = $totalUptime;
+	$resultArray['trafficUsage'] = (int)$totalTraffic;
+	$resultArray['uptimeUsage'] = (int)$totalUptime;
 
 	# Loop through topups and add to return array
 	$resultArray['trafficTopups'] = 0;
@@ -278,30 +267,26 @@ function getWiSPUserLogs($params) {
 
 		# Input
 		$acctInputMbyte = 0;
-
 		if (isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
-			$acctInputMbyte += ($row->acctinputoctets / 1024) / 1024;
+			$acctInputMbyte += ceil($row->acctinputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctinputgigawords) && $row->acctinputgigawords > 0) {
-			$acctInputMbyte += ($row->acctinputgigawords * 4096);
+			$acctInputMbyte += ceil($row->acctinputgigawords * 4096);
 		}
-
 		# Output
 		$acctOutputMbyte = 0;
-
 		if (isset($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
-			$acctOutputMbyte += ($row->acctoutputoctets / 1024) / 1024;
+			$acctOutputMbyte += ceil($row->acctoutputoctets / 1024 / 1024);
 		}
 		if (isset($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
-			$acctOutputMbyte += ($row->acctoutputgigawords * 4096);
+			$acctOutputMbyte += ceil($row->acctoutputgigawords * 4096);
 		}
 
 		# Uptime
 		$acctSessionTime = 0;
 		if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
-			$acctSessionTime += ($row->acctsessiontime / 60);
+			$acctSessionTime += ceil($row->acctsessiontime / 60);
 		}
-		ceil($acctSessionTime);
 
 		# Build array for this row
 		$item = array();
@@ -320,9 +305,9 @@ function getWiSPUserLogs($params) {
 		$item['CalledStationID'] = $row->calledstationid;
 		$item['AcctSessionID'] = $row->acctsessionid;
 		$item['FramedIPAddress'] = $row->framedipaddress;
-		$item['AcctInputMbyte'] = $acctInputMbyte;
-		$item['AcctOutputMbyte'] = $acctOutputMbyte;
-		$item['AcctSessionTime'] = $acctSessionTime;
+		$item['AcctInputMbyte'] = (int)$acctInputMbyte;
+		$item['AcctOutputMbyte'] = (int)$acctOutputMbyte;
+		$item['AcctSessionTime'] = (int)$acctSessionTime;
 		$item['ConnectTermReason'] = strRadiusTermCode($row->acctterminatecause);
 
 		# Push this row onto main array
-- 
GitLab