= :now)) OR (starttime BETWEEN :now2 AND :future2) ) ORDER BY starttime ASC"; $stmt = $pdo->prepare($sql); $stmt->execute([ ':now' => $now, ':now2' => $now, ':future' => $future, ':future2' => $future ]); $notifications = $stmt->fetchAll(); // Categorize notifications $currentEvents = []; $upcomingEvents = []; foreach ($notifications as $notification) { $start = strtotime($notification['starttime']); $end = $notification['endtime'] ? strtotime($notification['endtime']) : null; $nowTimestamp = time(); if ($start <= $nowTimestamp && ($end === null || $end >= $nowTimestamp)) { $currentEvents[] = $notification; } else { $upcomingEvents[] = $notification; } } // Return JSON response echo json_encode([ 'success' => true, 'timestamp' => date('Y-m-d H:i:s'), 'current' => $currentEvents, 'upcoming' => $upcomingEvents ], JSON_PRETTY_PRINT); } catch (PDOException $e) { http_response_code(500); echo json_encode([ 'success' => false, 'error' => 'Database error: ' . $e->getMessage() ]); } catch (Exception $e) { http_response_code(500); echo json_encode([ 'success' => false, 'error' => 'Server error: ' . $e->getMessage() ]); } ?>