-
Notifications
You must be signed in to change notification settings - Fork 4
/
profil_cp.php
331 lines (270 loc) · 8.96 KB
/
profil_cp.php
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<?php
/**
* @package Wanewsletter
* @author Bobe <wascripts@webnaute.net>
* @link http://dev.webnaute.net/wanewsletter/
* @copyright 2002-2021 Aurélien Maille
* @license https://www.gnu.org/licenses/gpl.html GNU General Public License
*/
namespace Wanewsletter;
use Wamailer\{Mailer, Email};
const IN_PROFILCP = true;
require './includes/common.inc.php';
//
// Initialisation de la connexion à la base de données et récupération de la configuration
//
$db = WaDatabase($dsn);
$nl_config = wa_get_config();
if (!$nl_config['enable_profil_cp']) {
load_l10n();
$output->message('Profil_cp_disabled');
}
//
// Instanciation d'une session
//
$session = new Session($nl_config);
$auth = new Auth();
//
// End
//
$error = false;
$mode = filter_input(INPUT_GET, 'mode');
// Spécial. la présence du paramètre 'k' signifie qu'on est dans le mode 'reset'
$reset_key = filter_input(INPUT_GET, 'k');
if ($reset_key && !$mode) {
$mode = 'reset';
}
if ($mode == 'login' || $mode == 'logout' || $mode == 'reset' || $mode == 'cp') {
require './includes/login.inc.php';
}
if (!$auth->isLoggedIn()) {
$session->reset();
http_redirect('profil_cp.php?mode=login');
}
$abodata = $auth->getUserData($_SESSION['uid']);
if (empty($abodata['abo_lang'])) {
$abodata['abo_lang'] = $nl_config['language'];
}
load_l10n($abodata);
$other_tags = wan_get_tags();
switch ($mode) {
case 'editprofile':
if (isset($_POST['submit'])) {
$vararray = ['new_email', 'confirm_email', 'username', 'language',
'current_passwd', 'new_passwd', 'confirm_passwd'
];
foreach ($vararray as $varname) {
${$varname} = utf8_normalize(trim(filter_input(INPUT_POST, $varname)));
}
if ($language == '' || !validate_lang($language)) {
$language = $nl_config['language'];
}
if ($new_email != '') {
if (strcmp($new_email, $confirm_email) != 0) {
$error = true;
$output->warn('Bad_confirm_email');
}
else if (!Mailer::checkMailSyntax($new_email)) {
$error = true;
$output->warn('Invalid_email');
}
else {
$sql = "SELECT COUNT(*) AS test
FROM " . ABONNES_TABLE . "
WHERE abo_email = '" . $db->escape($new_email) . "'";
$result = $db->query($sql);
if ($result->column('test') != 0) {
$error = true;
$output->warn('Allready_reg2');
}
}
}
$set_password = false;
if ($new_passwd != '') {
$set_password = true;
if (!password_verify($current_passwd, $abodata['passwd'])) {
$error = true;
$output->warn('Error_login');
}
else if (!validate_pass($new_passwd)) {
$error = true;
$output->warn('Alphanum_pass');
}
else if ($new_passwd !== $confirm_passwd) {
$error = true;
$output->warn('Bad_confirm_pass');
}
}
if (!$error) {
$sql_data = [
'abo_pseudo' => strip_tags($username),
'abo_lang' => $language
];
if ($set_password) {
if (!($passwd_hash = password_hash($new_passwd, PASSWORD_DEFAULT))) {
trigger_error("Unexpected error returned by password API", E_USER_ERROR);
}
$sql_data['abo_pwd'] = $passwd_hash;
}
if ($new_email != '') {
$sql_data['abo_email'] = $new_email;
}
foreach ($other_tags as $tag) {
$input_name = (!empty($tag['field_name'])) ? $tag['field_name'] : $tag['column_name'];
$data = filter_input(INPUT_POST, $input_name);
if (!is_null($data)) {
$sql_data[$tag['column_name']] = utf8_normalize(trim($data));
}
}
$db->update(ABONNES_TABLE, $sql_data, ['abo_id' => $abodata['uid']]);
$output->redirect('profil_cp.php', 4);
$output->message('Profile_updated');
}
}
$output->header();
$template = new Template('editprofile_body.tpl');
$template->assign([
'TITLE' => $lang['Module']['editprofile'],
'L_EXPLAIN' => nl2br($lang['Explain']['editprofile']),
'L_EXPLAIN_EMAIL' => nl2br($lang['Explain']['change_email']),
'L_EMAIL' => $lang['Email_address'],
'L_NEW_EMAIL' => $lang['New_Email'],
'L_CONFIRM_EMAIL' => $lang['Confirm_Email'],
'L_USERNAME' => $lang['Login'],
'L_LANG' => $lang['Default_lang'],
'L_PASSWD' => $lang['Password'],
'L_NEW_PASSWD' => $lang['New_passwd'],
'L_CONFIRM_PASSWD'=> $lang['Confirm_passwd'],
'L_VALID_BUTTON' => $lang['Button']['valid'],
'EMAIL' => htmlspecialchars($abodata['email']),
'USERNAME' => htmlspecialchars($abodata['username']),
'LANG_BOX' => lang_box($abodata['abo_lang'])
]);
foreach ($other_tags as $tag) {
if (isset($abodata[$tag['column_name']])) {
$template->assign([
$tag['tag_name'] => htmlspecialchars($abodata[$tag['column_name']])
]);
}
}
break;
case 'archives':
// Données des listes
$sql = "SELECT al.format, al.register_key, al.register_date,
l.liste_id, l.liste_name, l.sender_email, l.return_email,
l.liste_sig, l.liste_format, l.use_cron, l.liste_alias, l.form_url
FROM %s AS l
INNER JOIN %s AS al ON al.abo_id = %d
AND al.liste_id = l.liste_id
ORDER BY l.liste_name ASC";
$sql = sprintf($sql, LISTE_TABLE, ABO_LISTE_TABLE, $abodata['uid']);
$result = $db->query($sql);
$abodata['lists'] = [];
while ($listdata = $result->fetch($result::FETCH_ASSOC)) {
$abodata['lists'][$listdata['liste_id']] = $listdata;
}
if (isset($_POST['submit'])) {
$listlog = (array) filter_input(INPUT_POST, 'log',
FILTER_VALIDATE_INT,
FILTER_REQUIRE_ARRAY
);
$listlog = array_filter($listlog);
$sql_log_id = [];
foreach ($listlog as $liste_id => $logs) {
if (isset($abodata['lists'][$liste_id])) {
$sql_log_id = array_merge($sql_log_id, $logs);
}
}
if (count($sql_log_id) == 0) {
$output->message('No_log_id');
}
$sql = "SELECT lf.log_id, jf.file_id, jf.file_real_name,
jf.file_physical_name, jf.file_size, jf.file_mimetype
FROM " . JOINED_FILES_TABLE . " AS jf
INNER JOIN " . LOG_FILES_TABLE . " AS lf ON lf.file_id = jf.file_id
AND lf.log_id IN(" . implode(', ', $sql_log_id) . ")";
$result = $db->query($sql);
$files = [];
while ($row = $result->fetch()) {
$files[$row['log_id']][] = $row;
}
$sql = "SELECT liste_id, log_id, log_subject, log_body_text, log_body_html, log_status
FROM " . LOG_TABLE . "
WHERE log_id IN(" . implode(', ', $sql_log_id) . ")
AND log_status = " . STATUS_SENT;
$result = $db->query($sql);
while ($logdata = $result->fetch()) {
$listdata = $abodata['lists'][$logdata['liste_id']];
$logdata['joined_files'] = [];
$abodata['register_key'] = $listdata['register_key'];
$abodata['format'] = $listdata['format'];// À ne pas confondre avec liste_format
$abodata['name'] = $abodata['abo_pseudo'];
if (isset($files[$logdata['log_id']])) {
$logdata['joined_files'] = $files[$logdata['log_id']];
}
$sender = new Sender($listdata, $logdata);
try {
$sender->send($abodata);
}
catch (\Exception $e) {
trigger_error(sprintf($lang['Message']['Failed_sending'],
htmlspecialchars($e->getMessage())
), E_USER_ERROR);
}
}
$output->message(sprintf($lang['Message']['Logs_sent'], $abodata['email']));
}
$liste_ids = [];
foreach ($abodata['lists'] as $liste_id => $listdata) {
$liste_ids[] = $liste_id;
}
$sql = "SELECT log_id, liste_id, log_subject, log_date
FROM " . LOG_TABLE . "
WHERE liste_id IN(" . implode(', ', $liste_ids) . ")
AND log_status = " . STATUS_SENT . "
ORDER BY log_date DESC";
$result = $db->query($sql);
while ($row = $result->fetch()) {
$abodata['lists'][$row['liste_id']]['archives'][] = $row;
}
$output->header();
$template = new Template('archives_body.tpl');
$template->assign([
'TITLE' => $lang['Title']['archives'],
'L_EXPLAIN' => $lang['Explain']['archives'],
'L_VALID_BUTTON' => $lang['Button']['valid']
]);
foreach ($abodata['lists'] as $liste_id => $listdata) {
if (!isset($abodata['lists'][$liste_id]['archives'])) {
continue;
}
$num_logs = count($abodata['lists'][$liste_id]['archives']);
$select_log = '<select id="liste_%1$d" name="log[%1$d][]" class="logList" size="%2$d" multiple>';
$select_log = sprintf($select_log, $liste_id, min(8, $num_logs));
for ($i = 0; $i < $num_logs; $i++) {
$logdata = $abodata['lists'][$liste_id]['archives'][$i];
$select_log .= sprintf('<option value="%d">%s – [%s]</option>',
$logdata['log_id'],
htmlspecialchars($logdata['log_subject'], ENT_NOQUOTES),
convert_time('d/m/Y', $logdata['log_date'])
);
}
$select_log .= '</select>'."\n";
$template->assignToBlock('listerow', [
'LISTE_ID' => $liste_id,
'LISTE_NAME' => htmlspecialchars($listdata['liste_name']),
'SELECT_LOG' => $select_log
]);
}
break;
default:
$output->header();
$template = new Template('index_body.tpl');
$template->assign([
'TITLE' => $lang['Title']['profil_cp'],
'L_EXPLAIN' => nl2br($lang['Welcome_profil_cp'])
]);
break;
}
$template->pparse();
$output->footer();