8624bd4ebf8b3b76282078ffe5a222270dd5d5d6
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
;
67 return $globals->mail
->domain
;
70 function prepare_list($list, $user=null
)
75 $this->mlist
= new MailingList($list, $this->get_domain(), $user);
78 function is_group_admin($page)
80 $force_rights = false
;
81 if ($GLOBALS['IS_XNET_SITE']) {
82 $perms = S
::v('perms');
83 if (is_object($perms) && $perms->hasFlag('groupadmin')) {
87 $page->assign('group_admin', $force_rights);
92 function verify_list_owner($page, $liste)
94 if (list(, , $owners) = $this->client
->get_members($liste)) {
95 if (!(in_array(S
::user()->forlifeEmail(), $owners) || S
::admin())) {
96 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
99 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
100 . " Si tu penses qu'il s'agit d'une erreur, "
101 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
105 function get_pending_ops($domain, $list)
107 list($subs,$mails) = $this->client
->get_pending_ops($list);
108 $res = XDB
::query("SELECT mid
109 FROM email_list_moderate
110 WHERE ml = {?} AND domain = {?}",
112 $mids = $res->fetchColumn();
113 foreach ($mails as $key=>$mail) {
114 if (in_array($mail['id'], $mids)) {
118 return array($subs, $mails);
121 function handler_lists($page)
123 function filter_owner($list)
128 function filter_member($list)
133 $domain = $this->prepare_client($page);
135 $page->changeTpl('lists/index.tpl');
136 $page->setTitle('Listes de diffusion');
139 if (Get
::has('del')) {
140 S
::assert_xsrf_token();
141 $this->client
->unsubscribe(Get
::v('del'));
142 pl_redirect('lists');
144 if (Get
::has('add')) {
145 S
::assert_xsrf_token();
146 $this->client
->subscribe(Get
::v('add'));
147 pl_redirect('lists');
149 if (Post
::has('promo_add')) {
150 S
::assert_xsrf_token();
152 $promo = Post
::i('promo_add');
153 if ($promo >= 1900 and $promo < 2100) {
154 $mlist = MailingList
::promo($promo, S
::user());
157 $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
161 if (!is_null($listes = $this->client
->get_lists())) {
162 $owner = array_filter($listes, 'filter_owner');
163 $listes = array_diff_key($listes, $owner);
164 $member = array_filter($listes, 'filter_member');
165 $listes = array_diff_key($listes, $member);
166 foreach ($owner as $key => $liste) {
167 list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
168 $owner[$key]['subscriptions'] = $subs;
169 $owner[$key]['mails'] = $mails;
171 $page->register_modifier('hdc', 'list_header_decode');
172 $page->assign_by_ref('owner', $owner);
173 $page->assign_by_ref('member', $member);
174 $page->assign_by_ref('public', $listes);
178 function handler_ajax($page, $list = null
)
180 pl_content_headers("text/html");
181 $domain = $this->prepare_client($page);
182 $this->prepare_list($list);
183 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
184 S
::assert_xsrf_token();
186 if (Get
::has('unsubscribe')) {
187 $this->mlist
->unsubscribe();
189 if (Get
::has('subscribe')) {
190 $this->mlist
->subscribe();
192 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
193 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
195 if (Get
::has('mid')) {
196 $this->moderate_mail($domain, $list, Get
::i('mid'));
199 list($liste, $members, $owners) = $this->mlist
->getMembers();
201 list($subs,$mails) = $this->get_pending_ops($domain, $list);
202 $liste['subscriptions'] = $subs;
203 $liste['mails'] = $mails;
205 $page->register_modifier('hdc', 'list_header_decode');
206 $page->assign_by_ref('liste', $liste);
209 function handler_create($page)
213 $page->changeTpl('lists/create.tpl');
215 $user_promo = S
::user()->profile()->yearPromo();
218 // scolar year starts in september
219 $scolarmonth = ($year - $user_promo) * 12 +
($month - 8);
220 $young_promo = $very_young_promo = 0;
221 // binet are accessible only in april in the first year and until
222 // march of the 5th year
223 if ($scolarmonth >= 8 && $scolarmonth < 56) {
226 // PSC aliases are accesible only between september and june of the second
228 if ($scolarmonth >= 12 && $scolarmonth < 22) {
229 $very_young_promo = 1;
231 $page->assign('young_promo', $young_promo);
232 $page->assign('very_young_promo', $very_young_promo);
234 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
235 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
237 // click on validate button 'add_owner_sub' or type <enter>
238 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
239 // if we want to add an owner and then type <enter>, then both
240 // add_owner_sub and add_owner are filled.
241 $oforlifes = User
::getBulkForlifeEmails(Post
::v('add_owner'), true
);
242 $mforlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
243 if (!is_null($oforlifes)) {
244 $owners = array_merge($owners, $oforlifes);
246 // if we want to add a member and then type <enter>, then
247 // add_owner_sub is filled, whereas add_owner is empty.
248 if (!is_null($mforlifes)) {
249 $members = array_merge($members, $mforlifes);
253 // click on validate button 'add_member_sub'
254 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
255 $forlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
256 if (!is_null($forlifes)) {
257 $members = array_merge($members, $forlifes);
260 if (Post
::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
261 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
263 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
265 $forlifes = User
::getBulkForlifeEmails($upload->getContents(), true
);
266 if (!is_null($forlifes)) {
267 $members = array_merge($members, $forlifes);
273 $owners = array_unique($owners);
275 $members = array_unique($members);
277 $page->assign('owners', join("\n", $owners));
278 $page->assign('members', join("\n", $members));
280 if (!Post
::has('submit')) {
283 S
::assert_xsrf_token();
286 $asso = Post
::t('asso');
287 $list = strtolower(Post
::t('liste'));
290 $page->trigError('Le champ « adresse souhaitée » est vide.');
292 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
293 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
296 if (($asso == 'binet') ||
($asso == 'alias')) {
297 $promo = Post
::i('promo');
298 $domain = $promo . '.' . $globals->mail
->domain
;
300 if (($promo < 1921) ||
($promo > date('Y'))) {
301 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
304 } elseif ($asso == 'groupex') {
305 $domain = XDB
::fetchOneCell('SELECT mail_domain
308 Post
::t('groupex_name'));
311 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
314 $domain = $globals->mail
->domain
;
317 require_once 'emails.inc.php';
318 if (list_exist($list, $domain)) {
319 $page->trigError("L'« adresse souhaitée » est déjà prise.");
322 if (!Post
::t('desc')) {
323 $page->trigError('Le sujet est vide.');
326 if (!count($owners)) {
327 $page->trigError('Il n\'y a pas de gestionnaire.');
330 if (count($members) < 4) {
331 $page->trigError('Il n\'y a pas assez de membres.');
334 if (!$page->nb_errs()) {
335 $page->trigSuccess('Demande de création envoyée !');
336 $page->assign('created', true
);
337 $req = new ListeReq(S
::user(), $asso, $list, $domain,
338 Post
::t('desc'), Post
::i('advertise'),
339 Post
::i('modlevel'), Post
::i('inslevel'),
345 function handler_members($page, $liste = null
)
347 if (is_null($liste)) {
351 $this->prepare_list($liste);
352 $this->prepare_client($page);
353 $this->is_group_admin($page);
355 $page->changeTpl('lists/members.tpl');
357 if (Get
::has('del')) {
358 S
::assert_xsrf_token();
359 $this->mlist
->unsubscribe()
360 pl_redirect('lists/members/'.$liste);
363 if (Get
::has('add')) {
364 S
::assert_xsrf_token();
365 $this->mlist
->subscribe();
366 pl_redirect('lists/members/'.$liste);
369 $members = $this->mlist
->getMembers();
371 $tri_promo = !Env
::b('alpha');
373 if (list($det,$mem,$own) = $members) {
374 $membres = list_sort_members($mem, $tri_promo);
375 $moderos = list_sort_owners($own, $tri_promo);
377 $page->assign_by_ref('details', $det);
378 $page->assign_by_ref('members', $membres);
379 $page->assign_by_ref('owners', $moderos);
380 $page->assign('nb_m', count($mem));
382 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
386 function handler_csv(PlPage
$page, $liste = null
)
388 if (is_null($liste)) {
391 $this->prepare_client($page);
392 $this->prepare_list($liste);
393 $this->is_group_admin($page);
394 $members = $this->mlist
->getMembers();
395 $list = list_fetch_basic_info(list_extract_members($members[1]));
396 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
398 echo utf8_decode("Nom;Prénom;Promotion\n");
399 echo utf8_decode(implode("\n", $list));
403 function handler_annu($page, $liste = null
, $action = null
, $subaction = null
)
405 if (is_null($liste)) {
409 $this->prepare_client($page);
410 $this->prepare_list($liste);
411 $this->is_group_admin($page);
413 if (Get
::has('del')) {
414 S
::assert_xsrf_token();
415 $this->mlist
->unsubscribe();
416 pl_redirect('lists/annu/'.$liste);
418 if (Get
::has('add')) {
419 S
::assert_xsrf_token();
420 $this->mlist
->subscribe();
421 pl_redirect('lists/annu/'.$liste);
424 $owners = $this->mlist
->getOwners();
425 if (!is_array($owners)) {
426 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
429 list(,$members) = $this->mlist
->getMembers();
431 if ($action == 'moderators') {
433 $show_moderators = true
;
434 $action = $subaction;
437 $show_moderators = false
;
439 foreach ($members as $m) {
444 require_once 'userset.inc.php';
445 $view = new UserArraySet($users);
446 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
));
447 $view->addMod('listmember', 'Annuaire', true
);
448 if (empty($GLOBALS['IS_XNET_SITE'])) {
449 $view->addMod('minifiche', 'Mini-fiches', false
);
451 $view->addMod('map', 'Planisphère');
452 $view->apply("lists/annu/$liste", $page, $action, $subaction);
454 $page->changeTpl('lists/annu.tpl');
455 $page->assign_by_ref('details', $owners[0]);
456 $page->assign('show_moderators', $show_moderators);
459 function handler_archives($page, $liste = null
, $action = null
, $artid = null
)
463 if (is_null($liste)) {
467 $domain = $this->prepare_client($page);
468 $this->prepare_list($liste);
469 $this->is_group_admin($page);
471 $page->changeTpl('lists/archives.tpl');
473 if (list($det) = $this->mlist
->getMembers()) {
474 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
475 && !$det['own'] && ($det['sub'] < 2)) {
476 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
478 $get = Array('listname' => $liste, 'domain' => $mlist->domain
);
479 if (Post
::has('updateall')) {
480 $get['updateall'] = Post
::v('updateall');
482 require_once 'banana/ml.inc.php';
483 get_banana_params($get, null
, $action, $artid);
484 run_banana($page, 'MLBanana', $get);
486 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
490 function handler_rss($page, $liste = null
, $alias = null
, $hash = null
)
495 $user = Platal
::session()->tokenAuth($alias, $hash);
496 if (is_null($user)) {
500 $domain = $this->prepare_client($page, $user);
501 $this->prepare_list($liste);
503 if (list($det) = $this->mlist
->getMembers()) {
504 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
505 && !$det['own'] && ($det['sub'] < 2)) {
508 require_once('banana/ml.inc.php');
509 $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $this->mlist
->domain
, 'action' => 'rss2'));
515 function moderate_mail($domain, $liste, $mid)
517 if (Env
::has('mok')) {
519 } elseif (Env
::has('mno')) {
521 } elseif (Env
::has('mdel')) {
527 return XDB
::execute("INSERT IGNORE INTO email_list_moderate
528 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
529 $liste, $domain, $mid, S
::i('uid'), $action, Post
::v('reason'));
532 function handler_moderate($page, $liste = null
)
534 if (is_null($liste)) {
538 $domain = $this->prepare_client($page);
539 if (!$this->is_group_admin($page)) {
540 $this->verify_list_owner($page, $liste);
543 $page->changeTpl('lists/moderate.tpl');
545 $page->register_modifier('hdc', 'list_header_decode');
547 if (Env
::has('sadd') || Env
::has('sdel')) {
548 S
::assert_xsrf_token();
550 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
551 $sub = $this->client
->get_pending_sub($liste, Env
::v('sadd'));
552 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
555 if (Post
::has('sdel')) { /* 2 = REJECT */
556 $sub = $this->client
->get_pending_sub($liste, Env
::v('sdel'));
557 $this->client
->handle_request($liste, Post
::v('sdel'), 2, utf8_decode(Post
::v('reason')));
561 $mailer = new PlMailer();
562 $mailer->setFrom("$liste-bounces@{$domain}");
563 $mailer->addTo("$liste-owner@{$domain}");
564 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
565 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
566 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S
::user()->fullName(true
) . ".\n";
567 if (trim(Post
::v('reason'))) {
568 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
570 $mailer->setTxtBody(wordwrap($text, 72));
573 if (Env
::has('sadd')) {
574 pl_redirect('lists/moderate/'.$liste);
578 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
579 S
::assert_xsrf_token();
581 $mails = array_keys(Post
::v('select_mails'));
582 foreach($mails as $mail) {
583 $this->moderate_mail($domain, $liste, $mail);
585 } elseif (Env
::has('mid')) {
586 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
587 require_once 'banana/moderate.inc.php';
589 $page->changeTpl('lists/moderate_mail.tpl');
590 $params = array('listname' => $liste, 'domain' => $domain,
591 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
592 $params['client'] = $this->client
;
593 run_banana($page, 'ModerationBanana', $params);
595 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
596 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
597 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
598 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
599 $msg = str_replace("%(listname)s", $liste, $msg);
600 $page->assign('msg', $msg);
604 $this->moderate_mail($domain, $liste, Env
::i('mid'));
605 } elseif (Env
::has('sid')) {
606 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
607 foreach($subs as $user) {
608 if ($user['id'] == Env
::v('sid')) {
609 $page->changeTpl('lists/moderate_sub.tpl');
610 $page->assign('del_user', $user);
618 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
619 foreach ($mails as $key=>$mail) {
620 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
621 if ($mail['fromx']) {
622 $page->assign('with_fromx', true
);
624 $page->assign('with_nonfromx', true
);
627 $page->assign_by_ref('subs', $subs);
628 $page->assign_by_ref('mails', $mails);
630 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
634 static public function no_login_callback($login)
636 global $list_unregistered;
638 $users = User
::getPendingAccounts($login, true
);
639 if ($users && $users->total()) {
640 if (!isset($list_unregistered)) {
641 $list_unregistered = array();
643 $list_unregistered[$login] = $users;
645 list($name, $domain) = @explode
('@', $login);
646 if (User
::isMainMailDomain($domain)) {
647 User
::_default_user_callback($login);
652 function handler_admin($page, $liste = null
)
656 if (is_null($liste)) {
660 $domain = $this->prepare_client($page);
661 $this->is_group_admin($page);
662 if (!$this->is_group_admin($page)) {
663 $this->verify_list_owner($page, $liste);
666 $page->changeTpl('lists/admin.tpl');
668 if (Env
::has('send_mark')) {
669 S
::assert_xsrf_token();
671 $actions = Env
::v('mk_action');
672 $uids = Env
::v('mk_uid');
673 $mails = Env
::v('mk_email');
674 foreach ($actions as $key=>$action) {
679 case 'marketu': case 'markets':
680 require_once 'emails.inc.php';
681 $user = User
::get($uids[$key]);
682 $mail = valide_email($mails[$key]);
683 if (isvalid_email_redirection($mail, $user)) {
684 $from = ($action == 'marketu') ?
'user' : 'staff';
685 $market = Marketing
::get($uids[$key], $mail);
687 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S
::v('uid'));
694 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
695 VALUES ({?}, \'list\', {?}, {?})',
696 $uids[$key], $liste, $domain);
701 if (Env
::has('add_member') ||
702 isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
703 S
::assert_xsrf_token();
705 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
706 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
708 $page->trigError("Une erreur s'est produite lors du téléchargement du fichier.");
710 $logins = $upload->getContents();
713 $logins = Env
::v('add_member');
716 $logins = preg_split("/[; ,\r\n\|]+/", $logins);
717 $members = User
::getBulkForlifeEmails($logins,
719 array('ListsModule', 'no_login_callback'));
720 $unfound = array_diff_key($logins, $members);
722 // Make sure we send a list (array_values) of unique (array_unique)
724 $members = array_values(array_unique($members));
726 $arr = $this->client
->mass_subscribe($liste, $members);
728 $successes = array();
729 if (is_array($arr)) {
730 foreach($arr as $addr) {
731 $successes[] = $addr[1];
732 $page->trigSuccess("{$addr[0]} inscrit.");
736 $already = array_diff($members, $successes);
737 if (is_array($already)) {
738 foreach ($already as $item) {
739 $page->trigWarning($item . ' est déjà inscrit.');
743 if (is_array($unfound)) {
744 foreach ($unfound as $item) {
745 if (trim($item) != '') {
746 $page->trigError($item . " ne correspond pas à un compte existant et n'est pas une adresse email.");
752 if (Env
::has('del_member')) {
753 S
::assert_xsrf_token();
755 if (strpos(Env
::v('del_member'), '@') === false
) {
756 if ($del_member = User
::getSilent(Env
::t('del_member'))) {
757 $this->client
->mass_unsubscribe($liste, array($del_member->forlifeEmail()));
760 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
762 pl_redirect('lists/admin/'.$liste);
765 if (Env
::has('add_owner')) {
766 S
::assert_xsrf_token();
768 $owners = User
::getBulkForlifeEmails(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
770 foreach ($owners as $login) {
771 if ($this->client
->add_owner($liste, $login)) {
772 $page->trigSuccess($login ." ajouté aux modérateurs.");
778 if (Env
::has('del_owner')) {
779 S
::assert_xsrf_token();
781 if (strpos(Env
::v('del_owner'), '@') === false
) {
782 if ($del_owner = User
::getSilent(Env
::t('del_owner'))) {
783 $this->client
->mass_unsubscribe($liste, array($del_owner->forlifeEmail()));
786 $this->client
->del_owner($liste, Env
::v('del_owner'));
788 pl_redirect('lists/admin/'.$liste);
791 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
792 global $list_unregistered;
793 if ($list_unregistered) {
794 $page->assign_by_ref('unregistered', $list_unregistered);
796 $membres = list_sort_members($mem, @$tri_promo);
797 $moderos = list_sort_owners($own, @$tri_promo);
799 $page->assign_by_ref('details', $det);
800 $page->assign_by_ref('members', $membres);
801 $page->assign_by_ref('owners', $moderos);
802 $page->assign('np_m', count($mem));
804 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
805 . " Si tu penses qu'il s'agit d'une erreur, "
806 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
810 function handler_options($page, $liste = null
)
812 if (is_null($liste)) {
816 $this->prepare_client($page);
817 if (!$this->is_group_admin($page)) {
818 $this->verify_list_owner($page, $liste);
821 $page->changeTpl('lists/options.tpl');
823 if (Post
::has('submit')) {
824 S
::assert_xsrf_token();
827 $values = array_map('utf8_decode', $values);
828 $spamlevel = intval($values['bogo_level']);
829 $unsurelevel = intval($values['unsure_level']);
830 if ($spamlevel == 0) {
833 if ($spamlevel > 3 ||
$spamlevel < 0 ||
$unsurelevel < 0 ||
$unsurelevel > 1) {
834 $page->trigError("Réglage de l'antispam non valide");
836 $this->client
->set_bogo_level($liste, ($spamlevel << 1) +
$unsurelevel);
838 switch($values['moderate']) {
840 $values['generic_nonmember_action'] = 0;
841 $values['default_member_moderation'] = 0;
844 $values['generic_nonmember_action'] = 1;
845 $values['default_member_moderation'] = 0;
848 $values['generic_nonmember_action'] = 1;
849 $values['default_member_moderation'] = 1;
852 unset($values['submit'], $values['bogo_level'], $values['moderate']);
853 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
854 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
855 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
856 if (isset($values['subject_prefix'])) {
857 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
859 $this->client
->set_owner_options($liste, $values);
860 } elseif (isvalid_email(Post
::v('atn_add'))) {
861 S
::assert_xsrf_token();
862 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
863 } elseif (Get
::has('atn_del')) {
864 S
::assert_xsrf_token();
865 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
866 pl_redirect('lists/options/'.$liste);
869 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
870 $page->assign_by_ref('details', $details);
871 $page->assign_by_ref('options', $options);
872 $bogo_level = intval($this->client
->get_bogo_level($liste));
873 $page->assign('unsure_level', $bogo_level & 1);
874 $page->assign('bogo_level', $bogo_level >> 1);
876 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
880 function handler_delete($page, $liste = null
)
883 if (is_null($liste)) {
887 $domain = $this->prepare_client($page);
888 if (!$this->is_group_admin($page)) {
889 $this->verify_list_owner($page, $liste);
892 $page->changeTpl('lists/delete.tpl');
893 if (Post
::v('valid') == 'OUI') {
894 S
::assert_xsrf_token();
896 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
897 require_once 'emails.inc.php';
899 delete_list($liste, $domain);
900 $page->assign('deleted', true
);
901 $page->trigSuccess('La liste a été détruite !');
903 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
904 . 'Contact les administrateurs du site pour régler le problème : '
905 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
907 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
908 if (!$details['own']) {
909 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
911 $page->assign_by_ref('details', $details);
912 $page->assign_by_ref('options', $options);
913 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
915 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
919 function handler_soptions($page, $liste = null
)
921 if (is_null($liste)) {
925 $this->prepare_client($page);
926 if (!$this->is_group_admin($page)) {
927 $this->verify_list_owner($page, $liste);
930 $page->changeTpl('lists/soptions.tpl');
932 if (Post
::has('submit')) {
933 S
::assert_xsrf_token();
936 $values = array_map('utf8_decode', $values);
937 unset($values['submit']);
938 $values['advertised'] = empty($values['advertised']) ? false
: true
;
939 $values['archive'] = empty($values['archive']) ? false
: true
;
940 $this->client
->set_admin_options($liste, $values);
943 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
944 $page->assign_by_ref('details', $details);
945 $page->assign_by_ref('options', $options);
947 $page->kill("La liste n'existe pas.");
951 function handler_check($page, $liste = null
)
953 if (is_null($liste)) {
957 $this->prepare_client($page);
958 if (!$this->is_group_admin($page)) {
959 $this->verify_list_owner($page, $liste);
962 $page->changeTpl('lists/check.tpl');
964 if (Post
::has('correct')) {
965 S
::assert_xsrf_token();
966 $this->client
->check_options($liste, true
);
969 if (list($details,$options) = $this->client
->check_options($liste)) {
970 $page->assign_by_ref('details', $details);
971 $page->assign_by_ref('options', $options);
973 $page->kill("La liste n'existe pas.");
977 function handler_admin_all($page)
979 $page->changeTpl('lists/admin_all.tpl');
980 $page->setTitle('Administration - Mailing lists');
982 $this->prepare_client($page);
983 $listes = $this->client
->get_all_lists();
984 $page->assign_by_ref('listes', $listes);
987 function handler_aaliases($page, $alias = null
)
990 require_once 'emails.inc.php';
991 $page->setTitle('Administration - Aliases');
993 if (Post
::has('new_alias')) {
994 pl_redirect('admin/aliases/' . Post
::t('new_alias') . '@' . $globals->mail
->domain
);
997 // If no alias, list them all.
998 if (is_null($alias)) {
999 $page->changeTpl('lists/admin_aliases.tpl');
1000 $page->assign('aliases', array_merge(iterate_list_alias($globals->mail
->domain
), iterate_list_alias($globals->mail
->domain2
)));
1004 list($local_part, $domain) = explode('@', $alias);
1005 if (!($globals->mail
->domain
== $domain ||
$globals->mail
->domain2
== $domain)
1006 ||
!preg_match("/^[a-zA-Z0-9\-\.]*$/", $local_part)) {
1007 $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
1010 // Now we can perform the action.
1011 if (Post
::has('del_alias')) {
1012 S
::assert_xsrf_token();
1014 delete_list_alias($local_part, $domain);
1015 $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
1018 if (Post
::has('add_member')) {
1019 S
::assert_xsrf_token();
1021 if (add_to_list_alias(Post
::t('add_member'), $local_part, $domain)) {
1022 $page->trigSuccess('Ajout réussit.');
1024 $page->trigError('Ajout infructueux.');
1028 if (Get
::has('del_member')) {
1029 S
::assert_xsrf_token();
1031 if (delete_from_list_alias(Get
::t('del_member'), $local_part, $domain)) {
1032 $page->trigSuccess('Suppression réussie.');
1034 $page->trigError('Suppression infructueuse.');
1038 $page->changeTpl('lists/admin_edit_alias.tpl');
1039 $page->assign('members', list_alias_members($local_part, $domain));
1040 $page->assign('alias', $alias);
1044 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: