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 | { | |
032b244e SJ |
162 | global $globals; |
163 | ||
edc4367b | 164 | $page->changeTpl('lists/create.tpl'); |
bc4ad6aa | 165 | |
5e2307dc | 166 | $owners = preg_split("/[\s]+/", Post::v('owners'), -1, PREG_SPLIT_NO_EMPTY); |
167 | $members = preg_split("/[\s]+/", Post::v('members'), -1, PREG_SPLIT_NO_EMPTY); | |
bc4ad6aa | 168 | |
169 | // click on validate button 'add_owner_sub' or type <enter> | |
170 | if (Post::has('add_owner_sub') && Post::has('add_owner')) { | |
171 | require_once('user.func.inc.php'); | |
172 | // if we want to add an owner and then type <enter>, then both | |
173 | // add_owner_sub and add_owner are filled. | |
e7545178 | 174 | $oforlifes = get_users_forlife_list(Post::v('add_owner'), true); |
175 | $mforlifes = get_users_forlife_list(Post::v('add_member'), true); | |
176 | if (!is_null($oforlifes)) { | |
177 | $owners = array_merge($owners, $oforlifes); | |
178 | } | |
179 | // if we want to add a member and then type <enter>, then | |
180 | // add_owner_sub is filled, whereas add_owner is empty. | |
181 | if (!is_null($mforlifes)) { | |
182 | $members = array_merge($members, $mforlifes); | |
bc4ad6aa | 183 | } |
184 | } | |
185 | ||
186 | // click on validate button 'add_member_sub' | |
45070158 | 187 | require_once('user.func.inc.php'); |
bc4ad6aa | 188 | if (Post::has('add_member_sub') && Post::has('add_member')) { |
1555e55e | 189 | $forlifes = get_users_forlife_list(Post::v('add_member'), true); |
e7545178 | 190 | if (!is_null($forlifes)) { |
191 | $members = array_merge($members, $forlifes); | |
bc4ad6aa | 192 | } |
193 | } | |
45070158 FB |
194 | if (Post::has('add_member_sub') && isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { |
195 | $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); | |
196 | if (!$upload) { | |
197 | $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); | |
198 | } else { | |
1555e55e | 199 | $forlifes = get_users_forlife_list($upload->getContents(), true); |
45070158 FB |
200 | if (!is_null($forlifes)) { |
201 | $members = array_merge($members, $forlifes); | |
202 | } | |
203 | } | |
204 | } | |
bc4ad6aa | 205 | |
e7545178 | 206 | ksort($owners); |
207 | $owners = array_unique($owners); | |
208 | ksort($members); | |
209 | $members = array_unique($members); | |
bc4ad6aa | 210 | |
45070158 FB |
211 | $page->assign('owners', join("\n", $owners)); |
212 | $page->assign('members', join("\n", $members)); | |
bc4ad6aa | 213 | |
214 | if (!Post::has('submit')) { | |
215 | return; | |
216 | } | |
217 | ||
59887c4a | 218 | $asso = Post::v('asso'); |
5e2307dc | 219 | $liste = Post::v('liste'); |
bc4ad6aa | 220 | |
221 | if (empty($liste)) { | |
59887c4a | 222 | $page->trigError('Le champ «adresse souhaitée» est vide.'); |
bc4ad6aa | 223 | } |
224 | if (!preg_match("/^[a-zA-Z0-9\-]*$/", $liste)) { | |
59887c4a | 225 | $page->trigError('Le nom de la liste ne doit contenir que des lettres non accentuées, chiffres et tirets.'); |
bc4ad6aa | 226 | } |
227 | ||
59887c4a SJ |
228 | if (($asso == "binet") || ($asso == "alias")) { |
229 | $promo = Post::i('promo'); | |
032b244e | 230 | $domain = $promo . '.' . $globals->mail->domain; |
59887c4a SJ |
231 | |
232 | if (($promo < 1921) || ($promo > date('Y'))) { | |
233 | $page->trigError('La promotion est mal renseignée, elle doit être du type : 2004.'); | |
234 | } | |
235 | ||
236 | $new = $liste . '@' . $domain; | |
237 | $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new); | |
238 | ||
239 | } else { | |
240 | if ($asso == "groupex") { | |
241 | $groupex_name = Post::v('groupex_name'); | |
242 | ||
243 | $res_groupe = XDB::query('SELECT mail_domain FROM groupex.asso WHERE nom={?}', $groupex_name); | |
244 | $domain = $res_groupe->fetchOneCell(); | |
245 | ||
246 | if (!$domain) { | |
247 | $page->trigError('Il n\'y a aucun groupe de ce nom sur Polytechnique.net.'); | |
248 | } | |
249 | ||
250 | $new = $liste . '@' . $domain; | |
251 | $res = XDB::query('SELECT COUNT(*) FROM x4dat.virtual WHERE alias={?}', $new); | |
252 | } else { | |
253 | $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste); | |
032b244e | 254 | $domain = $globals->mail->domain; |
59887c4a SJ |
255 | } |
256 | } | |
257 | ||
258 | $n = $res->fetchOneCell(); | |
bc4ad6aa | 259 | |
260 | if ($n) { | |
032b244e | 261 | $page->trigError('L\'«adresse souhaitée» est déjà prise.'); |
bc4ad6aa | 262 | } |
263 | ||
92144f3e | 264 | if (!Post::v('desc')) { |
59887c4a | 265 | $page->trigError('Le sujet est vide.'); |
bc4ad6aa | 266 | } |
267 | ||
268 | if (!count($owners)) { | |
59887c4a | 269 | $page->trigError('Il n\'y a pas de gestionnaire.'); |
bc4ad6aa | 270 | } |
271 | ||
272 | if (count($members)<4) { | |
59887c4a | 273 | $page->trigError('Il n\'y a pas assez de membres.'); |
bc4ad6aa | 274 | } |
275 | ||
276 | if (!$page->nb_errs()) { | |
277 | $page->assign('created', true); | |
278 | require_once 'validations.inc.php'; | |
59887c4a | 279 | $req = new ListeReq(S::v('uid'), $asso, $liste, $domain, |
5e2307dc | 280 | Post::v('desc'), Post::i('advertise'), |
281 | Post::i('modlevel'), Post::i('inslevel'), | |
bc4ad6aa | 282 | $owners, $members); |
283 | $req->submit(); | |
284 | } | |
285 | } | |
286 | ||
287 | function handler_members(&$page, $liste = null) | |
288 | { | |
bc4ad6aa | 289 | if (is_null($liste)) { |
290 | return PL_NOT_FOUND; | |
291 | } | |
292 | ||
7b9d64a8 | 293 | $this->prepare_client($page); |
bc4ad6aa | 294 | |
1490093c | 295 | $page->changeTpl('lists/members.tpl'); |
bc4ad6aa | 296 | |
297 | if (Get::has('del')) { | |
298 | $this->client->unsubscribe($liste); | |
8b00e0e0 | 299 | pl_redirect('lists/members/'.$liste); |
bc4ad6aa | 300 | } |
301 | ||
302 | if (Get::has('add')) { | |
303 | $this->client->subscribe($liste); | |
8b00e0e0 | 304 | pl_redirect('lists/members/'.$liste); |
bc4ad6aa | 305 | } |
306 | ||
307 | $members = $this->client->get_members($liste); | |
308 | ||
5e2307dc | 309 | $tri_promo = !Env::b('alpha'); |
bc4ad6aa | 310 | |
311 | if (list($det,$mem,$own) = $members) { | |
312 | $membres = list_sort_members($mem, $tri_promo); | |
313 | $moderos = list_sort_owners($own, $tri_promo); | |
314 | ||
315 | $page->assign_by_ref('details', $det); | |
316 | $page->assign_by_ref('members', $membres); | |
317 | $page->assign_by_ref('owners', $moderos); | |
318 | $page->assign('nb_m', count($mem)); | |
319 | } else { | |
a7de4ef7 | 320 | $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); |
bc4ad6aa | 321 | } |
322 | } | |
323 | ||
1cc0afe7 | 324 | function handler_annu(&$page, $liste = null, $action = null, $subaction = null) |
bc4ad6aa | 325 | { |
bc4ad6aa | 326 | if (is_null($liste)) { |
327 | return PL_NOT_FOUND; | |
328 | } | |
329 | ||
7b9d64a8 | 330 | $this->prepare_client($page); |
bc4ad6aa | 331 | |
bc4ad6aa | 332 | if (Get::has('del')) { |
333 | $this->client->unsubscribe($liste); | |
1cc0afe7 | 334 | pl_redirect('lists/annu/'.$liste); |
bc4ad6aa | 335 | } |
336 | if (Get::has('add')) { | |
337 | $this->client->subscribe($liste); | |
1cc0afe7 | 338 | pl_redirect('lists/annu/'.$liste); |
bc4ad6aa | 339 | } |
340 | ||
341 | $owners = $this->client->get_owners($liste); | |
1cc0afe7 | 342 | if (!is_array($owners)) { |
a7de4ef7 | 343 | $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); |
bc4ad6aa | 344 | } |
1cc0afe7 | 345 | |
346 | global $platal; | |
347 | list(,$members) = $this->client->get_members($liste); | |
348 | $users = array(); | |
349 | foreach ($members as $m) { | |
350 | $users[] = $m[1]; | |
351 | } | |
352 | require_once 'userset.inc.php'; | |
353 | $view = new ArraySet($users); | |
354 | $view->addMod('trombi', 'Trombinoscope', true, array('with_promo' => true)); | |
355 | if (empty($GLOBALS['IS_XNET_SITE'])) { | |
356 | $view->addMod('minifiche', 'Minifiches', false); | |
357 | } | |
358 | $view->addMod('geoloc', 'Planisphère'); | |
359 | $view->apply("lists/annu/$liste", $page, $action, $subaction); | |
360 | if ($action == 'geoloc' && $subaction) { | |
361 | return; | |
362 | } | |
363 | ||
364 | $page->changeTpl('lists/annu.tpl'); | |
365 | $moderos = list_sort_owners($owners[1]); | |
366 | $page->assign_by_ref('details', $owners[0]); | |
367 | $page->assign_by_ref('owners', $moderos); | |
bc4ad6aa | 368 | } |
369 | ||
fa7d6c7b | 370 | function handler_archives(&$page, $liste = null, $action = null, $artid = null) |
bc4ad6aa | 371 | { |
372 | global $globals; | |
373 | ||
374 | if (is_null($liste)) { | |
375 | return PL_NOT_FOUND; | |
376 | } | |
377 | ||
092945b4 | 378 | $domain = $this->prepare_client($page); |
bc4ad6aa | 379 | |
1490093c | 380 | $page->changeTpl('lists/archives.tpl'); |
bc4ad6aa | 381 | |
bc4ad6aa | 382 | if (list($det) = $this->client->get_members($liste)) { |
383 | if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) | |
fa7d6c7b | 384 | && !$det['own'] && ($det['sub'] < 2)) { |
38421eaa | 385 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter."); |
fa7d6c7b | 386 | } |
387 | $get = Array('listname' => $liste, 'domain' => $domain); | |
388 | if (Post::has('updateall')) { | |
389 | $get['updateall'] = Post::v('updateall'); | |
390 | } | |
4f355064 | 391 | require_once 'banana/ml.inc.php'; |
392 | get_banana_params($get, null, $action, $artid); | |
393 | run_banana($page, 'MLBanana', $get); | |
bc4ad6aa | 394 | } else { |
38421eaa | 395 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de la consulter."); |
bc4ad6aa | 396 | } |
397 | } | |
398 | ||
6544d0e1 | 399 | function handler_rss(&$page, $liste = null, $alias = null, $hash = null) |
400 | { | |
401 | require_once('rss.inc.php'); | |
402 | $uid = init_rss(null, $alias, $hash); | |
403 | if (!$uid || !$liste) { | |
404 | exit; | |
405 | } | |
406 | ||
407 | $res = XDB::query("SELECT user_id AS uid, password, alias AS forlife | |
408 | FROM auth_user_md5 AS u | |
409 | INNER JOIN aliases AS a ON (a.id = u.user_id AND a.type = 'a_vie') | |
410 | WHERE u.user_id = {?}", $uid); | |
411 | $row = $res->fetchOneAssoc(); | |
412 | $_SESSION = array_merge($row, $_SESSION); | |
413 | ||
414 | $domain = $this->prepare_client($page); | |
415 | if (list($det) = $this->client->get_members($liste)) { | |
416 | if (substr($liste,0,5) != 'promo' && ($det['ins'] || $det['priv']) | |
417 | && !$det['own'] && ($det['sub'] < 2)) { | |
eaf30d86 | 418 | exit; |
6544d0e1 | 419 | } |
420 | require_once('banana/ml.inc.php'); | |
b2bffbe6 | 421 | $banana = new MLBanana(S::v('forlife'), Array('listname' => $liste, 'domain' => $domain, 'action' => 'rss2')); |
4f355064 | 422 | $banana->run(); |
6544d0e1 | 423 | } |
424 | exit; | |
425 | } | |
426 | ||
5cbb1fad | 427 | function moderate_mail($domain, $liste, $mid) |
50c655ee | 428 | { |
50c655ee | 429 | if (Env::has('mok')) { |
834fd0f6 | 430 | $action = 'accept'; |
50c655ee | 431 | } elseif (Env::has('mno')) { |
834fd0f6 | 432 | $action = 'refuse'; |
50c655ee | 433 | } elseif (Env::has('mdel')) { |
834fd0f6 | 434 | $action = 'delete'; |
435 | } else { | |
436 | return false; | |
437 | } | |
438 | Get::kill('mid'); | |
439 | return XDB::execute("INSERT IGNORE INTO ml_moderate | |
440 | VALUES ({?}, {?}, {?}, {?}, {?}, NOW(), {?}, NULL)", | |
441 | $liste, $domain, $mid, S::i('uid'), $action, Post::v('reason')); | |
50c655ee | 442 | } |
443 | ||
bc4ad6aa | 444 | function handler_moderate(&$page, $liste = null) |
445 | { | |
bc4ad6aa | 446 | if (is_null($liste)) { |
4b0d9ef3 | 447 | return PL_NOT_FOUND; |
bc4ad6aa | 448 | } |
449 | ||
092945b4 | 450 | $domain = $this->prepare_client($page); |
bc4ad6aa | 451 | |
1490093c | 452 | $page->changeTpl('lists/moderate.tpl'); |
bc4ad6aa | 453 | |
c8529706 | 454 | $page->register_modifier('hdc', 'list_header_decode'); |
bc4ad6aa | 455 | |
4b0d9ef3 | 456 | if (Env::has('sadd') || Env::has('sdel')) { |
457 | if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ | |
458 | $sub = $this->client->get_pending_sub($liste, Env::v('sadd')); | |
459 | $this->client->handle_request($liste,Env::v('sadd'),4,''); | |
460 | $info = "validée"; | |
461 | } | |
462 | if (Post::has('sdel')) { /* 2 = REJECT */ | |
463 | $sub = $this->client->get_pending_sub($liste, Env::v('sdel')); | |
a5878ac1 | 464 | $this->client->handle_request($liste, Post::v('sdel'), 2, utf8_decode(Post::v('reason'))); |
4b0d9ef3 | 465 | $info = "refusée"; |
466 | } | |
467 | if ($sub) { | |
468 | $mailer = new PlMailer(); | |
469 | $mailer->setFrom("$liste-bounces@{$domain}"); | |
470 | $mailer->addTo("$liste-owner@{$domain}"); | |
471 | $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); | |
472 | $mailer->setSubject("L'inscription de {$sub['name']} a été $info"); | |
473 | $text = "L'inscription de {$sub['name']} à la liste $liste@{$domain} a été $info par " . S::v('prenom') . ' ' | |
474 | . S::v('nom') . '(' . S::v('promo') . ")\n"; | |
475 | if (trim(Post::v('reason'))) { | |
476 | $text .= "\nLa raison invoquée est :\n" . Post::v('reason'); | |
477 | } | |
478 | $mailer->setTxtBody(wordwrap($text, 72)); | |
479 | $mailer->send(); | |
480 | } | |
481 | if (Env::has('sadd')) { | |
482 | pl_redirect('lists/moderate/'.$liste); | |
eaf30d86 | 483 | } |
bc4ad6aa | 484 | } |
485 | ||
e940f534 | 486 | if (Post::has('moderate_mails') && Post::has('select_mails')) { |
487 | $mails = array_keys(Post::v('select_mails')); | |
488 | foreach($mails as $mail) { | |
489 | $this->moderate_mail($domain, $liste, $mail); | |
490 | } | |
491 | } elseif (Env::has('mid')) { | |
d96379f6 | 492 | if (Get::has('mid') && !Env::has('mok') && !Env::has('mdel')) { |
4f355064 | 493 | $page->changeTpl('lists/moderate_mail.tpl'); |
ed03d07f | 494 | require_once('banana/moderate.inc.php'); |
d96379f6 | 495 | $params = array('listname' => $liste, 'domain' => $domain, |
496 | 'artid' => Get::i('mid'), 'part' => Get::v('part'), 'action' => Get::v('action')); | |
4f355064 | 497 | $params['client'] = $this->client; |
498 | run_banana($page, 'ModerationBanana', $params); | |
bc4ad6aa | 499 | |
bc4ad6aa | 500 | $msg = file_get_contents('/etc/mailman/fr/refuse.txt'); |
501 | $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); | |
502 | $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg); | |
503 | $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); | |
504 | $msg = str_replace("%(listname)s", $liste, $msg); | |
50c655ee | 505 | $page->assign('msg', $msg); |
6a20c6a3 | 506 | return; |
ed03d07f | 507 | } |
508 | ||
509 | $mail = $this->moderate_mail($domain, $liste, Env::i('mid')); | |
bc4ad6aa | 510 | } elseif (Env::has('sid')) { |
834fd0f6 | 511 | if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) { |
bc4ad6aa | 512 | foreach($subs as $user) { |
5e2307dc | 513 | if ($user['id'] == Env::v('sid')) { |
1490093c | 514 | $page->changeTpl('lists/moderate_sub.tpl'); |
6a20c6a3 | 515 | $page->assign('del_user', $user); |
516 | return; | |
bc4ad6aa | 517 | } |
518 | } | |
519 | } | |
520 | ||
521 | } | |
522 | ||
834fd0f6 | 523 | if (list($subs,$mails) = $this->get_pending_ops($domain, $liste)) { |
46ab179a | 524 | foreach ($mails as $key=>$mail) { |
525 | $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']); | |
717b9fa7 FB |
526 | if ($mail['fromx']) { |
527 | $page->assign('with_fromx', true); | |
528 | } else { | |
529 | $page->assign('with_nonfromx', true); | |
530 | } | |
46ab179a | 531 | } |
bc4ad6aa | 532 | $page->assign_by_ref('subs', $subs); |
533 | $page->assign_by_ref('mails', $mails); | |
534 | } else { | |
a7de4ef7 | 535 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer"); |
bc4ad6aa | 536 | } |
537 | } | |
538 | ||
0baf0741 | 539 | static public function no_login_callback($login) |
540 | { | |
541 | require_once 'user.func.inc.php'; | |
be792642 | 542 | global $list_unregistered, $globals; |
0baf0741 | 543 | |
544 | $users = get_not_registered_user($login, true); | |
a58d8539 | 545 | if ($users && $users->total()) { |
0baf0741 | 546 | if (!isset($list_unregistered)) { |
547 | $list_unregistered = array(); | |
548 | } | |
549 | $list_unregistered[$login] = $users; | |
550 | } else { | |
be792642 FB |
551 | list($name, $dom) = @explode('@', $login); |
552 | if ($dom == $globals->mail->domain || $dom == $globals->mail->domain2) { | |
553 | _default_user_callback($login); | |
554 | } | |
0baf0741 | 555 | } |
556 | } | |
557 | ||
bc4ad6aa | 558 | function handler_admin(&$page, $liste = null) |
559 | { | |
560 | global $globals; | |
561 | ||
562 | if (is_null($liste)) { | |
563 | return PL_NOT_FOUND; | |
564 | } | |
565 | ||
0baf0741 | 566 | $domain = $this->prepare_client($page); |
bc4ad6aa | 567 | |
1490093c | 568 | $page->changeTpl('lists/admin.tpl'); |
bc4ad6aa | 569 | |
0baf0741 | 570 | if (Env::has('send_mark')) { |
571 | $actions = Env::v('mk_action'); | |
572 | $uids = Env::v('mk_uid'); | |
573 | $mails = Env::v('mk_email'); | |
574 | foreach ($actions as $key=>$action) { | |
575 | switch ($action) { | |
576 | case 'none': | |
577 | break; | |
578 | ||
579 | case 'marketu': case 'markets': | |
580 | require_once 'emails.inc.php'; | |
581 | $mail = valide_email($mails[$key]); | |
582 | if (isvalid_email_redirection($mail)) { | |
583 | $from = ($action == 'marketu') ? 'user' : 'staff'; | |
584 | $market = Marketing::get($uids[$key], $mail); | |
585 | if (!$market) { | |
586 | $market = new Marketing($uids[$key], $mail, 'list', "$liste@$domain", $from, S::v('uid')); | |
587 | $market->add(); | |
588 | break; | |
589 | } | |
590 | } | |
591 | ||
592 | default: | |
593 | XDB::execute('INSERT IGNORE INTO register_subs (uid, type, sub, domain) | |
594 | VALUES ({?}, \'list\', {?}, {?})', | |
595 | $uids[$key], $liste, $domain); | |
596 | } | |
597 | } | |
598 | } | |
599 | ||
bc4ad6aa | 600 | if (Env::has('add_member')) { |
bc4ad6aa | 601 | require_once('user.func.inc.php'); |
be792642 FB |
602 | $members = get_users_forlife_list(Env::v('add_member'), |
603 | false, | |
604 | array('ListsModule', 'no_login_callback')); | |
bc4ad6aa | 605 | $arr = $this->client->mass_subscribe($liste, $members); |
606 | if (is_array($arr)) { | |
607 | foreach($arr as $addr) { | |
a7d35093 | 608 | $page->trigSuccess("{$addr[0]} inscrit."); |
bc4ad6aa | 609 | } |
610 | } | |
611 | } | |
612 | ||
108d1d90 FB |
613 | if (isset($_FILES['add_member_file']) && $_FILES['add_member_file']['tmp_name']) { |
614 | $upload =& PlUpload::get($_FILES['add_member_file'], S::v('forlife'), 'list.addmember', true); | |
615 | if (!$upload) { | |
616 | $page->trigError('Une erreur s\'est produite lors du téléchargement du fichier'); | |
617 | } else { | |
618 | $members = get_users_forlife_list($upload->getContents(), | |
619 | false, | |
620 | array('ListsModule', 'no_login_callback')); | |
621 | $arr = $this->client->mass_subscribe($liste, $members); | |
622 | if (is_array($arr)) { | |
623 | foreach($arr as $addr) { | |
624 | $page->trigSuccess("{$addr[0]} inscrit."); | |
625 | } | |
626 | } | |
627 | } | |
628 | } | |
629 | ||
bc4ad6aa | 630 | if (Env::has('del_member')) { |
5e2307dc | 631 | if (strpos(Env::v('del_member'), '@') === false) { |
bc4ad6aa | 632 | $this->client->mass_unsubscribe( |
5e2307dc | 633 | $liste, array(Env::v('del_member').'@'.$globals->mail->domain)); |
bc4ad6aa | 634 | } else { |
5e2307dc | 635 | $this->client->mass_unsubscribe($liste, array(Env::v('del_member'))); |
bc4ad6aa | 636 | } |
8b00e0e0 | 637 | pl_redirect('lists/admin/'.$liste); |
bc4ad6aa | 638 | } |
639 | ||
640 | if (Env::has('add_owner')) { | |
641 | require_once('user.func.inc.php'); | |
0baf0741 | 642 | $owners = get_users_forlife_list(Env::v('add_owner'), false, array('ListsModule', 'no_login_callback')); |
e7545178 | 643 | if ($owners) { |
644 | foreach ($owners as $login) { | |
645 | if ($this->client->add_owner($liste, $login)) { | |
a7d35093 | 646 | $page->trigSuccess($alias." ajouté aux modérateurs."); |
e7545178 | 647 | } |
bc4ad6aa | 648 | } |
649 | } | |
650 | } | |
651 | ||
652 | if (Env::has('del_owner')) { | |
5e2307dc | 653 | if (strpos(Env::v('del_owner'), '@') === false) { |
654 | $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain); | |
bc4ad6aa | 655 | } else { |
5e2307dc | 656 | $this->client->del_owner($liste, Env::v('del_owner')); |
bc4ad6aa | 657 | } |
8b00e0e0 | 658 | pl_redirect('lists/admin/'.$liste); |
bc4ad6aa | 659 | } |
660 | ||
661 | if (list($det,$mem,$own) = $this->client->get_members($liste)) { | |
0baf0741 | 662 | global $list_unregistered; |
663 | if ($list_unregistered) { | |
664 | $page->assign_by_ref('unregistered', $list_unregistered); | |
665 | } | |
30fc8ee7 | 666 | $membres = list_sort_members($mem, @$tri_promo); |
667 | $moderos = list_sort_owners($own, @$tri_promo); | |
bc4ad6aa | 668 | |
669 | $page->assign_by_ref('details', $det); | |
670 | $page->assign_by_ref('members', $membres); | |
671 | $page->assign_by_ref('owners', $moderos); | |
672 | $page->assign('np_m', count($mem)); | |
673 | ||
674 | } else { | |
383eaddd | 675 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />" |
676 | ." Si tu penses qu'il s'agit d'une erreur, " | |
677 | ."<a href='mailto:support@polytechnique.org'>contact le support</a>"); | |
bc4ad6aa | 678 | } |
679 | } | |
680 | ||
681 | function handler_options(&$page, $liste = null) | |
682 | { | |
bc4ad6aa | 683 | if (is_null($liste)) { |
684 | return PL_NOT_FOUND; | |
685 | } | |
686 | ||
7b9d64a8 | 687 | $this->prepare_client($page); |
bc4ad6aa | 688 | |
1490093c | 689 | $page->changeTpl('lists/options.tpl'); |
bc4ad6aa | 690 | |
691 | if (Post::has('submit')) { | |
692 | $values = $_POST; | |
5fb22b39 | 693 | $values = array_map('utf8_decode', $values); |
c638d8c8 FB |
694 | $spamlevel = intval($values['bogo_level']); |
695 | $unsurelevel = intval($values['unsure_level']); | |
696 | if ($spamlevel == 0) { | |
697 | $unsurelevel = 0; | |
698 | } | |
699 | if ($spamlevel > 3 || $spamlevel < 0 || $unsurelevel < 0 || $unsurelevel > 1) { | |
700 | $page->trigError("Réglage de l'antispam non valide"); | |
701 | } else { | |
702 | $this->client->set_bogo_level($liste, ($spamlevel << 1) + $unsurelevel); | |
703 | } | |
bc4ad6aa | 704 | switch($values['moderate']) { |
705 | case '0': | |
706 | $values['generic_nonmember_action'] = 0; | |
707 | $values['default_member_moderation'] = 0; | |
708 | break; | |
709 | case '1': | |
710 | $values['generic_nonmember_action'] = 1; | |
711 | $values['default_member_moderation'] = 0; | |
712 | break; | |
713 | case '2': | |
714 | $values['generic_nonmember_action'] = 1; | |
715 | $values['default_member_moderation'] = 1; | |
716 | break; | |
717 | } | |
718 | unset($values['submit'], $values['bogo_level'], $values['moderate']); | |
719 | $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']); | |
720 | $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']); | |
721 | $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2; | |
722 | if (isset($values['subject_prefix'])) { | |
723 | $values['subject_prefix'] = trim($values['subject_prefix']).' '; | |
724 | } | |
725 | $this->client->set_owner_options($liste, $values); | |
5e2307dc | 726 | } elseif (isvalid_email(Post::v('atn_add'))) { |
727 | $this->client->add_to_wl($liste, Post::v('atn_add')); | |
bc4ad6aa | 728 | } elseif (Get::has('atn_del')) { |
5e2307dc | 729 | $this->client->del_from_wl($liste, Get::v('atn_del')); |
8b00e0e0 | 730 | pl_redirect('lists/options/'.$liste); |
bc4ad6aa | 731 | } |
732 | ||
733 | if (list($details,$options) = $this->client->get_owner_options($liste)) { | |
734 | $page->assign_by_ref('details', $details); | |
735 | $page->assign_by_ref('options', $options); | |
c638d8c8 FB |
736 | $bogo_level = intval($this->client->get_bogo_level($liste)); |
737 | $page->assign('unsure_level', $bogo_level & 1); | |
738 | $page->assign('bogo_level', $bogo_level >> 1); | |
bc4ad6aa | 739 | } else { |
740 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); | |
741 | } | |
742 | } | |
743 | ||
744 | function handler_delete(&$page, $liste = null) | |
745 | { | |
7c5842f3 | 746 | global $globals; |
bc4ad6aa | 747 | if (is_null($liste)) { |
748 | return PL_NOT_FOUND; | |
749 | } | |
750 | ||
7c5842f3 | 751 | $domain = $this->prepare_client($page); |
752 | if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { | |
753 | $domain = ''; | |
754 | $table = 'aliases'; | |
755 | $type = 'liste'; | |
756 | } else { | |
757 | $domain = '@' . $domain; | |
758 | $table = 'virtual'; | |
759 | $type = 'list'; | |
760 | } | |
bc4ad6aa | 761 | |
1490093c | 762 | $page->changeTpl('lists/delete.tpl'); |
7c5842f3 | 763 | if (Post::v('valid') == 'OUI') { |
764 | if ($this->client->delete_list($liste, Post::b('del_archive'))) { | |
7d427b10 | 765 | foreach (array('', '-owner', '-admin', '-bounces', '-unsubscribe') as $app) { |
7c5842f3 | 766 | XDB::execute("DELETE FROM $table |
767 | WHERE type={?} AND alias={?}", | |
768 | $type, $liste.$app.$domain); | |
769 | } | |
770 | $page->assign('deleted', true); | |
771 | } else { | |
772 | $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />' | |
a7de4ef7 | 773 | . 'Contact les administrateurs du site pour régler le problème : ' |
7c5842f3 | 774 | . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>'); |
bc4ad6aa | 775 | } |
bc4ad6aa | 776 | } elseif (list($details,$options) = $this->client->get_owner_options($liste)) { |
777 | $page->assign_by_ref('details', $details); | |
778 | $page->assign_by_ref('options', $options); | |
779 | $page->assign('bogo_level', $this->client->get_bogo_level($liste)); | |
780 | } else { | |
781 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); | |
782 | } | |
783 | } | |
784 | ||
785 | function handler_soptions(&$page, $liste = null) | |
786 | { | |
bc4ad6aa | 787 | if (is_null($liste)) { |
788 | return PL_NOT_FOUND; | |
789 | } | |
790 | ||
7b9d64a8 | 791 | $this->prepare_client($page); |
bc4ad6aa | 792 | |
1490093c | 793 | $page->changeTpl('lists/soptions.tpl'); |
bc4ad6aa | 794 | |
795 | if (Post::has('submit')) { | |
796 | $values = $_POST; | |
5fb22b39 | 797 | $values = array_map('utf8_decode', $values); |
bc4ad6aa | 798 | unset($values['submit']); |
799 | $values['advertised'] = empty($values['advertised']) ? false : true; | |
800 | $values['archive'] = empty($values['archive']) ? false : true; | |
801 | $this->client->set_admin_options($liste, $values); | |
802 | } | |
803 | ||
804 | if (list($details,$options) = $this->client->get_admin_options($liste)) { | |
805 | $page->assign_by_ref('details', $details); | |
806 | $page->assign_by_ref('options', $options); | |
807 | } else { | |
808 | $page->kill("La liste n'existe pas"); | |
809 | } | |
810 | } | |
811 | ||
812 | function handler_check(&$page, $liste = null) | |
813 | { | |
bc4ad6aa | 814 | if (is_null($liste)) { |
815 | return PL_NOT_FOUND; | |
816 | } | |
817 | ||
7b9d64a8 | 818 | $this->prepare_client($page); |
bc4ad6aa | 819 | |
1490093c | 820 | $page->changeTpl('lists/check.tpl'); |
bc4ad6aa | 821 | |
822 | if (Post::has('correct')) { | |
823 | $this->client->check_options($liste, true); | |
824 | } | |
825 | ||
826 | if (list($details,$options) = $this->client->check_options($liste)) { | |
827 | $page->assign_by_ref('details', $details); | |
828 | $page->assign_by_ref('options', $options); | |
829 | } else { | |
830 | $page->kill("La liste n'existe pas"); | |
831 | } | |
832 | } | |
92423144 | 833 | |
834 | function handler_admin_all(&$page) { | |
1490093c | 835 | $page->changeTpl('lists/admin_all.tpl'); |
92423144 | 836 | $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists'); |
9bb8bf21 | 837 | |
838 | $client = new MMList(S::v('uid'), S::v('password')); | |
92423144 | 839 | $listes = $client->get_all_lists(); |
9bb8bf21 | 840 | $page->assign_by_ref('listes', $listes); |
92423144 | 841 | } |
bc4ad6aa | 842 | } |
843 | ||
a7de4ef7 | 844 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
bc4ad6aa | 845 | ?> |