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
This commit is contained in:
44
src/admin/toggle_event_published.php
Normal file
44
src/admin/toggle_event_published.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
$rootPath = dirname(dirname(__DIR__));
|
||||
include_once($rootPath . '/header.php');
|
||||
checkAdmin();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$event_id = $_POST['event_id'] ?? null;
|
||||
|
||||
if (!$event_id) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Event ID is required']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Get current published status
|
||||
$stmt = $conn->prepare("SELECT published FROM events WHERE event_id = ?");
|
||||
$stmt->bind_param("i", $event_id);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows === 0) {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Event not found']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$event = $result->fetch_assoc();
|
||||
$new_status = $event['published'] == 1 ? 0 : 1;
|
||||
|
||||
// Update published status
|
||||
$update_stmt = $conn->prepare("UPDATE events SET published = ? WHERE event_id = ?");
|
||||
$update_stmt->bind_param("ii", $new_status, $event_id);
|
||||
|
||||
if ($update_stmt->execute()) {
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $new_status == 1 ? 'Event published' : 'Event unpublished',
|
||||
'published' => $new_status
|
||||
]);
|
||||
} else {
|
||||
echo json_encode(['status' => 'error', 'message' => 'Failed to update event status']);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$update_stmt->close();
|
||||
Reference in New Issue
Block a user