summaryrefslogtreecommitdiff
path: root/src/controller
diff options
context:
space:
mode:
Diffstat (limited to 'src/controller')
-rw-r--r--src/controller/ajax.php15
-rw-r--r--src/controller/ajax_admin.php22
2 files changed, 23 insertions, 14 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{