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