From f522b84fc1d89b1aafe13f6a67a8639f9fa13abd Mon Sep 17 00:00:00 2001 From: twotalesanimation <80506065+twotalesanimation@users.noreply.github.com> Date: Thu, 4 Dec 2025 21:40:11 +0200 Subject: [PATCH] refactor: align events admin pages with trips layout and add publish functionality - Remove checkbox from manage_events.php form (publish via admin table instead) - Redesign admin_events.php to match admin_trips.php layout exactly - Add table-based actions with icon buttons (Edit, Publish/Unpublish, Delete) - Change button styling to match trips (btn classes with colors) - Add publish/unpublish toggle button with eye icon - Create toggle_event_published.php endpoint for publish status switching - Create delete_event.php endpoint for event deletion - Add AJAX functionality for instant publish/delete without page reload - Update .htaccess with new endpoint rewrite rules - Badge styling updated to match trips (bg-success, bg-warning) - Consistent sorting and filtering functionality --- .htaccess | 2 + src/admin/admin_events.php | 308 +++++++++++++++++---------- src/admin/delete_event.php | 46 ++++ src/admin/manage_events.php | 10 - src/admin/process_event.php | 8 +- src/admin/toggle_event_published.php | 44 ++++ 6 files changed, 290 insertions(+), 128 deletions(-) create mode 100644 src/admin/delete_event.php create mode 100644 src/admin/toggle_event_published.php diff --git a/.htaccess b/.htaccess index 70cbdf64..908abdf0 100644 --- a/.htaccess +++ b/.htaccess @@ -118,7 +118,9 @@ RewriteRule ^logout$ src/processors/logout.php [L] RewriteRule ^process_trip$ src/processors/process_trip.php [L] RewriteRule ^process_event$ src/admin/process_event.php [L] RewriteRule ^toggle_trip_published$ src/processors/toggle_trip_published.php [L] +RewriteRule ^toggle_event_published$ src/admin/toggle_event_published.php [L] RewriteRule ^delete_trip$ src/processors/delete_trip.php [L] +RewriteRule ^delete_event$ src/admin/delete_event.php [L] diff --git a/src/admin/admin_events.php b/src/admin/admin_events.php index 0ac2c5d6..396fd145 100644 --- a/src/admin/admin_events.php +++ b/src/admin/admin_events.php @@ -3,6 +3,22 @@ $headerStyle = 'light'; $rootPath = dirname(dirname(__DIR__)); include_once($rootPath . '/header.php'); checkAdmin(); + +// Fetch all events +$events_query = " + SELECT + event_id, name, type, location, date, published + FROM events + ORDER BY date DESC +"; + +$result = $conn->query($events_query); +$events = []; +if ($result && $result->num_rows > 0) { + while ($row = $result->fetch_assoc()) { + $events[] = $row; + } +} ?> + -
+ 'index'], [$pageTitle => '']]; + require_once($rootPath . '/components/banner.php'); +?> + + +
-
+ prepare("SELECT event_id, name, type, location, date, published FROM events ORDER BY date DESC"); - $stmt->execute(); - $result = $stmt->get_result(); - - if ($result->num_rows > 0) { - echo ''; - echo ' - - - - - - - - - - - '; - - while ($event = $result->fetch_assoc()) { - $event_id = $event['event_id']; - $name = htmlspecialchars($event['name']); - $type = htmlspecialchars($event['type']); - $location = htmlspecialchars($event['location']); - $date = convertDate($event['date']); - $status = $event['published'] ? 'Published' : 'Draft'; - - echo " - - - - - - - "; +
Event NameTypeLocationDateStatusActions
{$name}{$type}{$location}{$date}{$status} -
- Edit - + if (!empty($events)) { + echo '
+
+
+
-
+ + + + + + + + + + + '; + foreach ($events as $event) { + $publishButtonText = $event['published'] == 1 ? 'Unpublish' : 'Publish'; + $publishButtonClass = $event['published'] == 1 ? 'btn-warning' : 'btn-success'; + echo ' + + + + + + + '; } - echo '
Event NameTypeLocationDateStatusActions
' . htmlspecialchars($event['name']) . '' . htmlspecialchars($event['type']) . '' . htmlspecialchars($event['location']) . '' . convertDate($event['date']) . '' . ($event['published'] == 1 ? 'Published' : 'Draft') . ' + + + + + +
'; + echo '
'; + echo '
'; } else { - echo '
No events found. Create the first event
'; + echo '

No events found. Create one

'; } ?>
+ diff --git a/src/admin/delete_event.php b/src/admin/delete_event.php new file mode 100644 index 00000000..152ae71f --- /dev/null +++ b/src/admin/delete_event.php @@ -0,0 +1,46 @@ + 'error', 'message' => 'Event ID is required']); + exit; +} + +// Get event details to delete associated files +$stmt = $conn->prepare("SELECT image, promo FROM events WHERE event_id = ?"); +$stmt->bind_param("i", $event_id); +$stmt->execute(); +$result = $stmt->get_result(); + +if ($result->num_rows > 0) { + $event = $result->fetch_assoc(); + + // Delete image files + if ($event['image'] && file_exists($rootPath . '/' . $event['image'])) { + unlink($rootPath . '/' . $event['image']); + } + if ($event['promo'] && file_exists($rootPath . '/' . $event['promo'])) { + unlink($rootPath . '/' . $event['promo']); + } + + // Delete from database + $delete_stmt = $conn->prepare("DELETE FROM events WHERE event_id = ?"); + $delete_stmt->bind_param("i", $event_id); + + if ($delete_stmt->execute()) { + echo json_encode(['status' => 'success', 'message' => 'Event deleted successfully']); + } else { + echo json_encode(['status' => 'error', 'message' => 'Failed to delete event']); + } + $delete_stmt->close(); +} else { + echo json_encode(['status' => 'error', 'message' => 'Event not found']); +} + +$stmt->close(); diff --git a/src/admin/manage_events.php b/src/admin/manage_events.php index 21157eeb..0d746b76 100644 --- a/src/admin/manage_events.php +++ b/src/admin/manage_events.php @@ -118,16 +118,6 @@ if ($event_id) { - -
-
- -
-
-