Newer
Older
# Main User Control Panel Page
# Copyright (c) 2007-2009, AllWorldIT
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
# pre takes care of authentication and creates soap object we need
include("include/pre.php");
# Page header
include("include/header.php");
# NB: We will only end up here if we authenticated!
# Displays error
function webuiError($msg) {
echo isset($msg) ? $msg : "Unknown error";
}
# Display details
function displayDetails() {
global $db;
global $DB_TABLE_PREFIX;
# Get user's ID
$sql = "
SELECT
Username = ".$db->quote($_SESSION['username'])."
if (!(is_object($res))) {
webuiError("Error fetching user information");
}
# Get accounting data
$currentMonth = date("Y-m");
$sql = "
SELECT
Robert Anderson
committed
SUM(AcctSessionTime) / 60 AS AcctSessionTime,
SUM(AcctInputOctets) / 1024 / 1024 +
SUM(AcctInputGigawords) * 4096 AS AcctInputTraffic,
SUM(AcctOutputOctets) / 1024 / 1024 +
SUM(AcctOutputGigawords) * 4096 AS AcctOutputTraffic
Username = ".$db->quote($_SESSION['username'])."
if (!(is_object($res))) {
webuiError("Error fetching user accounting");
}
# Set total traffic and uptime used
$totalTraffic = 0;
$totalUptime = 0;
Robert Anderson
committed
# Pull in row
$row = $res->fetchObject();
# Traffic in
if (isset($row->acctinputtraffic) && $row->acctinputtraffic > 0) {
$totalTraffic += $row->acctinputtraffic;
}
# Traffic out
if (isset($row->acctoutputtraffic) && $row->acctoutputtraffic > 0) {
$totalTraffic += $row->acctoutputtraffic;
}
# Uptime
if (isset($row->acctsessiontime) && $row->acctsessiontime > 0) {
$totalUptime += $row->acctsessiontime;
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# Fetch user uptime and traffic cap (group attributes)
$sql = "
SELECT
${DB_TABLE_PREFIX}group_attributes.Name, ${DB_TABLE_PREFIX}group_attributes.Value
FROM
${DB_TABLE_PREFIX}group_attributes, ${DB_TABLE_PREFIX}users_to_groups
WHERE
${DB_TABLE_PREFIX}users_to_groups.GroupID = ${DB_TABLE_PREFIX}group_attributes.GroupID
AND ${DB_TABLE_PREFIX}users_to_groups.UserID = ".$db->quote($userID)."
";
$res = $db->query($sql);
if (!(is_object($res))) {
webuiError("Error fetching user attributes");
}
# Initial values
$trafficCap = "Prepaid";
$uptimeCap = "Prepaid";
while ($row = $res->fetchObject()) {
if ($row->name === "SMRadius-Capping-Traffic-Limit") {
$trafficCap = (int)$row->value;
}
if ($row->name === "SMRadius-Capping-Uptime-Limit") {
$uptimeCap = (int)$row->value;
}
}
# Fetch user uptime and traffic cap (user attributes)
SELECT
Name, Value
FROM
${DB_TABLE_PREFIX}user_attributes
WHERE
if (!(is_object($res))) {
webuiError("Error fetching user attributes");
}
if ($row->name === "SMRadius-Capping-Traffic-Limit") {
$trafficCap = (int)$row->value;
if ($row->name === "SMRadius-Capping-Uptime-Limit") {
$uptimeCap = (int)$row->value;
# Fetch user uptime and traffic summary
$sql = "
${DB_TABLE_PREFIX}topups_summary.Balance,
${DB_TABLE_PREFIX}topups.Type,
${DB_TABLE_PREFIX}topups.Value,
${DB_TABLE_PREFIX}topups.ValidFrom,
${DB_TABLE_PREFIX}topups.ValidTo
FROM
${DB_TABLE_PREFIX}topups_summary,
${DB_TABLE_PREFIX}topups
WHERE
${DB_TABLE_PREFIX}topups_summary.TopupID = ${DB_TABLE_PREFIX}topups.ID
AND ${DB_TABLE_PREFIX}topups.UserID = ".$db->quote($userID)."
AND ${DB_TABLE_PREFIX}topups_summary.PeriodKey = ".$db->quote($currentMonth)."
ORDER BY
${DB_TABLE_PREFIX}topups.Timestamp
if (!(is_object($res))) {
webuiError("Error fetching topup summaries");
}
$topups[$i] = array();
$topups[$i]['Type'] = $row->type;
$topups[$i]['CurrentLimit'] = $row->balance;
$topups[$i]['Limit'] = $row->value;
$topups[$i]['ValidFrom'] = $row->validfrom;
$topups[$i]['Expires'] = $row->validto;
$i++;
# Fetch user uptime and traffic topups
$thisMonthTimestamp = date("Y-m").'-01';
$now = date("Y-m-d");
UserID = ".$db->quote($userID)."
AND ValidFrom = ".$db->quote($thisMonthTimestamp)."
AND ValidTo >= ".$db->quote($now)."
AND Depleted = 0
if (!(is_object($res))) {
webuiError("Error fetching topup");
}
$topups[$i] = array();
$topups[$i]['Type'] = $row->type;
$topups[$i]['Limit'] = $row->value;
$topups[$i]['ValidFrom'] = $row->validfrom;
$topups[$i]['Expires'] = $row->validto;
# Calculate topup usage for prepaid and normal users
if (!($trafficCap === "Unlimited")) {
# Excess usage
$excess = 0;
if ($trafficCap === "Prepaid") {
$excess = $totalTraffic;
} else {
$excess = $totalTraffic > $trafficCap ? ($totalTraffic - $trafficCap) : 0;
}
# Loop through all valid topups
$totalTrafficTopupsAvail = 0;
$trafficRows = array();
foreach ($topups as $topup) {
# Traffic topups
if ($topup['Type'] == 1) {
# Topup not currently in use
if ($excess <= 0) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = isset($topup['CurrentLimit']) ? ($topup['Limit'] - $topup['CurrentLimit']) : 0;
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalTrafficTopupsAvail += $topup['Limit'];
$i++;
# Topup currently in use
Robert Anderson
committed
} elseif (!isset($topup['CurrentLimit']) && $excess < $topup['Limit']) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = $excess;
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalTrafficTopupsAvail += $topup['Limit'];
# Set current topup
$currentTrafficTopup = array();
$currentTrafficTopup['Used'] = $excess;
$currentTrafficTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
Robert Anderson
committed
} elseif (isset($topup['CurrentLimit']) && $excess < $topup['CurrentLimit']) {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
# Set total available topups
$totalTrafficTopupsAvail += $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
# Topup has been used up
} else {
$trafficRows[$i] = array();
$trafficRows[$i]['Cap'] = $topup['Limit'];
$trafficRows[$i]['Used'] = $topup['Limit'];
$trafficRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$trafficRows[$i]['Expires'] = $topup['Expires'];
# Subtract this topup from excess usage
$excess -= $topup['Limit'];
Robert Anderson
committed
$i++;
# Calculate topup usage for prepaid and normal users
if (!($uptimeCap === "Unlimited")) {
# Excess usage
$excess = 0;
if ($uptimeCap === "Prepaid") {
$excess = $totalUptime;
$excess = $totalUptime > $uptimeCap ? ($totalUptime - $uptimeCap) : 0;
# Loop through all valid topups
$totalUptimeTopupsAvail = 0;
$uptimeRows = array();
$i = 0;
foreach ($topups as $topup) {
# Topup not currently in use
if ($excess <= 0) {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = isset($topup['CurrentLimit']) ? ($topup['Limit'] - $topup['CurrentLimit']) : 0;
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalUptimeTopupsAvail += $topup['Limit'];
$i++;
# Topup currently in use
Robert Anderson
committed
} elseif (!isset($topup['CurrentLimit']) && $excess < $topup['Limit']) {
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = $excess;
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Set total available topups
$totalUptimeTopupsAvail += $topup['Limit'];
# Set current topup
$currentUptimeTopup = array();
$currentUptimeTopup['Used'] = $excess;
$currentUptimeTopup['Cap'] = $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
Robert Anderson
committed
} elseif (isset($topup['CurrentLimit']) && $excess < $topup['CurrentLimit']) {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Used'] = ($topup['Limit'] - $topup['CurrentLimit']) + $excess;
# Set total available topups
$totalUptimeTopupsAvail += $topup['Limit'];
# If we hit this topup then all the rest of them are available
$excess = 0;
$i++;
# Topup has been used up
} else {
$uptimeRows[$i] = array();
$uptimeRows[$i]['Cap'] = $topup['Limit'];
$uptimeRows[$i]['Used'] = $topup['Limit'];
$uptimeRows[$i]['ValidFrom'] = $topup['ValidFrom'];
$uptimeRows[$i]['Expires'] = $topup['Expires'];
# Subtract this topup from excess usage
$excess -= $topup['Limit'];
$i++;
}
}
}
}
# HTML
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<td width="500" colspan="4" class="section">Account Information</td>
</tr>
<tr>
<td align="center" class="title">Username</td>
<td align="center" class="title">Traffic Cap</td>
<td align="center" class="title">Uptime Cap</td>
</tr>
<tr>
<td align="center" class="value"><?php echo $username; ?></td>
<td align="center" class="value">
<?php
if (is_numeric($trafficCap) && $trafficCap == 0) {
echo "Unlimited";
} elseif (is_string($trafficCap) && $trafficCap === "Prepaid") {
echo $trafficCap;
} else {
echo $trafficCap." MB";
}
?>
</td>
<td align="center" class="value">
<?php
if (is_numeric($uptimeCap) && $uptimeCap == 0) {
echo "Unlimited";
} elseif (is_string($uptimeCap) && $uptimeCap === "Prepaid") {
echo $uptimeCap;
} else {
echo $uptimeCap." MB";
}
?>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td colspan="4" class="section">Traffic Usage</td>
</tr>
<tr>
<td align="center" class="title">Active Topup</td>
<td align="center" class="title">Total Topup</td>
<td align="center" class="title">Total Usage</td>
</tr>
<td align="center" class="value">
<?php
if (isset($currentTrafficTopup) && (!(is_numeric($trafficCap) && $trafficCap == 0))) {
echo sprintf("%.2f",$currentTrafficTopup['Used'])."/".sprintf($currentTrafficTopup['Cap'])." MB";
} else {
echo "None";
}
?>
</td>
<td align="center" class="value"><?php echo $totalTrafficTopupsAvail." MB"; ?></td>
<td align="center" class="value"><?php echo sprintf("%.2f",$totalTraffic)." MB"; ?></td>
<tr>
</tr>
<tr>
<td> </td>
<td align="center" class="title">Active Topup</td>
<td align="center" class="title">Total Topup</td>
<td align="center" class="title">Total Usage</td>
<tr>
<td align="center" class="value">
<?php
if (isset($currentUptimeTopup) && (!(is_numeric($uptimeCap) && $uptimeCap == 0))) {
echo sprintf("%.2f",$currentUptimeTopup['Used'])."/".sprintf($currentUptimeTopup['Cap'])." MB";
} else {
echo "None";
}
?>
</td>
<td align="center" class="value"><?php echo $totalUptimeTopupsAvail." MB"; ?></td>
<td align="center" class="value"><?php echo sprintf("%.2f",$totalUptime)." Min"; ?></td>
</tr>
</table>
<p> </p>
Robert Anderson
committed
if (!(is_numeric($trafficCap) && $trafficCap == 0)) {
<td width="500" colspan="3" class="section">Topup Overview: Traffic</td>
<td align="center" class="title">Used</td>
<td align="center" class="title">Valid From</td>
<td align="center" class="title">Valid To</td>
echo sprintf("%.2f",$trafficRow['Used'])."/".sprintf($trafficRow['Cap'])." MB";
Robert Anderson
committed
</td>
Robert Anderson
committed
<td align="center" class="value"><?php $validFrom = strtotime($trafficRow['ValidFrom']); echo date("Y-m-d",$validFrom);?></td>
<td align="center" class="value"><?php $validTo = strtotime($trafficRow['Expires']); echo date("Y-m-d",$validTo);?></td>
Robert Anderson
committed
if (!(is_numeric($uptimeCap) && $uptimeCap == 0)) {
<td width="500" colspan="3" class="section">Topup Overview: Uptime</td>
<td align="center" class="title">Used</td>
<td align="center" class="title">Valid From</td>
<td align="center" class="title">Valid To</td>
echo sprintf("%.2f",$uptimeRow['Used'])."/".sprintf($uptimeRow['Cap'])." MB";
Robert Anderson
committed
</td>
Robert Anderson
committed
<td align="center" class="value"><?php $validFrom = strtotime($uptimeRow['ValidFrom']); echo date("Y-m-d",$validFrom);?></td>
<td align="center" class="value"><?php $validTo = strtotime($uptimeRow['Expires']); echo date("Y-m-d",$validTo);?></td>
<p> </p>
<p align="center"><a href="logs.php">Usage Logs</a></p>