= $today); } // Handle Actions (Save, Delete, Toggle). Success isn't announced with a // banner — the list itself is the feedback (the row appears/updates/ // disappears, the status badge flips) — same as the menu admin, and it // avoids a banner shoving the whole page down every time someone clicks // the status badge. // // The status toggle specifically is also fetched via AJAX (see index.js) // so clicking it doesn't reload the page, matching the menu item's status // toggle — everything else here (save/delete) is still a plain form POST. if ($_SERVER['REQUEST_METHOD'] === 'POST') { $isAjax = ($_SERVER['HTTP_X_REQUESTED_WITH'] ?? '') === 'XMLHttpRequest'; if (!verify_csrf_token($_POST['csrf_token'] ?? '')) { if ($isAjax) { header('Content-Type: application/json; charset=utf-8'); http_response_code(403); echo json_encode(['success' => false, 'error' => 'Session expired or invalid security token. Please refresh.']); exit; } $errorMsg = 'Session expired or invalid security token. Please try again.'; } else { $action = $_POST['action'] ?? ''; if ($action === 'save_announcement') { $annId = !empty($_POST['announcement_id']) ? (int)$_POST['announcement_id'] : null; save_announcement([ 'is_active' => isset($_POST['is_active']) ? 1 : 0, 'type' => $_POST['type'] ?? 'holiday', 'headline' => $_POST['headline'] ?? '', 'message' => $_POST['message'] ?? '', 'start_date' => $_POST['start_date'] ?? null, 'end_date' => $_POST['end_date'] ?? null, 'show_banner' => isset($_POST['show_banner']) ? 1 : 0, 'show_in_hours' => isset($_POST['show_in_hours']) ? 1 : 0, ], $annId); } elseif ($action === 'delete_announcement') { $annId = (int)($_POST['announcement_id'] ?? 0); if ($annId > 0) { delete_announcement($annId); } } elseif ($action === 'toggle_active') { $annId = (int)($_POST['announcement_id'] ?? 0); if ($annId > 0) { toggle_announcement_active($annId); } if ($isAjax) { header('Content-Type: application/json; charset=utf-8'); $ann = $annId > 0 ? get_announcement_by_id($annId) : null; if (!$ann) { http_response_code(404); echo json_encode(['success' => false, 'error' => 'Announcement not found.']); exit; } $isLive = announcement_is_live($ann, $today); echo json_encode([ 'success' => true, 'is_active' => (bool) $ann['is_active'], 'status_class' => $isLive ? 'active' : 'inactive', 'status_label' => $isLive ? '● Live' : ($ann['is_active'] ? '⏳ Scheduled' : '○ Off'), ]); exit; } } } } // Check if editing a specific announcement or creating new $editingId = isset($_GET['edit']) ? (int)$_GET['edit'] : null; $isCreatingNew = isset($_GET['new']); $editItem = null; if ($editingId) { $editItem = get_announcement_by_id($editingId); } $announcements = get_all_announcements(); ?> Pub Management Dashboard | The Old Fitz

Content & Operations

Site Announcements & Alerts

📢 All Announcements ()

No announcements created yet.

+ Create Your First Announcement
→ Always (while on)
Edit
>
Leave blank to show immediately while enabled.
Auto-hides after 11:59 PM on this date.
Cancel