Close #515
[platal.git] / modules / lists.php
CommitLineData
bc4ad6aa 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 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{
24 var $client;
25
26 function handlers()
27 {
28 return array(
29 'lists' => $this->make_hook('lists', AUTH_MDP),
94c63478 30 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, '', NO_AUTH),
bc4ad6aa 31 'lists/create' => $this->make_hook('create', AUTH_MDP),
32
33 'lists/members' => $this->make_hook('members', AUTH_COOKIE),
34 'lists/trombi' => $this->make_hook('trombi', AUTH_COOKIE),
35 'lists/archives' => $this->make_hook('archives', AUTH_COOKIE),
6544d0e1 36 'lists/archives/rss' => $this->make_hook('rss', AUTH_PUBLIC),
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),
92423144 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
65 function handler_lists(&$page)
66 {
50c655ee 67 function filter_owner($list)
68 {
69 return $list['own'];
70 }
71
72 function filter_member($list)
73 {
da398501 74 return $list['sub'];
50c655ee 75 }
76
7b9d64a8 77 $this->prepare_client($page);
bc4ad6aa 78
edc4367b 79 $page->changeTpl('lists/index.tpl');
50c655ee 80 $page->addJsLink('ajax.js');
bc4ad6aa 81 $page->assign('xorg_title','Polytechnique.org - Listes de diffusion');
82
83
84 if (Get::has('del')) {
5e2307dc 85 $this->client->unsubscribe(Get::v('del'));
8b00e0e0 86 pl_redirect('lists');
bc4ad6aa 87 }
88 if (Get::has('add')) {
5e2307dc 89 $this->client->subscribe(Get::v('add'));
8b00e0e0 90 pl_redirect('lists');
bc4ad6aa 91 }
92 if (Post::has('promo_add')) {
5e2307dc 93 $promo = Post::i('promo_add');
bc4ad6aa 94 if ($promo >= 1900 and $promo < 2100) {
95 $this->client->subscribe("promo$promo");
96 } else {
97 $page->trig("promo incorrecte, il faut une promo sur 4 chiffres.");
98 }
99 }
100 $listes = $this->client->get_lists();
50c655ee 101 $owner = array_filter($listes, 'filter_owner');
102 $listes = array_diff_key($listes, $owner);
103 $member = array_filter($listes, 'filter_member');
104 $listes = array_diff_key($listes, $member);
105 foreach ($owner as $key=>$liste) {
106 list($subs,$mails) = $this->client->get_pending_ops($liste['list']);
107 $owner[$key]['subscriptions'] = $subs;
108 $owner[$key]['mails'] = $mails;
109 }
110 $page->register_modifier('hdc', 'list_header_decode');
111 $page->assign_by_ref('owner', $owner);
112 $page->assign_by_ref('member', $member);
113 $page->assign_by_ref('public', $listes);
114 }
115
116 function handler_ajax(&$page, $list = null)
117 {
493b6abe 118 header('Content-Type: text/html; charset="UTF-8"');
5cbb1fad 119 $domain = $this->prepare_client($page);
edc4367b 120 $page->changeTpl('lists/liste.inc.tpl', NO_SKIN);
50c655ee 121 if (Get::has('unsubscribe')) {
122 $this->client->unsubscribe($list);
123 }
124 if (Get::has('subscribe')) {
125 $this->client->subscribe($list);
126 }
127 if (Get::has('sadd')) { /* 4 = SUBSCRIBE */
128 $this->client->handle_request($list, Get::v('sadd'), 4, '');
129 }
130 if (Get::has('mid')) {
5cbb1fad 131 $this->moderate_mail($domain, $list, Get::i('mid'));
50c655ee 132 }
133
134 list($liste, $members, $owners) = $this->client->get_members($list);
135 if ($liste['own']) {
136 list($subs,$mails) = $this->client->get_pending_ops($list);
137 $liste['subscriptions'] = $subs;
138 $liste['mails'] = $mails;
139 }
140 $page->register_modifier('hdc', 'list_header_decode');
141 $page->assign_by_ref('liste', $liste);
bc4ad6aa 142 }
143
144 function handler_create(&$page)
145 {
edc4367b 146 $page->changeTpl('lists/create.tpl');
bc4ad6aa 147
5e2307dc 148 $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY);
149 $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY);
bc4ad6aa 150
151 // click on validate button 'add_owner_sub' or type <enter>
152 if (Post::has('add_owner_sub') && Post::has('add_owner')) {
153 require_once('user.func.inc.php');
154 // if we want to add an owner and then type <enter>, then both
155 // add_owner_sub and add_owner are filled.
e7545178 156 $oforlifes = get_users_forlife_list(Post::v('add_owner'), true);
157 $mforlifes = get_users_forlife_list(Post::v('add_member'), true);
158 if (!is_null($oforlifes)) {
159 $owners = array_merge($owners, $oforlifes);
160 }
161 // if we want to add a member and then type <enter>, then
162 // add_owner_sub is filled, whereas add_owner is empty.
163 if (!is_null($mforlifes)) {
164 $members = array_merge($members, $mforlifes);
bc4ad6aa 165 }
166 }
167
168 // click on validate button 'add_member_sub'
169 if (Post::has('add_member_sub') && Post::has('add_member')) {
170 require_once('user.func.inc.php');
e7545178 171 $forlifes = get_users_forlife_list(Post::v('add_member'), true);
172 if (!is_null($forlifes)) {
173 $members = array_merge($members, $forlifes);
bc4ad6aa 174 }
175 }
176
e7545178 177 ksort($owners);
178 $owners = array_unique($owners);
179 ksort($members);
180 $members = array_unique($members);
bc4ad6aa 181
182 $page->assign('owners', join(' ', $owners));
183 $page->assign('members', join(' ', $members));
184
185 if (!Post::has('submit')) {
186 return;
187 }
188
5e2307dc 189 $liste = Post::v('liste');
bc4ad6aa 190
191 if (empty($liste)) {
a7de4ef7 192 $page->trig('champs «addresse souhaitée» vide');
bc4ad6aa 193 }
194 if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) {
1b5b2b79 195 $page->trig('le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets');
bc4ad6aa 196 }
197
08cce2ff 198 $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste);
bc4ad6aa 199 $n = $res->fetchOneCell();
200
201 if ($n) {
a7de4ef7 202 $page->trig('cet alias est déjà pris');
bc4ad6aa 203 }
204
5e2307dc 205 if (!Post::v(desc)) {
bc4ad6aa 206 $page->trig('le sujet est vide');
207 }
208
209 if (!count($owners)) {
210 $page->trig('pas de gestionnaire');
211 }
212
213 if (count($members)<4) {
214 $page->trig('pas assez de membres');
215 }
216
217 if (!$page->nb_errs()) {
218 $page->assign('created', true);
219 require_once 'validations.inc.php';
cab08090 220 $req = new ListeReq(S::v('uid'), $liste,
5e2307dc 221 Post::v('desc'), Post::i('advertise'),
222 Post::i('modlevel'), Post::i('inslevel'),
bc4ad6aa 223 $owners, $members);
224 $req->submit();
225 }
226 }
227
b2192733 228 function changeTpl($tpl)
229 {
230 if (!empty($GLOBALS['IS_XNET_SITE'])) {
231 new_group_open_page($tpl);
232 } else {
233 global $page;
234 $page->changeTpl($tpl);
235 }
236 }
237
bc4ad6aa 238 function handler_members(&$page, $liste = null)
239 {
bc4ad6aa 240 if (is_null($liste)) {
241 return PL_NOT_FOUND;
242 }
243
7b9d64a8 244 $this->prepare_client($page);
bc4ad6aa 245
b2192733 246 $this->changeTpl('lists/members.tpl');
bc4ad6aa 247
248 if (Get::has('del')) {
249 $this->client->unsubscribe($liste);
8b00e0e0 250 pl_redirect('lists/members/'.$liste);
bc4ad6aa 251 }
252
253 if (Get::has('add')) {
254 $this->client->subscribe($liste);
8b00e0e0 255 pl_redirect('lists/members/'.$liste);
bc4ad6aa 256 }
257
258 $members = $this->client->get_members($liste);
259
5e2307dc 260 $tri_promo = !Env::b('alpha');
bc4ad6aa 261
262 if (list($det,$mem,$own) = $members) {
263 $membres = list_sort_members($mem, $tri_promo);
264 $moderos = list_sort_owners($own, $tri_promo);
265
266 $page->assign_by_ref('details', $det);
267 $page->assign_by_ref('members', $membres);
268 $page->assign_by_ref('owners', $moderos);
269 $page->assign('nb_m', count($mem));
270 } else {
a7de4ef7 271 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 272 }
273 }
274
e48e6f5f 275 function compare($a, $b)
276 {
277 if ($a['promo'] == $b['promo']) {
278 if ($a['nom'] == $b['nom']) {
279 return strcmp($a['prenom'], $b['prenom']);
280 }
281 return strcmp($a['nom'], $b['nom']);
282 }
283 return $a['promo'] - $b['promo'];
284 }
285
bc4ad6aa 286 function _get_list($offset, $limit)
287 {
a3a049fc 288 global $platal;
bc4ad6aa 289 list($total, $members) = $this->client->get_members_limit($platal->argv[1], $offset, $limit);
290
291 $membres = Array();
292 foreach ($members as $member) {
293 list($m) = explode('@',$member[1]);
08cce2ff 294 $res = XDB::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom,
bc4ad6aa 295 promo, a.alias AS forlife
296 FROM auth_user_md5 AS u
297 INNER JOIN aliases AS a ON u.user_id = a.id
c8f17b03 298 INNER JOIN photo AS p ON p.uid = u.user_id
bc4ad6aa 299 WHERE a.alias = {?}", $m);
300 if ($tmp = $res->fetchOneAssoc()) {
301 $membres[$tmp['nom']] = $tmp;
302 } else {
c8f17b03 303 $total--;
bc4ad6aa 304 }
305 }
e48e6f5f 306 uasort($membres, array($this, 'compare'));
bc4ad6aa 307 return array($total, $membres);
308 }
309
310 function handler_trombi(&$page, $liste = null)
311 {
bc4ad6aa 312 if (is_null($liste)) {
313 return PL_NOT_FOUND;
314 }
315
7b9d64a8 316 $this->prepare_client($page);
bc4ad6aa 317
b2192733 318 $this->changeTpl('lists/trombi.tpl');
bc4ad6aa 319
320 if (Get::has('del')) {
321 $this->client->unsubscribe($liste);
14f3419e 322 pl_redirect('lists/trombi/'.$liste);
bc4ad6aa 323 }
324 if (Get::has('add')) {
325 $this->client->subscribe($liste);
14f3419e 326 pl_redirect('lists/trombi/'.$liste);
bc4ad6aa 327 }
328
329 $owners = $this->client->get_owners($liste);
330
331 if (is_array($owners)) {
bc4ad6aa 332 $moderos = list_sort_owners($owners[1]);
333
334 $page->assign_by_ref('details', $owners[0]);
335 $page->assign_by_ref('owners', $moderos);
336
337 $trombi = new Trombi(array(&$this, '_get_list'));
338 $page->assign('trombi', $trombi);
339 } else {
a7de4ef7 340 $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails");
bc4ad6aa 341 }
342 }
343
fa7d6c7b 344 function handler_archives(&$page, $liste = null, $action = null, $artid = null)
bc4ad6aa 345 {
346 global $globals;
347
348 if (is_null($liste)) {
349 return PL_NOT_FOUND;
350 }
351
092945b4 352 $domain = $this->prepare_client($page);
bc4ad6aa 353
b2192733 354 $this->changeTpl('lists/archives.tpl');
bc4ad6aa 355
bc4ad6aa 356 if (list($det) = $this->client->get_members($liste)) {
357 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
fa7d6c7b 358 && !$det['own'] && ($det['sub'] < 2)) {
bc4ad6aa 359 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
fa7d6c7b 360 }
361 $get = Array('listname' => $liste, 'domain' => $domain);
362 if (Post::has('updateall')) {
363 $get['updateall'] = Post::v('updateall');
364 }
365 if (!is_null($action)) {
366 if ($action == 'new') {
367 $get['action'] = 'new';
368 } elseif (!is_null($artid)) {
369 $get['artid'] = $artid;
370 if ($action == 'reply') {
371 $get['action'] = 'new';
372 } elseif ($action == 'cancel') {
373 $get['action'] = $action;
374 } elseif ($action == 'from') {
375 $get['first'] = $artid;
82838f55 376 unset($get['artid']);
fa7d6c7b 377 } elseif ($action == 'read') {
378 $get['part'] = @$_GET['part'];
379 } elseif ($action == 'source') {
380 $get['part'] = 'source';
381 } elseif ($action == 'xface') {
382 $get['part'] = 'xface';
1515e65a 383 } elseif ($action) {
384 $get['part'] = str_replace('.', '/', $action);
bc4ad6aa 385 }
d96379f6 386 if (Get::v('action') == 'showext') {
387 $get['action'] = 'showext';
388 }
bc4ad6aa 389 }
bc4ad6aa 390 }
fa7d6c7b 391 require_once('banana/ml.inc.php');
392 $banana = new MLBanana($get);
393 $page->assign('banana', $banana->run());
ea626742 394 $page->addCssInline($banana->css());
fa7d6c7b 395 $page->addCssLink('banana.css');
6544d0e1 396 $rss = $banana->feed();
397 if ($rss) {
398 $page->setRssLink('Banana :: ' . $list, $rss);
399 }
d3f26be9 400 new PlBacktrace('MBox', $banana->backtrace(), 'response', 'time');
bc4ad6aa 401 } else {
402 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter");
403 }
404 }
405
6544d0e1 406 function handler_rss(&$page, $liste = null, $alias = null, $hash = null)
407 {
408 require_once('rss.inc.php');
409 $uid = init_rss(null, $alias, $hash);
410 if (!$uid || !$liste) {
411 exit;
412 }
413
414 $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife
415 FROM auth_user_md5 AS u
416 INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie')
417 WHERE u.user_id = {?}", $uid);
418 $row = $res->fetchOneAssoc();
419 $_SESSION = array_merge($row, $_SESSION);
420
421 $domain = $this->prepare_client($page);
422 if (list($det) = $this->client->get_members($liste)) {
423 if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv'])
424 && !$det['own'] && ($det['sub'] < 2)) {
425 exit;
426 }
427 require_once('banana/ml.inc.php');
428 $banana = new MLBanana(Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2'));
429 echo $banana->run();
430 }
431 exit;
432 }
433
5cbb1fad 434 function moderate_mail($domain, $liste, $mid)
50c655ee 435 {
436 $mail = $this->client->get_pending_mail($liste, $mid);
437 $reason = '';
438
439 $prenom = S::v('prenom');
440 $nom = S::v('nom');
441
442 if (Env::has('mok')) {
443 $action = 1; /** 2 = ACCEPT **/
a7de4ef7 444 $subject = "Message accepté";
445 $append .= "a été accepté par $prenom $nom.\n";
50c655ee 446 } elseif (Env::has('mno')) {
447 $action = 2; /** 2 = REJECT **/
a7de4ef7 448 $subject = "Message refusé";
50c655ee 449 $reason = Post::v('reason');
a7de4ef7 450 $append = "a été refusé par $prenom $nom avec la raison :\n\n"
50c655ee 451 . $reason;
452 } elseif (Env::has('mdel')) {
453 $action = 3; /** 3 = DISCARD **/
a7de4ef7 454 $subject = "Message supprimé";
455 $append = "a été supprimé par $prenom $nom.\n\n"
456 . "Rappel: il ne faut utiliser cette opération "
50c655ee 457 . "que dans le cas de spams ou de virus !\n";
458 }
459
460 if (isset($action) && $this->client->handle_request($liste, $mid, $action, $reason)) {
461 $texte = "le message suivant :\n\n"
462 ." Auteur: {$mail['sender']}\n"
a7de4ef7 463 ." Sujet : « {$mail['subj']} »\n"
464 ." Date : ".strftime("le %d %b %Y à %H:%M:%S", (int)$mail['stamp'])."\n\n"
50c655ee 465 .$append;
1e33266a 466 $mailer = new PlMailer();
50c655ee 467 $mailer->addTo("$liste-owner@{$domain}");
468 $mailer->setFrom("$liste-bounces@{$domain}");
469 $mailer->addHeader('Reply-To', "$liste-owner@{$domain}");
470 $mailer->setSubject($subject);
471 $mailer->setTxtBody(wordwrap($texte,72));
472 $mailer->send();
473 Get::kill('mid');
474 }
475
476 return $mail;
477 }
478
bc4ad6aa 479 function handler_moderate(&$page, $liste = null)
480 {
bc4ad6aa 481 if (is_null($liste)) {
482 return PL_NOT_FOUND;
483 }
484
092945b4 485 $domain = $this->prepare_client($page);
bc4ad6aa 486
b2192733 487 $this->changeTpl('lists/moderate.tpl');
bc4ad6aa 488
c8529706 489 $page->register_modifier('hdc', 'list_header_decode');
bc4ad6aa 490
491 if (Env::has('sadd')) { /* 4 = SUBSCRIBE */
5e2307dc 492 $this->client->handle_request($liste,Env::v('sadd'),4,'');
8b00e0e0 493 pl_redirect('lists/moderate/'.$liste);
bc4ad6aa 494 }
bc4ad6aa 495 if (Post::has('sdel')) { /* 2 = REJECT */
5e2307dc 496 $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason'));
bc4ad6aa 497 }
498
e940f534 499 if (Post::has('moderate_mails') && Post::has('select_mails')) {
500 $mails = array_keys(Post::v('select_mails'));
501 foreach($mails as $mail) {
502 $this->moderate_mail($domain, $liste, $mail);
503 }
504 } elseif (Env::has('mid')) {
d96379f6 505 if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) {
ed03d07f 506 require_once('banana/moderate.inc.php');
d96379f6 507 $params = array('listname' => $liste, 'domain' => $domain,
508 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action'));
ed03d07f 509 $banana = new ModerationBanana($params, $this->client);
510 $res = $banana->run();
ea626742 511 $page->addCssInline($banana->css());
bc4ad6aa 512
bc4ad6aa 513 $msg = file_get_contents('/etc/mailman/fr/refuse.txt');
514 $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg);
515 $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg);
516 $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg);
517 $msg = str_replace("%(listname)s", $liste, $msg);
50c655ee 518 $page->assign('msg', $msg);
5fb22b39 519
ed03d07f 520 $page->addCssLink('banana.css');
b2192733 521 $this->changeTpl('lists/moderate_mail.tpl');
ed03d07f 522 $page->assign_by_ref('mail', $res);
6a20c6a3 523 return;
ed03d07f 524 }
525
526 $mail = $this->moderate_mail($domain, $liste, Env::i('mid'));
bc4ad6aa 527 } elseif (Env::has('sid')) {
bc4ad6aa 528 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
529 foreach($subs as $user) {
5e2307dc 530 if ($user['id'] == Env::v('sid')) {
b2192733 531 $this->changeTpl('lists/moderate_sub.tpl');
6a20c6a3 532 $page->assign('del_user', $user);
533 return;
bc4ad6aa 534 }
535 }
536 }
537
538 }
539
540 if (list($subs,$mails) = $this->client->get_pending_ops($liste)) {
46ab179a 541 foreach ($mails as $key=>$mail) {
542 $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']);
543 }
bc4ad6aa 544 $page->assign_by_ref('subs', $subs);
545 $page->assign_by_ref('mails', $mails);
546 } else {
a7de4ef7 547 $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer");
bc4ad6aa 548 }
549 }
550
551 function handler_admin(&$page, $liste = null)
552 {
553 global $globals;
554
555 if (is_null($liste)) {
556 return PL_NOT_FOUND;
557 }
558
7b9d64a8 559 $this->prepare_client($page);
bc4ad6aa 560
b2192733 561 $this->changeTpl('lists/admin.tpl');
bc4ad6aa 562
563 if (Env::has('add_member')) {
bc4ad6aa 564 require_once('user.func.inc.php');
e7545178 565 $members = get_users_forlife_list(Env::v('add_member'));
bc4ad6aa 566 $arr = $this->client->mass_subscribe($liste, $members);
567 if (is_array($arr)) {
568 foreach($arr as $addr) {
569 $page->trig("{$addr[0]} inscrit.");
570 }
571 }
572 }
573
574 if (Env::has('del_member')) {
5e2307dc 575 if (strpos(Env::v('del_member'), '@') === false) {
bc4ad6aa 576 $this->client->mass_unsubscribe(
5e2307dc 577 $liste, array(Env::v('del_member').'@'.$globals->mail->domain));
bc4ad6aa 578 } else {
5e2307dc 579 $this->client->mass_unsubscribe($liste, array(Env::v('del_member')));
bc4ad6aa 580 }
8b00e0e0 581 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 582 }
583
584 if (Env::has('add_owner')) {
585 require_once('user.func.inc.php');
e7545178 586 $owners = get_users_forlife_list(Env::v('add_owner'));
587 if ($owners) {
588 foreach ($owners as $login) {
589 if ($this->client->add_owner($liste, $login)) {
a7de4ef7 590 $page->trig($alias." ajouté aux modérateurs.");
e7545178 591 }
bc4ad6aa 592 }
593 }
594 }
595
596 if (Env::has('del_owner')) {
5e2307dc 597 if (strpos(Env::v('del_owner'), '@') === false) {
598 $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain);
bc4ad6aa 599 } else {
5e2307dc 600 $this->client->del_owner($liste, Env::v('del_owner'));
bc4ad6aa 601 }
8b00e0e0 602 pl_redirect('lists/admin/'.$liste);
bc4ad6aa 603 }
604
605 if (list($det,$mem,$own) = $this->client->get_members($liste)) {
30fc8ee7 606 $membres = list_sort_members($mem, @$tri_promo);
607 $moderos = list_sort_owners($own, @$tri_promo);
bc4ad6aa 608
609 $page->assign_by_ref('details', $det);
610 $page->assign_by_ref('members', $membres);
611 $page->assign_by_ref('owners', $moderos);
612 $page->assign('np_m', count($mem));
613
614 } else {
383eaddd 615 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />"
616 ." Si tu penses qu'il s'agit d'une erreur, "
617 ."<a href='mailto:support@polytechnique.org'>contact le support</a>");
bc4ad6aa 618 }
619 }
620
621 function handler_options(&$page, $liste = null)
622 {
bc4ad6aa 623 if (is_null($liste)) {
624 return PL_NOT_FOUND;
625 }
626
7b9d64a8 627 $this->prepare_client($page);
bc4ad6aa 628
b2192733 629 $this->changeTpl('lists/options.tpl');
bc4ad6aa 630
631 if (Post::has('submit')) {
632 $values = $_POST;
5fb22b39 633 $values = array_map('utf8_decode', $values);
bc4ad6aa 634 $this->client->set_bogo_level($liste, intval($values['bogo_level']));
635 switch($values['moderate']) {
636 case '0':
637 $values['generic_nonmember_action'] = 0;
638 $values['default_member_moderation'] = 0;
639 break;
640 case '1':
641 $values['generic_nonmember_action'] = 1;
642 $values['default_member_moderation'] = 0;
643 break;
644 case '2':
645 $values['generic_nonmember_action'] = 1;
646 $values['default_member_moderation'] = 1;
647 break;
648 }
649 unset($values['submit'], $values['bogo_level'], $values['moderate']);
650 $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']);
651 $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']);
652 $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2;
653 if (isset($values['subject_prefix'])) {
654 $values['subject_prefix'] = trim($values['subject_prefix']).' ';
655 }
656 $this->client->set_owner_options($liste, $values);
5e2307dc 657 } elseif (isvalid_email(Post::v('atn_add'))) {
658 $this->client->add_to_wl($liste, Post::v('atn_add'));
bc4ad6aa 659 } elseif (Get::has('atn_del')) {
5e2307dc 660 $this->client->del_from_wl($liste, Get::v('atn_del'));
8b00e0e0 661 pl_redirect('lists/options/'.$liste);
bc4ad6aa 662 }
663
664 if (list($details,$options) = $this->client->get_owner_options($liste)) {
665 $page->assign_by_ref('details', $details);
666 $page->assign_by_ref('options', $options);
667 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
668 } else {
669 $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer");
670 }
671 }
672
673 function handler_delete(&$page, $liste = null)
674 {
7c5842f3 675 global $globals;
bc4ad6aa 676 if (is_null($liste)) {
677 return PL_NOT_FOUND;
678 }
679
7c5842f3 680 $domain = $this->prepare_client($page);
681 if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) {
682 $domain = '';
683 $table = 'aliases';
684 $type = 'liste';
685 } else {
686 $domain = '@' . $domain;
687 $table = 'virtual';
688 $type = 'list';
689 }
bc4ad6aa 690
b2192733 691 $this->changeTpl('lists/delete.tpl');
7c5842f3 692 if (Post::v('valid') == 'OUI') {
693 if ($this->client->delete_list($liste, Post::b('del_archive'))) {
694 foreach (array('', '-owner', '-admin', '-bounces') as $app) {
695 XDB::execute("DELETE FROM $table
696 WHERE type={?} AND alias={?}",
697 $type, $liste.$app.$domain);
698 }
699 $page->assign('deleted', true);
700 } else {
701 $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />'
a7de4ef7 702 . 'Contact les administrateurs du site pour régler le problème : '
7c5842f3 703 . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>');
bc4ad6aa 704 }
bc4ad6aa 705 } elseif (list($details,$options) = $this->client->get_owner_options($liste)) {
706 $page->assign_by_ref('details', $details);
707 $page->assign_by_ref('options', $options);
708 $page->assign('bogo_level', $this->client->get_bogo_level($liste));
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_soptions(&$page, $liste = null)
715 {
bc4ad6aa 716 if (is_null($liste)) {
717 return PL_NOT_FOUND;
718 }
719
7b9d64a8 720 $this->prepare_client($page);
bc4ad6aa 721
b2192733 722 $this->changeTpl('lists/soptions.tpl');
bc4ad6aa 723
724 if (Post::has('submit')) {
725 $values = $_POST;
5fb22b39 726 $values = array_map('utf8_decode', $values);
bc4ad6aa 727 unset($values['submit']);
728 $values['advertised'] = empty($values['advertised']) ? false : true;
729 $values['archive'] = empty($values['archive']) ? false : true;
730 $this->client->set_admin_options($liste, $values);
731 }
732
733 if (list($details,$options) = $this->client->get_admin_options($liste)) {
734 $page->assign_by_ref('details', $details);
735 $page->assign_by_ref('options', $options);
736 } else {
737 $page->kill("La liste n'existe pas");
738 }
739 }
740
741 function handler_check(&$page, $liste = null)
742 {
bc4ad6aa 743 if (is_null($liste)) {
744 return PL_NOT_FOUND;
745 }
746
7b9d64a8 747 $this->prepare_client($page);
bc4ad6aa 748
b2192733 749 $this->changeTpl('lists/check.tpl');
bc4ad6aa 750
751 if (Post::has('correct')) {
752 $this->client->check_options($liste, true);
753 }
754
755 if (list($details,$options) = $this->client->check_options($liste)) {
756 $page->assign_by_ref('details', $details);
757 $page->assign_by_ref('options', $options);
758 } else {
759 $page->kill("La liste n'existe pas");
760 }
761 }
92423144 762
763 function handler_admin_all(&$page) {
b2192733 764 $this->changeTpl('lists/admin_all.tpl');
92423144 765 $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists');
9bb8bf21 766
767 $client = new MMList(S::v('uid'), S::v('password'));
92423144 768 $listes = $client->get_all_lists();
9bb8bf21 769 $page->assign_by_ref('listes', $listes);
92423144 770 }
bc4ad6aa 771}
772
a7de4ef7 773// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
bc4ad6aa 774?>