Translates peremption to expiration.
[platal.git] / modules / lists.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the Free Software *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 class ListsModule extends PLModule
23 {
24 protected $client;
25
26 function handlers()
27 {
28 return array(
29 'lists' => $this->make_hook('lists', AUTH_MDP),
30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH),
31 'lists/create' => $this->make_hook('create', AUTH_MDP),
32
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE),
34 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE),
35 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE),
36 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE),
37 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
38
39 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP),
40 'lists/admin' => $this->make_hook('admin', AUTH_MDP),
41 'lists/options' => $this->make_hook('options', AUTH_MDP),
42 'lists/delete' => $this->make_hook('delete', AUTH_MDP),
43
44 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP),
45 'lists/check' => $this->make_hook('check', AUTH_MDP),
46 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'),
47 );
48 }
49
50 function prepare_client(&$page, $user = null)
51 {
52 global $globals;
53
54 $this->load('lists.inc.php');
55 if (is_null($user)) {
56 $user = S::user();
57 }
58
59 $this->client = new MMList($user);
60 return $globals->mail->domain;
61 }
62
63 function get_pending_ops($domain, $list)
64 {
65 list($subs,$mails) = $this->client->get_pending_ops($list);
66 $res = XDB::query("SELECT mid
67 FROM email_list_moderate
68 WHERE ml = {?} AND domain = {?}",
69 $list, $domain);
70 $mids = $res->fetchColumn();
71 foreach ($mails as $key=>$mail) {
72 if (in_array($mail['id'], $mids)) {
73 unset($mails[$key]);
74 }
75 }
76 return array($subs, $mails);
77 }
78
79 function handler_lists(&$page)
80 {
81 function filter_owner($list)
82 {
83 return $list['own'];
84 }
85
86 function filter_member($list)
87 {
88 return $list['sub'];
89 }
90
91 $domain = $this->prepare_client($page);
92
93 $page->changeTpl('lists/index.tpl');
94 $page->addJsLink('ajax.js');
95 $page->setTitle('Listes de diffusion');
96
97
98 if (Get::has('del')) {
99 S::assert_xsrf_token();
100 $this->client->unsubscribe(Get::v('del'));
101 pl_redirect('lists');
102 }
103 if (Get::has('add')) {
104 S::assert_xsrf_token();
105 $this->client->subscribe(Get::v('add'));
106 pl_redirect('lists');
107 }
108 if (Post::has('promo_add')) {
109 S::assert_xsrf_token();
110
111 $promo = Post::i('promo_add');
112 if ($promo >= 1900 and $promo < 2100) {
113 $this->client->subscribe("promo$promo");
114 } else {
115 $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres.");
116 }
117 }
118
119 if (!is_null($listes = $this->client->get_lists())) {
120 $owner = array_filter($listes, 'filter_owner');
121 $listes = array_diff_key($listes, $owner);
122 $member = array_filter($listes, 'filter_member');
123 $listes = array_diff_key($listes, $member);
124 foreach ($owner as $key => $liste) {
125 list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
126 $owner[$key]['subscriptions'] = $subs;
127 $owner[$key]['mails'] = $mails;
128 }
129 $page->register_modifier('hdc', 'list_header_decode');
130 $page->assign_by_ref('owner', $owner);
131 $page->assign_by_ref('member', $member);
132 $page->assign_by_ref('public', $listes);
133 }
134 }
135
136 function handler_ajax(&$page, $list = null)
137 {
138 pl_content_headers("text/html");
139 $domain = $this->prepare_client($page);
140 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
141 S::assert_xsrf_token();
142
143 if (Get::has('unsubscribe')) {
144 $this->client->unsubscribe($list);
145 }
146 if (Get::has('subscribe')) {
147 $this->client->subscribe($list);
148 }
149 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
150 $this->client->handle_request($list, Get::v('sadd'), 4, '');
151 }
152 if (Get::has('mid')) {
153 $this->moderate_mail($domain, $list, Get::i('mid'));
154 }
155
156 list($liste, $members, $owners) = $this->client->get_members($list);
157 if ($liste['own']) {
158 list($subs,$mails) = $this->get_pending_ops($domain, $list);
159 $liste['subscriptions'] = $subs;
160 $liste['mails'] = $mails;
161 }
162 $page->register_modifier('hdc', 'list_header_decode');
163 $page->assign_by_ref('liste', $liste);
164 }
165
166 function handler_create(&$page)
167 {
168 global $globals;
169
170 $page->changeTpl('lists/create.tpl');
171
172 $user_promo = S::i('promo');
173 $year = date('Y');
174 $month = date('m');
175 $young_promo = $very_young_promo = 0;
176 if ((($year > $user_promo) && ($month > 3)) && ($year < $user_promo + 5)) {
177 $young_promo = 1;
178 }
179 if ((($year > $user_promo) && ($month > 7)) && (($year < $user_promo + 1) && ($month < 8))) {
180 $very_young_promo = 1;
181 }
182 $page->assign('young_promo', $young_promo);
183 $page->assign('very_young_promo', $very_young_promo);
184
185 $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
186 $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
187
188 // click on validate button 'add_owner_sub' or type <enter>
189 if (Post::has('add_owner_sub') && Post::has('add_owner')) {
190 // if we want to add an owner and then type <enter>, then both
191 // add_owner_sub and add_owner are filled.
192 $oforlifes = User::getBulkForlifeEmails(Post::v('add_owner'), true);
193 $mforlifes = User::getBulkForlifeEmails(Post::v('add_member'), true);
194 if (!is_null($oforlifes)) {
195 $owners = array_merge($owners, $oforlifes);
196 }
197 // if we want to add a member and then type <enter>, then
198 // add_owner_sub is filled, whereas add_owner is empty.
199 if (!is_null($mforlifes)) {
200 $members = array_merge($members, $mforlifes);
201 }
202 }
203
204 // click on validate button 'add_member_sub'
205 if (Post::has('add_member_sub') && Post::has('add_member')) {
206 $forlifes = User::getBulkForlifeEmails(Post::v('add_member'), true);
207 if (!is_null($forlifes)) {
208 $members = array_merge($members, $forlifes);
209 }
210 }
211 if (Post::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
212 $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true);
213 if (!$upload) {
214 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
215 } else {
216 $forlifes = User::getBulkForlifeEmails($upload->getContents(), true);
217 if (!is_null($forlifes)) {
218 $members = array_merge($members, $forlifes);
219 }
220 }
221 }
222
223 ksort($owners);
224 $owners = array_unique($owners);
225 ksort($members);
226 $members = array_unique($members);
227
228 $page->assign('owners', join("\n", $owners));
229 $page->assign('members', join("\n", $members));
230
231 if (!Post::has('submit')) {
232 return;
233 } else {
234 S::assert_xsrf_token();
235 }
236
237 $asso = Post::v('asso');
238 $liste = Post::v('liste');
239
240 if (empty($liste)) {
241 $page->trigError('Le champ «&nbsp;adresse souhaitée&nbsp;» est vide.');
242 }
243 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
244 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
245 }
246
247 if (($asso == "binet") || ($asso == "alias")) {
248 $promo = Post::i('promo');
249 $domain = $promo . '.' . $globals->mail->domain;
250
251 if (($promo < 1921) || ($promo > date('Y'))) {
252 $page->trigError('La promotion est mal renseignée, elle doit être du type&nbsp;: 2004.');
253 }
254
255 $new = $liste . '@' . $domain;
256 $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', $new);
257
258 } else {
259 if ($asso == "groupex") {
260 $groupex_name = Post::v('groupex_name');
261
262 $res_groupe = XDB::query('SELECT mail_domain FROM groups WHERE nom={?}', $groupex_name);
263 $domain = $res_groupe->fetchOneCell();
264
265 if (!$domain) {
266 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
267 }
268
269 $new = $liste . '@' . $domain;
270 $res = XDB::query('SELECT COUNT(*) FROM virtual WHERE alias={?}', $new);
271 } else {
272 $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
273 $domain = $globals->mail->domain;
274 }
275 }
276
277 $n = $res->fetchOneCell();
278
279 if ($n) {
280 $page->trigError("L'«&nbsp;adresse souhaitée&nbsp;» est déjà prise.");
281 }
282
283 if (!Post::v('desc')) {
284 $page->trigError('Le sujet est vide.');
285 }
286
287 if (!count($owners)) {
288 $page->trigError('Il n\'y a pas de gestionnaire.');
289 }
290
291 if (count($members)<4) {
292 $page->trigError('Il n\'y a pas assez de membres.');
293 }
294
295 if (!$page->nb_errs()) {
296 $page->trigSuccess('Demande de création envoyée&nbsp;!');
297 $page->assign('created', true);
298 require_once 'validations.inc.php';
299 $req = new ListeReq(S::user(), $asso, $liste, $domain,
300 Post::v('desc'), Post::i('advertise'),
301 Post::i('modlevel'), Post::i('inslevel'),
302 $owners, $members);
303 $req->submit();
304 }
305 }
306
307 function handler_members(&$page, $liste = null)
308 {
309 if (is_null($liste)) {
310 return PL_NOT_FOUND;
311 }
312
313 $this->prepare_client($page);
314
315 $page->changeTpl('lists/members.tpl');
316
317 if (Get::has('del')) {
318 S::assert_xsrf_token();
319 $this->client->unsubscribe($liste);
320 pl_redirect('lists/members/'.$liste);
321 }
322
323 if (Get::has('add')) {
324 S::assert_xsrf_token();
325 $this->client->subscribe($liste);
326 pl_redirect('lists/members/'.$liste);
327 }
328
329 $members = $this->client->get_members($liste);
330
331 $tri_promo = !Env::b('alpha');
332
333 if (list($det,$mem,$own) = $members) {
334 $membres = list_sort_members($mem, $tri_promo);
335 $moderos = list_sort_owners($own, $tri_promo);
336
337 $page->assign_by_ref('details', $det);
338 $page->assign_by_ref('members', $membres);
339 $page->assign_by_ref('owners', $moderos);
340 $page->assign('nb_m', count($mem));
341 } else {
342 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
343 }
344 }
345
346 function handler_csv(PlPage &$page, $liste = null)
347 {
348 if (is_null($liste)) {
349 return PL_NOT_FOUND;
350 }
351 $this->prepare_client($page);
352 $members = $this->client->get_members($liste);
353 $list = list_fetch_names(list_extract_members($members[1]));
354 pl_content_headers("text/x-csv");
355
356 echo "email,nom,prenom,promo\n";
357 foreach ($list as $member) {
358 echo @$member['email'] . ',' . @$member['nom'] . ',' . @$member['prenom'] . ',' . @$member['promo'] . "\n";
359 }
360 exit;
361 }
362
363 function handler_annu(&$page, $liste = null, $action = null, $subaction = null)
364 {
365 if (is_null($liste)) {
366 return PL_NOT_FOUND;
367 }
368
369 $this->prepare_client($page);
370
371 if (Get::has('del')) {
372 S::assert_xsrf_token();
373 $this->client->unsubscribe($liste);
374 pl_redirect('lists/annu/'.$liste);
375 }
376 if (Get::has('add')) {
377 S::assert_xsrf_token();
378 $this->client->subscribe($liste);
379 pl_redirect('lists/annu/'.$liste);
380 }
381
382 $owners = $this->client->get_owners($liste);
383 if (!is_array($owners)) {
384 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
385 }
386
387 global $platal;
388 list(,$members) = $this->client->get_members($liste);
389 $users = array();
390 foreach ($members as $m) {
391 $users[] = $m[1];
392 }
393 require_once 'userset.inc.php';
394 $view = new ArraySet($users);
395 $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true));
396 if (empty($GLOBALS['IS_XNET_SITE'])) {
397 $view->addMod('minifiche', 'Mini-fiches', false);
398 }
399 // TODO: Reactivate when the new map is completed.
400 // $view->addMod('geoloc', 'Planisphère');
401 $view->apply("lists/annu/$liste", $page, $action, $subaction);
402 if ($action == 'geoloc' && $subaction) {
403 return;
404 }
405
406 $page->changeTpl('lists/annu.tpl');
407 $moderos = list_sort_owners($owners[1]);
408 $page->assign_by_ref('details', $owners[0]);
409 $page->assign_by_ref('owners', $moderos);
410 }
411
412 function handler_archives(&$page, $liste = null, $action = null, $artid = null)
413 {
414 global $globals;
415
416 if (is_null($liste)) {
417 return PL_NOT_FOUND;
418 }
419
420 $domain = $this->prepare_client($page);
421
422 $page->changeTpl('lists/archives.tpl');
423
424 if (list($det) = $this->client->get_members($liste)) {
425 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
426 && !$det['own'] && ($det['sub'] < 2)) {
427 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
428 }
429 $get = Array('listname' => $liste, 'domain' => $domain);
430 if (Post::has('updateall')) {
431 $get['updateall'] = Post::v('updateall');
432 }
433 require_once 'banana/ml.inc.php';
434 get_banana_params($get, null, $action, $artid);
435 run_banana($page, 'MLBanana', $get);
436 } else {
437 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
438 }
439 }
440
441 function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
442 {
443 if (!$liste) {
444 return PL_NOT_FOUND;
445 }
446 $user = Platal::session()->tokenAuth($alias, $hash);
447 if (is_null($user)) {
448 return PL_FORBIDDEN;
449 }
450
451 $domain = $this->prepare_client($page, $user);
452 if (list($det) = $this->client->get_members($liste)) {
453 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
454 && !$det['own'] && ($det['sub'] < 2)) {
455 exit;
456 }
457 require_once('banana/ml.inc.php');
458 $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
459 $banana->run();
460 }
461 exit;
462 }
463
464 function moderate_mail($domain, $liste, $mid)
465 {
466 if (Env::has('mok')) {
467 $action = 'accept';
468 } elseif (Env::has('mno')) {
469 $action = 'refuse';
470 } elseif (Env::has('mdel')) {
471 $action = 'delete';
472 } else {
473 return false;
474 }
475 Get::kill('mid');
476 return XDB::execute("INSERT IGNORE INTO email_list_moderate
477 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
478 $liste, $domain, $mid, S::i('uid'), $action, Post::v('reason'));
479 }
480
481 function handler_moderate(&$page, $liste = null)
482 {
483 if (is_null($liste)) {
484 return PL_NOT_FOUND;
485 }
486
487 $domain = $this->prepare_client($page);
488
489 $page->changeTpl('lists/moderate.tpl');
490
491 $page->register_modifier('hdc', 'list_header_decode');
492
493 if (Env::has('sadd') || Env::has('sdel')) {
494 S::assert_xsrf_token();
495
496 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
497 $sub = $this->client->get_pending_sub($liste, Env::v('sadd'));
498 $this->client->handle_request($liste,Env::v('sadd'),4,'');
499 $info = "validée";
500 }
501 if (Post::has('sdel')) { /* 2 = REJECT */
502 $sub = $this->client->get_pending_sub($liste, Env::v('sdel'));
503 $this->client->handle_request($liste, Post::v('sdel'), 2, utf8_decode(Post::v('reason')));
504 $info = "refusée";
505 }
506 if ($sub) {
507 $mailer = new PlMailer();
508 $mailer->setFrom("$liste-bounces@{$domain}");
509 $mailer->addTo("$liste-owner@{$domain}");
510 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
511 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
512 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::v('prenom') . ' '
513 . S::v('nom') . '(' . S::v('promo') . ")\n";
514 if (trim(Post::v('reason'))) {
515 $text .= "\nLa raison invoquée est :\n" . Post::v('reason');
516 }
517 $mailer->setTxtBody(wordwrap($text, 72));
518 $mailer->send();
519 }
520 if (Env::has('sadd')) {
521 pl_redirect('lists/moderate/'.$liste);
522 }
523 }
524
525 if (Post::has('moderate_mails') && Post::has('select_mails')) {
526 S::assert_xsrf_token();
527
528 $mails = array_keys(Post::v('select_mails'));
529 foreach($mails as $mail) {
530 $this->moderate_mail($domain, $liste, $mail);
531 }
532 } elseif (Env::has('mid')) {
533 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
534 require_once 'banana/moderate.inc.php';
535
536 $page->changeTpl('lists/moderate_mail.tpl');
537 $params = array('listname' => $liste, 'domain' => $domain,
538 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
539 $params['client'] = $this->client;
540 run_banana($page, 'ModerationBanana', $params);
541
542 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
543 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
544 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
545 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
546 $msg = str_replace("%(listname)s", $liste, $msg);
547 $page->assign('msg', $msg);
548 return;
549 }
550
551 $this->moderate_mail($domain, $liste, Env::i('mid'));
552 } elseif (Env::has('sid')) {
553 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
554 foreach($subs as $user) {
555 if ($user['id'] == Env::v('sid')) {
556 $page->changeTpl('lists/moderate_sub.tpl');
557 $page->assign('del_user', $user);
558 return;
559 }
560 }
561 }
562
563 }
564
565 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
566 foreach ($mails as $key=>$mail) {
567 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
568 if ($mail['fromx']) {
569 $page->assign('with_fromx', true);
570 } else {
571 $page->assign('with_nonfromx', true);
572 }
573 }
574 $page->assign_by_ref('subs', $subs);
575 $page->assign_by_ref('mails', $mails);
576 } else {
577 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
578 }
579 }
580
581 static public function no_login_callback($login)
582 {
583 global $list_unregistered, $globals;
584
585 /* TODO: fixes this call to a removed function. */
586 $users = get_not_registered_user($login, true);
587 if ($users && $users->total()) {
588 if (!isset($list_unregistered)) {
589 $list_unregistered = array();
590 }
591 $list_unregistered[$login] = $users;
592 } else {
593 list($name, $dom) = @explode('@', $login);
594 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
595 User::_default_user_callback($login);
596 }
597 }
598 }
599
600 function handler_admin(&$page, $liste = null)
601 {
602 global $globals;
603
604 if (is_null($liste)) {
605 return PL_NOT_FOUND;
606 }
607
608 $domain = $this->prepare_client($page);
609
610 $page->changeTpl('lists/admin.tpl');
611
612 if (Env::has('send_mark')) {
613 S::assert_xsrf_token();
614
615 $actions = Env::v('mk_action');
616 $uids = Env::v('mk_uid');
617 $mails = Env::v('mk_email');
618 foreach ($actions as $key=>$action) {
619 switch ($action) {
620 case 'none':
621 break;
622
623 case 'marketu': case 'markets':
624 require_once 'emails.inc.php';
625 $mail = valide_email($mails[$key]);
626 if (isvalid_email_redirection($mail)) {
627 $from = ($action == 'marketu') ? 'user' : 'staff';
628 $market = Marketing::get($uids[$key], $mail);
629 if (!$market) {
630 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid'));
631 $market->add();
632 break;
633 }
634 }
635
636 default:
637 XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
638 VALUES ({?}, \'list\', {?}, {?})',
639 $uids[$key], $liste, $domain);
640 }
641 }
642 }
643
644 if (Env::has('add_member')) {
645 S::assert_xsrf_token();
646
647 $members = User::getBulkForlifeEmails(Env::v('add_member'),
648 true,
649 array('ListsModule', 'no_login_callback'));
650 $arr = $this->client->mass_subscribe($liste, $members);
651 if (is_array($arr)) {
652 foreach($arr as $addr) {
653 $page->trigSuccess("{$addr[0]} inscrit.");
654 }
655 }
656 }
657
658 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
659 S::assert_xsrf_token();
660
661 $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true);
662 if (!$upload) {
663 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
664 } else {
665 $members = User::getBulkForlifeEmails($upload->getContents(),
666 true,
667 array('ListsModule', 'no_login_callback'));
668 $arr = $this->client->mass_subscribe($liste, $members);
669 if (is_array($arr)) {
670 foreach($arr as $addr) {
671 $page->trigSuccess("{$addr[0]} inscrit.");
672 }
673 }
674 }
675 }
676
677 if (Env::has('del_member')) {
678 S::assert_xsrf_token();
679
680 if (strpos(Env::v('del_member'), '@') === false) {
681 $this->client->mass_unsubscribe(
682 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
683 } else {
684 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
685 }
686 pl_redirect('lists/admin/'.$liste);
687 }
688
689 if (Env::has('add_owner')) {
690 S::assert_xsrf_token();
691
692 $owners = User::getBulkForlifeEmails(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback'));
693 if ($owners) {
694 foreach ($owners as $login) {
695 if ($this->client->add_owner($liste, $login)) {
696 $page->trigSuccess($login ." ajouté aux modérateurs.");
697 }
698 }
699 }
700 }
701
702 if (Env::has('del_owner')) {
703 S::assert_xsrf_token();
704
705 if (strpos(Env::v('del_owner'), '@') === false) {
706 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
707 } else {
708 $this->client->del_owner($liste, Env::v('del_owner'));
709 }
710 pl_redirect('lists/admin/'.$liste);
711 }
712
713 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
714 global $list_unregistered;
715 if ($list_unregistered) {
716 $page->assign_by_ref('unregistered', $list_unregistered);
717 }
718 $membres = list_sort_members($mem, @$tri_promo);
719 $moderos = list_sort_owners($own, @$tri_promo);
720
721 $page->assign_by_ref('details', $det);
722 $page->assign_by_ref('members', $membres);
723 $page->assign_by_ref('owners', $moderos);
724 $page->assign('np_m', count($mem));
725
726 } else {
727 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
728 . " Si tu penses qu'il s'agit d'une erreur, "
729 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
730 }
731 }
732
733 function handler_options(&$page, $liste = null)
734 {
735 if (is_null($liste)) {
736 return PL_NOT_FOUND;
737 }
738
739 $this->prepare_client($page);
740
741 $page->changeTpl('lists/options.tpl');
742
743 if (Post::has('submit')) {
744 S::assert_xsrf_token();
745
746 $values = $_POST;
747 $values = array_map('utf8_decode', $values);
748 $spamlevel = intval($values['bogo_level']);
749 $unsurelevel = intval($values['unsure_level']);
750 if ($spamlevel == 0) {
751 $unsurelevel = 0;
752 }
753 if ($spamlevel > 3 || $spamlevel < 0 || $unsurelevel < 0 || $unsurelevel > 1) {
754 $page->trigError("Réglage de l'antispam non valide");
755 } else {
756 $this->client->set_bogo_level($liste, ($spamlevel << 1) + $unsurelevel);
757 }
758 switch($values['moderate']) {
759 case '0':
760 $values['generic_nonmember_action'] = 0;
761 $values['default_member_moderation'] = 0;
762 break;
763 case '1':
764 $values['generic_nonmember_action'] = 1;
765 $values['default_member_moderation'] = 0;
766 break;
767 case '2':
768 $values['generic_nonmember_action'] = 1;
769 $values['default_member_moderation'] = 1;
770 break;
771 }
772 unset($values['submit'], $values['bogo_level'], $values['moderate']);
773 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
774 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
775 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
776 if (isset($values['subject_prefix'])) {
777 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
778 }
779 $this->client->set_owner_options($liste, $values);
780 } elseif (isvalid_email(Post::v('atn_add'))) {
781 S::assert_xsrf_token();
782 $this->client->add_to_wl($liste, Post::v('atn_add'));
783 } elseif (Get::has('atn_del')) {
784 S::assert_xsrf_token();
785 $this->client->del_from_wl($liste, Get::v('atn_del'));
786 pl_redirect('lists/options/'.$liste);
787 }
788
789 if (list($details,$options) = $this->client->get_owner_options($liste)) {
790 $page->assign_by_ref('details', $details);
791 $page->assign_by_ref('options', $options);
792 $bogo_level = intval($this->client->get_bogo_level($liste));
793 $page->assign('unsure_level', $bogo_level & 1);
794 $page->assign('bogo_level', $bogo_level >> 1);
795 } else {
796 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
797 }
798 }
799
800 function handler_delete(&$page, $liste = null)
801 {
802 global $globals;
803 if (is_null($liste)) {
804 return PL_NOT_FOUND;
805 }
806
807 $domain = $this->prepare_client($page);
808 if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
809 $domain = '';
810 $table = 'aliases';
811 $type = 'liste';
812 } else {
813 $domain = '@' . $domain;
814 $table = 'virtual';
815 $type = 'list';
816 }
817
818 $page->changeTpl('lists/delete.tpl');
819 if (Post::v('valid') == 'OUI') {
820 S::assert_xsrf_token();
821
822 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
823 foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) {
824 XDB::execute("DELETE FROM $table
825 WHERE type={?} AND alias={?}",
826 $type, $liste.$app.$domain);
827 }
828 $page->assign('deleted', true);
829 $page->trigSuccess('La liste a été détruite&nbsp;!');
830 } else {
831 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
832 . 'Contact les administrateurs du site pour régler le problème : '
833 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
834 }
835 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
836 if (!$details['own']) {
837 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
838 }
839 $page->assign_by_ref('details', $details);
840 $page->assign_by_ref('options', $options);
841 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
842 } else {
843 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
844 }
845 }
846
847 function handler_soptions(&$page, $liste = null)
848 {
849 if (is_null($liste)) {
850 return PL_NOT_FOUND;
851 }
852
853 $this->prepare_client($page);
854
855 $page->changeTpl('lists/soptions.tpl');
856
857 if (Post::has('submit')) {
858 S::assert_xsrf_token();
859
860 $values = $_POST;
861 $values = array_map('utf8_decode', $values);
862 unset($values['submit']);
863 $values['advertised'] = empty($values['advertised']) ? false : true;
864 $values['archive'] = empty($values['archive']) ? false : true;
865 $this->client->set_admin_options($liste, $values);
866 }
867
868 if (list($details,$options) = $this->client->get_admin_options($liste)) {
869 $page->assign_by_ref('details', $details);
870 $page->assign_by_ref('options', $options);
871 } else {
872 $page->kill("La liste n'existe pas.");
873 }
874 }
875
876 function handler_check(&$page, $liste = null)
877 {
878 if (is_null($liste)) {
879 return PL_NOT_FOUND;
880 }
881
882 $this->prepare_client($page);
883
884 $page->changeTpl('lists/check.tpl');
885
886 if (Post::has('correct')) {
887 S::assert_xsrf_token();
888 $this->client->check_options($liste, true);
889 }
890
891 if (list($details,$options) = $this->client->check_options($liste)) {
892 $page->assign_by_ref('details', $details);
893 $page->assign_by_ref('options', $options);
894 } else {
895 $page->kill("La liste n'existe pas.");
896 }
897 }
898
899 function handler_admin_all(&$page)
900 {
901 $page->changeTpl('lists/admin_all.tpl');
902 $page->setTitle('Administration - Mailing lists');
903
904 $this->prepare_client($page);
905 $listes = $this->client->get_all_lists();
906 $page->assign_by_ref('listes', $listes);
907 }
908 }
909
910 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
911 ?>