Merge branch 'platal-0.9.17'
[platal.git] / modules / lists.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2008 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
22 class 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/annu' => $this->make_hook('annu', AUTH_COOKIE),
35 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE),
36 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
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 get_pending_ops($domain, $list)
66 {
67 list($subs,$mails) = $this->client->get_pending_ops($list);
68 $res = XDB::query("SELECT mid
69 FROM ml_moderate
70 WHERE ml = {?} AND domain = {?}",
71 $list, $domain);
72 $mids = $res->fetchColumn();
73 foreach ($mails as $key=>$mail) {
74 if (in_array($mail['id'], $mids)) {
75 unset($mails[$key]);
76 }
77 }
78 return array($subs, $mails);
79 }
80
81 function handler_lists(&$page)
82 {
83 function filter_owner($list)
84 {
85 return $list['own'];
86 }
87
88 function filter_member($list)
89 {
90 return $list['sub'];
91 }
92
93 $domain = $this->prepare_client($page);
94
95 $page->changeTpl('lists/index.tpl');
96 $page->addJsLink('ajax.js');
97 $page->setTitle('Polytechnique.org - Listes de diffusion');
98
99
100 if (Get::has('del')) {
101 $this->client->unsubscribe(Get::v('del'));
102 pl_redirect('lists');
103 }
104 if (Get::has('add')) {
105 $this->client->subscribe(Get::v('add'));
106 pl_redirect('lists');
107 }
108 if (Post::has('promo_add')) {
109 $promo = Post::i('promo_add');
110 if ($promo >= 1900 and $promo < 2100) {
111 $this->client->subscribe("promo$promo");
112 } else {
113 $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres.");
114 }
115 }
116 $listes = $this->client->get_lists();
117 $owner = array_filter($listes, 'filter_owner');
118 $listes = array_diff_key($listes, $owner);
119 $member = array_filter($listes, 'filter_member');
120 $listes = array_diff_key($listes, $member);
121 foreach ($owner as $key=>$liste) {
122 list($subs,$mails) = $this->get_pending_ops($domain, $liste['list']);
123 $owner[$key]['subscriptions'] = $subs;
124 $owner[$key]['mails'] = $mails;
125 }
126 $page->register_modifier('hdc', 'list_header_decode');
127 $page->assign_by_ref('owner', $owner);
128 $page->assign_by_ref('member', $member);
129 $page->assign_by_ref('public', $listes);
130 }
131
132 function handler_ajax(&$page, $list = null)
133 {
134 header('Content-Type: text/html; charset="UTF-8"');
135 $domain = $this->prepare_client($page);
136 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
137 if (Get::has('unsubscribe')) {
138 $this->client->unsubscribe($list);
139 }
140 if (Get::has('subscribe')) {
141 $this->client->subscribe($list);
142 }
143 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
144 $this->client->handle_request($list, Get::v('sadd'), 4, '');
145 }
146 if (Get::has('mid')) {
147 $this->moderate_mail($domain, $list, Get::i('mid'));
148 }
149
150 list($liste, $members, $owners) = $this->client->get_members($list);
151 if ($liste['own']) {
152 list($subs,$mails) = $this->get_pending_ops($domain, $list);
153 $liste['subscriptions'] = $subs;
154 $liste['mails'] = $mails;
155 }
156 $page->register_modifier('hdc', 'list_header_decode');
157 $page->assign_by_ref('liste', $liste);
158 }
159
160 function handler_create(&$page)
161 {
162 global $globals;
163
164 $page->changeTpl('lists/create.tpl');
165
166 $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
167 $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
168
169 // click on validate button 'add_owner_sub' or type <enter>
170 if (Post::has('add_owner_sub') && Post::has('add_owner')) {
171 require_once('user.func.inc.php');
172 // if we want to add an owner and then type <enter>, then both
173 // add_owner_sub and add_owner are filled.
174 $oforlifes = get_users_forlife_list(Post::v('add_owner'), true);
175 $mforlifes = get_users_forlife_list(Post::v('add_member'), true);
176 if (!is_null($oforlifes)) {
177 $owners = array_merge($owners, $oforlifes);
178 }
179 // if we want to add a member and then type <enter>, then
180 // add_owner_sub is filled, whereas add_owner is empty.
181 if (!is_null($mforlifes)) {
182 $members = array_merge($members, $mforlifes);
183 }
184 }
185
186 // click on validate button 'add_member_sub'
187 require_once('user.func.inc.php');
188 if (Post::has('add_member_sub') && Post::has('add_member')) {
189 $forlifes = get_users_forlife_list(Post::v('add_member'), true);
190 if (!is_null($forlifes)) {
191 $members = array_merge($members, $forlifes);
192 }
193 }
194 if (Post::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
195 $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true);
196 if (!$upload) {
197 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
198 } else {
199 $forlifes = get_users_forlife_list($upload->getContents(), true);
200 if (!is_null($forlifes)) {
201 $members = array_merge($members, $forlifes);
202 }
203 }
204 }
205
206 ksort($owners);
207 $owners = array_unique($owners);
208 ksort($members);
209 $members = array_unique($members);
210
211 $page->assign('owners', join("\n", $owners));
212 $page->assign('members', join("\n", $members));
213
214 if (!Post::has('submit')) {
215 return;
216 }
217
218 $asso = Post::v('asso');
219 $liste = Post::v('liste');
220
221 if (empty($liste)) {
222 $page->trigError('Le champ «adresse souhaitée» est vide.');
223 }
224 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
225 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
226 }
227
228 if (($asso == "binet") || ($asso == "alias")) {
229 $promo = Post::i('promo');
230 $domain = $promo . '.' . $globals->mail->domain;
231
232 if (($promo < 1921) || ($promo > date('Y'))) {
233 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
234 }
235
236 $new = $liste . '@' . $domain;
237 $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
238
239 } else {
240 if ($asso == "groupex") {
241 $groupex_name = Post::v('groupex_name');
242
243 $res_groupe = XDB::query('SELECT mail_domain FROM groupex.asso WHERE nom={?}', $groupex_name);
244 $domain = $res_groupe->fetchOneCell();
245
246 if (!$domain) {
247 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
248 }
249
250 $new = $liste . '@' . $domain;
251 $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
252 } else {
253 $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
254 $domain = $globals->mail->domain;
255 }
256 }
257
258 $n = $res->fetchOneCell();
259
260 if ($n) {
261 $page->trigError('L\'«adresse souhaitée» est déjà prise.');
262 }
263
264 if (!Post::v('desc')) {
265 $page->trigError('Le sujet est vide.');
266 }
267
268 if (!count($owners)) {
269 $page->trigError('Il n\'y a pas de gestionnaire.');
270 }
271
272 if (count($members)<4) {
273 $page->trigError('Il n\'y a pas assez de membres.');
274 }
275
276 if (!$page->nb_errs()) {
277 $page->assign('created', true);
278 require_once 'validations.inc.php';
279 $req = new ListeReq(S::v('uid'), $asso, $liste, $domain,
280 Post::v('desc'), Post::i('advertise'),
281 Post::i('modlevel'), Post::i('inslevel'),
282 $owners, $members);
283 $req->submit();
284 }
285 }
286
287 function handler_members(&$page, $liste = null)
288 {
289 if (is_null($liste)) {
290 return PL_NOT_FOUND;
291 }
292
293 $this->prepare_client($page);
294
295 $page->changeTpl('lists/members.tpl');
296
297 if (Get::has('del')) {
298 $this->client->unsubscribe($liste);
299 pl_redirect('lists/members/'.$liste);
300 }
301
302 if (Get::has('add')) {
303 $this->client->subscribe($liste);
304 pl_redirect('lists/members/'.$liste);
305 }
306
307 $members = $this->client->get_members($liste);
308
309 $tri_promo = !Env::b('alpha');
310
311 if (list($det,$mem,$own) = $members) {
312 $membres = list_sort_members($mem, $tri_promo);
313 $moderos = list_sort_owners($own, $tri_promo);
314
315 $page->assign_by_ref('details', $det);
316 $page->assign_by_ref('members', $membres);
317 $page->assign_by_ref('owners', $moderos);
318 $page->assign('nb_m', count($mem));
319 } else {
320 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
321 }
322 }
323
324 function handler_annu(&$page, $liste = null, $action = null, $subaction = null)
325 {
326 if (is_null($liste)) {
327 return PL_NOT_FOUND;
328 }
329
330 $this->prepare_client($page);
331
332 if (Get::has('del')) {
333 $this->client->unsubscribe($liste);
334 pl_redirect('lists/annu/'.$liste);
335 }
336 if (Get::has('add')) {
337 $this->client->subscribe($liste);
338 pl_redirect('lists/annu/'.$liste);
339 }
340
341 $owners = $this->client->get_owners($liste);
342 if (!is_array($owners)) {
343 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
344 }
345
346 global $platal;
347 list(,$members) = $this->client->get_members($liste);
348 $users = array();
349 foreach ($members as $m) {
350 $users[] = $m[1];
351 }
352 require_once 'userset.inc.php';
353 $view = new ArraySet($users);
354 $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true));
355 if (empty($GLOBALS['IS_XNET_SITE'])) {
356 $view->addMod('minifiche', 'Minifiches', false);
357 }
358 $view->addMod('geoloc', 'Planisphère');
359 $view->apply("lists/annu/$liste", $page, $action, $subaction);
360 if ($action == 'geoloc' && $subaction) {
361 return;
362 }
363
364 $page->changeTpl('lists/annu.tpl');
365 $moderos = list_sort_owners($owners[1]);
366 $page->assign_by_ref('details', $owners[0]);
367 $page->assign_by_ref('owners', $moderos);
368 }
369
370 function handler_archives(&$page, $liste = null, $action = null, $artid = null)
371 {
372 global $globals;
373
374 if (is_null($liste)) {
375 return PL_NOT_FOUND;
376 }
377
378 $domain = $this->prepare_client($page);
379
380 $page->changeTpl('lists/archives.tpl');
381
382 if (list($det) = $this->client->get_members($liste)) {
383 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
384 && !$det['own'] && ($det['sub'] < 2)) {
385 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
386 }
387 $get = Array('listname' => $liste, 'domain' => $domain);
388 if (Post::has('updateall')) {
389 $get['updateall'] = Post::v('updateall');
390 }
391 require_once 'banana/ml.inc.php';
392 get_banana_params($get, null, $action, $artid);
393 run_banana($page, 'MLBanana', $get);
394 } else {
395 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
396 }
397 }
398
399 function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
400 {
401 require_once('rss.inc.php');
402 $uid = init_rss(null, $alias, $hash);
403 if (!$uid || !$liste) {
404 exit;
405 }
406
407 $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
408 FROM auth_user_md5 AS u
409 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
410 WHERE u.user_id = {?}", $uid);
411 $row = $res->fetchOneAssoc();
412 $_SESSION = array_merge($row, $_SESSION);
413
414 $domain = $this->prepare_client($page);
415 if (list($det) = $this->client->get_members($liste)) {
416 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
417 && !$det['own'] && ($det['sub'] < 2)) {
418 exit;
419 }
420 require_once('banana/ml.inc.php');
421 $banana = new MLBanana(S::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
422 $banana->run();
423 }
424 exit;
425 }
426
427 function moderate_mail($domain, $liste, $mid)
428 {
429 if (Env::has('mok')) {
430 $action = 'accept';
431 } elseif (Env::has('mno')) {
432 $action = 'refuse';
433 } elseif (Env::has('mdel')) {
434 $action = 'delete';
435 } else {
436 return false;
437 }
438 Get::kill('mid');
439 return XDB::execute("INSERT IGNORE INTO ml_moderate
440 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
441 $liste, $domain, $mid, S::i('uid'), $action, Post::v('reason'));
442 }
443
444 function handler_moderate(&$page, $liste = null)
445 {
446 if (is_null($liste)) {
447 return PL_NOT_FOUND;
448 }
449
450 $domain = $this->prepare_client($page);
451
452 $page->changeTpl('lists/moderate.tpl');
453
454 $page->register_modifier('hdc', 'list_header_decode');
455
456 if (Env::has('sadd') || Env::has('sdel')) {
457 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
458 $sub = $this->client->get_pending_sub($liste, Env::v('sadd'));
459 $this->client->handle_request($liste,Env::v('sadd'),4,'');
460 $info = "validée";
461 }
462 if (Post::has('sdel')) { /* 2 = REJECT */
463 $sub = $this->client->get_pending_sub($liste, Env::v('sdel'));
464 $this->client->handle_request($liste, Post::v('sdel'), 2, utf8_decode(Post::v('reason')));
465 $info = "refusée";
466 }
467 if ($sub) {
468 $mailer = new PlMailer();
469 $mailer->setFrom("$liste-bounces@{$domain}");
470 $mailer->addTo("$liste-owner@{$domain}");
471 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
472 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
473 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::v('prenom') . ' '
474 . S::v('nom') . '(' . S::v('promo') . ")\n";
475 if (trim(Post::v('reason'))) {
476 $text .= "\nLa raison invoquée est :\n" . Post::v('reason');
477 }
478 $mailer->setTxtBody(wordwrap($text, 72));
479 $mailer->send();
480 }
481 if (Env::has('sadd')) {
482 pl_redirect('lists/moderate/'.$liste);
483 }
484 }
485
486 if (Post::has('moderate_mails') && Post::has('select_mails')) {
487 $mails = array_keys(Post::v('select_mails'));
488 foreach($mails as $mail) {
489 $this->moderate_mail($domain, $liste, $mail);
490 }
491 } elseif (Env::has('mid')) {
492 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
493 $page->changeTpl('lists/moderate_mail.tpl');
494 require_once('banana/moderate.inc.php');
495 $params = array('listname' => $liste, 'domain' => $domain,
496 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
497 $params['client'] = $this->client;
498 run_banana($page, 'ModerationBanana', $params);
499
500 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
501 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
502 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
503 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
504 $msg = str_replace("%(listname)s", $liste, $msg);
505 $page->assign('msg', $msg);
506 return;
507 }
508
509 $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
510 } elseif (Env::has('sid')) {
511 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
512 foreach($subs as $user) {
513 if ($user['id'] == Env::v('sid')) {
514 $page->changeTpl('lists/moderate_sub.tpl');
515 $page->assign('del_user', $user);
516 return;
517 }
518 }
519 }
520
521 }
522
523 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
524 foreach ($mails as $key=>$mail) {
525 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
526 if ($mail['fromx']) {
527 $page->assign('with_fromx', true);
528 } else {
529 $page->assign('with_nonfromx', true);
530 }
531 }
532 $page->assign_by_ref('subs', $subs);
533 $page->assign_by_ref('mails', $mails);
534 } else {
535 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
536 }
537 }
538
539 static public function no_login_callback($login)
540 {
541 require_once 'user.func.inc.php';
542 global $list_unregistered, $globals;
543
544 $users = get_not_registered_user($login, true);
545 if ($users && $users->total()) {
546 if (!isset($list_unregistered)) {
547 $list_unregistered = array();
548 }
549 $list_unregistered[$login] = $users;
550 } else {
551 list($name, $dom) = @explode('@', $login);
552 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
553 _default_user_callback($login);
554 }
555 }
556 }
557
558 function handler_admin(&$page, $liste = null)
559 {
560 global $globals;
561
562 if (is_null($liste)) {
563 return PL_NOT_FOUND;
564 }
565
566 $domain = $this->prepare_client($page);
567
568 $page->changeTpl('lists/admin.tpl');
569
570 if (Env::has('send_mark')) {
571 $actions = Env::v('mk_action');
572 $uids = Env::v('mk_uid');
573 $mails = Env::v('mk_email');
574 foreach ($actions as $key=>$action) {
575 switch ($action) {
576 case 'none':
577 break;
578
579 case 'marketu': case 'markets':
580 require_once 'emails.inc.php';
581 $mail = valide_email($mails[$key]);
582 if (isvalid_email_redirection($mail)) {
583 $from = ($action == 'marketu') ? 'user' : 'staff';
584 $market = Marketing::get($uids[$key], $mail);
585 if (!$market) {
586 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid'));
587 $market->add();
588 break;
589 }
590 }
591
592 default:
593 XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
594 VALUES ({?}, \'list\', {?}, {?})',
595 $uids[$key], $liste, $domain);
596 }
597 }
598 }
599
600 if (Env::has('add_member')) {
601 require_once('user.func.inc.php');
602 $members = get_users_forlife_list(Env::v('add_member'),
603 false,
604 array('ListsModule', 'no_login_callback'));
605 $arr = $this->client->mass_subscribe($liste, $members);
606 if (is_array($arr)) {
607 foreach($arr as $addr) {
608 $page->trigSuccess("{$addr[0]} inscrit.");
609 }
610 }
611 }
612
613 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
614 $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true);
615 if (!$upload) {
616 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
617 } else {
618 $members = get_users_forlife_list($upload->getContents(),
619 false,
620 array('ListsModule', 'no_login_callback'));
621 $arr = $this->client->mass_subscribe($liste, $members);
622 if (is_array($arr)) {
623 foreach($arr as $addr) {
624 $page->trigSuccess("{$addr[0]} inscrit.");
625 }
626 }
627 }
628 }
629
630 if (Env::has('del_member')) {
631 if (strpos(Env::v('del_member'), '@') === false) {
632 $this->client->mass_unsubscribe(
633 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
634 } else {
635 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
636 }
637 pl_redirect('lists/admin/'.$liste);
638 }
639
640 if (Env::has('add_owner')) {
641 require_once('user.func.inc.php');
642 $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback'));
643 if ($owners) {
644 foreach ($owners as $login) {
645 if ($this->client->add_owner($liste, $login)) {
646 $page->trigSuccess($alias." ajouté aux modérateurs.");
647 }
648 }
649 }
650 }
651
652 if (Env::has('del_owner')) {
653 if (strpos(Env::v('del_owner'), '@') === false) {
654 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
655 } else {
656 $this->client->del_owner($liste, Env::v('del_owner'));
657 }
658 pl_redirect('lists/admin/'.$liste);
659 }
660
661 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
662 global $list_unregistered;
663 if ($list_unregistered) {
664 $page->assign_by_ref('unregistered', $list_unregistered);
665 }
666 $membres = list_sort_members($mem, @$tri_promo);
667 $moderos = list_sort_owners($own, @$tri_promo);
668
669 $page->assign_by_ref('details', $det);
670 $page->assign_by_ref('members', $membres);
671 $page->assign_by_ref('owners', $moderos);
672 $page->assign('np_m', count($mem));
673
674 } else {
675 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
676 ." Si tu penses qu'il s'agit d'une erreur, "
677 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
678 }
679 }
680
681 function handler_options(&$page, $liste = null)
682 {
683 if (is_null($liste)) {
684 return PL_NOT_FOUND;
685 }
686
687 $this->prepare_client($page);
688
689 $page->changeTpl('lists/options.tpl');
690
691 if (Post::has('submit')) {
692 $values = $_POST;
693 $values = array_map('utf8_decode', $values);
694 $spamlevel = intval($values['bogo_level']);
695 $unsurelevel = intval($values['unsure_level']);
696 if ($spamlevel == 0) {
697 $unsurelevel = 0;
698 }
699 if ($spamlevel > 3 || $spamlevel < 0 || $unsurelevel < 0 || $unsurelevel > 1) {
700 $page->trigError("Réglage de l'antispam non valide");
701 } else {
702 $this->client->set_bogo_level($liste, ($spamlevel << 1) + $unsurelevel);
703 }
704 switch($values['moderate']) {
705 case '0':
706 $values['generic_nonmember_action'] = 0;
707 $values['default_member_moderation'] = 0;
708 break;
709 case '1':
710 $values['generic_nonmember_action'] = 1;
711 $values['default_member_moderation'] = 0;
712 break;
713 case '2':
714 $values['generic_nonmember_action'] = 1;
715 $values['default_member_moderation'] = 1;
716 break;
717 }
718 unset($values['submit'], $values['bogo_level'], $values['moderate']);
719 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
720 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
721 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
722 if (isset($values['subject_prefix'])) {
723 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
724 }
725 $this->client->set_owner_options($liste, $values);
726 } elseif (isvalid_email(Post::v('atn_add'))) {
727 $this->client->add_to_wl($liste, Post::v('atn_add'));
728 } elseif (Get::has('atn_del')) {
729 $this->client->del_from_wl($liste, Get::v('atn_del'));
730 pl_redirect('lists/options/'.$liste);
731 }
732
733 if (list($details,$options) = $this->client->get_owner_options($liste)) {
734 $page->assign_by_ref('details', $details);
735 $page->assign_by_ref('options', $options);
736 $bogo_level = intval($this->client->get_bogo_level($liste));
737 $page->assign('unsure_level', $bogo_level & 1);
738 $page->assign('bogo_level', $bogo_level >> 1);
739 } else {
740 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
741 }
742 }
743
744 function handler_delete(&$page, $liste = null)
745 {
746 global $globals;
747 if (is_null($liste)) {
748 return PL_NOT_FOUND;
749 }
750
751 $domain = $this->prepare_client($page);
752 if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
753 $domain = '';
754 $table = 'aliases';
755 $type = 'liste';
756 } else {
757 $domain = '@' . $domain;
758 $table = 'virtual';
759 $type = 'list';
760 }
761
762 $page->changeTpl('lists/delete.tpl');
763 if (Post::v('valid') == 'OUI') {
764 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
765 foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) {
766 XDB::execute("DELETE FROM $table
767 WHERE type={?} AND alias={?}",
768 $type, $liste.$app.$domain);
769 }
770 $page->assign('deleted', true);
771 } else {
772 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
773 . 'Contact les administrateurs du site pour régler le problème : '
774 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
775 }
776 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
777 $page->assign_by_ref('details', $details);
778 $page->assign_by_ref('options', $options);
779 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
780 } else {
781 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
782 }
783 }
784
785 function handler_soptions(&$page, $liste = null)
786 {
787 if (is_null($liste)) {
788 return PL_NOT_FOUND;
789 }
790
791 $this->prepare_client($page);
792
793 $page->changeTpl('lists/soptions.tpl');
794
795 if (Post::has('submit')) {
796 $values = $_POST;
797 $values = array_map('utf8_decode', $values);
798 unset($values['submit']);
799 $values['advertised'] = empty($values['advertised']) ? false : true;
800 $values['archive'] = empty($values['archive']) ? false : true;
801 $this->client->set_admin_options($liste, $values);
802 }
803
804 if (list($details,$options) = $this->client->get_admin_options($liste)) {
805 $page->assign_by_ref('details', $details);
806 $page->assign_by_ref('options', $options);
807 } else {
808 $page->kill("La liste n'existe pas");
809 }
810 }
811
812 function handler_check(&$page, $liste = null)
813 {
814 if (is_null($liste)) {
815 return PL_NOT_FOUND;
816 }
817
818 $this->prepare_client($page);
819
820 $page->changeTpl('lists/check.tpl');
821
822 if (Post::has('correct')) {
823 $this->client->check_options($liste, true);
824 }
825
826 if (list($details,$options) = $this->client->check_options($liste)) {
827 $page->assign_by_ref('details', $details);
828 $page->assign_by_ref('options', $options);
829 } else {
830 $page->kill("La liste n'existe pas");
831 }
832 }
833
834 function handler_admin_all(&$page) {
835 $page->changeTpl('lists/admin_all.tpl');
836 $page->setTitle('Polytechnique.org - Administration - Mailing lists');
837
838 $client = new MMList(S::v('uid'), S::v('password'));
839 $listes = $client->get_all_lists();
840 $page->assign_by_ref('listes', $listes);
841 }
842 }
843
844 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
845 ?>