diff options
Diffstat (limited to 'src/view')
-rw-r--r-- | src/view/FormBuilder.php | 53 | ||||
-rw-r--r-- | src/view/templates/form.php | 16 | ||||
-rw-r--r-- | src/view/templates/form_params.php | 50 | ||||
-rw-r--r-- | src/view/templates/user_edit.php | 4 |
4 files changed, 85 insertions, 38 deletions
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php index 7a2adcb..cb438b9 100644 --- a/src/view/FormBuilder.php +++ b/src/view/FormBuilder.php | |||
@@ -7,41 +7,38 @@ use App\Entity\Node; | |||
7 | 7 | ||
8 | class FormBuilder extends AbstractBuilder | 8 | class FormBuilder extends AbstractBuilder |
9 | { | 9 | { |
10 | static private ?Captcha $captcha = null; | ||
11 | |||
10 | public function __construct(Node $node) | 12 | public function __construct(Node $node) |
11 | { | 13 | { |
12 | parent::__construct($node); | 14 | parent::__construct($node); |
13 | $viewFile = self::VIEWS_PATH . $node->getName() . '.php'; | ||
14 | 15 | ||
15 | if(file_exists($viewFile)) | 16 | if(!empty($node->getNodeData()->getData())) |
16 | { | 17 | { |
17 | if(!empty($node->getNodeData()->getData())) | 18 | extract($node->getNodeData()->getData()); |
18 | { | 19 | } |
19 | extract($node->getNodeData()->getData()); | 20 | |
20 | } | 21 | // un seul captcha à la fois! |
21 | 22 | if(!self::$captcha){ | |
22 | $captcha = new Captcha; | 23 | self::$captcha = new Captcha; |
23 | $_SESSION['captcha'] = $captcha->getSolution(); | 24 | $_SESSION['captcha'] = self::$captcha->getSolution(); |
24 | 25 | } | |
25 | $email = $email ?? Config::$email_dest; | ||
26 | |||
27 | $admin_content = ''; | ||
28 | if($_SESSION['admin']) | ||
29 | { | ||
30 | $admin_content = '<div class="admin_form"> | ||
31 | <p> | ||
32 | <label for="recipient">E-mail de destination de ce formulaire</label> | ||
33 | <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '"> | ||
34 | <input type="hidden" id="recipient_hidden" value=""> | ||
35 | <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button> | ||
36 | </p> | ||
37 | <p><button onclick="sendTestEmail(' . $node->getNodeData()->getId() . ')">Envoi d\'un e-mail de test</button></p> | ||
38 | <p class="test_email_success full_width_column"></p> | ||
39 | </div>' . "\n"; | ||
40 | } | ||
41 | 26 | ||
27 | $smtp_host = $smtp_host ?? Config::$smtp_host; | ||
28 | $smtp_secure = $smtp_secure ?? Config::$smtp_secure; | ||
29 | $smtp_username = $smtp_username ?? Config::$smtp_username; | ||
30 | $email_dest = $email_dest ?? Config::$email_dest; | ||
31 | |||
32 | $admin_content = ''; | ||
33 | if($_SESSION['admin']) | ||
34 | { | ||
42 | ob_start(); | 35 | ob_start(); |
43 | require $viewFile; | 36 | require self::VIEWS_PATH . 'form_params.php'; |
44 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | 37 | $admin_content = ob_get_clean(); |
45 | } | 38 | } |
39 | |||
40 | ob_start(); | ||
41 | require self::VIEWS_PATH . $node->getName() . '.php'; | ||
42 | $this->html = ob_get_clean(); // pas de concaténation ici, on écrase | ||
46 | } | 43 | } |
47 | } \ No newline at end of file | 44 | } \ No newline at end of file |
diff --git a/src/view/templates/form.php b/src/view/templates/form.php index 25446c1..5c959a0 100644 --- a/src/view/templates/form.php +++ b/src/view/templates/form.php | |||
@@ -1,33 +1,33 @@ | |||
1 | <?php declare(strict_types=1); ?> | 1 | <?php declare(strict_types=1); ?> |
2 | <section class="form" id="<?= $this->id_node ?>"> | 2 | <section class="form" id="<?= $this->id_node ?>"> |
3 | <?= $admin_content ?> | ||
4 | <h3><?= $title ?></h3> | 3 | <h3><?= $title ?></h3> |
4 | <?= $admin_content ?> | ||
5 | <div class="form_inputs"> | 5 | <div class="form_inputs"> |
6 | <label for="email_name">Votre nom</label> | 6 | <label for="email_name">Votre nom</label> |
7 | <input id="email_name" type="text" name="email_name" value=""> | 7 | <input id="email_name_<?= $node->getNodeData()->getId() ?>" type="text" name="email_name" value=""> |
8 | 8 | ||
9 | <label for="email_address">Votre e-mail</label> | 9 | <label for="email_address">Votre e-mail</label> |
10 | <input id="email_address" type="email" name="email_address" placeholder="mon-adresse@email.fr" value="" onchange="checkCase()"> | 10 | <input id="email_address_<?= $node->getNodeData()->getId() ?>" type="email" name="email_address" placeholder="mon-adresse@email.fr" value="" onchange="checkCase()"> |
11 | 11 | ||
12 | <label for="email_message">Votre message</label> | 12 | <label for="email_message">Votre message</label> |
13 | <textarea id="email_message" type="text" name="email_message" rows="4"></textarea> | 13 | <textarea id="email_message_<?= $node->getNodeData()->getId() ?>" type="text" name="email_message" rows="4"></textarea> |
14 | 14 | ||
15 | <div class="full_width_column"> | 15 | <div class="full_width_column"> |
16 | <label for="captcha" >Montrez que vous n'êtes pas un robot</label> | 16 | <label for="captcha" >Montrez que vous n'êtes pas un robot</label> |
17 | </div> | 17 | </div> |
18 | 18 | ||
19 | <label for="email_captcha" >Combien font <?= $captcha->getA() ?> fois <?= $captcha->getB() ?>?</label> | 19 | <label for="email_captcha" >Combien font <?= self::$captcha->getA() ?> fois <?= self::$captcha->getB() ?>?</label> |
20 | <div> | 20 | <div> |
21 | <input id="email_captcha" type="text" name="email_captcha" size="1" autocomplete="off"> | 21 | <input id="email_captcha_<?= $node->getNodeData()->getId() ?>" type="text" name="email_captcha" size="1" autocomplete="off"> |
22 | </div> | 22 | </div> |
23 | 23 | ||
24 | <input id="form_id_hidden" type="hidden" name="form_id_hidden" value=""> | 24 | <input id="form_id_hidden" type="hidden" name="form_id_hidden" value=""> |
25 | <input id="email_hidden" type="hidden" name="email_hidden"> | 25 | <input id="email_hidden_<?= $node->getNodeData()->getId() ?>" type="hidden" name="email_hidden"> |
26 | 26 | ||
27 | <div class="full_width_column"> | 27 | <div class="full_width_column"> |
28 | <input type="submit" value="Envoyez votre message" onclick="sendVisitorEmail(<?= $node->getNodeData()->getId() ?>)"> | 28 | <input type="submit" value="Envoyez votre message" onclick="sendVisitorEmail(<?= $node->getNodeData()->getId() ?>)"> |
29 | </div> | 29 | </div> |
30 | 30 | ||
31 | <p class="send_email_success full_width_column"></p> | 31 | <p class="send_email_success_<?= $node->getNodeData()->getId() ?> full_width_column"></p> |
32 | </div> | 32 | </div> |
33 | </section> \ No newline at end of file | 33 | </section> \ No newline at end of file |
diff --git a/src/view/templates/form_params.php b/src/view/templates/form_params.php new file mode 100644 index 0000000..a7bf1d8 --- /dev/null +++ b/src/view/templates/form_params.php | |||
@@ -0,0 +1,50 @@ | |||
1 | <?php | ||
2 | // src/view/templates/form_params.php | ||
3 | declare(strict_types=1); | ||
4 | // note: l'id ici n'est pas celui du noeud bloc mais celui de l'entrée dans node_data correspondante | ||
5 | ?> | ||
6 | <div class="admin_form"> | ||
7 | <h3>Paramètres d'envoi</h3> | ||
8 | <p> | ||
9 | <label for="smtp_host_<?= $node->getNodeData()->getId() ?>">Adresse serveur SMTP</label> | ||
10 | <input id="smtp_host_<?= $node->getNodeData()->getId() ?>" type="text" name="smtp_host" placeholder="smtp.messagerie.fr" value="<?= htmlspecialchars($smtp_host) ?>"> | ||
11 | <input type="hidden" id="smtp_host_hidden_<?= $node->getNodeData()->getId() ?>" value=""> | ||
12 | <button onclick="setEmailParam('smtp_host', <?= $node->getNodeData()->getId() ?>)">Valider</button> | ||
13 | </p> | ||
14 | <p> | ||
15 | <label for="smtp_secure_<?= $node->getNodeData()->getId() ?>">Chiffrement</label> | ||
16 | <select id="smtp_secure_<?= $node->getNodeData()->getId() ?>" name="smtp_secure" onchange="setEmailParam('smtp_secure', <?= $node->getNodeData()->getId() ?>)"> | ||
17 | <option value="plain_text" >Aucun (port 25)</option> | ||
18 | <option value="tls" <?php echo htmlspecialchars($smtp_secure) === 'tls' ? 'selected' : '' ?>>StartTLS (port 587)</option> | ||
19 | <option value="ssl" <?php echo htmlspecialchars($smtp_secure) === 'ssl' ? 'selected' : '' ?>>SSL (port 465)</option> | ||
20 | </select> | ||
21 | <input type="hidden" id="smtp_secure_hidden_<?= $node->getNodeData()->getId() ?>" value=""> | ||
22 | </p> | ||
23 | <p> | ||
24 | <label for="smtp_username_<?= $node->getNodeData()->getId() ?>">Identifiant (adresse e-mail)</label> | ||
25 | <input id="smtp_username_<?= $node->getNodeData()->getId() ?>" type="email" name="smtp_username" placeholder="mon-adresse@email.fr" value="<?= htmlspecialchars($smtp_username) ?>"> | ||
26 | <input type="hidden" id="smtp_username_hidden_<?= $node->getNodeData()->getId() ?>" value=""> | ||
27 | <button onclick="setEmailParam('smtp_username', <?= $node->getNodeData()->getId() ?>)">Valider</button> | ||
28 | </p> | ||
29 | <p> | ||
30 | <label for="smtp_password_<?= $node->getNodeData()->getId() ?>">Mot de passe</label> | ||
31 | <input id="smtp_password_<?= $node->getNodeData()->getId() ?>" type="password" name="smtp_password"> | ||
32 | <input type="hidden" id="smtp_password_hidden_<?= $node->getNodeData()->getId() ?>" value=""> | ||
33 | <button onclick="setEmailParam('smtp_password', <?= $node->getNodeData()->getId() ?>)">Valider</button> | ||
34 | </p> | ||
35 | <p><i>Il s'agit du service qui acheminera les messages envoyés par ce formulaire. Les services d'envoi de courriels nécéssitent généralement de s'y connecter avec un identifiant et un mot de passe. Les adresses d'envoi et de réception peuvent être identiques. Le site web peut ne pas réussir à se connecter à certains fournisseurs.</i></p> | ||
36 | </div> | ||
37 | <div class="admin_form"> | ||
38 | <p><button onclick="sendTestEmail(<?= $node->getNodeData()->getId() ?>)">Envoi d'un e-mail de test</button></p> | ||
39 | <p><i>Vérifie la connexion au serveur d'envoi. Pour tester la réception, consultez vos e-mails à l'adresse de réception.</i></p> | ||
40 | <p class="test_email_success_<?= $node->getNodeData()->getId() ?> full_width_column"></p> | ||
41 | </div> | ||
42 | <div class="admin_form"> | ||
43 | <h3>Paramètres de réception</h3> | ||
44 | <p> | ||
45 | <label for="email_dest_<?= $node->getNodeData()->getId() ?>">Adresse e-mail</label> | ||
46 | <input id="email_dest_<?= $node->getNodeData()->getId() ?>" type="email" name="email_dest" placeholder="mon-adresse@email.fr" value="<?= htmlspecialchars($email_dest) ?>"> | ||
47 | <input type="hidden" id="email_dest_hidden_<?= $node->getNodeData()->getId() ?>" value=""> | ||
48 | <button onclick="setEmailParam('email_dest', <?= $node->getNodeData()->getId() ?>)">Valider</button> | ||
49 | </p> | ||
50 | </div> \ No newline at end of file | ||
diff --git a/src/view/templates/user_edit.php b/src/view/templates/user_edit.php index 77cd9f2..18eb037 100644 --- a/src/view/templates/user_edit.php +++ b/src/view/templates/user_edit.php | |||
@@ -10,7 +10,7 @@ | |||
10 | </div> | 10 | </div> |
11 | <div class="user_edit_flex"> | 11 | <div class="user_edit_flex"> |
12 | <div class="login_form"> | 12 | <div class="login_form"> |
13 | <p class="connexionP" >Modifier mon nom d'utilisateur.</p> | 13 | <p class="connexionP" >Modifier mon <b>nom d'utilisateur</b>.</p> |
14 | <p style="color: red; font-style: italic;"><?= $error_username ?></p> | 14 | <p style="color: red; font-style: italic;"><?= $error_username ?></p> |
15 | <p style="color: green; font-style: italic;"><?= $success_username ?></p> | 15 | <p style="color: green; font-style: italic;"><?= $success_username ?></p> |
16 | <form class="connexionFormulaire" method="post" action="<?= $link_user_form ?>" > | 16 | <form class="connexionFormulaire" method="post" action="<?= $link_user_form ?>" > |
@@ -31,7 +31,7 @@ | |||
31 | </form> | 31 | </form> |
32 | </div> | 32 | </div> |
33 | <div class="login_form"> | 33 | <div class="login_form"> |
34 | <p class="connexionP" >Modifier mon mot de passe.</p> | 34 | <p class="connexionP" >Modifier mon <b>mot de passe</b>.</p> |
35 | <p style="color: red; font-style: italic;"><?= $error_password ?></p> | 35 | <p style="color: red; font-style: italic;"><?= $error_password ?></p> |
36 | <p style="color: green; font-style: italic;"><?= $success_password ?></p> | 36 | <p style="color: green; font-style: italic;"><?= $success_password ?></p> |
37 | <form class="connexionFormulaire" method="post" action="<?= $link_password_form ?>" > | 37 | <form class="connexionFormulaire" method="post" action="<?= $link_password_form ?>" > |