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