Close #407: RSS feed for Forums and MLs
[platal.git] / modules / lists.php
... / ...
CommitLineData
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
22class ListsModule extends PLModule
23{
24 var $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, '', NO_AUTH),
31 'lists/create' => $this->make_hook('create', AUTH_MDP),
32
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE),
34 'lists/trombi' => $this->make_hook('trombi', 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, 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 changeTpl($tpl)
229 {
230 if (!empty($GLOBALS['IS_XNET_SITE'])) {
231 new_group_open_page($tpl);
232 } else {
233 global $page;
234 $page->changeTpl($tpl);
235 }
236 }
237
238 function handler_members(&$page, $liste = null)
239 {
240 if (is_null($liste)) {
241 return PL_NOT_FOUND;
242 }
243
244 $this->prepare_client($page);
245
246 $this->changeTpl('lists/members.tpl');
247
248 if (Get::has('del')) {
249 $this->client->unsubscribe($liste);
250 pl_redirect('lists/members/'.$liste);
251 }
252
253 if (Get::has('add')) {
254 $this->client->subscribe($liste);
255 pl_redirect('lists/members/'.$liste);
256 }
257
258 $members = $this->client->get_members($liste);
259
260 $tri_promo = !Env::b('alpha');
261
262 if (list($det,$mem,$own) = $members) {
263 $membres = list_sort_members($mem, $tri_promo);
264 $moderos = list_sort_owners($own, $tri_promo);
265
266 $page->assign_by_ref('details', $det);
267 $page->assign_by_ref('members', $membres);
268 $page->assign_by_ref('owners', $moderos);
269 $page->assign('nb_m', count($mem));
270 } else {
271 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
272 }
273 }
274
275 function _get_list($offset, $limit)
276 {
277 global $platal;
278 list($total, $members) = $this->client->get_members_limit($platal->argv[1], $offset, $limit);
279
280 $membres = Array();
281 foreach ($members as $member) {
282 list($m) = explode('@',$member[1]);
283 $res = XDB::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
284 promo, a.alias AS forlife
285 FROM auth_user_md5 AS u
286 INNER JOIN aliases AS a ON u.user_id = a.id
287 INNER JOIN photo AS p ON p.uid = u.user_id
288 WHERE a.alias = {?}", $m);
289 if ($tmp = $res->fetchOneAssoc()) {
290 $membres[$tmp['nom']] = $tmp;
291 } else {
292 $total--;
293 }
294 }
295 uasort($membres, create_function('$a,$b', 'return $a["promo"] > $b["promo"] || '
296 . '($a["promo"] == $b["promo"] && (strcmp($a["nom"], $b["nom"]) > 0 || '
297 . '($a["nom"] == $b["nom"] && strcmp($a["prenom"], $b["prenom"]) > 0)));'));
298 return array($total, $membres);
299 }
300
301 function handler_trombi(&$page, $liste = null)
302 {
303 if (is_null($liste)) {
304 return PL_NOT_FOUND;
305 }
306
307 $this->prepare_client($page);
308
309 $this->changeTpl('lists/trombi.tpl');
310
311 if (Get::has('del')) {
312 $this->client->unsubscribe($liste);
313 pl_redirect('lists/trombi/'.$liste);
314 }
315 if (Get::has('add')) {
316 $this->client->subscribe($liste);
317 pl_redirect('lists/trombi/'.$liste);
318 }
319
320 $owners = $this->client->get_owners($liste);
321
322 if (is_array($owners)) {
323 $moderos = list_sort_owners($owners[1]);
324
325 $page->assign_by_ref('details', $owners[0]);
326 $page->assign_by_ref('owners', $moderos);
327
328 $trombi = new Trombi(array(&$this, '_get_list'));
329 $page->assign('trombi', $trombi);
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_archives(&$page, $liste = null, $action = null, $artid = null)
336 {
337 global $globals;
338
339 if (is_null($liste)) {
340 return PL_NOT_FOUND;
341 }
342
343 $domain = $this->prepare_client($page);
344
345 $this->changeTpl('lists/archives.tpl');
346
347 if (list($det) = $this->client->get_members($liste)) {
348 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
349 && !$det['own'] && ($det['sub'] < 2)) {
350 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
351 }
352 $get = Array('listname' => $liste, 'domain' => $domain);
353 if (Post::has('updateall')) {
354 $get['updateall'] = Post::v('updateall');
355 }
356 if (!is_null($action)) {
357 if ($action == 'new') {
358 $get['action'] = 'new';
359 } elseif (!is_null($artid)) {
360 $get['artid'] = $artid;
361 if ($action == 'reply') {
362 $get['action'] = 'new';
363 } elseif ($action == 'cancel') {
364 $get['action'] = $action;
365 } elseif ($action == 'from') {
366 $get['first'] = $artid;
367 unset($get['artid']);
368 } elseif ($action == 'read') {
369 $get['part'] = @$_GET['part'];
370 } elseif ($action == 'source') {
371 $get['part'] = 'source';
372 } elseif ($action == 'xface') {
373 $get['part'] = 'xface';
374 } elseif ($action) {
375 $get['part'] = str_replace('.', '/', $action);
376 }
377 if (Get::v('action') == 'showext') {
378 $get['action'] = 'showext';
379 }
380 }
381 }
382 require_once('banana/ml.inc.php');
383 $banana = new MLBanana($get);
384 $page->assign('banana', $banana->run());
385 $page->addCssInline($banana->css());
386 $page->addCssLink('banana.css');
387 $rss = $banana->feed();
388 if ($rss) {
389 $page->setRssLink('Banana :: ' . $list, $rss);
390 }
391 new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time');
392 } else {
393 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
394 }
395 }
396
397 function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
398 {
399 require_once('rss.inc.php');
400 $uid = init_rss(null, $alias, $hash);
401 if (!$uid || !$liste) {
402 exit;
403 }
404
405 $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
406 FROM auth_user_md5 AS u
407 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
408 WHERE u.user_id = {?}", $uid);
409 $row = $res->fetchOneAssoc();
410 $_SESSION = array_merge($row, $_SESSION);
411
412 $domain = $this->prepare_client($page);
413 if (list($det) = $this->client->get_members($liste)) {
414 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
415 && !$det['own'] && ($det['sub'] < 2)) {
416 exit;
417 }
418 require_once('banana/ml.inc.php');
419 $banana = new MLBanana(Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
420 echo $banana->run();
421 }
422 exit;
423 }
424
425 function moderate_mail($domain, $liste, $mid)
426 {
427 $mail = $this->client->get_pending_mail($liste, $mid);
428 $reason = '';
429
430 $prenom = S::v('prenom');
431 $nom = S::v('nom');
432
433 if (Env::has('mok')) {
434 $action = 1; /** 2 = ACCEPT **/
435 $subject = "Message accepté";
436 $append .= "a été accepté par $prenom $nom.\n";
437 } elseif (Env::has('mno')) {
438 $action = 2; /** 2 = REJECT **/
439 $subject = "Message refusé";
440 $reason = Post::v('reason');
441 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
442 . $reason;
443 } elseif (Env::has('mdel')) {
444 $action = 3; /** 3 = DISCARD **/
445 $subject = "Message supprimé";
446 $append = "a été supprimé par $prenom $nom.\n\n"
447 . "Rappel: il ne faut utiliser cette opération "
448 . "que dans le cas de spams ou de virus !\n";
449 }
450
451 if (isset($action) && $this->client->handle_request($liste, $mid, $action, $reason)) {
452 $texte = "le message suivant :\n\n"
453 ." Auteur: {$mail['sender']}\n"
454 ." Sujet : « {$mail['subj']} »\n"
455 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
456 .$append;
457 $mailer = new PlMailer();
458 $mailer->addTo("$liste-owner@{$domain}");
459 $mailer->setFrom("$liste-bounces@{$domain}");
460 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
461 $mailer->setSubject($subject);
462 $mailer->setTxtBody(wordwrap($texte,72));
463 $mailer->send();
464 Get::kill('mid');
465 }
466
467 return $mail;
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 $this->changeTpl('lists/moderate.tpl');
479
480 $page->register_modifier('hdc', 'list_header_decode');
481
482 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
483 $this->client->handle_request($liste,Env::v('sadd'),4,'');
484 pl_redirect('lists/moderate/'.$liste);
485 }
486 if (Post::has('sdel')) { /* 2 = REJECT */
487 $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason'));
488 }
489
490 if (Post::has('moderate_mails') && Post::has('select_mails')) {
491 $mails = array_keys(Post::v('select_mails'));
492 foreach($mails as $mail) {
493 $this->moderate_mail($domain, $liste, $mail);
494 }
495 } elseif (Env::has('mid')) {
496 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
497 require_once('banana/moderate.inc.php');
498 $params = array('listname' => $liste, 'domain' => $domain,
499 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
500 $banana = new ModerationBanana($params, $this->client);
501 $res = $banana->run();
502 $page->addCssInline($banana->css());
503
504 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
505 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
506 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
507 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
508 $msg = str_replace("%(listname)s", $liste, $msg);
509 $page->assign('msg', $msg);
510
511 $page->addCssLink('banana.css');
512 $this->changeTpl('lists/moderate_mail.tpl');
513 $page->assign_by_ref('mail', $res);
514 return;
515 }
516
517 $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
518 } elseif (Env::has('sid')) {
519 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
520 foreach($subs as $user) {
521 if ($user['id'] == Env::v('sid')) {
522 $this->changeTpl('lists/moderate_sub.tpl');
523 $page->assign('del_user', $user);
524 return;
525 }
526 }
527 }
528
529 }
530
531 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
532 foreach ($mails as $key=>$mail) {
533 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
534 }
535 $page->assign_by_ref('subs', $subs);
536 $page->assign_by_ref('mails', $mails);
537 } else {
538 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
539 }
540 }
541
542 function handler_admin(&$page, $liste = null)
543 {
544 global $globals;
545
546 if (is_null($liste)) {
547 return PL_NOT_FOUND;
548 }
549
550 $this->prepare_client($page);
551
552 $this->changeTpl('lists/admin.tpl');
553
554 if (Env::has('add_member')) {
555 require_once('user.func.inc.php');
556 $members = get_users_forlife_list(Env::v('add_member'));
557 $arr = $this->client->mass_subscribe($liste, $members);
558 if (is_array($arr)) {
559 foreach($arr as $addr) {
560 $page->trig("{$addr[0]} inscrit.");
561 }
562 }
563 }
564
565 if (Env::has('del_member')) {
566 if (strpos(Env::v('del_member'), '@') === false) {
567 $this->client->mass_unsubscribe(
568 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
569 } else {
570 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
571 }
572 pl_redirect('lists/admin/'.$liste);
573 }
574
575 if (Env::has('add_owner')) {
576 require_once('user.func.inc.php');
577 $owners = get_users_forlife_list(Env::v('add_owner'));
578 if ($owners) {
579 foreach ($owners as $login) {
580 if ($this->client->add_owner($liste, $login)) {
581 $page->trig($alias." ajouté aux modérateurs.");
582 }
583 }
584 }
585 }
586
587 if (Env::has('del_owner')) {
588 if (strpos(Env::v('del_owner'), '@') === false) {
589 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
590 } else {
591 $this->client->del_owner($liste, Env::v('del_owner'));
592 }
593 pl_redirect('lists/admin/'.$liste);
594 }
595
596 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
597 $membres = list_sort_members($mem, @$tri_promo);
598 $moderos = list_sort_owners($own, @$tri_promo);
599
600 $page->assign_by_ref('details', $det);
601 $page->assign_by_ref('members', $membres);
602 $page->assign_by_ref('owners', $moderos);
603 $page->assign('np_m', count($mem));
604
605 } else {
606 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
607 ." Si tu penses qu'il s'agit d'une erreur, "
608 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
609 }
610 }
611
612 function handler_options(&$page, $liste = null)
613 {
614 if (is_null($liste)) {
615 return PL_NOT_FOUND;
616 }
617
618 $this->prepare_client($page);
619
620 $this->changeTpl('lists/options.tpl');
621
622 if (Post::has('submit')) {
623 $values = $_POST;
624 $values = array_map('utf8_decode', $values);
625 $this->client->set_bogo_level($liste, intval($values['bogo_level']));
626 switch($values['moderate']) {
627 case '0':
628 $values['generic_nonmember_action'] = 0;
629 $values['default_member_moderation'] = 0;
630 break;
631 case '1':
632 $values['generic_nonmember_action'] = 1;
633 $values['default_member_moderation'] = 0;
634 break;
635 case '2':
636 $values['generic_nonmember_action'] = 1;
637 $values['default_member_moderation'] = 1;
638 break;
639 }
640 unset($values['submit'], $values['bogo_level'], $values['moderate']);
641 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
642 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
643 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
644 if (isset($values['subject_prefix'])) {
645 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
646 }
647 $this->client->set_owner_options($liste, $values);
648 } elseif (isvalid_email(Post::v('atn_add'))) {
649 $this->client->add_to_wl($liste, Post::v('atn_add'));
650 } elseif (Get::has('atn_del')) {
651 $this->client->del_from_wl($liste, Get::v('atn_del'));
652 pl_redirect('lists/options/'.$liste);
653 }
654
655 if (list($details,$options) = $this->client->get_owner_options($liste)) {
656 $page->assign_by_ref('details', $details);
657 $page->assign_by_ref('options', $options);
658 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
659 } else {
660 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
661 }
662 }
663
664 function handler_delete(&$page, $liste = null)
665 {
666 global $globals;
667 if (is_null($liste)) {
668 return PL_NOT_FOUND;
669 }
670
671 $domain = $this->prepare_client($page);
672 if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
673 $domain = '';
674 $table = 'aliases';
675 $type = 'liste';
676 } else {
677 $domain = '@' . $domain;
678 $table = 'virtual';
679 $type = 'list';
680 }
681
682 $this->changeTpl('lists/delete.tpl');
683 if (Post::v('valid') == 'OUI') {
684 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
685 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
686 XDB::execute("DELETE FROM $table
687 WHERE type={?} AND alias={?}",
688 $type, $liste.$app.$domain);
689 }
690 $page->assign('deleted', true);
691 } else {
692 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
693 . 'Contact les administrateurs du site pour régler le problème : '
694 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
695 }
696 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
697 $page->assign_by_ref('details', $details);
698 $page->assign_by_ref('options', $options);
699 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
700 } else {
701 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
702 }
703 }
704
705 function handler_soptions(&$page, $liste = null)
706 {
707 if (is_null($liste)) {
708 return PL_NOT_FOUND;
709 }
710
711 $this->prepare_client($page);
712
713 $this->changeTpl('lists/soptions.tpl');
714
715 if (Post::has('submit')) {
716 $values = $_POST;
717 $values = array_map('utf8_decode', $values);
718 unset($values['submit']);
719 $values['advertised'] = empty($values['advertised']) ? false : true;
720 $values['archive'] = empty($values['archive']) ? false : true;
721 $this->client->set_admin_options($liste, $values);
722 }
723
724 if (list($details,$options) = $this->client->get_admin_options($liste)) {
725 $page->assign_by_ref('details', $details);
726 $page->assign_by_ref('options', $options);
727 } else {
728 $page->kill("La liste n'existe pas");
729 }
730 }
731
732 function handler_check(&$page, $liste = null)
733 {
734 if (is_null($liste)) {
735 return PL_NOT_FOUND;
736 }
737
738 $this->prepare_client($page);
739
740 $this->changeTpl('lists/check.tpl');
741
742 if (Post::has('correct')) {
743 $this->client->check_options($liste, true);
744 }
745
746 if (list($details,$options) = $this->client->check_options($liste)) {
747 $page->assign_by_ref('details', $details);
748 $page->assign_by_ref('options', $options);
749 } else {
750 $page->kill("La liste n'existe pas");
751 }
752 }
753
754 function handler_admin_all(&$page) {
755 $this->changeTpl('lists/admin_all.tpl');
756 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
757
758 $client = new MMList(S::v('uid'), S::v('password'));
759 $listes = $client->get_all_lists();
760 $page->assign_by_ref('listes', $listes);
761 }
762}
763
764// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
765?>