2 /***************************************************************************
3 * Copyright (C) 2003-2008 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_MDP
),
30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP
, 'user', NO_AUTH
),
31 'lists/create' => $this->make_hook('create', AUTH_MDP
),
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE
),
34 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE
),
35 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE
),
36 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC
, 'user', NO_HTTPS
),
38 'lists/moderate' => $this->make_hook('moderate', AUTH_MDP
),
39 'lists/admin' => $this->make_hook('admin', AUTH_MDP
),
40 'lists/options' => $this->make_hook('options', AUTH_MDP
),
41 'lists/delete' => $this->make_hook('delete', AUTH_MDP
),
43 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP
),
44 'lists/check' => $this->make_hook('check', AUTH_MDP
),
45 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP
, 'admin'),
49 function on_subscribe($forlife, $uid, $promo, $password)
51 $this->prepare_client(null
);
52 $this->client
->subscribe("promo$promo");
55 function prepare_client(&$page)
59 require_once dirname(__FILE__
).'/lists/lists.inc.php';
61 $this->client
= new MMList(S
::v('uid'), S
::v('password'));
62 return $globals->mail
->domain
;
65 function get_pending_ops($domain, $list)
67 list($subs,$mails) = $this->client
->get_pending_ops($list);
68 $res = XDB
::query("SELECT mid
70 WHERE ml = {?} AND domain = {?}",
72 $mids = $res->fetchColumn();
73 foreach ($mails as $key=>$mail) {
74 if (in_array($mail['id'], $mids)) {
78 return array($subs, $mails);
81 function handler_lists(&$page)
83 function filter_owner($list)
88 function filter_member($list)
93 $domain = $this->prepare_client($page);
95 $page->changeTpl('lists/index.tpl');
96 $page->addJsLink('ajax.js');
97 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
100 if (Get
::has('del')) {
101 $this->client
->unsubscribe(Get
::v('del'));
102 pl_redirect('lists');
104 if (Get
::has('add')) {
105 $this->client
->subscribe(Get
::v('add'));
106 pl_redirect('lists');
108 if (Post
::has('promo_add')) {
109 $promo = Post
::i('promo_add');
110 if ($promo >= 1900 and $promo < 2100) {
111 $this->client
->subscribe("promo$promo");
113 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
116 $listes = $this->client
->get_lists();
117 $owner = array_filter($listes, 'filter_owner');
118 $listes = array_diff_key($listes, $owner);
119 $member = array_filter($listes, 'filter_member');
120 $listes = array_diff_key($listes, $member);
121 foreach ($owner as $key=>$liste) {
122 list($subs,$mails) = $this->get_pending_ops($domain, $liste['list']);
123 $owner[$key]['subscriptions'] = $subs;
124 $owner[$key]['mails'] = $mails;
126 $page->register_modifier('hdc', 'list_header_decode');
127 $page->assign_by_ref('owner', $owner);
128 $page->assign_by_ref('member', $member);
129 $page->assign_by_ref('public', $listes);
132 function handler_ajax(&$page, $list = null
)
134 header('Content-Type: text/html; charset="UTF-8"');
135 $domain = $this->prepare_client($page);
136 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN
);
137 if (Get
::has('unsubscribe')) {
138 $this->client
->unsubscribe($list);
140 if (Get
::has('subscribe')) {
141 $this->client
->subscribe($list);
143 if (Get
::has('sadd')) { /* 4 = SUBSCRIBE */
144 $this->client
->handle_request($list, Get
::v('sadd'), 4, '');
146 if (Get
::has('mid')) {
147 $this->moderate_mail($domain, $list, Get
::i('mid'));
150 list($liste, $members, $owners) = $this->client
->get_members($list);
152 list($subs,$mails) = $this->get_pending_ops($domain, $list);
153 $liste['subscriptions'] = $subs;
154 $liste['mails'] = $mails;
156 $page->register_modifier('hdc', 'list_header_decode');
157 $page->assign_by_ref('liste', $liste);
160 function handler_create(&$page)
162 $page->changeTpl('lists/create.tpl');
164 $owners = preg_split("/[\s]+/", Post
::v('owners'), -1, PREG_SPLIT_NO_EMPTY
);
165 $members = preg_split("/[\s]+/", Post
::v('members'), -1, PREG_SPLIT_NO_EMPTY
);
167 // click on validate button 'add_owner_sub' or type <enter>
168 if (Post
::has('add_owner_sub') && Post
::has('add_owner')) {
169 require_once('user.func.inc.php');
170 // if we want to add an owner and then type <enter>, then both
171 // add_owner_sub and add_owner are filled.
172 $oforlifes = get_users_forlife_list(Post
::v('add_owner'), true
);
173 $mforlifes = get_users_forlife_list(Post
::v('add_member'), true
);
174 if (!is_null($oforlifes)) {
175 $owners = array_merge($owners, $oforlifes);
177 // if we want to add a member and then type <enter>, then
178 // add_owner_sub is filled, whereas add_owner is empty.
179 if (!is_null($mforlifes)) {
180 $members = array_merge($members, $mforlifes);
184 // click on validate button 'add_member_sub'
185 if (Post
::has('add_member_sub') && Post
::has('add_member')) {
186 require_once('user.func.inc.php');
187 $forlifes = get_users_forlife_list(Post
::v('add_member'), true
);
188 if (!is_null($forlifes)) {
189 $members = array_merge($members, $forlifes);
194 $owners = array_unique($owners);
196 $members = array_unique($members);
198 $page->assign('owners', join(' ', $owners));
199 $page->assign('members', join(' ', $members));
201 if (!Post
::has('submit')) {
205 $liste = Post
::v('liste');
208 $page->trig('champs «addresse souhaitée» vide');
210 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
211 $page->trig('le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets');
214 $res = XDB
::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
215 $n = $res->fetchOneCell();
218 $page->trig('cet alias est déjà pris');
221 if (!Post
::v('desc')) {
222 $page->trig('le sujet est vide');
225 if (!count($owners)) {
226 $page->trig('pas de gestionnaire');
229 if (count($members)<4) {
230 $page->trig('pas assez de membres');
233 if (!$page->nb_errs()) {
234 $page->assign('created', true
);
235 require_once 'validations.inc.php';
236 $req = new ListeReq(S
::v('uid'), $liste,
237 Post
::v('desc'), Post
::i('advertise'),
238 Post
::i('modlevel'), Post
::i('inslevel'),
244 function handler_members(&$page, $liste = null
)
246 if (is_null($liste)) {
250 $this->prepare_client($page);
252 $page->changeTpl('lists/members.tpl');
254 if (Get
::has('del')) {
255 $this->client
->unsubscribe($liste);
256 pl_redirect('lists/members/'.$liste);
259 if (Get
::has('add')) {
260 $this->client
->subscribe($liste);
261 pl_redirect('lists/members/'.$liste);
264 $members = $this->client
->get_members($liste);
266 $tri_promo = !Env
::b('alpha');
268 if (list($det,$mem,$own) = $members) {
269 $membres = list_sort_members($mem, $tri_promo);
270 $moderos = list_sort_owners($own, $tri_promo);
272 $page->assign_by_ref('details', $det);
273 $page->assign_by_ref('members', $membres);
274 $page->assign_by_ref('owners', $moderos);
275 $page->assign('nb_m', count($mem));
277 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
281 function handler_annu(&$page, $liste = null
, $action = null
, $subaction = null
)
283 if (is_null($liste)) {
287 $this->prepare_client($page);
289 if (Get
::has('del')) {
290 $this->client
->unsubscribe($liste);
291 pl_redirect('lists/annu/'.$liste);
293 if (Get
::has('add')) {
294 $this->client
->subscribe($liste);
295 pl_redirect('lists/annu/'.$liste);
298 $owners = $this->client
->get_owners($liste);
299 if (!is_array($owners)) {
300 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
304 list(,$members) = $this->client
->get_members($liste);
306 foreach ($members as $m) {
309 require_once 'userset.inc.php';
310 $view = new ArraySet($users);
311 $view->addMod('trombi', 'Trombinoscope', true
, array('with_promo' => true
));
312 if (empty($GLOBALS['IS_XNET_SITE'])) {
313 $view->addMod('minifiche', 'Minifiches', false
);
315 $view->addMod('geoloc', 'Planisphère');
316 $view->apply("lists/annu/$liste", $page, $action, $subaction);
317 if ($action == 'geoloc' && $subaction) {
321 $page->changeTpl('lists/annu.tpl');
322 $moderos = list_sort_owners($owners[1]);
323 $page->assign_by_ref('details', $owners[0]);
324 $page->assign_by_ref('owners', $moderos);
327 function handler_archives(&$page, $liste = null
, $action = null
, $artid = null
)
331 if (is_null($liste)) {
335 $domain = $this->prepare_client($page);
337 $page->changeTpl('lists/archives.tpl');
339 if (list($det) = $this->client
->get_members($liste)) {
340 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
341 && !$det['own'] && ($det['sub'] < 2)) {
342 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
344 $get = Array('listname' => $liste, 'domain' => $domain);
345 if (Post
::has('updateall')) {
346 $get['updateall'] = Post
::v('updateall');
348 require_once 'banana/ml.inc.php';
349 get_banana_params($get, null
, $action, $artid);
350 run_banana($page, 'MLBanana', $get);
352 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
356 function handler_rss(&$page, $liste = null
, $alias = null
, $hash = null
)
358 require_once('rss.inc.php');
359 $uid = init_rss(null
, $alias, $hash);
360 if (!$uid ||
!$liste) {
364 $res = XDB
::query("SELECT user_id AS uid, password, alias AS forlife
365 FROM auth_user_md5 AS u
366 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
367 WHERE u.user_id = {?}", $uid);
368 $row = $res->fetchOneAssoc();
369 $_SESSION = array_merge($row, $_SESSION);
371 $domain = $this->prepare_client($page);
372 if (list($det) = $this->client
->get_members($liste)) {
373 if (substr($liste,0,5) != 'promo' && ($det['ins'] ||
$det['priv'])
374 && !$det['own'] && ($det['sub'] < 2)) {
377 require_once('banana/ml.inc.php');
378 $banana = new MLBanana(S
::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
384 function moderate_mail($domain, $liste, $mid)
386 if (Env
::has('mok')) {
388 } elseif (Env
::has('mno')) {
390 } elseif (Env
::has('mdel')) {
396 return XDB
::execute("INSERT IGNORE INTO ml_moderate
397 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
398 $liste, $domain, $mid, S
::i('uid'), $action, Post
::v('reason'));
401 function handler_moderate(&$page, $liste = null
)
403 if (is_null($liste)) {
407 $domain = $this->prepare_client($page);
409 $page->changeTpl('lists/moderate.tpl');
411 $page->register_modifier('hdc', 'list_header_decode');
413 if (Env
::has('sadd') || Env
::has('sdel')) {
414 if (Env
::has('sadd')) { /* 4 = SUBSCRIBE */
415 $sub = $this->client
->get_pending_sub($liste, Env
::v('sadd'));
416 $this->client
->handle_request($liste,Env
::v('sadd'),4,'');
419 if (Post
::has('sdel')) { /* 2 = REJECT */
420 $sub = $this->client
->get_pending_sub($liste, Env
::v('sdel'));
421 $this->client
->handle_request($liste, Post
::v('sdel'), 2, Post
::v('reason'));
425 $mailer = new PlMailer();
426 $mailer->setFrom("$liste-bounces@{$domain}");
427 $mailer->addTo("$liste-owner@{$domain}");
428 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
429 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
430 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S
::v('prenom') . ' '
431 . S
::v('nom') . '(' . S
::v('promo') . ")\n";
432 if (trim(Post
::v('reason'))) {
433 $text .= "\nLa raison invoquée est :\n" . Post
::v('reason');
435 $mailer->setTxtBody(wordwrap($text, 72));
438 if (Env
::has('sadd')) {
439 pl_redirect('lists/moderate/'.$liste);
443 if (Post
::has('moderate_mails') && Post
::has('select_mails')) {
444 $mails = array_keys(Post
::v('select_mails'));
445 foreach($mails as $mail) {
446 $this->moderate_mail($domain, $liste, $mail);
448 } elseif (Env
::has('mid')) {
449 if (Get
::has('mid') && !Env
::has('mok') && !Env
::has('mdel')) {
450 $page->changeTpl('lists/moderate_mail.tpl');
451 require_once('banana/moderate.inc.php');
452 $params = array('listname' => $liste, 'domain' => $domain,
453 'artid' => Get
::i('mid'), 'part' => Get
::v('part'), 'action' => Get
::v('action'));
454 $params['client'] = $this->client
;
455 run_banana($page, 'ModerationBanana', $params);
457 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
458 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
459 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
460 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
461 $msg = str_replace("%(listname)s", $liste, $msg);
462 $page->assign('msg', $msg);
466 $mail = $this->moderate_mail($domain, $liste, Env
::i('mid'));
467 } elseif (Env
::has('sid')) {
468 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
469 foreach($subs as $user) {
470 if ($user['id'] == Env
::v('sid')) {
471 $page->changeTpl('lists/moderate_sub.tpl');
472 $page->assign('del_user', $user);
480 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
481 foreach ($mails as $key=>$mail) {
482 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
484 $page->assign_by_ref('subs', $subs);
485 $page->assign_by_ref('mails', $mails);
487 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
491 static public function no_login_callback($login)
493 require_once 'user.func.inc.php';
494 global $list_unregistered;
496 $users = get_not_registered_user($login, true
);
497 if ($users && $users->total()) {
498 if (!isset($list_unregistered)) {
499 $list_unregistered = array();
501 $list_unregistered[$login] = $users;
503 _default_user_callback($login);
507 function handler_admin(&$page, $liste = null
)
511 if (is_null($liste)) {
515 $domain = $this->prepare_client($page);
517 $page->changeTpl('lists/admin.tpl');
519 if (Env
::has('send_mark')) {
520 $actions = Env
::v('mk_action');
521 $uids = Env
::v('mk_uid');
522 $mails = Env
::v('mk_email');
523 foreach ($actions as $key=>$action) {
528 case 'marketu': case 'markets':
529 require_once 'emails.inc.php';
530 $mail = valide_email($mails[$key]);
531 if (isvalid_email_redirection($mail)) {
532 $from = ($action == 'marketu') ?
'user' : 'staff';
533 $market = Marketing
::get($uids[$key], $mail);
535 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S
::v('uid'));
542 XDB
::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
543 VALUES ({?}, \'list\', {?}, {?})',
544 $uids[$key], $liste, $domain);
549 if (Env
::has('add_member')) {
550 require_once('user.func.inc.php');
551 $members = get_users_forlife_list(Env
::v('add_member'), false
, array('ListsModule', 'no_login_callback'));
552 $arr = $this->client
->mass_subscribe($liste, $members);
553 if (is_array($arr)) {
554 foreach($arr as $addr) {
555 $page->trig("{$addr[0]} inscrit.");
560 if (Env
::has('del_member')) {
561 if (strpos(Env
::v('del_member'), '@') === false
) {
562 $this->client
->mass_unsubscribe(
563 $liste, array(Env
::v('del_member').'@'.$globals->mail
->domain
));
565 $this->client
->mass_unsubscribe($liste, array(Env
::v('del_member')));
567 pl_redirect('lists/admin/'.$liste);
570 if (Env
::has('add_owner')) {
571 require_once('user.func.inc.php');
572 $owners = get_users_forlife_list(Env
::v('add_owner'), false
, array('ListsModule', 'no_login_callback'));
574 foreach ($owners as $login) {
575 if ($this->client
->add_owner($liste, $login)) {
576 $page->trig($alias." ajouté aux modérateurs.");
582 if (Env
::has('del_owner')) {
583 if (strpos(Env
::v('del_owner'), '@') === false
) {
584 $this->client
->del_owner($liste, Env
::v('del_owner').'@'.$globals->mail
->domain
);
586 $this->client
->del_owner($liste, Env
::v('del_owner'));
588 pl_redirect('lists/admin/'.$liste);
591 if (list($det,$mem,$own) = $this->client
->get_members($liste)) {
592 global $list_unregistered;
593 if ($list_unregistered) {
594 $page->assign_by_ref('unregistered', $list_unregistered);
596 $membres = list_sort_members($mem, @$tri_promo);
597 $moderos = list_sort_owners($own, @$tri_promo);
599 $page->assign_by_ref('details', $det);
600 $page->assign_by_ref('members', $membres);
601 $page->assign_by_ref('owners', $moderos);
602 $page->assign('np_m', count($mem));
605 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
606 ." Si tu penses qu'il s'agit d'une erreur, "
607 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
611 function handler_options(&$page, $liste = null
)
613 if (is_null($liste)) {
617 $this->prepare_client($page);
619 $page->changeTpl('lists/options.tpl');
621 if (Post
::has('submit')) {
623 $values = array_map('utf8_decode', $values);
624 $this->client
->set_bogo_level($liste, intval($values['bogo_level']));
625 switch($values['moderate']) {
627 $values['generic_nonmember_action'] = 0;
628 $values['default_member_moderation'] = 0;
631 $values['generic_nonmember_action'] = 1;
632 $values['default_member_moderation'] = 0;
635 $values['generic_nonmember_action'] = 1;
636 $values['default_member_moderation'] = 1;
639 unset($values['submit'], $values['bogo_level'], $values['moderate']);
640 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
641 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
642 $values['subscribe_policy'] = empty($values['subscribe_policy']) ?
0 : 2;
643 if (isset($values['subject_prefix'])) {
644 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
646 $this->client
->set_owner_options($liste, $values);
647 } elseif (isvalid_email(Post
::v('atn_add'))) {
648 $this->client
->add_to_wl($liste, Post
::v('atn_add'));
649 } elseif (Get
::has('atn_del')) {
650 $this->client
->del_from_wl($liste, Get
::v('atn_del'));
651 pl_redirect('lists/options/'.$liste);
654 if (list($details,$options) = $this->client
->get_owner_options($liste)) {
655 $page->assign_by_ref('details', $details);
656 $page->assign_by_ref('options', $options);
657 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
659 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
663 function handler_delete(&$page, $liste = null
)
666 if (is_null($liste)) {
670 $domain = $this->prepare_client($page);
671 if ($domain == $globals->mail
->domain ||
$domain == $globals->mail
->domain2
) {
676 $domain = '@' . $domain;
681 $page->changeTpl('lists/delete.tpl');
682 if (Post
::v('valid') == 'OUI') {
683 if ($this->client
->delete_list($liste, Post
::b('del_archive'))) {
684 foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) {
685 XDB
::execute("DELETE FROM $table
686 WHERE type={?} AND alias={?}",
687 $type, $liste.$app.$domain);
689 $page->assign('deleted', true
);
691 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
692 . 'Contact les administrateurs du site pour régler le problème : '
693 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
695 } elseif (list($details,$options) = $this->client
->get_owner_options($liste)) {
696 $page->assign_by_ref('details', $details);
697 $page->assign_by_ref('options', $options);
698 $page->assign('bogo_level', $this->client
->get_bogo_level($liste));
700 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
704 function handler_soptions(&$page, $liste = null
)
706 if (is_null($liste)) {
710 $this->prepare_client($page);
712 $page->changeTpl('lists/soptions.tpl');
714 if (Post
::has('submit')) {
716 $values = array_map('utf8_decode', $values);
717 unset($values['submit']);
718 $values['advertised'] = empty($values['advertised']) ? false
: true
;
719 $values['archive'] = empty($values['archive']) ? false
: true
;
720 $this->client
->set_admin_options($liste, $values);
723 if (list($details,$options) = $this->client
->get_admin_options($liste)) {
724 $page->assign_by_ref('details', $details);
725 $page->assign_by_ref('options', $options);
727 $page->kill("La liste n'existe pas");
731 function handler_check(&$page, $liste = null
)
733 if (is_null($liste)) {
737 $this->prepare_client($page);
739 $page->changeTpl('lists/check.tpl');
741 if (Post
::has('correct')) {
742 $this->client
->check_options($liste, true
);
745 if (list($details,$options) = $this->client
->check_options($liste)) {
746 $page->assign_by_ref('details', $details);
747 $page->assign_by_ref('options', $options);
749 $page->kill("La liste n'existe pas");
753 function handler_admin_all(&$page) {
754 $page->changeTpl('lists/admin_all.tpl');
755 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
757 $client = new MMList(S
::v('uid'), S
::v('password'));
758 $listes = $client->get_all_lists();
759 $page->assign_by_ref('listes', $listes);
763 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: