diff options
| author | polo-pc-greta <ordipolo@gmx.fr> | 2025-05-08 12:32:34 +0200 |
|---|---|---|
| committer | polo-pc-greta <ordipolo@gmx.fr> | 2025-05-08 12:32:34 +0200 |
| commit | 28698982ff6dc67a331788c2637bce8689121769 (patch) | |
| tree | 6df30593fdcdd2ead77dd894467e5031a31cfde9 /src/controller/post.php | |
| parent | 2d8ec75f4aaf3b93fd9f6758f8dcb4f1f9f03d0c (diff) | |
| download | cms-28698982ff6dc67a331788c2637bce8689121769.tar.gz cms-28698982ff6dc67a331788c2637bce8689121769.tar.bz2 cms-28698982ff6dc67a331788c2637bce8689121769.zip | |
modif page, création d'un bloc
Diffstat (limited to 'src/controller/post.php')
| -rw-r--r-- | src/controller/post.php | 47 |
1 files changed, 40 insertions, 7 deletions
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 @@ | |||
| 3 | 3 | ||
| 4 | declare(strict_types=1); | 4 | declare(strict_types=1); |
| 5 | 5 | ||
| 6 | use App\Entity\Node; | ||
| 7 | use App\Entity\NodeData; | ||
| 6 | use App\Entity\Page; | 8 | use App\Entity\Page; |
| 7 | 9 | ||
| 8 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | 10 | if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) |
| @@ -10,17 +12,48 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 10 | /* -- formulaires HTML classiques -- */ | 12 | /* -- formulaires HTML classiques -- */ |
| 11 | if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') | 13 | if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') |
| 12 | { | 14 | { |
| 13 | // création d'une entrée de menu avec une URL | 15 | /* -- mode Modification d'une page -- */ |
| 14 | if(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | 16 | |
| 15 | echo $_POST["label_input"] . '<br>'; | 17 | // ajout d'un bloc dans une page |
| 16 | echo $_POST["url_input"] . '<br>'; | 18 | if(isset($_POST['bloc_title']) && isset($_POST['bloc_select'])){ |
| 17 | echo $_POST["location"] . '<br>'; // id entrée précédente | 19 | $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data |
| 20 | $page = Director::$page_path->getLast(); | ||
| 21 | $director->findNodeByName('main'); | ||
| 22 | $main = $director->getNode(); | ||
| 23 | $position = count($main->getChildren()) + 1; // position dans la fraterie | ||
| 24 | |||
| 25 | $bloc = new Node( | ||
| 26 | trim(htmlspecialchars($_POST["bloc_select"])), | ||
| 27 | null, [], | ||
| 28 | $position, | ||
| 29 | $main, | ||
| 30 | $page); | ||
| 31 | $data = new NodeData( | ||
| 32 | ['title' => trim(htmlspecialchars($_POST["bloc_title"]))], | ||
| 33 | $bloc); | ||
| 34 | |||
| 35 | $entityManager->persist($bloc); | ||
| 36 | $entityManager->persist($data); | ||
| 37 | $entityManager->flush(); | ||
| 38 | header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); | ||
| 39 | } | ||
| 18 | 40 | ||
| 41 | |||
| 42 | /* -- page Menu et chemins -- */ | ||
| 43 | |||
| 44 | // création d'une entrée de menu avec une URL | ||
| 45 | elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | ||
| 19 | Director::$menu_data = new Menu($entityManager); | 46 | Director::$menu_data = new Menu($entityManager); |
| 20 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); | 47 | $previous_page = Director::$menu_data->findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); |
| 21 | $parent = $previous_page->getParent(); | 48 | $parent = $previous_page->getParent(); |
| 22 | 49 | ||
| 23 | $page = new Page($_POST["label_input"], $_POST["url_input"], true, true, false, $previous_page->getPosition(), $parent); | 50 | $page = new Page( |
| 51 | trim(htmlspecialchars($_POST["label_input"])), | ||
| 52 | filter_var($_POST["url_input"], FILTER_VALIDATE_URL), | ||
| 53 | true, true, false, | ||
| 54 | $previous_page->getPosition(), | ||
| 55 | $parent); | ||
| 56 | |||
| 24 | // 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 | 57 | // 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 |
| 25 | // 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 | 58 | // 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 |
| 26 | if($parent == null){ | 59 | if($parent == null){ |
| @@ -31,7 +64,6 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 31 | 64 | ||
| 32 | $entityManager->persist($page); | 65 | $entityManager->persist($page); |
| 33 | $entityManager->flush(); | 66 | $entityManager->flush(); |
| 34 | |||
| 35 | header("Location: " . new URL(['page' => $_GET['from']])); | 67 | header("Location: " . new URL(['page' => $_GET['from']])); |
| 36 | } | 68 | } |
| 37 | // suppression d'une entrée de menu avec une URL | 69 | // suppression d'une entrée de menu avec une URL |
| @@ -54,6 +86,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 54 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | 86 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); |
| 55 | } | 87 | } |
| 56 | } | 88 | } |
| 89 | |||
| 57 | /* -- requêtes AJAX -- */ | 90 | /* -- requêtes AJAX -- */ |
| 58 | else{ | 91 | else{ |
| 59 | require '../src/controller/ajax.php'; | 92 | require '../src/controller/ajax.php'; |
