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