diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/controller/post.php | 8 | ||||
| -rw-r--r-- | src/model/EventDTO.php | 2 | ||||
| -rw-r--r-- | src/view/FormBuilder.php | 51 | ||||
| -rw-r--r-- | src/view/MainBuilder.php | 25 | ||||
| -rw-r--r-- | src/view/templates/form.php | 32 |
5 files changed, 107 insertions, 11 deletions
diff --git a/src/controller/post.php b/src/controller/post.php index 7e6ed53..acad1ce 100644 --- a/src/controller/post.php +++ b/src/controller/post.php | |||
| @@ -132,14 +132,14 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 132 | $main = $director->getNode(); | 132 | $main = $director->getNode(); |
| 133 | $position = count($main->getChildren()) + 1; // position dans la fraterie | 133 | $position = count($main->getChildren()) + 1; // position dans la fraterie |
| 134 | 134 | ||
| 135 | $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php | 135 | $blocks = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans FormBuilder.php |
| 136 | if(!in_array($_POST["bloc_select"], $blocs_true_names, true)) // 3è param: contrôle du type | 136 | if(!in_array($_POST["bloc_select"], $blocks, true)) // 3è param: contrôle du type |
| 137 | { | 137 | { |
| 138 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); | 138 | header("Location: " . new URL(['page' => $_GET['page'], 'error' => 'bad_bloc_type'])); |
| 139 | die; | 139 | die; |
| 140 | } | 140 | } |
| 141 | 141 | ||
| 142 | if($_POST["bloc_select"] === 'calendar'){ | 142 | if($_POST["bloc_select"] === 'calendar' || $_POST["bloc_select"] === 'form'){ |
| 143 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page | 143 | $dql = 'SELECT n FROM App\Entity\Node n WHERE n.page = :page AND n.name_node = :name'; // noeud 'head' de la page |
| 144 | $bulk_data = $entityManager | 144 | $bulk_data = $entityManager |
| 145 | ->createQuery($dql) | 145 | ->createQuery($dql) |
| @@ -152,7 +152,7 @@ if($_SERVER['REQUEST_METHOD'] === 'POST' && $_SESSION['admin'] === true) | |||
| 152 | die; | 152 | die; |
| 153 | } | 153 | } |
| 154 | 154 | ||
| 155 | $bulk_data[0]->addAttribute('css_array', 'calendar'); | 155 | $bulk_data[0]->addAttribute('css_array', $_POST["bloc_select"]); |
| 156 | $entityManager->persist($bulk_data[0]); | 156 | $entityManager->persist($bulk_data[0]); |
| 157 | } | 157 | } |
| 158 | 158 | ||
diff --git a/src/model/EventDTO.php b/src/model/EventDTO.php index 8d33733..70013dd 100644 --- a/src/model/EventDTO.php +++ b/src/model/EventDTO.php | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | // classe de données JSONifiable compatible avec fullcalendar | 4 | // classe de données JSONifiable compatible avec fullcalendar |
| 5 | // servira aussi pour l'import/export de fichiers .ics | 5 | // servira aussi pour l'import/export de fichiers .ics |
| 6 | 6 | ||
| 7 | declare(strict_types=1); | ||
| 8 | |||
| 7 | use App\Entity\Event; | 9 | use App\Entity\Event; |
| 8 | 10 | ||
| 9 | class EventDTO | 11 | class EventDTO |
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php new file mode 100644 index 0000000..b3a96f3 --- /dev/null +++ b/src/view/FormBuilder.php | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | <?php | ||
| 2 | // src/view/FormBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Node; | ||
| 7 | |||
| 8 | class FormBuilder extends AbstractBuilder | ||
| 9 | { | ||
| 10 | public function __construct(Node $node) | ||
| 11 | { | ||
| 12 | parent::__construct($node); | ||
| 13 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
| 14 | |||
| 15 | if(file_exists($viewFile)) | ||
| 16 | { | ||
| 17 | if(!empty($node->getNodeData()->getData())) | ||
| 18 | { | ||
| 19 | extract($node->getNodeData()->getData()); | ||
| 20 | } | ||
| 21 | |||
| 22 | $action_url = new URL(['page' => CURRENT_PAGE]); | ||
| 23 | $captcha = new Captcha; | ||
| 24 | $_SESSION['captcha'] = $captcha->getSolution(); | ||
| 25 | |||
| 26 | $no_recipient_warning = ''; | ||
| 27 | $admin_content = ''; | ||
| 28 | if($_SESSION['admin']) | ||
| 29 | { | ||
| 30 | $admin_content = '<script src="js/form.js"></script> | ||
| 31 | <h3>Configuration du formulaire</h3> | ||
| 32 | <div class="admin_form"> | ||
| 33 | <label for="recipient">E-mail du destinataire</label> | ||
| 34 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value=""> | ||
| 35 | <button onclick="changeRecipient()">Valider</button> | ||
| 36 | </div>'; | ||
| 37 | } | ||
| 38 | |||
| 39 | $recipient_found = false; | ||
| 40 | // recherche BDD | ||
| 41 | |||
| 42 | if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée | ||
| 43 | $no_recipient_warning = '<p class="no_recipient_warning">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>'; | ||
| 44 | } | ||
| 45 | |||
| 46 | ob_start(); | ||
| 47 | require $viewFile; | ||
| 48 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | ||
| 49 | } | ||
| 50 | } | ||
| 51 | } \ No newline at end of file | ||
diff --git a/src/view/MainBuilder.php b/src/view/MainBuilder.php index a478412..4bd79c3 100644 --- a/src/view/MainBuilder.php +++ b/src/view/MainBuilder.php | |||
| @@ -54,13 +54,25 @@ class MainBuilder extends AbstractBuilder | |||
| 54 | { | 54 | { |
| 55 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement | 55 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; // mode modification uniquement |
| 56 | 56 | ||
| 57 | // blocs disponibles | 57 | // blocs disponibles, même liste dans post.php |
| 58 | $blocs = ['Blog', 'Grille', 'Calendrier', 'Galerie', 'Formulaire']; // générer ça dynamiquement! | 58 | $blocks = [ // créer une classe pour ça? |
| 59 | $blocs_true_names = ['blog', 'grid', 'calendar', 'galery', 'form']; // même liste dans post.php | 59 | ['type' => 'blog', 'name' => 'Blog'], |
| 60 | ['type' => 'grid', 'name' => 'Grille'], | ||
| 61 | ['type' => 'calendar', 'name' => 'Calendrier'], | ||
| 62 | ['type' => 'galery', 'name' => 'Galerie'], | ||
| 63 | ['type' => 'form', 'name' => 'Formulaire']]; | ||
| 64 | |||
| 65 | function getBlockName(array $blocks, string $type){ // créer une classe pour ça? | ||
| 66 | for($i=0; $i < count($blocks); $i++){ | ||
| 67 | if($blocks[$i]['type'] === $type){ | ||
| 68 | return $blocks[$i]['name']; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | } | ||
| 60 | 72 | ||
| 61 | $options = ''; | 73 | $options = ''; |
| 62 | for($i = 0; $i < count($blocs); $i++){ | 74 | for($i = 0; $i < count($blocks); $i++){ |
| 63 | $options .= '<option value= "' . $blocs_true_names[$i] . '">' . $blocs[$i] . "</option>\n"; | 75 | $options .= '<option value= "' . $blocks[$i]['type'] . '">' . $blocks[$i]['name'] . "</option>\n"; |
| 64 | } | 76 | } |
| 65 | 77 | ||
| 66 | // blabla | 78 | // blabla |
| @@ -85,8 +97,7 @@ class MainBuilder extends AbstractBuilder | |||
| 85 | foreach($node->getChildren() as $child_node){ | 97 | foreach($node->getChildren() as $child_node){ |
| 86 | // renommage d'un bloc | 98 | // renommage d'un bloc |
| 87 | $bloc_edit .= '<div id="bloc_edit_' . $child_node->getId() . '"> | 99 | $bloc_edit .= '<div id="bloc_edit_' . $child_node->getId() . '"> |
| 88 | <p><label>Type <i>' . $child_node->getName() . '</i>, </label> | 100 | <p><label for="bloc_rename_' . $child_node->getId() . '"><b>' . getBlockName($blocks, $child_node->getName()) . '</b></label> |
| 89 | <label for="bloc_rename_' . $child_node->getId() . '">Titre</label> | ||
| 90 | <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> | 101 | <input type="text" id="bloc_rename_' . $child_node->getId() . '" name="bloc_rename_title" value="' . $child_node->getNodeData()->getdata()['title'] . '" required> |
| 91 | <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; | 102 | <button onclick="renamePageBloc(' . $child_node->getId() . ')">Renommer</button>'. "\n"; |
| 92 | // déplacement d'un bloc | 103 | // déplacement d'un bloc |
diff --git a/src/view/templates/form.php b/src/view/templates/form.php new file mode 100644 index 0000000..97d53d4 --- /dev/null +++ b/src/view/templates/form.php | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | <?php declare(strict_types=1); ?> | ||
| 2 | <section class="form" id="<?= $this->id_node ?>"> | ||
| 3 | <?= $admin_content ?> | ||
| 4 | <h3><?= $title ?></h3> | ||
| 5 | <?= $no_recipient_warning ?> | ||
| 6 | <form method="post" action="<?= $action_url ?>"> | ||
| 7 | <label for="email">Adresse e-mail</label> | ||
| 8 | <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required> | ||
| 9 | |||
| 10 | <label for="subject">Objet</label> | ||
| 11 | <input type="text" name="subject" value="" required> | ||
| 12 | |||
| 13 | <label for="message">Votre message</label> | ||
| 14 | <textarea type="text" name="message" rows="4" required></textarea> | ||
| 15 | |||
| 16 | <div class="full_width_column"> | ||
| 17 | <label for="captcha" >Montrez que vous n'êtes pas un robot</label> | ||
| 18 | </div> | ||
| 19 | |||
| 20 | <label for="captcha" >Combien font <?= $captcha->getA() ?> fois <?= $captcha->getB() ?>?</label> | ||
| 21 | <div> | ||
| 22 | <input type="text" name="captcha" size="1" required> | ||
| 23 | </div> | ||
| 24 | |||
| 25 | <input type="hidden" name="form_id" value=""> | ||
| 26 | <input type="hidden" name="form_hidden"> | ||
| 27 | |||
| 28 | <div class="full_width_column"> | ||
| 29 | <input type="submit" value="Envoyez votre message"> | ||
| 30 | </div> | ||
| 31 | </form> | ||
| 32 | </section> \ No newline at end of file | ||
