-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
executable file
·218 lines (178 loc) · 8.51 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
<?php
if (!file_exists('config.php')) {
echo "<h1>Site is not configured, please see documentation on configuration.</h1>";
exit;
}
session_start();
include 'db.php';
$version = trim(exec('git describe --tags $(git rev-list --tags --max-count=1)'));
//IS_DEMO = isset($_SESSION['IS_DEMO']) && $_SESSION['IS_DEMO'] === true;
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Overview of current locker Status Check">
<title>Truck Checks</title>
<link rel="stylesheet" href="styles/styles.css?id=<?php echo $version; ?> ">
<script>
// Automatically refresh the page using the REFRESH interval in config.php
setTimeout(function(){
window.location.reload(1);
}, <?php echo REFRESH; ?>);
// Function to display the last refreshed time in local browser time zone
function displayLastRefreshed() {
const now = new Date();
const formattedTime = now.toLocaleString(); // Local time string
document.getElementById('last-refreshed').textContent = 'Last refreshed at: ' + formattedTime;
}
// Run the function when the page loads
window.onload = displayLastRefreshed;
</script>
</head>
<body class="<?php echo IS_DEMO ? 'demo-mode' : ''; ?>">
<?php
;
//include 'templates/header.php';
// Read the cookie value
$colorBlindMode = isset($_COOKIE['color_blind_mode']) ? $_COOKIE['color_blind_mode'] : false;
if ($colorBlindMode) {
$colours = [
'green' => '#0072b2',
'orange' => '#e69f00',
'red' => '#d55e00',
];
} else {
$colours = [
'green' => '#28a745',
'orange' => '#ff8800',
'red' => '#dc3545',
];
}
$db = get_db_connection();
$trucks = $db->query('SELECT * FROM trucks')->fetchAll(PDO::FETCH_ASSOC);
function get_locker_status($locker_id, $db, $colours) {
// Fetch the most recent check for the locker
$query = $db->prepare('SELECT * FROM checks WHERE locker_id = :locker_id ORDER BY check_date DESC LIMIT 1');
$query->execute(['locker_id' => $locker_id]);
$check = $query->fetch(PDO::FETCH_ASSOC);
if (!$check) {
return ['status' => $colours['red'], 'check' => null, 'missing_items' => []];
}
// Check if the locker was checked in the last 7 days
$recent_check = (new DateTime())->diff(new DateTime($check['check_date']))->days < 6 && !$check['ignore_check'];
// Fetch missing items from the last check
$query = $db->prepare('SELECT items.name FROM check_items INNER JOIN items ON check_items.item_id = items.id WHERE check_items.check_id = :check_id AND check_items.is_present = 0');
$query->execute(['check_id' => $check['id']]);
$missing_items = $query->fetchAll(PDO::FETCH_COLUMN);
if ($recent_check && empty($missing_items)) {
return ['status' => $colours['green'], 'check' => $check, 'missing_items' => []];
} elseif ($recent_check && !empty($missing_items)) {
return ['status' => $colours['orange'], 'check' => $check, 'missing_items' => $missing_items];
} else {
return ['status' => $colours['red'], 'check' => $check, 'missing_items' => $missing_items];
}
}
// Function to convert UTC to NZST
function convertToNZST($utcDate) {
$date = new DateTime($utcDate, new DateTimeZone('UTC'));
$date->setTimezone(new DateTimeZone('Pacific/Auckland')); // NZST timezone
return $date->format('Y-m-d H:i:s');
}
?>
<?php foreach ($trucks as $truck): ?>
<div class="truck-listing">
<a href="check_locker_items.php?truck_id=<?= $truck['id'] ?>" class="truck-button">
<?= htmlspecialchars($truck['name']) ?> - Locker Checks
</a>
<?php
$query = $db->prepare('SELECT * FROM lockers WHERE truck_id = :truck_id order by name');
$query->execute(['truck_id' => $truck['id']]);
$lockers = $query->fetchAll(PDO::FETCH_ASSOC);
?>
<?php if (!empty($lockers)): ?>
<div class="locker-grid">
<?php foreach ($lockers as $locker): ?>
<?php
$locker_status = get_locker_status($locker['id'], $db, $colours);
$locker_url = 'check_locker_items.php?truck_id=' . $truck['id'] . '&locker_id=' . $locker['id'];
$background_color = $locker_status['status'];
$text_color = 'white';
$last_checked = $locker_status['check'] ? $locker_status['check']['check_date'] : 'Never';
$last_checked_display = $last_checked !== 'Never' ? convertToNZST($last_checked) : $last_checked;
$checked_by = $locker_status['check'] ? $locker_status['check']['checked_by'] : 'N/A';
$missing_items = $locker_status['missing_items'];
?>
<div class="locker-cell" style="background-color: <?= $background_color ?>; color: <?= $text_color ?>;"
onclick="showLockerInfo('<?= htmlspecialchars($locker['name']) ?>', '<?= $last_checked_display ?>', '<?= $checked_by ?>', <?= htmlspecialchars(json_encode($missing_items)) ?>, '<?= $locker_url ?>')">
<?= htmlspecialchars($locker['name']) ?>
<?php if (!empty($missing_items)): ?>
<span class="badge">!</span>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php else: ?>
<p>No lockers found for this truck.</p>
<?php endif; ?>
</div>
<?php endforeach; ?>
<!-- Admin Button -->
<div style="text-align: center; margin-top: 40px;">
<a href="find.php" class="button touch-button">Find an item</a>
<a href="changeover.php" class="button touch-button">Relief Change Over</a>
<a href="quiz/quiz.php" class="button touch-button">Quiz</a>
<a href="reports.php" class="button touch-button">Reports</a>
<a href="login.php" class="button touch-button">Admin</a>
<a href="settings.php" class="button touch-button">Settings</a>
</div>
<!-- Modal -->
<div id="lockerInfoModal" class="modal">
<div class="modal-content">
<span class="close-button" onclick="closeModal()">×</span>
<h2 id="lockerName">Locker Info</h2>
<p>Last Checked: <span id="lastChecked">N/A</span></p>
<p>Checked By: <span id="checkedBy">N/A</span></p>
<p>Missing Items: <span id="missingItems">None</span></p>
<button class="button touch-button" onclick="openUrl(document.getElementById('lockerUrl').innerText)">Check Locker</button>
<p id="lockerUrl" style="display: none;">
<!-- <p>Locker URL: <span id="lockerUrl">N/A</span></p> -->
<!-- <a href="" id="lockerUrl" target="_blank" class="button touch-button">Check <span id="lockerName">< /span> Locker 1</a>
<a href="#" id="lockerUrl" target="_blank" class="button touch-button">Check <span id="lockerName"></span> Locker 2</a> -->
<button class="button touch-button" onclick="closeModal()">Close</button>
</div>
</div>
<script>
function openUrl(url) {
window.open(url, '_blank');
}
function showLockerInfo(lockerName, lastChecked, checkedBy, missingItems, lockerUrl) {
document.getElementById('lockerName').innerText = lockerName;
if (lastChecked !== 'Never') {
document.getElementById('lastChecked').innerText = lastChecked;
} else {
document.getElementById('lastChecked').innerText = lastChecked;
}
document.getElementById('checkedBy').innerText = checkedBy;
if (missingItems.length > 0) {
document.getElementById('missingItems').innerHTML = missingItems.join(', ');
} else {
document.getElementById('missingItems').innerText = 'None';
}
document.getElementById('lockerInfoModal').style.display = 'block';
document.getElementById('lockerUrl').innerHTML = `<a href="${lockerUrl}" target="_blank">${lockerUrl}</a>`;
}
function closeModal() {
document.getElementById('lockerInfoModal').style.display = 'none';
}
</script>
<!-- Footer section -->
<footer>
<p id="last-refreshed" style="margin-top: 10px;"></p>
<div class="version-number">
Version: <?php echo htmlspecialchars($version); ?>
</div>
</footer>
</body>
</html>