bc4ad6aa |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
89 | $page->changeTpl('listes/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); |
50c655ee |
130 | $page->changeTpl('listes/liste.inc.tpl', NO_SKIN); |
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 | { |
bc4ad6aa |
156 | $page->changeTpl('listes/create.tpl'); |
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 | |
246 | $page->changeTpl('listes/members.tpl'); |
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 | |
305 | $page->changeTpl('listes/trombi.tpl'); |
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 | |
341 | $page->changeTpl('listes/archives.tpl'); |
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; |
407 | require_once 'diogenes/diogenes.hermes.inc.php'; |
408 | $mailer = new HermesMailer(); |
409 | $mailer->addTo("$liste-owner@{$domain}"); |
410 | $mailer->setFrom("$liste-bounces@{$domain}"); |
411 | $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); |
412 | $mailer->setSubject($subject); |
413 | $mailer->setTxtBody(wordwrap($texte,72)); |
414 | $mailer->send(); |
415 | Get::kill('mid'); |
416 | } |
417 | |
418 | return $mail; |
419 | } |
420 | |
bc4ad6aa |
421 | function handler_moderate(&$page, $liste = null) |
422 | { |
bc4ad6aa |
423 | if (is_null($liste)) { |
424 | return PL_NOT_FOUND; |
425 | } |
426 | |
092945b4 |
427 | $domain = $this->prepare_client($page); |
bc4ad6aa |
428 | |
429 | $page->changeTpl('listes/moderate.tpl'); |
430 | |
431 | $page->register_modifier('qpd', 'quoted_printable_decode'); |
c8529706 |
432 | $page->register_modifier('hdc', 'list_header_decode'); |
ae0508cb |
433 | $page->register_modifier('clean_html', array($this, 'clean_html')); |
bc4ad6aa |
434 | |
435 | if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ |
5e2307dc |
436 | $this->client->handle_request($liste,Env::v('sadd'),4,''); |
8b00e0e0 |
437 | pl_redirect('lists/moderate/'.$liste); |
bc4ad6aa |
438 | } |
bc4ad6aa |
439 | if (Post::has('sdel')) { /* 2 = REJECT */ |
5e2307dc |
440 | $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason')); |
bc4ad6aa |
441 | } |
442 | |
e940f534 |
443 | if (Post::has('moderate_mails') && Post::has('select_mails')) { |
444 | $mails = array_keys(Post::v('select_mails')); |
445 | foreach($mails as $mail) { |
446 | $this->moderate_mail($domain, $liste, $mail); |
447 | } |
448 | } elseif (Env::has('mid')) { |
5cbb1fad |
449 | $mail = $this->moderate_mail($domain, $liste, Env::i('mid')); |
bc4ad6aa |
450 | |
451 | if (Get::has('mid') && is_array($mail)) { |
452 | $msg = file_get_contents('/etc/mailman/fr/refuse.txt'); |
453 | $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); |
454 | $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg); |
455 | $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); |
456 | $msg = str_replace("%(listname)s", $liste, $msg); |
bc4ad6aa |
457 | |
50c655ee |
458 | $page->assign('msg', $msg); |
459 | |
bc4ad6aa |
460 | $page->changeTpl('listes/moderate_mail.tpl'); |
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')) { |
bc4ad6aa |
468 | $page->changeTpl('listes/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)) { |
478 | $page->assign_by_ref('subs', $subs); |
479 | $page->assign_by_ref('mails', $mails); |
480 | } else { |
089a5801 |
481 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer"); |
bc4ad6aa |
482 | } |
483 | } |
484 | |
485 | function handler_admin(&$page, $liste = null) |
486 | { |
487 | global $globals; |
488 | |
489 | if (is_null($liste)) { |
490 | return PL_NOT_FOUND; |
491 | } |
492 | |
7b9d64a8 |
493 | $this->prepare_client($page); |
bc4ad6aa |
494 | |
495 | $page->changeTpl('listes/admin.tpl'); |
496 | |
497 | if (Env::has('add_member')) { |
bc4ad6aa |
498 | require_once('user.func.inc.php'); |
e7545178 |
499 | $members = get_users_forlife_list(Env::v('add_member')); |
bc4ad6aa |
500 | $arr = $this->client->mass_subscribe($liste, $members); |
501 | if (is_array($arr)) { |
502 | foreach($arr as $addr) { |
503 | $page->trig("{$addr[0]} inscrit."); |
504 | } |
505 | } |
506 | } |
507 | |
508 | if (Env::has('del_member')) { |
5e2307dc |
509 | if (strpos(Env::v('del_member'), '@') === false) { |
bc4ad6aa |
510 | $this->client->mass_unsubscribe( |
5e2307dc |
511 | $liste, array(Env::v('del_member').'@'.$globals->mail->domain)); |
bc4ad6aa |
512 | } else { |
5e2307dc |
513 | $this->client->mass_unsubscribe($liste, array(Env::v('del_member'))); |
bc4ad6aa |
514 | } |
8b00e0e0 |
515 | pl_redirect('lists/admin/'.$liste); |
bc4ad6aa |
516 | } |
517 | |
518 | if (Env::has('add_owner')) { |
519 | require_once('user.func.inc.php'); |
e7545178 |
520 | $owners = get_users_forlife_list(Env::v('add_owner')); |
521 | if ($owners) { |
522 | foreach ($owners as $login) { |
523 | if ($this->client->add_owner($liste, $login)) { |
524 | $page->trig($alias." ajouté aux modérateurs."); |
525 | } |
bc4ad6aa |
526 | } |
527 | } |
528 | } |
529 | |
530 | if (Env::has('del_owner')) { |
5e2307dc |
531 | if (strpos(Env::v('del_owner'), '@') === false) { |
532 | $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain); |
bc4ad6aa |
533 | } else { |
5e2307dc |
534 | $this->client->del_owner($liste, Env::v('del_owner')); |
bc4ad6aa |
535 | } |
8b00e0e0 |
536 | pl_redirect('lists/admin/'.$liste); |
bc4ad6aa |
537 | } |
538 | |
539 | if (list($det,$mem,$own) = $this->client->get_members($liste)) { |
30fc8ee7 |
540 | $membres = list_sort_members($mem, @$tri_promo); |
541 | $moderos = list_sort_owners($own, @$tri_promo); |
bc4ad6aa |
542 | |
543 | $page->assign_by_ref('details', $det); |
544 | $page->assign_by_ref('members', $membres); |
545 | $page->assign_by_ref('owners', $moderos); |
546 | $page->assign('np_m', count($mem)); |
547 | |
548 | } else { |
549 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); |
550 | } |
551 | } |
552 | |
553 | function handler_options(&$page, $liste = null) |
554 | { |
bc4ad6aa |
555 | if (is_null($liste)) { |
556 | return PL_NOT_FOUND; |
557 | } |
558 | |
7b9d64a8 |
559 | $this->prepare_client($page); |
bc4ad6aa |
560 | |
561 | $page->changeTpl('listes/options.tpl'); |
562 | |
563 | if (Post::has('submit')) { |
564 | $values = $_POST; |
565 | $this->client->set_bogo_level($liste, intval($values['bogo_level'])); |
566 | switch($values['moderate']) { |
567 | case '0': |
568 | $values['generic_nonmember_action'] = 0; |
569 | $values['default_member_moderation'] = 0; |
570 | break; |
571 | case '1': |
572 | $values['generic_nonmember_action'] = 1; |
573 | $values['default_member_moderation'] = 0; |
574 | break; |
575 | case '2': |
576 | $values['generic_nonmember_action'] = 1; |
577 | $values['default_member_moderation'] = 1; |
578 | break; |
579 | } |
580 | unset($values['submit'], $values['bogo_level'], $values['moderate']); |
581 | $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']); |
582 | $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']); |
583 | $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2; |
584 | if (isset($values['subject_prefix'])) { |
585 | $values['subject_prefix'] = trim($values['subject_prefix']).' '; |
586 | } |
587 | $this->client->set_owner_options($liste, $values); |
5e2307dc |
588 | } elseif (isvalid_email(Post::v('atn_add'))) { |
589 | $this->client->add_to_wl($liste, Post::v('atn_add')); |
bc4ad6aa |
590 | } elseif (Get::has('atn_del')) { |
5e2307dc |
591 | $this->client->del_from_wl($liste, Get::v('atn_del')); |
8b00e0e0 |
592 | pl_redirect('lists/options/'.$liste); |
bc4ad6aa |
593 | } |
594 | |
595 | if (list($details,$options) = $this->client->get_owner_options($liste)) { |
596 | $page->assign_by_ref('details', $details); |
597 | $page->assign_by_ref('options', $options); |
598 | $page->assign('bogo_level', $this->client->get_bogo_level($liste)); |
599 | } else { |
600 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); |
601 | } |
602 | } |
603 | |
604 | function handler_delete(&$page, $liste = null) |
605 | { |
7c5842f3 |
606 | global $globals; |
bc4ad6aa |
607 | if (is_null($liste)) { |
608 | return PL_NOT_FOUND; |
609 | } |
610 | |
7c5842f3 |
611 | $domain = $this->prepare_client($page); |
612 | if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { |
613 | $domain = ''; |
614 | $table = 'aliases'; |
615 | $type = 'liste'; |
616 | } else { |
617 | $domain = '@' . $domain; |
618 | $table = 'virtual'; |
619 | $type = 'list'; |
620 | } |
bc4ad6aa |
621 | |
622 | $page->changeTpl('listes/delete.tpl'); |
7c5842f3 |
623 | if (Post::v('valid') == 'OUI') { |
624 | if ($this->client->delete_list($liste, Post::b('del_archive'))) { |
625 | foreach (array('', '-owner', '-admin', '-bounces') as $app) { |
626 | XDB::execute("DELETE FROM $table |
627 | WHERE type={?} AND alias={?}", |
628 | $type, $liste.$app.$domain); |
629 | } |
630 | $page->assign('deleted', true); |
631 | } else { |
632 | $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />' |
633 | . 'Contact les administrateurs du site pour régler le problème : ' |
634 | . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>'); |
bc4ad6aa |
635 | } |
bc4ad6aa |
636 | } elseif (list($details,$options) = $this->client->get_owner_options($liste)) { |
637 | $page->assign_by_ref('details', $details); |
638 | $page->assign_by_ref('options', $options); |
639 | $page->assign('bogo_level', $this->client->get_bogo_level($liste)); |
640 | } else { |
641 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); |
642 | } |
643 | } |
644 | |
645 | function handler_soptions(&$page, $liste = null) |
646 | { |
bc4ad6aa |
647 | if (is_null($liste)) { |
648 | return PL_NOT_FOUND; |
649 | } |
650 | |
7b9d64a8 |
651 | $this->prepare_client($page); |
bc4ad6aa |
652 | |
653 | $page->changeTpl('listes/soptions.tpl'); |
654 | |
655 | if (Post::has('submit')) { |
656 | $values = $_POST; |
657 | unset($values['submit']); |
658 | $values['advertised'] = empty($values['advertised']) ? false : true; |
659 | $values['archive'] = empty($values['archive']) ? false : true; |
660 | $this->client->set_admin_options($liste, $values); |
661 | } |
662 | |
663 | if (list($details,$options) = $this->client->get_admin_options($liste)) { |
664 | $page->assign_by_ref('details', $details); |
665 | $page->assign_by_ref('options', $options); |
666 | } else { |
667 | $page->kill("La liste n'existe pas"); |
668 | } |
669 | } |
670 | |
671 | function handler_check(&$page, $liste = null) |
672 | { |
bc4ad6aa |
673 | if (is_null($liste)) { |
674 | return PL_NOT_FOUND; |
675 | } |
676 | |
7b9d64a8 |
677 | $this->prepare_client($page); |
bc4ad6aa |
678 | |
679 | $page->changeTpl('listes/check.tpl'); |
680 | |
681 | if (Post::has('correct')) { |
682 | $this->client->check_options($liste, true); |
683 | } |
684 | |
685 | if (list($details,$options) = $this->client->check_options($liste)) { |
686 | $page->assign_by_ref('details', $details); |
687 | $page->assign_by_ref('options', $options); |
688 | } else { |
689 | $page->kill("La liste n'existe pas"); |
690 | } |
691 | } |
92423144 |
692 | |
693 | function handler_admin_all(&$page) { |
163eddd2 |
694 | $page->changeTpl('listes/admin_all.tpl'); |
92423144 |
695 | $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists'); |
9bb8bf21 |
696 | |
697 | $client = new MMList(S::v('uid'), S::v('password')); |
92423144 |
698 | $listes = $client->get_all_lists(); |
9bb8bf21 |
699 | $page->assign_by_ref('listes', $listes); |
92423144 |
700 | } |
bc4ad6aa |
701 | } |
702 | |
703 | ?> |