forked from gvsulib/library-Status
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.php
More file actions
executable file
·494 lines (350 loc) · 15.1 KB
/
admin.php
File metadata and controls
executable file
·494 lines (350 loc) · 15.1 KB
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
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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
<?php
session_start();
$_SESSION['location'] = 'http://' . $_SERVER['SERVER_NAME'] . "/status/admin.php";
include ('resources/php/markdown.php');
include 'resources/secret/config.php';
$db = new mysqli($db_host, $db_user, $db_pass, $db_database);
if ($db->connect_errno) {
printf("Connect failed: %s\n", $db->connect_error);
exit();
}
date_default_timezone_set('America/Detroit');
$logged_in = 0; // By default, user is logged out
// Debug the user login by a force login
//$_SESSION['username'] = 'earleyj';
if(isset($_SESSION['username'])) { // User has logged in
if (isset($_REQUEST['logout'])) {
$_SESSION = array();
session_destroy();
header('Location: index.php');
}
$username = $_SESSION['username'];
// User names are unique, so only need a single row
// Get all the bits from the user name so you don't have to ask again
$user_result=$db->query("SELECT * FROM user WHERE user_username = '$username' LIMIT 1");
if(($user_result) && ($user_result->num_rows > 0)) { // Query was successful, a user was found
while($row = $user_result->fetch_assoc()) {
$user_access = $row["user_access"];
$user_id = $row["user_id"];
}
$logged_in = 1;
// Create the user object as $user.
// User id is then $loggedin_user->user_id
$loggedin_user = $user_result->fetch_object();
// Open or all issues
if(isset($_GET['issues']) && ($_GET['issues'] == 'all')) {
$all_issues = 1;
$issue_query = "SELECT issue_entries.issue_id, systems.system_name, issue_entries.end_time FROM issue_entries, systems WHERE issue_entries.system_id = systems.system_id ORDER BY issue_entries.issue_id DESC";
} else {
// Display in all issues descending
if ($user_access == 9) {
$issue_query = "SELECT issue_entries.issue_id, systems.system_name, issue_entries.end_time FROM issue_entries, systems WHERE issue_entries.system_id = systems.system_id AND (issue_entries.end_time BETWEEN 0 AND 0) ORDER BY issue_entries.issue_id DESC";
// Display Systems first
} else if ($user_access == 1) {
$issue_query = "SELECT i.issue_id, s.system_name, i.end_time, s.system_category
FROM issue_entries i, systems s
WHERE i.system_id = s.system_id AND (i.end_time BETWEEN 0 AND 0)
ORDER BY s.system_category ASC, i.issue_id DESC";
// Display Buildings first
} else if ($user_access == 2) {
$issue_query = "SELECT i.issue_id, s.system_name, i.end_time, s.system_category
FROM issue_entries i, systems s
WHERE i.system_id = s.system_id AND (i.end_time BETWEEN 0 AND 0)
ORDER BY s.system_category DESC, i.issue_id DESC";
}
$all_issues = 0;
}
// new issue post
if ($_POST['submit_issue']) {
$issue_text = $db->real_escape_string($_POST['issue_text']);
$system_id = $_POST['system_id'];
$status_type_id = $_POST['status_type_id'];
// Create a time one year back to see use to check if posting time is in range.
$time_check = time();
$time_check = strtotime('-1 month');
// If time is something special or ready or for now and is within the last year.
if (($_POST['when'] != 'Now') && (strtotime($_POST['when']) > $time_check)) {
$time = strtotime($_POST['when']);
} else {
$time = time();
}
// Create new issue
$db->query("INSERT INTO issue_entries
VALUES ('','$system_id', $status_type_id, '$time', '0')");
$issue_id = $db->insert_id;
// Create a new status entry for issue
$db->query("INSERT INTO status_entries
VALUES ('','$issue_id','$time','1','$status_type_id','$user_id','$issue_text','0')");
}
// new status post$loggedin
if ($_POST['submit_status']) {
$issue_id = $_POST['issue_id'];
$status_type_id = $_POST['status_type_id'];
$status_text = $_POST['status'];
$issue_resolved = $_POST['issue_resolved'];
// Create a time one year back to see use to check if posting time is in range.
$time_check = time();
$time_check = strtotime('-1 month');
// If time is something special or ready or for now and is within the last year.
if (($_POST['when'] != 'Now') && (strtotime($_POST['when']) > $time_check)) {
$time = strtotime($_POST['when']);
} else {
$time = time();
}
$status_value = $status_type_id;
if ($issue_resolved == 'on') {
$status_value = 3;
//update issue end_time and close issue
$db->query("UPDATE issue_entries
SET issue_entries.end_time = '$time'
WHERE $issue_id = issue_entries.issue_id");
}
// Create a new status entry
$db->query("INSERT INTO status_entries
VALUES ('','$issue_id','$time','1','$status_value','$user_id','$status_text','0')") or die(mysqli_error());
}
} // End loop for logged in user
} else { // No $_SESSION['username'] variable, send to login script
// User has not logged in
header('Location: http://labs.library.gvsu.edu/login');
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>GVSU University Libraries Status</title>
<link rel="stylesheet" type="text/css" href="resources/css/styles.css"/>
<link rel="stylesheet" type="text/css" href="http://gvsu.edu/cms3/assets/741ECAAE-BD54-A816-71DAF591D1D7955C/libui.css" />
<link rel="stylesheet" type="text/css" href="resources/css/layout.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div id="gvsu-header-wrapper">
<div id="gvsu-header">
<div id="gvsu-logo">
<a href="http://www.gvsu.edu/">
<img src="http://www.gvsu.edu/homepage/files/img/gvsu_logo.png" alt="Grand Valley State University" border="0">
</a>
</div>
</div>
</div>
<div id="wrapper">
<div class="line break">
<div class="span2of3 unit left">
<h2><a href="index.php" title="University Libraries System Status">University Libraries Status</a></h2>
</div> <!-- end span -->
<div class="span3 unit left login">
<?php echo '<p style="text-align:right;">' . ($logged_in == 1 ? '<a href="?logout" title="Log out">Log out</a></p>' : '</p>'); ?>
</div>
</div> <!-- end line -->
<?php
if($logged_in != 1) {
?>
<div class="line">
<div class="span1 unit">
<span class="lib-error">Whoops! You don't have access to this page. Think this is wrong? Email <a href="mailto:reidsmam@gvsu.edu">reidsmam@gvsu.edu</a></span>
</div>
</div>
<?php
} else { // User is logged in, show the page
?>
<!-- Form Submit Status -->
<div class="line lib-form box">
<div class = "span1 unit">
<div class = "span1 unit">
<h4>Report an Issue</h4>
</div>
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" name="issue-form" onsubmit="return validateForm()">
<div style="float: left; padding-right: 1em;">
<label class="lib-inline">System:</label>
<select name="system_id">
<!-- load system names -->
<?php
$result = $db->query("SELECT * FROM systems");
while($row = $result->fetch_assoc())
{
// Restrict issue submission on user access limits
if ($user_access == 1 && $row['system_category'] == 0) {
echo '<option value="' . $row["system_id"] . '">' . $row["system_name"] . '</option>';
} else if ($user_access == 2 && $row['system_category'] == 1) {
echo '<option value="' . $row["system_id"] . '">' . $row["system_name"] . '</option>';
} else if ($user_access == 9) {
echo '<option value="' . $row["system_id"] . '">' . $row["system_name"] . '</option>';
}
}
?>
</select>
</div>
<div style="float: left;">
<label class="lib-inline">Status:</label>
<select name="status_type_id">
<!-- Load status types -->
<?php
$result = $db->query("SELECT * FROM status_type");
while($row = $result->fetch_assoc())
{
if ($row["status_type_id"] != 3)
echo '<option value="' . $row["status_type_id"] . '">' . $row["status_type_text"] . '</option>';
}
?>
</select>
</div>
<div class="when_box">
<label style="padding-top: .2em; ">When:</label>
<input type="text" name="when" value = "Now" style="width: 70%; font-size: .8em; font; color: #575757; display: inline">
</div>
<div class = "span1 unit" style="float: left; padding: 1em 0">
<textarea style="font-size: 1em" name="issue_text" placeholder="Describe issue..."></textarea>
</div>
<input class="status-button" style="float: left;" name="submit_issue" type="submit" value="Submit Issue" />
</form>
</div> <!-- end span -->
</div> <!-- end line -->
<div class="line break">
<div class="span1 unit">
<div class="lib-tabs">
<ul>
<li<?php echo ($all_issues == 0 ? ' class="active">' : '>'); ?> <a href="admin.php">Open Issues</a></li>
<li<?php echo ($all_issues == 1 ? ' class="active">' : '>'); ?><a href="admin.php?issues=all">All Issues</a></li>
</ul>
</div>
</div>
<!-- Create issues -->
<?php
$issue_result = $db->query($issue_query);
$n_rows = $issue_result->num_rows;
if ($n_rows > 0) {
while ($issue_entries = $issue_result->fetch_assoc()) {
$result = $db->query("SELECT s.status_id, s.issue_id, s.status_timestamp, s.status_public, s.status_user_id, s.status_text, s.status_delete, u.user_id, u.user_fn, u.user_ln, st.status_type_id, st.status_type_text
FROM status_entries s, user u, status_type st
WHERE s.issue_id = '{$issue_entries['issue_id']}' AND s.status_user_id = u.user_id AND s.status_type_id = st.status_type_id
ORDER BY s.status_timestamp ASC");
$num_rows = $result->num_rows;
$issue_id = $status_entries['issue_id'];
$rc = 0;
// display issues and check for comments
while ($status_entries = $result->fetch_assoc()) {
$rc++;
if ($rc == 1) {
echo '
<!-- Issue -->
<div class = "line">
<div class="issue-box" style="margin-top: 1em;">
<div class="span1 unit issue">
<div style="float: left;">
<p class="name">' . $status_entries['user_fn'] . " " . $status_entries['user_ln'] .'</p>
<p class="time">' . date("n/j/y - g:i a", $status_entries['status_timestamp']) . '</p>
</div>
<div style="float: right;">
<p class="name tag-system">' . $issue_entries['system_name'] . '</p>';
if ($status_entries['status_type_text'] == 'Outage') {
echo '<p class="name tag-outage">' . $status_entries['status_type_text'] . '</p>';
} else if ($status_entries['status_type_text'] == 'Disruption') {
echo '<p class="name tag-disruption">' . $status_entries['status_type_text'] . '</p>';
} else {
echo '<p class="name tag-resolution">' . $status_entries['status_type_text'] . '</p>';
}
echo '
</div>
<div class="comment-text">' . Markdown($status_entries['status_text']) . '</div>
</div> <!-- end span --> ';
if ($rc == $num_rows) {
if (($user_access-1 == $issue_entries['system_category']) || $user_access == 9) {
?>
<div class="span1 unit comment-box lib-form">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" name="status-form">
<textarea style="margin-top: .5em; max-width: 95%; height: 2em; font-size: 1em" name="status" placeholder="Add a comment"></textarea>
<div style = "padding-top: .5em;">
<input class="status-button" name="submit_status" type="submit" value="Post comment" />
<label style="margin-left: 1em;" class="lib-inline resolved">Issue Resolved:</label>
<input type="checkbox" name="issue_resolved">
<div class="when_box" style="margin-right: 1.2em;">
<label style="padding-top: .2em; ">When:</label>
<input type="text" name="when" value = "Now" style="width: 70%; font-size: .8em; font; color: #575757; display: inline">
</div>
</div>
<input type="hidden" name="issue_id" value="<?php echo $status_entries['issue_id'] ?>" />
<input type="hidden" name="status_type_id" value="<?php echo $status_entries['status_type_id'] ?>" />
</form>
</div>
<?php
}
}
// comment show/hide
if ($num_rows >= 2) {
echo '
<div style = "cursor: hand; cursor: pointer;" class="comment-toggle">
<div class="span1 unit comment-box">
<p class="name">'.($num_rows -1).' comment';
if ($num_rows > 2)
echo 's';
echo '</p>
</div>
</div>';
}
// Comment wrapper
echo '<div class="comment-wrapper">';
// list comments
} else if ($num_rows >= 2) {
echo '
<div class="span1 unit comment-box">
<div style="float: left;">
<p class="name">' . $status_entries['user_fn'] . " " . $status_entries['user_ln'] .'</p>
<p class="time">' . date("n/j/y - g:i a", $status_entries["status_timestamp"]) . '</p>
</div>
<div class ="comment-text">' . Markdown($status_entries['status_text']) . '</div>
</div> <!-- end span --> ';
// Add a comment
if ($rc == $num_rows && $status_entries['status_type_id'] != 3) {
if (($user_access-1 == $issue_entries['system_category']) || $user_access == 9) {
?>
<div class="span1 unit comment-box lib-form">
<form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST" name="status-form">
<textarea style="margin-top: .5em; max-width: 95%; height: 2em; font-size: 1em" name="status" placeholder="Add a comment"></textarea>
<div style = "padding: .5em;">
<input class="status-button" style="float: left; margin-top: 0em;" name="submit_status" type="submit" value="Post comment" />
<label style="margin-left: 1em;" class="lib-inline">Issue Resolved:</label>
<input type="checkbox" name="issue_resolved">
</div>
<input type="hidden" name="issue_id" value="<?php echo $status_entries['issue_id'] ?>" />
<input type="hidden" name="status_type_id" value="<?php echo $status_entries['status_type_id'] ?>" />
</form>
</div>
<?php
}
}
}
} // close status loop
// close comment wrapper
echo '</div>';
echo '
</div>
</div> <!-- close issue line -->';
} // close issue loop
} else {
echo '<p style="margin-top: 1em">No open issues.</p>';
}
?>
</div>
<div class="line footer" style="padding-bottom: 3em;">
<div class="span1 unit">
<p>Written by <a href="http://jonearley.net/">Jon Earley</a> for <a href="http://gvsu.edu/library">Grand Valley State University Libraries</a>. Code is <a href="https://github.com/gvsulib/library-Status">available on Github</a>.</p>
</div> <!-- end span -->
</div> <!-- end line -->
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
// Hide the items you don't want to show if JS is available
$(".comment-wrapper").hide();
// Make the div toggle visible/invisible on click
$(".comment-toggle").click(function() {
$(this).next(".comment-wrapper").slideToggle(400);
});
});
</script>
<?php
} // End logged-in user loop
?>
</body>
</html>