-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_bookings.php
More file actions
31 lines (25 loc) · 805 Bytes
/
get_bookings.php
File metadata and controls
31 lines (25 loc) · 805 Bytes
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
<?php
session_start();
require 'db.php';
if (!isset($_SESSION['user_id'])) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
exit();
}
$user_id = $_SESSION['user_id'];
$role = $_SESSION['role'] ?? 'user';
if ($role === 'admin') {
$stmt = $conn->prepare("SELECT id, name, email, phone, service, date, time, status FROM bookings ORDER BY date DESC LIMIT 50");
} else {
$stmt = $conn->prepare("SELECT id, name, email, phone, service, date, time, status FROM bookings WHERE user_id = ? ORDER BY date DESC LIMIT 50");
$stmt->bind_param("i", $user_id);
}
$stmt->execute();
$query = $stmt->get_result();
$bookings = [];
while ($row = $query->fetch_assoc()) {
$bookings[] = $row;
}
header('Content-Type: application/json');
echo json_encode($bookings);
?>