diff --git a/arbre.php b/arbre.php index 92346bc..8937cbc 100644 --- a/arbre.php +++ b/arbre.php @@ -3,76 +3,77 @@ require_once 'fonctions.php'; session_start(); if (!isset($_SESSION['admin_id'])) { - header('Location: admin.php?action=login'); - exit; + header('Location: admin.php?action=login'); + exit; } if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $action = $_POST['action'] ?? ''; - $path = $_POST['path'] ?? ''; - $newName = $_POST['new_name'] ?? ''; - $description = $_POST['description'] ?? ''; - - switch ($action) { - case 'create_folder': - if ($path && $newName) { - $newPath = $path . '/' . sanitizeFilename($newName); - if (!file_exists($newPath)) { - mkdir($newPath, 0755, true); - $infoContent = $newName . "\n" . $description; - file_put_contents($newPath . '/infos.txt', $infoContent); - $_SESSION['success_message'] = "Dossier créé avec succès."; - } else { - $_SESSION['error_message'] = "Ce dossier existe déjà."; - } - } - break; - - case 'edit_folder': - if ($path && isSecurePath($path)) { - $infoContent = $newName . "\n" . $description; - $infoPath = $path . '/infos.txt'; - if (file_put_contents($infoPath, $infoContent) !== false) { - $_SESSION['success_message'] = "Dossier modifié avec succès."; - } else { - $_SESSION['error_message'] = "Erreur lors de la modification du dossier."; - } - } - break; - - case 'delete_folder': - if ($path && isSecurePath($path) && $path !== './liste_albums') { // Empêcher la suppression du dossier racine - function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - if (is_dir($dir . "/" . $object)) { - rrmdir($dir . "/" . $object); - } else { - unlink($dir . "/" . $object); - } - } - } - rmdir($dir); - } - } - rrmdir($path); - $_SESSION['success_message'] = "Dossier supprimé avec succès."; - } - break; - } - - header('Location: arbre.php'); - exit; + $action = $_POST['action'] ?? ''; + $path = $_POST['path'] ?? ''; + $newName = $_POST['new_name'] ?? ''; + $description = $_POST['description'] ?? ''; + $matureContent = isset($_POST['mature_content']) ? '18+' : '18-'; + + switch ($action) { + case 'create_folder': + if ($path && $newName) { + $newPath = $path . '/' . sanitizeFilename($newName); + if (!file_exists($newPath)) { + mkdir($newPath, 0755, true); + $infoContent = $newName . "\n" . $description . "\n" . $matureContent; + file_put_contents($newPath . '/infos.txt', $infoContent); + $_SESSION['success_message'] = "Dossier créé avec succès."; + } else { + $_SESSION['error_message'] = "Ce dossier existe déjà."; + } + } + break; + + case 'edit_folder': + if ($path && isSecurePath($path)) { + $infoContent = $newName . "\n" . $description . "\n" . $matureContent; + $infoPath = $path . '/infos.txt'; + if (file_put_contents($infoPath, $infoContent) !== false) { + $_SESSION['success_message'] = "Dossier modifié avec succès."; + } else { + $_SESSION['error_message'] = "Erreur lors de la modification du dossier."; + } + } + break; + + case 'delete_folder': + if ($path && isSecurePath($path) && $path !== './liste_albums') { + function rrmdir($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + if (is_dir($dir . "/" . $object)) { + rrmdir($dir . "/" . $object); + } else { + unlink($dir . "/" . $object); + } + } + } + rmdir($dir); + } + } + rrmdir($path); + $_SESSION['success_message'] = "Dossier supprimé avec succès."; + } + break; + } + + header('Location: arbre.php'); + exit; } $currentPath = isset($_GET['path']) ? $_GET['path'] : './liste_albums'; $currentPath = realpath($currentPath); if (!isSecurePath($currentPath)) { - header('Location: arbre.php'); - exit; + header('Location: arbre.php'); + exit; } function generateTree($path, $currentPath) { @@ -87,9 +88,12 @@ function generateTree($path, $currentPath) { $output .= '