On Tap ThuβSat
- -- Thursday @@ -283,4 +295,4 @@ $siteUrl = rtrim(SITE_URL, '/'); -
diff --git a/admin/index.php b/admin/index.php index a65117e..a1bec99 100644 --- a/admin/index.php +++ b/admin/index.php @@ -4,48 +4,58 @@ require_once __DIR__ . '/../inc/announcements.php'; require_auth(); $user = get_logged_in_user(); -$pdo = get_db(); $successMsg = ''; $errorMsg = ''; -// Handle announcement form submission -if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'save_announcement') { +// Handle Actions (Save, Delete, Toggle) +if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (!verify_csrf_token($_POST['csrf_token'] ?? '')) { $errorMsg = 'Session expired or invalid security token. Please try again.'; } else { - $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); + $action = $_POST['action'] ?? ''; - $successMsg = 'Announcement updated successfully!'; + 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); + + $successMsg = $annId ? 'Announcement updated successfully!' : 'New announcement created successfully!'; + } elseif ($action === 'delete_announcement') { + $annId = (int)($_POST['announcement_id'] ?? 0); + if ($annId > 0) { + delete_announcement($annId); + $successMsg = 'Announcement deleted successfully.'; + } + } elseif ($action === 'toggle_active') { + $annId = (int)($_POST['announcement_id'] ?? 0); + if ($annId > 0) { + toggle_announcement_active($annId); + $successMsg = 'Status updated.'; + } + } } } -// Fetch current announcement (or default empty template) -$announcement = get_active_announcement(); -if (!$announcement) { - $stmt = $pdo->query("SELECT * FROM announcements ORDER BY id DESC LIMIT 1"); - $announcement = $stmt->fetch() ?: [ - 'id' => 0, - 'is_active' => 0, - 'type' => 'holiday', - 'headline' => 'Holiday Closure', - 'message' => 'The Old Fitz will be closed for the holiday weekend.', - 'start_date' => '', - 'end_date' => '', - 'show_banner' => 1, - 'show_in_hours' => 1 - ]; +// 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(); +$today = date('Y-m-d'); ?> @@ -88,87 +98,184 @@ if (!$announcement) {
No announcements created yet.
+ + Create Your First Announcement| Status | +Headline | +Type | +Schedule | +Placements | +Actions | +
|---|---|---|---|---|---|
| + + β Live + + β³ Scheduled + + β Off + + | ++ = htmlspecialchars($ann['headline']) ?> + + | ++ = htmlspecialchars($ann['type']) ?> + | ++ + = htmlspecialchars($ann['start_date'] ?: 'Now') ?> β = htmlspecialchars($ann['end_date'] ?: 'Ongoing') ?> + + Always (while on) + + | ++ + | +
+
+ Edit
+
+
-
-
-
+
+
+ |
+