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