Automation of the management of associations' mailing lists (Closes #817), Updates...
[platal.git] / modules / lists.php
CommitLineData
bc4ad6aa 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
bc4ad6aa 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
22class ListsModule extends PLModule
23{
0baf0741 24 protected $client;
bc4ad6aa 25
26 function handlers()
27 {
28 return array(
29 'lists' => $this->make_hook('lists', AUTH_MDP),
9ed396c0 30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, 'user', NO_AUTH),
bc4ad6aa 31 'lists/create' => $this->make_hook('create', AUTH_MDP),
32
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE),
1cc0afe7 34 'lists/annu' => $this->make_hook('annu', AUTH_COOKIE),
bc4ad6aa 35 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE),
8fc4efa3 36 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS),
bc4ad6aa 37
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),
42
43 'lists/soptions' => $this->make_hook('soptions', AUTH_MDP),
44 'lists/check' => $this->make_hook('check', AUTH_MDP),
9ed396c0 45 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'),
bc4ad6aa 46 );
47 }
48
8d8f7607 49 function on_subscribe($forlife, $uid, $promo, $password)
50 {
51 $this->prepare_client(null);
52 $this->client->subscribe("promo$promo");
53 }
54
7b9d64a8 55 function prepare_client(&$page)
bc4ad6aa 56 {
0ec52d96 57 global $globals;
58
9bb8bf21 59 require_once dirname(__FILE__).'/lists/lists.inc.php';
bc4ad6aa 60
9bb8bf21 61 $this->client = new MMList(S::v('uid'), S::v('password'));
092945b4 62 return $globals->mail->domain;
bc4ad6aa 63 }
64
834fd0f6 65 function get_pending_ops($domain, $list)
66 {
67 list($subs,$mails) = $this->client->get_pending_ops($list);
68 $res = XDB::query("SELECT mid
69 FROM ml_moderate
70 WHERE ml = {?} AND domain = {?}",
71 $list, $domain);
72 $mids = $res->fetchColumn();
73 foreach ($mails as $key=>$mail) {
74 if (in_array($mail['id'], $mids)) {
75 unset($mails[$key]);
76 }
77 }
78 return array($subs, $mails);
79 }
80
bc4ad6aa 81 function handler_lists(&$page)
82 {
50c655ee 83 function filter_owner($list)
84 {
85 return $list['own'];
86 }
87
88 function filter_member($list)
89 {
da398501 90 return $list['sub'];
50c655ee 91 }
92
834fd0f6 93 $domain = $this->prepare_client($page);
bc4ad6aa 94
edc4367b 95 $page->changeTpl('lists/index.tpl');
50c655ee 96 $page->addJsLink('ajax.js');
bc4ad6aa 97 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
98
99
100 if (Get::has('del')) {
5e2307dc 101 $this->client->unsubscribe(Get::v('del'));
8b00e0e0 102 pl_redirect('lists');
bc4ad6aa 103 }
104 if (Get::has('add')) {
5e2307dc 105 $this->client->subscribe(Get::v('add'));
8b00e0e0 106 pl_redirect('lists');
bc4ad6aa 107 }
108 if (Post::has('promo_add')) {
5e2307dc 109 $promo = Post::i('promo_add');
bc4ad6aa 110 if ($promo >= 1900 and $promo < 2100) {
111 $this->client->subscribe("promo$promo");
112 } else {
a7d35093 113 $page->trigSuccess("promo incorrecte, il faut une promo sur 4 chiffres.");
bc4ad6aa 114 }
115 }
116 $listes = $this->client->get_lists();
50c655ee 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) {
834fd0f6 122 list($subs,$mails) = $this->get_pending_ops($domain, $liste['list']);
50c655ee 123 $owner[$key]['subscriptions'] = $subs;
124 $owner[$key]['mails'] = $mails;
125 }
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);
130 }
131
132 function handler_ajax(&$page, $list = null)
133 {
493b6abe 134 header('Content-Type: text/html; charset="UTF-8"');
5cbb1fad 135 $domain = $this->prepare_client($page);
edc4367b 136 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
50c655ee 137 if (Get::has('unsubscribe')) {
138 $this->client->unsubscribe($list);
139 }
140 if (Get::has('subscribe')) {
141 $this->client->subscribe($list);
142 }
143 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
144 $this->client->handle_request($list, Get::v('sadd'), 4, '');
145 }
146 if (Get::has('mid')) {
5cbb1fad 147 $this->moderate_mail($domain, $list, Get::i('mid'));
50c655ee 148 }
149
150 list($liste, $members, $owners) = $this->client->get_members($list);
151 if ($liste['own']) {
834fd0f6 152 list($subs,$mails) = $this->get_pending_ops($domain, $list);
50c655ee 153 $liste['subscriptions'] = $subs;
154 $liste['mails'] = $mails;
155 }
156 $page->register_modifier('hdc', 'list_header_decode');
157 $page->assign_by_ref('liste', $liste);
bc4ad6aa 158 }
159
160 function handler_create(&$page)
161 {
edc4367b 162 $page->changeTpl('lists/create.tpl');
bc4ad6aa 163
5e2307dc 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);
bc4ad6aa 166
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.
e7545178 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);
176 }
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);
bc4ad6aa 181 }
182 }
183
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');
e7545178 187 $forlifes = get_users_forlife_list(Post::v('add_member'), true);
188 if (!is_null($forlifes)) {
189 $members = array_merge($members, $forlifes);
bc4ad6aa 190 }
191 }
192
e7545178 193 ksort($owners);
194 $owners = array_unique($owners);
195 ksort($members);
196 $members = array_unique($members);
bc4ad6aa 197
198 $page->assign('owners', join(' ', $owners));
199 $page->assign('members', join(' ', $members));
200
201 if (!Post::has('submit')) {
202 return;
203 }
204
59887c4a 205 $asso = Post::v('asso');
5e2307dc 206 $liste = Post::v('liste');
bc4ad6aa 207
208 if (empty($liste)) {
59887c4a 209 $page->trigError('Le champ «adresse souhaitée» est vide.');
bc4ad6aa 210 }
211 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
59887c4a 212 $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.');
bc4ad6aa 213 }
214
59887c4a
SJ
215 if (($asso == "binet") || ($asso == "alias")) {
216 $promo = Post::i('promo');
217 $domain = $promo . '.polytechnique.org';
218
219 if (($promo < 1921) || ($promo > date('Y'))) {
220 $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.');
221 }
222
223 $new = $liste . '@' . $domain;
224 $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
225
226 } else {
227 if ($asso == "groupex") {
228 $groupex_name = Post::v('groupex_name');
229
230 $res_groupe = XDB::query('SELECT mail_domain FROM groupex.asso WHERE nom={?}', $groupex_name);
231 $domain = $res_groupe->fetchOneCell();
232
233 if (!$domain) {
234 $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.');
235 }
236
237 $new = $liste . '@' . $domain;
238 $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new);
239 } else {
240 $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
241 $domain = "polytechnique.org";
242 }
243 }
244
245 $n = $res->fetchOneCell();
bc4ad6aa 246
247 if ($n) {
59887c4a 248 $page->trigError('Cette «adresse souhaitée» est déjà prise.');
bc4ad6aa 249 }
250
92144f3e 251 if (!Post::v('desc')) {
59887c4a 252 $page->trigError('Le sujet est vide.');
bc4ad6aa 253 }
254
255 if (!count($owners)) {
59887c4a 256 $page->trigError('Il n\'y a pas de gestionnaire.');
bc4ad6aa 257 }
258
259 if (count($members)<4) {
59887c4a 260 $page->trigError('Il n\'y a pas assez de membres.');
bc4ad6aa 261 }
262
263 if (!$page->nb_errs()) {
264 $page->assign('created', true);
265 require_once 'validations.inc.php';
59887c4a 266 $req = new ListeReq(S::v('uid'), $asso, $liste, $domain,
5e2307dc 267 Post::v('desc'), Post::i('advertise'),
268 Post::i('modlevel'), Post::i('inslevel'),
bc4ad6aa 269 $owners, $members);
270 $req->submit();
271 }
272 }
273
274 function handler_members(&$page, $liste = null)
275 {
bc4ad6aa 276 if (is_null($liste)) {
277 return PL_NOT_FOUND;
278 }
279
7b9d64a8 280 $this->prepare_client($page);
bc4ad6aa 281
1490093c 282 $page->changeTpl('lists/members.tpl');
bc4ad6aa 283
284 if (Get::has('del')) {
285 $this->client->unsubscribe($liste);
8b00e0e0 286 pl_redirect('lists/members/'.$liste);
bc4ad6aa 287 }
288
289 if (Get::has('add')) {
290 $this->client->subscribe($liste);
8b00e0e0 291 pl_redirect('lists/members/'.$liste);
bc4ad6aa 292 }
293
294 $members = $this->client->get_members($liste);
295
5e2307dc 296 $tri_promo = !Env::b('alpha');
bc4ad6aa 297
298 if (list($det,$mem,$own) = $members) {
299 $membres = list_sort_members($mem, $tri_promo);
300 $moderos = list_sort_owners($own, $tri_promo);
301
302 $page->assign_by_ref('details', $det);
303 $page->assign_by_ref('members', $membres);
304 $page->assign_by_ref('owners', $moderos);
305 $page->assign('nb_m', count($mem));
306 } else {
a7de4ef7 307 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 308 }
309 }
310
1cc0afe7 311 function handler_annu(&$page, $liste = null, $action = null, $subaction = null)
bc4ad6aa 312 {
bc4ad6aa 313 if (is_null($liste)) {
314 return PL_NOT_FOUND;
315 }
316
7b9d64a8 317 $this->prepare_client($page);
bc4ad6aa 318
bc4ad6aa 319 if (Get::has('del')) {
320 $this->client->unsubscribe($liste);
1cc0afe7 321 pl_redirect('lists/annu/'.$liste);
bc4ad6aa 322 }
323 if (Get::has('add')) {
324 $this->client->subscribe($liste);
1cc0afe7 325 pl_redirect('lists/annu/'.$liste);
bc4ad6aa 326 }
327
328 $owners = $this->client->get_owners($liste);
1cc0afe7 329 if (!is_array($owners)) {
a7de4ef7 330 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 331 }
1cc0afe7 332
333 global $platal;
334 list(,$members) = $this->client->get_members($liste);
335 $users = array();
336 foreach ($members as $m) {
337 $users[] = $m[1];
338 }
339 require_once 'userset.inc.php';
340 $view = new ArraySet($users);
341 $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true));
342 if (empty($GLOBALS['IS_XNET_SITE'])) {
343 $view->addMod('minifiche', 'Minifiches', false);
344 }
345 $view->addMod('geoloc', 'Planisphère');
346 $view->apply("lists/annu/$liste", $page, $action, $subaction);
347 if ($action == 'geoloc' && $subaction) {
348 return;
349 }
350
351 $page->changeTpl('lists/annu.tpl');
352 $moderos = list_sort_owners($owners[1]);
353 $page->assign_by_ref('details', $owners[0]);
354 $page->assign_by_ref('owners', $moderos);
bc4ad6aa 355 }
356
fa7d6c7b 357 function handler_archives(&$page, $liste = null, $action = null, $artid = null)
bc4ad6aa 358 {
359 global $globals;
360
361 if (is_null($liste)) {
362 return PL_NOT_FOUND;
363 }
364
092945b4 365 $domain = $this->prepare_client($page);
bc4ad6aa 366
1490093c 367 $page->changeTpl('lists/archives.tpl');
bc4ad6aa 368
bc4ad6aa 369 if (list($det) = $this->client->get_members($liste)) {
370 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
fa7d6c7b 371 && !$det['own'] && ($det['sub'] < 2)) {
38421eaa 372 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
fa7d6c7b 373 }
374 $get = Array('listname' => $liste, 'domain' => $domain);
375 if (Post::has('updateall')) {
376 $get['updateall'] = Post::v('updateall');
377 }
4f355064 378 require_once 'banana/ml.inc.php';
379 get_banana_params($get, null, $action, $artid);
380 run_banana($page, 'MLBanana', $get);
bc4ad6aa 381 } else {
38421eaa 382 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter.");
bc4ad6aa 383 }
384 }
385
6544d0e1 386 function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
387 {
388 require_once('rss.inc.php');
389 $uid = init_rss(null, $alias, $hash);
390 if (!$uid || !$liste) {
391 exit;
392 }
393
394 $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
395 FROM auth_user_md5 AS u
396 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
397 WHERE u.user_id = {?}", $uid);
398 $row = $res->fetchOneAssoc();
399 $_SESSION = array_merge($row, $_SESSION);
400
401 $domain = $this->prepare_client($page);
402 if (list($det) = $this->client->get_members($liste)) {
403 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
404 && !$det['own'] && ($det['sub'] < 2)) {
eaf30d86 405 exit;
6544d0e1 406 }
407 require_once('banana/ml.inc.php');
b2bffbe6 408 $banana = new MLBanana(S::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
4f355064 409 $banana->run();
6544d0e1 410 }
411 exit;
412 }
413
5cbb1fad 414 function moderate_mail($domain, $liste, $mid)
50c655ee 415 {
50c655ee 416 if (Env::has('mok')) {
834fd0f6 417 $action = 'accept';
50c655ee 418 } elseif (Env::has('mno')) {
834fd0f6 419 $action = 'refuse';
50c655ee 420 } elseif (Env::has('mdel')) {
834fd0f6 421 $action = 'delete';
422 } else {
423 return false;
424 }
425 Get::kill('mid');
426 return XDB::execute("INSERT IGNORE INTO ml_moderate
427 VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)",
428 $liste, $domain, $mid, S::i('uid'), $action, Post::v('reason'));
50c655ee 429 }
430
bc4ad6aa 431 function handler_moderate(&$page, $liste = null)
432 {
bc4ad6aa 433 if (is_null($liste)) {
4b0d9ef3 434 return PL_NOT_FOUND;
bc4ad6aa 435 }
436
092945b4 437 $domain = $this->prepare_client($page);
bc4ad6aa 438
1490093c 439 $page->changeTpl('lists/moderate.tpl');
bc4ad6aa 440
c8529706 441 $page->register_modifier('hdc', 'list_header_decode');
bc4ad6aa 442
4b0d9ef3 443 if (Env::has('sadd') || Env::has('sdel')) {
444 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
445 $sub = $this->client->get_pending_sub($liste, Env::v('sadd'));
446 $this->client->handle_request($liste,Env::v('sadd'),4,'');
447 $info = "validée";
448 }
449 if (Post::has('sdel')) { /* 2 = REJECT */
450 $sub = $this->client->get_pending_sub($liste, Env::v('sdel'));
a5878ac1 451 $this->client->handle_request($liste, Post::v('sdel'), 2, utf8_decode(Post::v('reason')));
4b0d9ef3 452 $info = "refusée";
453 }
454 if ($sub) {
455 $mailer = new PlMailer();
456 $mailer->setFrom("$liste-bounces@{$domain}");
457 $mailer->addTo("$liste-owner@{$domain}");
458 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
459 $mailer->setSubject("L'inscription de {$sub['name']} a été $info");
460 $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::v('prenom') . ' '
461 . S::v('nom') . '(' . S::v('promo') . ")\n";
462 if (trim(Post::v('reason'))) {
463 $text .= "\nLa raison invoquée est :\n" . Post::v('reason');
464 }
465 $mailer->setTxtBody(wordwrap($text, 72));
466 $mailer->send();
467 }
468 if (Env::has('sadd')) {
469 pl_redirect('lists/moderate/'.$liste);
eaf30d86 470 }
bc4ad6aa 471 }
472
e940f534 473 if (Post::has('moderate_mails') && Post::has('select_mails')) {
474 $mails = array_keys(Post::v('select_mails'));
475 foreach($mails as $mail) {
476 $this->moderate_mail($domain, $liste, $mail);
477 }
478 } elseif (Env::has('mid')) {
d96379f6 479 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
4f355064 480 $page->changeTpl('lists/moderate_mail.tpl');
ed03d07f 481 require_once('banana/moderate.inc.php');
d96379f6 482 $params = array('listname' => $liste, 'domain' => $domain,
483 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
4f355064 484 $params['client'] = $this->client;
485 run_banana($page, 'ModerationBanana', $params);
bc4ad6aa 486
bc4ad6aa 487 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
488 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
489 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
490 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
491 $msg = str_replace("%(listname)s", $liste, $msg);
50c655ee 492 $page->assign('msg', $msg);
6a20c6a3 493 return;
ed03d07f 494 }
495
496 $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
bc4ad6aa 497 } elseif (Env::has('sid')) {
834fd0f6 498 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
bc4ad6aa 499 foreach($subs as $user) {
5e2307dc 500 if ($user['id'] == Env::v('sid')) {
1490093c 501 $page->changeTpl('lists/moderate_sub.tpl');
6a20c6a3 502 $page->assign('del_user', $user);
503 return;
bc4ad6aa 504 }
505 }
506 }
507
508 }
509
834fd0f6 510 if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) {
46ab179a 511 foreach ($mails as $key=>$mail) {
512 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
717b9fa7
FB
513 if ($mail['fromx']) {
514 $page->assign('with_fromx', true);
515 } else {
516 $page->assign('with_nonfromx', true);
517 }
46ab179a 518 }
bc4ad6aa 519 $page->assign_by_ref('subs', $subs);
520 $page->assign_by_ref('mails', $mails);
521 } else {
a7de4ef7 522 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
bc4ad6aa 523 }
524 }
525
0baf0741 526 static public function no_login_callback($login)
527 {
528 require_once 'user.func.inc.php';
be792642 529 global $list_unregistered, $globals;
0baf0741 530
531 $users = get_not_registered_user($login, true);
a58d8539 532 if ($users && $users->total()) {
0baf0741 533 if (!isset($list_unregistered)) {
534 $list_unregistered = array();
535 }
536 $list_unregistered[$login] = $users;
537 } else {
be792642
FB
538 list($name, $dom) = @explode('@', $login);
539 if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) {
540 _default_user_callback($login);
541 }
0baf0741 542 }
543 }
544
bc4ad6aa 545 function handler_admin(&$page, $liste = null)
546 {
547 global $globals;
548
549 if (is_null($liste)) {
550 return PL_NOT_FOUND;
551 }
552
0baf0741 553 $domain = $this->prepare_client($page);
bc4ad6aa 554
1490093c 555 $page->changeTpl('lists/admin.tpl');
bc4ad6aa 556
0baf0741 557 if (Env::has('send_mark')) {
558 $actions = Env::v('mk_action');
559 $uids = Env::v('mk_uid');
560 $mails = Env::v('mk_email');
561 foreach ($actions as $key=>$action) {
562 switch ($action) {
563 case 'none':
564 break;
565
566 case 'marketu': case 'markets':
567 require_once 'emails.inc.php';
568 $mail = valide_email($mails[$key]);
569 if (isvalid_email_redirection($mail)) {
570 $from = ($action == 'marketu') ? 'user' : 'staff';
571 $market = Marketing::get($uids[$key], $mail);
572 if (!$market) {
573 $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid'));
574 $market->add();
575 break;
576 }
577 }
578
579 default:
580 XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain)
581 VALUES ({?}, \'list\', {?}, {?})',
582 $uids[$key], $liste, $domain);
583 }
584 }
585 }
586
bc4ad6aa 587 if (Env::has('add_member')) {
bc4ad6aa 588 require_once('user.func.inc.php');
be792642
FB
589 $members = get_users_forlife_list(Env::v('add_member'),
590 false,
591 array('ListsModule', 'no_login_callback'));
bc4ad6aa 592 $arr = $this->client->mass_subscribe($liste, $members);
593 if (is_array($arr)) {
594 foreach($arr as $addr) {
a7d35093 595 $page->trigSuccess("{$addr[0]} inscrit.");
bc4ad6aa 596 }
597 }
598 }
599
600 if (Env::has('del_member')) {
5e2307dc 601 if (strpos(Env::v('del_member'), '@') === false) {
bc4ad6aa 602 $this->client->mass_unsubscribe(
5e2307dc 603 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
bc4ad6aa 604 } else {
5e2307dc 605 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
bc4ad6aa 606 }
8b00e0e0 607 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 608 }
609
610 if (Env::has('add_owner')) {
611 require_once('user.func.inc.php');
0baf0741 612 $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback'));
e7545178 613 if ($owners) {
614 foreach ($owners as $login) {
615 if ($this->client->add_owner($liste, $login)) {
a7d35093 616 $page->trigSuccess($alias." ajouté aux modérateurs.");
e7545178 617 }
bc4ad6aa 618 }
619 }
620 }
621
622 if (Env::has('del_owner')) {
5e2307dc 623 if (strpos(Env::v('del_owner'), '@') === false) {
624 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
bc4ad6aa 625 } else {
5e2307dc 626 $this->client->del_owner($liste, Env::v('del_owner'));
bc4ad6aa 627 }
8b00e0e0 628 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 629 }
630
631 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
0baf0741 632 global $list_unregistered;
633 if ($list_unregistered) {
634 $page->assign_by_ref('unregistered', $list_unregistered);
635 }
30fc8ee7 636 $membres = list_sort_members($mem, @$tri_promo);
637 $moderos = list_sort_owners($own, @$tri_promo);
bc4ad6aa 638
639 $page->assign_by_ref('details', $det);
640 $page->assign_by_ref('members', $membres);
641 $page->assign_by_ref('owners', $moderos);
642 $page->assign('np_m', count($mem));
643
644 } else {
383eaddd 645 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
646 ." Si tu penses qu'il s'agit d'une erreur, "
647 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
bc4ad6aa 648 }
649 }
650
651 function handler_options(&$page, $liste = null)
652 {
bc4ad6aa 653 if (is_null($liste)) {
654 return PL_NOT_FOUND;
655 }
656
7b9d64a8 657 $this->prepare_client($page);
bc4ad6aa 658
1490093c 659 $page->changeTpl('lists/options.tpl');
bc4ad6aa 660
661 if (Post::has('submit')) {
662 $values = $_POST;
5fb22b39 663 $values = array_map('utf8_decode', $values);
c638d8c8
FB
664 $spamlevel = intval($values['bogo_level']);
665 $unsurelevel = intval($values['unsure_level']);
666 if ($spamlevel == 0) {
667 $unsurelevel = 0;
668 }
669 if ($spamlevel > 3 || $spamlevel < 0 || $unsurelevel < 0 || $unsurelevel > 1) {
670 $page->trigError("Réglage de l'antispam non valide");
671 } else {
672 $this->client->set_bogo_level($liste, ($spamlevel << 1) + $unsurelevel);
673 }
bc4ad6aa 674 switch($values['moderate']) {
675 case '0':
676 $values['generic_nonmember_action'] = 0;
677 $values['default_member_moderation'] = 0;
678 break;
679 case '1':
680 $values['generic_nonmember_action'] = 1;
681 $values['default_member_moderation'] = 0;
682 break;
683 case '2':
684 $values['generic_nonmember_action'] = 1;
685 $values['default_member_moderation'] = 1;
686 break;
687 }
688 unset($values['submit'], $values['bogo_level'], $values['moderate']);
689 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
690 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
691 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
692 if (isset($values['subject_prefix'])) {
693 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
694 }
695 $this->client->set_owner_options($liste, $values);
5e2307dc 696 } elseif (isvalid_email(Post::v('atn_add'))) {
697 $this->client->add_to_wl($liste, Post::v('atn_add'));
bc4ad6aa 698 } elseif (Get::has('atn_del')) {
5e2307dc 699 $this->client->del_from_wl($liste, Get::v('atn_del'));
8b00e0e0 700 pl_redirect('lists/options/'.$liste);
bc4ad6aa 701 }
702
703 if (list($details,$options) = $this->client->get_owner_options($liste)) {
704 $page->assign_by_ref('details', $details);
705 $page->assign_by_ref('options', $options);
c638d8c8
FB
706 $bogo_level = intval($this->client->get_bogo_level($liste));
707 $page->assign('unsure_level', $bogo_level & 1);
708 $page->assign('bogo_level', $bogo_level >> 1);
bc4ad6aa 709 } else {
710 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
711 }
712 }
713
714 function handler_delete(&$page, $liste = null)
715 {
7c5842f3 716 global $globals;
bc4ad6aa 717 if (is_null($liste)) {
718 return PL_NOT_FOUND;
719 }
720
7c5842f3 721 $domain = $this->prepare_client($page);
722 if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
723 $domain = '';
724 $table = 'aliases';
725 $type = 'liste';
726 } else {
727 $domain = '@' . $domain;
728 $table = 'virtual';
729 $type = 'list';
730 }
bc4ad6aa 731
1490093c 732 $page->changeTpl('lists/delete.tpl');
7c5842f3 733 if (Post::v('valid') == 'OUI') {
734 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
7d427b10 735 foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) {
7c5842f3 736 XDB::execute("DELETE FROM $table
737 WHERE type={?} AND alias={?}",
738 $type, $liste.$app.$domain);
739 }
740 $page->assign('deleted', true);
741 } else {
742 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
a7de4ef7 743 . 'Contact les administrateurs du site pour régler le problème : '
7c5842f3 744 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
bc4ad6aa 745 }
bc4ad6aa 746 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
747 $page->assign_by_ref('details', $details);
748 $page->assign_by_ref('options', $options);
749 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
750 } else {
751 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
752 }
753 }
754
755 function handler_soptions(&$page, $liste = null)
756 {
bc4ad6aa 757 if (is_null($liste)) {
758 return PL_NOT_FOUND;
759 }
760
7b9d64a8 761 $this->prepare_client($page);
bc4ad6aa 762
1490093c 763 $page->changeTpl('lists/soptions.tpl');
bc4ad6aa 764
765 if (Post::has('submit')) {
766 $values = $_POST;
5fb22b39 767 $values = array_map('utf8_decode', $values);
bc4ad6aa 768 unset($values['submit']);
769 $values['advertised'] = empty($values['advertised']) ? false : true;
770 $values['archive'] = empty($values['archive']) ? false : true;
771 $this->client->set_admin_options($liste, $values);
772 }
773
774 if (list($details,$options) = $this->client->get_admin_options($liste)) {
775 $page->assign_by_ref('details', $details);
776 $page->assign_by_ref('options', $options);
777 } else {
778 $page->kill("La liste n'existe pas");
779 }
780 }
781
782 function handler_check(&$page, $liste = null)
783 {
bc4ad6aa 784 if (is_null($liste)) {
785 return PL_NOT_FOUND;
786 }
787
7b9d64a8 788 $this->prepare_client($page);
bc4ad6aa 789
1490093c 790 $page->changeTpl('lists/check.tpl');
bc4ad6aa 791
792 if (Post::has('correct')) {
793 $this->client->check_options($liste, true);
794 }
795
796 if (list($details,$options) = $this->client->check_options($liste)) {
797 $page->assign_by_ref('details', $details);
798 $page->assign_by_ref('options', $options);
799 } else {
800 $page->kill("La liste n'existe pas");
801 }
802 }
92423144 803
804 function handler_admin_all(&$page) {
1490093c 805 $page->changeTpl('lists/admin_all.tpl');
92423144 806 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
9bb8bf21 807
808 $client = new MMList(S::v('uid'), S::v('password'));
92423144 809 $listes = $client->get_all_lists();
9bb8bf21 810 $page->assign_by_ref('listes', $listes);
92423144 811 }
bc4ad6aa 812}
813
a7de4ef7 814// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
bc4ad6aa 815?>