34 lines
No EOL
1 KiB
PHP
34 lines
No EOL
1 KiB
PHP
<?php
|
|
require_once './includes/nav.php';
|
|
$id = isset($_GET['id']) ? sanitizeInput($_GET['id']) : null;
|
|
if (!$id) {
|
|
echo "<div class='alert alert-error'>ID de projet manquant.</div>";
|
|
exit;
|
|
}
|
|
|
|
$jsonFile = '../data/projects.json';
|
|
|
|
if(file_exists($jsonFile)) {
|
|
$content = file_get_contents($jsonFile);
|
|
$projects = $content ? json_decode($content, true) : [];
|
|
} else {
|
|
$projects = [];
|
|
}
|
|
|
|
// Check if project exists
|
|
$projectKey = array_search($id, array_column($projects, 'id'));
|
|
if ($projectKey === false) {
|
|
echo "<div class='alert alert-error'>Projet non trouvé.</div>";
|
|
exit;
|
|
}
|
|
// On supprime le projet
|
|
unset($projects[$projectKey]);
|
|
// Reindex the array
|
|
$projects = array_values($projects);
|
|
// Save updated projects back to the JSON file
|
|
if (file_put_contents($jsonFile, json_encode($projects, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE))) {
|
|
echo "<div class='alert alert-success'>Projet supprimé avec succès !</div>";
|
|
} else {
|
|
echo "<div class='alert alert-error'>Erreur lors de la suppression du projet.</div>";
|
|
}
|
|
?>
|