e1315e0e84764c504c9163af0098392942755a6b
2 /***************************************************************************
3 * Copyright (C) 2003-2013 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
27 'lists' => $this->make_hook('lists', AUTH_PASSWD
, 'user'),
28 'lists/ajax' => $this->make_hook('ajax', AUTH_PASSWD
, 'user', NO_AUTH
),
29 'lists/create' => $this->make_hook('create', AUTH_PASSWD
, 'lists'),
31 'lists/members' => $this->make_hook('members', AUTH_COOKIE
, 'user'),
32 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE
, 'user'),
33 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE
, 'user'),
34 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
, 'user'),
35 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC
, 'user', NO_HTTPS
),
37 'lists/moderate' => $this->make_hook('moderate', AUTH_PASSWD
, 'user'),
38 'lists/admin' => $this->make_hook('admin', AUTH_PASSWD
, 'user'),
39 'lists/options' => $this->make_hook('options', AUTH_PASSWD
, 'user'),
40 'lists/delete' => $this->make_hook('delete', AUTH_PASSWD
, 'user'),
42 'lists/soptions' => $this->make_hook('soptions', AUTH_PASSWD
, 'user'),
43 'lists/check' => $this->make_hook('check', AUTH_PASSWD
, 'user'),
44 'admin/lists' => $this->make_hook('admin_all', AUTH_PASSWD
, 'admin'),
45 'admin/aliases' => $this->make_hook('aaliases', AUTH_PASSWD
, 'admin')
49 protected function prepare_client($user = null
)
55 $domain = $this->get_lists_domain();
57 return new MMList($user, $domain);
60 protected function get_lists_domain()
63 return $globals->mail
->domain
;
66 /** Prepare a MailingList from its mailbox
68 protected function prepare_list($mbox)
70 // Required: modules/xnetlists.php uses it too.
71 Platal
::load('lists', 'lists.inc.php');
73 return new MailingList($mbox, $this->get_lists_domain());
76 /** Ensure the current user is an administrator of the group.
78 protected 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 /** Ensure the current user owns the given MailingList.
94 protected function verify_list_owner($page, $mlist)
96 if (list(, , $owners) = $mlist->getMembers()) {
97 if (!(in_array(S
::user()->forlifeEmail(), $owners) || S
::admin())) {
98 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
101 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
102 . " Si tu penses qu'il s'agit d'une erreur, "
103 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
107 /** Fetch pending operations on a MailingList instance.
109 protected function get_pending_ops($mlist)
111 list($subs, $mails) = $mlist->getPendingOps();
112 $res = XDB
::query("SELECT mid
113 FROM email_list_moderate
114 WHERE ml = {?} AND domain = {?}",
115 $mlist->mbox
, $mlist->domain
);
116 $mids = $res->fetchColumn();
117 foreach ($mails as $key => $mail) {
118 if (in_array($mail['id'], $mids)) {
122 return array($subs, $mails);
125 function handler_lists($page)
128 function filter_owner($list)
133 function filter_member($list)
138 $page->changeTpl('lists/index.tpl');
139 $page->setTitle('Listes de diffusion');
142 if (Get
::has('del')) {
143 S
::assert_xsrf_token();
144 $mlist = $this->prepare_list(Get
::v('del'));
145 $mlist->unsubscribe();
146 pl_redirect('lists');
148 if (Get
::has('add')) {
149 S
::assert_xsrf_token();
150 $mlist = $this->prepare_list(Get
::v('add'));
152 pl_redirect('lists');
154 if (Post
::has('promo_add')) {
155 S
::assert_xsrf_token();
157 $promo = Post
::i('promo_add');
158 if ($promo >= 1900 and $promo < 2100) {
159 $mlist = MailingList
::promo($promo);
162 $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
166 $client = $this->prepare_client();
167 if (!is_null($listes = $client->get_lists())) {
168 $owner = array_filter($listes, 'filter_owner');
169 $listes = array_diff_key($listes, $owner);
170 $member = array_filter($listes, 'filter_member');
171 $listes = array_diff_key($listes, $member);
172 foreach ($owner as $key => $liste) {
173 $mlist = $this->prepare_list($liste['list']);
174 list($subs, $mails) = $this->get_pending_ops($mlist);
175 $owner[$key]['subscriptions'] = $subs;
176 $owner[$key]['mails'] = $mails;
178 $page->register_modifier('hdc', 'list_header_decode');
179 $page->assign_by_ref('owner', $owner);
180 $page->assign_by_ref('member', $member);
181 $page->assign_by_ref('public', $listes);
185 function handler_ajax($page, $list = null
)
187 pl_content_headers("text/html");
188 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
189 S
::assert_xsrf_token();
191 $mlist = $this->prepare_list($list);
192 if (Get
::has('unsubscribe')) {
193 $mlist->unsubscribe();
195 if (Get
::has('subscribe')) {
198 if (Get
::has('sadd')) {
199 $mlist->handleRequest(MailingList
::REQ_SUBSCRIBE
, Get
::v('sadd'));
201 if (Get
::has('mid')) {
202 $this->moderate_mail($mlist, Get
::i('mid'));
205 list($liste, $members, $owners) = $mlist->getMembers();
207 list($subs, $mails) = $this->get_pending_ops($mlist);
208 $liste['subscriptions'] = $subs;
209 $liste['mails'] = $mails;
211 $page->register_modifier('hdc', 'list_header_decode');
212 $page->assign_by_ref('liste', $liste);
215 function handler_create($page)
219 $page->changeTpl('lists/create.tpl');
221 $user_promo = S
::user()->profile()->yearPromo();
224 // scolar year starts in september
225 $scolarmonth = ($year - $user_promo) * 12 +
($month - 8);
226 $young_promo = $very_young_promo = 0;
227 // binet are accessible only in april in the first year and until
228 // march of the 5th year
229 if ($scolarmonth >= 8 && $scolarmonth < 56) {
232 // PSC aliases are accesible only between september and june of the second
234 if ($scolarmonth >= 12 && $scolarmonth < 22) {
235 $very_young_promo = 1;
237 $page->assign('young_promo', $young_promo);
238 $page->assign('very_young_promo', $very_young_promo);
240 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
241 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
243 // click on validate button 'add_owner_sub' or type <enter>
244 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
245 // if we want to add an owner and then type <enter>, then both
246 // add_owner_sub and add_owner are filled.
247 $oforlifes = User
::getBulkForlifeEmails(Post
::v('add_owner'), true
);
248 $mforlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
249 if (!is_null($oforlifes)) {
250 $owners = array_merge($owners, $oforlifes);
252 // if we want to add a member and then type <enter>, then
253 // add_owner_sub is filled, whereas add_owner is empty.
254 if (!is_null($mforlifes)) {
255 $members = array_merge($members, $mforlifes);
259 // click on validate button 'add_member_sub'
260 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
261 $forlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
262 if (!is_null($forlifes)) {
263 $members = array_merge($members, $forlifes);
266 if (Post
::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
267 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
269 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
271 $forlifes = User
::getBulkForlifeEmails($upload->getContents(), true
);
272 if (!is_null($forlifes)) {
273 $members = array_merge($members, $forlifes);
279 $owners = array_unique($owners);
281 $members = array_unique($members);
283 $page->assign('owners', join("\n", $owners));
284 $page->assign('members', join("\n", $members));
286 if (!Post
::has('submit')) {
289 S
::assert_xsrf_token();
292 $asso = Post
::t('asso');
293 $list = strtolower(Post
::t('liste'));
296 $page->trigError('Le champ « adresse souhaitée » est vide.');
298 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
299 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
302 if (($asso == 'binet') ||
($asso == 'alias')) {
303 $promo = Post
::i('promo');
304 $domain = $promo . '.' . $globals->mail
->domain
;
306 if (($promo < 1921) ||
($promo > date('Y'))) {
307 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
310 } elseif ($asso == 'groupex') {
311 $domain = XDB
::fetchOneCell('SELECT mail_domain
314 Post
::t('groupex_name'));
317 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
320 $domain = $globals->mail
->domain
;
323 require_once 'emails.inc.php';
324 if (list_exist($list, $domain)) {
325 $page->trigError("L'« adresse souhaitée » est déjà prise.");
328 if (!Post
::t('desc')) {
329 $page->trigError('Le sujet est vide.');
332 if (!count($owners)) {
333 $page->trigError('Il n\'y a pas de gestionnaire.');
336 if (count($members) < 4) {
337 $page->trigError('Il n\'y a pas assez de membres.');
340 if (!$page->nb_errs()) {
341 $page->trigSuccess('Demande de création envoyée !');
342 $page->assign('created', true
);
343 $req = new ListeReq(S
::user(), $asso, $list, $domain,
344 Post
::t('desc'), Post
::i('advertise'),
345 Post
::i('modlevel'), Post
::i('inslevel'),
351 function handler_members($page, $liste = null
)
353 if (is_null($liste)) {
357 $mlist = $this->prepare_list($liste);
358 $this->is_group_admin($page);
360 $page->changeTpl('lists/members.tpl');
362 if (Get
::has('del')) {
363 S
::assert_xsrf_token();
364 $mlist->unsubscribe();
365 pl_redirect('lists/members/' . $liste);
368 if (Get
::has('add')) {
369 S
::assert_xsrf_token();
371 pl_redirect('lists/members/' . $liste);
374 $members = $mlist->getMembers();
376 $tri_promo = !Env
::b('alpha');
378 if (list($det,$mem,$own) = $members) {
379 $membres = list_sort_members($mem, $tri_promo);
380 $moderos = list_sort_owners($own, $tri_promo);
382 $page->assign_by_ref('details', $det);
383 $page->assign_by_ref('members', $membres);
384 $page->assign_by_ref('owners', $moderos);
385 $page->assign('nb_m', count($mem));
387 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
391 function handler_csv(PlPage
$page, $liste = null
)
393 if (is_null($liste)) {
396 $this->is_group_admin($page);
398 $mlist = $this->prepare_list($liste);
399 $members = $mlist->getMembers();
400 $list = list_fetch_basic_info(list_extract_members($members[1]));
401 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
403 echo utf8_decode("Nom;Prénom;Promotion\n");
404 echo utf8_decode(implode("\n", $list));
408 function handler_annu($page, $liste = null
, $action = null
, $subaction = null
)
410 if (is_null($liste)) {
414 $this->is_group_admin($page);
416 $mlist = $this->prepare_list($liste);
418 if (Get
::has('del')) {
419 S
::assert_xsrf_token();
420 $mlist->unsubscribe();
421 pl_redirect('lists/annu/'.$liste);
423 if (Get
::has('add')) {
424 S
::assert_xsrf_token();
426 pl_redirect('lists/annu/'.$liste);
429 $owners = $mlist->getOwners();
430 if (!is_array($owners)) {
431 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
434 list(,$members) = $mlist->getMembers();
436 if ($action == 'moderators') {
438 $show_moderators = true
;
439 $action = $subaction;
442 $show_moderators = false
;
444 foreach ($members as $m) {
449 require_once 'userset.inc.php';
450 $view = new UserArraySet($users);
451 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
));
452 $view->addMod('listmember', 'Annuaire', true
);
453 if (empty($GLOBALS['IS_XNET_SITE'])) {
454 $view->addMod('minifiche', 'Mini-fiches', false
);
456 $view->addMod('map', 'Planisphère');
457 $view->apply("lists/annu/$liste", $page, $action, $subaction);
459 $page->changeTpl('lists/annu.tpl');
460 $page->assign_by_ref('details', $owners[0]);
461 $page->assign('show_moderators', $show_moderators);
464 function handler_archives($page, $liste = null
, $action = null
, $artid = null
)
468 if (is_null($liste)) {
472 $this->is_group_admin($page);
474 $mlist = $this->prepare_list($liste);
476 $page->changeTpl('lists/archives.tpl');
478 if (list($det) = $mlist->getMembers()) {
479 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
480 && !$det['own'] && ($det['sub'] < 2)) {
481 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
483 $get = Array('listname' => $mlist->mbox
, 'domain' => $mlist->domain
);
484 if (Post
::has('updateall')) {
485 $get['updateall'] = Post
::v('updateall');
487 require_once 'banana/ml.inc.php';
488 get_banana_params($get, null
, $action, $artid);
489 run_banana($page, 'MLBanana', $get);
491 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
495 function handler_rss($page, $liste = null
, $alias = null
, $hash = null
)
500 $user = Platal
::session()->tokenAuth($alias, $hash);
501 if (is_null($user)) {
505 $mlist = $this->prepare_list($liste);
507 if (list($det) = $mlist->getMembers()) {
508 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
509 && !$det['own'] && ($det['sub'] < 2)) {
512 require_once('banana/ml.inc.php');
513 $banana = new MLBanana($user, Array(
514 'listname' => $mlist->mbox
,
515 'domain' => $mlist->domain
,
516 'action' => 'rss2'));
522 /** Register a moderation decision.
523 * @param $mlist MailingList: the mailing list being moderated
524 * @param $mid int: the message being moderated
526 protected function moderate_mail($mlist, $mid)
528 if (Env
::has('mok')) {
530 } elseif (Env
::has('mno')) {
532 } elseif (Env
::has('mdel')) {
538 return XDB
::execute("INSERT IGNORE INTO email_list_moderate
539 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
540 $mlist->mbox
, $mlist->domain
, $mid, S
::i('uid'), $action, Post
::v('reason'));
543 function handler_moderate($page, $liste = null
)
545 if (is_null($liste)) {
549 $mlist = $this->prepare_list($liste);
550 if (!$this->is_group_admin($page)) {
551 $this->verify_list_owner($page, $mlist);
554 $page->changeTpl('lists/moderate.tpl');
556 $page->register_modifier('hdc', 'list_header_decode');
558 if (Env
::has('sadd') || Env
::has('sdel')) {
559 S
::assert_xsrf_token();
561 if (Env
::has('sadd')) {
562 // Ensure the moderated request is still active
563 $sub = $mlist->getPendingSubscription(Env
::v('sadd'));
565 $mlist->handleRequest(MailingList
::REQ_SUBSCRIBE
, Env
::v('sadd'));
568 if (Post
::has('sdel')) {
569 // Ensure the moderated request is still active
570 $sub = $mlist->getPendingSubscription(Env
::v('sdel'));
572 $mlist->handleRequest(MailingList
::REQ_REJECT
, Post
::v('sdel'), Post
::v('reason'));
576 $mailer = new PlMailer();
577 $mailer->setFrom($mlist->getAddress(MailingList
::KIND_BOUNCE
));
578 $mailer->addTo($mlist->getAddress(MailingList
::KIND_OWNER
));
579 $mailer->addHeader('Reply-To', $mlist->getAddress(MailingList
::KIND_OWNER
));
580 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
581 $text = "L'inscription de {$sub['name']} à la liste " . $mlist->address
." a été $info par " . S
::user()->fullName(true
) . ".\n";
582 if (trim(Post
::v('reason'))) {
583 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
585 $mailer->setTxtBody(wordwrap($text, 72));
588 if (Env
::has('sadd')) {
589 pl_redirect('lists/moderate/'.$liste);
593 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
594 S
::assert_xsrf_token();
596 $mails = array_keys(Post
::v('select_mails'));
597 foreach($mails as $mail) {
598 $this->moderate_mail($mlist, $mail);
600 } elseif (Env
::has('mid')) {
601 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
602 require_once 'banana/moderate.inc.php';
604 $page->changeTpl('lists/moderate_mail.tpl');
606 'listname' => $mlist->mbox
,
607 'domain' => $mlist->domain
,
608 'artid' => Get
::i('mid'),
609 'part' => Get
::v('part'),
610 'action' => Get
::v('action'));
611 $params['client'] = $this->prepare_client();
612 run_banana($page, 'ModerationBanana', $params);
614 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
615 $msg = str_replace("%(adminaddr)s", $mlist->getAddress(MailingList
::KIND_OWNER
), $msg);
616 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
617 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
618 $msg = str_replace("%(listname)s", $liste, $msg);
619 $page->assign('msg', $msg);
623 $this->moderate_mail($mlist, Env
::i('mid'));
624 } elseif (Env
::has('sid')) {
625 if (list($subs,$mails) = $this->get_pending_ops($mlist)) {
626 foreach($subs as $user) {
627 if ($user['id'] == Env
::v('sid')) {
628 $page->changeTpl('lists/moderate_sub.tpl');
629 $page->assign('del_user', $user);
637 if (list($subs,$mails) = $this->get_pending_ops($mlist)) {
638 foreach ($mails as $key=>$mail) {
639 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
640 if ($mail['fromx']) {
641 $page->assign('with_fromx', true
);
643 $page->assign('with_nonfromx', true
);
646 $page->assign_by_ref('subs', $subs);
647 $page->assign_by_ref('mails', $mails);
649 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
653 static public function no_login_callback($login)
655 global $list_unregistered;
657 $users = User
::getPendingAccounts($login, true
);
658 if ($users && $users->total()) {
659 if (!isset($list_unregistered)) {
660 $list_unregistered = array();
662 $list_unregistered[$login] = $users;
664 list($name, $domain) = @explode
('@', $login);
665 if (User
::isMainMailDomain($domain)) {
666 User
::_default_user_callback($login);
671 function handler_admin($page, $liste = null
)
675 if (is_null($liste)) {
679 $mlist = $this->prepare_list($liste);
680 $this->is_group_admin($page);
681 if (!$this->is_group_admin($page)) {
682 $this->verify_list_owner($page, $mlist);
685 $page->changeTpl('lists/admin.tpl');
687 if (Env
::has('send_mark')) {
688 S
::assert_xsrf_token();
690 $actions = Env
::v('mk_action');
691 $uids = Env
::v('mk_uid');
692 $mails = Env
::v('mk_email');
693 foreach ($actions as $key=>$action) {
698 case 'marketu': case 'markets':
699 require_once 'emails.inc.php';
700 $user = User
::get($uids[$key]);
701 $mail = valide_email($mails[$key]);
702 if (isvalid_email_redirection($mail, $user)) {
703 $from = ($action == 'marketu') ?
'user' : 'staff';
704 $market = Marketing
::get($uids[$key], $mail);
706 $market = new Marketing($uids[$key], $mail, 'list', $mlist->address
, $from, S
::v('uid'));
713 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
714 VALUES ({?}, \'list\', {?}, {?})',
715 $uids[$key], $mlist->mbox
, $mlist->domain
);
720 if (Env
::has('add_member') ||
721 isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
722 S
::assert_xsrf_token();
724 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
725 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
727 $page->trigError("Une erreur s'est produite lors du téléchargement du fichier.");
729 $logins = $upload->getContents();
732 $logins = Env
::v('add_member');
735 $logins = preg_split("/[; ,\r\n\|]+/", $logins);
736 $members = User
::getBulkForlifeEmails($logins,
738 array('ListsModule', 'no_login_callback'));
739 $unfound = array_diff_key($logins, $members);
741 // Make sure we send a list (array_values) of unique (array_unique)
743 $members = array_values(array_unique($members));
745 $arr = $mlist->subscribeBulk($members);
747 $successes = array();
748 if (is_array($arr)) {
749 foreach($arr as $addr) {
750 $successes[] = $addr[1];
751 $page->trigSuccess("{$addr[0]} inscrit.");
755 $already = array_diff($members, $successes);
756 if (is_array($already)) {
757 foreach ($already as $item) {
758 $page->trigWarning($item . ' est déjà inscrit.');
762 if (is_array($unfound)) {
763 foreach ($unfound as $item) {
764 if (trim($item) != '') {
765 $page->trigError($item . " ne correspond pas à un compte existant et n'est pas une adresse email.");
771 if (Env
::has('del_member')) {
772 S
::assert_xsrf_token();
774 if (strpos(Env
::v('del_member'), '@') === false
) {
775 if ($del_member = User
::getSilent(Env
::t('del_member'))) {
776 $mlist->unsubscribeBulk(array($del_member->forlifeEmail()));
779 $mlist->unsubscribeBulk(array(Env
::v('del_member')));
781 pl_redirect('lists/admin/'.$liste);
784 if (Env
::has('add_owner')) {
785 S
::assert_xsrf_token();
787 $owners = User
::getBulkForlifeEmails(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
789 foreach ($owners as $forlife_email) {
790 if ($mlist->addOwner($forlife_email)) {
791 $page->trigSuccess($login ." ajouté aux modérateurs.");
797 if (Env
::has('del_owner')) {
798 S
::assert_xsrf_token();
800 if (strpos(Env
::v('del_owner'), '@') === false
) {
801 if ($del_owner = User
::getSilent(Env
::t('del_owner'))) {
802 $mlist->unsubscribeBulk(array($del_owner->forlifeEmail()));
805 $mlist->removeOwner(Env
::v('del_owner'));
807 pl_redirect('lists/admin/'.$liste);
810 if (list($det,$mem,$own) = $mlist->getMembers()) {
811 global $list_unregistered;
812 if ($list_unregistered) {
813 $page->assign_by_ref('unregistered', $list_unregistered);
815 $membres = list_sort_members($mem, @$tri_promo);
816 $moderos = list_sort_owners($own, @$tri_promo);
818 $page->assign_by_ref('details', $det);
819 $page->assign_by_ref('members', $membres);
820 $page->assign_by_ref('owners', $moderos);
821 $page->assign('np_m', count($mem));
823 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
824 . " Si tu penses qu'il s'agit d'une erreur, "
825 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
829 function handler_options($page, $liste = null
)
831 if (is_null($liste)) {
835 $mlist = $this->prepare_list($liste);
836 if (!$this->is_group_admin($page)) {
837 $this->verify_list_owner($page, $mlist);
840 $page->changeTpl('lists/options.tpl');
842 if (Post
::has('submit')) {
843 S
::assert_xsrf_token();
846 $values = array_map('utf8_decode', $values);
847 $spamlevel = intval($values['bogo_level']);
848 $unsurelevel = intval($values['unsure_level']);
849 if ($spamlevel == 0) {
852 if ($spamlevel > 3 ||
$spamlevel < 0 ||
$unsurelevel < 0 ||
$unsurelevel > 1) {
853 $page->trigError("Réglage de l'antispam non valide");
855 $mlist->setBogoLevel(($spamlevel << 1) +
$unsurelevel);
857 switch($values['moderate']) {
859 $values['generic_nonmember_action'] = 0;
860 $values['default_member_moderation'] = 0;
863 $values['generic_nonmember_action'] = 1;
864 $values['default_member_moderation'] = 0;
867 $values['generic_nonmember_action'] = 1;
868 $values['default_member_moderation'] = 1;
871 unset($values['submit'], $values['bogo_level'], $values['moderate']);
872 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
873 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
874 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
875 if (isset($values['subject_prefix'])) {
876 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
878 $mlist->setOwnerOptions($values);
879 } elseif (isvalid_email(Post
::v('atn_add'))) {
880 S
::assert_xsrf_token();
881 $mlist->whitelistAdd(Post
::v('atn_add'));
882 } elseif (Get
::has('atn_del')) {
883 S
::assert_xsrf_token();
884 $mlist->whitelistRemove(Post
::v('atn_del'));
885 pl_redirect('lists/options/'.$liste);
888 if (list($details, $options) = $mlist->getOwnerOptions()) {
889 $page->assign_by_ref('details', $details);
890 $page->assign_by_ref('options', $options);
891 $bogo_level = intval($mlist->getBogoLevel());
892 $page->assign('unsure_level', $bogo_level & 1);
893 $page->assign('bogo_level', $bogo_level >> 1);
895 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
899 function handler_delete($page, $liste = null
)
902 if (is_null($liste)) {
906 $mlist = $this->prepare_list($liste);
907 if (!$this->is_group_admin($page)) {
908 $this->verify_list_owner($page, $mlist);
911 $page->changeTpl('lists/delete.tpl');
912 if (Post
::v('valid') == 'OUI') {
913 S
::assert_xsrf_token();
915 if ($mlist->delete(Post
::b('del_archive'))) {
916 require_once 'emails.inc.php';
918 delete_list($mlist->mbox
, $mlist->domain
);
919 $page->assign('deleted', true
);
920 $page->trigSuccess('La liste a été détruite !');
922 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
923 . 'Contact les administrateurs du site pour régler le problème : '
924 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
926 } elseif (list($details, $options) = $mlist->getOwnerOptions()) {
927 if (!$details['own']) {
928 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
930 $page->assign_by_ref('details', $details);
931 $page->assign_by_ref('options', $options);
932 $page->assign('bogo_level', $mlist->getBogoLevel());
934 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
938 function handler_soptions($page, $liste = null
)
940 if (is_null($liste)) {
944 $mlist = $this->prepare_list($liste);
945 if (!$this->is_group_admin($page)) {
946 $this->verify_list_owner($page, $mlist);
949 $page->changeTpl('lists/soptions.tpl');
951 if (Post
::has('submit')) {
952 S
::assert_xsrf_token();
955 $values = array_map('utf8_decode', $values);
956 unset($values['submit']);
957 $values['advertised'] = empty($values['advertised']) ? false
: true
;
958 $values['archive'] = empty($values['archive']) ? false
: true
;
959 $mlist->setAdminOptions($values);
962 if (list($details, $options) = $mlist->getAdminOptions()) {
963 $page->assign_by_ref('details', $details);
964 $page->assign_by_ref('options', $options);
966 $page->kill("La liste n'existe pas.");
970 function handler_check($page, $liste = null
)
972 if (is_null($liste)) {
976 $mlist = $this->prepare_list($liste);
977 if (!$this->is_group_admin($page)) {
978 $this->verify_list_owner($page, $mlist);
981 $page->changeTpl('lists/check.tpl');
983 if (Post
::has('correct')) {
984 S
::assert_xsrf_token();
985 $mlist->checkOptions(true
);
988 if (list($details, $options) = $mlist->checkOptions()) {
989 $page->assign_by_ref('details', $details);
990 $page->assign_by_ref('options', $options);
992 $page->kill("La liste n'existe pas.");
996 function handler_admin_all($page)
998 $page->changeTpl('lists/admin_all.tpl');
999 $page->setTitle('Administration - Mailing lists');
1001 $client = $this->prepare_client();
1002 $listes = $client->get_all_lists();
1003 $page->assign_by_ref('listes', $listes);
1006 function handler_aaliases($page, $alias = null
)
1009 require_once 'emails.inc.php';
1010 $page->setTitle('Administration - Aliases');
1012 if (Post
::has('new_alias')) {
1013 pl_redirect('admin/aliases/' . Post
::t('new_alias') . '@' . $globals->mail
->domain
);
1016 // If no alias, list them all.
1017 if (is_null($alias)) {
1018 $page->changeTpl('lists/admin_aliases.tpl');
1019 $page->assign('aliases', array_merge(iterate_list_alias($globals->mail
->domain
), iterate_list_alias($globals->mail
->domain2
)));
1023 list($local_part, $domain) = explode('@', $alias);
1024 if (!($globals->mail
->domain
== $domain ||
$globals->mail
->domain2
== $domain)
1025 ||
!preg_match("/^[a-zA-Z0-9\-\.]*$/", $local_part)) {
1026 $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
1029 // Now we can perform the action.
1030 if (Post
::has('del_alias')) {
1031 S
::assert_xsrf_token();
1033 delete_list_alias($local_part, $domain);
1034 $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
1037 if (Post
::has('add_member')) {
1038 S
::assert_xsrf_token();
1040 if (add_to_list_alias(Post
::t('add_member'), $local_part, $domain)) {
1041 $page->trigSuccess('Ajout réussit.');
1043 $page->trigError('Ajout infructueux.');
1047 if (Get
::has('del_member')) {
1048 S
::assert_xsrf_token();
1050 if (delete_from_list_alias(Get
::t('del_member'), $local_part, $domain)) {
1051 $page->trigSuccess('Suppression réussie.');
1053 $page->trigError('Suppression infructueuse.');
1057 $page->changeTpl('lists/admin_edit_alias.tpl');
1058 $page->assign('members', list_alias_members($local_part, $domain));
1059 $page->assign('alias', $alias);
1063 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: