/
users.php
335 lines (318 loc) · 14.1 KB
/
users.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
241
242
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
275
276
277
278
279
280
281
282
283
284
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
<?php
require_once('lib/path.php');
$action = param('action', 'none');
$do = param('do', 'none');
if ($do == 'none')
echo '<h1>Manage Users</h1>';
if ($action == 'none') {
?>
<br /><br />
<table class="table table-hover">
<tr>
<th>ID</th>
<th>Rank</th>
<th>Name</th>
<th>Division</th>
<th>Security Clearance</th>
<th>Email</th>
</tr>
<?php
foreach (User::getUsers($_SESSION['user'], true) as $user) {
?>
<tr>
<td>
<?php echo $user->getUsername() ?>
<?php
if (!$user->getAdmin() || $user->getAdmin()->getAdminLevel() < $_SESSION['user']->getAdmin()->getAdminLevel()) {
?>
(<a onclick="load('users', 'edit', 'none', {id: '<?php echo $user->getID() ?>'})">Edit</a> || <a onclick="load('users', 'delete', 'none', {id: '<?php echo $user->getID() ?>'})">Delete</a> || <a onclick="load('users', 'switch', 'none', {id: '<?php echo $user->getID() ?>'})">Switch To</a>)
<?php
}
?>
</td>
<td><?php echo $user->getRank()->getName() ?></td>
<td><?php echo $user->getName() ?></td>
<td><?php echo $user->getDivision()->getName() ?></td>
<td><?php echo $user->getClearance()->getClearanceName() ?></td>
<td><a href="mailto:<?php echo $user->getEmail() ?>"><?php echo $user->getEmail() ?></a></td>
</tr>
<?php
}
?>
</table>
<center><a onclick="load('users', 'new', 'none', {})">New User</a></center>
<?php
} if ($action == 'edit') {
$user = new User($_GET['id']);
if ($do == 'none') {
?>
<form action="#" method="post">
<input type="hidden" id="id" name="id" value="<?php echo $user->getID() ?>" />
<table>
<tr>
<th>Security Code:</th>
<td><a onclick="load('users', 'edit', 'resetpass', {id: '<?php echo $user->getID() ?>'})">Reset</a></td>
</tr>
<tr>
<th><label for="login">Login ID:</label></th>
<td><input type="text" id="login" name="login" value="<?php echo $user->getUsername() ?>" required /></td>
</tr>
<tr>
<th><label for="email">Email Address:</label></th>
<td><input type="email" id="email" name="email" value="<?php echo $user->getEmail() ?>" required /></td>
</tr>
<tr>
<th><label for="division">Division:</label></th>
<td>
<select id="division" name="division">
<?php
foreach (Division::getAllDivisions() as $division) {
if ($user->getDivision()->getDivision() == $division->getDivision())
echo '<option value=' . $division->getDivision() . ' selected>' . $division->getName() . '</option>';
else
echo '<option value=' . $division->getDivision() . '>' . $division->getName() . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="clearance">Clearance:</label></th>
<td>
<select id="clearance" name="clearance">
<?php
foreach (SecurityClearance::getAllClearances() as $val => $clearance) {
if ($val != 0) {
if ($user->getClearance()->getClearance() == $val)
echo '<option value=' . $val . ' selected>'. $clearance . '</option>';
else
echo '<option value=' . $val . '>'. $clearance . '</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="name">Name:</label></th>
<td><input type="text" id="name" name="name" value="<?php echo $user->getName() ?>" required /></td>
</tr>
<tr>
<th><label for="rank">Rank:</label></th>
<td>
<select id="rank" name="rank">
<?php
foreach (Rank::getRanks($_SESSION['user']) as $rank) {
if ($user->getRank()->getRank() == $rank->getRank())
echo '<option value=' . $rank->getRank() . ' selected>' . $rank->getName() . '</option>';
else
echo '<option value=' . $rank->getRank() . '>' . $rank->getName() . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="divcommand">Division Command Status:</label> </th>
<td>
<select id="divcommand" name="divcommand">
<?php
if ($user->getDivLeader()) {
?>
<option value=0>None</option>
<option value=1>Division Subleader</option>
<option value=2 selected>Division Leader</option>
<?php
} else if ($user->getSubDivLeader()) {
?>
<option value=0>None</option>
<option value=1 selected>Division Subleader</option>
<option value=2>Division Leader</option>
<?php
} else {
?>
<option value=0 selected>None</option>
<option value=1>Division Subleader</option>
<option value=2>Division Leader</option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2"><button id="edit" name="edit" class="btn btn-primary" type="button" onclick="editUser()">Edit</button></td>
</tr>
</table>
</form>
<div id="loading" class="alert alert-info" role="alert" style="display: none">
</div>
<?php
} else if ($do == 'edit') {
extract($_POST);
$subdiv = $div = 0;
switch($divcommand) {
case 1:
$subdiv = 1;
$div = 0;
break;
case 2:
$subdiv = 1;
$div = 1;
break;
}
Event::addEvent($name . '\'s account has been modified.', $_SESSION['user'], 2);
$user->update($login, $email, $division, $clearance, $name, $rank, $div, $subdiv);
} else if ($do == 'resetpass') {
$pass = User::createPassword();
$user->changePassword($pass);
$to = $user->getEmail();
$subject = 'IRIN - Password Reset';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: IRIN <DoNotReply@irin.eotir.com>" . "\r\n";
$message = 'Your password has been reset by an admin.<br /><br /><b>Login ID:</b> ' . $user->getUsername() . '<br /><b>New Password:</b> ' . $pass;
//mail($to, $subject, $message, $headers);
$mail->setFrom('DoNotReply@eotir.com', 'IRIN');
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
if (!$mail->send()) {
throw new MailException($mail->ErrorInfo);
}
?>
<script>
load('users', 'none', 'none', {});
</script>
<?php
Event::addEvent($name . '\'s password has been reset.', $_SESSION['user'], 2);
}
} else if ($action == 'delete') {
if ($do == 'none') {
?>
<a onclick="load('users', 'delete', 'delete', {id: '<?php echo $_GET['id'] ?>'})">Continue?</a> (<b>NOTE:</b> This action cannot be reversed!)
<?php
} else if ($do == 'delete') {
$user = new User($_GET['id']);
$user->delete();
$to = $user->getEmail();
$subject = 'IRIN - Account Deleted';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: IRIN <DoNotReply@irin.eotir.com>" . "\r\n";
$message = 'Your account has been deleted by an admin.<br /><br /><b>Login ID:</b> ' . $user->getUsername() . '<br /><b>Name:</b> ' . $user->getName();
//mail($to, $subject, $message, $headers);
$mail->setFrom('DoNotReply@eotir.com', 'IRIN');
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
if (!$mail->send()) {
throw new MailException($mail->ErrorInfo);
}
?>
<script>
load('users', 'none', 'none', {});
</script>
<?php
Event::addEvent($name . '\'s account has been deleted.', $_SESSION['user'], 3);
}
} else if ($action == 'new') {
if ($do == 'none') {
?>
<form action="#" method="post">
<table>
<tr>
<th><label for="login">Login ID:</label></th>
<td><input type="text" id="login" name="login" required /></td>
</tr>
<tr>
<th><label for="email">Email Address:</label> </th>
<td><input type="email" id="email" name="email" required /></td>
</tr>
<tr>
<th><label for="division">Division:</label></th>
<td>
<select id="division" name="division">
<?php
foreach (Division::getAllDivisions() as $division) {
echo '<option value=' . $division->getDivision() . '>' . $division->getName() . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="clearance">Clearance:</label></th>
<td>
<select id="clearance" name="clearance">
<?php
foreach (SecurityClearance::getAllClearances() as $val => $clearance) {
if ($val != 0) {
echo '<option value=' . $val . '>'. $clearance . '</option>';
}
}
?>
</select>
</td>
</tr>
<tr>
<th><label for="name">Name:</label></th>
<td><input type="text" id="name" name="name" required /></td>
</tr>
<tr>
<th><label for="rank">Rank:</label></th>
<td>
<select id="rank" name="rank">
<?php
foreach (Rank::getRanks($_SESSION['user']) as $rank) {
echo '<option value=' . $rank->getRank() . '>' . $rank->getName() . '</option>';
}
?>
</select>
</td>
</tr>
<tr>
<td colspan="2"><button id="create" name="create" class="btn btn-primary" type="button" onclick="createUser()">Create</button></td>
</tr>
</table>
</form>
<div id="error" class="alert alert-danger" role="alert" style="display: none">
</div>
<?php
} else if ($do == 'create') {
extract($_POST);
if (User::getUserByUsername($login)) {
echo 'Username already in use.';
} else if (User::getUserByEmail($email)) {
echo 'Email address already in use.';
} else {
$password = User::createPassword();
User::create($login, $email, $division, $clearance, $name, $rank, $password);
$to = $email;
$subject = 'IRIN - New Account';
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
$headers .= "From: IRIN <DoNotReply@irin.eotir.com>" . "\r\n";
$message = 'A new account has been created with your email address.<br /><br /><b>Login ID:</b> ' . $login . '<br /><b>New Password:</b> ' . $password . '<br /><b>Name:</b> ' . $name;
//mail($to, $subject, $message, $headers);
$mail->setFrom('DoNotReply@eotir.com', 'IRIN');
$mail->addAddress($to);
$mail->Subject = $subject;
$mail->Body = $message;
if (!$mail->send()) {
throw new MailException($mail->ErrorInfo);
}
echo 'true';
Event::addEvent($name . '\'s account has been created.', $_SESSION['user'], 1);
}
}
} else if ($action == 'switch') {
if (!isset($_SESSION['real']))
$_SESSION['real'] = $_SESSION['user'];
$_SESSION['user'] = new User($_GET['id']);
?>
<script>
window.location = 'main.php';
</script>
<?php
}