53 lines
1.4 KiB
PHP
53 lines
1.4 KiB
PHP
<?php
|
|
ob_start();
|
|
header('Content-Type: application/json');
|
|
|
|
$rootPath = dirname(dirname(__DIR__));
|
|
require_once($rootPath . '/src/config/functions.php');
|
|
require_once($rootPath . '/src/config/connection.php');
|
|
|
|
// Check admin status
|
|
session_start();
|
|
if (empty($_SESSION['user_id']) || !in_array($_SESSION['role'] ?? '', ['admin', 'superadmin'])) {
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'error', 'message' => 'Unauthorized access']);
|
|
exit;
|
|
}
|
|
|
|
try {
|
|
$trip_id = intval($_POST['trip_id'] ?? 0);
|
|
|
|
if ($trip_id <= 0) {
|
|
throw new Exception('Invalid trip ID');
|
|
}
|
|
|
|
// Delete trip images from filesystem
|
|
$upload_dir = $rootPath . '/assets/images/trips/';
|
|
if (is_dir($upload_dir)) {
|
|
$files = glob($upload_dir . $trip_id . '_*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
|
|
foreach ($files as $file) {
|
|
if (is_file($file)) {
|
|
unlink($file);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Delete trip from database
|
|
$stmt = $conn->prepare("DELETE FROM trips WHERE trip_id = ?");
|
|
$stmt->bind_param("i", $trip_id);
|
|
|
|
if (!$stmt->execute()) {
|
|
throw new Exception('Failed to delete trip: ' . $stmt->error);
|
|
}
|
|
|
|
$stmt->close();
|
|
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'success', 'message' => 'Trip deleted successfully']);
|
|
|
|
} catch (Exception $e) {
|
|
ob_end_clean();
|
|
echo json_encode(['status' => 'error', 'message' => $e->getMessage()]);
|
|
}
|
|
?>
|