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