From 3104104e838b7d57de49daba0178b1aefe646548 Mon Sep 17 00:00:00 2001 From: polo Date: Fri, 4 Jul 2025 10:29:45 +0200 Subject: formulaire de contact 4 --- public/css/body.css | 6 +++--- public/css/foot.css | 8 ++++---- public/css/form.css | 2 +- public/css/head.css | 2 +- public/css/menu.css | 2 +- public/css/modif_page.css | 2 +- public/css/nav.css | 2 +- public/css/new_page.css | 2 +- public/js/form.js | 23 +++++++++++------------ src/controller/ajax.php | 15 +++++++++------ src/controller/ajax_admin.php | 22 ++++++++++++++-------- src/model/entities/Email.php | 4 ++-- src/model/entities/NodeData.php | 10 ++++++++-- src/view/FormBuilder.php | 22 ++++++++-------------- src/view/templates/form.php | 2 +- 15 files changed, 66 insertions(+), 58 deletions(-) diff --git a/public/css/body.css b/public/css/body.css index eb198e6..c3f518a 100644 --- a/public/css/body.css +++ b/public/css/body.css @@ -116,7 +116,7 @@ article .logo2 } .new_content button:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; } article img @@ -137,7 +137,7 @@ button .action_icon } .action_icon:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; border: lightgrey 2px outset; cursor: pointer; @@ -187,7 +187,7 @@ section button } section button:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; cursor: pointer; } diff --git a/public/css/foot.css b/public/css/foot.css index dd9b953..0eb250e 100644 --- a/public/css/foot.css +++ b/public/css/foot.css @@ -28,7 +28,7 @@ footer > div padding: 0 2px; /*background-color: #13aff0ff; border-bottom: 3px #fadb11 solid;*/ - background-color: #ffff00; + background-color: yellow; /*border-bottom: 2px #00a8f3 solid;*/ border-bottom: 2px #ff1d04 solid; } @@ -58,7 +58,7 @@ footer > div { /*background-color: #13aff0; border-bottom: 3px #fadb11 solid;*/ - background-color: #ffff00; + background-color: yellow; /*border-bottom: 2px #00a8f3 solid;*/ border-bottom: 2px #ff1d04 solid; } @@ -131,7 +131,7 @@ footer > div /*height: 70px;*/ width: 100%; margin: auto; - background-color: #ffff00; + background-color: yellow; position: fixed; bottom: 0px; z-index: 1; /* augmenter la valeur si nécessaire */ @@ -149,7 +149,7 @@ footer > div .logged_in button:hover { cursor: pointer; /* curseur qui touche du doigt */ - background-color: #ffff00; + background-color: yellow; border-radius: 4px; } .modif_mode diff --git a/public/css/form.css b/public/css/form.css index d317360..84c73ac 100644 --- a/public/css/form.css +++ b/public/css/form.css @@ -24,7 +24,7 @@ } .form_inputs input[type=submit]:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; cursor: pointer; } diff --git a/public/css/head.css b/public/css/head.css index eff7de6..a55449a 100644 --- a/public/css/head.css +++ b/public/css/head.css @@ -61,5 +61,5 @@ header a .social img:hover { - background-color: #ffff00; + background-color: yellow; } diff --git a/public/css/menu.css b/public/css/menu.css index 68e2b2a..62e6623 100644 --- a/public/css/menu.css +++ b/public/css/menu.css @@ -72,7 +72,7 @@ } .menu #location:hover, .menu input[type=submit]:hover, .move_entry_icon:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; border: lightgrey 2px outset; cursor: pointer; diff --git a/public/css/modif_page.css b/public/css/modif_page.css index 77392d2..d6fc23e 100644 --- a/public/css/modif_page.css +++ b/public/css/modif_page.css @@ -19,7 +19,7 @@ }*/ .page_modification form input[type=submit]:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; cursor: pointer; } diff --git a/public/css/nav.css b/public/css/nav.css index 50bf4af..7f47cff 100644 --- a/public/css/nav.css +++ b/public/css/nav.css @@ -72,7 +72,7 @@ ul /*.sub-menu p:hover*/ .nav_main p:hover { - background-color: #ffff00; + background-color: yellow; } .drop-right > a > p:after { diff --git a/public/css/new_page.css b/public/css/new_page.css index 0cc067a..29d3ad0 100644 --- a/public/css/new_page.css +++ b/public/css/new_page.css @@ -19,7 +19,7 @@ } .new_page #page_location:hover, .new_page input[type=submit]:hover { - background-color: #ffff00; + background-color: yellow; border-radius: 4px; border: lightgrey 2px outset; cursor: pointer; diff --git a/public/js/form.js b/public/js/form.js index 0be2313..5c5a164 100644 --- a/public/js/form.js +++ b/public/js/form.js @@ -1,10 +1,9 @@ //function sendMessage(){} // modif des paramètre d'envoi d'e-mail depuis l'espace admin -/*function changeRecipient(id){ +function changeRecipient(id){ const email = document.getElementById('recipient').value; const hidden = document.getElementById('recipient_hidden').value; - const warning = document.querySelector('.no_recipient_warning'); fetch('index.php?action=recipient_email', { method: 'POST', @@ -16,7 +15,6 @@ .then(response => response.json()) .then(data => { if(data.success){ - warning.classList.add('hidden'); toastNotify('Adresse e-mail de destination modifiée'); } else{ @@ -26,20 +24,20 @@ .catch(error => { console.error('Erreur:', error); }); -}*/ +} -function sendTestEmail(){ +function sendTestEmail(id){ const admin_form = document.querySelector('.admin_form'); const test_email_success = document.querySelector('.test_email_success'); test_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; - test_email_success.style.backgroundColor = '#f0f0f0'; + test_email_success.style.backgroundColor = 'yellow'; fetch('index.php?action=test_email', { method: 'POST', headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({}) + body: JSON.stringify({ id: id}) }) .then(response => response.json()) .then(data => { @@ -47,10 +45,10 @@ function sendTestEmail(){ let color; if(data.success){ message = 'E-mail de test envoyé avec succès'; - color = 'lawngreen'; + color = 'chartreuse'; } else{ - message = "Erreur à l'envoi de l'e-mail"; + message = "Erreur à l'envoi de l'e-mail, vérifiez la configuration du serveur"; color = "orangered" } test_email_success.innerHTML = message; @@ -62,10 +60,10 @@ function sendTestEmail(){ }); } -function sendVisitorEmail(){ +function sendVisitorEmail(id){ const send_email_success = document.querySelector('.send_email_success'); send_email_success.innerHTML = 'Envoi en cours, veuillez patienter'; - send_email_success.style.backgroundColor = 'initial'; + send_email_success.style.backgroundColor = 'yellow'; const email_name = document.getElementById('email_name').value; const email_address = document.getElementById('email_address').value; @@ -83,7 +81,8 @@ function sendVisitorEmail(){ email: email_address, message: email_message, captcha: email_captcha, - hidden: email_hidden + hidden: email_hidden, + id: id }) }) .then(response => response.json()) 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; use App\Entity\Email; // mettre ça ailleurs? -function sendEmail(bool $true_email, string $name = '', string $email = '', string $message = ''): bool +function sendEmail(string $recipient, bool $true_email, string $name = '', string $email = '', string $message = ''): bool { $mail = new PHPMailer(true); // true => exceptions $mail->CharSet = 'UTF-8'; @@ -35,7 +35,7 @@ function sendEmail(bool $true_email, string $name = '', string $email = '', stri // Expéditeur et destinataire $mail->setFrom(strtolower(Config::$email_from), Config::$email_from_name); // expéditeur - $mail->addAddress(strtolower(Config::$email_dest), Config::$email_dest_name); // destinataire + $mail->addAddress(strtolower($recipient), Config::$email_dest_name); // destinataire // Contenu $mail->isHTML(true); @@ -65,10 +65,9 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json') $data = file_get_contents('php://input'); $json = json_decode($data, true); - // requêtes de tinymce ou touchant aux articles if(isset($_GET['action'])) { - // e-mail envoyé par le formulaire de contact + /* -- bloc Formulaire -- */ if($_GET['action'] === 'send_email'){ $captcha_solution = (isset($_SESSION['captcha']) && is_int($_SESSION['captcha'])) ? $_SESSION['captcha'] : 0; $captcha_try = isset($json['captcha']) ? Captcha::controlInput($json['captcha']) : 0; @@ -77,12 +76,16 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json') $name = htmlspecialchars(trim($json['name'])); $email = strtolower(htmlspecialchars(trim($json['email']))); $message = htmlspecialchars(trim($json['message'])); + + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $recipient = $form_data->getData()['email'] ?? Config::$email_dest; if($captcha_try != 0 && $captcha_solution != 0 && ($captcha_try === $captcha_solution) && filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden']) - && sendEmail(true, $name, $email, $message)) + && sendEmail($recipient, true, $name, $email, $message)) { - $db_email = new Email(strtolower(Config::$email_from), strtolower(Config::$email_dest), $message); + $db_email = new Email(Config::$email_from, Config::$email_dest, $message); $entityManager->persist($db_email); $entityManager->flush(); 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') $data = file_get_contents('php://input'); $json = json_decode($data, true); - // requêtes de tinymce ou touchant aux articles if(isset($_GET['action'])) { if($_GET['action'] === 'editor_submit' && isset($json['id']) && isset($json['content'])) @@ -356,13 +355,17 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json') die; } - // config formulaire - /*elseif($_GET['action'] === 'recipient_email'){ + + /* -- bloc Formulaire -- */ + elseif($_GET['action'] === 'recipient_email'){ $email = htmlspecialchars(trim($json['email'])); - if(filter_var($email, FILTER_VALIDATE_EMAIL) && isset($json['hidden']) && empty($json['hidden'])){ + if((filter_var($email, FILTER_VALIDATE_EMAIL) // nouvel e-mail + || ($json['email'] === '' && !empty(Config::$email_dest))) // e-mail par défaut + && isset($json['hidden']) && empty($json['hidden'])) + { $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); - $form_data->updateData('email', $json['email']); + $form_data->updateData('email', $email); $entityManager->persist($form_data); $entityManager->flush(); @@ -372,10 +375,13 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json') echo json_encode(['success' => false]); } die; - }*/ - // e-mail de test + } elseif($_GET['action'] === 'test_email'){ - if(sendEmail(false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ + // destinataire = e-mail par défaut dans config.ini OU choisi par l'utilisateur + $form_data = $entityManager->find('App\Entity\NodeData', $json['id']); + $recipient = $form_data->getData()['email'] ?? Config::$email_dest; + + if(sendEmail($recipient, false, 'nom du visiteur', 'adresse@du_visiteur.fr', "TEST d'un envoi d'e-mail depuis le site web")){ echo json_encode(['success' => true]); } 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 private ?\DateTime $date_time ; public function __construct(string $sender, string $recipient, string $content){ - $this->sender = $sender; - $this->recipient = $recipient; + $this->sender = strtolower($sender); + $this->recipient = strtolower($recipient); $this->content = $content; $this->date_time = new \DateTime(); } 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 { $this->data = $data; }*/ - public function updateData(string $key, string $value): void + public function updateData(string $key, string $value = ''): void { - $this->data[$key] = $value; + if($value !== ''){ + $this->data[$key] = $value; + } + // si $value est vide, supprime la clé + elseif(isset($this->data[$key])){ + unset($this->data[$key]); + } } /*public function setNode(Node $node): void { 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 $captcha = new Captcha; $_SESSION['captcha'] = $captcha->getSolution(); + $email = $email ?? Config::$email_dest; + $admin_content = ''; if($_SESSION['admin']) { - $admin_content = '' - //. '

Configuration du formulaire

' . "\n" - . '
' . "\n" - /*. '

- + $admin_content = '

+

+

-

- - - - -

' . "\n"*/ - . '

' . "\n" - . '

' - . '
' . "\n"; +

+

+
' . "\n"; } 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 @@
- +

-- cgit v1.2.3