summaryrefslogtreecommitdiff
path: root/src/controller/post.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller/post.php')
-rw-r--r--src/controller/post.php47
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
4declare(strict_types=1); 4declare(strict_types=1);
5 5
6use App\Entity\Node;
7use App\Entity\NodeData;
6use App\Entity\Page; 8use App\Entity\Page;
7 9
8if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) 10if($_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';