true]); Security::requireAdmin(); if ($_SERVER['REQUEST_METHOD'] !== 'POST') { header('Location: index.php'); exit; } Security::verifyCsrf($_POST['csrf_token'] ?? ''); require_once __DIR__ . '/../config/database.php'; $projectId = (int) ($_POST['project_id'] ?? 0); if ($projectId > 0) { try { $db = getDatabase(); // Récupérer l'image pour la supprimer du disque $stmt = $db->prepare('SELECT image FROM projects WHERE id = :id LIMIT 1'); $stmt->execute(['id' => $projectId]); $project = $stmt->fetch(); if ($project) { // Supprimer l'image si elle existe if (!empty($project['image'])) { $uploadDir = realpath(__DIR__ . '/../assets/img/projects'); if ($uploadDir !== false) { $imagePath = $uploadDir . DIRECTORY_SEPARATOR . basename((string) $project['image']); if (is_file($imagePath)) { unlink($imagePath); } } } // Supprimer le projet $stmt = $db->prepare('DELETE FROM projects WHERE id = :id'); $stmt->execute(['id' => $projectId]); } header('Location: index.php?success=deleted'); exit; } catch (PDOException $e) { error_log('Erreur suppression projet : ' . $e->getMessage()); header('Location: index.php'); exit; } } header('Location: index.php'); exit;