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 is_group_admin($page)
66 $force_rights = false
;
67 if ($GLOBALS['IS_XNET_SITE']) {
68 $perms = S
::v('perms');
69 if (is_object($perms) && $perms->hasFlag('groupadmin')) {
73 $page->assign('group_admin', $force_rights);
78 function verify_list_owner($page, $liste)
80 if (list(, , $owners) = $this->client
->get_members($liste)) {
81 if (!(in_array(S
::user()->forlifeEmail(), $owners) || S
::admin())) {
82 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
85 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
86 . " Si tu penses qu'il s'agit d'une erreur, "
87 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
91 function get_pending_ops($domain, $list)
93 list($subs,$mails) = $this->client
->get_pending_ops($list);
94 $res = XDB
::query("SELECT mid
95 FROM email_list_moderate
96 WHERE ml = {?} AND domain = {?}",
98 $mids = $res->fetchColumn();
99 foreach ($mails as $key=>$mail) {
100 if (in_array($mail['id'], $mids)) {
104 return array($subs, $mails);
107 function handler_lists($page)
109 function filter_owner($list)
114 function filter_member($list)
119 $domain = $this->prepare_client($page);
121 $page->changeTpl('lists/index.tpl');
122 $page->setTitle('Listes de diffusion');
125 if (Get
::has('del')) {
126 S
::assert_xsrf_token();
127 $this->client
->unsubscribe(Get
::v('del'));
128 pl_redirect('lists');
130 if (Get
::has('add')) {
131 S
::assert_xsrf_token();
132 $this->client
->subscribe(Get
::v('add'));
133 pl_redirect('lists');
135 if (Post
::has('promo_add')) {
136 S
::assert_xsrf_token();
138 $promo = Post
::i('promo_add');
139 if ($promo >= 1900 and $promo < 2100) {
140 $mlist = MailingList
::promo($promo, S
::user());
143 $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
147 if (!is_null($listes = $this->client
->get_lists())) {
148 $owner = array_filter($listes, 'filter_owner');
149 $listes = array_diff_key($listes, $owner);
150 $member = array_filter($listes, 'filter_member');
151 $listes = array_diff_key($listes, $member);
152 foreach ($owner as $key => $liste) {
153 list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
154 $owner[$key]['subscriptions'] = $subs;
155 $owner[$key]['mails'] = $mails;
157 $page->register_modifier('hdc', 'list_header_decode');
158 $page->assign_by_ref('owner', $owner);
159 $page->assign_by_ref('member', $member);
160 $page->assign_by_ref('public', $listes);
164 function handler_ajax($page, $list = null
)
166 pl_content_headers("text/html");
167 $domain = $this->prepare_client($page);
168 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
169 S
::assert_xsrf_token();
171 if (Get
::has('unsubscribe')) {
172 $this->client
->unsubscribe($list);
174 if (Get
::has('subscribe')) {
175 $this->client
->subscribe($list);
177 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
178 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
180 if (Get
::has('mid')) {
181 $this->moderate_mail($domain, $list, Get
::i('mid'));
184 list($liste, $members, $owners) = $this->client
->get_members($list);
186 list($subs,$mails) = $this->get_pending_ops($domain, $list);
187 $liste['subscriptions'] = $subs;
188 $liste['mails'] = $mails;
190 $page->register_modifier('hdc', 'list_header_decode');
191 $page->assign_by_ref('liste', $liste);
194 function handler_create($page)
198 $page->changeTpl('lists/create.tpl');
200 $user_promo = S
::user()->profile()->yearPromo();
203 // scolar year starts in september
204 $scolarmonth = ($year - $user_promo) * 12 +
($month - 8);
205 $young_promo = $very_young_promo = 0;
206 // binet are accessible only in april in the first year and until
207 // march of the 5th year
208 if ($scolarmonth >= 8 && $scolarmonth < 56) {
211 // PSC aliases are accesible only between september and june of the second
213 if ($scolarmonth >= 12 && $scolarmonth < 22) {
214 $very_young_promo = 1;
216 $page->assign('young_promo', $young_promo);
217 $page->assign('very_young_promo', $very_young_promo);
219 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
220 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
222 // click on validate button 'add_owner_sub' or type <enter>
223 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
224 // if we want to add an owner and then type <enter>, then both
225 // add_owner_sub and add_owner are filled.
226 $oforlifes = User
::getBulkForlifeEmails(Post
::v('add_owner'), true
);
227 $mforlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
228 if (!is_null($oforlifes)) {
229 $owners = array_merge($owners, $oforlifes);
231 // if we want to add a member and then type <enter>, then
232 // add_owner_sub is filled, whereas add_owner is empty.
233 if (!is_null($mforlifes)) {
234 $members = array_merge($members, $mforlifes);
238 // click on validate button 'add_member_sub'
239 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
240 $forlifes = User
::getBulkForlifeEmails(Post
::v('add_member'), true
);
241 if (!is_null($forlifes)) {
242 $members = array_merge($members, $forlifes);
245 if (Post
::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
246 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
248 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
250 $forlifes = User
::getBulkForlifeEmails($upload->getContents(), true
);
251 if (!is_null($forlifes)) {
252 $members = array_merge($members, $forlifes);
258 $owners = array_unique($owners);
260 $members = array_unique($members);
262 $page->assign('owners', join("\n", $owners));
263 $page->assign('members', join("\n", $members));
265 if (!Post
::has('submit')) {
268 S
::assert_xsrf_token();
271 $asso = Post
::t('asso');
272 $list = strtolower(Post
::t('liste'));
275 $page->trigError('Le champ « adresse souhaitée » est vide.');
277 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
278 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
281 if (($asso == 'binet') ||
($asso == 'alias')) {
282 $promo = Post
::i('promo');
283 $domain = $promo . '.' . $globals->mail
->domain
;
285 if (($promo < 1921) ||
($promo > date('Y'))) {
286 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
289 } elseif ($asso == 'groupex') {
290 $domain = XDB
::fetchOneCell('SELECT mail_domain
293 Post
::t('groupex_name'));
296 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
299 $domain = $globals->mail
->domain
;
302 require_once 'emails.inc.php';
303 if (list_exist($list, $domain)) {
304 $page->trigError("L'« adresse souhaitée » est déjà prise.");
307 if (!Post
::t('desc')) {
308 $page->trigError('Le sujet est vide.');
311 if (!count($owners)) {
312 $page->trigError('Il n\'y a pas de gestionnaire.');
315 if (count($members) < 4) {
316 $page->trigError('Il n\'y a pas assez de membres.');
319 if (!$page->nb_errs()) {
320 $page->trigSuccess('Demande de création envoyée !');
321 $page->assign('created', true
);
322 $req = new ListeReq(S
::user(), $asso, $list, $domain,
323 Post
::t('desc'), Post
::i('advertise'),
324 Post
::i('modlevel'), Post
::i('inslevel'),
330 function handler_members($page, $liste = null
)
332 if (is_null($liste)) {
336 $this->prepare_client($page);
337 $this->is_group_admin($page);
339 $page->changeTpl('lists/members.tpl');
341 if (Get
::has('del')) {
342 S
::assert_xsrf_token();
343 $this->client
->unsubscribe($liste);
344 pl_redirect('lists/members/'.$liste);
347 if (Get
::has('add')) {
348 S
::assert_xsrf_token();
349 $this->client
->subscribe($liste);
350 pl_redirect('lists/members/'.$liste);
353 $members = $this->client
->get_members($liste);
355 $tri_promo = !Env
::b('alpha');
357 if (list($det,$mem,$own) = $members) {
358 $membres = list_sort_members($mem, $tri_promo);
359 $moderos = list_sort_owners($own, $tri_promo);
361 $page->assign_by_ref('details', $det);
362 $page->assign_by_ref('members', $membres);
363 $page->assign_by_ref('owners', $moderos);
364 $page->assign('nb_m', count($mem));
366 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
370 function handler_csv(PlPage
$page, $liste = null
)
372 if (is_null($liste)) {
375 $this->prepare_client($page);
376 $this->is_group_admin($page);
377 $members = $this->client
->get_members($liste);
378 $list = list_fetch_basic_info(list_extract_members($members[1]));
379 pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1);
381 echo utf8_decode("Nom;Prénom;Promotion\n");
382 echo utf8_decode(implode("\n", $list));
386 function handler_annu($page, $liste = null
, $action = null
, $subaction = null
)
388 if (is_null($liste)) {
392 $this->prepare_client($page);
393 $this->is_group_admin($page);
395 if (Get
::has('del')) {
396 S
::assert_xsrf_token();
397 $this->client
->unsubscribe($liste);
398 pl_redirect('lists/annu/'.$liste);
400 if (Get
::has('add')) {
401 S
::assert_xsrf_token();
402 $this->client
->subscribe($liste);
403 pl_redirect('lists/annu/'.$liste);
406 $owners = $this->client
->get_owners($liste);
407 if (!is_array($owners)) {
408 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
411 list(,$members) = $this->client
->get_members($liste);
413 if ($action == 'moderators') {
415 $show_moderators = true
;
416 $action = $subaction;
419 $show_moderators = false
;
421 foreach ($members as $m) {
426 require_once 'userset.inc.php';
427 $view = new UserArraySet($users);
428 $view->addMod('trombi', 'Trombinoscope', false
, array('with_promo' => true
));
429 $view->addMod('listmember', 'Annuaire', true
);
430 if (empty($GLOBALS['IS_XNET_SITE'])) {
431 $view->addMod('minifiche', 'Mini-fiches', false
);
433 $view->addMod('map', 'Planisphère');
434 $view->apply("lists/annu/$liste", $page, $action, $subaction);
436 $page->changeTpl('lists/annu.tpl');
437 $page->assign_by_ref('details', $owners[0]);
438 $page->assign('show_moderators', $show_moderators);
441 function handler_archives($page, $liste = null
, $action = null
, $artid = null
)
445 if (is_null($liste)) {
449 $domain = $this->prepare_client($page);
450 $this->is_group_admin($page);
452 $page->changeTpl('lists/archives.tpl');
454 if (list($det) = $this->client
->get_members($liste)) {
455 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
456 && !$det['own'] && ($det['sub'] < 2)) {
457 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
459 $get = Array('listname' => $liste, 'domain' => $domain);
460 if (Post
::has('updateall')) {
461 $get['updateall'] = Post
::v('updateall');
463 require_once 'banana/ml.inc.php';
464 get_banana_params($get, null
, $action, $artid);
465 run_banana($page, 'MLBanana', $get);
467 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
471 function handler_rss($page, $liste = null
, $alias = null
, $hash = null
)
476 $user = Platal
::session()->tokenAuth($alias, $hash);
477 if (is_null($user)) {
481 $domain = $this->prepare_client($page, $user);
482 if (list($det) = $this->client
->get_members($liste)) {
483 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
484 && !$det['own'] && ($det['sub'] < 2)) {
487 require_once('banana/ml.inc.php');
488 $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
494 function moderate_mail($domain, $liste, $mid)
496 if (Env
::has('mok')) {
498 } elseif (Env
::has('mno')) {
500 } elseif (Env
::has('mdel')) {
506 return XDB
::execute("INSERT IGNORE INTO email_list_moderate
507 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
508 $liste, $domain, $mid, S
::i('uid'), $action, Post
::v('reason'));
511 function handler_moderate($page, $liste = null
)
513 if (is_null($liste)) {
517 $domain = $this->prepare_client($page);
518 if (!$this->is_group_admin($page)) {
519 $this->verify_list_owner($page, $liste);
522 $page->changeTpl('lists/moderate.tpl');
524 $page->register_modifier('hdc', 'list_header_decode');
526 if (Env
::has('sadd') || Env
::has('sdel')) {
527 S
::assert_xsrf_token();
529 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
530 $sub = $this->client
->get_pending_sub($liste, Env
::v('sadd'));
531 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
534 if (Post
::has('sdel')) { /* 2 = REJECT */
535 $sub = $this->client
->get_pending_sub($liste, Env
::v('sdel'));
536 $this->client
->handle_request($liste, Post
::v('sdel'), 2, utf8_decode(Post
::v('reason')));
540 $mailer = new PlMailer();
541 $mailer->setFrom("$liste-bounces@{$domain}");
542 $mailer->addTo("$liste-owner@{$domain}");
543 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
544 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
545 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S
::user()->fullName(true
) . ".\n";
546 if (trim(Post
::v('reason'))) {
547 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
549 $mailer->setTxtBody(wordwrap($text, 72));
552 if (Env
::has('sadd')) {
553 pl_redirect('lists/moderate/'.$liste);
557 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
558 S
::assert_xsrf_token();
560 $mails = array_keys(Post
::v('select_mails'));
561 foreach($mails as $mail) {
562 $this->moderate_mail($domain, $liste, $mail);
564 } elseif (Env
::has('mid')) {
565 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
566 require_once 'banana/moderate.inc.php';
568 $page->changeTpl('lists/moderate_mail.tpl');
569 $params = array('listname' => $liste, 'domain' => $domain,
570 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
571 $params['client'] = $this->client
;
572 run_banana($page, 'ModerationBanana', $params);
574 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
575 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
576 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
577 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
578 $msg = str_replace("%(listname)s", $liste, $msg);
579 $page->assign('msg', $msg);
583 $this->moderate_mail($domain, $liste, Env
::i('mid'));
584 } elseif (Env
::has('sid')) {
585 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
586 foreach($subs as $user) {
587 if ($user['id'] == Env
::v('sid')) {
588 $page->changeTpl('lists/moderate_sub.tpl');
589 $page->assign('del_user', $user);
597 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
598 foreach ($mails as $key=>$mail) {
599 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
600 if ($mail['fromx']) {
601 $page->assign('with_fromx', true
);
603 $page->assign('with_nonfromx', true
);
606 $page->assign_by_ref('subs', $subs);
607 $page->assign_by_ref('mails', $mails);
609 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
613 static public function no_login_callback($login)
615 global $list_unregistered;
617 $users = User
::getPendingAccounts($login, true
);
618 if ($users && $users->total()) {
619 if (!isset($list_unregistered)) {
620 $list_unregistered = array();
622 $list_unregistered[$login] = $users;
624 list($name, $domain) = @explode
('@', $login);
625 if (User
::isMainMailDomain($domain)) {
626 User
::_default_user_callback($login);
631 function handler_admin($page, $liste = null
)
635 if (is_null($liste)) {
639 $domain = $this->prepare_client($page);
640 $this->is_group_admin($page);
641 if (!$this->is_group_admin($page)) {
642 $this->verify_list_owner($page, $liste);
645 $page->changeTpl('lists/admin.tpl');
647 if (Env
::has('send_mark')) {
648 S
::assert_xsrf_token();
650 $actions = Env
::v('mk_action');
651 $uids = Env
::v('mk_uid');
652 $mails = Env
::v('mk_email');
653 foreach ($actions as $key=>$action) {
658 case 'marketu': case 'markets':
659 require_once 'emails.inc.php';
660 $user = User
::get($uids[$key]);
661 $mail = valide_email($mails[$key]);
662 if (isvalid_email_redirection($mail, $user)) {
663 $from = ($action == 'marketu') ?
'user' : 'staff';
664 $market = Marketing
::get($uids[$key], $mail);
666 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S
::v('uid'));
673 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
674 VALUES ({?}, \'list\', {?}, {?})',
675 $uids[$key], $liste, $domain);
680 if (Env
::has('add_member') ||
681 isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
682 S
::assert_xsrf_token();
684 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
685 $upload =& PlUpload
::get($_FILES['add_member_file'], S
::user()->login(), 'list.addmember', true
);
687 $page->trigError("Une erreur s'est produite lors du téléchargement du fichier.");
689 $logins = $upload->getContents();
692 $logins = Env
::v('add_member');
695 $logins = preg_split("/[; ,\r\n\|]+/", $logins);
696 $members = User
::getBulkForlifeEmails($logins,
698 array('ListsModule', 'no_login_callback'));
699 $unfound = array_diff_key($logins, $members);
701 // Make sure we send a list (array_values) of unique (array_unique)
703 $members = array_values(array_unique($members));
705 $arr = $this->client
->mass_subscribe($liste, $members);
707 $successes = array();
708 if (is_array($arr)) {
709 foreach($arr as $addr) {
710 $successes[] = $addr[1];
711 $page->trigSuccess("{$addr[0]} inscrit.");
715 $already = array_diff($members, $successes);
716 if (is_array($already)) {
717 foreach ($already as $item) {
718 $page->trigWarning($item . ' est déjà inscrit.');
722 if (is_array($unfound)) {
723 foreach ($unfound as $item) {
724 if (trim($item) != '') {
725 $page->trigError($item . " ne correspond pas à un compte existant et n'est pas une adresse email.");
731 if (Env
::has('del_member')) {
732 S
::assert_xsrf_token();
734 if (strpos(Env
::v('del_member'), '@') === false
) {
735 if ($del_member = User
::getSilent(Env
::t('del_member'))) {
736 $this->client
->mass_unsubscribe($liste, array($del_member->forlifeEmail()));
739 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
741 pl_redirect('lists/admin/'.$liste);
744 if (Env
::has('add_owner')) {
745 S
::assert_xsrf_token();
747 $owners = User
::getBulkForlifeEmails(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
749 foreach ($owners as $login) {
750 if ($this->client
->add_owner($liste, $login)) {
751 $page->trigSuccess($login ." ajouté aux modérateurs.");
757 if (Env
::has('del_owner')) {
758 S
::assert_xsrf_token();
760 if (strpos(Env
::v('del_owner'), '@') === false
) {
761 if ($del_owner = User
::getSilent(Env
::t('del_owner'))) {
762 $this->client
->mass_unsubscribe($liste, array($del_owner->forlifeEmail()));
765 $this->client
->del_owner($liste, Env
::v('del_owner'));
767 pl_redirect('lists/admin/'.$liste);
770 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
771 global $list_unregistered;
772 if ($list_unregistered) {
773 $page->assign_by_ref('unregistered', $list_unregistered);
775 $membres = list_sort_members($mem, @$tri_promo);
776 $moderos = list_sort_owners($own, @$tri_promo);
778 $page->assign_by_ref('details', $det);
779 $page->assign_by_ref('members', $membres);
780 $page->assign_by_ref('owners', $moderos);
781 $page->assign('np_m', count($mem));
783 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
784 . " Si tu penses qu'il s'agit d'une erreur, "
785 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
789 function handler_options($page, $liste = null
)
791 if (is_null($liste)) {
795 $this->prepare_client($page);
796 if (!$this->is_group_admin($page)) {
797 $this->verify_list_owner($page, $liste);
800 $page->changeTpl('lists/options.tpl');
802 if (Post
::has('submit')) {
803 S
::assert_xsrf_token();
806 $values = array_map('utf8_decode', $values);
807 $spamlevel = intval($values['bogo_level']);
808 $unsurelevel = intval($values['unsure_level']);
809 if ($spamlevel == 0) {
812 if ($spamlevel > 3 ||
$spamlevel < 0 ||
$unsurelevel < 0 ||
$unsurelevel > 1) {
813 $page->trigError("Réglage de l'antispam non valide");
815 $this->client
->set_bogo_level($liste, ($spamlevel << 1) +
$unsurelevel);
817 switch($values['moderate']) {
819 $values['generic_nonmember_action'] = 0;
820 $values['default_member_moderation'] = 0;
823 $values['generic_nonmember_action'] = 1;
824 $values['default_member_moderation'] = 0;
827 $values['generic_nonmember_action'] = 1;
828 $values['default_member_moderation'] = 1;
831 unset($values['submit'], $values['bogo_level'], $values['moderate']);
832 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
833 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
834 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
835 if (isset($values['subject_prefix'])) {
836 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
838 $this->client
->set_owner_options($liste, $values);
839 } elseif (isvalid_email(Post
::v('atn_add'))) {
840 S
::assert_xsrf_token();
841 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
842 } elseif (Get
::has('atn_del')) {
843 S
::assert_xsrf_token();
844 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
845 pl_redirect('lists/options/'.$liste);
848 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
849 $page->assign_by_ref('details', $details);
850 $page->assign_by_ref('options', $options);
851 $bogo_level = intval($this->client
->get_bogo_level($liste));
852 $page->assign('unsure_level', $bogo_level & 1);
853 $page->assign('bogo_level', $bogo_level >> 1);
855 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
859 function handler_delete($page, $liste = null
)
862 if (is_null($liste)) {
866 $domain = $this->prepare_client($page);
867 if (!$this->is_group_admin($page)) {
868 $this->verify_list_owner($page, $liste);
871 $page->changeTpl('lists/delete.tpl');
872 if (Post
::v('valid') == 'OUI') {
873 S
::assert_xsrf_token();
875 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
876 require_once 'emails.inc.php';
878 delete_list($liste, $domain);
879 $page->assign('deleted', true
);
880 $page->trigSuccess('La liste a été détruite !');
882 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
883 . 'Contact les administrateurs du site pour régler le problème : '
884 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
886 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
887 if (!$details['own']) {
888 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
890 $page->assign_by_ref('details', $details);
891 $page->assign_by_ref('options', $options);
892 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
894 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
898 function handler_soptions($page, $liste = null
)
900 if (is_null($liste)) {
904 $this->prepare_client($page);
905 if (!$this->is_group_admin($page)) {
906 $this->verify_list_owner($page, $liste);
909 $page->changeTpl('lists/soptions.tpl');
911 if (Post
::has('submit')) {
912 S
::assert_xsrf_token();
915 $values = array_map('utf8_decode', $values);
916 unset($values['submit']);
917 $values['advertised'] = empty($values['advertised']) ? false
: true
;
918 $values['archive'] = empty($values['archive']) ? false
: true
;
919 $this->client
->set_admin_options($liste, $values);
922 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
923 $page->assign_by_ref('details', $details);
924 $page->assign_by_ref('options', $options);
926 $page->kill("La liste n'existe pas.");
930 function handler_check($page, $liste = null
)
932 if (is_null($liste)) {
936 $this->prepare_client($page);
937 if (!$this->is_group_admin($page)) {
938 $this->verify_list_owner($page, $liste);
941 $page->changeTpl('lists/check.tpl');
943 if (Post
::has('correct')) {
944 S
::assert_xsrf_token();
945 $this->client
->check_options($liste, true
);
948 if (list($details,$options) = $this->client
->check_options($liste)) {
949 $page->assign_by_ref('details', $details);
950 $page->assign_by_ref('options', $options);
952 $page->kill("La liste n'existe pas.");
956 function handler_admin_all($page)
958 $page->changeTpl('lists/admin_all.tpl');
959 $page->setTitle('Administration - Mailing lists');
961 $this->prepare_client($page);
962 $listes = $this->client
->get_all_lists();
963 $page->assign_by_ref('listes', $listes);
966 function handler_aaliases($page, $alias = null
)
969 require_once 'emails.inc.php';
970 $page->setTitle('Administration - Aliases');
972 if (Post
::has('new_alias')) {
973 pl_redirect('admin/aliases/' . Post
::t('new_alias') . '@' . $globals->mail
->domain
);
976 // If no alias, list them all.
977 if (is_null($alias)) {
978 $page->changeTpl('lists/admin_aliases.tpl');
979 $page->assign('aliases', array_merge(iterate_list_alias($globals->mail
->domain
), iterate_list_alias($globals->mail
->domain2
)));
983 list($local_part, $domain) = explode('@', $alias);
984 if (!($globals->mail
->domain
== $domain ||
$globals->mail
->domain2
== $domain)
985 ||
!preg_match("/^[a-zA-Z0-9\-\.]*$/", $local_part)) {
986 $page->trigErrorRedirect('Le nom de l\'alias est erroné.', $globals->asso('diminutif') . 'admin/aliases');
989 // Now we can perform the action.
990 if (Post
::has('del_alias')) {
991 S
::assert_xsrf_token();
993 delete_list_alias($local_part, $domain);
994 $page->trigSuccessRedirect($alias . ' supprimé.', 'admin/aliases');
997 if (Post
::has('add_member')) {
998 S
::assert_xsrf_token();
1000 if (add_to_list_alias(Post
::t('add_member'), $local_part, $domain)) {
1001 $page->trigSuccess('Ajout réussit.');
1003 $page->trigError('Ajout infructueux.');
1007 if (Get
::has('del_member')) {
1008 S
::assert_xsrf_token();
1010 if (delete_from_list_alias(Get
::t('del_member'), $local_part, $domain)) {
1011 $page->trigSuccess('Suppression réussie.');
1013 $page->trigError('Suppression infructueuse.');
1017 $page->changeTpl('lists/admin_edit_alias.tpl');
1018 $page->assign('members', list_alias_members($local_part, $domain));
1019 $page->assign('alias', $alias);
1023 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: