From 28698982ff6dc67a331788c2637bce8689121769 Mon Sep 17 00:00:00 2001 From: polo-pc-greta Date: Thu, 8 May 2025 12:32:34 +0200 Subject: =?UTF-8?q?modif=20page,=20cr=C3=A9ation=20d'un=20bloc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controller/post.php | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'src/controller/post.php') diff --git a/src/controller/post.php b/src/controller/post.php index d2e4477..76ac72b 100644 --- a/src/controller/post.php +++ b/src/controller/post.php @@ -3,6 +3,8 @@ declare(strict_types=1); +use App\Entity\Node; +use App\Entity\NodeData; use App\Entity\Page; if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) @@ -10,17 +12,48 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) /* -- formulaires HTML classiques -- */ if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') { - // création d'une entrée de menu avec une URL - if(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ - echo $_POST["label_input"] . '
'; - echo $_POST["url_input"] . '
'; - echo $_POST["location"] . '
'; // id entrée précédente + /* -- mode Modification d'une page -- */ + + // ajout d'un bloc dans une page + if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ + $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data + $page = Director::$page_path->getLast(); + $director->findNodeByName('main'); + $main = $director->getNode(); + $position = count($main->getChildren()) + 1; // position dans la fraterie + + $bloc = new Node( + trim(htmlspecialchars($_POST["bloc_select"])), + null, [], + $position, + $main, + $page); + $data = new NodeData( + ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], + $bloc); + + $entityManager->persist($bloc); + $entityManager->persist($data); + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + } + + /* -- page Menu et chemins -- */ + + // création d'une entrée de menu avec une URL + elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ Director::$menu_data = new Menu($entityManager); $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); $parent = $previous_page->getParent(); - $page = new Page($_POST["label_input"], $_POST["url_input"], true, true, false, $previous_page->getPosition(), $parent); + $page = new Page( + trim(htmlspecialchars($_POST["label_input"])), + filter_var($_POST["url_input"], FILTER_VALIDATE_URL), + true, true, false, + $previous_page->getPosition(), + $parent); + // on indique pour la nouvelle entrée la même position que la précédente, puis addChild l'ajoute à la fin du tableau "children" avant de déclencher un tri // exemple avec 2 comme position demandée: 1 2 3 4 2 devient 1 2 3 4 5 et la nouvelle entrée sera en 3è position if($parent == null){ @@ -31,7 +64,6 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) $entityManager->persist($page); $entityManager->flush(); - header("Location: " . new URL(['page' => $_GET['from']])); } // suppression d'une entrée de menu avec une URL @@ -54,6 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) header("Location: " . new URL(['error' => 'paramètres inconnus'])); } } + /* -- requêtes AJAX -- */ else{ require '../src/controller/ajax.php'; -- cgit v1.2.3