diff options
author | polo <ordipolo@gmx.fr> | 2025-08-02 17:03:42 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-08-02 17:03:42 +0200 |
commit | 9934a32f7e02c484d6b122c9af860ab1ca9b2dca (patch) | |
tree | f4f8d621a42104246375c0489e19e4673d726279 /src/controller/post_router.php | |
parent | 20e1d288035a274b48f0d2d26f547ad15e99761d (diff) | |
download | cms-9934a32f7e02c484d6b122c9af860ab1ca9b2dca.zip |
réorganisation 2 requêtes "form": séparation routage et contrôleurs avec des fonctions
Diffstat (limited to 'src/controller/post_router.php')
-rw-r--r-- | src/controller/post_router.php | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/controller/post_router.php b/src/controller/post_router.php new file mode 100644 index 0000000..e71852a --- /dev/null +++ b/src/controller/post_router.php | |||
@@ -0,0 +1,120 @@ | |||
1 | <?php | ||
2 | // src/controller/post_router.php | ||
3 | // | ||
4 | // routage des requêtes des formulaires et AJAX | ||
5 | // n'utilisent que des POST à l'exception d'un GET par fullcalendar | ||
6 | // les contrôleurs des formulaires sont appelés ici, | ||
7 | // ceux des requêtes AJAX sont derrière d'autres routeurs | ||
8 | |||
9 | declare(strict_types=1); | ||
10 | |||
11 | |||
12 | /* appel des contrôleurs dans password.php */ | ||
13 | if(isset($_GET['action']) && $_GET['action'] === 'deconnexion') | ||
14 | { | ||
15 | disconnect($entityManager); | ||
16 | } | ||
17 | elseif(isset($_GET['action']) && $_GET['action'] === 'modif_mdp') | ||
18 | { | ||
19 | changePassword($entityManager); | ||
20 | } | ||
21 | |||
22 | |||
23 | if($_SERVER['REQUEST_METHOD'] === 'POST'){ | ||
24 | /* -- contrôleurs appellables par tout le monde -- */ | ||
25 | // POST "ajax" | ||
26 | require '../src/controller/ajax_email.php'; | ||
27 | |||
28 | // POST "form" | ||
29 | // ... | ||
30 | |||
31 | |||
32 | if($_SESSION['admin'] === true) | ||
33 | { | ||
34 | /* -- requêtes "form" -- */ | ||
35 | if($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') // moyen approximatif de distinguer les requêtes de formulaires et AJAX | ||
36 | { | ||
37 | require '../src/controller/post_functions_admin.php'; | ||
38 | |||
39 | /* -- nouvelle page -- */ | ||
40 | if(isset($_POST['page_name']) && $_POST['page_name'] !== null | ||
41 | && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null | ||
42 | && isset($_POST['page_location']) && $_POST['page_location'] !== null | ||
43 | && isset($_POST['page_description']) && $_POST['page_description'] !== null | ||
44 | && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') | ||
45 | { | ||
46 | newPage($entityManager); | ||
47 | } | ||
48 | |||
49 | /* -- suppression d'une page -- */ | ||
50 | elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null | ||
51 | && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') | ||
52 | { | ||
53 | deletePage($entityManager); | ||
54 | } | ||
55 | |||
56 | |||
57 | /* -- mode Modification d'une page -- */ | ||
58 | |||
59 | // modification du chemins en snake_case | ||
60 | elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null | ||
61 | && isset($_POST['page_id']) && $_POST['page_id'] !== null | ||
62 | && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') | ||
63 | { | ||
64 | pageMenuPathUpdate($entityManager); | ||
65 | } | ||
66 | // ajout d'un bloc dans une page | ||
67 | elseif(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null | ||
68 | && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null | ||
69 | && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden | ||
70 | { | ||
71 | addBloc($entityManager); | ||
72 | } | ||
73 | // suppression d'un bloc de page | ||
74 | elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null | ||
75 | && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden | ||
76 | { | ||
77 | deleteBloc($entityManager); | ||
78 | } | ||
79 | |||
80 | |||
81 | /* -- page Menu et chemins -- */ | ||
82 | |||
83 | // création d'une entrée de menu avec une URL | ||
84 | elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | ||
85 | newUrlMenuEntry($entityManager); | ||
86 | } | ||
87 | // suppression d'une entrée de menu avec une URL | ||
88 | elseif(isset($_POST['delete']) && isset($_POST['x']) && isset($_POST['y'])){ // 2 params x et y sont là parce qu'on a cliqué sur une image | ||
89 | deleteUrlMenuEntry($entityManager); | ||
90 | } | ||
91 | |||
92 | // modification du mot de passe | ||
93 | elseif(isset($_GET['action']) && $_GET['action'] === 'modif_mdp' | ||
94 | && isset($_POST['login']) && isset($_POST['old_password']) && isset($_POST['new_password']) | ||
95 | && isset($_POST['modify_password_hidden']) && empty($_POST['modify_password_hidden'])) | ||
96 | { | ||
97 | changePassword($entityManager); | ||
98 | } | ||
99 | else{ | ||
100 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | ||
101 | die; | ||
102 | } | ||
103 | } | ||
104 | |||
105 | /* -- requêtes AJAX -- */ | ||
106 | else{ | ||
107 | require '../src/controller/ajax_admin.php'; | ||
108 | require '../src/controller/ajax_calendar_admin.php'; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | // cas particulier d'un GET ajax non-admin par fullcalendar | ||
113 | elseif($_SERVER['REQUEST_METHOD'] === 'GET'){ | ||
114 | // non-admin | ||
115 | require '../src/controller/ajax_calendar_visitor.php'; | ||
116 | |||
117 | if($_SESSION['admin'] === true){ | ||
118 | // ... | ||
119 | } | ||
120 | } \ No newline at end of file | ||