This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
manageusers.php
240 lines (239 loc) · 9.42 KB
/
manageusers.php
1
2
3
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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
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
232
233
234
235
236
237
238
239
240
<?php
/*
* @author: Scottish Borders Design
* @script: SBD SHOUTcast Manager
* @function: Manage Users
* @website: http://scottishbordersdesign.co.uk/
*/
if (useraccess($_SESSION['username']) < "5") {
echo "ACCESS DENIED - INCIDENT REPORTED";
$event = " Attempted to access the restricted user management section.";
addevent($_SESSION['username'], $event);
} else {
$db = dbConnect();
/////////////////////////////////////
//
// Handle the post if we are adding a new user
//
/////////////////////////////////////
if (isset($_POST['newuser'])) {
$username = $_POST['username'];
$password = md5($_POST['password']);
$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$access = $_POST['access'];
adduser($username, $password, $fname, $lname, $email, $access);
}
/////////////////////////////////////
//
// Handle the post if we are deleting a user
//
/////////////////////////////////////
if (isset($_REQUEST['delete'])) {
$id = $_REQUEST['id'];
$username = $_REQUEST['username'];
deluser($id, $username);
}
/////////////////////////////////////
//
// Login as User
//
/////////////////////////////////////
if (isset($_REQUEST['loginas'])) {
$id = $_REQUEST['id'];
$username = $_REQUEST['username'];
loginas($id, $username);
}
/////////////////////////////////////
//
// Handle the post if we are editing a user
//
/////////////////////////////////////
if (isset($_POST['edituser'])) {
$usrname = $_POST['username'];
$password = $_POST['password'];
if (!empty($password)) {
$password = $_POST['password'];
}
$email = $_POST['email'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$id = $_POST['id'];
$access = $_POST['access'];
edituser($id, $usrname, $password, $fname, $lname, $email, $access);
}
/////////////////////////////////////
//
// Create our header table, we do this outside the query.
//
/////////////////////////////////////
?>
<div class="box">
<div class="box-header">
<h3 class="box-title">Registered Users</h3>
<div class="box-tools">
<div class="input-group">
<input type="text" name="table_search" class="form-control input-sm pull-right" style="width: 150px;" placeholder="Search">
<div class="input-group-btn">
<button class="btn btn-sm btn-default"><i class="fa fa-search"></i></button>
</div>
</div>
</div>
</div><!-- /.box-header -->
<div class="box-body table-responsive no-padding">
<table class="table table-hover">
<tbody><tr>
<th>ID</th>
<th>Username</th>
<th>First Name</th>
<th>Last Name</th>
<th>Email Address</th>
<th>Action</th>
</tr>
<?php /////////////////////////////////////
//
// Run our query and create alternating colors on the rows
//
/////////////////////////////////////
$i = "0";
$members = $db->get("members");
foreach ($members as $row) {
$row = index_array($row);
$bgcolor = ($i++ & 1) ? '#FFFFFF' : '#bcbcbc';
echo "<tr>";
?>
<td >
<?echo $row[0];?>
</td>
<td>
<?echo $row[1];?>
</td>
<td>
<?echo $row[3];?>
</td>
<td>
<?echo $row[4];?>
</td>
<td>
<?echo $row[5];?>
</td>
<td>
<?php
if ($row[1] == $_SESSION['username']) {
echo "<a href=\"#\"><span class=\"badge bg-grey\">Login As</span></a> / ";
} else { ?>
<?echo "<a href=\"users.php?loginas=yes&id=$row[0]&username=$row[1]\"><span class=\"badge bg-orange\">Login As</span></a> / "; } ?>
<?echo "<a href=\"users.php?edit=yes&userid=$row[0]\"><span class=\"badge bg-light-blue\">Edit</span></a>";?>
/ <a href="users.php?delete=yes&id=<?echo $row[0];?>&username=<?echo $row[1];?>" onclick="javascript:return confirm('Are you sure you want to delete this user?')"><span class="badge bg-red">Delete</span></a>
</td>
</tr>
<?php }
?>
</tbody></table>
</div><!-- /.box-body -->
</div>
<?php if(isset($_REQUEST['edit'])) {
$userid = $_REQUEST['userid'];
$db->where("user_id", $userid);
$members = $db->get("members");
foreach ($members as $row) {
$row = index_array($row);
?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Edit User</h3>
</div><!-- /.box-header -->
<!-- form start -->
<form method="post" action="">
<div class="box-body">
<div class="form-group">
<label for="">Username</label>
<input type="text" class="form-control" id="" name="username" value="<?echo $row[1];?>" placeholder="<?echo $row[1];?>">
</div>
<div class="form-group" data-toggle="tooltip" title="Leave empty for no change">
<label for="">Password</label>
<input type="password" class="form-control" name="password" id="" placeholder="Password">
</div>
<div class="form-group">
<label for="">First Name</label>
<input type="text" class="form-control" name="fname" id="" value="<?echo $row[3];?>" placeholder="<?echo $row[3];?>">
</div>
<div class="form-group">
<label for="">Last Name</label>
<input type="text" class="form-control" name="lname" id="" value="<?echo $row[4];?>" placeholder="<?echo $row[4];?>">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" class="form-control" name="email" id="" value="<?echo $row[5];?>" placeholder="<?echo $row[5];?>">
</div>
<div class="form-group">
<label>Access Level</label>
<select class="form-control" name="access">
<option value="5" <?php if ($row[6] == "5") { echo "selected"; } ?>>Administrator</option>
<option value="4" <?php if ($row[6] == "4") { echo "selected"; } ?>>Technician</option>
<option value="3" <?php if ($row[6] == "3") { echo "selected"; } ?>>Helper</option>
<option value="2" <?php if ($row[6] == "2") { echo "selected"; } ?>>Read Only</option>
<option value="1" <?php if ($row[6] == "1") { echo "selected"; } ?>>User</option>
<option value="0" <?php if ($row[6] == "0") { echo "selected"; } ?>>Disabled</option>
</select>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<input type="hidden" name="id" value="<?php echo $row['0'];?>">
<input type="hidden" name="edituser" value="yes">
<button type="submit" name="go" class="btn btn-primary">Update user</button>
</div>
</form>
</div>
<?php }
}else{
?>
<div class="box box-primary">
<div class="box-header">
<h3 class="box-title">Add New User</h3>
</div><!-- /.box-header -->
<!-- form start -->
<form method="post" action="">
<div class="box-body">
<div class="form-group">
<label for="">Username</label>
<input type="text" class="form-control" id="" name="username" placeholder="Username">
</div>
<div class="form-group">
<label for="">Password</label>
<input type="password" class="form-control" name="password" id="" placeholder="Password">
</div>
<div class="form-group">
<label for="">First Name</label>
<input type="text" class="form-control" name="fname" id="" placeholder="First Name">
</div>
<div class="form-group">
<label for="">Last Name</label>
<input type="text" class="form-control" name="lname" id="" placeholder="Last Name">
</div>
<div class="form-group">
<label for="">Email</label>
<input type="email" class="form-control" name="email" id="" placeholder="Email">
</div>
<div class="form-group">
<label>Access Level</label>
<select class="form-control" name="access">
<option value="5">Administrator</option>
<option value="4">Technician</option>
<option value="3">Helper</option>
<option value="2">Read Only</option>
<option value="1">User</option>
<option value="0">Disabled</option>
</select>
</div>
</div><!-- /.box-body -->
<div class="box-footer">
<input type="hidden" name="newuser" value="yes">
<button type="submit" name="go" class="btn btn-primary">Add user</button>
</div>
</form>
</div>
<?php }
}
?>