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