| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2007 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), |
| 30 | 'lists/ajax' => $this->make_hook('ajax', AUTH_MDP, '', NO_AUTH), |
| 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), |
| 44 | 'admin/lists' => $this->make_hook('admin_all', AUTH_MDP, 'admin'), |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | function on_subscribe($forlife, $uid, $promo, $password) |
| 49 | { |
| 50 | $this->prepare_client(null); |
| 51 | $this->client->subscribe("promo$promo"); |
| 52 | } |
| 53 | |
| 54 | function prepare_client(&$page) |
| 55 | { |
| 56 | global $globals; |
| 57 | |
| 58 | require_once dirname(__FILE__).'/lists/lists.inc.php'; |
| 59 | |
| 60 | $this->client = new MMList(S::v('uid'), S::v('password')); |
| 61 | return $globals->mail->domain; |
| 62 | } |
| 63 | |
| 64 | function clean_html($res) |
| 65 | { |
| 66 | $res = html_entity_decode($res); |
| 67 | $res = preg_replace('@<a[^>]*href=["\']([^ >]+)["\'][^>]*>([^<]*)</a>@ie', |
| 68 | "'\\2 [' . htmlentities('\\1') . ']'", $res); |
| 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); |
| 72 | return $res; |
| 73 | } |
| 74 | |
| 75 | function handler_lists(&$page) |
| 76 | { |
| 77 | function filter_owner($list) |
| 78 | { |
| 79 | return $list['own']; |
| 80 | } |
| 81 | |
| 82 | function filter_member($list) |
| 83 | { |
| 84 | return $list['sub']; |
| 85 | } |
| 86 | |
| 87 | $this->prepare_client($page); |
| 88 | |
| 89 | $page->changeTpl('lists/index.tpl'); |
| 90 | $page->addJsLink('ajax.js'); |
| 91 | $page->assign('xorg_title','Polytechnique.org - Listes de diffusion'); |
| 92 | |
| 93 | |
| 94 | if (Get::has('del')) { |
| 95 | $this->client->unsubscribe(Get::v('del')); |
| 96 | pl_redirect('lists'); |
| 97 | } |
| 98 | if (Get::has('add')) { |
| 99 | $this->client->subscribe(Get::v('add')); |
| 100 | pl_redirect('lists'); |
| 101 | } |
| 102 | if (Post::has('promo_add')) { |
| 103 | $promo = Post::i('promo_add'); |
| 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(); |
| 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 | { |
| 128 | header('Content-Type: text/html; charset="iso-8859-15"'); |
| 129 | $domain = $this->prepare_client($page); |
| 130 | $page->changeTpl('lists/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')) { |
| 141 | $this->moderate_mail($domain, $list, Get::i('mid')); |
| 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); |
| 152 | } |
| 153 | |
| 154 | function handler_create(&$page) |
| 155 | { |
| 156 | $page->changeTpl('lists/create.tpl'); |
| 157 | |
| 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); |
| 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. |
| 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); |
| 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'); |
| 181 | $forlifes = get_users_forlife_list(Post::v('add_member'), true); |
| 182 | if (!is_null($forlifes)) { |
| 183 | $members = array_merge($members, $forlifes); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | ksort($owners); |
| 188 | $owners = array_unique($owners); |
| 189 | ksort($members); |
| 190 | $members = array_unique($members); |
| 191 | |
| 192 | $page->assign('owners', join(' ', $owners)); |
| 193 | $page->assign('members', join(' ', $members)); |
| 194 | |
| 195 | if (!Post::has('submit')) { |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | $liste = Post::v('liste'); |
| 200 | |
| 201 | if (empty($liste)) { |
| 202 | $page->trig('champs «addresse souhaitée» vide'); |
| 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 | |
| 208 | $res = XDB::query("SELECT COUNT(*) FROM aliases WHERE alias={?}", $liste); |
| 209 | $n = $res->fetchOneCell(); |
| 210 | |
| 211 | if ($n) { |
| 212 | $page->trig('cet alias est déjà pris'); |
| 213 | } |
| 214 | |
| 215 | if (!Post::v(desc)) { |
| 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'; |
| 230 | $req = new ListeReq(S::v('uid'), $liste, |
| 231 | Post::v('desc'), Post::i('advertise'), |
| 232 | Post::i('modlevel'), Post::i('inslevel'), |
| 233 | $owners, $members); |
| 234 | $req->submit(); |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | function handler_members(&$page, $liste = null) |
| 239 | { |
| 240 | if (is_null($liste)) { |
| 241 | return PL_NOT_FOUND; |
| 242 | } |
| 243 | |
| 244 | $this->prepare_client($page); |
| 245 | |
| 246 | $page->changeTpl('lists/members.tpl'); |
| 247 | |
| 248 | if (Get::has('del')) { |
| 249 | $this->client->unsubscribe($liste); |
| 250 | pl_redirect('lists/members/'.$liste); |
| 251 | } |
| 252 | |
| 253 | if (Get::has('add')) { |
| 254 | $this->client->subscribe($liste); |
| 255 | pl_redirect('lists/members/'.$liste); |
| 256 | } |
| 257 | |
| 258 | $members = $this->client->get_members($liste); |
| 259 | |
| 260 | $tri_promo = !Env::b('alpha'); |
| 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 { |
| 271 | $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | function _get_list($offset, $limit) |
| 276 | { |
| 277 | global $platal; |
| 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]); |
| 283 | $res = XDB::query("SELECT prenom,if (nom_usage='', nom, nom_usage) AS nom, |
| 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 | { |
| 299 | if (is_null($liste)) { |
| 300 | return PL_NOT_FOUND; |
| 301 | } |
| 302 | |
| 303 | $this->prepare_client($page); |
| 304 | |
| 305 | $page->changeTpl('lists/trombi.tpl'); |
| 306 | |
| 307 | if (Get::has('del')) { |
| 308 | $this->client->unsubscribe($liste); |
| 309 | pl_redirect('lists/tromi/'.$liste); |
| 310 | } |
| 311 | if (Get::has('add')) { |
| 312 | $this->client->subscribe($liste); |
| 313 | pl_redirect('lists/tromi/'.$liste); |
| 314 | } |
| 315 | |
| 316 | $owners = $this->client->get_owners($liste); |
| 317 | |
| 318 | if (is_array($owners)) { |
| 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 { |
| 327 | $page->kill("La liste n'existe pas ou tu n'as pas le droit d'en voir les détails"); |
| 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 | |
| 339 | $domain = $this->prepare_client($page); |
| 340 | |
| 341 | $page->changeTpl('lists/archives.tpl'); |
| 342 | |
| 343 | $page->addCssLink('lists.archives.css'); |
| 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')) { |
| 350 | $file = Get::v('file'); |
| 351 | $rep = Get::v('rep'); |
| 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 | |
| 375 | function moderate_mail($domain, $liste, $mid) |
| 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 | $mailer = new PlMailer(); |
| 408 | $mailer->addTo("$liste-owner@{$domain}"); |
| 409 | $mailer->setFrom("$liste-bounces@{$domain}"); |
| 410 | $mailer->addHeader('Reply-To', "$liste-owner@{$domain}"); |
| 411 | $mailer->setSubject($subject); |
| 412 | $mailer->setTxtBody(wordwrap($texte,72)); |
| 413 | $mailer->send(); |
| 414 | Get::kill('mid'); |
| 415 | } |
| 416 | |
| 417 | return $mail; |
| 418 | } |
| 419 | |
| 420 | function handler_moderate(&$page, $liste = null) |
| 421 | { |
| 422 | if (is_null($liste)) { |
| 423 | return PL_NOT_FOUND; |
| 424 | } |
| 425 | |
| 426 | $domain = $this->prepare_client($page); |
| 427 | |
| 428 | $page->changeTpl('lists/moderate.tpl'); |
| 429 | |
| 430 | $page->register_modifier('qpd', 'quoted_printable_decode'); |
| 431 | $page->register_modifier('hdc', 'list_header_decode'); |
| 432 | $page->register_modifier('clean_html', array($this, 'clean_html')); |
| 433 | |
| 434 | if (Env::has('sadd')) { /* 4 = SUBSCRIBE */ |
| 435 | $this->client->handle_request($liste,Env::v('sadd'),4,''); |
| 436 | pl_redirect('lists/moderate/'.$liste); |
| 437 | } |
| 438 | if (Post::has('sdel')) { /* 2 = REJECT */ |
| 439 | $this->client->handle_request($liste,Post::v('sdel'),2,Post::v('reason')); |
| 440 | } |
| 441 | |
| 442 | if (Post::has('moderate_mails') && Post::has('select_mails')) { |
| 443 | $mails = array_keys(Post::v('select_mails')); |
| 444 | foreach($mails as $mail) { |
| 445 | $this->moderate_mail($domain, $liste, $mail); |
| 446 | } |
| 447 | } elseif (Env::has('mid')) { |
| 448 | $mail = $this->moderate_mail($domain, $liste, Env::i('mid')); |
| 449 | |
| 450 | if (Get::has('mid') && is_array($mail)) { |
| 451 | $msg = file_get_contents('/etc/mailman/fr/refuse.txt'); |
| 452 | $msg = str_replace("%(adminaddr)s", "$liste-owner@{$domain}", $msg); |
| 453 | $msg = str_replace("%(request)s", "<< SUJET DU MAIL >>", $msg); |
| 454 | $msg = str_replace("%(reason)s", "<< TON EXPLICATION >>", $msg); |
| 455 | $msg = str_replace("%(listname)s", $liste, $msg); |
| 456 | |
| 457 | $mail['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']); |
| 458 | $page->assign('msg', $msg); |
| 459 | |
| 460 | $page->changeTpl('lists/moderate_mail.tpl'); |
| 461 | $page->assign_by_ref('mail', $mail); |
| 462 | return; |
| 463 | } |
| 464 | } elseif (Env::has('sid')) { |
| 465 | if (list($subs,$mails) = $this->client->get_pending_ops($liste)) { |
| 466 | foreach($subs as $user) { |
| 467 | if ($user['id'] == Env::v('sid')) { |
| 468 | $page->changeTpl('lists/moderate_sub.tpl'); |
| 469 | $page->assign('del_user', $user); |
| 470 | return; |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | } |
| 476 | |
| 477 | if (list($subs,$mails) = $this->client->get_pending_ops($liste)) { |
| 478 | foreach ($mails as $key=>$mail) { |
| 479 | $mails[$key]['stamp'] = strftime("%Y%m%d%H%M%S", $mail['stamp']); |
| 480 | } |
| 481 | $page->assign_by_ref('subs', $subs); |
| 482 | $page->assign_by_ref('mails', $mails); |
| 483 | } else { |
| 484 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de la modérer"); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | function handler_admin(&$page, $liste = null) |
| 489 | { |
| 490 | global $globals; |
| 491 | |
| 492 | if (is_null($liste)) { |
| 493 | return PL_NOT_FOUND; |
| 494 | } |
| 495 | |
| 496 | $this->prepare_client($page); |
| 497 | |
| 498 | $page->changeTpl('lists/admin.tpl'); |
| 499 | |
| 500 | if (Env::has('add_member')) { |
| 501 | require_once('user.func.inc.php'); |
| 502 | $members = get_users_forlife_list(Env::v('add_member')); |
| 503 | $arr = $this->client->mass_subscribe($liste, $members); |
| 504 | if (is_array($arr)) { |
| 505 | foreach($arr as $addr) { |
| 506 | $page->trig("{$addr[0]} inscrit."); |
| 507 | } |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | if (Env::has('del_member')) { |
| 512 | if (strpos(Env::v('del_member'), '@') === false) { |
| 513 | $this->client->mass_unsubscribe( |
| 514 | $liste, array(Env::v('del_member').'@'.$globals->mail->domain)); |
| 515 | } else { |
| 516 | $this->client->mass_unsubscribe($liste, array(Env::v('del_member'))); |
| 517 | } |
| 518 | pl_redirect('lists/admin/'.$liste); |
| 519 | } |
| 520 | |
| 521 | if (Env::has('add_owner')) { |
| 522 | require_once('user.func.inc.php'); |
| 523 | $owners = get_users_forlife_list(Env::v('add_owner')); |
| 524 | if ($owners) { |
| 525 | foreach ($owners as $login) { |
| 526 | if ($this->client->add_owner($liste, $login)) { |
| 527 | $page->trig($alias." ajouté aux modérateurs."); |
| 528 | } |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if (Env::has('del_owner')) { |
| 534 | if (strpos(Env::v('del_owner'), '@') === false) { |
| 535 | $this->client->del_owner($liste, Env::v('del_owner').'@'.$globals->mail->domain); |
| 536 | } else { |
| 537 | $this->client->del_owner($liste, Env::v('del_owner')); |
| 538 | } |
| 539 | pl_redirect('lists/admin/'.$liste); |
| 540 | } |
| 541 | |
| 542 | if (list($det,$mem,$own) = $this->client->get_members($liste)) { |
| 543 | $membres = list_sort_members($mem, @$tri_promo); |
| 544 | $moderos = list_sort_owners($own, @$tri_promo); |
| 545 | |
| 546 | $page->assign_by_ref('details', $det); |
| 547 | $page->assign_by_ref('members', $membres); |
| 548 | $page->assign_by_ref('owners', $moderos); |
| 549 | $page->assign('np_m', count($mem)); |
| 550 | |
| 551 | } else { |
| 552 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer.<br />" |
| 553 | ." Si tu penses qu'il s'agit d'une erreur, " |
| 554 | ."<a href='mailto:support@polytechnique.org'>contact le support</a>"); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | function handler_options(&$page, $liste = null) |
| 559 | { |
| 560 | if (is_null($liste)) { |
| 561 | return PL_NOT_FOUND; |
| 562 | } |
| 563 | |
| 564 | $this->prepare_client($page); |
| 565 | |
| 566 | $page->changeTpl('lists/options.tpl'); |
| 567 | |
| 568 | if (Post::has('submit')) { |
| 569 | $values = $_POST; |
| 570 | $this->client->set_bogo_level($liste, intval($values['bogo_level'])); |
| 571 | switch($values['moderate']) { |
| 572 | case '0': |
| 573 | $values['generic_nonmember_action'] = 0; |
| 574 | $values['default_member_moderation'] = 0; |
| 575 | break; |
| 576 | case '1': |
| 577 | $values['generic_nonmember_action'] = 1; |
| 578 | $values['default_member_moderation'] = 0; |
| 579 | break; |
| 580 | case '2': |
| 581 | $values['generic_nonmember_action'] = 1; |
| 582 | $values['default_member_moderation'] = 1; |
| 583 | break; |
| 584 | } |
| 585 | unset($values['submit'], $values['bogo_level'], $values['moderate']); |
| 586 | $values['send_goodbye_msg'] = !empty($values['send_goodbye_msg']); |
| 587 | $values['admin_notify_mchanges'] = !empty($values['admin_notify_mchanges']); |
| 588 | $values['subscribe_policy'] = empty($values['subscribe_policy']) ? 0 : 2; |
| 589 | if (isset($values['subject_prefix'])) { |
| 590 | $values['subject_prefix'] = trim($values['subject_prefix']).' '; |
| 591 | } |
| 592 | $this->client->set_owner_options($liste, $values); |
| 593 | } elseif (isvalid_email(Post::v('atn_add'))) { |
| 594 | $this->client->add_to_wl($liste, Post::v('atn_add')); |
| 595 | } elseif (Get::has('atn_del')) { |
| 596 | $this->client->del_from_wl($liste, Get::v('atn_del')); |
| 597 | pl_redirect('lists/options/'.$liste); |
| 598 | } |
| 599 | |
| 600 | if (list($details,$options) = $this->client->get_owner_options($liste)) { |
| 601 | $page->assign_by_ref('details', $details); |
| 602 | $page->assign_by_ref('options', $options); |
| 603 | $page->assign('bogo_level', $this->client->get_bogo_level($liste)); |
| 604 | } else { |
| 605 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | function handler_delete(&$page, $liste = null) |
| 610 | { |
| 611 | global $globals; |
| 612 | if (is_null($liste)) { |
| 613 | return PL_NOT_FOUND; |
| 614 | } |
| 615 | |
| 616 | $domain = $this->prepare_client($page); |
| 617 | if ($domain == $globals->mail->domain || $domain == $globals->mail->domain2) { |
| 618 | $domain = ''; |
| 619 | $table = 'aliases'; |
| 620 | $type = 'liste'; |
| 621 | } else { |
| 622 | $domain = '@' . $domain; |
| 623 | $table = 'virtual'; |
| 624 | $type = 'list'; |
| 625 | } |
| 626 | |
| 627 | $page->changeTpl('lists/delete.tpl'); |
| 628 | if (Post::v('valid') == 'OUI') { |
| 629 | if ($this->client->delete_list($liste, Post::b('del_archive'))) { |
| 630 | foreach (array('', '-owner', '-admin', '-bounces') as $app) { |
| 631 | XDB::execute("DELETE FROM $table |
| 632 | WHERE type={?} AND alias={?}", |
| 633 | $type, $liste.$app.$domain); |
| 634 | } |
| 635 | $page->assign('deleted', true); |
| 636 | } else { |
| 637 | $page->kill('Une erreur est survenue lors de la suppression de la liste.<br />' |
| 638 | . 'Contact les administrateurs du site pour régler le problème : ' |
| 639 | . '<a href="mailto:support@polytechnique.org">support@polytechnique.org</a>'); |
| 640 | } |
| 641 | } elseif (list($details,$options) = $this->client->get_owner_options($liste)) { |
| 642 | $page->assign_by_ref('details', $details); |
| 643 | $page->assign_by_ref('options', $options); |
| 644 | $page->assign('bogo_level', $this->client->get_bogo_level($liste)); |
| 645 | } else { |
| 646 | $page->kill("La liste n'existe pas ou tu n'as pas le droit de l'administrer"); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | function handler_soptions(&$page, $liste = null) |
| 651 | { |
| 652 | if (is_null($liste)) { |
| 653 | return PL_NOT_FOUND; |
| 654 | } |
| 655 | |
| 656 | $this->prepare_client($page); |
| 657 | |
| 658 | $page->changeTpl('lists/soptions.tpl'); |
| 659 | |
| 660 | if (Post::has('submit')) { |
| 661 | $values = $_POST; |
| 662 | unset($values['submit']); |
| 663 | $values['advertised'] = empty($values['advertised']) ? false : true; |
| 664 | $values['archive'] = empty($values['archive']) ? false : true; |
| 665 | $this->client->set_admin_options($liste, $values); |
| 666 | } |
| 667 | |
| 668 | if (list($details,$options) = $this->client->get_admin_options($liste)) { |
| 669 | $page->assign_by_ref('details', $details); |
| 670 | $page->assign_by_ref('options', $options); |
| 671 | } else { |
| 672 | $page->kill("La liste n'existe pas"); |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | function handler_check(&$page, $liste = null) |
| 677 | { |
| 678 | if (is_null($liste)) { |
| 679 | return PL_NOT_FOUND; |
| 680 | } |
| 681 | |
| 682 | $this->prepare_client($page); |
| 683 | |
| 684 | $page->changeTpl('lists/check.tpl'); |
| 685 | |
| 686 | if (Post::has('correct')) { |
| 687 | $this->client->check_options($liste, true); |
| 688 | } |
| 689 | |
| 690 | if (list($details,$options) = $this->client->check_options($liste)) { |
| 691 | $page->assign_by_ref('details', $details); |
| 692 | $page->assign_by_ref('options', $options); |
| 693 | } else { |
| 694 | $page->kill("La liste n'existe pas"); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | function handler_admin_all(&$page) { |
| 699 | $page->changeTpl('lists/admin_all.tpl'); |
| 700 | $page->assign('xorg_title','Polytechnique.org - Administration - Mailing lists'); |
| 701 | |
| 702 | $client = new MMList(S::v('uid'), S::v('password')); |
| 703 | $listes = $client->get_all_lists(); |
| 704 | $page->assign_by_ref('listes', $listes); |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | ?> |