Newer
Older
# WiSP User List
# Copyright (C) 2007-2009, AllWorldIT
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
# 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.
include_once("includes/header.php");
include_once("includes/footer.php");
include_once("includes/db.php");
$db = connect_db();
printHeader(array(
));
# If we have nothing to do - display search
if (!isset($_POST['frmaction'])) {
?>
<p class="pageheader">User List</p>
<form id="main_form" action="wisp-user-list.php" method="post">
<input type="hidden" name="frmaction" value="dofilter" />
<table class="entry" style="width: 80%;">
<tr>
<td>Sort by:</td>
<td colspan="4">
<input type="radio" name="sortby" value="id">ID</input>
<input type="radio" name="sortby" value="fname">First Name</input>
<input type="radio" name="sortby" value="lname">Last Name</input>
<input type="radio" name="sortby" value="uname">Username</input>
</td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username" /></td>
<td>First Name:</td>
<td><input type="text" name="firstname" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" /></td>
<td>Phone:</td>
<td><input type="text" name="phone" /></td>
</tr>
<tr>
<td>Location:</td>
<td><input type="text" name="location" /></td>
<td>Email:</td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td class="textcenter" colspan="5"><input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}
if (isset($_POST['frmaction']) && $_POST['frmaction'] == "dofilter") {
?>
<form id="main_form" action="wisp-user-list.php" method="post">
<div class="textcenter">
Action
<select id="main_form_action" name="frmaction"
onchange="
var myform = document.getElementById('main_form');
var myobj = document.getElementById('main_form_action');
if (myobj.selectedIndex == 2) {
myform.action = 'wisp-user-edit.php';
} else if (myobj.selectedIndex == 3) {
myform.action = 'wisp-user-delete.php';
} else if (myobj.selectedIndex == 5) {
myform.action = 'wisp-user-logs.php';
}
myform.submit();
">
<option selected="selected">select action</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="edit">Edit User</option>
<option value="delete">Remove User</option>
<option disabled="disabled"> - - - - - - - - - - - </option>
<option value="viewlogs">Logs</option>
</select>
</div>
<p />
Robert Anderson
committed
<table class="results">
<tr class="resultstitle">
<td class="textcenter">ID</td>
<td class="textcenter">Username</td>
<td class="textcenter">FirstName</td>
<td class="textcenter">LastName</td>
<td class="textcenter">Email</td>
<td class="textcenter">Phone</td>
Robert Anderson
committed
<td class="textcenter">Location</td>
<td class="textcenter">Data Cap</td>
<td class="textcenter">Time Cap</td>
<td class="textcenter">IP Address</td>
</tr>
<?php
# Additions to the SQL statement
$extraSQLVals = array();
$extraSQL = "";
$orderSQL = "";
# What searches are we going to do?
if ($_POST['username']) {
Robert Anderson
committed
$extraSQL = " AND users.Username LIKE ?";
array_push($extraSQLVals,"%".$_POST['username']."%");
}
if ($_POST['firstname']) {
Robert Anderson
committed
$extraSQL = " AND userdata.FirstName LIKE ?";
array_push($extraSQLVals,"%".$_POST['firstname']."%");
}
if ($_POST['lastname']) {
Robert Anderson
committed
$extraSQL = " AND userdata.LastName LIKE ?";
array_push($extraSQLVals,"%".$_POST['lastname']."%");
}
if ($_POST['phone']) {
Robert Anderson
committed
$extraSQL = " AND userdata.Phone LIKE ?";
array_push($extraSQLVals,"%".$_POST['phone']."%");
}
if ($_POST['location']) {
Robert Anderson
committed
$extraSQL = " AND userdata.Location LIKE ?";
array_push($extraSQLVals,"%".$_POST['location']."%");
}
if ($_POST['email']) {
Robert Anderson
committed
$extraSQL = " AND userdata.Email LIKE ?";
array_push($extraSQLVals,"%".$_POST['email']."%");
}
$sortSQL = "";
if (isset($_POST['sortby'])) {
# How are we sorting the results?
switch ($_POST['sortby']) {
case "id":
$sortSQL = " ORDER BY users.ID";
break;
case "fname":
$sortSQL = " ORDER BY userdata.FirstName";
break;
case "lname":
$sortSQL = " ORDER BY userdata.LastName";
break;
case "uname":
$sortSQL = " ORDER BY users.Username";
break;
}
}
# Query based on user input
$sql = "
SELECT
Robert Anderson
committed
users.ID,
users.Username,
userdata.UserID,
userdata.FirstName,
userdata.LastName,
userdata.Email,
userdata.Phone,
userdata.Location
Robert Anderson
committed
users, userdata
Robert Anderson
committed
users.ID = userdata.UserID
$extraSQL
$sortSQL
";
$res = $db->prepare($sql);
$res->execute($extraSQLVals);
# List users
while ($row = $res->fetchObject()) {
Robert Anderson
committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# Second dirty query to get user's attributes
$tempUserID = $row->id;
$attrQuery = "
SELECT
Name,
Value
FROM
user_attributes
WHERE
UserID = $tempUserID
";
$dataCap = NULL;
$timeCap = NULL;
$userIP = NULL;
$attrResult = $db->query($attrQuery);
while ($attrRow = $attrResult->fetchObject()) {
# Is it the data cap attribute
if ($attrRow->name == "SMRadius-Capping-Traffic-Limit") {
$dataCap = $attrRow->value;
}
# Or the time cap attribute
if ($attrRow->name == "SMRadius-Capping-Time-Limit") {
$timeCap = $attrRow->value;
}
# Or the user IP attribute
if ($attrRow->name == "Framed-IP-Address") {
$userIP = $attrRow->value;
}
}
$attrResult->closeCursor();
?>
<tr class="resultsitem">
<td><input type="radio" name="user_id" value="<?php echo $row->id; ?>"/><?php echo $row->id; ?></td>
<td><?php echo $row->username; ?></td>
<td><?php echo $row->firstname; ?></td>
<td><?php echo $row->lastname; ?></td>
<td><?php echo $row->email; ?></td>
<td><?php echo $row->phone; ?></td>
<td><?php echo $row->location; ?></td>
<td><?php echo $dataCap; ?> MB</td>
<td><?php echo $timeCap; ?> Min</td>
<td><?php echo $userIP; ?></td>
</tr>
<?php
}
# If there were no rows, complain
?>
<p />
<tr>
<td colspan="3" class="textcenter">No users found</td>
</tr>
<?php
}