summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--public/css/body.css4
-rw-r--r--public/css/tinymce.css4
-rw-r--r--public/js/form.js15
-rw-r--r--src/controller/ajax.php18
-rw-r--r--src/model/entities/Node.php2
-rw-r--r--src/view/FormBuilder.php23
-rw-r--r--src/view/templates/form.php2
7 files changed, 46 insertions, 22 deletions
diff --git a/public/css/body.css b/public/css/body.css
index a2b099a..eb198e6 100644
--- a/public/css/body.css
+++ b/public/css/body.css
@@ -7,6 +7,10 @@ body
7 background-color: #0cceec; 7 background-color: #0cceec;
8} 8}
9 9
10.hidden{
11 display: none;
12}
13
10#bloc_page 14#bloc_page
11{} 15{}
12 16
diff --git a/public/css/tinymce.css b/public/css/tinymce.css
index 55639e0..1a99de9 100644
--- a/public/css/tinymce.css
+++ b/public/css/tinymce.css
@@ -1,6 +1,6 @@
1.tox-promotion{ 1.tox-promotion{
2 display: none; 2 display: none;
3} 3}
4.hidden{ 4/*.hidden{
5 display: none; 5 display: none;
6} \ No newline at end of file 6}*/ \ No newline at end of file
diff --git a/public/js/form.js b/public/js/form.js
index 6386ea8..1752f55 100644
--- a/public/js/form.js
+++ b/public/js/form.js
@@ -1,24 +1,23 @@
1//function sendMessage(){} 1//function sendMessage(){}
2 2
3function changeRecipient(){ 3function changeRecipient(id){
4 const email = document.getElementById('recipient').value; 4 const email = document.getElementById('recipient').value;
5 const id_form = ''; 5 const warning = document.querySelector('.no_recipient_warning');
6 6
7 fetch('index.php?action=recipient_email', { 7 fetch('index.php?action=recipient_email', {
8 method: 'POST', 8 method: 'POST',
9 headers: { 9 headers: {
10 'Content-Type': 'application/json' 10 'Content-Type': 'application/json'
11 }, 11 },
12 body: JSON.stringify({ id_form: id_form, email: email }) 12 body: JSON.stringify({ id: id, email: email })
13 }) 13 })
14 .then(response => response.json()) 14 .then(response => response.json())
15 .then(data => { 15 .then(data => {
16 if(data.success) 16 if(data.success){
17 { 17 warning.classList.add('hidden');
18 toastNotify('Adresse e-mail de destination modifiée'); 18 toastNotify('Adresse e-mail de destination modifiée');
19 } 19 }
20 else { 20 else{
21
22 console.error('Erreur: echec de la modification de l\'adresse e-mail de destination'); 21 console.error('Erreur: echec de la modification de l\'adresse e-mail de destination');
23 } 22 }
24 }) 23 })
diff --git a/src/controller/ajax.php b/src/controller/ajax.php
index a462921..ae43b75 100644
--- a/src/controller/ajax.php
+++ b/src/controller/ajax.php
@@ -353,6 +353,24 @@ if($_SERVER['CONTENT_TYPE'] === 'application/json'){
353 echo json_encode(['success' => true]); 353 echo json_encode(['success' => true]);
354 die; 354 die;
355 } 355 }
356
357 // config formulaire
358 elseif($_GET['action'] === 'recipient_email'){
359 $form_data = $entityManager->find('App\Entity\NodeData', $json['id']);
360 $email = htmlspecialchars(trim($json['email']));
361
362 if(filter_var($email, FILTER_VALIDATE_EMAIL)){
363 $form_data->updateData('email', $json['email']);
364 $entityManager->persist($form_data);
365 $entityManager->flush();
366 echo json_encode(['success' => true]);
367 die;
368 }
369 else{
370 echo json_encode(['success' => false]);
371 die;
372 }
373 }
356 } 374 }
357 375
358 376
diff --git a/src/model/entities/Node.php b/src/model/entities/Node.php
index c4d0830..93363d3 100644
--- a/src/model/entities/Node.php
+++ b/src/model/entities/Node.php
@@ -56,7 +56,7 @@ class Node
56 56
57 private array $children = []; // tableau de Node 57 private array $children = []; // tableau de Node
58 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article" 58 private ?self $adopted = null; // = "new" est un enfant de "main" lorsque la page est "article"
59 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot', 'calendar'],'js_array' => ['main']]; 59 static private array $default_attributes = ['css_array' => ['body', 'head', 'nav', 'foot'],'js_array' => ['main']];
60 60
61 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null) 61 public function __construct(string $name = '', ?string $article_timestamp = null, array $attributes = [], int $position = 0, ?self $parent = null, ?Page $page = null, ?Article $article = null)
62 { 62 {
diff --git a/src/view/FormBuilder.php b/src/view/FormBuilder.php
index b3a96f3..5f8545c 100644
--- a/src/view/FormBuilder.php
+++ b/src/view/FormBuilder.php
@@ -23,25 +23,28 @@ class FormBuilder extends AbstractBuilder
23 $captcha = new Captcha; 23 $captcha = new Captcha;
24 $_SESSION['captcha'] = $captcha->getSolution(); 24 $_SESSION['captcha'] = $captcha->getSolution();
25 25
26 $no_recipient_warning = ''; 26 $recipient_found = false;
27 if(isset($email)){
28 $recipient_found = true;
29 }
30 else{
31 $email = '';
32 }
33
27 $admin_content = ''; 34 $admin_content = '';
28 if($_SESSION['admin']) 35 if($_SESSION['admin'])
29 { 36 {
30 $admin_content = '<script src="js/form.js"></script> 37 $admin_content = '<script src="js/form.js"></script>
31 <h3>Configuration du formulaire</h3> 38 <h3>Configuration du formulaire</h3>
32 <div class="admin_form"> 39 <div class="admin_form">
33 <label for="recipient">E-mail du destinataire</label> 40 <label for="recipient">E-mail de destination</label>
34 <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value=""> 41 <input id="recipient" type="email" name="recipient" placeholder="mon-adresse@email.fr" value="' . $email . '">
35 <button onclick="changeRecipient()">Valider</button> 42 <button onclick="changeRecipient(' . $node->getNodeData()->getId() . ')">Valider</button>
36 </div>'; 43 </div>';
37 } 44 }
38
39 $recipient_found = false;
40 // recherche BDD
41 45
42 if(!$recipient_found){ // vérifier qu'une adresse de destination est bien configurée 46 // vérifier qu'une adresse de destination est bien configurée
43 $no_recipient_warning = '<p class="no_recipient_warning">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>'; 47 $no_recipient_warning = '<p class="no_recipient_warning ' . ($recipient_found ? 'hidden' : '') . '">Aucune adresse de destination n\'a été configurée, envoi d\'e-mail impossible!</p>';
44 }
45 48
46 ob_start(); 49 ob_start();
47 require $viewFile; 50 require $viewFile;
diff --git a/src/view/templates/form.php b/src/view/templates/form.php
index 97d53d4..0c44bf8 100644
--- a/src/view/templates/form.php
+++ b/src/view/templates/form.php
@@ -4,7 +4,7 @@
4 <h3><?= $title ?></h3> 4 <h3><?= $title ?></h3>
5 <?= $no_recipient_warning ?> 5 <?= $no_recipient_warning ?>
6 <form method="post" action="<?= $action_url ?>"> 6 <form method="post" action="<?= $action_url ?>">
7 <label for="email">Adresse e-mail</label> 7 <label for="email">Votre e-mail</label>
8 <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required> 8 <input type="email" name="email" placeholder="mon-adresse@email.fr" value="" required>
9 9
10 <label for="subject">Objet</label> 10 <label for="subject">Objet</label>