2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ListsModule
extends PLModule
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
),
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE
),
34 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE
),
35 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE
),
36 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
37 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC
, 'user', NO_HTTPS
),
39 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
40 'lists/admin' => $this->make_hook('admin', AUTH_MDP
),
41 'lists/options' => $this->make_hook('options', AUTH_MDP
),
42 'lists/delete' => $this->make_hook('delete', AUTH_MDP
),
44 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
45 'lists/check' => $this->make_hook('check', AUTH_MDP
),
46 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP
, 'admin'),
50 function prepare_client(&$page)
54 $this->load('lists.inc.php');
56 $this->client
= new MMList(S
::v('uid'), S
::v('password'));
57 return $globals->mail
->domain
;
60 function get_pending_ops($domain, $list)
62 list($subs,$mails) = $this->client
->get_pending_ops($list);
63 $res = XDB
::query("SELECT mid
65 WHERE ml = {?} AND domain = {?}",
67 $mids = $res->fetchColumn();
68 foreach ($mails as $key=>$mail) {
69 if (in_array($mail['id'], $mids)) {
73 return array($subs, $mails);
76 function handler_lists(&$page)
78 function filter_owner($list)
83 function filter_member($list)
88 $domain = $this->prepare_client($page);
90 $page->changeTpl('lists/index.tpl');
91 $page->addJsLink('ajax.js');
92 $page->setTitle('Listes de diffusion');
95 if (Get
::has('del')) {
96 S
::assert_xsrf_token();
97 $this->client
->unsubscribe(Get
::v('del'));
100 if (Get
::has('add')) {
101 S
::assert_xsrf_token();
102 $this->client
->subscribe(Get
::v('add'));
103 pl_redirect('lists');
105 if (Post
::has('promo_add')) {
106 S
::assert_xsrf_token();
108 $promo = Post
::i('promo_add');
109 if ($promo >= 1900 and $promo < 2100) {
110 $this->client
->subscribe("promo$promo");
112 $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres.");
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;
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);
132 function handler_ajax(&$page, $list = null
)
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 S
::assert_xsrf_token();
139 if (Get
::has('unsubscribe')) {
140 $this->client
->unsubscribe($list);
142 if (Get
::has('subscribe')) {
143 $this->client
->subscribe($list);
145 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
146 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
148 if (Get
::has('mid')) {
149 $this->moderate_mail($domain, $list, Get
::i('mid'));
152 list($liste, $members, $owners) = $this->client
->get_members($list);
154 list($subs,$mails) = $this->get_pending_ops($domain, $list);
155 $liste['subscriptions'] = $subs;
156 $liste['mails'] = $mails;
158 $page->register_modifier('hdc', 'list_header_decode');
159 $page->assign_by_ref('liste', $liste);
162 function handler_create(&$page)
166 $page->changeTpl('lists/create.tpl');
168 $user_promo = S
::i('promo');
171 $young_promo = $very_young_promo = 0;
172 if ((($year > $user_promo) && ($month > 3)) && ($year < $user_promo +
5)) {
175 if ((($year > $user_promo) && ($month > 7)) && (($year < $user_promo +
1) && ($month < 8))) {
176 $very_young_promo = 1;
178 $page->assign('young_promo', $young_promo);
179 $page->assign('very_young_promo', $very_young_promo);
181 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
182 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
184 // click on validate button 'add_owner_sub' or type <enter>
185 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
186 // if we want to add an owner and then type <enter>, then both
187 // add_owner_sub and add_owner are filled.
188 $oforlifes = User
::getBulkForlifeEmails(Post
::v('add_owner'), true
);
189 $mforlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
190 if (!is_null($oforlifes)) {
191 $owners = array_merge($owners, $oforlifes);
193 // if we want to add a member and then type <enter>, then
194 // add_owner_sub is filled, whereas add_owner is empty.
195 if (!is_null($mforlifes)) {
196 $members = array_merge($members, $mforlifes);
200 // click on validate button 'add_member_sub'
201 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
202 $forlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
203 if (!is_null($forlifes)) {
204 $members = array_merge($members, $forlifes);
207 if (Post
::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
208 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
210 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
212 $forlifes = User
::getBulkForlifeEmails($upload->getContents(), true
);
213 if (!is_null($forlifes)) {
214 $members = array_merge($members, $forlifes);
220 $owners = array_unique($owners);
222 $members = array_unique($members);
224 $page->assign('owners', join("\n", $owners));
225 $page->assign('members', join("\n", $members));
227 if (!Post
::has('submit')) {
230 S
::assert_xsrf_token();
233 $asso = Post
::v('asso');
234 $liste = Post
::v('liste');
237 $page->trigError('Le champ «adresse souhaitée» est vide.');
239 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
240 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
243 if (($asso == "binet") ||
($asso == "alias")) {
244 $promo = Post
::i('promo');
245 $domain = $promo . '.' . $globals->mail
->domain
;
247 if (($promo < 1921) ||
($promo > date('Y'))) {
248 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
251 $new = $liste . '@' . $domain;
252 $res = XDB
::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
255 if ($asso == "groupex") {
256 $groupex_name = Post
::v('groupex_name');
258 $res_groupe = XDB
::query('SELECT mail_domain FROM groupex.asso WHERE nom={?}', $groupex_name);
259 $domain = $res_groupe->fetchOneCell();
262 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
265 $new = $liste . '@' . $domain;
266 $res = XDB
::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
268 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
269 $domain = $globals->mail
->domain
;
273 $n = $res->fetchOneCell();
276 $page->trigError('L\'«adresse souhaitée» est déjà prise.');
279 if (!Post
::v('desc')) {
280 $page->trigError('Le sujet est vide.');
283 if (!count($owners)) {
284 $page->trigError('Il n\'y a pas de gestionnaire.');
287 if (count($members)<4) {
288 $page->trigError('Il n\'y a pas assez de membres.');
291 if (!$page->nb_errs()) {
292 $page->assign('created', true
);
293 require_once 'validations.inc.php';
294 $req = new ListeReq(S
::user(), $asso, $liste, $domain,
295 Post
::v('desc'), Post
::i('advertise'),
296 Post
::i('modlevel'), Post
::i('inslevel'),
302 function handler_members(&$page, $liste = null
)
304 if (is_null($liste)) {
308 $this->prepare_client($page);
310 $page->changeTpl('lists/members.tpl');
312 if (Get
::has('del')) {
313 S
::assert_xsrf_token();
314 $this->client
->unsubscribe($liste);
315 pl_redirect('lists/members/'.$liste);
318 if (Get
::has('add')) {
319 S
::assert_xsrf_token();
320 $this->client
->subscribe($liste);
321 pl_redirect('lists/members/'.$liste);
324 $members = $this->client
->get_members($liste);
326 $tri_promo = !Env
::b('alpha');
328 if (list($det,$mem,$own) = $members) {
329 $membres = list_sort_members($mem, $tri_promo);
330 $moderos = list_sort_owners($own, $tri_promo);
332 $page->assign_by_ref('details', $det);
333 $page->assign_by_ref('members', $membres);
334 $page->assign_by_ref('owners', $moderos);
335 $page->assign('nb_m', count($mem));
337 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
341 function handler_csv(PlPage
&$page, $liste = null
)
343 if (is_null($liste)) {
346 $this->prepare_client($page);
347 $members = $this->client
->get_members($liste);
348 $list = list_fetch_names(list_extract_members($members[1]));
349 header('Content-Type: text/x-csv; charset=utf-8;');
351 header('Cache-Control: ');
353 echo "email,nom,prenom,promo\n";
354 foreach ($list as $member) {
355 echo @$member['email'] . ',' . @$member['nom'] . ',' . @$member['prenom'] . ',' . @$member['promo'] . "\n";
360 function handler_annu(&$page, $liste = null
, $action = null
, $subaction = null
)
362 if (is_null($liste)) {
366 $this->prepare_client($page);
368 if (Get
::has('del')) {
369 S
::assert_xsrf_token();
370 $this->client
->unsubscribe($liste);
371 pl_redirect('lists/annu/'.$liste);
373 if (Get
::has('add')) {
374 S
::assert_xsrf_token();
375 $this->client
->subscribe($liste);
376 pl_redirect('lists/annu/'.$liste);
379 $owners = $this->client
->get_owners($liste);
380 if (!is_array($owners)) {
381 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
385 list(,$members) = $this->client
->get_members($liste);
387 foreach ($members as $m) {
390 require_once 'userset.inc.php';
391 $view = new ArraySet($users);
392 $view->addMod('trombi', 'Trombinoscope', true
, array('with_promo' => true
));
393 if (empty($GLOBALS['IS_XNET_SITE'])) {
394 $view->addMod('minifiche', 'Mini-fiches', false
);
396 $view->addMod('geoloc', 'Planisphère');
397 $view->apply("lists/annu/$liste", $page, $action, $subaction);
398 if ($action == 'geoloc' && $subaction) {
402 $page->changeTpl('lists/annu.tpl');
403 $moderos = list_sort_owners($owners[1]);
404 $page->assign_by_ref('details', $owners[0]);
405 $page->assign_by_ref('owners', $moderos);
408 function handler_archives(&$page, $liste = null
, $action = null
, $artid = null
)
412 if (is_null($liste)) {
416 $domain = $this->prepare_client($page);
418 $page->changeTpl('lists/archives.tpl');
420 if (list($det) = $this->client
->get_members($liste)) {
421 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
422 && !$det['own'] && ($det['sub'] < 2)) {
423 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
425 $get = Array('listname' => $liste, 'domain' => $domain);
426 if (Post
::has('updateall')) {
427 $get['updateall'] = Post
::v('updateall');
429 require_once 'banana/ml.inc.php';
430 get_banana_params($get, null
, $action, $artid);
431 run_banana($page, 'MLBanana', $get);
433 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
437 function handler_rss(&$page, $liste = null
, $alias = null
, $hash = null
)
439 require_once('rss.inc.php');
440 $uid = init_rss(null
, $alias, $hash);
441 if (!$uid ||
!$liste) {
445 $res = XDB
::query("SELECT user_id AS uid, password, alias AS forlife
446 FROM auth_user_md5 AS u
447 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
448 WHERE u.user_id = {?}", $uid);
449 $row = $res->fetchOneAssoc();
450 $_SESSION = array_merge($row, $_SESSION);
452 $domain = $this->prepare_client($page);
453 if (list($det) = $this->client
->get_members($liste)) {
454 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
455 && !$det['own'] && ($det['sub'] < 2)) {
458 require_once('banana/ml.inc.php');
459 $banana = new MLBanana(S
::user(), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
465 function moderate_mail($domain, $liste, $mid)
467 if (Env
::has('mok')) {
469 } elseif (Env
::has('mno')) {
471 } elseif (Env
::has('mdel')) {
477 return XDB
::execute("INSERT IGNORE INTO ml_moderate
478 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
479 $liste, $domain, $mid, S
::i('uid'), $action, Post
::v('reason'));
482 function handler_moderate(&$page, $liste = null
)
484 if (is_null($liste)) {
488 $domain = $this->prepare_client($page);
490 $page->changeTpl('lists/moderate.tpl');
492 $page->register_modifier('hdc', 'list_header_decode');
494 if (Env
::has('sadd') || Env
::has('sdel')) {
495 S
::assert_xsrf_token();
497 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
498 $sub = $this->client
->get_pending_sub($liste, Env
::v('sadd'));
499 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
502 if (Post
::has('sdel')) { /* 2 = REJECT */
503 $sub = $this->client
->get_pending_sub($liste, Env
::v('sdel'));
504 $this->client
->handle_request($liste, Post
::v('sdel'), 2, utf8_decode(Post
::v('reason')));
508 $mailer = new PlMailer();
509 $mailer->setFrom("$liste-bounces@{$domain}");
510 $mailer->addTo("$liste-owner@{$domain}");
511 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
512 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
513 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S
::v('prenom') . ' '
514 . S
::v('nom') . '(' . S
::v('promo') . ")\n";
515 if (trim(Post
::v('reason'))) {
516 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
518 $mailer->setTxtBody(wordwrap($text, 72));
521 if (Env
::has('sadd')) {
522 pl_redirect('lists/moderate/'.$liste);
526 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
527 S
::assert_xsrf_token();
529 $mails = array_keys(Post
::v('select_mails'));
530 foreach($mails as $mail) {
531 $this->moderate_mail($domain, $liste, $mail);
533 } elseif (Env
::has('mid')) {
534 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
535 $page->changeTpl('lists/moderate_mail.tpl');
536 require_once('banana/moderate.inc.php');
537 $params = array('listname' => $liste, 'domain' => $domain,
538 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
539 $params['client'] = $this->client
;
540 run_banana($page, 'ModerationBanana', $params);
542 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
543 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
544 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
545 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
546 $msg = str_replace("%(listname)s", $liste, $msg);
547 $page->assign('msg', $msg);
549 } elseif (Get
::has('mid') && Env
::has('mok')) {
550 $page->changeTpl('lists/moderate_mail.tpl');
551 require_once('banana/moderate.inc.php');
552 $params = array('listname' => $liste, 'domain' => $domain,
553 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
554 $params['client'] = $this->client
;
555 run_banana($page, 'ModerationBanana', $params);
557 $msg = file_get_contents('/etc/mailman/fr/accept.txt');
558 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
559 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
560 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
561 $msg = str_replace("%(listname)s", $liste, $msg);
562 $page->assign('msg', $msg);
566 $mail = $this->moderate_mail($domain, $liste, Env
::i('mid'));
567 } elseif (Env
::has('sid')) {
568 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
569 foreach($subs as $user) {
570 if ($user['id'] == Env
::v('sid')) {
571 $page->changeTpl('lists/moderate_sub.tpl');
572 $page->assign('del_user', $user);
580 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
581 foreach ($mails as $key=>$mail) {
582 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
583 if ($mail['fromx']) {
584 $page->assign('with_fromx', true
);
586 $page->assign('with_nonfromx', true
);
589 $page->assign_by_ref('subs', $subs);
590 $page->assign_by_ref('mails', $mails);
592 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
596 static public function no_login_callback($login)
598 require_once 'user.func.inc.php';
599 global $list_unregistered, $globals;
601 $users = get_not_registered_user($login, true
);
602 if ($users && $users->total()) {
603 if (!isset($list_unregistered)) {
604 $list_unregistered = array();
606 $list_unregistered[$login] = $users;
608 list($name, $dom) = @explode
('@', $login);
609 if ($dom == $globals->mail
->domain ||
$dom == $globals->mail
->domain2
) {
610 User
::_default_user_callback($login);
615 function handler_admin(&$page, $liste = null
)
619 if (is_null($liste)) {
623 $domain = $this->prepare_client($page);
625 $page->changeTpl('lists/admin.tpl');
627 if (Env
::has('send_mark')) {
628 S
::assert_xsrf_token();
630 $actions = Env
::v('mk_action');
631 $uids = Env
::v('mk_uid');
632 $mails = Env
::v('mk_email');
633 foreach ($actions as $key=>$action) {
638 case 'marketu': case 'markets':
639 require_once 'emails.inc.php';
640 $mail = valide_email($mails[$key]);
641 if (isvalid_email_redirection($mail)) {
642 $from = ($action == 'marketu') ?
'user' : 'staff';
643 $market = Marketing
::get($uids[$key], $mail);
645 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S
::v('uid'));
652 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
653 VALUES ({?}, \'list\', {?}, {?})',
654 $uids[$key], $liste, $domain);
659 if (Env
::has('add_member')) {
660 S
::assert_xsrf_token();
662 $members = User
::getBulkForlifeEmails(Env
::v('add_member'),
664 array('ListsModule', 'no_login_callback'));
665 $arr = $this->client
->mass_subscribe($liste, $members);
666 if (is_array($arr)) {
667 foreach($arr as $addr) {
668 $page->trigSuccess("{$addr[0]} inscrit.");
673 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
674 S
::assert_xsrf_token();
676 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
678 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
680 $members = User
::getBulkForlifeEmails($upload->getContents(),
682 array('ListsModule', 'no_login_callback'));
683 $arr = $this->client
->mass_subscribe($liste, $members);
684 if (is_array($arr)) {
685 foreach($arr as $addr) {
686 $page->trigSuccess("{$addr[0]} inscrit.");
692 if (Env
::has('del_member')) {
693 S
::assert_xsrf_token();
695 if (strpos(Env
::v('del_member'), '@') === false
) {
696 $this->client
->mass_unsubscribe(
697 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
699 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
701 pl_redirect('lists/admin/'.$liste);
704 if (Env
::has('add_owner')) {
705 S
::assert_xsrf_token();
707 $owners = User
::getBulkForlifeEmails(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
709 foreach ($owners as $login) {
710 if ($this->client
->add_owner($liste, $login)) {
711 $page->trigSuccess($login ." ajouté aux modérateurs.");
717 if (Env
::has('del_owner')) {
718 S
::assert_xsrf_token();
720 if (strpos(Env
::v('del_owner'), '@') === false
) {
721 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
723 $this->client
->del_owner($liste, Env
::v('del_owner'));
725 pl_redirect('lists/admin/'.$liste);
728 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
729 global $list_unregistered;
730 if ($list_unregistered) {
731 $page->assign_by_ref('unregistered', $list_unregistered);
733 $membres = list_sort_members($mem, @$tri_promo);
734 $moderos = list_sort_owners($own, @$tri_promo);
736 $page->assign_by_ref('details', $det);
737 $page->assign_by_ref('members', $membres);
738 $page->assign_by_ref('owners', $moderos);
739 $page->assign('np_m', count($mem));
742 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
743 ." Si tu penses qu'il s'agit d'une erreur, "
744 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
748 function handler_options(&$page, $liste = null
)
750 if (is_null($liste)) {
754 $this->prepare_client($page);
756 $page->changeTpl('lists/options.tpl');
758 if (Post
::has('submit')) {
759 S
::assert_xsrf_token();
762 $values = array_map('utf8_decode', $values);
763 $spamlevel = intval($values['bogo_level']);
764 $unsurelevel = intval($values['unsure_level']);
765 if ($spamlevel == 0) {
768 if ($spamlevel > 3 ||
$spamlevel < 0 ||
$unsurelevel < 0 ||
$unsurelevel > 1) {
769 $page->trigError("Réglage de l'antispam non valide");
771 $this->client
->set_bogo_level($liste, ($spamlevel << 1) +
$unsurelevel);
773 switch($values['moderate']) {
775 $values['generic_nonmember_action'] = 0;
776 $values['default_member_moderation'] = 0;
779 $values['generic_nonmember_action'] = 1;
780 $values['default_member_moderation'] = 0;
783 $values['generic_nonmember_action'] = 1;
784 $values['default_member_moderation'] = 1;
787 unset($values['submit'], $values['bogo_level'], $values['moderate']);
788 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
789 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
790 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
791 if (isset($values['subject_prefix'])) {
792 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
794 $this->client
->set_owner_options($liste, $values);
795 } elseif (isvalid_email(Post
::v('atn_add'))) {
796 S
::assert_xsrf_token();
797 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
798 } elseif (Get
::has('atn_del')) {
799 S
::assert_xsrf_token();
800 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
801 pl_redirect('lists/options/'.$liste);
804 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
805 $page->assign_by_ref('details', $details);
806 $page->assign_by_ref('options', $options);
807 $bogo_level = intval($this->client
->get_bogo_level($liste));
808 $page->assign('unsure_level', $bogo_level & 1);
809 $page->assign('bogo_level', $bogo_level >> 1);
811 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
815 function handler_delete(&$page, $liste = null
)
818 if (is_null($liste)) {
822 $domain = $this->prepare_client($page);
823 if ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
828 $domain = '@' . $domain;
833 $page->changeTpl('lists/delete.tpl');
834 if (Post
::v('valid') == 'OUI') {
835 S
::assert_xsrf_token();
837 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
838 foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) {
839 XDB
::execute("DELETE FROM $table
840 WHERE type={?} AND alias={?}",
841 $type, $liste.$app.$domain);
843 $page->assign('deleted', true
);
844 $page->trigSuccess('La liste a été détruite !');
846 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
847 . 'Contact les administrateurs du site pour régler le problème : '
848 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
850 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
851 if (!$details['own']) {
852 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
854 $page->assign_by_ref('details', $details);
855 $page->assign_by_ref('options', $options);
856 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
858 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
862 function handler_soptions(&$page, $liste = null
)
864 if (is_null($liste)) {
868 $this->prepare_client($page);
870 $page->changeTpl('lists/soptions.tpl');
872 if (Post
::has('submit')) {
873 S
::assert_xsrf_token();
876 $values = array_map('utf8_decode', $values);
877 unset($values['submit']);
878 $values['advertised'] = empty($values['advertised']) ? false
: true
;
879 $values['archive'] = empty($values['archive']) ? false
: true
;
880 $this->client
->set_admin_options($liste, $values);
883 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
884 $page->assign_by_ref('details', $details);
885 $page->assign_by_ref('options', $options);
887 $page->kill("La liste n'existe pas");
891 function handler_check(&$page, $liste = null
)
893 if (is_null($liste)) {
897 $this->prepare_client($page);
899 $page->changeTpl('lists/check.tpl');
901 if (Post
::has('correct')) {
902 S
::assert_xsrf_token();
903 $this->client
->check_options($liste, true
);
906 if (list($details,$options) = $this->client
->check_options($liste)) {
907 $page->assign_by_ref('details', $details);
908 $page->assign_by_ref('options', $options);
910 $page->kill("La liste n'existe pas");
914 function handler_admin_all(&$page) {
915 $page->changeTpl('lists/admin_all.tpl');
916 $page->setTitle('Administration - Mailing lists');
918 $client = new MMList(S
::v('uid'), S
::v('password'));
919 $listes = $client->get_all_lists();
920 $page->assign_by_ref('listes', $listes);
924 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: