-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathget_safe_spaces.php
More file actions
39 lines (33 loc) · 1.09 KB
/
get_safe_spaces.php
File metadata and controls
39 lines (33 loc) · 1.09 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
<?php
require_once 'config.php';
header('Content-Type: application/json');
session_start();
if (!isset($_SESSION['user_id'])) {
echo json_encode(['success' => false, 'message' => 'User not logged in']);
exit;
}
$user_id = $_SESSION['user_id'];
// Get active safe spaces (not expired based on time_active) for the logged-in user
$sql = "SELECT ss.*, u.name as user_name
FROM safe_spaces ss
LEFT JOIN users u ON ss.user_id = u.id
WHERE TIMESTAMPADD(HOUR, time_active, timestamp) > NOW() AND ss.user_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$safe_spaces = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$safe_spaces[] = [
'id' => $row['id'],
'latitude' => (float)$row['latitude'],
'longitude' => (float)$row['longitude'],
'description' => $row['description'],
'timestamp' => $row['timestamp'],
'user_name' => $row['user_name'] ?? 'Anonymous'
];
}
}
echo json_encode($safe_spaces);
$conn->close();