summaryrefslogtreecommitdiff
path: root/src/view
diff options
context:
space:
mode:
Diffstat (limited to 'src/view')
-rw-r--r--src/view/FormBuilder.php51
-rw-r--r--src/view/MainBuilder.php25
-rw-r--r--src/view/templates/form.php32
3 files changed, 101 insertions, 7 deletions
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
4declare(strict_types=1);
5
6use App\Entity\Node;
7
8class 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