diff --git a/assets/js/main.js b/assets/js/main.js index a8c440a..9fd2b4c 100644 --- a/assets/js/main.js +++ b/assets/js/main.js @@ -19,9 +19,17 @@ document.addEventListener('DOMContentLoaded', function() { slotMaxTime: '22:00:00', allDaySlot: false, slotDuration: '00:15:00', + slotLabelInterval: '00:15:00', + snapDuration: '00:15:00', selectable: true, editable: true, + selectLongPressDelay: 200, + longPressDelay: 200, select: function(info) { + // Force 1-hour selection + info.end = new Date(info.start.getTime() + 60 * 60 * 1000); + info.endStr = info.end.toISOString(); + currentSelectionInfo = info; modal.style.display = 'block'; document.getElementById('organizer-name').focus(); diff --git a/create_booking.php b/create_booking.php index 9cce516..16cc53c 100644 --- a/create_booking.php +++ b/create_booking.php @@ -9,6 +9,7 @@ $data = json_decode(file_get_contents('php://input'), true); if ($data) { try { $pdo = db(); + // Main booking $stmt = $pdo->prepare("INSERT INTO bookings (title, sport, start_time, end_time) VALUES (?, ?, ?, ?)"); $stmt->execute([ $data['title'], @@ -16,9 +17,24 @@ if ($data) { $data['start'], $data['end'] ]); + + // Buffer booking + $buffer_start = $data['end']; + $buffer_end_dt = new DateTime($buffer_start); + $buffer_end_dt->modify('+15 minutes'); + $buffer_end = $buffer_end_dt->format('Y-m-d H:i:s'); + + $stmt_buffer = $pdo->prepare("INSERT INTO bookings (title, sport, start_time, end_time) VALUES (?, ?, ?, ?)"); + $stmt_buffer->execute([ + 'Buffer', + 'Buffer', + $buffer_start, + $buffer_end + ]); + $response['status'] = 'success'; $response['message'] = 'Booking created successfully'; - } catch (PDOException $e) { + } catch (Exception $e) { // Catch generic Exception $response['message'] = 'Database error: ' . $e->getMessage(); } } diff --git a/get_bookings.php b/get_bookings.php index 8b7d8d0..fe9e06d 100644 --- a/get_bookings.php +++ b/get_bookings.php @@ -4,18 +4,21 @@ require_once 'db/config.php'; try { $pdo = db(); - // Insert sample data if the table is empty - $stmt = $pdo->query('SELECT COUNT(*) FROM bookings'); - if ($stmt->fetchColumn() == 0) { - $pdo->exec("INSERT INTO bookings (title, start_time, end_time) VALUES ('Booking 1', '2025-10-02 10:00:00', '2025-10-02 11:00:00')"); - $pdo->exec("INSERT INTO bookings (title, start_time, end_time) VALUES ('Booking 2', '2025-10-02 14:00:00', '2025-10-02 15:00:00')"); - } - $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($bookings); + echo json_encode($events); } catch (PDOException $e) { http_response_code(500);