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