load(); header('Content-Type: application/json'); if (!isLoggedIn()) { http_response_code(401); echo json_encode(['success' => false, 'error' => 'Niet geautoriseerd.']); exit; } try { $db = getDbConnection(); $date = $_GET['date'] ?? date('Y-m-d'); $channel = $_GET['channel'] ?? 'SBS9'; $requestedTime = $_GET['requested_time'] ?? null; // Get next start time using helper function $nextStartTime = calculateNextStartTime($db, $date, $channel, $requestedTime); jsonResponse([ 'next_start_time' => $nextStartTime, 'date' => $date, 'channel' => $channel ]); } catch (Exception $e) { jsonResponse([ 'error' => $e->getMessage() ], 500); }