From 547d7feed68e89957f062b8ed9b988f28c5830ce Mon Sep 17 00:00:00 2001 From: polo Date: Sun, 3 Aug 2025 00:23:11 +0200 Subject: =?UTF-8?q?r=C3=A9organisation=203:=20classes=20controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/index.php | 4 +- src/controller/ArticleController.php | 169 ++++++++ src/controller/CalendarController.php | 79 ++++ src/controller/ContactFormController.php | 44 ++ src/controller/EmailController.php | 91 ++++ src/controller/ImageUploadController.php | 184 ++++++++ src/controller/MenuAndPathsController.php | 189 +++++++++ src/controller/PageManagementController.php | 264 ++++++++++++ src/controller/ajax_admin.php | 636 ---------------------------- src/controller/ajax_calendar_admin.php | 54 --- src/controller/ajax_calendar_visitor.php | 39 -- src/controller/ajax_email.php | 105 ----- src/controller/password.php | 3 +- src/controller/post_functions_admin.php | 231 ---------- src/controller/post_router.php | 120 ------ src/controller/request_router.php | 256 +++++++++++ src/model/EventDTO.php | 2 +- 17 files changed, 1281 insertions(+), 1189 deletions(-) create mode 100644 src/controller/ArticleController.php create mode 100644 src/controller/CalendarController.php create mode 100644 src/controller/ContactFormController.php create mode 100644 src/controller/EmailController.php create mode 100644 src/controller/ImageUploadController.php create mode 100644 src/controller/MenuAndPathsController.php create mode 100644 src/controller/PageManagementController.php delete mode 100644 src/controller/ajax_admin.php delete mode 100644 src/controller/ajax_calendar_admin.php delete mode 100644 src/controller/ajax_calendar_visitor.php delete mode 100644 src/controller/ajax_email.php delete mode 100644 src/controller/post_functions_admin.php delete mode 100644 src/controller/post_router.php create mode 100644 src/controller/request_router.php diff --git a/public/index.php b/public/index.php index 09af532..ba0e354 100644 --- a/public/index.php +++ b/public/index.php @@ -53,8 +53,8 @@ if(!empty($_GET['id'])) $id = htmlspecialchars($_GET['id']); // nettoyage qui n'abime pas les id du genre "n16" } -/* -- contrôleurs qui traitent les POST (formulaires ou AJAX) -- */ -require '../src/controller/post_router.php'; +/* -- routeur des données de formulaires et requêtes AJAX -- */ +require '../src/controller/request_router.php'; /* -- affichage d'une page -- */ diff --git a/src/controller/ArticleController.php b/src/controller/ArticleController.php new file mode 100644 index 0000000..e3e4edb --- /dev/null +++ b/src/controller/ArticleController.php @@ -0,0 +1,169 @@ + + $director->findNodeById($section_id); + $director->makeSectionNode(); + $node = $director->getNode(); // =
+ + if(is_array($content)){ + $date = new \DateTime($content['d']); + $article = new Article($content['i'], $date, $content['t'], $content['p']); + $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); + + // id_node tout juste généré + //$article_node->getId(); + } + else{ + $timestamp = time(); + $date = new \DateTime; + $date->setTimestamp($timestamp); + + $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD + $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); + } + + $entityManager->persist($article_node); + $entityManager->flush(); + + echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); + die; + } + // modification article + else{ + $id[0] = 'i'; // id de l'article node + } + + if($director->makeArticleNode($id)) // une entrée est trouvée + { + $node = $director->getArticleNode(); // article + switch($json['id'][0]){ + case 'i': + $node->getArticle()->setContent($content); + break; + case 'p': + $node->getArticle()->setPreview($content); // html de l'éditeur + break; + case 't': + $node->getArticle()->setTitle($content); // html de l'éditeur + break; + case 'd': + echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); + die; + default: + echo json_encode(['success' => false, 'message' => 'identifiant non utilisable']); + die; + } + $entityManager->flush(); + echo json_encode(['success' => true]); + } + else + { + echo json_encode(['success' => false, 'message' => 'article non identifié']); + } + } + else{ + echo json_encode(['success' => false, 'message' => 'Erreur de décodage JSON']); + } + die; + } + + static public function deleteArticle(EntityManager $entityManager, array $json): void + { + $director = new Director($entityManager); + $director->makeArticleNode($json['id'], true); + $article = $director->getArticleNode(); + $section = $director->getNode(); + + $entityManager->remove($article); + $section->removeChild($article); + $section->sortChildren(true); // régénère les positions + $entityManager->flush(); + + // test avec une nouvelle requête qui ne devrait rien trouver + if(!$director->makeArticleNode($json['id'])) + { + echo json_encode(['success' => true]); + + // on pourrait afficher une notification "toast" + } + else{ + http_response_code(500); + echo json_encode(['success' => false, 'message' => 'Erreur lors de la suppression de l\'article.']); + } + die; + } + + static public function switchPositions(EntityManager $entityManager, array $json): void + { + $director = new Director($entityManager); + $director->makeArticleNode($json['id1'], true); + $article1 = $director->getArticleNode(); + $section = $director->getNode(); + + $section->sortChildren(true); // régénère les positions avant inversion + + $article2 = null; + foreach($section->getChildren() as $child){ + if($child->getArticleTimestamp() === $json['id2']) // type string + { + $article2 = $child; + break; + } + } + + // inversion + $tmp = $article1->getPosition(); + $article1->setPosition($article2->getPosition()); + $article2->setPosition($tmp); + $entityManager->flush(); + + echo json_encode(['success' => true]); + die; + } + + static public function dateSubmit(EntityManager $entityManager, array $json): void + { + $id = $json['id']; + $id[0] = 'i'; + $date = new DateTime($json['date']); + + $director = new Director($entityManager); + $director->makeArticleNode($id); + $node = $director->getArticleNode(); + $node->getArticle()->setDateTime($date); + $entityManager->flush(); + + echo json_encode(['success' => true]); + die; + } +} \ No newline at end of file diff --git a/src/controller/CalendarController.php b/src/controller/CalendarController.php new file mode 100644 index 0000000..cc37d0f --- /dev/null +++ b/src/controller/CalendarController.php @@ -0,0 +1,79 @@ +setTimezone(new DateTimeZone('UTC')); + $end->setTimezone(new DateTimeZone('UTC')); + + // affichage format ISO à l'heure UTC + //$date->format('Y-m-d\TH:i:s\Z'); + + // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette + $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; + $bulk_data = $entityManager->createQuery($dql) + ->setParameter('start', $start) + ->setParameter('end', $end) + ->getResult(); + + $events = []; + foreach($bulk_data as $one_entry){ + $event = new EventDTO($one_entry); + $events[] = $event->toArray(); + } + + header('Content-Type: application/json'); + echo json_encode($events); + die; + } + + static public function newEvent(array $json, EntityManager $entityManager):void + { + try{ + $event = new Event($json); + } + catch(InvalidArgumentException $e){ + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + http_response_code(400); + die; + } + $entityManager->persist($event); + $entityManager->flush(); + + echo json_encode(['success' => true, 'id' => $event->getId()]); + } + static public function updateEvent(array $json, EntityManager $entityManager):void + { + $event = $entityManager->find('App\Entity\Event', (int)$json['id']); + try{ + $event->securedUpdateFromJSON($json); + } + catch(InvalidArgumentException $e){ + echo json_encode(['success' => false, 'error' => $e->getMessage()]); + http_response_code(400); + die; + } + $entityManager->flush(); + + echo json_encode(['success' => true]); + } + static public function removeEvent(array $json, EntityManager $entityManager):void + { + $event = $entityManager->find('App\Entity\Event', (int)$json['id']); + $entityManager->remove($event); + $entityManager->flush(); + + echo json_encode(['success' => true]); + } +} \ No newline at end of file diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php new file mode 100644 index 0000000..9d62a77 --- /dev/null +++ b/src/controller/ContactFormController.php @@ -0,0 +1,44 @@ +find('App\Entity\NodeData', $json['id']); + $form_data->updateData('email', $email); + $entityManager->persist($form_data); + $entityManager->flush(); + + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + static public function sendTestEmail(EntityManager $entityManager, array $json): void + { + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $recipient = $form_data->getData()['email'] ?? Config::$email_dest; + + if(EmailController::send($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } +} \ No newline at end of file diff --git a/src/controller/EmailController.php b/src/controller/EmailController.php new file mode 100644 index 0000000..1eea257 --- /dev/null +++ b/src/controller/EmailController.php @@ -0,0 +1,91 @@ + exceptions + $mail->CharSet = 'UTF-8'; + + try{ + // Paramètres du serveur + $mail->isSMTP(); + $mail->Host = Config::$smtp_host; + $mail->SMTPAuth = true; + $mail->Port = 25; + + if($mail->SMTPAuth){ + $mail->Username = Config::$smtp_username; // e-mail + $mail->Password = Config::$smtp_password; + $mail->SMTPSecure = Config::$smtp_secure; // tls (starttls) ou ssl (smtps) + if($mail->SMTPSecure === 'tls'){ + $mail->Port = 587; + } + elseif($mail->SMTPSecure === 'ssl'){ + $mail->Port = 465; + } + } + //var_dump($mail->smtpConnect());die; // test de connexion + + // Expéditeur et destinataire + $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur + $mail->addAddress(strtolower($recipient), Config::$email_dest_name); // destinataire + + // Contenu + $mail->isHTML(true); + if($true_email){ + $mail->Subject = 'Message envoyé par: ' . $name . ' (' . $email . ') depuis le site web'; + + } + else{ + $mail->Subject = "TEST d'un envoi d'e-mail depuis le site web"; + } + $mail->Body = $message; + $mail->AltBody = $message; + + $mail->send(); + return true; + } + catch(Exception $e){ + return false; + //echo "Le message n'a pas pu être envoyé. Erreur : {$mail->ErrorInfo}"; + } + } + + static public function submit(array $json, EntityManager $entityManager): void + { + $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; + $captcha_try = isset($json['captcha']) ? Captcha::controlInput($json['captcha']) : 0; + + // contrôles des entrées + $name = htmlspecialchars(trim($json['name'])); + $email = strtolower(htmlspecialchars(trim($json['email']))); + $message = htmlspecialchars(trim($json['message'])); + + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $recipient = $form_data->getData()['email'] ?? Config::$email_dest; + + if($captcha_try != 0 && $captcha_solution != 0 && ($captcha_try === $captcha_solution) + && filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden']) + && self::send($recipient, true, $name, $email, $message)) + { + $db_email = new Email($email, Config::$email_dest, $message); + $entityManager->persist($db_email); + $entityManager->flush(); + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } +} \ No newline at end of file diff --git a/src/controller/ImageUploadController.php b/src/controller/ImageUploadController.php new file mode 100644 index 0000000..29b8059 --- /dev/null +++ b/src/controller/ImageUploadController.php @@ -0,0 +1,184 @@ +readImageBlob($image_data); + $imagick->stripImage(); // nettoyage métadonnées + $imagick->setImageFormat($format); + if($format === 'jpeg'){ + $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); + $imagick->setImageCompressionQuality(85); // optionnel + } + $imagick->writeImage($local_path); // enregistrement + $imagick->clear(); + $imagick->destroy(); + return true; + } + catch(Exception $e){ + return false; + } + } + static public function curlDownloadImage(string $url, $maxRetries = 3, $timeout = 10): string|false + { + $attempt = 0; + $imageData = false; + + while($attempt < $maxRetries){ + $ch = curl_init($url); // instance de CurlHandle + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); + curl_setopt($ch, CURLOPT_USERAGENT, 'TinyMCE-Image-Downloader'); + + $imageData = curl_exec($ch); + $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); + //$curlError = curl_error($ch); + + curl_close($ch); + + if($imageData !== false && $httpCode >= 200 && $httpCode < 300){ + return $imageData; + } + + $attempt++; + sleep(1); + } + + return false; // échec après trois tentatives + } + + // téléchargement par le plugin (bouton "insérer une image") + static public function imageUploadTinyMce(): void + { + if(isset($_FILES['file'])){ + $file = $_FILES['file']; + $dest = 'images/'; + $dest_mini = 'images-mini/'; + + // Vérifier si les répertoires existent, sinon les créer + if(!is_dir($dest)) { + mkdir($dest, 0700, true); + } + if(!is_dir($dest_mini)) { + mkdir($dest_mini, 0700, true); + } + + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; + $name = Security::secureFileName(pathinfo($file['name'], PATHINFO_FILENAME)); + $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ + $extension = 'jpeg'; + } + $file_path = $dest . $name . '_' . uniqid() . '.' . $extension; + + // créer une miniature de l'image + // + + if(self::imagickCleanImage(file_get_contents($file['tmp_name']), $file_path, $extension)){ // recréer l’image pour la nettoyer + echo json_encode(['location' => $file_path]); // renvoyer l'URL de l'image téléchargée + } + else{ + http_response_code(500); + echo json_encode(['message' => 'Erreur image non valide']); + } + } + else{ + http_response_code(400); + echo json_encode(['message' => 'Erreur 400: Bad Request']); + } + die; + } + + // collage de HTML => recherche de balises , téléchargement côté serveur et renvoi de l'adresse sur le serveur + static public function uploadImageHtml(): void + { + $json = json_decode(file_get_contents('php://input'), true); + + if(isset($json['image_url'])){ + $image_data = self::curlDownloadImage($json['image_url']); // téléchargement de l’image par le serveur avec cURL au lieu de file_get_contents + $dest = 'images/'; + + if(!is_dir($dest)) { // Vérifier si le répertoire existe, sinon le créer + mkdir($dest, 0777, true); + } + + if($image_data === false){ + http_response_code(400); + echo json_encode(['message' => "Erreur, le serveur n'a pas réussi à télécharger l'image."]); + die; + } + + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; + $url_path = parse_url($json['image_url'], PHP_URL_PATH); + $name = Security::secureFileName(pathinfo($url_path, PATHINFO_FILENAME)); + $extension = strtolower(pathinfo($url_path, PATHINFO_EXTENSION)); + if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ + $extension = 'jpeg'; + } + $local_path = $dest . $name . '_' . uniqid() . '.' . $extension; + + if(self::imagickCleanImage($image_data, $local_path, $extension)){ // recréer l’image pour la nettoyer + echo json_encode(['location' => $local_path]); // nouvelle adresse + } + else{ + http_response_code(500); + echo json_encode(['message' => 'Erreur image non valide']); + } + } + else{ + echo json_encode(['message' => 'Erreur 400: Bad Request']); + } + die; + } + + // collage simple d'une image (base64 dans le presse-papier) non encapsulée dans du HTML + static public function uploadImageBase64(): void + { + $json = json_decode(file_get_contents('php://input'), true); + $dest = 'images/'; + + if(!is_dir('images')){ + mkdir('images', 0777, true); + } + + // détection de data:image/ et de ;base64, et capture du format dans $type + if(!isset($json['image_base64']) || !preg_match('/^data:image\/(\w+);base64,/', $json['image_base64'], $type)){ + http_response_code(400); + echo json_encode(['message' => 'Données image base64 manquantes ou invalides']); + die; + } + + $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; + $extension = strtolower($type[1]); + if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ + $extension = 'jpeg'; + } + + $image_data = base64_decode(substr($json['image_base64'], strpos($json['image_base64'], ',') + 1)); // découpe la chaine à la virgule puis convertit en binaire + if($image_data === false){ + http_response_code(400); + echo json_encode(['message' => 'Décodage base64 invalide']); + die; + } + + $local_path = $dest . 'pasted_image_' . uniqid() . '.' . $extension; + + if(self::imagickCleanImage($image_data, $local_path)){ + echo json_encode(['location' => $local_path]); + } + else{ + http_response_code(500); + echo json_encode(['message' => 'Erreur image non valide']); + } + die; + } +} \ No newline at end of file diff --git a/src/controller/MenuAndPathsController.php b/src/controller/MenuAndPathsController.php new file mode 100644 index 0000000..d429287 --- /dev/null +++ b/src/controller/MenuAndPathsController.php @@ -0,0 +1,189 @@ +findPageById((int)$_POST["location"]); // (int) à cause de declare(strict_types=1); + $parent = $previous_page->getParent(); + + $page = new Page( + trim(htmlspecialchars($_POST["label_input"])), + filter_var($_POST["url_input"], FILTER_VALIDATE_URL), + true, true, false, + $previous_page->getPosition(), + $parent); // peut et DOIT être null si on est au 1er niveau + + // on a donné à la nouvelle entrée la même position qu'à la précédente, + // addChild l'ajoute à la fin du tableau "children" puis on trie + // 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){ + $parent = Director::$menu_data; + } + $parent->addChild($page); // true pour réindexer les positions en BDD + $parent->reindexPositions(); + + $entityManager->persist($page); + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['from']])); + die; + } + + static public function deleteUrlMenuEntry(EntityManager $entityManager): void + { + Director::$menu_data = new Menu($entityManager); + $page = Director::$menu_data->findPageById((int)$_POST["delete"]); + $parent = $page->getParent(); + if($parent == null){ + $parent = Director::$menu_data; + } + + $parent->removeChild($page); // suppression de $children avant de trier + $parent->reindexPositions(); + + $entityManager->remove($page); // suppression en BDD + $entityManager->flush(); + header("Location: " . new URL(['page' => $_GET['from']])); + die; + } + + static public function MoveOneLevelUp(EntityManager $entityManager, array $json): void + { + $id = $json['id']; + $page = Director::$menu_data->findPageById((int)$id); + + $parent = $page->getParent(); // peut être null + if($parent === null){ + // 1er niveau: ne rien faire + echo json_encode(['success' => false]); + die; + } + // BDD + else{ + $page->setPosition($parent->getPosition() + 1); // nouvelle position + + // 2ème niveau: le parent devient $menu_data, puis null après tri + if($parent->getParent() === null){ + // connexion dans les deux sens + $page->setParent(Director::$menu_data); // => pour la persistance + + //Director::$menu_data->addChild($page); // => pour sortChildren + $page->getParent()->addChild($page); // => pour sortChildren + //Director::$menu_data->sortChildren(true); // positions décaléees des nouveaux petits frères + $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères + $page->setParent(null); + + // affichage + $page->setPagePath($page->getEndOfPath()); + $page->fillChildrenPagePath(); + } + // 3ème niveau et plus + else{ + $page->setParent($parent->getParent()); // nouveau parent + $page->getParent()->addChild($page); // => pour sortChildren + $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères + $page->fillChildrenPagePath($page->getParent()->getPagePath()); + } + //$parent->sortChildren(true); // positions des enfants restants, inutile si la fonction est récursive? + $entityManager->flush(); + + // affichage + $parent->removeChild($page); + $nav_builder = new NavBuilder(); + $menu_builder = new MenuBuilder(null, false); + echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]); + die; + } + } + + static public function MoveOneLevelDown(EntityManager $entityManager, array $json): void + { + $id = $json['id']; + $page = Director::$menu_data->findPageById((int)$id); + + $parent = $page->getParent(); // peut être null + if($parent == null){ + $parent = Director::$menu_data; + } + + // BDD + $parent->sortChildren(true); // trie et réindexe par sécurité: 1, 2, 3... + if($page->getPosition() > 1){ + foreach($parent->getChildren() as $child){ + if($child->getPosition() === $page->getPosition() - 1){ + $page->setParent($child); + break; + } + } + $page->setPosition(count($page->getParent()->getChildren()) + 1); + } + $entityManager->flush(); + + // affichage + $parent->removeChild($page); + $page->getParent()->addChild($page); + $page->fillChildrenPagePath($page->getParent()->getPagePath()); // variable non mappée $page_path + $nav_builder = new NavBuilder(); + $menu_builder = new MenuBuilder(null, false); + + echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]); + die; + } + + static public function SwitchPositions(EntityManager $entityManager, array $json): void + { + $id1 = $json['id1']; + $id2 = $json['id2']; + + // vérifier qu'ils ont le même parent + $page1 = Director::$menu_data->findPageById((int)$id1); + $page2 = Director::$menu_data->findPageById((int)$id2); + + // double le contrôle fait en JS + if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) + { + // inversion + $tmp = $page1->getPosition(); + $page1->setPosition($page2->getPosition()); + $page2->setPosition($tmp); + Director::$menu_data->sortChildren(true); // modifie tableau children + $entityManager->flush(); + + // nouveau menu + $nav_builder = new NavBuilder(); + echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); + } + else{ + echo json_encode(['success' => false]); + } + + die; + } + + static public function displayInMenu(EntityManager $entityManager, array $json): void + { + $id = $json['id']; + $checked = $json['checked']; + + $page = Director::$menu_data->findPageById((int)$id); + if($page->isHidden() === $checked){ + $page->setHidden(!$checked); + $entityManager->flush(); + + // nouveau menu + $nav_builder = new NavBuilder(); + echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } +} \ No newline at end of file diff --git a/src/controller/PageManagementController.php b/src/controller/PageManagementController.php new file mode 100644 index 0000000..f84c528 --- /dev/null +++ b/src/controller/PageManagementController.php @@ -0,0 +1,264 @@ +find('App\Entity\Page', $json['page_id']); + $page->setPageName(htmlspecialchars($json['title'])); + $entityManager->flush(); + echo json_encode(['success' => true, 'title' => $page->getPageName()]); + die; + } + + static public function updatePageMenuPath(EntityManager $entityManager): void + { + Director::$menu_data = new Menu($entityManager); + Director::$page_path = new Path(); + $page = Director::$page_path->getLast(); + $path = htmlspecialchars($_POST['page_menu_path']); + + // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores + $path = trim(preg_replace('/_+/', '_', strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $path))), '_'); + $page->setEndOfPath($path); + foreach(Director::$menu_data->getChildren() as $child){ + if($child->getEndOfPath() === Director::$page_path->getArray()[0]->getEndOfPath()){ + $child->fillChildrenPagePath(); // MAJ de $page_path + } + } + $entityManager->flush(); + header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); + die; + } + + static public function setPageDescription(EntityManager $entityManager, array $json): void + { + $node_data = $entityManager->find('App\Entity\NodeData', $json['node_data_id']); + $node_data->updateData('description', htmlspecialchars($json['description'])); + $entityManager->flush(); + echo json_encode(['success' => true, 'description' => $node_data->getData()['description']]); + die; + } + + static public function newPage(EntityManager $entityManager): void + { + // titre et chemin + $director = new Director($entityManager, true); + //Director::$menu_data = new Menu($entityManager); + $previous_page = Director::$menu_data->findPageById((int)$_POST["page_location"]); // (int) à cause de declare(strict_types=1); + $parent = $previous_page->getParent(); + + $page = new Page( + trim(htmlspecialchars($_POST["page_name"])), + trim(htmlspecialchars($_POST["page_name_path"])), + true, true, false, + $previous_page->getPosition(), + $parent); // peut et DOIT être null si on est au 1er niveau + + // on a donné à la nouvelle entrée la même position qu'à la précédente, + // addChild l'ajoute à la fin du tableau "children" puis on trie + // 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){ + $parent = Director::$menu_data; + } + $parent->addChild($page); + $parent->reindexPositions(); + + $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); + + // noeud "head" + $node = new Node( + 'head', + null, [], + 1, // position d'un head = 1 + null, // pas de parent + $page); + $node->useDefaultAttributes(); // fichiers CSS et JS + + $data = new NodeData([ + // pas de titre, il est dans $page + 'description' => trim(htmlspecialchars($_POST["page_description"]))], + $node); + + $bulk_data = $entityManager + ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') + ->setParameter('name', '%favicon%') + ->getResult(); + $data->setImages(new ArrayCollection($bulk_data)); + + $entityManager->persist($page); + $entityManager->persist($node); + $entityManager->persist($data); + $entityManager->flush(); + + // page créée, direction la page en mode modification pour ajouter des blocs + header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); + die; + } + + static public function deletePage(EntityManager $entityManager): void + { + $page = $entityManager->find('App\Entity\Page', (int)$_POST['page_id']); + $nodes = $entityManager->getRepository('App\Entity\Node')->findBy(['page' => $page]); + $data = []; + foreach($nodes as $node){ + $data[] = $entityManager->getRepository('App\Entity\NodeData')->findOneBy(['node' => $node]); + $entityManager->remove($node); + } + foreach($data as $one_data){ + $entityManager->remove($one_data); + } + $entityManager->remove($page); // suppression en BDD + + $entityManager->flush(); + header("Location: " . new URL); + die; + } + + /* partie "blocs" */ + static public function addBloc(EntityManager $entityManager): void + { + $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data + $page = Director::$page_path->getLast(); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + $main = $director->getNode(); + $position = count($main->getChildren()) + 1; // position dans la fraterie + + $blocks = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php + if(!in_array($_POST["bloc_select"], $blocks, true)) // 3è param: contrôle du type + { + header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); + die; + } + + if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ + $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page + $bulk_data = $entityManager + ->createQuery($dql) + ->setParameter('page', $page) + ->setParameter('name', 'head') + ->getResult(); + + if(count($bulk_data) != 1){ // 1 head par page + header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found'])); + die; + } + + $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); + if($_POST["bloc_select"] === 'form'){ + $bulk_data[0]->addAttribute('js_array', $_POST["bloc_select"]); + } + $entityManager->persist($bulk_data[0]); + } + + $bloc = new Node( + $_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'])); + die; + } + + static public function deleteBloc(EntityManager $entityManager): void + { + $director = new Director($entityManager, true); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + //$director->findNodeById((int)$_POST['delete_bloc_id']); + $main = $director->getNode(); + $bloc = null; + foreach($main->getChildren() as $child){ + if($child->getId() === (int)$_POST['delete_bloc_id']){ + $bloc = $child; + break; + } + } + if(!empty($bloc)){ // si $bloc est null c'est que le HTML a été modifié volontairement + $main->removeChild($bloc); // réindex le tableau $children au passage + $main->reindexPositions(); + $entityManager->remove($bloc); // suppression en BDD + $entityManager->flush(); + } + header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); + die; + } + + static public function renameBloc(EntityManager $entityManager, array $json): void + { + if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ + $director = new Director($entityManager); + $director->findNodeById($json['bloc_id']); + + // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé + $data = $director->getNode()->getNodeData()->getData(); + $data['title'] = htmlspecialchars($json['bloc_title']); + $director->getNode()->getNodeData()->updateData('title', htmlspecialchars($json['bloc_title'])); + + $entityManager->flush(); + echo json_encode(['success' => true, 'title' => $data['title']]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + + static public function SwitchBlocsPositions(EntityManager $entityManager, array $json): void + { + if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ + $director = new Director($entityManager, true); + $director->findUniqueNodeByName('main'); + $director->findItsChildren(); + $main = $director->getNode(); + $main->sortChildren(true); // régénère les positions avant inversion + + $bloc1 = null; + $bloc2 = null; + foreach($main->getChildren() as $child){ + if($child->getId() === $json['id1']){ + $bloc1 = $child; + break; + } + } + foreach($main->getChildren() as $child){ + if($child->getId() === $json['id2']){ + $bloc2 = $child; + break; + } + } + + // inversion + $tmp = $bloc1->getPosition(); + $bloc1->setPosition($bloc2->getPosition()); + $bloc2->setPosition($tmp); + + $entityManager->flush(); + echo json_encode(['success' => true]); + } + else{ + echo json_encode(['success' => false]); + } + die; + } +} \ No newline at end of file diff --git a/src/controller/ajax_admin.php b/src/controller/ajax_admin.php deleted file mode 100644 index b69be77..0000000 --- a/src/controller/ajax_admin.php +++ /dev/null @@ -1,636 +0,0 @@ -readImageBlob($image_data); - $imagick->stripImage(); // nettoyage métadonnées - $imagick->setImageFormat($format); - if($format === 'jpeg'){ - $imagick->setImageCompression(Imagick::COMPRESSION_JPEG); - $imagick->setImageCompressionQuality(85); // optionnel - } - $imagick->writeImage($local_path); // enregistrement - $imagick->clear(); - $imagick->destroy(); - return true; - } - catch(Exception $e){ - return false; - } -} -function curlDownloadImage(string $url, $maxRetries = 3, $timeout = 10): string|false -{ - $attempt = 0; - $imageData = false; - - while($attempt < $maxRetries){ - $ch = curl_init($url); // instance de CurlHandle - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true); - curl_setopt($ch, CURLOPT_USERAGENT, 'TinyMCE-Image-Downloader'); - - $imageData = curl_exec($ch); - $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); - //$curlError = curl_error($ch); - - curl_close($ch); - - if($imageData !== false && $httpCode >= 200 && $httpCode < 300){ - return $imageData; - } - - $attempt++; - sleep(1); - } - - return false; // échec après trois tentatives -} - -function imageUploadTinyMce(): void -{ - if(isset($_FILES['file'])){ - $file = $_FILES['file']; - $dest = 'images/'; - $dest_mini = 'images-mini/'; - - // Vérifier si les répertoires existent, sinon les créer - if(!is_dir($dest)) { - mkdir($dest, 0700, true); - } - if(!is_dir($dest_mini)) { - mkdir($dest_mini, 0700, true); - } - - $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; - $name = Security::secureFileName(pathinfo($file['name'], PATHINFO_FILENAME)); - $extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); - if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ - $extension = 'jpeg'; - } - $file_path = $dest . $name . '_' . uniqid() . '.' . $extension; - - // créer une miniature de l'image - // - - if(imagickCleanImage(file_get_contents($file['tmp_name']), $file_path, $extension)){ // recréer l’image pour la nettoyer - echo json_encode(['location' => $file_path]); // renvoyer l'URL de l'image téléchargée - } - else{ - http_response_code(500); - echo json_encode(['message' => 'Erreur image non valide']); - } - } - else{ - http_response_code(400); - echo json_encode(['message' => 'Erreur 400: Bad Request']); - } - die; -} - -// détection des requêtes d'upload d'image de tinymce -if(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image') -{ - imageUploadTinyMce(); -} -// cas du collage d'un contenu HTML, réception d'une URL, téléchargement par le serveur et renvoie de l'adresse sur le serveur -elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image_url') -{ - $json = json_decode(file_get_contents('php://input'), true); - - if(isset($json['image_url'])){ - $image_data = curlDownloadImage($json['image_url']); // téléchargement de l’image par le serveur avec cURL au lieu de file_get_contents - $dest = 'images/'; - - if(!is_dir($dest)) { // Vérifier si le répertoire existe, sinon le créer - mkdir($dest, 0777, true); - } - - if($image_data === false){ - http_response_code(400); - echo json_encode(['message' => "Erreur, le serveur n'a pas réussi à télécharger l'image."]); - die; - } - - $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; - $url_path = parse_url($json['image_url'], PHP_URL_PATH); - $name = Security::secureFileName(pathinfo($url_path, PATHINFO_FILENAME)); - $extension = strtolower(pathinfo($url_path, PATHINFO_EXTENSION)); - if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ - $extension = 'jpeg'; - } - $local_path = $dest . $name . '_' . uniqid() . '.' . $extension; - - if(imagickCleanImage($image_data, $local_path, $extension)){ // recréer l’image pour la nettoyer - echo json_encode(['location' => $local_path]); // nouvelle adresse - } - else{ - http_response_code(500); - echo json_encode(['message' => 'Erreur image non valide']); - } - } - else{ - echo json_encode(['message' => 'Erreur 400: Bad Request']); - } - die; -} -// cas du collage d'une image (code base64) non encapsulée dans du HTML -elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image_base64') -{ - $json = json_decode(file_get_contents('php://input'), true); - $dest = 'images/'; - - if(!is_dir('images')){ - mkdir('images', 0777, true); - } - - // détection de data:image/ et de ;base64, et capture du format dans $type - if(!isset($json['image_base64']) || !preg_match('/^data:image\/(\w+);base64,/', $json['image_base64'], $type)){ - http_response_code(400); - echo json_encode(['message' => 'Données image base64 manquantes ou invalides']); - die; - } - - $allowed_extensions = ['jpg', 'jpeg', 'png', 'gif', 'webp', 'tiff', 'tif']; - $extension = strtolower($type[1]); - if(!in_array($extension, $allowed_extensions) || $extension === 'jpg'){ - $extension = 'jpeg'; - } - - $image_data = base64_decode(substr($json['image_base64'], strpos($json['image_base64'], ',') + 1)); // découpe la chaine à la virgule puis convertit en binaire - if($image_data === false){ - http_response_code(400); - echo json_encode(['message' => 'Décodage base64 invalide']); - die; - } - - $local_path = $dest . 'pasted_image_' . uniqid() . '.' . $extension; - - if(imagickCleanImage($image_data, $local_path)){ - echo json_encode(['location' => $local_path]); - } - else{ - http_response_code(500); - echo json_encode(['message' => 'Erreur image non valide']); - } - die; -} - -// détection des requêtes de type XHR, y en a pas à priori -/*elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ - echo "requête XHR reçue par le serveur"; - die; -}*/ - - -// détection des requêtes envoyées avec fetch (application/json) et récupération du JSON -if($_SERVER['CONTENT_TYPE'] === 'application/json') -{ - $data = file_get_contents('php://input'); - $json = json_decode($data, true); - - if(isset($_GET['action'])) - { - if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content'])) - { - if(json_last_error() === JSON_ERROR_NONE) - { - $id = $json['id']; - $director = new Director($entityManager); - - // cas d'une nouvelle "news" - if(is_array($json['content'])){ - foreach($json['content'] as $one_input){ - $one_input = Security::secureString($one_input); - } - $content = $json['content']; - } - else{ - $content = Security::secureString($json['content']); - } - - // nouvel article - if($id[0] === 'n') - { - $section_id = (int)substr($id, 1); // id du bloc
- $director->findNodeById($section_id); - $director->makeSectionNode(); - $node = $director->getNode(); // =
- - if(is_array($content)){ - $date = new \DateTime($content['d']); - $article = new Article($content['i'], $date, $content['t'], $content['p']); - $article_node = new Node('new', 'i' . (string)$date->getTimestamp(), [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); - - // id_node tout juste généré - //$article_node->getId(); - } - else{ - $timestamp = time(); - $date = new \DateTime; - $date->setTimestamp($timestamp); - - $article = new Article($content, $date); // le "current" timestamp est obtenu par la BDD - $article_node = new Node('article', 'i' . (string)$timestamp, [], count($node->getChildren()) + 1, $node, $node->getPage(), $article); - } - - $entityManager->persist($article_node); - $entityManager->flush(); - - echo json_encode(['success' => true, 'article_id' => $article_node->getArticleTimestamp()]); - die; - } - // modification article - else{ - $id[0] = 'i'; // id de l'article node - } - - if($director->makeArticleNode($id)) // une entrée est trouvée - { - $node = $director->getArticleNode(); // article - switch($json['id'][0]){ - case 'i': - $node->getArticle()->setContent($content); - break; - case 'p': - $node->getArticle()->setPreview($content); // html de l'éditeur - break; - case 't': - $node->getArticle()->setTitle($content); // html de l'éditeur - break; - case 'd': - echo json_encode(['success' => false, 'message' => 'l\'action editor_submit ne supporte pas les dates, utiliser date_submit.']); - die; - default: - echo json_encode(['success' => false, 'message' => 'identifiant non utilisable']); - die; - } - $entityManager->flush(); - echo json_encode(['success' => true]); - } - else - { - echo json_encode(['success' => false, 'message' => 'article non identifié']); - } - } - else{ - echo json_encode(['success' => false, 'message' => 'Erreur de décodage JSON']); - } - die; - } - elseif($_GET['action'] === 'delete_article' && isset($json['id'])) - { - $director = new Director($entityManager); - $director->makeArticleNode($json['id'], true); - $article = $director->getArticleNode(); - $section = $director->getNode(); - - $entityManager->remove($article); - $section->removeChild($article); - $section->sortChildren(true); // régénère les positions - $entityManager->flush(); - - // test avec une nouvelle requête qui ne devrait rien trouver - if(!$director->makeArticleNode($json['id'])) - { - echo json_encode(['success' => true]); - - // on pourrait afficher une notification "toast" - } - else{ - http_response_code(500); - echo json_encode(['success' => false, 'message' => 'Erreur lors de la suppression de l\'article.']); - } - die; - } - // inversion de la position de deux noeuds - elseif($_GET['action'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) - { - $director = new Director($entityManager); - $director->makeArticleNode($json['id1'], true); - $article1 = $director->getArticleNode(); - $section = $director->getNode(); - - $section->sortChildren(true); // régénère les positions avant inversion - - $article2; - foreach($section->getChildren() as $child){ - if($child->getArticleTimestamp() === $json['id2']) // type string - { - $article2 = $child; - break; - } - } - - // inversion - $tmp = $article1->getPosition(); - $article1->setPosition($article2->getPosition()); - $article2->setPosition($tmp); - $entityManager->flush(); - - echo json_encode(['success' => true]); - die; - } - elseif($_GET['action'] === 'date_submit' && isset($json['id']) && isset($json['date'])) - { - $id = $json['id']; - $id[0] = 'i'; - $date = new DateTime($json['date']); - - $director = new Director($entityManager); - $director->makeArticleNode($id); - $node = $director->getArticleNode(); - $node->getArticle()->setDateTime($date); - $entityManager->flush(); - - echo json_encode(['success' => true]); - die; - } - - - /* -- bloc Formulaire -- */ - elseif($_GET['action'] === 'recipient_email'){ - $email = htmlspecialchars(trim($json['email'])); - - if((filter_var($email, FILTER_VALIDATE_EMAIL) // nouvel e-mail - || ($json['email'] === '' && !empty(Config::$email_dest))) // e-mail par défaut - && isset($json['hidden']) && empty($json['hidden'])) - { - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); - $form_data->updateData('email', $email); - $entityManager->persist($form_data); - $entityManager->flush(); - - echo json_encode(['success' => true]); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - elseif($_GET['action'] === 'test_email'){ - // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); - $recipient = $form_data->getData()['email'] ?? Config::$email_dest; - - if(sendEmail($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ - echo json_encode(['success' => true]); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - } - - - /* -- page Menu et chemins -- */ - elseif(isset($_GET['menu_edit'])) - { - // récupération des données - $data = file_get_contents('php://input'); - $json = json_decode($data, true); - Director::$menu_data = new Menu($entityManager); - - // flèche gauche <=: position = position du parent + 1, parent = grand-parent, recalculer les positions - if($_GET['menu_edit'] === 'move_one_level_up' && isset($json['id'])){ - $id = $json['id']; - $page = Director::$menu_data->findPageById((int)$id); - - $parent = $page->getParent(); // peut être null - if($parent === null){ - // 1er niveau: ne rien faire - echo json_encode(['success' => false]); - die; - } - // BDD - else{ - $page->setPosition($parent->getPosition() + 1); // nouvelle position - - // 2ème niveau: le parent devient $menu_data, puis null après tri - if($parent->getParent() === null){ - // connexion dans les deux sens - $page->setParent(Director::$menu_data); // => pour la persistance - - //Director::$menu_data->addChild($page); // => pour sortChildren - $page->getParent()->addChild($page); // => pour sortChildren - //Director::$menu_data->sortChildren(true); // positions décaléees des nouveaux petits frères - $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères - $page->setParent(null); - - // affichage - $page->setPagePath($page->getEndOfPath()); - $page->fillChildrenPagePath(); - } - // 3ème niveau et plus - else{ - $page->setParent($parent->getParent()); // nouveau parent - $page->getParent()->addChild($page); // => pour sortChildren - $page->getParent()->sortChildren(true); // positions décaléees des nouveaux petits frères - $page->fillChildrenPagePath($page->getParent()->getPagePath()); - } - //$parent->sortChildren(true); // positions des enfants restants, inutile si la fonction est récursive? - $entityManager->flush(); - - // affichage - $parent->removeChild($page); - $nav_builder = new NavBuilder(); - $menu_builder = new MenuBuilder(null, false); - echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]); - die; - } - } - - // flèche droite =>: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent - if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){ - $id = $json['id']; - $page = Director::$menu_data->findPageById((int)$id); - - $parent = $page->getParent(); // peut être null - if($parent == null){ - $parent = Director::$menu_data; - } - - // BDD - $parent->sortChildren(true); // trie et réindexe par sécurité: 1, 2, 3... - if($page->getPosition() > 1){ - foreach($parent->getChildren() as $child){ - if($child->getPosition() === $page->getPosition() - 1){ - $page->setParent($child); - break; - } - } - $page->setPosition(count($page->getParent()->getChildren()) + 1); - } - $entityManager->flush(); - - // affichage - $parent->removeChild($page); - $page->getParent()->addChild($page); - $page->fillChildrenPagePath($page->getParent()->getPagePath()); // variable non mappée $page_path - $nav_builder = new NavBuilder(); - $menu_builder = new MenuBuilder(null, false); - - echo json_encode(['success' => true, 'nav' => $nav_builder->render(), 'menu_buttons' => $menu_builder->render()]); - die; - } - - if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])) - { - $id1 = $json['id1']; - $id2 = $json['id2']; - - // vérifier qu'ils ont le même parent - $page1 = Director::$menu_data->findPageById((int)$id1); - $page2 = Director::$menu_data->findPageById((int)$id2); - - // double le contrôle fait en JS - if($page1->getParent() === $page2->getParent()) // comparaison stricte d'objet (même instance du parent?) - { - // inversion - $tmp = $page1->getPosition(); - $page1->setPosition($page2->getPosition()); - $page2->setPosition($tmp); - Director::$menu_data->sortChildren(true); // modifie tableau children - $entityManager->flush(); - - // nouveau menu - $nav_builder = new NavBuilder(); - echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); - } - else{ - echo json_encode(['success' => false]); - } - - die; - } - - if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])) - { - $id = $json['id']; - $checked = $json['checked']; - - $page = Director::$menu_data->findPageById((int)$id); - if($page->isHidden() === $checked){ - $page->setHidden(!$checked); - $entityManager->flush(); - - // nouveau menu - $nav_builder = new NavBuilder(); - echo json_encode(['success' => true, 'nav' => $nav_builder->render()]); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - } - - - /* -- mode Modification d'une page -- */ - - // partie "page" - elseif(isset($_GET['page_edit'])) - { - // récupération des données - $data = file_get_contents('php://input'); - $json = json_decode($data, true); - - // titre de la page - if($_GET['page_edit'] === 'page_title'){ - $page = $entityManager->find('App\Entity\Page', $json['page_id']); - $page->setPageName(htmlspecialchars($json['title'])); - $entityManager->flush(); - echo json_encode(['success' => true, 'title' => $page->getPageName()]); - } - // titre en snake_case pour le menu - /*elseif($_GET['page_edit'] === 'page_menu_path'){ - $page = $entityManager->find('App\Entity\Page', $json['page_id']); - $page->setEndOfPath(htmlspecialchars($json['page_menu_path'])); - $entityManager->flush(); - echo json_encode(['success' => true, 'page_name_path' => $page->getEndOfPath()]); - }*/ - // description dans les métadonnées - elseif($_GET['page_edit'] === 'page_description'){ - $node_data = $entityManager->find('App\Entity\NodeData', $json['node_data_id']); - $node_data->updateData('description', htmlspecialchars($json['description'])); - $entityManager->flush(); - echo json_encode(['success' => true, 'description' => $node_data->getData()['description']]); - } - die; - } - - // partie "blocs" - elseif(isset($_GET['bloc_edit'])) - { - // renommage d'un bloc - if($_GET['bloc_edit'] === 'rename_page_bloc') - { - if(isset($json['bloc_title']) && $json['bloc_title'] !== null && isset($json['bloc_id']) && is_int($json['bloc_id'])){ - $director = new Director($entityManager); - $director->findNodeById($json['bloc_id']); - - // le titre (du JSON en BDD) est récupéré sous forme de tableau, modifié et renvoyé - $data = $director->getNode()->getNodeData()->getData(); - $data['title'] = htmlspecialchars($json['bloc_title']); - $director->getNode()->getNodeData()->updateData('title', htmlspecialchars($json['bloc_title'])); - - $entityManager->flush(); - echo json_encode(['success' => true, 'title' => $data['title']]); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - // inversion des positions de deux blocs - elseif($_GET['bloc_edit'] === 'switch_blocs_positions') - { - if(isset($json['id1']) && is_int($json['id1']) && isset($json['id2']) && is_int($json['id2']) && isset($_GET['page'])){ - $director = new Director($entityManager, true); - $director->findUniqueNodeByName('main'); - $director->findItsChildren(); - $main = $director->getNode(); - $main->sortChildren(true); // régénère les positions avant inversion - - $bloc1; $bloc2; - foreach($main->getChildren() as $child){ - if($child->getId() === $json['id1']){ - $bloc1 = $child; - break; - } - } - foreach($main->getChildren() as $child){ - if($child->getId() === $json['id2']){ - $bloc2 = $child; - break; - } - } - - // inversion - $tmp = $bloc1->getPosition(); - $bloc1->setPosition($bloc2->getPosition()); - $bloc2->setPosition($tmp); - - $entityManager->flush(); - echo json_encode(['success' => true]); - } - else{ - echo json_encode(['success' => false]); - } - die; - } - } -} \ No newline at end of file diff --git a/src/controller/ajax_calendar_admin.php b/src/controller/ajax_calendar_admin.php deleted file mode 100644 index 0baf73e..0000000 --- a/src/controller/ajax_calendar_admin.php +++ /dev/null @@ -1,54 +0,0 @@ - false, 'error' => $e->getMessage()]); - http_response_code(400); - die; - } - $entityManager->persist($event); - $entityManager->flush(); - - echo json_encode(['success' => true, 'id' => $event->getId()]); - } - elseif($_GET['action'] === 'update_event'){ - $event = $entityManager->find('App\Entity\Event', (int)$json['id']); - try{ - $event->securedUpdateFromJSON($json); - } - catch(InvalidArgumentException $e){ - echo json_encode(['success' => false, 'error' => $e->getMessage()]); - http_response_code(400); - die; - } - $entityManager->flush(); - - echo json_encode(['success' => true]); - } - elseif($_GET['action'] === 'remove_event'){ - $event = $entityManager->find('App\Entity\Event', (int)$json['id']); - $entityManager->remove($event); - $entityManager->flush(); - - echo json_encode(['success' => true]); - } - else{ - echo json_encode(['success' => false]); - } - die; -} \ No newline at end of file diff --git a/src/controller/ajax_calendar_visitor.php b/src/controller/ajax_calendar_visitor.php deleted file mode 100644 index dcdbebd..0000000 --- a/src/controller/ajax_calendar_visitor.php +++ /dev/null @@ -1,39 +0,0 @@ -setTimezone(new DateTimeZone('UTC')); - $end->setTimezone(new DateTimeZone('UTC')); - - // affichage format ISO à l'heure UTC - //$date->format('Y-m-d\TH:i:s\Z'); - - // on prend les évènements se finissant après le début ou commençant avant la fin de la fourchette - $dql = 'SELECT e FROM App\Entity\Event e WHERE e.end >= :start AND e.start <= :end'; - $bulk_data = $entityManager->createQuery($dql) - ->setParameter('start', $start) - ->setParameter('end', $end) - ->getResult(); - - $events = []; - foreach($bulk_data as $one_entry){ - $event = new EventDTO($one_entry); - $events[] = $event->toArray(); - } - - header('Content-Type: application/json'); - echo json_encode($events); - die; -} \ No newline at end of file diff --git a/src/controller/ajax_email.php b/src/controller/ajax_email.php deleted file mode 100644 index 1138e04..0000000 --- a/src/controller/ajax_email.php +++ /dev/null @@ -1,105 +0,0 @@ - exceptions - $mail->CharSet = 'UTF-8'; - - try{ - // Paramètres du serveur - $mail->isSMTP(); - $mail->Host = Config::$smtp_host; - $mail->SMTPAuth = true; - $mail->Port = 25; - - if($mail->SMTPAuth){ - $mail->Username = Config::$smtp_username; // e-mail - $mail->Password = Config::$smtp_password; - $mail->SMTPSecure = Config::$smtp_secure; // tls (starttls) ou ssl (smtps) - if($mail->SMTPSecure === 'tls'){ - $mail->Port = 587; - } - elseif($mail->SMTPSecure === 'ssl'){ - $mail->Port = 465; - } - } - //var_dump($mail->smtpConnect());die; // test de connexion - - // Expéditeur et destinataire - $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur - $mail->addAddress(strtolower($recipient), Config::$email_dest_name); // destinataire - - // Contenu - $mail->isHTML(true); - if($true_email){ - $mail->Subject = 'Message envoyé par: ' . $name . ' (' . $email . ') depuis le site web'; - - } - else{ - $mail->Subject = "TEST d'un envoi d'e-mail depuis le site web"; - } - $mail->Body = $message; - $mail->AltBody = $message; - - $mail->send(); - return true; - } - catch(Exception $e){ - return false; - //echo "Le message n'a pas pu être envoyé. Erreur : {$mail->ErrorInfo}"; - } -} - -function submitEmail(array $json, EntityManager $entityManager): void -{ - $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; - $captcha_try = isset($json['captcha']) ? Captcha::controlInput($json['captcha']) : 0; - - // contrôles des entrées - $name = htmlspecialchars(trim($json['name'])); - $email = strtolower(htmlspecialchars(trim($json['email']))); - $message = htmlspecialchars(trim($json['message'])); - - // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur - $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); - $recipient = $form_data->getData()['email'] ?? Config::$email_dest; - - if($captcha_try != 0 && $captcha_solution != 0 && ($captcha_try === $captcha_solution) - && filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden']) - && sendEmail($recipient, true, $name, $email, $message)) - { - $db_email = new Email($email, Config::$email_dest, $message); - $entityManager->persist($db_email); - $entityManager->flush(); - echo json_encode(['success' => true]); - } - else{ - echo json_encode(['success' => false]); - } - die; -} - - -// détection des requêtes envoyées avec fetch (application/json) et récupération du JSON -if($_SERVER['CONTENT_TYPE'] === 'application/json') -{ - $data = file_get_contents('php://input'); - $json = json_decode($data, true); - - if(isset($_GET['action'])) - { - // formulaire de contact - if($_GET['action'] === 'send_email'){ - submitEmail($json, $entityManager); - } - } -} \ No newline at end of file diff --git a/src/controller/password.php b/src/controller/password.php index e91cc16..3d003da 100644 --- a/src/controller/password.php +++ b/src/controller/password.php @@ -226,7 +226,8 @@ function changePassword(EntityManager $entityManager): void } elseif(!isset($_POST['login']) || empty($_POST['login']) || !isset($_POST['old_password']) || empty($_POST['old_password']) - || !isset($_POST['new_password']) || empty($_POST['new_password'])) + || !isset($_POST['new_password']) || empty($_POST['new_password']) + || !isset($_POST['modify_password_hidden']) || !empty($_POST['modify_password_hidden'])) { $error = 'bad_login_or_password'; } diff --git a/src/controller/post_functions_admin.php b/src/controller/post_functions_admin.php deleted file mode 100644 index b47850a..0000000 --- a/src/controller/post_functions_admin.php +++ /dev/null @@ -1,231 +0,0 @@ -findPageById((int)$_POST["page_location"]); // (int) à cause de declare(strict_types=1); - $parent = $previous_page->getParent(); - - $page = new Page( - trim(htmlspecialchars($_POST["page_name"])), - trim(htmlspecialchars($_POST["page_name_path"])), - true, true, false, - $previous_page->getPosition(), - $parent); // peut et DOIT être null si on est au 1er niveau - - // on a donné à la nouvelle entrée la même position qu'à la précédente, - // addChild l'ajoute à la fin du tableau "children" puis on trie - // 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){ - $parent = Director::$menu_data; - } - $parent->addChild($page); - $parent->reindexPositions(); - - $page->setPagePath(ltrim($parent->getPagePath() . '/' . $page->getEndOfPath(), '/')); - - // noeud "head" - $node = new Node( - 'head', - null, [], - 1, // position d'un head = 1 - null, // pas de parent - $page); - $node->useDefaultAttributes(); // fichiers CSS et JS - - $data = new NodeData([ - // pas de titre, il est dans $page - 'description' => trim(htmlspecialchars($_POST["page_description"]))], - $node); - - $bulk_data = $entityManager - ->createQuery('SELECT n FROM App\Entity\Image n WHERE n.file_name LIKE :name') - ->setParameter('name', '%favicon%') - ->getResult(); - $data->setImages(new ArrayCollection($bulk_data)); - - $entityManager->persist($page); - $entityManager->persist($node); - $entityManager->persist($data); - $entityManager->flush(); - - // page créée, direction la page en mode modification pour ajouter des blocs - header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); - die; -} - -function deletePage(EntityManager $entityManager): void -{ - $page = $entityManager->find('App\Entity\Page', (int)$_POST['page_id']); - $nodes = $entityManager->getRepository('App\Entity\Node')->findBy(['page' => $page]); - $data = []; - foreach($nodes as $node){ - $data[] = $entityManager->getRepository('App\Entity\NodeData')->findOneBy(['node' => $node]); - $entityManager->remove($node); - } - foreach($data as $one_data){ - $entityManager->remove($one_data); - } - $entityManager->remove($page); // suppression en BDD - - $entityManager->flush(); - header("Location: " . new URL); - die; -} - -function pageMenuPathUpdate(EntityManager $entityManager): void -{ - $director = new Director($entityManager, true); - $page = Director::$page_path->getLast(); - $path = htmlspecialchars($_POST['page_menu_path']); - - // mise en snake_case: filtre caractères non-alphanumériques, minuscule, doublons d'underscore, trim des underscores - $path = trim(preg_replace('/_+/', '_', strtolower(preg_replace('/[^a-zA-Z0-9]/', '_', $path))), '_'); - $page->setEndOfPath($path); - foreach(Director::$menu_data->getChildren() as $child){ - if($child->getEndOfPath() === Director::$page_path->getArray()[0]->getEndOfPath()){ - $child->fillChildrenPagePath(); // MAJ de $page_path - } - } - $entityManager->flush(); - header("Location: " . new URL(['page' => $page->getPagePath(), 'action' => 'modif_page'])); - die; -} - -function addBloc(EntityManager $entityManager): void -{ - $director = new Director($entityManager, true); // on a besoin de page_path qui dépend de menu_data - $page = Director::$page_path->getLast(); - $director->findUniqueNodeByName('main'); - $director->findItsChildren(); - $main = $director->getNode(); - $position = count($main->getChildren()) + 1; // position dans la fraterie - - $blocks = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php - if(!in_array($_POST["bloc_select"], $blocks, true)) // 3è param: contrôle du type - { - header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); - die; - } - - if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ - $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page - $bulk_data = $entityManager - ->createQuery($dql) - ->setParameter('page', $page) - ->setParameter('name', 'head') - ->getResult(); - - if(count($bulk_data) != 1){ // 1 head par page - header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'head_node_not_found'])); - die; - } - - $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); - if($_POST["bloc_select"] === 'form'){ - $bulk_data[0]->addAttribute('js_array', $_POST["bloc_select"]); - } - $entityManager->persist($bulk_data[0]); - } - - $bloc = new Node( - $_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'])); - die; -} - -function deleteBloc(EntityManager $entityManager): void -{ - $director = new Director($entityManager, true); - $director->findUniqueNodeByName('main'); - $director->findItsChildren(); - //$director->findNodeById((int)$_POST['delete_bloc_id']); - $main = $director->getNode(); - $bloc = null; - foreach($main->getChildren() as $child){ - if($child->getId() === (int)$_POST['delete_bloc_id']){ - $bloc = $child; - break; - } - } - if(!empty($bloc)){ // si $bloc est null c'est que le HTML a été modifié volontairement - $main->removeChild($bloc); // réindex le tableau $children au passage - $main->reindexPositions(); - $entityManager->remove($bloc); // suppression en BDD - $entityManager->flush(); - } - header("Location: " . new URL(['page' => $_GET['page'], 'action' => 'modif_page'])); - die; -} - -function newUrlMenuEntry(EntityManager $entityManager): void -{ - 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( - trim(htmlspecialchars($_POST["label_input"])), - filter_var($_POST["url_input"], FILTER_VALIDATE_URL), - true, true, false, - $previous_page->getPosition(), - $parent); // peut et DOIT être null si on est au 1er niveau - - // on a donné à la nouvelle entrée la même position qu'à la précédente, - // addChild l'ajoute à la fin du tableau "children" puis on trie - // 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){ - $parent = Director::$menu_data; - } - $parent->addChild($page); // true pour réindexer les positions en BDD - $parent->reindexPositions(); - - $entityManager->persist($page); - $entityManager->flush(); - header("Location: " . new URL(['page' => $_GET['from']])); - die; -} - -function deleteUrlMenuEntry(EntityManager $entityManager): void -{ - Director::$menu_data = new Menu($entityManager); - $page = Director::$menu_data->findPageById((int)$_POST["delete"]); - $parent = $page->getParent(); - if($parent == null){ - $parent = Director::$menu_data; - } - - $parent->removeChild($page); // suppression de $children avant de trier - $parent->reindexPositions(); - - $entityManager->remove($page); // suppression en BDD - $entityManager->flush(); - header("Location: " . new URL(['page' => $_GET['from']])); - die; -} \ No newline at end of file diff --git a/src/controller/post_router.php b/src/controller/post_router.php deleted file mode 100644 index e71852a..0000000 --- a/src/controller/post_router.php +++ /dev/null @@ -1,120 +0,0 @@ - 'paramètres inconnus'])); - die; - } - } - - /* -- requêtes AJAX -- */ - else{ - require '../src/controller/ajax_admin.php'; - require '../src/controller/ajax_calendar_admin.php'; - } - } -} -// cas particulier d'un GET ajax non-admin par fullcalendar -elseif($_SERVER['REQUEST_METHOD'] === 'GET'){ - // non-admin - require '../src/controller/ajax_calendar_visitor.php'; - - if($_SESSION['admin'] === true){ - // ... - } -} \ No newline at end of file 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 @@ +: position = nombre d'éléments de la fraterie + 1, l'élément précédent devient le parent + if($_GET['menu_edit'] === 'move_one_level_down' && isset($json['id'])){ + MenuAndPathsController::MoveOneLevelDown($entityManager, $json); + } + + if($_GET['menu_edit'] === 'switch_positions' && isset($json['id1']) && isset($json['id2'])){ + MenuAndPathsController::switchPositions($entityManager, $json); + } + + if($_GET['menu_edit'] === 'displayInMenu' && isset($json['id']) && isset($json['checked'])){ + MenuAndPathsController::displayInMenu($entityManager, $json); + } + } + + /* -- mode Modification d'une page -- */ + // partie "page" + elseif(isset($_GET['page_edit'])) + { + // titre de la page + if($_GET['page_edit'] === 'page_title'){ + PageManagementController::setPageTitle($entityManager, $json); + } + // description dans les métadonnées + elseif($_GET['page_edit'] === 'page_description'){ + PageManagementController::setPageDescription($entityManager, $json); + } + } + + // partie "blocs" + elseif(isset($_GET['bloc_edit'])) + { + // renommage d'un bloc + if($_GET['bloc_edit'] === 'rename_page_bloc') + { + PageManagementController::renameBloc($entityManager, $json); + } + // inversion des positions de deux blocs + elseif($_GET['bloc_edit'] === 'switch_blocs_positions') + { + PageManagementController::SwitchBlocsPositions($entityManager, $json); + } + } + + /* -- upload d'image dans tinymce par copier-coller -- */ + // collage de HTML contenant une ou plusieurs balises + if(isset($_GET['action']) && $_GET['action'] == 'upload_image_html'){ + ImageUploadController::uploadImageHtml(); + } + // collage d'une image (code base64 dans le presse-papier) non encapsulée dans du HTML + elseif(isset($_GET['action']) && $_GET['action'] == 'upload_image_base64'){ + ImageUploadController::uploadImageBase64(); + } + + /* -- requêtes spécifiques au calendrier -- */ + if($_GET['action'] === 'new_event'){ + CalendarController::newEvent($json, $entityManager); + } + elseif($_GET['action'] === 'update_event'){ + CalendarController::updateEvent($json, $entityManager); + } + elseif($_GET['action'] === 'remove_event'){ + CalendarController::removeEvent($json, $entityManager); + } + else{ + echo json_encode(['success' => false]); + } + die; + } + + // upload d'image dans tinymce avec le plugin (bouton "insérer une image" de l'éditeur) + elseif(strpos($_SERVER['CONTENT_TYPE'], 'multipart/form-data') !== false && isset($_GET['action']) && $_GET['action'] === 'upload_image') + { + ImageUploadController::imageUploadTinyMce(); + } + // requêtes XMLHttpRequest + elseif(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') + { + //echo "requête XMLHttpRequest reçue par le serveur"; + echo json_encode(['success' => false]); // ça marche mais ça marche pas... + die; + } + + /* -- envoi d'un formulaire HTML -- */ + elseif($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') + { + /* -- nouvelle page -- */ + if(isset($_POST['page_name']) && $_POST['page_name'] !== null + && isset($_POST['page_name_path']) && $_POST['page_name_path'] !== null + && isset($_POST['page_location']) && $_POST['page_location'] !== null + && isset($_POST['page_description']) && $_POST['page_description'] !== null + && isset($_POST['new_page_hidden']) && $_POST['new_page_hidden'] === '') + { + PageManagementController::newPage($entityManager); + } + + /* -- suppression d'une page -- */ + elseif(isset($_POST['page_id']) && $_POST['page_id'] !== null + && isset($_POST['submit_hidden']) && $_POST['submit_hidden'] === '') + { + PageManagementController::deletePage($entityManager); + } + + /* -- mode Modification d'une page -- */ + + // modification du chemins en snake_case + elseif(isset($_POST['page_menu_path']) && $_POST['page_menu_path'] !== null + && isset($_POST['page_id']) && $_POST['page_id'] !== null + && isset($_POST['page_name_path_hidden']) && $_POST['page_name_path_hidden'] === '') + { + PageManagementController::updatePageMenuPath($entityManager); + } + // ajout d'un bloc dans une page + elseif(isset($_POST['bloc_title']) && $_POST['bloc_title'] !== null + && isset($_POST['bloc_select']) && $_POST['bloc_select'] !== null + && isset($_POST['bloc_title_hidden']) && $_POST['bloc_title_hidden'] === '') // contrôle anti-robot avec input hidden + { + PageManagementController::addBloc($entityManager); + } + // suppression d'un bloc de page + elseif(isset($_POST['delete_bloc_id']) && $_POST['delete_bloc_id'] !== null + && isset($_POST['delete_bloc_hidden']) && $_POST['delete_bloc_hidden'] === '') // contrôle anti-robot avec input hidden + { + PageManagementController::deleteBloc($entityManager); + } + + + /* -- 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"])){ + MenuAndPathsController::newUrlMenuEntry($entityManager); + } + // suppression d'une entrée de menu avec une URL + 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 + MenuAndPathsController::deleteUrlMenuEntry($entityManager); + } + + // redirection page d'accueil + else{ + header("Location: " . new URL(['error' => 'paramètres inconnus'])); + die; + } + } + } +} + +// cas particulier d'un GET ajax non-admin par fullcalendar +elseif($_SERVER['REQUEST_METHOD'] === 'GET'){ + /* -- non-admin -- */ + // chargement des évènements à la création du calendrier + // et au changement de dates affichées (boutons flèches mais pas changement de vue) + if($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['action']) && $_GET['action'] === 'get_events' + && isset($_GET['start']) && isset($_GET['end']) && empty($_POST)) + { + CalendarController::getData($entityManager); + } + + if($_SESSION['admin'] === true){ + // ... + } +} \ No newline at end of file diff --git a/src/model/EventDTO.php b/src/model/EventDTO.php index 70013dd..6dd3722 100644 --- a/src/model/EventDTO.php +++ b/src/model/EventDTO.php @@ -2,7 +2,7 @@ // src/model/EventDTO.php // // classe de données JSONifiable compatible avec fullcalendar -// servira aussi pour l'import/export de fichiers .ics +// servira éventuellement pour l'import/export de fichiers .ics declare(strict_types=1); -- cgit v1.2.3