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