diff options
author | polo <ordipolo@gmx.fr> | 2025-09-12 15:04:53 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2025-09-12 15:04:53 +0200 |
commit | de6a28c63d18a72baa044d9385ed3d15afb40ef0 (patch) | |
tree | 69d25cf3719e540fb23d79b1cbe536e755eb9907 | |
parent | efd79d15adef2a27347c25ebb19754e9937f9715 (diff) | |
download | cms-de6a28c63d18a72baa044d9385ed3d15afb40ef0.zip |
paramètres SMTP en mode admin, possibilité d'utiliser deux formulaires sur la même page
-rw-r--r-- | public/css/form.css | 13 | ||||
-rw-r--r-- | public/js/form.js | 34 | ||||
-rw-r--r-- | src/Captcha.php | 3 | ||||
-rw-r--r-- | src/EmailService.php | 37 | ||||
-rw-r--r-- | src/FormValidation.php | 33 | ||||
-rw-r--r-- | src/controller/ContactFormController.php | 33 | ||||
-rw-r--r-- | src/router.php | 4 | ||||
-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 |
11 files changed, 191 insertions, 89 deletions
diff --git a/public/css/form.css b/public/css/form.css index 5bfa768..c17662d 100644 --- a/public/css/form.css +++ b/public/css/form.css | |||
@@ -22,10 +22,19 @@ | |||
22 | 22 | ||
23 | .form .admin_form{ | 23 | .form .admin_form{ |
24 | background-color: #f0f0f0; | 24 | background-color: #f0f0f0; |
25 | margin: auto; | 25 | margin: 8px auto; |
26 | padding: 10px; | 26 | padding: 10px; |
27 | max-width: 800px; | 27 | max-width: 800px; |
28 | } | 28 | } |
29 | .form .admin_form h3{ | ||
30 | margin: 10px 0; | ||
31 | } | ||
32 | .form .admin_form p{ | ||
33 | margin: 5px 0; | ||
34 | } | ||
35 | .form .admin_form i{ | ||
36 | font-size: smaller; | ||
37 | } | ||
29 | 38 | ||
30 | @media screen and (max-width: 600px){ | 39 | @media screen and (max-width: 600px){ |
31 | .form_inputs{ | 40 | .form_inputs{ |
@@ -37,4 +46,4 @@ | |||
37 | .form .full_width_column { | 46 | .form .full_width_column { |
38 | grid-column: 1; | 47 | grid-column: 1; |
39 | } | 48 | } |
40 | } \ No newline at end of file | 49 | } |
diff --git a/public/js/form.js b/public/js/form.js index cf138e6..4be83c6 100644 --- a/public/js/form.js +++ b/public/js/form.js | |||
@@ -1,28 +1,30 @@ | |||
1 | //function sendMessage(){} | 1 | //function sendMessage(){} |
2 | 2 | ||
3 | // modif des paramètre d'envoi d'e-mail depuis l'espace admin | 3 | // modif des paramètres d'e-mail: e-mail source/dest, mot de passe, serveur smtp & chiffrement tls/ssl |
4 | function changeRecipient(id){ | 4 | function setEmailParam(what_param, id){ |
5 | const email = document.getElementById('recipient').value; | 5 | const value = document.getElementById(what_param + '_' + id).value; |
6 | const hidden = document.getElementById('recipient_hidden').value; | 6 | const hidden = document.getElementById(what_param + '_hidden_' + id).value; |
7 | 7 | ||
8 | fetch('index.php?action=recipient_email', { | 8 | fetch('index.php?action=set_email_param', { |
9 | method: 'POST', | 9 | method: 'POST', |
10 | headers: { | 10 | headers: { |
11 | 'Content-Type': 'application/json' | 11 | 'Content-Type': 'application/json' |
12 | }, | 12 | }, |
13 | body: JSON.stringify({ id: id, email: email, hidden: hidden }) | 13 | body: JSON.stringify({ id: id, what_param: what_param, value: value, hidden: hidden }) |
14 | }) | 14 | }) |
15 | .then(response => response.json()) | 15 | .then(response => response.json()) |
16 | .then(data => { | 16 | .then(data => { |
17 | if(data.success){ | 17 | if(data.success){ |
18 | toastNotify('Adresse e-mail de destination modifiée'); | 18 | toastNotify(what_param + ' a été modifié(e)'); |
19 | } | 19 | } |
20 | else{ | 20 | else{ |
21 | toastNotify('E-mail non valide'); | 21 | console.error("Erreur rencontrée à l'enregistrement de cette donnée en base de données"); |
22 | toastNotify("Erreur rencontrée à l'enregistrement de cette donnée en base de données"); | ||
22 | } | 23 | } |
23 | }) | 24 | }) |
24 | .catch(error => { | 25 | .catch(error => { |
25 | console.error('Erreur:', error); | 26 | console.error('Erreur:', error); |
27 | toastNotify('Erreur:', error); | ||
26 | }); | 28 | }); |
27 | } | 29 | } |
28 | 30 | ||
@@ -33,8 +35,8 @@ function checkCase(){ | |||
33 | } | 35 | } |
34 | 36 | ||
35 | function sendTestEmail(id){ | 37 | function sendTestEmail(id){ |
36 | const admin_form = document.querySelector('.admin_form'); | 38 | //const admin_form = document.querySelector('.admin_form'); |
37 | const test_email_success = document.querySelector('.test_email_success'); | 39 | const test_email_success = document.querySelector('.test_email_success_' + id); |
38 | test_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; | 40 | test_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; |
39 | test_email_success.style.backgroundColor = 'yellow'; | 41 | test_email_success.style.backgroundColor = 'yellow'; |
40 | 42 | ||
@@ -67,12 +69,12 @@ function sendTestEmail(id){ | |||
67 | } | 69 | } |
68 | 70 | ||
69 | function sendVisitorEmail(id){ | 71 | function sendVisitorEmail(id){ |
70 | const email_name = document.getElementById('email_name').value; | 72 | const email_name = document.getElementById('email_name_' + id).value; |
71 | const email_address = document.getElementById('email_address').value; | 73 | const email_address = document.getElementById('email_address_' + id).value; |
72 | const email_message = document.getElementById('email_message').value; | 74 | const email_message = document.getElementById('email_message_' + id).value; |
73 | const email_captcha = document.getElementById('email_captcha').value; | 75 | const email_captcha = document.getElementById('email_captcha_' + id).value; |
74 | const email_hidden = document.getElementById('email_hidden').value; | 76 | const email_hidden = document.getElementById('email_hidden_' + id).value; |
75 | const send_email_success = document.querySelector('.send_email_success'); | 77 | const send_email_success = document.querySelector('.send_email_success_' + id); |
76 | 78 | ||
77 | if(email_name === '' || email_address === '' || email_message === '' || email_captcha === ''){ | 79 | if(email_name === '' || email_address === '' || email_message === '' || email_captcha === ''){ |
78 | toastNotify('Veuillez remplir tous les champs.'); | 80 | toastNotify('Veuillez remplir tous les champs.'); |
diff --git a/src/Captcha.php b/src/Captcha.php index c60a186..f60031a 100644 --- a/src/Captcha.php +++ b/src/Captcha.php | |||
@@ -1,5 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | // src/Captcha.php | 2 | // src/Captcha.php |
3 | // | ||
4 | // la solution est stockée dans une unique variable $_SESSION['captcha'] | ||
5 | // => on pourrait appliquer le pattern "singleton" (justification = le captcha devient une sorte de ressource partagée) | ||
3 | 6 | ||
4 | declare(strict_types=1); | 7 | declare(strict_types=1); |
5 | 8 | ||
diff --git a/src/EmailService.php b/src/EmailService.php index c1f74d1..a9abc85 100644 --- a/src/EmailService.php +++ b/src/EmailService.php | |||
@@ -5,27 +5,34 @@ declare(strict_types=1); | |||
5 | 5 | ||
6 | use PHPMailer\PHPMailer\PHPMailer; | 6 | use PHPMailer\PHPMailer\PHPMailer; |
7 | //use PHPMailer\PHPMailer\Exception; | 7 | //use PHPMailer\PHPMailer\Exception; |
8 | use App\Entity\Email; | ||
9 | use Doctrine\ORM\EntityManager; | 8 | use Doctrine\ORM\EntityManager; |
9 | use App\Entity\Email; | ||
10 | use App\Entity\NodeData; | ||
10 | 11 | ||
11 | class EmailService | 12 | class EmailService |
12 | { | 13 | { |
13 | static public function send(EntityManager $entityManager, string $recipient, bool $true_email, string $name = '', string $email = '', string $message = ''): bool | 14 | static public function send(EntityManager $entityManager, NodeData $form_data, bool $test_email, string $name = '', string $email = '', string $message = ''): bool |
14 | { | 15 | { |
15 | $mail = new PHPMailer(true); // true => exceptions | 16 | $mail = new PHPMailer(true); // true => exceptions |
16 | $mail->CharSet = 'UTF-8'; | 17 | $mail->CharSet = 'UTF-8'; |
17 | 18 | ||
19 | $smtp_host = $form_data->getData()['smtp_host'] ?? Config::$smtp_host; | ||
20 | $smtp_secure = $form_data->getData()['smtp_secure'] ?? Config::$smtp_secure; | ||
21 | $smtp_username = $form_data->getData()['smtp_username'] ?? Config::$smtp_username; | ||
22 | $smtp_password = $form_data->getData()['smtp_password'] ?? Config::$smtp_password; | ||
23 | $email_dest = $form_data->getData()['email_dest'] ?? Config::$email_dest; | ||
24 | |||
18 | try{ | 25 | try{ |
19 | // Paramètres du serveur | 26 | // Paramètres du serveur |
20 | $mail->isSMTP(); | 27 | $mail->isSMTP(); |
21 | $mail->Host = Config::$smtp_host; | 28 | $mail->Host = $smtp_host; |
22 | $mail->SMTPAuth = true; | 29 | $mail->SMTPAuth = true; |
23 | $mail->Port = 25; | 30 | $mail->Port = 25; |
24 | 31 | ||
25 | if($mail->SMTPAuth){ | 32 | if($mail->SMTPAuth){ |
26 | $mail->Username = Config::$smtp_username; // e-mail | 33 | $mail->Username = $smtp_username; // e-mail |
27 | $mail->Password = Config::$smtp_password; | 34 | $mail->Password = $smtp_password; |
28 | $mail->SMTPSecure = Config::$smtp_secure; // tls (starttls) ou ssl (smtps) | 35 | $mail->SMTPSecure = $smtp_secure; // tls (starttls) ou ssl (smtps) |
29 | if($mail->SMTPSecure === 'tls'){ | 36 | if($mail->SMTPSecure === 'tls'){ |
30 | $mail->Port = 587; | 37 | $mail->Port = 587; |
31 | } | 38 | } |
@@ -36,16 +43,16 @@ class EmailService | |||
36 | //var_dump($mail->smtpConnect());die; // test de connexion | 43 | //var_dump($mail->smtpConnect());die; // test de connexion |
37 | 44 | ||
38 | // Expéditeur et destinataire | 45 | // Expéditeur et destinataire |
39 | $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur | 46 | $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // paramètre modifiable uniquement dans le config.ini pour l'instant |
40 | $mail->addAddress(strtolower($recipient), Config::$email_dest_name); // destinataire | 47 | $mail->addAddress(strtolower($email_dest), Config::$email_dest_name); // // paramètre modifiable uniquement dans le config.ini pour l'instant |
41 | 48 | ||
42 | // Contenu | 49 | // Contenu |
43 | $mail->isHTML(true); | 50 | $mail->isHTML(true); |
44 | if($true_email){ | 51 | if($test_email){ |
45 | $mail->Subject = 'Message envoyé par: ' . $name . ' (' . $email . ') depuis le site web'; | 52 | $mail->Subject = "TEST d'un envoi d'e-mail depuis le site web"; |
46 | } | 53 | } |
47 | else{ | 54 | else{ |
48 | $mail->Subject = "TEST d'un envoi d'e-mail depuis le site web"; | 55 | $mail->Subject = 'Message envoyé par: ' . $name . ' (' . $email . ') depuis le site web'; |
49 | } | 56 | } |
50 | $mail->Body = $message; | 57 | $mail->Body = $message; |
51 | $mail->AltBody = $message; | 58 | $mail->AltBody = $message; |
@@ -53,9 +60,11 @@ class EmailService | |||
53 | $mail->send(); | 60 | $mail->send(); |
54 | 61 | ||
55 | // copie en BDD | 62 | // copie en BDD |
56 | $db_email = new Email($email, Config::$email_dest, $message); | 63 | if(!$test_email){ |
57 | $entityManager->persist($db_email); | 64 | $db_email = new Email($email, Config::$email_dest, $message); |
58 | $entityManager->flush(); | 65 | $entityManager->persist($db_email); |
66 | $entityManager->flush(); | ||
67 | } | ||
59 | 68 | ||
60 | return true; | 69 | return true; |
61 | } | 70 | } |
diff --git a/src/FormValidation.php b/src/FormValidation.php index 743cd13..b3a3793 100644 --- a/src/FormValidation.php +++ b/src/FormValidation.php | |||
@@ -1,6 +1,8 @@ | |||
1 | <?php | 1 | <?php |
2 | // src/FormValidation.php | 2 | // src/FormValidation.php |
3 | 3 | ||
4 | declare(strict_types=1); | ||
5 | |||
4 | class FormValidation | 6 | class FormValidation |
5 | { | 7 | { |
6 | private array $data; // tableau associatif (probablement $_POST) | 8 | private array $data; // tableau associatif (probablement $_POST) |
@@ -19,9 +21,15 @@ class FormValidation | |||
19 | 21 | ||
20 | // pattern stratégie en une seule classe | 22 | // pattern stratégie en une seule classe |
21 | switch($this->validation_strategy){ | 23 | switch($this->validation_strategy){ |
22 | case 'email': | 24 | // bloc formulaire de contact |
25 | case 'email_send': | ||
23 | $this->emailStrategy(); | 26 | $this->emailStrategy(); |
24 | break; | 27 | break; |
28 | case 'email_params': // paramètrage en mode admin | ||
29 | $this->emailParamsStrategy(); | ||
30 | break; | ||
31 | |||
32 | // formulaires pages spéciales | ||
25 | case 'create_user': | 33 | case 'create_user': |
26 | $this->createUserStrategy(); | 34 | $this->createUserStrategy(); |
27 | break; | 35 | break; |
@@ -34,6 +42,7 @@ class FormValidation | |||
34 | case 'password_update': | 42 | case 'password_update': |
35 | $this->passwordUpdateStrategy(); | 43 | $this->passwordUpdateStrategy(); |
36 | break; | 44 | break; |
45 | |||
37 | default: | 46 | default: |
38 | http_response_code(500); // c'est un peu comme jeter une exception | 47 | http_response_code(500); // c'est un peu comme jeter une exception |
39 | echo json_encode(['success' => false, 'error' => 'server_error']); | 48 | echo json_encode(['success' => false, 'error' => 'server_error']); |
@@ -94,7 +103,7 @@ class FormValidation | |||
94 | $this->errors[] = 'missing_fields'; | 103 | $this->errors[] = 'missing_fields'; |
95 | } | 104 | } |
96 | 105 | ||
97 | if(!filter_var(trim($this->data['email']), FILTER_VALIDATE_EMAIL)){ | 106 | elseif(!filter_var(trim($this->data['email']), FILTER_VALIDATE_EMAIL)){ |
98 | $this->errors[] = 'bad_email_address'; | 107 | $this->errors[] = 'bad_email_address'; |
99 | } | 108 | } |
100 | 109 | ||
@@ -102,6 +111,26 @@ class FormValidation | |||
102 | $this->data['email'] = htmlspecialchars(trim($this->data['email'])); | 111 | $this->data['email'] = htmlspecialchars(trim($this->data['email'])); |
103 | $this->data['message'] = htmlspecialchars($this->data['message']); | 112 | $this->data['message'] = htmlspecialchars($this->data['message']); |
104 | } | 113 | } |
114 | private function emailParamsStrategy(): void | ||
115 | { | ||
116 | if(!isset($this->data['id'], $this->data['what_param'], $this->data['value'], $this->data['hidden']) | ||
117 | || !empty($this->data['hidden'])){ | ||
118 | $this->errors[] = 'missing_fields'; | ||
119 | } | ||
120 | |||
121 | elseif($this->data['value'] !== ''){ | ||
122 | if(!in_array($this->data['what_param'], ['smtp_host', 'smtp_secure', 'smtp_username', 'smtp_password', 'email_dest'])){ | ||
123 | $this->errors[] = 'unknown_parameter'; | ||
124 | } | ||
125 | elseif($this->data['what_param'] === 'smtp_username' || $this->data['what_param'] === 'email_dest'){ | ||
126 | if(!filter_var($this->data['value'], FILTER_VALIDATE_EMAIL)){ | ||
127 | $this->errors[] = 'invalide_email_address'; | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | // htmlspecialchars exécutés à l'affichage dans FormBuilder | ||
133 | } | ||
105 | private function createUserStrategy(): void | 134 | private function createUserStrategy(): void |
106 | { | 135 | { |
107 | $this->captchaValidate(); | 136 | $this->captchaValidate(); |
diff --git a/src/controller/ContactFormController.php b/src/controller/ContactFormController.php index dcea868..181e93c 100644 --- a/src/controller/ContactFormController.php +++ b/src/controller/ContactFormController.php | |||
@@ -7,29 +7,34 @@ use Doctrine\ORM\EntityManager; | |||
7 | 7 | ||
8 | class ContactFormController | 8 | class ContactFormController |
9 | { | 9 | { |
10 | static public function updateRecipient(EntityManager $entityManager, array $json): void | 10 | static public function setEmailParam(EntityManager $entityManager, array $json): void |
11 | { | 11 | { |
12 | $email = htmlspecialchars(trim($json['email'])); | 12 | $form = new FormValidation($json, 'email_params'); |
13 | 13 | ||
14 | if((filter_var($email, FILTER_VALIDATE_EMAIL) // nouvel e-mail | 14 | $error = ''; |
15 | || ($json['email'] === '' && !empty(Config::$email_dest))) // e-mail par défaut | 15 | if($form->validate()){ |
16 | && isset($json['hidden']) && empty($json['hidden'])) | ||
17 | { | ||
18 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); | 16 | $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); |
19 | $form_data->updateData('email', $email); | 17 | $form_data->updateData($json['what_param'], trim($json['value'])); |
20 | $entityManager->persist($form_data); | 18 | $entityManager->persist($form_data); |
21 | $entityManager->flush(); | 19 | $entityManager->flush(); |
20 | } | ||
21 | else{ | ||
22 | $error = $form->getErrors()[0]; // la 1ère erreur sera affichée | ||
23 | } | ||
22 | 24 | ||
25 | if(empty($error)){ | ||
23 | echo json_encode(['success' => true]); | 26 | echo json_encode(['success' => true]); |
24 | } | 27 | } |
25 | else{ | 28 | else{ |
26 | echo json_encode(['success' => false]); | 29 | echo json_encode(['success' => false, 'error' => $error]); |
27 | } | 30 | } |
28 | die; | 31 | die; |
29 | } | 32 | } |
33 | |||
34 | // les deux méthodes suivantes sont "factorisables", elles ne se distinguent que par la gestion ou non du formulaire rempli par le visiteur | ||
30 | static public function sendVisitorEmail(EntityManager $entityManager, array $json): void | 35 | static public function sendVisitorEmail(EntityManager $entityManager, array $json): void |
31 | { | 36 | { |
32 | $form = new FormValidation($json, 'email'); | 37 | $form = new FormValidation($json, 'email_send'); |
33 | 38 | ||
34 | $error = ''; | 39 | $error = ''; |
35 | if($form->validate()){ | 40 | if($form->validate()){ |
@@ -40,9 +45,8 @@ class ContactFormController | |||
40 | echo json_encode(['success' => false, 'error' => 'server_error']); | 45 | echo json_encode(['success' => false, 'error' => 'server_error']); |
41 | die; | 46 | die; |
42 | } | 47 | } |
43 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; | 48 | |
44 | 49 | if(!EmailService::send($entityManager, $form_data, false, $form->getField('name'), $form->getField('email'), $form->getField('message'))){ | |
45 | if(!EmailService::send($entityManager, $recipient, true, $form->getField('name'), $form->getField('email'), $form->getField('message'))){ | ||
46 | $error = 'email_not_sent'; | 50 | $error = 'email_not_sent'; |
47 | } | 51 | } |
48 | } | 52 | } |
@@ -67,9 +71,8 @@ class ContactFormController | |||
67 | echo json_encode(['success' => false, 'error' => 'server_error']); | 71 | echo json_encode(['success' => false, 'error' => 'server_error']); |
68 | die; | 72 | die; |
69 | } | 73 | } |
70 | $recipient = $form_data->getData()['email'] ?? Config::$email_dest; | ||
71 | 74 | ||
72 | if(EmailService::send($entityManager, $recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ | 75 | if(EmailService::send($entityManager, $form_data, true, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ |
73 | echo json_encode(['success' => true]); | 76 | echo json_encode(['success' => true]); |
74 | } | 77 | } |
75 | else{ | 78 | else{ |
diff --git a/src/router.php b/src/router.php index 3c3c773..ccab426 100644 --- a/src/router.php +++ b/src/router.php | |||
@@ -103,8 +103,8 @@ elseif($_SERVER['REQUEST_METHOD'] === 'POST'){ | |||
103 | } | 103 | } |
104 | 104 | ||
105 | /* -- bloc Formulaire -- */ | 105 | /* -- bloc Formulaire -- */ |
106 | elseif($_GET['action'] === 'recipient_email'){ | 106 | elseif($_GET['action'] === 'set_email_param'){ |
107 | ContactFormController::updateRecipient($entityManager, $json); | 107 | ContactFormController::setEmailParam($entityManager, $json); |
108 | } | 108 | } |
109 | elseif($_GET['action'] === 'test_email'){ | 109 | elseif($_GET['action'] === 'test_email'){ |
110 | ContactFormController::sendTestEmail($entityManager, $json); | 110 | ContactFormController::sendTestEmail($entityManager, $json); |
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 ?>" > |