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