1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
// modif des paramètres d'e-mail: e-mail source/dest, mot de passe, serveur smtp & chiffrement tls/ssl
function setEmailParam(what_param, id){
const value = document.getElementById(what_param + '_' + id).value;
const hidden = document.getElementById(what_param + '_hidden_' + id).value;
fetch('index.php?action=set_email_param', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: id, what_param: what_param, value: value, hidden: hidden })
})
.then(response => response.json())
.then(data => {
if(data.success){
toastNotify(what_param + ' a été modifié(e)');
}
else{
console.error("Erreur rencontrée à l'enregistrement de cette donnée en base de données");
toastNotify("Erreur rencontrée à l'enregistrement de cette donnée en base de données");
}
})
.catch(error => {
console.error('Erreur:', error);
toastNotify('Erreur:', error);
});
}
function keepEmails(block_id){
const form = document.getElementById('keep_emails_' + block_id);
const warning = document.getElementById('form_warning_' + block_id);
if(!form || !warning){
return;
}
fetch('index.php?action=keep_emails', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: block_id,
checked: form.checked
})
})
.then(response => response.json())
.then(data => {
if(data.success){
form.checked = data.checked;
data.checked ? warning.classList.remove('hidden') : warning.classList.add('hidden');
toastNotify(data.checked ? "Les e-mails seront conservés. Pensez au RGPD." : "Les nouveaux e-mails ne seront pas conservés.");
}
else{
toastNotify("Erreur, le réglage n'a pas été enregistré par le serveur.");
}
})
.catch(error => {
console.error('Erreur:', error);
});
}
function checkCase(id){
if(document.getElementById('email_address_' + id).value.match('[A-Z]')){
toastNotify("Votre e-mail comporte une lettre majuscule, il s'agit probablement d'une erreur.");
}
}
function sendTestEmail(id){
//const admin_form = document.querySelector('.admin_form');
const test_email_success = document.querySelector('.test_email_success_' + id);
test_email_success.innerHTML = 'Envoi en cours, veuillez patienter';
test_email_success.style.backgroundColor = 'yellow';
fetch('index.php?action=test_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ id: id})
})
.then(response => response.json())
.then(data => {
let message;
let color;
if(data.success){
message = 'E-mail de test envoyé avec succès';
color = 'chartreuse';
}
else{
message = "Erreur à l'envoi de l'e-mail, vérifiez la configuration du serveur";
color = "orangered"
}
test_email_success.innerHTML = message;
toastNotify(message);
test_email_success.style.backgroundColor = color;
})
.catch(error => {
console.error('Erreur:', error);
});
}
function sendVisitorEmail(id){
const email_name = document.getElementById('email_name_' + id).value;
const email_address = document.getElementById('email_address_' + id).value;
const email_message = document.getElementById('email_message_' + id).value;
const email_captcha = document.getElementById('email_captcha_' + id).value;
const email_hidden = document.getElementById('email_hidden_' + id).value;
const send_email_success = document.querySelector('.send_email_success_' + id);
if(email_name === '' || email_address === '' || email_message === '' || email_captcha === ''){
toastNotify('Veuillez remplir tous les champs.');
return;
}
else{
send_email_success.innerHTML = 'Envoi en cours, veuillez patienter';
send_email_success.style.backgroundColor = 'yellow';
}
fetch('index.php?action=send_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: email_name,
email: email_address,
message: email_message,
captcha: email_captcha,
hidden: email_hidden,
id: id
})
})
.then(response => response.json())
.then(data => {
let message;
let color;
if(data.success){
message = 'Votre e-mail a été envoyé!';
color = 'lawngreen';
}
else{
message = "Votre message n'a pas pu être envoyé, votre e-mail ou le captcha ne sont peut-être pas corrects";
color = "orangered"
}
send_email_success.innerHTML = message;
send_email_success.style.backgroundColor = color;
toastNotify(message);
})
.catch(error => {
console.error('Erreur:', error);
});
}
function deleteEmail(id){
const table_row = document.getElementById(id);
if(!table_row){
return;
}
if(confirm('Voulez-vous supprimer cet e-mail ?')){
fetch('index.php?action=delete_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: id
})
})
.then(response => response.json())
.then(data => {
if(data.success){
table_row.remove();
toastNotify("E-mail supprimé");
}
else{}
})
.catch(error => {
console.error('Erreur:', error);
});
}
}
function toggleSensitiveEmail(id){
const table_row = document.getElementById(id);
const checkbox = table_row.querySelector("input[class='make_checkbox_sensitive']");
const deletion_date = table_row.querySelector(".deletion_date");
if(!table_row || !checkbox || !deletion_date){
return;
}
fetch('index.php?action=toggle_sensitive_email', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
id: id,
checked: checkbox.checked
})
})
.then(response => response.json())
.then(data => {
if(data.success){
checkbox.checked = data.checked;
deletion_date.innerHTML = data.deletion_date;
console.log(data.checked ? "Cet e-mail est maintenant considéré comme sensible." : "Cet e-mail n'est plus sensible.");
}
else{}
})
.catch(error => {
console.error('Erreur:', error);
});
}
|