This repository was archived by the owner on Nov 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathidr.php
More file actions
582 lines (565 loc) · 33.6 KB
/
Copy pathidr.php
File metadata and controls
582 lines (565 loc) · 33.6 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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<?php
include 'session.php';
include('SQLFunctions.php');
$title = "SVBX - Inspector's Daily Report";
$d = new DateTime();
$curDateNum = $d->format('Y-m-d');
$userID = $_SESSION['userID'];
$username = $_SESSION['username'];
$role = $_SESSION['role'];
$contractQry = 'SELECT contractID, contractName FROM contract';
$userFullName = "{$_SESSION['firstname']} {$_SESSION['lastname']}";
$userAuth = ($_SESSION['inspector'] || $role >= 30) ? $role : 0;
$locQry = "SELECT LocationID, LocationName FROM Location ORDER BY LocationID";
if ($userAuth < 10) {
// view is unauthorized to view
include 'unauthorised.php';
} else {
include('filestart.php');
$link = f_sqlConnect();
// view is authorized at some level
echo "
<header class='container page-header'>
<h1 class='page-title'>Inspector's Daily Report</h1>
</header>
<main class='container main-content'>";
if (isset($_GET['idrID'])) {
$idrID = $_GET['idrID'];
$idrQry = "SELECT idrID, i.userID, firstname, lastname, idrForDate, contractName, weather, shift, EIC, watchman, rapNum, sswpNum, tcpNum, approvedBy, editableUntil
FROM ((IDR i
LEFT JOIN users_enc u ON
i.userID=u.userID)
LEFT JOIN contract c ON
i.contractID=c.contractID)
WHERE i.idrID=$idrID";
$laborQry = "SELECT laborID, laborTotal, laborDesc, idrID, laborNotes, LocationName FROM
labor la JOIN
location L ON
la.LocationID=L.LocationID
WHERE la.idrID=$idrID";
$equipQry = "SELECT equipID, equipTotal, equipDesc, idrID, equipNotes, LocationName FROM
equipment e JOIN
location L ON
e.LocationID=L.LocationID
WHERE e.idrID=$idrID";
if ($result = $link->query($idrQry)) {
$numRows = intval($result->num_rows);
if ($numRows) {
while ($row = $result->fetch_assoc()) {
$expiry = new DateTime($row['editableUntil']);
$approved = $row['approvedBy'];
if ($row['userID'] === $userID || $userAuth > 1) {
// review view + comments
// + Approve btn if $userAuth > 1
echo ("
<h3 class='center-content font-italic'>Review</h3>
<div class='row item-margin-bottom'>
<div class='col-md-6'>
<div class='card h-100'>
<div class='card-header grey-bg'>
<h6 class='flex-row space-between'>
<span>Inspector Name</span>
<span>{$row['firstname']} {$row['lastname']}</span>
<input type='hidden' name='userID' value='{$userID}' />
</h6>
</div>
<div class='card-body'>
<ul>
<li class='flex-row space-between'>
<span style='font-style: bold'>date</span>
<span>{$row['idrForDate']}</span>
</li>
<li class='flex-row space-between'>
<span>Contract</span>
<span>{$row['contractName']}</span>
</li>
<li class='flex-row space-between'>
<span>weather</span>
<span>{$row['weather']}</span>
</li>
<li class='flex-row space-between'>
<span>shift hours</span>
<span>{$row['shift']}</span>
</li>
</ul>
</div>
</div>
</div>
<div class='col-md-6'>
<div class='card h-100'>
<div class='card-header grey-bg'><h6>Track safety</h6></div>
<div class='card-body'>
<ul>");
$safety = [
'EIC' => $row['EIC'],
'Watchman' => $row['watchman'],
'Rap #' => $row['rapNum'],
'SSWP #' => $row['sswpNum'],
'TCP #' => $row['tcpNum']
];
foreach ($safety as $key => $val) {
if (!$val) {
echo "
<li class='flex-row space-between'>
<span style='font-style: bold'>$key</span>
<span class='text-secondary font-italic'>none</span>
</li>";
} else {
echo "
<li class='flex-row space-between'>
<span style='font-style: bold'>$key</span>
<span>$val</span>
</li>";
}
}
echo ("
</ul>
</div>
</div>
</div>
</div>");
// iterate over results and display as nested <ul>s
if ($result = $link->query($laborQry)) {
$linkingT = 'laborAct_link';
$resourceT = 'labor';
$resourceID = 'laborID';
while ($row = $result->fetch_assoc()) {
$actQry = "SELECT * FROM (($linkingT link
JOIN $resourceT rsrc ON
link.{$resourceID}=rsrc.{$resourceID}
AND rsrc.{$resourceID}={$row[$resourceID]})
join activity a on
link.activityID=a.activityID)";
echo "
<div class='row'>
<p class='col-md-4'>
<span class='d-block text-secondary'>Location</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['LocationName']}</span>
</p>
<p class='col-md-2'>
<span class='d-block text-secondary'># personnel:</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['laborTotal']}</span>
</p>
<p class='col-md-6'>
<span class='d-block text-secondary'>Description of labor:</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['laborDesc']}</span>
</p>
</div>";
if ($row['laborNotes']) {
echo "
<div class='row'>
<p class='col-12 mb-2 thin-grey-border'>{$row['laborNotes']}</p>
</div>";
}
if ($actResult = $link->query($actQry)) {
echo "
<div class='row'>
<ul class='col'>";
while ($row = $actResult->fetch_assoc()) {
echo "
<li class='row striped pad-less'>
<p class='col-6 offset-md-1 mb-0'>
<span class='text-secondary font-italic mr-md-2'>task:</span>
<span> {$row['actDesc']}</span>
</p>
<p class='col-2 mb-0'>
<span class='text-secondary font-italic mr-md-2'># pers.:</span>
<span> {$row['numResources']}</span>
</p>
<p class='col-2 mb-0'>
<span class='text-secondary font-italic mr-md-2'>hours:</span>
<span>{$row['actHrs']}</span>
</p>
</li>";
}
echo "</ul></div>";
}
}
} else echo "<pre style='font-size: 2rem; color: orangeRed;'>{$link->error}</pre>";
if ($result = $link->query($equipQry)) {
$linkingT = 'equipAct_link';
$resourceT = 'equipment';
$resourceID = 'equipID';
while ($row = $result->fetch_assoc()) {
$actQry = "SELECT * FROM (($linkingT link
JOIN $resourceT rsrc ON
link.{$resourceID}=rsrc.{$resourceID}
AND rsrc.{$resourceID}={$row[$resourceID]})
join activity a on
link.activityID=a.activityID)";
echo "
<div class='row'>
<p class='col-md-4'>
<span class='d-block text-secondary'>Location</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['LocationName']}</span>
</p>
<p class='col-md-2'>
<span class='d-block text-secondary'># equipment:</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['equipTotal']}</span>
</p>
<p class='col-md-6'>
<span class='d-block text-secondary'>Description of equip:</span>
<span class='d-block border-radius thin-grey-border grey-bg pad-less'>{$row['equipDesc']}</span>
</p>
</div>";
if ($row['equipNotes']) {
echo "
<div class='row'>
<p class='col-12 thin-grey-border'>{$row['equipNotes']}</p>
</div>";
}
if ($actResult = $link->query($actQry)) {
echo "
<div class='row'>
<ul class='col'>";
while ($row = $actResult->fetch_assoc()) {
echo "
<li class='row striped pad-less'>
<p class='col-6 offset-md-1 mb-0'>
<span class='text-secondary font-italic mr-md-2'>task:</span>
<span> {$row['actDesc']}</span>
</p>
<p class='col-2 mb-0'>
<span class='text-secondary font-italic mr-md-2'># equip.:</span>
<span> {$row['numResources']}</span>
</p>
<p class='col-2 mb-0'>
<span class='text-secondary font-italic mr-md-2'>hours:</span>
<span>{$row['actHrs']}</span>
</p>
</li>";
}
echo "</ul></div>";
}
}
} else echo "<pre style='font-size: 2rem; color: orangeRed;'>{$link->error}</pre>";
// comment & Approve elements
echo ("
<hr />
<form class='item-margin-bottom'>
<input type='hidden' name='idrID' value='$idrID' />
<input type='hidden' name='userID' value='$userID' />
<div class='row item-margin-bottom'>
<div class='col-md-6 offset-md-3'>
<label>Comment</label>
<textarea id='commentBox' name='comment' class='form-control' rows='5'></textarea>
</div>
</div>");
if (!$approved && $userAuth > 1) {
echo "
<div class='row item-margin-bottom'>
<div class='col center-content'>
<button type='button' class='btn btn-lg btn-primary' onclick='return submitAndApprove(event);'>Approve</button>
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col center-content'>
<button type='button' class='btn btn-light text-secondary' onclick='return submitNoApprove(event);'><u>Request revisions</u></button>
</div>
</div>";
} else {
echo "
<div class='row item-margin-bottom'>
<div class='col center-content'>
<button type='button' class='btn btn-lg btn-primary' onclick='return submitNoApprove(event);'>Add comment</button>
</div>
</div>";
}
echo "
</form>";
// query for comments
$commentQry = "SELECT idrCommentID, commentDate, firstname, lastname, idrID, comment FROM
idrComments ic JOIN
users_enc ue ON
ic.userID = ue.userID
AND idrID=$idrID";
if ($result = $link->query($commentQry)) {
while ($row = $result->fetch_assoc()) {
echo "
<div class='row'>
<div class='col-md-8 offset-md-2'>
<blockquote class='blockquote pad border-radius thin-grey-border'>
<p class='mb-2'>{$row['comment']}</p>
<footer class='blockquote-footer'>{$row['firstname']} {$row['lastname']}, <cite class='title'>{$row['commentDate']}</cite></footer>
</blockquote>
</div>
</div>";
}
} else echo "<pre class='text-danger'>{$result->error}</pre>";
echo ("
<script>
function submitAndApprove(ev) {
submitReview(ev, 'true');
}
function submitNoApprove(ev) {
submitReview(ev, 'false');
}
function submitReview(ev, approval) {
ev.preventDefault();
const formData = new FormData(document.forms[0]);
formData.append('userID', {$userID});
formData.append('approve', approval);
window.fetch('submitIdrReview.php',
{
method: 'POST',
body: formData
}
).then(res => {
if (res.ok) return res.text();
else {
res.text().then(text => window.alert(text));
}
})
.then(text => {
window.alert(text);
window.location.reload();
return;
})
}
</script>");
} else {
http_response_code(401);
$code = http_response_code();
echo "<pre>";
var_dump($row);
echo "</pre>";
echo "
<ul>
<li>$code</li>
<li>$role</li>
<li>$userAuth</li>
<li>{$row['userID']} === $userID</li>
<li>{$row['approvedBy']}</li>
</ul>";
return;
}
}
} else {
http_response_code(404);
$code = http_response_code();
echo "
<div class='row'>
<div class='col-md-6 offset-md-3'>
<h4 class='text-center'>$code</h4>
<p class='text-light text-center bg-info pad'>No report found here</p>
<p class='text-primary text-center'>$numRows</p>
</div>
</div>";
return;
}
} else {
http_response_code(500);
$code = http_response_code();
echo "
<p class='text-danger text-center'>There was a problem retrieving the report data</p>
<p class='text-secondary text-center'>{$link->error}</p>";
return;
}
echo "</main>";
} else {
// initial input view
echo "
<h6><span class='text-danger'>*</span><span> = required</span></h6>
<div class='row'>
<form class='col-12' id='dailyReportForm'>
<div class='row item-margin-bottom'>
<div class='col-md-6' id='dayData'>
<div class='card h-100'>
<div class='card-header grey-bg'>
<h6 class='flex-row space-between'>
<span class='item-margin-right'>Inspector Name</span>
<span>{$userFullName}</span>
</h6>
<input type='hidden' name='userID' value='{$userID}' />
</div>
<div class='card-body'>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label item-margin-right'>Date</label>
</div>
<div class='col-6'>
<input name='idrForDate' type='date' value='{$curDateNum}' id='curDate' class='form-control' />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label item-margin-right required'>Contract</label>
</div>
<div class='col-6'>
<select name='contractID' class='form-control' required>";
if ($result = $link->query($contractQry)) {
while ($row = $result->fetch_array()) {
if ($row[1] === 'C700') $default='selected';
else $default = '';
echo "<option value ='{$row[0]}' $default>{$row[1]}</option>";
}
} else echo "<option value=''>{$result->error}</option>";
echo "
</select>
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label item-margin-right required'>Weather</label>
</div>
<div class='col-6'>
<input type='text' id='weatherDescrip' name='weather' class='form-control' required />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label item-margin-right required'>Shift Hrs</label>
</div>
<div class='col-6'>
<input type='text' id='shiftHrs' name='shift' class='form-control' required />
</div>
</div>
</div>
</div>
</div>
<div class='col-md-6' id='safetyData'>
<div class='card h-100'>
<div class='card-header grey-bg'>
<h6>Track safety</h6>
</div>
<div class='card-body'>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label'>EIC</label>
</div>
<div class='col-6'>
<input type='text' id='eic' name='EIC' class='form-control' />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label'>Watchman</label>
</div>
<div class='col-6'>
<input type='text' id='watchman' name='watchman' class='form-control' />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label'>RAP #</label>
</div>
<div class='col-6'>
<input type='text' id='rapNum' name='rapNum' class='form-control' />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label'>SSWP #</label>
</div>
<div class='col-6'>
<input type='text' id='sswpNum' name='sswpNum' class='form-control' />
</div>
</div>
<div class='row item-margin-bottom'>
<div class='col-6'>
<label class='input-label'>TCP #</label>
</div>
<div class='col-6'>
<input type='text' id='tcpNum' name='tcpNum' class='form-control' />
</div>
</div>
</div>
</div>
</div>
</div>
<div id='workInputList' class='row item-margin-bottom'>
<div id='workInputGroup_0' class='col-12 item-border-bottom item-margin-bottom'>
<div class='row item-margin-bottom'>
<div class='col-md-2 pl-1 pr-1'>
<label class='input-label required'>Location</label>
<select id='locationID_0' name='laborLocationID_0' class='form-control' required>";
if ($result = $link->query($locQry)) {
$locJSON = array();
while ($row = $result->fetch_assoc()) {
$locJSON[$row['LocationID']] = $row['LocationName'];
echo "<option value='{$row['LocationID']}'>{$row['LocationName']}</option>";
}
$locJSON = json_encode($locJSON);
} else echo "<option value=''>{$result->error}</option>";
echo "
</select>
</div>
<div class='col-md-2 pl-1 pr-1'>
<label class='input-label required'>Equip/Labor</label>
<select id='selectEquipLabor_0' class='form-control' required>
<option value='labor' selected>Labor</option>
<option value='equipment'>Equipment</option>
</select>
</div>
<div class='col-md-5 pl-1 pr-1'>
<label id='labelDescEquipLabor_0' class='input-label required'>Description of labor</label>
<input type='text' id='equipOrLaborDesc_0' name='laborDesc_0' class='form-control full-width' required>
</div>
<div class='col-md-2 pl-1 pr-1 mw-50'>
<label id='labelTotalEquipLabor_0' class='input-label required'>Tot. Personnel</label>
<input type='number' id='equipOrLaborTotal_0' name='laborTotal_0' class='form-control' required>
</div>
<div class='col-md-1 pl-1 pr-1 flex-column align-end mw-50'>
<label class='input-label'>Notes</label>
<button type='button' id='showNotes_0' class='form-control' style='width: 40px'><i class='typcn typcn-document-text'></i></button>
<aside
id='notesField_0'
style='
display: none;
position: absolute;
right: 50px;
bottom: -2px;
border: 1px solid #3333;
width: 260px;
padding: .25rem;
background-color: white;
'
>
<textarea name='laborNotes_0' id='notes_0' rows='5' cols='30' maxlength='125' class='form-control'></textarea>
</aside>
</div>
</div>
<div class='row item-margin-bottom pad border-radius grey-bg'>
<div class='col-md-6 pl-1 pr-1 item-margin-bottom'>
<label class='input-label'>Description of task/activity</label>
<input id='actInput_0' type='text' class='form-control full-width' />
</div>
<div class='col-md-3 pl-1 pr-1 mw-33 item-margin-bottom'>
<label id='labelNumEquipLabor_0' class='input-label'># persons</label>
<input type='number' id='numEquipOrLabor_0' class='form-control'/>
</div>
<div class='col-md-2 pl-1 pr-1 mw-33 item-margin-bottom'>
<label class='input-label'>Hours</label>
<input type='number' id='hours_0' class='form-control full-width' />
</div>
<div class='col-md-1 pl-1 pr-1 mw-33 item-margin-bottom'>
<label class='input-label'>Add Task</label>
<button type='button' id='addAct_0' class='btn btn-success block'>Add<i class='typcn typcn-chevron-right-outline'></i></button>
</div>
</div>
</div>
</div>
<div style='text-align: right'>
<button type='button' id='addLineBtn' class='btn btn-success'>Add Line</button>
</div>
<div class='row item-margin-bottom'>
<div class='col-md-6 offset-md-3'>
<label>Comment</label>
<textarea id='commentBox' name='comment' class='form-control' rows='5'></textarea>
</div>
</div>
<div class='center-content'>
<button type='submit' class='btn btn-primary btn-lg'>Submit</button>
</div>
</form>
</div>
</main>
<script>
var locJSON = $locJSON;
</script>;
<script src='js/dailyReport.js'></script>";
}
}
if (!empty($link) && is_a($link, 'mysqli')) $link->close();
include('fileend.php');
?>