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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
<script type="text/javascript">
$(document).ready(function(){
$(".flip").click(function(){
$(".slidepanel").slideToggle("slow");
});
});
</script>
<style type="text/css">
p.flip
{
margin:0px;
padding:5px;
text-align:center;
background:#e5eecc;
border:solid 1px #c3c3c3;
}
div.slidepanel
{
height:75px;
display:none;
}
</style>
<?php
/**
* Bayonet Content Management System
* Copyright (C) 2008 Joseph Hunkeler
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
function ListAdmins()
{
global $db;
$result = $db->Query("SELECT `user_id`, `username`, `level` FROM `bayonet_users` ORDER BY `level` DESC");
while(($rows = $db->fetch($result))!=false)
{
$admins[] = $rows;
}
$num = 1;
OpenTable("300px");
echo "<tr><th></th><th>Username</th><th>Level</th></tr>";
foreach($admins as $admin)
{
echo "<tr><td>{$num}.</td><td><a href=\"?op=admins&edit={$admin['user_id']}\">{$admin['username']}</a></td><td>{$admin['level']}</td></tr>";
$num++;
}
CloseTable();
}
function NewAdmin()
{
$maxLevel = $_SESSION['level'];
if(isset($_POST['processed'])){
echo GeneratePassword(8);
return;
}
?>
<div style="text-align:right"><img src="images/cancel.png" />Cancel</div>
<center>
<form method="POST" action="<?php $_SERVER['PHP_SELF']?>">
<table>
<tr><th>Username:</th><td><input type="text" value="" name="username" /></td></tr>
<tr><th>First Name:</th><td><input type="text" value="" name="first" /></td></tr>
<tr><th>Last Name:</th><td><input type="text" value="" name="last" /></td></tr>
<tr><th>Email Address:</th><td><input type="text" value="" name="email" /></td></tr>
<tr>
<th>Level:</th>
<td>
<select name="level">
<?php
for($x=$maxLevel; $x>0;$x--){
echo "<option value=\"{$x}\">{$x}</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input type="submit" name="processed" value="Submit" />
</td>
</tr>
</table>
<br />
<?php GetPermissions(); ?>
</form>
</center>
<?php
}
function GetPermissions($user)
{
?>
<div class="slidepanel">
<table width="100%" style="text-align:center;">
<tr><th>Everything else</th><th>Adjutant</th><th>Quartermaster</th></tr>
<tr>
<td>
<input type="hidden" name="all" value="0" />
<?php
if(isset($user['all']) && $user['all'] == 1)
echo "<input type=\"checkbox\" name=\"all\" value=\"1\" checked/>";
else
echo "<input type=\"checkbox\" name=\"all\" value=\"1\" />";
?>
</td>
<td>
<input type="hidden" name="adjutant" value="0" />
<?php
if(isset($user['adjutant']) && $user['adjutant'] == 1)
echo "<input type=\"checkbox\" name=\"adjutant\" value=\"1\" checked/>";
else
echo "<input type=\"checkbox\" name=\"adjutant\" value=\"1\" />";
?>
</td>
<td>
<input type="hidden" name="quartermaster" value="0" />
<?php
if(isset($user['quartermaster']) && $user['quartermaster'] == 1)
echo "<input type=\"checkbox\" name=\"quartermaster\" value=\"1\" checked/>";
else
echo "<input type=\"checkbox\" name=\"quartermaster\" value=\"1\" />";
?>
</td>
</tr>
</table>
</div>
<p class="flip">Show/Hide Permissions</p>
<?php
}
function GeneratePassword($length)
{
srand(date("s"));
$possible_charactors = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$string = "";
while(strlen($string)<$length) {
$string .= substr($possible_charactors, rand()%(strlen($possible_charactors)),1);
}
return($string);
}
function EditAdmin($user_id)
{
global $db;
$maxLevel = $_SESSION['level'];
if(isset($_POST['processed']))
{
$username = addslashes($_POST['username']);
$level = addslashes($_POST['level']);
$all = $_POST['all'];
$adjutant = $_POST['adjutant'];
$quartermaster = $_POST['quartermaster'];
if(empty($username))
{
echo "You must fill everything out before proceeding.";
return;
}
$db->Query("UPDATE `bayonet_users` SET `username` = '$username', `level` = '$level', `all` = '$all', `adjutant` = '$adjutant', `quartermaster` = '$quartermaster' WHERE `user_id` = '$user_id' LIMIT 1");
echo "Admin, '$username' level '$level' has been edited.\n <br /><br />
Please wait while you are redirected. <br /><br />
<a href=\"?op=admins\">Click here if you don't feel like waiting.</a>";
// 3 second redirect to go back to the edit page
PageRedirect(2, "?op=admins&edit={$user_id}");
return;
}
$result = $db->Query("SELECT * FROM `bayonet_users` WHERE `user_id` = '$user_id' LIMIT 1");
$admin = $db->fetch($result);
if($maxLevel < $admin['level']){
ReportError("You do not have permission to access this user.");
return;
}
?>
<center>
Edit the attributes of this administrator.<br />
<form method="POST" action="<?php $_SERVER['PHP_SELF']?>">
<table>
<tr><th>Username:</th><td><input type="text" value="<?php echo $admin['username']; ?>" name="username" /></td></tr>
<tr>
<th>Level:</th>
<td>
<select name="level">
<?php
for($x=$maxLevel; $x>0;$x--){
if($admin['level'] == $x)
echo "<option value=\"{$x}\" selected>{$x}</option>";
else
echo "<option value=\"{$x}\">{$x}</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input type="submit" name="processed" value="Submit" />
<a href="?op=admins&delete=<?php echo $user_id; ?>"><input type="button" value="Delete Admin" /></a>
</td>
</tr>
</table>
<br />
<?php GetPermissions($admin); ?>
</form>
</center>
<?php
}
function DeleteAdmin($user_id)
{
global $db;
$maxLevel = $_SESSION['level'];
$result = $db->Query("SELECT `username` FROM `bayonet_users` WHERE `user_id` = '$user_id'");
$admin = $db->Fetch($result);
if(isset($_POST['proceed']))
{
echo "Admin '{$admin['username']}', was deleted.";
$db->Query("DELETE FROM `bayonet_users` WHERE `user_id` = '$user_id' LIMIT 1");
PageRedirect(3,"?op=admins");
return;
}
if(isset($_POST['cancel']))
{
echo "User cancelled deletion of admin: '{$admin['username']}'";
PageRedirect(3,"?op=admins");
return;
}
?>
<center>
<form action="<?php $_SERVER['PHP_SELF'] ?>" method="post">
<table>
<th>Are you SURE you want to delete the administrative user: '<?php echo $admin['username']?>'?</th>
<tr><th><button name="proceed">Yes</button> <button name="cancel">No</button></th></tr>
</table>
</form>
</center>
<?php
}
?>
|