5c4ec4d30ffe2309f933fd82a40bb81a70913af2
[platal.git] / modules / lists.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2011 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
5 * *
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. *
10 * *
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. *
15 * *
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 *
18 * Foundation, Inc., *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
21
22 class ListsModule extends PLModule
23 {
24 protected $client;
25
26 function handlers()
27 {
28 return array(
29 'lists' => $this->make_hook('lists', AUTH_MDP),
30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH),
31 'lists/create' => $this->make_hook('create', AUTH_MDP, 'lists'),
32
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE),
34 'lists/csv' => $this->make_hook('csv', AUTH_COOKIE),
35 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE),
36 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE),
37 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
38
39 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP),
40 'lists/admin' => $this->make_hook('admin', AUTH_MDP),
41 'lists/options' => $this->make_hook('options', AUTH_MDP),
42 'lists/delete' => $this->make_hook('delete', AUTH_MDP),
43
44 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP),
45 'lists/check' => $this->make_hook('check', AUTH_MDP),
46 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'),
47 );
48 }
49
50 function prepare_client($page, $user = null)
51 {
52 global $globals;
53
54 $this->load('lists.inc.php');
55 if (is_null($user)) {
56 $user = S::user();
57 }
58
59 $this->client = new MMList($user);
60 return $globals->mail->domain;
61 }
62
63 function get_pending_ops($domain, $list)
64 {
65 list($subs,$mails) = $this->client->get_pending_ops($list);
66 $res = XDB::query("SELECT mid
67 FROM email_list_moderate
68 WHERE ml = {?} AND domain = {?}",
69 $list, $domain);
70 $mids = $res->fetchColumn();
71 foreach ($mails as $key=>$mail) {
72 if (in_array($mail['id'], $mids)) {
73 unset($mails[$key]);
74 }
75 }
76 return array($subs, $mails);
77 }
78
79 function handler_lists($page)
80 {
81 function filter_owner($list)
82 {
83 return $list['own'];
84 }
85
86 function filter_member($list)
87 {
88 return $list['sub'];
89 }
90
91 $domain = $this->prepare_client($page);
92
93 $page->changeTpl('lists/index.tpl');
94 $page->setTitle('Listes de diffusion');
95
96
97 if (Get::has('del')) {
98 S::assert_xsrf_token();
99 $this->client->unsubscribe(Get::v('del'));
100 pl_redirect('lists');
101 }
102 if (Get::has('add')) {
103 S::assert_xsrf_token();
104 $this->client->subscribe(Get::v('add'));
105 pl_redirect('lists');
106 }
107 if (Post::has('promo_add')) {
108 S::assert_xsrf_token();
109
110 $promo = Post::i('promo_add');
111 if ($promo >= 1900 and $promo < 2100) {
112 $this->client->subscribe("promo$promo");
113 } else {
114 $page->trigError("promo incorrecte, il faut une promo sur 4 chiffres.");
115 }
116 }
117
118 if (!is_null($listes = $this->client->get_lists())) {
119 $owner = array_filter($listes, 'filter_owner');
120 $listes = array_diff_key($listes, $owner);
121 $member = array_filter($listes, 'filter_member');
122 $listes = array_diff_key($listes, $member);
123 foreach ($owner as $key => $liste) {
124 list($subs, $mails) = $this->get_pending_ops($domain, $liste['list']);
125 $owner[$key]['subscriptions'] = $subs;
126 $owner[$key]['mails'] = $mails;
127 }
128 $page->register_modifier('hdc', 'list_header_decode');
129 $page->assign_by_ref('owner', $owner);
130 $page->assign_by_ref('member', $member);
131 $page->assign_by_ref('public', $listes);
132 }
133 }
134
135 function handler_ajax($page, $list = null)
136 {
137 pl_content_headers("text/html");
138 $domain = $this->prepare_client($page);
139 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
140 S::assert_xsrf_token();
141
142 if (Get::has('unsubscribe')) {
143 $this->client->unsubscribe($list);
144 }
145 if (Get::has('subscribe')) {
146 $this->client->subscribe($list);
147 }
148 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
149 $this->client->handle_request($list, Get::v('sadd'), 4, '');
150 }
151 if (Get::has('mid')) {
152 $this->moderate_mail($domain, $list, Get::i('mid'));
153 }
154
155 list($liste, $members, $owners) = $this->client->get_members($list);
156 if ($liste['own']) {
157 list($subs,$mails) = $this->get_pending_ops($domain, $list);
158 $liste['subscriptions'] = $subs;
159 $liste['mails'] = $mails;
160 }
161 $page->register_modifier('hdc', 'list_header_decode');
162 $page->assign_by_ref('liste', $liste);
163 }
164
165 function handler_create($page)
166 {
167 global $globals;
168
169 $page->changeTpl('lists/create.tpl');
170
171 $user_promo = S::user()->profile()->yearPromo();
172 $year = date('Y');
173 $month = date('m');
174 // scolar year starts in september
175 $scolarmonth = ($year - $user_promo) * 12 + ($month - 8);
176 $young_promo = $very_young_promo = 0;
177 // binet are accessible only in april in the first year and until
178 // march of the 5th year
179 if ($scolarmonth >= 8 && $scolarmonth < 56) {
180 $young_promo = 1;
181 }
182 // PSC aliases are accesible only between september and june of the second
183 // year of scolarity
184 if ($scolarmonth >= 12 && $scolarmonth < 22) {
185 $very_young_promo = 1;
186 }
187 $page->assign('young_promo', $young_promo);
188 $page->assign('very_young_promo', $very_young_promo);
189
190 $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
191 $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
192
193 // click on validate button 'add_owner_sub' or type <enter>
194 if (Post::has('add_owner_sub') && Post::has('add_owner')) {
195 // if we want to add an owner and then type <enter>, then both
196 // add_owner_sub and add_owner are filled.
197 $oforlifes = User::getBulkForlifeEmails(Post::v('add_owner'), true);
198 $mforlifes = User::getBulkForlifeEmails(Post::v('add_member'), true);
199 if (!is_null($oforlifes)) {
200 $owners = array_merge($owners, $oforlifes);
201 }
202 // if we want to add a member and then type <enter>, then
203 // add_owner_sub is filled, whereas add_owner is empty.
204 if (!is_null($mforlifes)) {
205 $members = array_merge($members, $mforlifes);
206 }
207 }
208
209 // click on validate button 'add_member_sub'
210 if (Post::has('add_member_sub') && Post::has('add_member')) {
211 $forlifes = User::getBulkForlifeEmails(Post::v('add_member'), true);
212 if (!is_null($forlifes)) {
213 $members = array_merge($members, $forlifes);
214 }
215 }
216 if (Post::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
217 $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true);
218 if (!$upload) {
219 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
220 } else {
221 $forlifes = User::getBulkForlifeEmails($upload->getContents(), true);
222 if (!is_null($forlifes)) {
223 $members = array_merge($members, $forlifes);
224 }
225 }
226 }
227
228 ksort($owners);
229 $owners = array_unique($owners);
230 ksort($members);
231 $members = array_unique($members);
232
233 $page->assign('owners', join("\n", $owners));
234 $page->assign('members', join("\n", $members));
235
236 if (!Post::has('submit')) {
237 return;
238 } else {
239 S::assert_xsrf_token();
240 }
241
242 $asso = Post::t('asso');
243 $list = strtolower(Post::t('liste'));
244
245 if (empty($list)) {
246 $page->trigError('Le champ «&nbsp;adresse souhaitée&nbsp;» est vide.');
247 }
248 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $list)) {
249 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
250 }
251
252 if (($asso == 'binet') || ($asso == 'alias')) {
253 $promo = Post::i('promo');
254 $domain = $promo . '.' . $globals->mail->domain;
255
256 if (($promo < 1921) || ($promo > date('Y'))) {
257 $page->trigError('La promotion est mal renseignée, elle doit être du type&nbsp;: 2004.');
258 }
259
260 } elseif ($asso == 'groupex') {
261 $domain = XDB::fetchOneCell('SELECT mail_domain
262 FROM groups
263 WHERE nom = {?}',
264 Post::t('groupex_name'));
265
266 if (!$domain) {
267 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
268 }
269 } else {
270 $domain = $globals->mail->domain;
271 }
272
273 require_once 'emails.inc.php';
274 if (list_exist($list, $domain)) {
275 $page->trigError("L'«&nbsp;adresse souhaitée&nbsp;» est déjà prise.");
276 }
277
278 if (!Post::t('desc')) {
279 $page->trigError('Le sujet est vide.');
280 }
281
282 if (!count($owners)) {
283 $page->trigError('Il n\'y a pas de gestionnaire.');
284 }
285
286 if (count($members) < 4) {
287 $page->trigError('Il n\'y a pas assez de membres.');
288 }
289
290 if (!$page->nb_errs()) {
291 $page->trigSuccess('Demande de création envoyée&nbsp;!');
292 $page->assign('created', true);
293 $req = new ListeReq(S::user(), $asso, $list, $domain,
294 Post::t('desc'), Post::i('advertise'),
295 Post::i('modlevel'), Post::i('inslevel'),
296 $owners, $members);
297 $req->submit();
298 }
299 }
300
301 function handler_members($page, $liste = null)
302 {
303 if (is_null($liste)) {
304 return PL_NOT_FOUND;
305 }
306
307 $this->prepare_client($page);
308
309 $page->changeTpl('lists/members.tpl');
310
311 if (Get::has('del')) {
312 S::assert_xsrf_token();
313 $this->client->unsubscribe($liste);
314 pl_redirect('lists/members/'.$liste);
315 }
316
317 if (Get::has('add')) {
318 S::assert_xsrf_token();
319 $this->client->subscribe($liste);
320 pl_redirect('lists/members/'.$liste);
321 }
322
323 $members = $this->client->get_members($liste);
324
325 $tri_promo = !Env::b('alpha');
326
327 if (list($det,$mem,$own) = $members) {
328 $membres = list_sort_members($mem, $tri_promo);
329 $moderos = list_sort_owners($own, $tri_promo);
330
331 $page->assign_by_ref('details', $det);
332 $page->assign_by_ref('members', $membres);
333 $page->assign_by_ref('owners', $moderos);
334 $page->assign('nb_m', count($mem));
335 } else {
336 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
337 }
338 }
339
340 function handler_csv(PlPage $page, $liste = null)
341 {
342 if (is_null($liste)) {
343 return PL_NOT_FOUND;
344 }
345 $this->prepare_client($page);
346 $members = $this->client->get_members($liste);
347 $list = list_fetch_basic_info(list_extract_members($members[1]));
348 pl_cached_content_headers('text/x-csv', 1);
349
350 echo "email,nom,promo\n";
351 echo implode("\n", $list);
352 exit;
353 }
354
355 function handler_annu($page, $liste = null, $action = null, $subaction = null)
356 {
357 if (is_null($liste)) {
358 return PL_NOT_FOUND;
359 }
360
361 $this->prepare_client($page);
362
363 if (Get::has('del')) {
364 S::assert_xsrf_token();
365 $this->client->unsubscribe($liste);
366 pl_redirect('lists/annu/'.$liste);
367 }
368 if (Get::has('add')) {
369 S::assert_xsrf_token();
370 $this->client->subscribe($liste);
371 pl_redirect('lists/annu/'.$liste);
372 }
373
374 $owners = $this->client->get_owners($liste);
375 if (!is_array($owners)) {
376 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails.");
377 }
378
379 global $platal;
380 list(,$members) = $this->client->get_members($liste);
381 $users = array();
382 foreach ($members as $m) {
383 $users[] = $m[1];
384 }
385 require_once 'userset.inc.php';
386 $view = new ArraySet($users);
387 $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true));
388 if (empty($GLOBALS['IS_XNET_SITE'])) {
389 $view->addMod('minifiche', 'Mini-fiches', false);
390 }
391 // TODO: Reactivate when the new map is completed.
392 // $view->addMod('geoloc', 'Planisphère');
393 $view->apply("lists/annu/$liste", $page, $action, $subaction);
394 if ($action == 'geoloc' && $subaction) {
395 return;
396 }
397
398 $page->changeTpl('lists/annu.tpl');
399 $moderos = list_sort_owners($owners[1]);
400 $page->assign_by_ref('details', $owners[0]);
401 $page->assign_by_ref('owners', $moderos);
402 }
403
404 function handler_archives($page, $liste = null, $action = null, $artid = null)
405 {
406 global $globals;
407
408 if (is_null($liste)) {
409 return PL_NOT_FOUND;
410 }
411
412 $domain = $this->prepare_client($page);
413
414 $page->changeTpl('lists/archives.tpl');
415
416 if (list($det) = $this->client->get_members($liste)) {
417 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
418 && !$det['own'] && ($det['sub'] < 2)) {
419 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
420 }
421 $get = Array('listname' => $liste, 'domain' => $domain);
422 if (Post::has('updateall')) {
423 $get['updateall'] = Post::v('updateall');
424 }
425 require_once 'banana/ml.inc.php';
426 get_banana_params($get, null, $action, $artid);
427 run_banana($page, 'MLBanana', $get);
428 } else {
429 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
430 }
431 }
432
433 function handler_rss($page, $liste = null, $alias = null, $hash = null)
434 {
435 if (!$liste) {
436 return PL_NOT_FOUND;
437 }
438 $user = Platal::session()->tokenAuth($alias, $hash);
439 if (is_null($user)) {
440 return PL_FORBIDDEN;
441 }
442
443 $domain = $this->prepare_client($page, $user);
444 if (list($det) = $this->client->get_members($liste)) {
445 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
446 && !$det['own'] && ($det['sub'] < 2)) {
447 exit;
448 }
449 require_once('banana/ml.inc.php');
450 $banana = new MLBanana($user, Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
451 $banana->run();
452 }
453 exit;
454 }
455
456 function moderate_mail($domain, $liste, $mid)
457 {
458 if (Env::has('mok')) {
459 $action = 'accept';
460 } elseif (Env::has('mno')) {
461 $action = 'refuse';
462 } elseif (Env::has('mdel')) {
463 $action = 'delete';
464 } else {
465 return false;
466 }
467 Get::kill('mid');
468 return XDB::execute("INSERT IGNORE INTO email_list_moderate
469 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
470 $liste, $domain, $mid, S::i('uid'), $action, Post::v('reason'));
471 }
472
473 function handler_moderate($page, $liste = null)
474 {
475 if (is_null($liste)) {
476 return PL_NOT_FOUND;
477 }
478
479 $domain = $this->prepare_client($page);
480
481 $page->changeTpl('lists/moderate.tpl');
482
483 $page->register_modifier('hdc', 'list_header_decode');
484
485 if (Env::has('sadd') || Env::has('sdel')) {
486 S::assert_xsrf_token();
487
488 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
489 $sub = $this->client->get_pending_sub($liste, Env::v('sadd'));
490 $this->client->handle_request($liste,Env::v('sadd'),4,'');
491 $info = "validée";
492 }
493 if (Post::has('sdel')) { /* 2 = REJECT */
494 $sub = $this->client->get_pending_sub($liste, Env::v('sdel'));
495 $this->client->handle_request($liste, Post::v('sdel'), 2, utf8_decode(Post::v('reason')));
496 $info = "refusée";
497 }
498 if ($sub) {
499 $mailer = new PlMailer();
500 $mailer->setFrom("$liste-bounces@{$domain}");
501 $mailer->addTo("$liste-owner@{$domain}");
502 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
503 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
504 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::user()->fullName(true) . ".\n";
505 if (trim(Post::v('reason'))) {
506 $text .= "\nLa raison invoquée est :\n" . Post::v('reason');
507 }
508 $mailer->setTxtBody(wordwrap($text, 72));
509 $mailer->send();
510 }
511 if (Env::has('sadd')) {
512 pl_redirect('lists/moderate/'.$liste);
513 }
514 }
515
516 if (Post::has('moderate_mails') && Post::has('select_mails')) {
517 S::assert_xsrf_token();
518
519 $mails = array_keys(Post::v('select_mails'));
520 foreach($mails as $mail) {
521 $this->moderate_mail($domain, $liste, $mail);
522 }
523 } elseif (Env::has('mid')) {
524 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
525 require_once 'banana/moderate.inc.php';
526
527 $page->changeTpl('lists/moderate_mail.tpl');
528 $params = array('listname' => $liste, 'domain' => $domain,
529 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
530 $params['client'] = $this->client;
531 run_banana($page, 'ModerationBanana', $params);
532
533 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
534 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
535 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
536 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
537 $msg = str_replace("%(listname)s", $liste, $msg);
538 $page->assign('msg', $msg);
539 return;
540 }
541
542 $this->moderate_mail($domain, $liste, Env::i('mid'));
543 } elseif (Env::has('sid')) {
544 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
545 foreach($subs as $user) {
546 if ($user['id'] == Env::v('sid')) {
547 $page->changeTpl('lists/moderate_sub.tpl');
548 $page->assign('del_user', $user);
549 return;
550 }
551 }
552 }
553
554 }
555
556 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
557 foreach ($mails as $key=>$mail) {
558 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
559 if ($mail['fromx']) {
560 $page->assign('with_fromx', true);
561 } else {
562 $page->assign('with_nonfromx', true);
563 }
564 }
565 $page->assign_by_ref('subs', $subs);
566 $page->assign_by_ref('mails', $mails);
567 } else {
568 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer.");
569 }
570 }
571
572 static public function no_login_callback($login)
573 {
574 global $list_unregistered, $globals;
575
576 $users = User::getPendingAccounts($login, true);
577 if ($users && $users->total()) {
578 if (!isset($list_unregistered)) {
579 $list_unregistered = array();
580 }
581 $list_unregistered[$login] = $users;
582 } else {
583 list($name, $dom) = @explode('@', $login);
584 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
585 User::_default_user_callback($login);
586 }
587 }
588 }
589
590 function handler_admin($page, $liste = null)
591 {
592 global $globals;
593
594 if (is_null($liste)) {
595 return PL_NOT_FOUND;
596 }
597
598 $domain = $this->prepare_client($page);
599
600 $page->changeTpl('lists/admin.tpl');
601
602 if (Env::has('send_mark')) {
603 S::assert_xsrf_token();
604
605 $actions = Env::v('mk_action');
606 $uids = Env::v('mk_uid');
607 $mails = Env::v('mk_email');
608 foreach ($actions as $key=>$action) {
609 switch ($action) {
610 case 'none':
611 break;
612
613 case 'marketu': case 'markets':
614 require_once 'emails.inc.php';
615 $mail = valide_email($mails[$key]);
616 if (isvalid_email_redirection($mail)) {
617 $from = ($action == 'marketu') ? 'user' : 'staff';
618 $market = Marketing::get($uids[$key], $mail);
619 if (!$market) {
620 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid'));
621 $market->add();
622 break;
623 }
624 }
625
626 default:
627 XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
628 VALUES ({?}, \'list\', {?}, {?})',
629 $uids[$key], $liste, $domain);
630 }
631 }
632 }
633
634 if (Env::has('add_member')) {
635 S::assert_xsrf_token();
636
637 $members = User::getBulkForlifeEmails(Env::v('add_member'),
638 true,
639 array('ListsModule', 'no_login_callback'));
640 $arr = $this->client->mass_subscribe($liste, $members);
641 if (is_array($arr)) {
642 foreach($arr as $addr) {
643 $page->trigSuccess("{$addr[0]} inscrit.");
644 }
645 }
646 }
647
648 if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) {
649 S::assert_xsrf_token();
650
651 $upload =& PlUpload::get($_FILES['add_member_file'], S::user()->login(), 'list.addmember', true);
652 if (!$upload) {
653 $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier');
654 } else {
655 $members = User::getBulkForlifeEmails($upload->getContents(),
656 true,
657 array('ListsModule', 'no_login_callback'));
658 $arr = $this->client->mass_subscribe($liste, $members);
659 if (is_array($arr)) {
660 foreach($arr as $addr) {
661 $page->trigSuccess("{$addr[0]} inscrit.");
662 }
663 }
664 }
665 }
666
667 if (Env::has('del_member')) {
668 S::assert_xsrf_token();
669
670 if (strpos(Env::v('del_member'), '@') === false) {
671 $this->client->mass_unsubscribe(
672 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
673 } else {
674 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
675 }
676 pl_redirect('lists/admin/'.$liste);
677 }
678
679 if (Env::has('add_owner')) {
680 S::assert_xsrf_token();
681
682 $owners = User::getBulkForlifeEmails(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback'));
683 if ($owners) {
684 foreach ($owners as $login) {
685 if ($this->client->add_owner($liste, $login)) {
686 $page->trigSuccess($login ." ajouté aux modérateurs.");
687 }
688 }
689 }
690 }
691
692 if (Env::has('del_owner')) {
693 S::assert_xsrf_token();
694
695 if (strpos(Env::v('del_owner'), '@') === false) {
696 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
697 } else {
698 $this->client->del_owner($liste, Env::v('del_owner'));
699 }
700 pl_redirect('lists/admin/'.$liste);
701 }
702
703 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
704 global $list_unregistered;
705 if ($list_unregistered) {
706 $page->assign_by_ref('unregistered', $list_unregistered);
707 }
708 $membres = list_sort_members($mem, @$tri_promo);
709 $moderos = list_sort_owners($own, @$tri_promo);
710
711 $page->assign_by_ref('details', $det);
712 $page->assign_by_ref('members', $membres);
713 $page->assign_by_ref('owners', $moderos);
714 $page->assign('np_m', count($mem));
715
716 } else {
717 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
718 . " Si tu penses qu'il s'agit d'une erreur, "
719 . "<a href='mailto:support@polytechnique.org'>contact le support</a>.");
720 }
721 }
722
723 function handler_options($page, $liste = null)
724 {
725 if (is_null($liste)) {
726 return PL_NOT_FOUND;
727 }
728
729 $this->prepare_client($page);
730
731 $page->changeTpl('lists/options.tpl');
732
733 if (Post::has('submit')) {
734 S::assert_xsrf_token();
735
736 $values = $_POST;
737 $values = array_map('utf8_decode', $values);
738 $spamlevel = intval($values['bogo_level']);
739 $unsurelevel = intval($values['unsure_level']);
740 if ($spamlevel == 0) {
741 $unsurelevel = 0;
742 }
743 if ($spamlevel > 3 || $spamlevel < 0 || $unsurelevel < 0 || $unsurelevel > 1) {
744 $page->trigError("Réglage de l'antispam non valide");
745 } else {
746 $this->client->set_bogo_level($liste, ($spamlevel << 1) + $unsurelevel);
747 }
748 switch($values['moderate']) {
749 case '0':
750 $values['generic_nonmember_action'] = 0;
751 $values['default_member_moderation'] = 0;
752 break;
753 case '1':
754 $values['generic_nonmember_action'] = 1;
755 $values['default_member_moderation'] = 0;
756 break;
757 case '2':
758 $values['generic_nonmember_action'] = 1;
759 $values['default_member_moderation'] = 1;
760 break;
761 }
762 unset($values['submit'], $values['bogo_level'], $values['moderate']);
763 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
764 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
765 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
766 if (isset($values['subject_prefix'])) {
767 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
768 }
769 $this->client->set_owner_options($liste, $values);
770 } elseif (isvalid_email(Post::v('atn_add'))) {
771 S::assert_xsrf_token();
772 $this->client->add_to_wl($liste, Post::v('atn_add'));
773 } elseif (Get::has('atn_del')) {
774 S::assert_xsrf_token();
775 $this->client->del_from_wl($liste, Get::v('atn_del'));
776 pl_redirect('lists/options/'.$liste);
777 }
778
779 if (list($details,$options) = $this->client->get_owner_options($liste)) {
780 $page->assign_by_ref('details', $details);
781 $page->assign_by_ref('options', $options);
782 $bogo_level = intval($this->client->get_bogo_level($liste));
783 $page->assign('unsure_level', $bogo_level & 1);
784 $page->assign('bogo_level', $bogo_level >> 1);
785 } else {
786 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
787 }
788 }
789
790 function handler_delete($page, $liste = null)
791 {
792 global $globals;
793 if (is_null($liste)) {
794 return PL_NOT_FOUND;
795 }
796
797 $domain = $this->prepare_client($page);
798 $page->changeTpl('lists/delete.tpl');
799 if (Post::v('valid') == 'OUI') {
800 S::assert_xsrf_token();
801
802 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
803 require_once 'emails.inc.php';
804
805 delete_list($liste, $domain);
806 $page->assign('deleted', true);
807 $page->trigSuccess('La liste a été détruite&nbsp;!');
808 } else {
809 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
810 . 'Contact les administrateurs du site pour régler le problème : '
811 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>.');
812 }
813 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
814 if (!$details['own']) {
815 $page->trigWarning('Tu n\'es pas administrateur de la liste, mais du site.');
816 }
817 $page->assign_by_ref('details', $details);
818 $page->assign_by_ref('options', $options);
819 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
820 } else {
821 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.");
822 }
823 }
824
825 function handler_soptions($page, $liste = null)
826 {
827 if (is_null($liste)) {
828 return PL_NOT_FOUND;
829 }
830
831 $this->prepare_client($page);
832
833 $page->changeTpl('lists/soptions.tpl');
834
835 if (Post::has('submit')) {
836 S::assert_xsrf_token();
837
838 $values = $_POST;
839 $values = array_map('utf8_decode', $values);
840 unset($values['submit']);
841 $values['advertised'] = empty($values['advertised']) ? false : true;
842 $values['archive'] = empty($values['archive']) ? false : true;
843 $this->client->set_admin_options($liste, $values);
844 }
845
846 if (list($details,$options) = $this->client->get_admin_options($liste)) {
847 $page->assign_by_ref('details', $details);
848 $page->assign_by_ref('options', $options);
849 } else {
850 $page->kill("La liste n'existe pas.");
851 }
852 }
853
854 function handler_check($page, $liste = null)
855 {
856 if (is_null($liste)) {
857 return PL_NOT_FOUND;
858 }
859
860 $this->prepare_client($page);
861
862 $page->changeTpl('lists/check.tpl');
863
864 if (Post::has('correct')) {
865 S::assert_xsrf_token();
866 $this->client->check_options($liste, true);
867 }
868
869 if (list($details,$options) = $this->client->check_options($liste)) {
870 $page->assign_by_ref('details', $details);
871 $page->assign_by_ref('options', $options);
872 } else {
873 $page->kill("La liste n'existe pas.");
874 }
875 }
876
877 function handler_admin_all($page)
878 {
879 $page->changeTpl('lists/admin_all.tpl');
880 $page->setTitle('Administration - Mailing lists');
881
882 $this->prepare_client($page);
883 $listes = $this->client->get_all_lists();
884 $page->assign_by_ref('listes', $listes);
885 }
886 }
887
888 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
889 ?>