Auto commit: 2025-10-03T00:08:51.683Z
This commit is contained in:
parent
fa09637699
commit
10404549fd
@ -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();
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user