- Add map-based location picker with centered pin for campsites (two-step process) - Hide edit buttons for campsites not owned by current user - Allow numbers in campsite names (fix validateName function) - Prepopulate edit form with existing campsite data - Preserve country/province selection when confirming location - Add real-time filter functionality to campsites table - Fix events publish button error handling (use output buffering cleanup) - Improve AJAX response handling with complete callback Changes: - src/pages/bookings/campsites.php: Location mode UI, filter, edit form improvements - src/config/functions.php: Allow numbers in validateName regex - src/admin/toggle_event_published.php: Clean output buffers before JSON response - src/admin/admin_events.php: Use complete callback instead of success/error handlers
76 lines
2.2 KiB
PHP
76 lines
2.2 KiB
PHP
<?php
|
|
// Set JSON header FIRST before any includes that might output
|
|
header('Content-Type: application/json');
|
|
header('Cache-Control: no-cache, no-store, must-revalidate');
|
|
header('Pragma: no-cache');
|
|
header('Expires: 0');
|
|
|
|
// Clean any output buffers before including header
|
|
while (ob_get_level() > 0) {
|
|
ob_end_clean();
|
|
}
|
|
|
|
$rootPath = dirname(dirname(__DIR__));
|
|
include_once($rootPath . '/header.php');
|
|
checkAdmin();
|
|
|
|
// Clean output buffer again in case header.php added content
|
|
ob_clean();
|
|
|
|
$event_id = $_POST['event_id'] ?? null;
|
|
|
|
if (!$event_id) {
|
|
http_response_code(400);
|
|
echo json_encode(['status' => 'error', 'message' => 'Event ID is required']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
// Get current published status
|
|
$stmt = $conn->prepare("SELECT published FROM events WHERE event_id = ?");
|
|
if (!$stmt) {
|
|
throw new Exception("Prepare failed: " . $conn->error);
|
|
}
|
|
|
|
$stmt->bind_param("i", $event_id);
|
|
$stmt->execute();
|
|
$result = $stmt->get_result();
|
|
|
|
if ($result->num_rows === 0) {
|
|
http_response_code(404);
|
|
echo json_encode(['status' => 'error', 'message' => 'Event not found']);
|
|
$stmt->close();
|
|
exit;
|
|
}
|
|
|
|
$event = $result->fetch_assoc();
|
|
$new_status = $event['published'] == 1 ? 0 : 1;
|
|
$stmt->close();
|
|
|
|
// Update published status
|
|
$update_stmt = $conn->prepare("UPDATE events SET published = ?, updated_at = NOW() WHERE event_id = ?");
|
|
if (!$update_stmt) {
|
|
throw new Exception("Prepare failed: " . $conn->error);
|
|
}
|
|
|
|
$update_stmt->bind_param("ii", $new_status, $event_id);
|
|
|
|
if ($update_stmt->execute()) {
|
|
ob_clean(); // Clean any buffered output before sending JSON
|
|
http_response_code(200);
|
|
echo json_encode([
|
|
'status' => 'success',
|
|
'message' => $new_status == 1 ? 'Event published' : 'Event unpublished',
|
|
'published' => $new_status
|
|
]);
|
|
} else {
|
|
throw new Exception("Update failed: " . $update_stmt->error);
|
|
}
|
|
$update_stmt->close();
|
|
} catch (Exception $e) {
|
|
ob_clean(); // Clean any buffered output before sending JSON
|
|
http_response_code(500);
|
|
echo json_encode(['status' => 'error', 'message' => 'Database error: ' . $e->getMessage()]);
|
|
}
|
|
|