summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/controller/ajax.php15
-rw-r--r--src/controller/ajax_admin.php22
-rw-r--r--src/model/entities/Email.php4
-rw-r--r--src/model/entities/NodeData.php10
-rw-r--r--src/view/FormBuilder.php22
-rw-r--r--src/view/templates/form.php2
6 files changed, 42 insertions, 33 deletions
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index 7529fe6..8a7cb34 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -8,7 +8,7 @@ use PHPMailer\PHPMailer\Exception;
8use App\Entity\Email; 8use App\Entity\Email;
9 9
10// mettre ça ailleurs? 10// mettre ça ailleurs?
11function sendEmail(bool $true_email, string $name = '', string $email = '', string $message = ''): bool 11function sendEmail(string $recipient, bool $true_email, string $name = '', string $email = '', string $message = ''): bool
12{ 12{
13 $mail = new PHPMailer(true); // true => exceptions 13 $mail = new PHPMailer(true); // true => exceptions
14 $mail->CharSet = 'UTF-8'; 14 $mail->CharSet = 'UTF-8';
@@ -35,7 +35,7 @@ function sendEmail(bool $true_email, string $name = '', string $email = '', stri
35 35
36 // Expéditeur et destinataire 36 // Expéditeur et destinataire
37 $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur 37 $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur
38 $mail->addAddress(strtolower(Config::$email_dest), Config::$email_dest_name); // destinataire 38 $mail->addAddress(strtolower($recipient), Config::$email_dest_name); // destinataire
39 39
40 // Contenu 40 // Contenu
41 $mail->isHTML(true); 41 $mail->isHTML(true);
@@ -65,10 +65,9 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json')
65 $data = file_get_contents('php://input'); 65 $data = file_get_contents('php://input');
66 $json = json_decode($data, true); 66 $json = json_decode($data, true);
67 67
68 // requêtes de tinymce ou touchant aux articles
69 if(isset($_GET['action'])) 68 if(isset($_GET['action']))
70 { 69 {
71 // e-mail envoyé par le formulaire de contact 70 /* -- bloc Formulaire -- */
72 if($_GET['action'] === 'send_email'){ 71 if($_GET['action'] === 'send_email'){
73 $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; 72 $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0;
74 $captcha_try = isset($json['captcha']) ? Captcha::controlInput($json['captcha']) : 0; 73 $captcha_try = isset($json['captcha']) ? Captcha::controlInput($json['captcha']) : 0;
@@ -77,12 +76,16 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json')
77 $name = htmlspecialchars(trim($json['name'])); 76 $name = htmlspecialchars(trim($json['name']));
78 $email = strtolower(htmlspecialchars(trim($json['email']))); 77 $email = strtolower(htmlspecialchars(trim($json['email'])));
79 $message = htmlspecialchars(trim($json['message'])); 78 $message = htmlspecialchars(trim($json['message']));
79
80 // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur
81 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']);
82 $recipient = $form_data->getData()['email'] ?? Config::$email_dest;
80 83
81 if($captcha_try != 0 && $captcha_solution != 0 && ($captcha_try === $captcha_solution) 84 if($captcha_try != 0 && $captcha_solution != 0 && ($captcha_try === $captcha_solution)
82 && filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden']) 85 && filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden'])
83 && sendEmail(true, $name, $email, $message)) 86 && sendEmail($recipient, true, $name, $email, $message))
84 { 87 {
85 $db_email = new Email(strtolower(Config::$email_from), strtolower(Config::$email_dest), $message); 88 $db_email = new Email(Config::$email_from, Config::$email_dest, $message);
86 $entityManager->persist($db_email); 89 $entityManager->persist($db_email);
87 $entityManager->flush(); 90 $entityManager->flush();
88 echo json_encode(['success' => true]); 91 echo json_encode(['success' => true]);
diff --git a/src/controller/ajax_admin.php b/src/controller/ajax_admin.php
index 944e84b..2318ac1 100644
--- a/src/controller/ajax_admin.php
+++ b/src/controller/ajax_admin.php
@@ -197,7 +197,6 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json')
197 $data = file_get_contents('php://input'); 197 $data = file_get_contents('php://input');
198 $json = json_decode($data, true); 198 $json = json_decode($data, true);
199 199
200 // requêtes de tinymce ou touchant aux articles
201 if(isset($_GET['action'])) 200 if(isset($_GET['action']))
202 { 201 {
203 if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content'])) 202 if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content']))
@@ -356,13 +355,17 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json')
356 die; 355 die;
357 } 356 }
358 357
359 // config formulaire 358
360 /*elseif($_GET['action'] === 'recipient_email'){ 359 /* -- bloc Formulaire -- */
360 elseif($_GET['action'] === 'recipient_email'){
361 $email = htmlspecialchars(trim($json['email'])); 361 $email = htmlspecialchars(trim($json['email']));
362 362
363 if(filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden'])){ 363 if((filter_var($email, FILTER_VALIDATE_EMAIL) // nouvel e-mail
364 || ($json['email'] === '' && !empty(Config::$email_dest))) // e-mail par défaut
365 && isset($json['hidden']) && empty($json['hidden']))
366 {
364 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); 367 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']);
365 $form_data->updateData('email', $json['email']); 368 $form_data->updateData('email', $email);
366 $entityManager->persist($form_data); 369 $entityManager->persist($form_data);
367 $entityManager->flush(); 370 $entityManager->flush();
368 371
@@ -372,10 +375,13 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json')
372 echo json_encode(['success' => false]); 375 echo json_encode(['success' => false]);
373 } 376 }
374 die; 377 die;
375 }*/ 378 }
376 // e-mail de test
377 elseif($_GET['action'] === 'test_email'){ 379 elseif($_GET['action'] === 'test_email'){
378 if(sendEmail(false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ 380 // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur
381 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']);
382 $recipient = $form_data->getData()['email'] ?? Config::$email_dest;
383
384 if(sendEmail($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){
379 echo json_encode(['success' => true]); 385 echo json_encode(['success' => true]);
380 } 386 }
381 else{ 387 else{
diff --git a/src/model/entities/Email.php b/src/model/entities/Email.php
index c6c2a29..9d87f1f 100644
--- a/src/model/entities/Email.php
+++ b/src/model/entities/Email.php
@@ -33,8 +33,8 @@ class Email
33 private ?\DateTime $date_time ; 33 private ?\DateTime $date_time ;
34 34
35 public function __construct(string $sender, string $recipient, string $content){ 35 public function __construct(string $sender, string $recipient, string $content){
36 $this->sender = $sender; 36 $this->sender = strtolower($sender);
37 $this->recipient = $recipient; 37 $this->recipient = strtolower($recipient);
38 $this->content = $content; 38 $this->content = $content;
39 $this->date_time = new \DateTime(); 39 $this->date_time = new \DateTime();
40 } 40 }
diff --git a/src/model/entities/NodeData.php b/src/model/entities/NodeData.php
index 9d23b8b..758ccb7 100644
--- a/src/model/entities/NodeData.php
+++ b/src/model/entities/NodeData.php
@@ -55,9 +55,15 @@ class NodeData
55 { 55 {
56 $this->data = $data; 56 $this->data = $data;
57 }*/ 57 }*/
58 public function updateData(string $key, string $value): void 58 public function updateData(string $key, string $value = ''): void
59 { 59 {
60 $this->data[$key] = $value; 60 if($value !== ''){
61 $this->data[$key] = $value;
62 }
63 // si $value est vide, supprime la clé
64 elseif(isset($this->data[$key])){
65 unset($this->data[$key]);
66 }
61 } 67 }
62 /*public function setNode(Node $node): void 68 /*public function setNode(Node $node): void
63 { 69 {
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php
index 508763b..7a2adcb 100644
--- a/src/view/FormBuilder.php
+++ b/src/view/FormBuilder.php
@@ -22,27 +22,21 @@ class FormBuilder extends AbstractBuilder
22 $captcha = new Captcha; 22 $captcha = new Captcha;
23 $_SESSION['captcha'] = $captcha->getSolution(); 23 $_SESSION['captcha'] = $captcha->getSolution();
24 24
25 $email = $email ?? Config::$email_dest;
26
25 $admin_content = ''; 27 $admin_content = '';
26 if($_SESSION['admin']) 28 if($_SESSION['admin'])
27 { 29 {
28 $admin_content = '' 30 $admin_content = '<div class="admin_form">
29 //. '<h3>Configuration du formulaire</h3>' . "\n" 31 <p>
30 . '<div class="admin_form">' . "\n" 32 <label for="recipient">E-mail de destination de ce formulaire</label>
31 /*. '<p>
32 <label for="recipient">E-mail de destination</label>
33 <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '"> 33 <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '">
34 <input type="hidden" id="recipient_hidden" value=""> 34 <input type="hidden" id="recipient_hidden" value="">
35 <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button> 35 <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button>
36 </p> 36 </p>
37 <p> 37 <p><button onclick="sendTestEmail(' . $node->getNodeData()->getId() . ')">Envoi d\'un e-mail de test</button></p>
38 <label for="smtp">Serveur SMTP</label> 38 <p class="test_email_success full_width_column"></p>
39 <input id="smtp" type="text" name="smtp" value="' . $smtp . '"> 39 </div>' . "\n";
40 <input type="hidden" id="smtp_hidden" value="">
41 <button onclick="changeSmtp(' . $node->getNodeData()->getId() . ')">Valider</button>
42 </p>' . "\n"*/
43 . '<p><button onclick="sendTestEmail()">Envoi d\'un e-mail de test</button></p>' . "\n"
44 . '<p class="test_email_success full_width_column"></p>'
45 . '</div>' . "\n";
46 } 40 }
47 41
48 ob_start(); 42 ob_start();
diff --git a/src/view/templates/form.php b/src/view/templates/form.php
index 5f81f6f..bcde2f4 100644
--- a/src/view/templates/form.php
+++ b/src/view/templates/form.php
@@ -25,7 +25,7 @@
25 <input id="email_hidden" type="hidden" name="email_hidden"> 25 <input id="email_hidden" 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()"> 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 full_width_column"></p>