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