8a5ccb9abb1746bc3dc403e51e6c3f0579b41fb2
2 /***************************************************************************
3 * Copyright (C) 2003-2011 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_PASSWD
, 'user'),
30 'lists/ajax' => $this->make_hook('ajax', AUTH_PASSWD
, 'user', NO_AUTH
),
31 'lists/create' => $this->make_hook('create', AUTH_PASSWD
, 'lists'),
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE
, 'user'),
34 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE
, 'user'),
35 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE
, 'user'),
36 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
, 'user'),
37 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC
, 'user', NO_HTTPS
),
39 'lists/moderate' => $this->make_hook('moderate', AUTH_PASSWD
, 'user'),
40 'lists/admin' => $this->make_hook('admin', AUTH_PASSWD
, 'user'),
41 'lists/options' => $this->make_hook('options', AUTH_PASSWD
, 'user'),
42 'lists/delete' => $this->make_hook('delete', AUTH_PASSWD
, 'user'),
44 'lists/soptions' => $this->make_hook('soptions', AUTH_PASSWD
, 'user'),
45 'lists/check' => $this->make_hook('check', AUTH_PASSWD
, 'user'),
46 'admin/lists' => $this->make_hook('admin_all', AUTH_PASSWD
, 'admin'),
47 'admin/aliases' => $this->make_hook('aaliases', AUTH_PASSWD
, 'admin')
51 function prepare_client($page, $user = null
)
55 $this->load('lists.inc.php');
60 $this->client
= new MMList($user);
61 return $globals->mail
->domain
;
64 function verify_list_owner($page, $liste)
66 if (list(, , $owners) = $this->client
->get_members($liste)) {
67 if (!(in_array(S
::user()->forlifeEmail(), $owners) || S
::admin())) {
68 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
71 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
72 . " Si tu penses qu'il s'agit d'une erreur, "
73 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
77 function get_pending_ops($domain, $list)
79 list($subs,$mails) = $this->client
->get_pending_ops($list);
80 $res = XDB
::query("SELECT mid
81 FROM email_list_moderate
82 WHERE ml = {?} AND domain = {?}",
84 $mids = $res->fetchColumn();
85 foreach ($mails as $key=>$mail) {
86 if (in_array($mail['id'], $mids)) {
90 return array($subs, $mails);
93 function handler_lists($page)
95 function filter_owner($list)
100 function filter_member($list)
105 $domain = $this->prepare_client($page);
107 $page->changeTpl('lists/index.tpl');
108 $page->setTitle('Listes de diffusion');
111 if (Get
::has('del')) {
112 S
::assert_xsrf_token();
113 $this->client
->unsubscribe(Get
::v('del'));
114 pl_redirect('lists');
116 if (Get
::has('add')) {
117 S
::assert_xsrf_token();
118 $this->client
->subscribe(Get
::v('add'));
119 pl_redirect('lists');
121 if (Post
::has('promo_add')) {
122 S
::assert_xsrf_token();
124 $promo = Post
::i('promo_add');
125 if ($promo >= 1900 and $promo < 2100) {
126 $this->client
->subscribe("promo$promo");
128 $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
132 if (!is_null($listes = $this->client
->get_lists())) {
133 $owner = array_filter($listes, 'filter_owner');
134 $listes = array_diff_key($listes, $owner);
135 $member = array_filter($listes, 'filter_member');
136 $listes = array_diff_key($listes, $member);
137 foreach ($owner as $key => $liste) {
138 list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
139 $owner[$key]['subscriptions'] = $subs;
140 $owner[$key]['mails'] = $mails;
142 $page->register_modifier('hdc', 'list_header_decode');
143 $page->assign_by_ref('owner', $owner);
144 $page->assign_by_ref('member', $member);
145 $page->assign_by_ref('public', $listes);
149 function handler_ajax($page, $list = null
)
151 pl_content_headers("text/html");
152 $domain = $this->prepare_client($page);
153 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
154 S
::assert_xsrf_token();
156 if (Get
::has('unsubscribe')) {
157 $this->client
->unsubscribe($list);
159 if (Get
::has('subscribe')) {
160 $this->client
->subscribe($list);
162 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
163 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
165 if (Get
::has('mid')) {
166 $this->moderate_mail($domain, $list, Get
::i('mid'));
169 list($liste, $members, $owners) = $this->client
->get_members($list);
171 list($subs,$mails) = $this->get_pending_ops($domain, $list);
172 $liste['subscriptions'] = $subs;
173 $liste['mails'] = $mails;
175 $page->register_modifier('hdc', 'list_header_decode');
176 $page->assign_by_ref('liste', $liste);
179 function handler_create($page)
183 $page->changeTpl('lists/create.tpl');
185 $user_promo = S
::user()->profile()->yearPromo();
188 // scolar year starts in september
189 $scolarmonth = ($year - $user_promo) * 12 +
($month - 8);
190 $young_promo = $very_young_promo = 0;
191 // binet are accessible only in april in the first year and until
192 // march of the 5th year
193 if ($scolarmonth >= 8 && $scolarmonth < 56) {
196 // PSC aliases are accesible only between september and june of the second
198 if ($scolarmonth >= 12 && $scolarmonth < 22) {
199 $very_young_promo = 1;
201 $page->assign('young_promo', $young_promo);
202 $page->assign('very_young_promo', $very_young_promo);
204 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
205 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
207 // click on validate button 'add_owner_sub' or type <enter>
208 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
209 // if we want to add an owner and then type <enter>, then both
210 // add_owner_sub and add_owner are filled.
211 $oforlifes = User
::getBulkForlifeEmails(Post
::v('add_owner'), true
);
212 $mforlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
213 if (!is_null($oforlifes)) {
214 $owners = array_merge($owners, $oforlifes);
216 // if we want to add a member and then type <enter>, then
217 // add_owner_sub is filled, whereas add_owner is empty.
218 if (!is_null($mforlifes)) {
219 $members = array_merge($members, $mforlifes);
223 // click on validate button 'add_member_sub'
224 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
225 $forlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
226 if (!is_null($forlifes)) {
227 $members = array_merge($members, $forlifes);
230 if (Post
::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
231 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
233 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
235 $forlifes = User
::getBulkForlifeEmails($upload->getContents(), true
);
236 if (!is_null($forlifes)) {
237 $members = array_merge($members, $forlifes);
243 $owners = array_unique($owners);
245 $members = array_unique($members);
247 $page->assign('owners', join("\n", $owners));
248 $page->assign('members', join("\n", $members));
250 if (!Post
::has('submit')) {
253 S
::assert_xsrf_token();
256 $asso = Post
::t('asso');
257 $list = strtolower(Post
::t('liste'));
260 $page->trigError('Le champ « adresse souhaitée » est vide.');
262 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
263 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
266 if (($asso == 'binet') ||
($asso == 'alias')) {
267 $promo = Post
::i('promo');
268 $domain = $promo . '.' . $globals->mail
->domain
;
270 if (($promo < 1921) ||
($promo > date('Y'))) {
271 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
274 } elseif ($asso == 'groupex') {
275 $domain = XDB
::fetchOneCell('SELECT mail_domain
278 Post
::t('groupex_name'));
281 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
284 $domain = $globals->mail
->domain
;
287 require_once 'emails.inc.php';
288 if (list_exist($list, $domain)) {
289 $page->trigError("L'« adresse souhaitée » est déjà prise.");
292 if (!Post
::t('desc')) {
293 $page->trigError('Le sujet est vide.');
296 if (!count($owners)) {
297 $page->trigError('Il n\'y a pas de gestionnaire.');
300 if (count($members) < 4) {
301 $page->trigError('Il n\'y a pas assez de membres.');
304 if (!$page->nb_errs()) {
305 $page->trigSuccess('Demande de création envoyée !');
306 $page->assign('created', true
);
307 $req = new ListeReq(S
::user(), $asso, $list, $domain,
308 Post
::t('desc'), Post
::i('advertise'),
309 Post
::i('modlevel'), Post
::i('inslevel'),
315 function handler_members($page, $liste = null
)
317 if (is_null($liste)) {
321 $this->prepare_client($page);
323 $page->changeTpl('lists/members.tpl');
325 if (Get
::has('del')) {
326 S
::assert_xsrf_token();
327 $this->client
->unsubscribe($liste);
328 pl_redirect('lists/members/'.$liste);
331 if (Get
::has('add')) {
332 S
::assert_xsrf_token();
333 $this->client
->subscribe($liste);
334 pl_redirect('lists/members/'.$liste);
337 $members = $this->client
->get_members($liste);
339 $tri_promo = !Env
::b('alpha');
341 if (list($det,$mem,$own) = $members) {
342 $membres = list_sort_members($mem, $tri_promo);
343 $moderos = list_sort_owners($own, $tri_promo);
345 $page->assign_by_ref('details', $det);
346 $page->assign_by_ref('members', $membres);
347 $page->assign_by_ref('owners', $moderos);
348 $page->assign('nb_m', count($mem));
350 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
354 function handler_csv(PlPage
$page, $liste = null
)
356 if (is_null($liste)) {
359 $this->prepare_client($page);
360 $members = $this->client
->get_members($liste);
361 $list = list_fetch_basic_info(list_extract_members($members[1]));
362 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
364 echo utf8_decode("Nom;Prénom;Promotion\n");
365 echo utf8_decode(implode("\n", $list));
369 function handler_annu($page, $liste = null
, $action = null
, $subaction = null
)
371 if (is_null($liste)) {
375 $this->prepare_client($page);
377 if (Get
::has('del')) {
378 S
::assert_xsrf_token();
379 $this->client
->unsubscribe($liste);
380 pl_redirect('lists/annu/'.$liste);
382 if (Get
::has('add')) {
383 S
::assert_xsrf_token();
384 $this->client
->subscribe($liste);
385 pl_redirect('lists/annu/'.$liste);
388 $owners = $this->client
->get_owners($liste);
389 if (!is_array($owners)) {
390 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
393 list(,$members) = $this->client
->get_members($liste);
395 if ($action == 'moderators') {
397 $show_moderators = true
;
398 $action = $subaction;
401 $show_moderators = false
;
403 foreach ($members as $m) {
408 require_once 'userset.inc.php';
409 $view = new UserArraySet($users);
410 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
));
411 $view->addMod('listmember', 'Annuaire', true
);
412 if (empty($GLOBALS['IS_XNET_SITE'])) {
413 $view->addMod('minifiche', 'Mini-fiches', false
);
415 $view->addMod('map', 'Planisphère');
416 $view->apply("lists/annu/$liste", $page, $action, $subaction);
418 $page->changeTpl('lists/annu.tpl');
419 $page->assign_by_ref('details', $owners[0]);
420 $page->assign('show_moderators', $show_moderators);
423 function handler_archives($page, $liste = null
, $action = null
, $artid = null
)
427 if (is_null($liste)) {
431 $domain = $this->prepare_client($page);
433 $page->changeTpl('lists/archives.tpl');
435 if (list($det) = $this->client
->get_members($liste)) {
436 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
437 && !$det['own'] && ($det['sub'] < 2)) {
438 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
440 $get = Array('listname' => $liste, 'domain' => $domain);
441 if (Post
::has('updateall')) {
442 $get['updateall'] = Post
::v('updateall');
444 require_once 'banana/ml.inc.php';
445 get_banana_params($get, null
, $action, $artid);
446 run_banana($page, 'MLBanana', $get);
448 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
452 function handler_rss($page, $liste = null
, $alias = null
, $hash = null
)
457 $user = Platal
::session()->tokenAuth($alias, $hash);
458 if (is_null($user)) {
462 $domain = $this->prepare_client($page, $user);
463 if (list($det) = $this->client
->get_members($liste)) {
464 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
465 && !$det['own'] && ($det['sub'] < 2)) {
468 require_once('banana/ml.inc.php');
469 $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
475 function moderate_mail($domain, $liste, $mid)
477 if (Env
::has('mok')) {
479 } elseif (Env
::has('mno')) {
481 } elseif (Env
::has('mdel')) {
487 return XDB
::execute("INSERT IGNORE INTO email_list_moderate
488 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
489 $liste, $domain, $mid, S
::i('uid'), $action, Post
::v('reason'));
492 function handler_moderate($page, $liste = null
)
494 if (is_null($liste)) {
498 $domain = $this->prepare_client($page);
499 $this->verify_list_owner($page, $liste);
501 $page->changeTpl('lists/moderate.tpl');
503 $page->register_modifier('hdc', 'list_header_decode');
505 if (Env
::has('sadd') || Env
::has('sdel')) {
506 S
::assert_xsrf_token();
508 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
509 $sub = $this->client
->get_pending_sub($liste, Env
::v('sadd'));
510 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
513 if (Post
::has('sdel')) { /* 2 = REJECT */
514 $sub = $this->client
->get_pending_sub($liste, Env
::v('sdel'));
515 $this->client
->handle_request($liste, Post
::v('sdel'), 2, utf8_decode(Post
::v('reason')));
519 $mailer = new PlMailer();
520 $mailer->setFrom("$liste-bounces@{$domain}");
521 $mailer->addTo("$liste-owner@{$domain}");
522 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
523 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
524 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S
::user()->fullName(true
) . ".\n";
525 if (trim(Post
::v('reason'))) {
526 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
528 $mailer->setTxtBody(wordwrap($text, 72));
531 if (Env
::has('sadd')) {
532 pl_redirect('lists/moderate/'.$liste);
536 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
537 S
::assert_xsrf_token();
539 $mails = array_keys(Post
::v('select_mails'));
540 foreach($mails as $mail) {
541 $this->moderate_mail($domain, $liste, $mail);
543 } elseif (Env
::has('mid')) {
544 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
545 require_once 'banana/moderate.inc.php';
547 $page->changeTpl('lists/moderate_mail.tpl');
548 $params = array('listname' => $liste, 'domain' => $domain,
549 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
550 $params['client'] = $this->client
;
551 run_banana($page, 'ModerationBanana', $params);
553 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
554 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
555 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
556 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
557 $msg = str_replace("%(listname)s", $liste, $msg);
558 $page->assign('msg', $msg);
562 $this->moderate_mail($domain, $liste, Env
::i('mid'));
563 } elseif (Env
::has('sid')) {
564 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
565 foreach($subs as $user) {
566 if ($user['id'] == Env
::v('sid')) {
567 $page->changeTpl('lists/moderate_sub.tpl');
568 $page->assign('del_user', $user);
576 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
577 foreach ($mails as $key=>$mail) {
578 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
579 if ($mail['fromx']) {
580 $page->assign('with_fromx', true
);
582 $page->assign('with_nonfromx', true
);
585 $page->assign_by_ref('subs', $subs);
586 $page->assign_by_ref('mails', $mails);
588 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
592 static public function no_login_callback($login)
594 global $list_unregistered;
596 $users = User
::getPendingAccounts($login, true
);
597 if ($users && $users->total()) {
598 if (!isset($list_unregistered)) {
599 $list_unregistered = array();
601 $list_unregistered[$login] = $users;
603 list($name, $domain) = @explode
('@', $login);
604 if (User
::isMainMailDomain($domain)) {
605 User
::_default_user_callback($login);
610 function handler_admin($page, $liste = null
)
614 if (is_null($liste)) {
618 $domain = $this->prepare_client($page);
619 $force_rights = false
;
620 if ($GLOBALS['IS_XNET_SITE']) {
621 $perms = S
::v('perms');
622 if (is_object($perms) && $perms->hasFlag('groupadmin')) {
623 $force_rights = true
;
626 $page->assign('group_admin', $force_rights);
627 if (!$force_rights) {
628 $this->verify_list_owner($page, $liste);
631 $page->changeTpl('lists/admin.tpl');
633 if (Env
::has('send_mark')) {
634 S
::assert_xsrf_token();
636 $actions = Env
::v('mk_action');
637 $uids = Env
::v('mk_uid');
638 $mails = Env
::v('mk_email');
639 foreach ($actions as $key=>$action) {
644 case 'marketu': case 'markets':
645 require_once 'emails.inc.php';
646 $user = User
::get($uids[$key]);
647 $mail = valide_email($mails[$key]);
648 if (isvalid_email_redirection($mail, $user)) {
649 $from = ($action == 'marketu') ?
'user' : 'staff';
650 $market = Marketing
::get($uids[$key], $mail);
652 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S
::v('uid'));
659 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
660 VALUES ({?}, \'list\', {?}, {?})',
661 $uids[$key], $liste, $domain);
666 if (Env
::has('add_member') ||
667 isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
668 S
::assert_xsrf_token();
670 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
671 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
673 $page->trigError("Une erreur s'est produite lors du téléchargement du fichier.");
675 $logins = $upload->getContents();
678 $logins = Env
::v('add_member');
681 $logins = preg_split("/[; ,\r\n\|]+/", $logins);
682 $members = User
::getBulkForlifeEmails($logins,
684 array('ListsModule', 'no_login_callback'));
685 $unfound = array_diff_key($logins, $members);
687 // Make sure we send a list (array_values) of unique (array_unique)
689 $members = array_values(array_unique($members));
691 $arr = $this->client
->mass_subscribe($liste, $members);
693 $successes = array();
694 if (is_array($arr)) {
695 foreach($arr as $addr) {
696 $successes[] = $addr[1];
697 $page->trigSuccess("{$addr[0]} inscrit.");
701 $already = array_diff($members, $successes);
702 if (is_array($already)) {
703 foreach ($already as $item) {
704 $page->trigWarning($item . ' est déjà inscrit.');
708 if (is_array($unfound)) {
709 foreach ($unfound as $item) {
710 if (trim($item) != '') {
711 $page->trigError($item . " ne correspond pas à un compte existant et n'est pas une adresse email.");
717 if (Env
::has('del_member')) {
718 S
::assert_xsrf_token();
720 if (strpos(Env
::v('del_member'), '@') === false
) {
721 if ($del_member = User
::getSilent(Env
::t('del_member'))) {
722 $this->client
->mass_unsubscribe($liste, array($del_member->forlifeEmail()));
725 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
727 pl_redirect('lists/admin/'.$liste);
730 if (Env
::has('add_owner')) {
731 S
::assert_xsrf_token();
733 $owners = User
::getBulkForlifeEmails(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
735 foreach ($owners as $login) {
736 if ($this->client
->add_owner($liste, $login)) {
737 $page->trigSuccess($login ." ajouté aux modérateurs.");
743 if (Env
::has('del_owner')) {
744 S
::assert_xsrf_token();
746 if (strpos(Env
::v('del_owner'), '@') === false
) {
747 if ($del_owner = User
::getSilent(Env
::t('del_owner'))) {
748 $this->client
->mass_unsubscribe($liste, array($del_owner->forlifeEmail()));
751 $this->client
->del_owner($liste, Env
::v('del_owner'));
753 pl_redirect('lists/admin/'.$liste);
756 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
757 global $list_unregistered;
758 if ($list_unregistered) {
759 $page->assign_by_ref('unregistered', $list_unregistered);
761 $membres = list_sort_members($mem, @$tri_promo);
762 $moderos = list_sort_owners($own, @$tri_promo);
764 $page->assign_by_ref('details', $det);
765 $page->assign_by_ref('members', $membres);
766 $page->assign_by_ref('owners', $moderos);
767 $page->assign('np_m', count($mem));
769 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
770 . " Si tu penses qu'il s'agit d'une erreur, "
771 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
775 function handler_options($page, $liste = null
)
777 if (is_null($liste)) {
781 $this->prepare_client($page);
782 $this->verify_list_owner($page, $liste);
784 $page->changeTpl('lists/options.tpl');
786 if (Post
::has('submit')) {
787 S
::assert_xsrf_token();
790 $values = array_map('utf8_decode', $values);
791 $spamlevel = intval($values['bogo_level']);
792 $unsurelevel = intval($values['unsure_level']);
793 if ($spamlevel == 0) {
796 if ($spamlevel > 3 ||
$spamlevel < 0 ||
$unsurelevel < 0 ||
$unsurelevel > 1) {
797 $page->trigError("Réglage de l'antispam non valide");
799 $this->client
->set_bogo_level($liste, ($spamlevel << 1) +
$unsurelevel);
801 switch($values['moderate']) {
803 $values['generic_nonmember_action'] = 0;
804 $values['default_member_moderation'] = 0;
807 $values['generic_nonmember_action'] = 1;
808 $values['default_member_moderation'] = 0;
811 $values['generic_nonmember_action'] = 1;
812 $values['default_member_moderation'] = 1;
815 unset($values['submit'], $values['bogo_level'], $values['moderate']);
816 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
817 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
818 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
819 if (isset($values['subject_prefix'])) {
820 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
822 $this->client
->set_owner_options($liste, $values);
823 } elseif (isvalid_email(Post
::v('atn_add'))) {
824 S
::assert_xsrf_token();
825 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
826 } elseif (Get
::has('atn_del')) {
827 S
::assert_xsrf_token();
828 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
829 pl_redirect('lists/options/'.$liste);
832 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
833 $page->assign_by_ref('details', $details);
834 $page->assign_by_ref('options', $options);
835 $bogo_level = intval($this->client
->get_bogo_level($liste));
836 $page->assign('unsure_level', $bogo_level & 1);
837 $page->assign('bogo_level', $bogo_level >> 1);
839 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
843 function handler_delete($page, $liste = null
)
846 if (is_null($liste)) {
850 $domain = $this->prepare_client($page);
851 $this->verify_list_owner($page, $liste);
852 $page->changeTpl('lists/delete.tpl');
853 if (Post
::v('valid') == 'OUI') {
854 S
::assert_xsrf_token();
856 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
857 require_once 'emails.inc.php';
859 delete_list($liste, $domain);
860 $page->assign('deleted', true
);
861 $page->trigSuccess('La liste a été détruite !');
863 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
864 . 'Contact les administrateurs du site pour régler le problème : '
865 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
867 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
868 if (!$details['own']) {
869 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
871 $page->assign_by_ref('details', $details);
872 $page->assign_by_ref('options', $options);
873 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
875 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
879 function handler_soptions($page, $liste = null
)
881 if (is_null($liste)) {
885 $this->prepare_client($page);
886 $this->verify_list_owner($page, $liste);
888 $page->changeTpl('lists/soptions.tpl');
890 if (Post
::has('submit')) {
891 S
::assert_xsrf_token();
894 $values = array_map('utf8_decode', $values);
895 unset($values['submit']);
896 $values['advertised'] = empty($values['advertised']) ? false
: true
;
897 $values['archive'] = empty($values['archive']) ? false
: true
;
898 $this->client
->set_admin_options($liste, $values);
901 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
902 $page->assign_by_ref('details', $details);
903 $page->assign_by_ref('options', $options);
905 $page->kill("La liste n'existe pas.");
909 function handler_check($page, $liste = null
)
911 if (is_null($liste)) {
915 $this->prepare_client($page);
916 $this->verify_list_owner($page, $liste);
918 $page->changeTpl('lists/check.tpl');
920 if (Post
::has('correct')) {
921 S
::assert_xsrf_token();
922 $this->client
->check_options($liste, true
);
925 if (list($details,$options) = $this->client
->check_options($liste)) {
926 $page->assign_by_ref('details', $details);
927 $page->assign_by_ref('options', $options);
929 $page->kill("La liste n'existe pas.");
933 function handler_admin_all($page)
935 $page->changeTpl('lists/admin_all.tpl');
936 $page->setTitle('Administration - Mailing lists');
938 $this->prepare_client($page);
939 $listes = $this->client
->get_all_lists();
940 $page->assign_by_ref('listes', $listes);
943 function handler_aaliases($page, $alias = null
)
946 require_once 'emails.inc.php';
947 $page->setTitle('Administration - Aliases');
949 if (Post
::has('new_alias')) {
950 pl_redirect('admin/aliases/' . Post
::t('new_alias') . '@' . $globals->mail
->domain
);
953 // If no alias, list them all.
954 if (is_null($alias)) {
955 $page->changeTpl('lists/admin_aliases.tpl');
956 $page->assign('aliases', array_merge(iterate_list_alias($globals->mail
->domain
), iterate_list_alias($globals->mail
->domain2
)));
960 list($local_part, $domain) = explode('@', $alias);
961 if (!($globals->mail
->domain
== $domain ||
$globals->mail
->domain2
== $domain)
962 ||
!preg_match("/^[a-zA-Z0-9\-\.]*$/", $local_part)) {
963 $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
966 // Now we can perform the action.
967 if (Post
::has('del_alias')) {
968 S
::assert_xsrf_token();
970 delete_list_alias($local_part, $domain);
971 $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
974 if (Post
::has('add_member')) {
975 S
::assert_xsrf_token();
977 if (add_to_list_alias(Post
::t('add_member'), $local_part, $domain)) {
978 $page->trigSuccess('Ajout réussit.');
980 $page->trigError('Ajout infructueux.');
984 if (Get
::has('del_member')) {
985 S
::assert_xsrf_token();
987 if (delete_from_list_alias(Get
::t('del_member'), $local_part, $domain)) {
988 $page->trigSuccess('Suppression réussie.');
990 $page->trigError('Suppression infructueuse.');
994 $page->changeTpl('lists/admin_edit_alias.tpl');
995 $page->assign('members', list_alias_members($local_part, $domain));
996 $page->assign('alias', $alias);
1000 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: