-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
395 lines (385 loc) · 10.3 KB
/
index.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
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
<?php
session_start();
set_error_handler("messageError");
// DEV NOTES---------------------------------------------------------------------------
// created by: Vincent Agresti
// program name: Consultant Check Program
// short summary: This program allows for administrators to monitor and document the printer checks and towers desk logins with ease.
// GLOBALS-----------------------------------------------------------------------------
$connection = new mysqli("localhost","root","","mydb");
if ($connection->connect_error)
{
trigger_error('Database connection failed: '.$connection->connect_error,E_USER_ERROR);
}
if (date("I", time()) == TRUE)
{
$rightNow = date('Y-m-d H:i:s', time()-21600); //21600 seconds - 6 hours (DST)
}
else
{
$rightNow = date('Y-m-d H:i:s', time()-18000); //18000 seconds - 5 hours
}
$messages = "";
$shiftAddNum = 0;
$shiftAddSuccess = 0;
$towersActive = FALSE;
$pageName = "index.php";
if (!empty($_SESSION["DMODE"]))
{
$displayMode = $_SESSION["DMODE"];
}
else
{
$displayMode = "AllCons";
}
//Verify GETs
if (!empty($_GET["menu"]))
{
$displayType = $_GET["menu"];
}
else
{
$displayType = "";
}
if (!empty($_GET["display"]))
{
$displayVal = $_GET["display"];
}
//Verify POSTs
if (!empty($_POST["action"]))
{
$fAction = $_POST["action"];
}
else
{
$fAction = "N/A";
}
if ($fAction != "Add Shift")
{
if (empty($_POST["startDate"]))
{
$_POST["startDate"] = "IGNORE";
}
if (empty($_POST["endDate"]))
{
$_POST["endDate"] = "IGNORE";
}
}
// FUNCTIONS---------------------------------------------------------------------------
//Display HTML Header
function displayHead()
{
global $displayType;
if ($displayType == "checks")
{
$title = "Browse Checks";
}
else if ($displayType == "add")
{
$title = "Add New Checks";
}
else if ($displayType == "stats")
{
$title = "Printer Check Stats";
}
else
{
$title = "Priority Checks";
}
echo "<!DOCTYPE html>
<head>
<meta http-equiv='Content-type' content='text/html;charset=UTF-8' />
<title>Consultant Checks</title>
<link rel='stylesheet' type='text/css' href='reset.css'/>
<link rel='stylesheet' type='text/css' href='css.css'/>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>";
?>
<script>
$(document).ready(function(){
$(".errorM").click(function(event){
$(this).hide();
});
$(".resultM").click(function(event){
$(this).hide();
});
});
function clearThis(target){target.value= "";}
</script>
<?php
echo"</head>
<body>
<header>$title</header>
<div class='body'>\n";
}
//Displays HTML Footer
function displayFooter()
{
global $displayType;
global $displayMode;
global $pageName;
echo "</div>
<footer>
<div class='footLinks'>
<a href='$pageName'>[priority]</a> <a href='$pageName?menu=checks'>[checks]</a> <a href='$pageName?menu=add'>[add shifts]</a> <a href='$pageName?menu=admin'>[admin]</a>
</div>
<div class='displayGroups'>";
if ($displayMode == "LabCons")
{
echo "<a href=$pageName?display=AllCons&menu=$displayType>[All *Cons]</a> <em>[LabCons Only]</em> <a href=$pageName?display=TechCons&menu=$displayType>[TechCons Only]</a>\n";
}
else if ($displayMode == "TechCons")
{
echo "<a href=$pageName?display=AllCons&menu=$displayType>[All *Cons]</a> <a href=$pageName?display=LabCons&menu=$displayType>[LabCons Only]</a> <em>[TechCons Only]</em>\n";
}
else
{
echo "<em>[All *Cons]</em> <a href=$pageName?display=LabCons&menu=$displayType>[LabCons Only]</a> <a href=$pageName?display=TechCons&menu=$displayType>[TechCons Only]</a>\n";
}
echo "</div>
</footer>
</body>
</html>";
}
//Custom Error Handler
function messageError($errno,$errstr)
{
global $messages;
$errorTrimmed = str_replace(':','-',$errstr);
$messages .= "ERROR:[$errno] $errorTrimmed::";
}
//Displays Success & Error Messages
function displayMessages()
{
global $messages;
echo "<div class='messages'>";
$continue = TRUE;
while ($continue == TRUE)
{
$end = strpos($messages, "::");
if ($end === FALSE)
{
$continue = FALSE;
}
else
{
$thisMessage = strstr($messages,"::",TRUE);
$messages = strstr($messages,"::",FALSE);
$messages = substr($messages,2);
$type = strstr($thisMessage,":",TRUE);
$message = strstr($thisMessage,":",FALSE);
$message = substr($message,1);
if ($type == "ERROR")
{
echo "<div class='errorM'>$message</div>";
}
else if ($type == "RESULT")
{
echo "<div class='resultM'>$message</div>";
}
else{}
}
}
echo "</div>";
}
//Toggles Between All, LabCons and TechCons
function displayModeToggle()
{
global $displayMode;
global $displayVal;
if (!empty($displayVal))
{
if ($displayVal == "LabCons")
{
$_SESSION["DMODE"] = "LabCons";
}
else if ($displayVal == "TechCons")
{
$_SESSION["DMODE"] = "TechCons";
}
else
{
$_SESSION["DMODE"] = "AllCons";
}
$displayMode = $_SESSION["DMODE"];
}
}
//Makes the drop-down form selection boxes for the Search Form
function generateDropDowns($section,$id)
{
global $displayMode;
global $connection;
if ($section == "location")
{
$name = "location";
if ($displayMode == "LabCons")
{
$query = "SELECT locationCode AS code, locationName AS name FROM locations WHERE locationType = 1 AND active = 1 ORDER BY locationCode ASC ";
}
else if ($displayMode == "TechCons")
{
$query = "SELECT locationCode AS code, locationName AS name FROM locations WHERE locationType != 1 AND active = 1 ORDER BY locationCode ASC ";
}
else
{
$query = "SELECT locationCode AS code, locationName AS name FROM locations WHERE active = 1 ORDER BY locationCode ASC ";
}
}
else if ($section == "employees")
{
$name = "employees".$id;
if ($displayMode == "LabCons")
{
$query = "SELECT username AS code, CONCAT_WS(', ', lastName, firstName) AS name FROM employees WHERE type = 1 AND active = 1 ORDER BY lastName ASC ";
}
else if ($displayMode == "TechCons")
{
$query = "SELECT username AS code, CONCAT_WS(', ', lastName, firstName) AS name FROM employees WHERE type = 2 AND active = 1 ORDER BY lastName ASC ";
}
else
{
$query = "SELECT username AS code, CONCAT_WS(', ', lastName, firstName) AS name FROM employees WHERE active = 1 ORDER BY lastName ASC ";
}
}
else if ($section == "shifts")
{
$name = "shifts";
$query = NULL;
if ($displayMode == "LabCons")
{
$sectArray = array(0=>"Alumni",1=>"Benedum",2=>"Hillman");
}
else if ($displayMode == "TechCons")
{
$sectArray = array(3=>"WPU, Towers & Bruce");
}
else
{
$sectArray = array(0=>"Alumni",1=>"Benedum",2=>"Hillman",3=>"WPU, Towers & Bruce");
}
}
else if ($section == "status")
{
$name = "status";
$query = NULL;
$sectArray = array(0=>"All",1=>"Not Completed",2=>"Completed",3=>"Missed");
}
else if ($section == "noteS")
{
$name = "note";
$query = NULL;
$sectArray = array("All"=>"All","None"=>"None","Completed"=>"Completed","Missed"=>"Missed","Email Sent"=>"Email Sent","Called Off"=>"Called Off","Supervisor Excused"=>"Supervisor Excused","Single Coverage"=>"Single Coverage","Location Error"=>"Location Error","Program Error"=>"Program Error","Printer Error"=>"Printer Error","Other Notes"=>"Other Notes","Deletion"=>"Deletion");
}
else if ($section == "noteU")
{
$name = "note".$id;
$query = NULL;
$sectArray = array("IGNORE"=>"","Missed"=>"Missed","Email Sent"=>"Email Sent","Called Off"=>"Called Off","Supervisor Excused"=>"Supervisor Excused","Single Coverage"=>"Single Coverage","Location Error"=>"Location Error","Program Error"=>"Program Error","Printer Error"=>"Printer Error","Other..."=>"Other...","Deletion"=>"Deletion");
}
else{}
$dropDownExport = "<select name='$name'>\n";
if ($query != NULL)
{
if ($stmtDD = $connection->prepare($query))
{
$dropDownExport .= "<option value='IGNORE'>All</option>\n";
$stmtDD->execute();
$stmtDD->store_result();
$stmtDD->bind_result($code,$name);
while ($stmtDD->fetch())
{
if (!empty($_POST[$name]) && $code == $_POST[$name])
{
$dropDownExport .= "<option value='$code' selected>$name</option>\n";
}
else
{
$dropDownExport .= "<option value='$code'>$name</option>\n";
}
}
}
}
else
{
foreach ($sectArray as $key => $value)
{
if (!empty($_POST[$name]) && $key == $_POST[$name])
{
$dropDownExport .= "<option value='$key' selected>$value</option>\n";
}
else
{
$dropDownExport .= "<option value='$key'>$value</option>\n";
}
}
}
$dropDownExport .= "</select><br/>\n";
return $dropDownExport;
}
// INCLUDES-----------------------------------------------------------------------------
require 'display.php'; //Display Functions
require 'action.php'; //Form-Action Functions
// PAGE RUN-----------------------------------------------------------------------------
displayModeToggle();
displayHead();
if ($displayType == "checks")
{
checkSearchForm();
if ($fAction == "Search")
{
checkSearchFunc($_POST["startDate"],$_POST["endDate"],$_POST["employees"],$_POST["location"],$_POST["note"],$_POST["active"]);
}
else if (!empty($fAction) && $fAction != "Search")
{
updateChecksFunc();
}
else{}
}
else if ($displayType == "add")
{
if ($fAction == "Add Custom Shift")
{
addCustomCheckFunc();
}
else if ($fAction == "Upload Checks XML")
{
parseChecksXML();
}
else{}
if ($displayMode == "TechCons" || $displayMode == "LabCons")
{
addXMLChecksForm();
addCustomCheckForm();
}
else
{
echo "<h1>Please Select a Con Type</h1><br/><a href=$pageName?display=LabCons&menu=add><strong>LabCons Only</strong></a><br/><a href=$pageName?display=TechCons&menu=add><strong>TechCons Only</strong></a>";
}
}
else if ($displayType == "admin")
{
if ($fAction == "Upload Consultant XML")
{
parseConsultantXML();
}
else if ($fAction == "Add Consultant")
{
addConsultantFunc();
}
else if ($fAction == "Edit Consultant")
{
editConsultantFunc();
}
consultantAdminForm();
//printerAdminForm();
}
else
{
if ($fAction == "Update")
{
updateChecksFunc();
}
checkSearchFunc("IGNORE",$rightNow,"IGNORE","IGNORE",NULL,1);
}
displayMessages();
displayFooter();
?>