-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.php
More file actions
366 lines (304 loc) · 14.6 KB
/
code.php
File metadata and controls
366 lines (304 loc) · 14.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
<?php
session_start();
require_once 'dbh.php';
if (isset($_POST['scannedData'])) {
$scannedData = mysqli_real_escape_string($conn, $_POST['scannedData']);
// Check the current time
date_default_timezone_set('Asia/Manila'); // Set timezone to Philippine time
$currentTime = date("H:i");
// Check if the time is within the restricted intervals (8:00 am - 9:00 am and 1:00 pm - 1:30 pm)
$isRestrictedTime = (($currentTime >= "08:00" && $currentTime <= "09:00"));
// Check if the typeofbusiness is "Personal"
if ($isRestrictedTime && isset($_POST['typeofbusiness']) && $_POST['typeofbusiness'] === 'Personal') {
// It's within the restricted time intervals and typeofbusiness is "Personal"
echo 'restricted';
} else {
// Query to check if the scanned data exists in the request table
$query = "SELECT * FROM request WHERE name = '$scannedData' AND Status = 'Partially Approved' ORDER BY `id` DESC";
$result = mysqli_query($conn, $query);
if ($result && mysqli_num_rows($result) > 0) {
// Scanned data exists in the database
// Update the Status column to 'Approved'
$update_query = "UPDATE request
SET `timedept` = NOW(),
Status = 'Approved',
`status1` = 'Pass-Slip',
`ImageName`= 'Check-Approved.png'
WHERE name = '$scannedData'
ORDER BY id DESC
LIMIT 1";
$update_result = mysqli_query($conn, $update_query);
if ($update_result) {
// Status updated successfully
echo 'exists';
} else {
// Error updating status
echo 'update_error';
}
} else {
// Scanned data does not exist in the database
echo 'not_exists';
}
}
} else if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Invalid request method or missing scannedData
echo 'invalid_request';
}
if (isset($_POST['approve_req'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$esttime = mysqli_real_escape_string($conn, $_POST['esttime']);
// Convert the $esttime to DATETIME format
$esttime = date('Y-m-d H:i:s', strtotime($esttime));
$query = "UPDATE request SET esttime = '$esttime', Status = '$status', confirmed_by = '$confirmed_by' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn);
header("Location: index.php");
exit(0);
}
}
if (isset($_POST['approve_req_desk'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$esttime = mysqli_real_escape_string($conn, $_POST['esttime']);
// Convert the $esttime to DATETIME format
$esttime = date('Y-m-d H:i:s', strtotime($esttime));
// Get the fixed time hours and minutes
$fix_hours = intval($_POST['fix_hours'] ?? 0);
$fix_minutes = intval($_POST['fix_minutes'] ?? 0);
// Calculate total minutes
$total_minutes = ($fix_hours * 60) + $fix_minutes;
// Get current time and add the total minutes
date_default_timezone_set('Asia/Manila'); // Ensure timezone is set
$current_time = new DateTime();
$current_time->modify("+$total_minutes minutes");
$time_allotted = $current_time->format('H:i:s');
$time_allotted_formatted = $fix_hours . ' hours ' . $fix_minutes . ' minutes';
$query = "UPDATE request SET esttime = '$time_allotted', Status = '$status', status1 = 'Scan Qrcode', confirmed_by = '$confirmed_by', time_allotted = '$time_allotted_formatted' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_desk.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn);
header("Location: index_desk.php");
exit(0);
}
}
if (isset($_POST['approve_req_r'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$esttime = mysqli_real_escape_string($conn, $_POST['esttime']);
// Convert the $esttime to DATETIME format
$esttime = date('Y-m-d H:i:s', strtotime($esttime));
// Get the fixed time hours and minutes
$fix_hours = intval($_POST['fix_hours'] ?? 0);
$fix_minutes = intval($_POST['fix_minutes'] ?? 0);
// Calculate total minutes
$total_minutes = ($fix_hours * 60) + $fix_minutes;
// Get current time and add the total minutes
date_default_timezone_set('Asia/Manila'); // Ensure timezone is set
$current_time = new DateTime();
$current_time->modify("+$total_minutes minutes");
$time_allotted = $current_time->format('H:i:s');
$time_allotted_formatted = $fix_hours . ' hours ' . $fix_minutes . ' minutes';
$query = "UPDATE request SET esttime = '$time_allotted', Status = '$status', status1 = 'Scan Qrcode', confirmed_by = '$confirmed_by', time_allotted = '$time_allotted_formatted' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_r.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn);
header("Location: index_r.php");
exit(0);
}
}
if (isset($_POST['approve_req_cviraa'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$esttime = mysqli_real_escape_string($conn, $_POST['esttime']);
// Convert the $esttime to DATETIME format
$esttime = date('Y-m-d H:i:s', strtotime($esttime));
$query = "UPDATE request SET esttime = '$esttime', Status = '$status', status1 = 'Scan Qrcode', confirmed_by = '$confirmed_by' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_cviraa.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn);
header("Location: index_cviraa.php");
exit(0);
}
}
if (isset($_POST['approve_req_tcws'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$esttime = mysqli_real_escape_string($conn, $_POST['esttime']);
// Convert the $esttime to DATETIME format
$esttime = date('Y-m-d H:i:s', strtotime($esttime));
$query = "UPDATE request SET esttime = '$esttime', Status = '$status', confirmed_by = '$confirmed_by' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_tcws.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn);
header("Location: index_tcws.php");
exit(0);
}
}
if (isset($_POST['decline_req'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$reason = mysqli_real_escape_string($conn, $_POST['decline_reason']);
$query = "UPDATE request SET Status = '$status', `status1` = 'Declined', confirmed_by = '$confirmed_by', `reason` = '$reason',`ImageName` = 'declined.png' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn); // Capture and display the error message
header("Location: index.php");
exit(0);
}
}
if (isset($_POST['decline_req_desk'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$reason = mysqli_real_escape_string($conn, $_POST['decline_reason']);
$query = "UPDATE request SET Status = '$status', `status1` = 'Declined', confirmed_by = '$confirmed_by', `reason` = '$reason',`ImageName` = 'declined.png' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_desk.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn); // Capture and display the error message
header("Location: index_desk.php");
exit(0);
}
}
if (isset($_POST['decline_req_r'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$reason = mysqli_real_escape_string($conn, $_POST['decline_reason']);
$query = "UPDATE request SET Status = '$status', `status1` = 'Declined', confirmed_by = '$confirmed_by', `reason` = '$reason',`ImageName` = 'declined.png' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_r.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn); // Capture and display the error message
header("Location: index_r.php");
exit(0);
}
}
if (isset($_POST['decline_req_cviraa'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$reason = mysqli_real_escape_string($conn, $_POST['decline_reason']);
$query = "UPDATE request SET Status = '$status', `status1` = 'Declined', confirmed_by = '$confirmed_by', `reason` = '$reason',`ImageName` = 'declined.png' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_cviraa.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn); // Capture and display the error message
header("Location: index_cviraa.php");
exit(0);
}
}
if (isset($_POST['decline_req_tcws'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$confirmed_by = mysqli_real_escape_string($conn, $_POST['confirmed_by']);
$reason = mysqli_real_escape_string($conn, $_POST['decline_reason']);
$query = "UPDATE request SET Status = '$status', `status1` = 'Declined', confirmed_by = '$confirmed_by', `reason` = '$reason',`ImageName` = 'declined.png' WHERE id = '$data_id'";
// Execute the query and check for errors
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Request Updated Successfully";
header("Location: index_tcws.php");
exit(0);
} else {
$_SESSION['message'] = "Request Not Updated. Error: " . mysqli_error($conn); // Capture and display the error message
header("Location: index_tcws.php");
exit(0);
}
}
if (isset($_POST['returned_emp'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$time_ret = mysqli_real_escape_string($conn, $_POST['time_ret']);
$location = mysqli_real_escape_string($conn, $_POST['designation']);
$remarks = mysqli_real_escape_string($conn, $_POST['remarks']);
$query = "UPDATE request SET `destination` = '$location', time_returned = '$time_ret', Status = '$status', `status1` = 'Present', remarks = '$remarks' WHERE id = '$data_id'";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
header("Location: approved.php");
exit(0);
} else {
header("Location: approved.php");
exit(0);
}
}
if (isset($_POST['delete'])) {
$id = $_POST['id'];
$query = "DELETE FROM logindb WHERE Id='$id'";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
$_SESSION['message'] = "Successfully Deleted";
header("Location: register.php");
exit(0);
} else {
$_SESSION['message'] = "Not Delete";
header("Location: register.php");
exit(0);
}
}
if (isset($_POST['returned_emp_desk'])) {
$data_id = mysqli_real_escape_string($conn, $_POST['data_id']);
$status = mysqli_real_escape_string($conn, $_POST['status']);
$time_ret = mysqli_real_escape_string($conn, $_POST['time_ret']);
$location = mysqli_real_escape_string($conn, $_POST['designation']);
$remarks = mysqli_real_escape_string($conn, $_POST['remarks']);
$query = "UPDATE request SET `destination` = '$location', time_returned = '$time_ret', Status = '$status', `status1` = 'Present', remarks = '$remarks' WHERE id = '$data_id'";
$query_run = mysqli_query($conn, $query);
if ($query_run) {
header("Location: approved_desk.php");
exit(0);
} else {
header("Location: approved_desk.php");
exit(0);
}
}