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 pathidrList.php
More file actions
135 lines (128 loc) · 7.14 KB
/
Copy pathidrList.php
File metadata and controls
135 lines (128 loc) · 7.14 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
<?php
include 'session.php';
include 'SQLFunctions.php';
$title = 'SVBX - Inspectors\' Daily Reports';
$userID = $_SESSION['userID'];
$role = $_SESSION['role'];
$qry = "SELECT userid, username, firstname, lastname, viewidr FROM users_enc where userid='$userID'";
$idrAuth = ($_SESSION['inspector'] || $role >= 30) ? $role : 0;
$qry = "SELECT idrID, i.userID, idrForDate, username FROM IDR i JOIN users_enc u on i.UserID=u.UserID";
$orderBy = " ORDER BY idrID DESC";
$errorMsg = [
'myIDRs' => 'Unable to retrieve reports for user',
'idrList' => 'There was a problem retrieving report list'
];
// check if non-admin user has own IDRs
try {
$link = f_sqlConnect();
if ($myIDRs = $link->query("$qry WHERE i.UserID='$userID'$orderBy")) {
// if auth level > 1 OR user has own IDRs, grant permission
$idrAuth = ($idrAuth > 10 || $myIDRs->num_rows) ? $idrAuth : 0;
}
if ($link->error) throw new mysqli_sql_exception($link->error);
} catch (Exception $e) {
echo "Unable to retrieve your daily reports";
} finally {
$link->close();
}
if ($idrAuth) {
include 'filestart.php';
$link = f_sqlConnect();
echo "
<header class='container page-header'>
<h1 class='page-title'>Inspectors' Daily Reports</h1>
</header>
<main class='container main-content'>
<div class='row'>
<div class='col-sm-10 col-md-6 offset-sm-1 offset-md-3'>
<div class='card no-border-radius box-shadow'>
<div class='card-body pad-more'>
<ul class='nav nav-tabs no-border flex-row flex-nowrap justify-content-center' role='tablist'>";
$active = ' active';
$expanded = " aria-expanded='true'";
if ($idrAuth > 10) {
echo "
<li class='item-margin-right-less' role='presentation'>
<a href='#allReports' aria-controls='allReports'{$expanded} role='tab' data-toggle='tab' class='h4 pl-3 pb-3 pr-3 border-dark-blue{$active}'>All Reports</a>
</li>";
$active = '';
$expanded = '';
}
// render My IDRs button only if user has IDRs of their own
if ($myIDRs->num_rows) {
echo "
<li class='item-margin-right-less' role='presentation'>
<a href='#myReports' aria-controls='myReports'{$expanded} role='tab' data-toggle='tab' class='h4 pl-3 pb-3 pr-3 border-dark-blue{$active}'>My Reports</a>
</li>";
}
echo "
</ul>
<div class='tab-content mt-3 thick-grey-line'>";
// if user is admin or super, query for all IDRs
$active = ' active';
if ($role >= 30) {
if ($result = $link->query($qry.$orderBy)) {
if ($result->num_rows) {
echo "
<div role='tabpanel' id='allReports' class='tab-pane pt-1 pl-2 pr-2 fit-content center-element{$active}'>
<ul class='pl-0'>";
while ($row = $result->fetch_assoc()) {
printf(
"<li class='item-margin-bottom-less'>
<a href='%s'>%s <span class='text-secondary font-italic'>• %s</span></a>
</li>",
"/idr.php?idrID={$row['idrID']}",
$row['idrForDate'],
$row['username']
);
}
echo "
</ul>
</div>";
$active = '';
} else echo "<h4>That's strange. No reports were found. I suspect something's up.</h4>";
$result->close();
} elseif ($link->error) {
echo "
<h4 id='error-msg-idrList' class='error-msg text-red'>{$errorMsg['idrList']}</h4>
<h5 id='error-msg-{$link->errno}' class='error-msg text-secondary'>{$link->error}</h5>";
return;
}
}
// if user has an IDRs of their own render them under My IDRs tab
if ($myIDRs) {
if ($myIDRs === $errorMsg['myIDRs']) {
echo "
<h4 id='error-msg-myIDRs' class='text-red'>{$errorMsg['myIDRs']}</h4>";
return;
}
elseif ($myIDRs->num_rows) {
echo "
<div role='tabpanel' id='myReports' class='tab-pane pt-1 pl-2 pr-2 fit-content center-element{$active}'>
<ul class='pl-0'>";
while ($row = $myIDRs->fetch_assoc()) {
printf(
"<li class='item-margin-bottom-less'>
<a href='%s'>%s</a>
</li>",
"/idr.php?idrID={$row['idrID']}",
$row['idrForDate']
);
}
echo "
</ul>
</div>";
$myIDRs->close();
}
}
echo "
</div>
</div>
</div>
</div>
</div>
</main>";
include 'fileend.php';
} else {
include "unauthorised.php";
}