Fix line break layout in validation comments
[platal.git] / modules / lists.php
CommitLineData
bc4ad6aa 1<?php
2/***************************************************************************
3 * Copyright (C) 2003-2006 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),
94c63478 30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, '', NO_AUTH),
bc4ad6aa 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
37 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP),
38 'lists/admin' => $this->make_hook('admin', AUTH_MDP),
39 'lists/options' => $this->make_hook('options', AUTH_MDP),
40 'lists/delete' => $this->make_hook('delete', AUTH_MDP),
41
42 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP),
43 'lists/check' => $this->make_hook('check', AUTH_MDP),
92423144 44 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'),
bc4ad6aa 45 );
46 }
47
8d8f7607 48 function on_subscribe($forlife, $uid, $promo, $password)
49 {
50 $this->prepare_client(null);
51 $this->client->subscribe("promo$promo");
52 }
53
7b9d64a8 54 function prepare_client(&$page)
bc4ad6aa 55 {
0ec52d96 56 global $globals;
57
9bb8bf21 58 require_once dirname(__FILE__).'/lists/lists.inc.php';
bc4ad6aa 59
9bb8bf21 60 $this->client = new MMList(S::v('uid'), S::v('password'));
092945b4 61 return $globals->mail->domain;
bc4ad6aa 62 }
63
ae0508cb 64 function clean_html($res)
65 {
66 $res = html_entity_decode($res);
4e2929c6 67 $res = preg_replace('@<a[^>]*href=["\']([^ >]+)["\'][^>]*>([^<]*)</a>@ie',
68 "'\\2 [' . htmlentities('\\1') . ']'", $res);
ae0508cb 69 $res = preg_replace("@<(/br|p|/div)[^>]*>(\\s*\n)?@i", "\n", $res);
70 $res = trim(strip_tags($res));
71 $res = preg_replace("/\n(\\s*\n)+/", "\n\n", $res);
4e2929c6 72 return $res;
ae0508cb 73 }
74
bc4ad6aa 75 function handler_lists(&$page)
76 {
50c655ee 77 function filter_owner($list)
78 {
79 return $list['own'];
80 }
81
82 function filter_member($list)
83 {
84 return $list['ins'];
85 }
86
7b9d64a8 87 $this->prepare_client($page);
bc4ad6aa 88
89 $page->changeTpl('listes/index.tpl');
50c655ee 90 $page->addJsLink('ajax.js');
bc4ad6aa 91 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
92
93
94 if (Get::has('del')) {
5e2307dc 95 $this->client->unsubscribe(Get::v('del'));
8b00e0e0 96 pl_redirect('lists');
bc4ad6aa 97 }
98 if (Get::has('add')) {
5e2307dc 99 $this->client->subscribe(Get::v('add'));
8b00e0e0 100 pl_redirect('lists');
bc4ad6aa 101 }
102 if (Post::has('promo_add')) {
5e2307dc 103 $promo = Post::i('promo_add');
bc4ad6aa 104 if ($promo >= 1900 and $promo < 2100) {
105 $this->client->subscribe("promo$promo");
106 } else {
107 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
108 }
109 }
110 $listes = $this->client->get_lists();
50c655ee 111 $owner = array_filter($listes, 'filter_owner');
112 $listes = array_diff_key($listes, $owner);
113 $member = array_filter($listes, 'filter_member');
114 $listes = array_diff_key($listes, $member);
115 foreach ($owner as $key=>$liste) {
116 list($subs,$mails) = $this->client->get_pending_ops($liste['list']);
117 $owner[$key]['subscriptions'] = $subs;
118 $owner[$key]['mails'] = $mails;
119 }
120 $page->register_modifier('hdc', 'list_header_decode');
121 $page->assign_by_ref('owner', $owner);
122 $page->assign_by_ref('member', $member);
123 $page->assign_by_ref('public', $listes);
124 }
125
126 function handler_ajax(&$page, $list = null)
127 {
2aa20e30 128 header('Content-Type: text/html; charset="iso-8859-15"');
5cbb1fad 129 $domain = $this->prepare_client($page);
50c655ee 130 $page->changeTpl('listes/liste.inc.tpl', NO_SKIN);
131 if (Get::has('unsubscribe')) {
132 $this->client->unsubscribe($list);
133 }
134 if (Get::has('subscribe')) {
135 $this->client->subscribe($list);
136 }
137 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
138 $this->client->handle_request($list, Get::v('sadd'), 4, '');
139 }
140 if (Get::has('mid')) {
5cbb1fad 141 $this->moderate_mail($domain, $list, Get::i('mid'));
50c655ee 142 }
143
144 list($liste, $members, $owners) = $this->client->get_members($list);
145 if ($liste['own']) {
146 list($subs,$mails) = $this->client->get_pending_ops($list);
147 $liste['subscriptions'] = $subs;
148 $liste['mails'] = $mails;
149 }
150 $page->register_modifier('hdc', 'list_header_decode');
151 $page->assign_by_ref('liste', $liste);
bc4ad6aa 152 }
153
154 function handler_create(&$page)
155 {
bc4ad6aa 156 $page->changeTpl('listes/create.tpl');
157
5e2307dc 158 $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
159 $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
bc4ad6aa 160
161 // click on validate button 'add_owner_sub' or type <enter>
162 if (Post::has('add_owner_sub') && Post::has('add_owner')) {
163 require_once('user.func.inc.php');
164 // if we want to add an owner and then type <enter>, then both
165 // add_owner_sub and add_owner are filled.
e7545178 166 $oforlifes = get_users_forlife_list(Post::v('add_owner'), true);
167 $mforlifes = get_users_forlife_list(Post::v('add_member'), true);
168 if (!is_null($oforlifes)) {
169 $owners = array_merge($owners, $oforlifes);
170 }
171 // if we want to add a member and then type <enter>, then
172 // add_owner_sub is filled, whereas add_owner is empty.
173 if (!is_null($mforlifes)) {
174 $members = array_merge($members, $mforlifes);
bc4ad6aa 175 }
176 }
177
178 // click on validate button 'add_member_sub'
179 if (Post::has('add_member_sub') && Post::has('add_member')) {
180 require_once('user.func.inc.php');
e7545178 181 $forlifes = get_users_forlife_list(Post::v('add_member'), true);
182 if (!is_null($forlifes)) {
183 $members = array_merge($members, $forlifes);
bc4ad6aa 184 }
185 }
186
e7545178 187 ksort($owners);
188 $owners = array_unique($owners);
189 ksort($members);
190 $members = array_unique($members);
bc4ad6aa 191
192 $page->assign('owners', join(' ', $owners));
193 $page->assign('members', join(' ', $members));
194
195 if (!Post::has('submit')) {
196 return;
197 }
198
5e2307dc 199 $liste = Post::v('liste');
bc4ad6aa 200
201 if (empty($liste)) {
089a5801 202 $page->trig('champs «addresse souhaitée» vide');
bc4ad6aa 203 }
204 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
205 $page->trig('le nom de la liste ne doit contenir que des lettres, chiffres et tirets');
206 }
207
08cce2ff 208 $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
bc4ad6aa 209 $n = $res->fetchOneCell();
210
211 if ($n) {
089a5801 212 $page->trig('cet alias est déjà pris');
bc4ad6aa 213 }
214
5e2307dc 215 if (!Post::v(desc)) {
bc4ad6aa 216 $page->trig('le sujet est vide');
217 }
218
219 if (!count($owners)) {
220 $page->trig('pas de gestionnaire');
221 }
222
223 if (count($members)<4) {
224 $page->trig('pas assez de membres');
225 }
226
227 if (!$page->nb_errs()) {
228 $page->assign('created', true);
229 require_once 'validations.inc.php';
cab08090 230 $req = new ListeReq(S::v('uid'), $liste,
5e2307dc 231 Post::v('desc'), Post::i('advertise'),
232 Post::i('modlevel'), Post::i('inslevel'),
bc4ad6aa 233 $owners, $members);
234 $req->submit();
235 }
236 }
237
238 function handler_members(&$page, $liste = null)
239 {
bc4ad6aa 240 if (is_null($liste)) {
241 return PL_NOT_FOUND;
242 }
243
7b9d64a8 244 $this->prepare_client($page);
bc4ad6aa 245
246 $page->changeTpl('listes/members.tpl');
247
248 if (Get::has('del')) {
249 $this->client->unsubscribe($liste);
8b00e0e0 250 pl_redirect('lists/members/'.$liste);
bc4ad6aa 251 }
252
253 if (Get::has('add')) {
254 $this->client->subscribe($liste);
8b00e0e0 255 pl_redirect('lists/members/'.$liste);
bc4ad6aa 256 }
257
258 $members = $this->client->get_members($liste);
259
5e2307dc 260 $tri_promo = !Env::b('alpha');
bc4ad6aa 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 {
089a5801 271 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 272 }
273 }
274
275 function _get_list($offset, $limit)
276 {
a3a049fc 277 global $platal;
bc4ad6aa 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]);
08cce2ff 283 $res = XDB::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
bc4ad6aa 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 WHERE a.alias = {?}", $m);
288 if ($tmp = $res->fetchOneAssoc()) {
289 $membres[$tmp['nom']] = $tmp;
290 } else {
291 $membres[$member[0]] = array('addr' => $member[0]);
292 }
293 }
294 return array($total, $membres);
295 }
296
297 function handler_trombi(&$page, $liste = null)
298 {
bc4ad6aa 299 if (is_null($liste)) {
300 return PL_NOT_FOUND;
301 }
302
7b9d64a8 303 $this->prepare_client($page);
bc4ad6aa 304
305 $page->changeTpl('listes/trombi.tpl');
306
307 if (Get::has('del')) {
308 $this->client->unsubscribe($liste);
8b00e0e0 309 pl_redirect('lists/tromi/'.$liste);
bc4ad6aa 310 }
311 if (Get::has('add')) {
312 $this->client->subscribe($liste);
8b00e0e0 313 pl_redirect('lists/tromi/'.$liste);
bc4ad6aa 314 }
315
316 $owners = $this->client->get_owners($liste);
317
318 if (is_array($owners)) {
bc4ad6aa 319 $moderos = list_sort_owners($owners[1]);
320
321 $page->assign_by_ref('details', $owners[0]);
322 $page->assign_by_ref('owners', $moderos);
323
324 $trombi = new Trombi(array(&$this, '_get_list'));
325 $page->assign('trombi', $trombi);
326 } else {
089a5801 327 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 328 }
329 }
330
331 function handler_archives(&$page, $liste = null)
332 {
333 global $globals;
334
335 if (is_null($liste)) {
336 return PL_NOT_FOUND;
337 }
338
092945b4 339 $domain = $this->prepare_client($page);
bc4ad6aa 340
341 $page->changeTpl('listes/archives.tpl');
342
c99ef281 343 $page->addCssLink('lists.archives.css');
bc4ad6aa 344 if (list($det) = $this->client->get_members($liste)) {
345 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
346 && !$det['own'] && ($det['sub'] < 2))
347 {
348 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
349 } elseif (Get::has('file')) {
5e2307dc 350 $file = Get::v('file');
351 $rep = Get::v('rep');
bc4ad6aa 352 if (strstr('/', $file)!==false || !preg_match(',^\d+/\d+$,', $rep)) {
353 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
354 } else {
355 $page->assign('archives', $globals->lists->spool
356 ."/{$domain}{$globals->lists->vhost_sep}$liste/$rep/$file");
357 }
358 } else {
359 $archs = Array();
360 foreach (glob($globals->lists->spool
361 ."/{$domain}{$globals->lists->vhost_sep}$liste/*/*") as $rep)
362 {
363 if (preg_match(",/(\d*)/(\d*)$,", $rep, $matches)) {
364 $archs[intval($matches[1])][intval($matches[2])] = true;
365 }
366 }
367 $page->assign('archs', $archs);
368 $page->assign('range', range(1,12));
369 }
370 } else {
371 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
372 }
373 }
374
5cbb1fad 375 function moderate_mail($domain, $liste, $mid)
50c655ee 376 {
377 $mail = $this->client->get_pending_mail($liste, $mid);
378 $reason = '';
379
380 $prenom = S::v('prenom');
381 $nom = S::v('nom');
382
383 if (Env::has('mok')) {
384 $action = 1; /** 2 = ACCEPT **/
385 $subject = "Message accepté";
386 $append .= "a été accepté par $prenom $nom.\n";
387 } elseif (Env::has('mno')) {
388 $action = 2; /** 2 = REJECT **/
389 $subject = "Message refusé";
390 $reason = Post::v('reason');
391 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
392 . $reason;
393 } elseif (Env::has('mdel')) {
394 $action = 3; /** 3 = DISCARD **/
395 $subject = "Message supprimé";
396 $append = "a été supprimé par $prenom $nom.\n\n"
397 . "Rappel: il ne faut utiliser cette opération "
398 . "que dans le cas de spams ou de virus !\n";
399 }
400
401 if (isset($action) && $this->client->handle_request($liste, $mid, $action, $reason)) {
402 $texte = "le message suivant :\n\n"
403 ." Auteur: {$mail['sender']}\n"
404 ." Sujet : « {$mail['subj']} »\n"
405 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
406 .$append;
407 require_once 'diogenes/diogenes.hermes.inc.php';
408 $mailer = new HermesMailer();
409 $mailer->addTo("$liste-owner@{$domain}");
410 $mailer->setFrom("$liste-bounces@{$domain}");
411 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
412 $mailer->setSubject($subject);
413 $mailer->setTxtBody(wordwrap($texte,72));
414 $mailer->send();
415 Get::kill('mid');
416 }
417
418 return $mail;
419 }
420
bc4ad6aa 421 function handler_moderate(&$page, $liste = null)
422 {
bc4ad6aa 423 if (is_null($liste)) {
424 return PL_NOT_FOUND;
425 }
426
092945b4 427 $domain = $this->prepare_client($page);
bc4ad6aa 428
429 $page->changeTpl('listes/moderate.tpl');
430
431 $page->register_modifier('qpd', 'quoted_printable_decode');
c8529706 432 $page->register_modifier('hdc', 'list_header_decode');
ae0508cb 433 $page->register_modifier('clean_html', array($this, 'clean_html'));
bc4ad6aa 434
435 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
5e2307dc 436 $this->client->handle_request($liste,Env::v('sadd'),4,'');
8b00e0e0 437 pl_redirect('lists/moderate/'.$liste);
bc4ad6aa 438 }
439
440 if (Post::has('sdel')) { /* 2 = REJECT */
5e2307dc 441 $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason'));
bc4ad6aa 442 }
443
444 if (Env::has('mid')) {
5cbb1fad 445 $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
bc4ad6aa 446
447 if (Get::has('mid') && is_array($mail)) {
448 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
449 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
450 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
451 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
452 $msg = str_replace("%(listname)s", $liste, $msg);
bc4ad6aa 453
50c655ee 454 $page->assign('msg', $msg);
455
bc4ad6aa 456 $page->changeTpl('listes/moderate_mail.tpl');
457 $page->assign_by_ref('mail', $mail);
6a20c6a3 458 return;
50c655ee 459 }
bc4ad6aa 460 } elseif (Env::has('sid')) {
461
462 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
463 foreach($subs as $user) {
5e2307dc 464 if ($user['id'] == Env::v('sid')) {
bc4ad6aa 465 $page->changeTpl('listes/moderate_sub.tpl');
6a20c6a3 466 $page->assign('del_user', $user);
467 return;
bc4ad6aa 468 }
469 }
470 }
471
472 }
473
474 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
475 $page->assign_by_ref('subs', $subs);
476 $page->assign_by_ref('mails', $mails);
477 } else {
089a5801 478 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
bc4ad6aa 479 }
480 }
481
482 function handler_admin(&$page, $liste = null)
483 {
484 global $globals;
485
486 if (is_null($liste)) {
487 return PL_NOT_FOUND;
488 }
489
7b9d64a8 490 $this->prepare_client($page);
bc4ad6aa 491
492 $page->changeTpl('listes/admin.tpl');
493
494 if (Env::has('add_member')) {
bc4ad6aa 495 require_once('user.func.inc.php');
e7545178 496 $members = get_users_forlife_list(Env::v('add_member'));
bc4ad6aa 497 $arr = $this->client->mass_subscribe($liste, $members);
498 if (is_array($arr)) {
499 foreach($arr as $addr) {
500 $page->trig("{$addr[0]} inscrit.");
501 }
502 }
503 }
504
505 if (Env::has('del_member')) {
5e2307dc 506 if (strpos(Env::v('del_member'), '@') === false) {
bc4ad6aa 507 $this->client->mass_unsubscribe(
5e2307dc 508 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
bc4ad6aa 509 } else {
5e2307dc 510 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
bc4ad6aa 511 }
8b00e0e0 512 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 513 }
514
515 if (Env::has('add_owner')) {
516 require_once('user.func.inc.php');
e7545178 517 $owners = get_users_forlife_list(Env::v('add_owner'));
518 if ($owners) {
519 foreach ($owners as $login) {
520 if ($this->client->add_owner($liste, $login)) {
521 $page->trig($alias." ajouté aux modérateurs.");
522 }
bc4ad6aa 523 }
524 }
525 }
526
527 if (Env::has('del_owner')) {
5e2307dc 528 if (strpos(Env::v('del_owner'), '@') === false) {
529 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
bc4ad6aa 530 } else {
5e2307dc 531 $this->client->del_owner($liste, Env::v('del_owner'));
bc4ad6aa 532 }
8b00e0e0 533 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 534 }
535
536 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
30fc8ee7 537 $membres = list_sort_members($mem, @$tri_promo);
538 $moderos = list_sort_owners($own, @$tri_promo);
bc4ad6aa 539
540 $page->assign_by_ref('details', $det);
541 $page->assign_by_ref('members', $membres);
542 $page->assign_by_ref('owners', $moderos);
543 $page->assign('np_m', count($mem));
544
545 } else {
546 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
547 }
548 }
549
550 function handler_options(&$page, $liste = null)
551 {
bc4ad6aa 552 if (is_null($liste)) {
553 return PL_NOT_FOUND;
554 }
555
7b9d64a8 556 $this->prepare_client($page);
bc4ad6aa 557
558 $page->changeTpl('listes/options.tpl');
559
560 if (Post::has('submit')) {
561 $values = $_POST;
562 $this->client->set_bogo_level($liste, intval($values['bogo_level']));
563 switch($values['moderate']) {
564 case '0':
565 $values['generic_nonmember_action'] = 0;
566 $values['default_member_moderation'] = 0;
567 break;
568 case '1':
569 $values['generic_nonmember_action'] = 1;
570 $values['default_member_moderation'] = 0;
571 break;
572 case '2':
573 $values['generic_nonmember_action'] = 1;
574 $values['default_member_moderation'] = 1;
575 break;
576 }
577 unset($values['submit'], $values['bogo_level'], $values['moderate']);
578 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
579 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
580 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
581 if (isset($values['subject_prefix'])) {
582 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
583 }
584 $this->client->set_owner_options($liste, $values);
5e2307dc 585 } elseif (isvalid_email(Post::v('atn_add'))) {
586 $this->client->add_to_wl($liste, Post::v('atn_add'));
bc4ad6aa 587 } elseif (Get::has('atn_del')) {
5e2307dc 588 $this->client->del_from_wl($liste, Get::v('atn_del'));
8b00e0e0 589 pl_redirect('lists/options/'.$liste);
bc4ad6aa 590 }
591
592 if (list($details,$options) = $this->client->get_owner_options($liste)) {
593 $page->assign_by_ref('details', $details);
594 $page->assign_by_ref('options', $options);
595 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
596 } else {
597 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
598 }
599 }
600
601 function handler_delete(&$page, $liste = null)
602 {
bc4ad6aa 603 if (is_null($liste)) {
604 return PL_NOT_FOUND;
605 }
606
7b9d64a8 607 $this->prepare_client($page);
bc4ad6aa 608
609 $page->changeTpl('listes/delete.tpl');
610
5e2307dc 611 if (Post::v('valid') == 'OUI'
612 && $this->client->delete_list($liste, Post::b('del_archive')))
bc4ad6aa 613 {
614 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
08cce2ff 615 XDB::execute("DELETE FROM aliases
bc4ad6aa 616 WHERE type='liste' AND alias='{?}'",
80f44cfe 617 $liste.$app);
bc4ad6aa 618 }
619 $page->assign('deleted', true);
620 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
621 $page->assign_by_ref('details', $details);
622 $page->assign_by_ref('options', $options);
623 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
624 } else {
625 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
626 }
627 }
628
629 function handler_soptions(&$page, $liste = null)
630 {
bc4ad6aa 631 if (is_null($liste)) {
632 return PL_NOT_FOUND;
633 }
634
7b9d64a8 635 $this->prepare_client($page);
bc4ad6aa 636
637 $page->changeTpl('listes/soptions.tpl');
638
639 if (Post::has('submit')) {
640 $values = $_POST;
641 unset($values['submit']);
642 $values['advertised'] = empty($values['advertised']) ? false : true;
643 $values['archive'] = empty($values['archive']) ? false : true;
644 $this->client->set_admin_options($liste, $values);
645 }
646
647 if (list($details,$options) = $this->client->get_admin_options($liste)) {
648 $page->assign_by_ref('details', $details);
649 $page->assign_by_ref('options', $options);
650 } else {
651 $page->kill("La liste n'existe pas");
652 }
653 }
654
655 function handler_check(&$page, $liste = null)
656 {
bc4ad6aa 657 if (is_null($liste)) {
658 return PL_NOT_FOUND;
659 }
660
7b9d64a8 661 $this->prepare_client($page);
bc4ad6aa 662
663 $page->changeTpl('listes/check.tpl');
664
665 if (Post::has('correct')) {
666 $this->client->check_options($liste, true);
667 }
668
669 if (list($details,$options) = $this->client->check_options($liste)) {
670 $page->assign_by_ref('details', $details);
671 $page->assign_by_ref('options', $options);
672 } else {
673 $page->kill("La liste n'existe pas");
674 }
675 }
92423144 676
677 function handler_admin_all(&$page) {
163eddd2 678 $page->changeTpl('listes/admin_all.tpl');
92423144 679 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
9bb8bf21 680
681 $client = new MMList(S::v('uid'), S::v('password'));
92423144 682 $listes = $client->get_all_lists();
9bb8bf21 683 $page->assign_by_ref('listes', $listes);
92423144 684 }
bc4ad6aa 685}
686
687?>