-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.php
262 lines (197 loc) · 10 KB
/
admin.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
<?php
session_start();
include('credentials.php');
$success = 0;
if (!isset($_SESSION['username'])) {
echo "<script type='text/javascript'> alert('Please log in first!') </script>";
echo "<meta http-equiv='Refresh' content='0;URL=adminLogin.php'>";
exit(0);
}
if (isset($_GET['logout'])) {
session_destroy();
echo "<meta http-equiv='Refresh' content='0;URL=adminLogin.php'>";
exit(0);
}
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$rows = $pdo->query("SELECT * FROM Admins;");
foreach ($rows as $row) {
if ($row['Email'] == $_SESSION['username']) {
$_SESSION['userType'] = "admin";
$success = 1;
}
}
if ($success == 0){
echo "<script type='text/javascript'> alert('You are not an assistant.') </script>";
session_destroy();
echo "<meta http-equiv='Refresh' content='0;URL=adminLogin.php'>";
exit(0);
}
}
catch (Exception $e) {
echo "<script type='text/javascript'> alert('Error when query if is a valid assistant.') </script>";
echo "<meta http-equiv='Refresh' content='0;URL=adminLogin.php'>";
exit(0);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Assistant</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<link rel="stylesheet" href="css/homepage.css">
</head>
<body>
<div class="wrapper">
<div>
Welcome <?php echo $_SESSION['username']?> !
</div>
<p>
<a href="admin.php?logout='1'" style="color: #dddd55">logout</a>
</p>
<div id="first">
<p id="currentLab"></p>
<p id="nextLab"></p>
<p id="requestInfo"></p>
<form action="getNextRequest.php" style="float: left">
<button id="getNext" class="btn btn-primary">Get Next</button>
</form>
<form action="suspendOneRequest.php" style="float: right">
<button id="suspend" class="btn btn-danger">Suspend</button>
</form>
<form action="finishOneRequest.php">
<button id="finish" class="btn btn-success" style="margin-left: 26.5%">Finish</button>
</form>
<p/>
<p id="requestSize"></p>
<table class='table-hover' border="1" style="width: 100%; border-color: white;">
<caption style="font-weight: bold; font-size: large; caption-side: top; color: #dd5; text-align: center">Request History</caption>
<tr style="color: #dddd55">
<th>Module</th>
<th>State</th>
<th>Generated By</th>
<th>Created Time</th>
<th>Finished Time</th>
</tr>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("credentials.php");
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("SELECT * FROM Requests WHERE Handled_By = :handled_by ORDER BY Created_Time;");
$stmt->bindParam(':handled_by', $_SESSION['username']);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach ($rows as $row) {
echo "<tr><td>" . $row['Made_In'] . "</td><td>" . $row['State'] . "</td><td>" .$row['Generated_By'] . "</td><td>" . $row['Created_Time'] . "</td><td>" . $row['Finished_Time'] . "</td></tr>";
}
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error for search history query!') </script>";
exit(0);
}
?>
</table>
<table class='table-hover' border="1" style="width: 100%; border-color: white;" id="suspendedTable">
<caption style="font-weight: bold; font-size: large; caption-side: top; color: #dd5; text-align: center">Suspended Requests</caption>
<tr style="color: #dddd55">
<th>Module</th>
<th>Generated By</th>
<th>Created Time</th>
<th>Suspended By</th>
<th>Action</th>
</tr>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("credentials.php");
$allModules;
//Query modules
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("SELECT * FROM AdminEnrollment WHERE aEmail = :email;");
$stmt->bindParam(":email", $_SESSION['username']);
$stmt->execute();
$allModules = $stmt->fetchAll();
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error when search modules!') </script>";
exit(0);
}
foreach ($allModules as $module) {
try {
$dsn = 'mysql:dbname='.$db_database.';host='.$db_host;
$pdo = new PDO($dsn,$db_username,$db_password);
$pdo->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$stmt = $pdo->prepare("SELECT * FROM Requests WHERE State = 'Suspended' AND Made_In = :module ORDER BY Created_Time;");
$stmt->bindParam(":module", $module['mCode']);
$stmt->execute();
$rows = $stmt->fetchAll();
foreach ($rows as $row) {
echo "<tr><td>" . $row['Made_In'] . "</td><td>" .$row['Generated_By'] . "</td><td>" . $row['Created_Time'] . "</td><td>" . $row['Handled_By'] . "</td>";
echo "<td><a href='finishSuspendedRequest.php?id=" . $row['ID'] . "' style='color: #dddd55'>Finish</a> </td></tr>";
// echo "<td><form action='finishSuspendedRequest.php?id=" . $row['ID'] . "'><input type=\"submit\" value=\"Finish\" id=\"finishSuspend\"/></form></td></tr>";
}
} catch (Exception $exception){
echo "<script type='text/javascript'> alert('Error when query request') </script>";
exit(0);
}
}
?>
</table>
</div>
</div>
<script>
function initial() {
$.get("nextRequest.php", function (email) {
if (email === "null"){
document.getElementById('requestInfo').innerHTML = "There is no request in the waiting queue you can handle now.";
document.getElementById('getNext').disabled = true;
document.getElementById('finish').disabled = true;
document.getElementById('suspend').disabled = true;
} else if (email === "Has request") {
document.getElementById('requestInfo').innerHTML = "There is one request available.";
document.getElementById('getNext').disabled = false;
document.getElementById('finish').disabled = true;
document.getElementById('suspend').disabled = true;
} else {
document.getElementById('requestInfo').innerHTML = "You should be coming for " + email + ".";
document.getElementById('getNext').disabled = true;
document.getElementById('finish').disabled = false;
document.getElementById('suspend').disabled = false;
}
});
$.get("requestSize.php", function (size) {
document.getElementById('requestSize').innerHTML = 'Waiting requests size (includes being handling ones): ' + size;
});
$.get("currentLab.php", function (lab) {
if (lab === 'duplicate labs') {
document.getElementById('currentLab').innerHTML = "There are more than 1 labs in the room, please contact admin!";
} else if (lab === "no lab") {
document.getElementById('currentLab').innerHTML = "No lab now.";
} else {
document.getElementById("currentLab").innerHTML = "Current lab is " + lab + ".";
}
});
$.get("nextLab.php", function (lab) {
if (lab === 'no lab after') {
document.getElementById("nextLab").innerHTML = "No more lab today.";
} else {
document.getElementById("nextLab").innerHTML = "Next lab is " + lab + ".";
}
});
}
initial();
setInterval(initial, 5000)
</script>
</body>
</html>