34566-vm/get_bookings.php
2025-10-03 00:08:51 +00:00

27 lines
673 B
PHP

<?php
require_once 'db/config.php';
try {
$pdo = db();
$stmt = $pdo->query('SELECT title, start_time AS start, end_time AS end FROM bookings');
$bookings = $stmt->fetchAll(PDO::FETCH_ASSOC);
$events = [];
foreach ($bookings as $booking) {
if ($booking['title'] === 'Buffer') {
$booking['color'] = 'red';
} else {
$booking['color'] = '#3788d8'; // FullCalendar default blue
}
$events[] = $booking;
}
header('Content-Type: application/json');
echo json_encode($events);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode(['error' => $e->getMessage()]);
}