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