- Node.js Express server with MySQL integration - Real-time event dashboard with live updates - GE Aerospace branding and design - Auto-refresh every 10 seconds (AJAX) - Shows current and upcoming events (48 hour window) - Connection status monitoring - Optimized for TV display 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
75 lines
2.0 KiB
PHP
75 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* API Endpoint - Fetch Live Notifications
|
|
* Returns JSON data for AJAX updates
|
|
*/
|
|
|
|
header('Content-Type: application/json');
|
|
require_once 'db_config.php';
|
|
|
|
try {
|
|
// Get current time and 48 hours from now
|
|
$now = date('Y-m-d H:i:s');
|
|
$future = date('Y-m-d H:i:s', strtotime('+48 hours'));
|
|
|
|
// Fetch active notifications within the next 48 hours
|
|
$pdo = getDbConnection();
|
|
|
|
$sql = "SELECT notificationid, notification, starttime, endtime, ticketnumber, link, isactive
|
|
FROM notifications
|
|
WHERE isactive = 1
|
|
AND (
|
|
(starttime <= :future AND (endtime IS NULL OR endtime >= :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()
|
|
]);
|
|
}
|
|
?>
|