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