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!
# Display details
function displayDetails() {
global $db;
global $DB_TABLE_PREFIX;
# Get user's ID
$sql = "
SELECT
ID
FROM
${DB_TABLE_PREFIX}users
WHERE
";
$res = $db->query($sql);
$row = $res->fetchObject();
$userID = $row->id;
# Get accounting data
$currentMonth = date("Y-m");
$sql = "
SELECT
AcctSessionTime,
AcctInputOctets,
AcctInputGigawords,
AcctOutputOctets,
AcctOutputGigawords
FROM
${DB_TABLE_PREFIX}accounting
WHERE
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
AND
EventTimestamp >= '$currentMonth'
ORDER BY
EventTimestamp
DESC
";
$res = $db->query($sql);
$totalData = 0;
$totalInputData = 0;
$totalOutputData = 0;
$totalSessionTime = 0;
while ($row = $res->fetchObject()) {
# Input
$inputDataItem = 0;
if (!isset($row->acctinputoctets) && $row->acctinputoctets > 0) {
$inputDataItem += ($row->accinputoctets / 1024 / 1024);
}
if (!empty($row->acctinputgigawords) && $row->inputgigawords > 0) {
$inputDataItem += ($row->acctinputgigawords * 4096);
}
$totalInputData += $inputDataItem;
# Output
$outputDataItem = 0;
if (!empty($row->acctoutputoctets) && $row->acctoutputoctets > 0) {
$outputDataItem += ($row->acctoutputoctets / 1024 / 1024);
}
if (!empty($row->acctoutputgigawords) && $row->acctoutputgigawords > 0) {
$outputDataItem += ($row->acctoutputgigawords * 4096);
}
$totalOutputData += $outputDataItem;
$totalData += $totalInputData + $totalOutputData;
# Time calculation
$sessionTimeItem = 0;
if (!empty($row->acctsessiontime) && $row->acctsessiontime > 0) {
$sessionTimeItem += ($row->acctsessiontime - ($row->acctsessiontime % 60)) / 60;
}
$totalSessionTime += $sessionTimeItem;
}
# Fetch user uptime and traffic cap
$sql = "
SELECT
Name, Value
FROM
${DB_TABLE_PREFIX}user_attributes
WHERE
UserID = '$userID'
";
$res = $db->query($sql);
$trafficCap = "None";
$uptimeCap = "None";
while ($row = $res->fetchObject()) {
if ($row->name == "SMRadius-Capping-Traffic-Limit") {
if ($row->name == "SMRadius-Capping-UpTime-Limit") {
# Fetch user phone and email info
$sql = "
SELECT
Phone, Email
FROM
${DB_TABLE_PREFIX}wisp_userdata
WHERE
UserID = '$userID'
";
$res = $db->query($sql);
$userPhone = "Not set";
$userEmail = "Not set";
if ($res->rowCount() > 0) {
$row = $res->fetchObject();
$userPhone = $row->phone;
$userEmail = $row->email;
}
?>
<table class="blockcenter">
<tr>
<td colspan="2" class="section">Account Information</td>
</tr>
<tr>
<td class="title">Username</td>
<td class="value"><?php echo $username; ?></td>
</tr>
<tr>
<td class="title">Service</td>
<td class="value"><?php echo $userService; ?></td>
</tr>
<?php
# Only display cap for DSL users
if (!$isDialup) {
?>
<tr>
<td colspan="2" class="section">Usage Info</td>
</tr>
<tr>
<td class="title">Bandwidth Cap</td>
<td class="title">Used This Month</td>
</tr>
<tr>
<?php
if (is_numeric($trafficCap)) {
?>
<td class="value"><?php echo $trafficCap; ?> MB</td>
<?php
} else {
?>
<td class="value"><?php echo $trafficCap; ?></td>
<?php
}
?>
<td class="value"><?php printf('%.2f', $totalData); ?> MB</td>
</tr>
<tr>
<td class="title">Time Cap</td>
<td class="title">Used This Month</td>
</tr>
<tr>
<?php
if (is_numeric($uptimeCap)) {
?>
<td class="value"><?php echo $uptimeCap; ?> Min</td>
<?php
} else {
?>
<td class="value"><?php echo $uptimeCap; ?></td>
<?php
}
?>
<td class="value"><?php echo $totalSessionTime; ?> Min</td>
</tr>
<tr>
<td colspan="2" class="section">Notifications</td>
</tr>
<form method="post">
<tr>
<td class="title">Email Address</td>
<td class="value">
<input type="text" name="notifyMethodEmail" value="php echo $userEmail; "></input>
</td>
</tr>
<tr>
<td class="title">Cell Number</td>
<td class="value">
<input type="text" name="notifyMethodCell" value="php echo $userPhone; "></input>
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
}
?>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td colspan="2" align="center">
<a href="logs.php">Usage Logs</a>
</td>
</tr>
</table>
<br><br>
<font size="-1">
Note:
<li>Please contact your ISP if you have any problem using this interface.</li>
</font>
<?php
}
# If this is a post and we're updating
if (isset($_POST['notifyUpdate']) && $_POST['notifyUpdate'] == "update") {
# Get user's ID
$sql = "
SELECT
ID
FROM
${DB_TABLE_PREFIX}users
WHERE
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
";
$res = $db->query($sql);
$row = $res->fetchObject();
$userID = $row->id;
$sql = "
SELECT
Name, Value
FROM
${DB_TABLE_PREFIX}user_attributes
WHERE
UserID = '$userID'
";
$res = $db->query($sql);
$userPhone = "Unavailable";
$userEmail = "Unavailable";
while ($row = $res->fetchObject()) {
if ($row->name == "SMRadius-Notify-Phone") {
$userPhone = $row->value;
}
if ($row->name == "SMRadius-Notify-Email") {
$userEmail = $row->value;
}
}
# If we want to update email address
if (isset($_POST['notifyMethodEmail']) && !empty($_POST['notifyMethodEmail'])) {
$db->beginTransaction();
# Unavailble if no email address is set yet
if ($userEmail == "Unavailable") {
# Prepare to insert email address for the first time
$emailStatement = $db->prepare("INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
('$userID','SMRadius-Notify-Email','=*',?)
");
$emailResult = $emailStatement->execute(array($_POST['notifyMethodEmail'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Email address updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating email address, please contact your ISP.</center>";
}
} else {
# Prepare to update existing email address
$emailStatement = $db->prepare("UPDATE
${DB_TABLE_PREFIX}user_attributes
SET
Value = ?
WHERE
Name = 'SMRadius-Notify-Email'
AND
UserID = '$userID'
");
$emailResult = $emailStatement->execute(array($_POST['notifyMethodEmail'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Email address updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating email address, please contact your ISP.</center>";
}
}
}
# If we want to update phone number
if (isset($_POST['notifyMethodCell']) && !empty($_POST['notifyMethodCell'])) {
$db->beginTransaction();
# Unavailable if there is none found for this user
if ($userPhone == "Unavailable") {
# Prepare to insert first number
$phoneStatement = $db->prepare("INSERT INTO
${DB_TABLE_PREFIX}user_attributes (UserID,Name,Operator,Value)
VALUES
('$userID','SMRadius-Notify-Phone','=*',?)
");
$phoneResult = $phoneStatement->execute(array($_POST['notifyMethodCell'],));
# If successful, commit
if ($phoneResult) {
$db->commit();
echo "<center>Mobile phone number updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating mobile phone number, please contact your ISP.</center>";
}
} else {
# Prepare to update existing number
$phoneStatement = $db->prepare("UPDATE
${DB_TABLE_PREFIX}user_attributes
SET
Value = ?
WHERE
Name = 'SMRadius-Notify-Phone'
AND
UserID = '$userID'
");
$phoneResult = $phoneStatement->execute(array($_POST['notifyMethodPhone'],));
# If successful, commit
if ($emailResult) {
$db->commit();
echo "<center>Mobile phone number updated</center>";
# Else, rollback changes and give error
} else {
$db->rollback();
echo "<center>Error updating mobile phone number, please contact your ISP.</center>";
}
}
}
}
displayDetails();
# Footer
include("include/footer.php");
# vim: ts=4
?>