diff options
Diffstat (limited to 'src/controller/request_router.php')
| -rw-r--r-- | src/controller/request_router.php | 256 |
1 files changed, 256 insertions, 0 deletions
diff --git a/src/controller/request_router.php b/src/controller/request_router.php new file mode 100644 index 0000000..157bc80 --- /dev/null +++ b/src/controller/request_router.php | |||
| @@ -0,0 +1,256 @@ | |||
| 1 | <?php | ||
| 2 | // src/controller/request_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 | // presque tout est ici | ||
| 24 | if($_SERVER['REQUEST_METHOD'] === 'POST'){ | ||
| 25 | /* -- contrôleurs appellables par tout le monde -- */ | ||
| 26 | |||
| 27 | // POST "ajax" avec fetch (application/json) | ||
| 28 | if($_SERVER['CONTENT_TYPE'] === 'application/json') | ||
| 29 | { | ||
| 30 | $data = file_get_contents('php://input'); | ||
| 31 | $json = json_decode($data, true); | ||
| 32 | |||
| 33 | if(isset($_GET['action'])) | ||
| 34 | { | ||
| 35 | // formulaire de contact | ||
| 36 | if($_GET['action'] === 'send_email'){ | ||
| 37 | EmailController::submit($json, $entityManager); | ||
| 38 | } | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | // POST "form" | ||
| 43 | // ... | ||
| 44 | |||
| 45 | |||
| 46 | if($_SESSION['admin'] === true) | ||
| 47 | { | ||
| 48 | /* -- requêtes AJAX -- */ | ||
| 49 | // requêtes JSON avec fetch() | ||
| 50 | if($_SERVER['CONTENT_TYPE'] === 'application/json') | ||
| 51 | { | ||
| 52 | $data = file_get_contents('php://input'); | ||
| 53 | $json = json_decode($data, true); | ||
| 54 | |||
| 55 | if(isset($_GET['action'])) | ||
| 56 | { | ||
| 57 | /* -- manipulation des articles -- */ | ||
| 58 | if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content'])) | ||
| 59 | { | ||
| 60 | ArticleController::editorSubmit($entityManager, $json); | ||
| 61 | } | ||
| 62 | elseif($_GET['action'] === 'delete_article' && isset($json['id'])) | ||
| 63 | { | ||
| 64 | ArticleController::deleteArticle($entityManager, $json); | ||
| 65 | } | ||
| 66 | // inversion de la position de deux noeuds | ||
| 67 | elseif($_GET['action'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) | ||
| 68 | { | ||
| 69 | ArticleController::switchPositions($entityManager, $json); | ||
| 70 | } | ||
| 71 | elseif($_GET['action'] === 'date_submit' && isset($json['id']) && isset($json['date'])) | ||
| 72 | { | ||
| 73 | ArticleController::dateSubmit($entityManager, $json); | ||
| 74 | } | ||
| 75 | |||
| 76 | /* -- bloc Formulaire -- */ | ||
| 77 | elseif($_GET['action'] === 'recipient_email'){ | ||
| 78 | ContactFormController::updateRecipient($entityManager, $json); | ||
| 79 | } | ||
| 80 | elseif($_GET['action'] === 'test_email'){ | ||
| 81 | ContactFormController::sendTestEmail($entityManager, $json); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | /* -- page Menu et chemins -- */ | ||
| 86 | elseif(isset($_GET['menu_edit'])) | ||
| 87 | { | ||
| 88 | // récupération des données (serait peut-être mieux dans la classe) | ||
| 89 | Director::$menu_data = new Menu($entityManager); | ||
| 90 | |||
| 91 | // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions | ||
| 92 | if($_GET['menu_edit'] === 'move_one_level_up' && isset($json['id'])){ | ||
| 93 | MenuAndPathsController::MoveOneLevelUp($entityManager, $json); | ||
| 94 | } | ||
| 95 | |||
| 96 | // flèche droite =>: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent | ||
| 97 | if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){ | ||
| 98 | MenuAndPathsController::MoveOneLevelDown($entityManager, $json); | ||
| 99 | } | ||
| 100 | |||
| 101 | if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])){ | ||
| 102 | MenuAndPathsController::switchPositions($entityManager, $json); | ||
| 103 | } | ||
| 104 | |||
| 105 | if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])){ | ||
| 106 | MenuAndPathsController::displayInMenu($entityManager, $json); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | |||
| 110 | /* -- mode Modification d'une page -- */ | ||
| 111 | // partie "page" | ||
| 112 | elseif(isset($_GET['page_edit'])) | ||
| 113 | { | ||
| 114 | // titre de la page | ||
| 115 | if($_GET['page_edit'] === 'page_title'){ | ||
| 116 | PageManagementController::setPageTitle($entityManager, $json); | ||
| 117 | } | ||
| 118 | // description dans les métadonnées | ||
| 119 | elseif($_GET['page_edit'] === 'page_description'){ | ||
| 120 | PageManagementController::setPageDescription($entityManager, $json); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | // partie "blocs" | ||
| 125 | elseif(isset($_GET['bloc_edit'])) | ||
| 126 | { | ||
| 127 | // renommage d'un bloc | ||
| 128 | if($_GET['bloc_edit'] === 'rename_page_bloc') | ||
| 129 | { | ||
| 130 | PageManagementController::renameBloc($entityManager, $json); | ||
| 131 | } | ||
| 132 | // inversion des positions de deux blocs | ||
| 133 | elseif($_GET['bloc_edit'] === 'switch_blocs_positions') | ||
| 134 | { | ||
| 135 | PageManagementController::SwitchBlocsPositions($entityManager, $json); | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | /* -- upload d'image dans tinymce par copier-coller -- */ | ||
| 140 | // collage de HTML contenant une ou plusieurs balises <img> | ||
| 141 | if(isset($_GET['action']) && $_GET['action'] == 'upload_image_html'){ | ||
| 142 | ImageUploadController::uploadImageHtml(); | ||
| 143 | } | ||
| 144 | // collage d'une image (code base64 dans le presse-papier) non encapsulée dans du HTML | ||
| 145 | elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image_base64'){ | ||
| 146 | ImageUploadController::uploadImageBase64(); | ||
| 147 | } | ||
| 148 | |||
| 149 | /* -- requêtes spécifiques au calendrier -- */ | ||
| 150 | if($_GET['action'] === 'new_event'){ | ||
| 151 | CalendarController::newEvent($json, $entityManager); | ||
| 152 | } | ||
| 153 | elseif($_GET['action'] === 'update_event'){ | ||
| 154 | CalendarController::updateEvent($json, $entityManager); | ||
| 155 | } | ||
| 156 | elseif($_GET['action'] === 'remove_event'){ | ||
| 157 | CalendarController::removeEvent($json, $entityManager); | ||
| 158 | } | ||
| 159 | else{ | ||
| 160 | echo json_encode(['success' => false]); | ||
| 161 | } | ||
| 162 | die; | ||
| 163 | } | ||
| 164 | |||
| 165 | // upload d'image dans tinymce avec le plugin (bouton "insérer une image" de l'éditeur) | ||
| 166 | elseif(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image') | ||
| 167 | { | ||
| 168 | ImageUploadController::imageUploadTinyMce(); | ||
| 169 | } | ||
| 170 | // requêtes XMLHttpRequest | ||
| 171 | elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') | ||
| 172 | { | ||
| 173 | //echo "requête XMLHttpRequest reçue par le serveur"; | ||
| 174 | echo json_encode(['success' => false]); // ça marche mais ça marche pas... | ||
| 175 | die; | ||
| 176 | } | ||
| 177 | |||
| 178 | /* -- envoi d'un formulaire HTML -- */ | ||
| 179 | elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') | ||
| 180 | { | ||
| 181 | /* -- nouvelle page -- */ | ||
| 182 | if(isset($_POST['page_name']) && $_POST['page_name'] !== null | ||
| 183 | && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null | ||
| 184 | && isset($_POST['page_location']) && $_POST['page_location'] !== null | ||
| 185 | && isset($_POST['page_description']) && $_POST['page_description'] !== null | ||
| 186 | && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') | ||
| 187 | { | ||
| 188 | PageManagementController::newPage($entityManager); | ||
| 189 | } | ||
| 190 | |||
| 191 | /* -- suppression d'une page -- */ | ||
| 192 | elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null | ||
| 193 | && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') | ||
| 194 | { | ||
| 195 | PageManagementController::deletePage($entityManager); | ||
| 196 | } | ||
| 197 | |||
| 198 | /* -- mode Modification d'une page -- */ | ||
| 199 | |||
| 200 | // modification du chemins en snake_case | ||
| 201 | elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null | ||
| 202 | && isset($_POST['page_id']) && $_POST['page_id'] !== null | ||
| 203 | && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') | ||
| 204 | { | ||
| 205 | PageManagementController::updatePageMenuPath($entityManager); | ||
| 206 | } | ||
| 207 | // ajout d'un bloc dans une page | ||
| 208 | elseif(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null | ||
| 209 | && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null | ||
| 210 | && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden | ||
| 211 | { | ||
| 212 | PageManagementController::addBloc($entityManager); | ||
| 213 | } | ||
| 214 | // suppression d'un bloc de page | ||
| 215 | elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null | ||
| 216 | && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden | ||
| 217 | { | ||
| 218 | PageManagementController::deleteBloc($entityManager); | ||
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | /* -- page Menu et chemins -- */ | ||
| 223 | |||
| 224 | // création d'une entrée de menu avec une URL | ||
| 225 | elseif(isset($_POST["label_input"]) && isset($_POST["url_input"]) && isset($_POST["location"])){ | ||
| 226 | MenuAndPathsController::newUrlMenuEntry($entityManager); | ||
| 227 | } | ||
| 228 | // suppression d'une entrée de menu avec une URL | ||
| 229 | 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 | ||
| 230 | MenuAndPathsController::deleteUrlMenuEntry($entityManager); | ||
| 231 | } | ||
| 232 | |||
| 233 | // redirection page d'accueil | ||
| 234 | else{ | ||
| 235 | header("Location: " . new URL(['error' => 'paramètres inconnus'])); | ||
| 236 | die; | ||
| 237 | } | ||
| 238 | } | ||
| 239 | } | ||
| 240 | } | ||
| 241 | |||
| 242 | // cas particulier d'un GET ajax non-admin par fullcalendar | ||
| 243 | elseif($_SERVER['REQUEST_METHOD'] === 'GET'){ | ||
| 244 | /* -- non-admin -- */ | ||
| 245 | // chargement des évènements à la création du calendrier | ||
| 246 | // et au changement de dates affichées (boutons flèches mais pas changement de vue) | ||
| 247 | if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' | ||
| 248 | && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) | ||
| 249 | { | ||
| 250 | CalendarController::getData($entityManager); | ||
| 251 | } | ||
| 252 | |||
| 253 | if($_SESSION['admin'] === true){ | ||
| 254 | // ... | ||
| 255 | } | ||
| 256 | } \ No newline at end of file | ||
