-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck.php
72 lines (55 loc) · 1.93 KB
/
check.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
<?php
include 'access.php';
// Start the session
session_start();
// Check if the user is logged in and has rescuer privileges
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'rescuer') {
header("Location: demo.php?block=1");
exit();
}
// Fetch the rescuer's information
$rescuerId = $_SESSION['user_id'];
// SQL query to get rescuer name and surname
$sql = "SELECT r.res_id, u.name AS rescuerName, u.surname AS rescuerSurname
FROM rescuer r
JOIN users u ON r.res_id = u.id
WHERE r.res_id = ?";
// Prepare and bind
$stmt = $con->prepare($sql);
$stmt->bind_param("i", $rescuerId);
$stmt->execute();
$result = $stmt->get_result();
$rescuer = $result->fetch_assoc();
$rescuerName = $rescuer['rescuerName'] ?? '';
$rescuerSurname = $rescuer['rescuerSurname'] ?? '';
$stmt->close();
// Load JSON data
$requestsJson = file_get_contents('requests.json');
$requests = json_decode($requestsJson, true);
// Initialize empty array in case of null
if (!$requests) {
$requests = [];
}
// Debugging: Output raw requests data
echo "<pre>Raw Requests Data:\n";
print_r($requests);
echo "</pre>";
$acceptedRequests = [];
// Process each request and output the unique keys being checked
foreach ($requests as $request) {
$uniqueKey = $request['request_id'] . '_' . $request['item_id'];
echo "<pre>Processing Request: $uniqueKey\n";
print_r($request);
echo "</pre>";
// Use the correct key names for rescuer name and surname
if (isset($request['status']) && $request['status'] === 'Accepted by rescuer' &&
$request['rescuerName'] === $rescuerName &&
$request['rescuerSurname'] === $rescuerSurname) {
$acceptedRequests[] = $request; // Add request to the list
}
}
// Debugging: Output accepted requests data
echo "<pre>Final Accepted Requests Data:\n";
print_r($acceptedRequests);
echo "</pre>";
?>