| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2009 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 | |
| 23 | class XnetGrpModule extends PLModule |
| 24 | { |
| 25 | function handlers() |
| 26 | { |
| 27 | return array( |
| 28 | '%grp' => $this->make_hook('index', AUTH_PUBLIC), |
| 29 | '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC), |
| 30 | '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC), |
| 31 | '%grp/site' => $this->make_hook('site', AUTH_PUBLIC), |
| 32 | '%grp/edit' => $this->make_hook('edit', AUTH_MDP, 'groupadmin'), |
| 33 | '%grp/mail' => $this->make_hook('mail', AUTH_MDP, 'groupadmin'), |
| 34 | '%grp/forum' => $this->make_hook('forum', AUTH_MDP, 'groupmember'), |
| 35 | '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'), |
| 36 | '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'), |
| 37 | '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'), |
| 38 | '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'), |
| 39 | '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'), |
| 40 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
| 41 | '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'), |
| 42 | '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'), |
| 43 | |
| 44 | '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP), |
| 45 | |
| 46 | '%grp/admin/annuaire' |
| 47 | => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'), |
| 48 | |
| 49 | '%grp/member' |
| 50 | => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'), |
| 51 | '%grp/member/new' |
| 52 | => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'), |
| 53 | '%grp/member/new/ajax' |
| 54 | => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH), |
| 55 | '%grp/member/del' |
| 56 | => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'), |
| 57 | |
| 58 | '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS), |
| 59 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), |
| 60 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), |
| 61 | '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC), |
| 62 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'), |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | function handler_index(&$page, $arg = null) |
| 67 | { |
| 68 | global $globals, $platal; |
| 69 | if (!is_null($arg)) { |
| 70 | return PL_NOT_FOUND; |
| 71 | } |
| 72 | $page->changeTpl('xnetgrp/asso.tpl'); |
| 73 | |
| 74 | if (S::logged()) { |
| 75 | if (Env::has('read')) { |
| 76 | XDB::query('DELETE groupex.r.* |
| 77 | FROM groupex.announces_read AS r |
| 78 | INNER JOIN groupex.announces AS a ON a.id = r.announce_id |
| 79 | WHERE peremption < CURRENT_DATE()'); |
| 80 | XDB::query('INSERT INTO groupex.announces_read |
| 81 | VALUES ({?}, {?})', |
| 82 | Env::i('read'), S::i('uid')); |
| 83 | pl_redirect(""); |
| 84 | } |
| 85 | if (Env::has('unread')) { |
| 86 | XDB::query('DELETE FROM groupex.announces_read |
| 87 | WHERE announce_id={?} AND user_id={?}', |
| 88 | Env::i('unread'), S::i('uid')); |
| 89 | pl_redirect("#art" . Env::i('unread')); |
| 90 | } |
| 91 | // XXX: Fix promo_min; promo_max |
| 92 | $arts = XDB::iterator("SELECT a.*, FIND_IN_SET('photo', a.flags) AS photo |
| 93 | FROM groupex.announces AS a |
| 94 | LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id) |
| 95 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
| 96 | AND (promo_min = 0 OR promo_min <= {?}) |
| 97 | AND (promo_max = 0 OR promo_max >= {?}) |
| 98 | AND r.announce_id IS NULL |
| 99 | ORDER BY a.peremption", |
| 100 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); |
| 101 | $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu |
| 102 | FROM groupex.announces AS a |
| 103 | LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?}) |
| 104 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
| 105 | AND (promo_min = 0 OR promo_min <= {?}) |
| 106 | AND (promo_max = 0 OR promo_max >= {?}) |
| 107 | ORDER BY a.peremption", |
| 108 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); |
| 109 | $page->assign('article_index', $index); |
| 110 | } else { |
| 111 | $arts = XDB::iterator("SELECT a.*, FIND_IN_SET('photo', a.flags) AS photo |
| 112 | FROM groupex.announces AS a |
| 113 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
| 114 | AND FIND_IN_SET('public', a.flags)", |
| 115 | $globals->asso('id')); |
| 116 | } |
| 117 | if (may_update()) { |
| 118 | $subs_valid = XDB::query("SELECT uid |
| 119 | FROM groupex.membres_sub_requests |
| 120 | WHERE asso_id = {?}", |
| 121 | $globals->asso('id')); |
| 122 | $page->assign('requests', $subs_valid->numRows()); |
| 123 | } |
| 124 | |
| 125 | if (!S::hasAuthToken()) { |
| 126 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", |
| 127 | $platal->ns . "rss/rss.xml"); |
| 128 | } else { |
| 129 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", |
| 130 | $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('token').'/rss.xml'); |
| 131 | } |
| 132 | |
| 133 | $page->assign('articles', $arts); |
| 134 | } |
| 135 | |
| 136 | function handler_logo(&$page) |
| 137 | { |
| 138 | global $globals; |
| 139 | |
| 140 | $logo = $globals->asso('logo'); |
| 141 | if (!empty($logo)) { |
| 142 | header('Content-type: ' . $globals->asso('logo_mime')); |
| 143 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
| 144 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 145 | header('Cache-Control: no-cache, must-revalidate'); |
| 146 | header('Pragma: no-cache'); |
| 147 | echo $logo; |
| 148 | } else { |
| 149 | header('Content-type: image/jpeg'); |
| 150 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
| 151 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
| 152 | header('Cache-Control: no-cache, must-revalidate'); |
| 153 | header('Pragma: no-cache'); |
| 154 | readfile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg'); |
| 155 | } |
| 156 | |
| 157 | exit; |
| 158 | } |
| 159 | |
| 160 | function handler_site(&$page) |
| 161 | { |
| 162 | global $globals; |
| 163 | $site = $globals->asso('site'); |
| 164 | if (!$site) { |
| 165 | $page->trigError('Le groupe n\'a pas de site web.'); |
| 166 | return $this->handler_index($page); |
| 167 | } |
| 168 | http_redirect($site); |
| 169 | exit; |
| 170 | } |
| 171 | |
| 172 | function handler_edit(&$page) |
| 173 | { |
| 174 | global $globals; |
| 175 | $page->changeTpl('xnetgrp/edit.tpl'); |
| 176 | |
| 177 | if (Post::has('submit')) { |
| 178 | S::assert_xsrf_token(); |
| 179 | |
| 180 | $flags = new PlFlagSet('wiki_desc'); |
| 181 | $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1); |
| 182 | $site = Post::t('site'); |
| 183 | if ($site && ($site != "http://")) { |
| 184 | $scheme = parse_url($site, PHP_URL_SCHEME); |
| 185 | if (!$scheme) { |
| 186 | $site = "http://" . $site; |
| 187 | } |
| 188 | } else { |
| 189 | $site = ""; |
| 190 | } |
| 191 | if (S::has_perms()) { |
| 192 | if (strstr(Post::v('mail_domain'), '.') === false) { |
| 193 | $page->trigError("le domaine doit être un FQDN (aucune modif effectuée) !!!"); |
| 194 | return; |
| 195 | } |
| 196 | XDB::execute( |
| 197 | "UPDATE groupex.asso |
| 198 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, |
| 199 | descr={?}, site={?}, mail={?}, resp={?}, |
| 200 | forum={?}, mail_domain={?}, ax={?}, pub={?}, |
| 201 | sub_url={?}, inscriptible={?}, unsub_url={?}, |
| 202 | flags={?} |
| 203 | WHERE id={?}", |
| 204 | Post::v('nom'), Post::v('diminutif'), |
| 205 | Post::v('cat'), Post::i('dom'), |
| 206 | Post::v('descr'), $site, |
| 207 | Post::v('mail'), Post::v('resp'), |
| 208 | Post::v('forum'), Post::v('mail_domain'), |
| 209 | Post::has('ax'), Post::v('pub'), |
| 210 | Post::v('sub_url'), Post::v('inscriptible'), |
| 211 | Post::v('unsub_url'), $flags, $globals->asso('id')); |
| 212 | if (Post::v('mail_domain')) { |
| 213 | XDB::execute('INSERT IGNORE INTO virtual_domains (domain) VALUES({?})', |
| 214 | Post::v('mail_domain')); |
| 215 | } |
| 216 | } else { |
| 217 | XDB::execute( |
| 218 | "UPDATE groupex.asso |
| 219 | SET descr={?}, site={?}, mail={?}, resp={?}, |
| 220 | forum={?}, ax={?}, pub= {?}, sub_url={?}, |
| 221 | unsub_url={?},flags={?} |
| 222 | WHERE id={?}", |
| 223 | Post::v('descr'), $site, |
| 224 | Post::v('mail'), Post::v('resp'), |
| 225 | Post::v('forum'), Post::has('ax'), |
| 226 | Post::v('pub'), |
| 227 | Post::v('sub_url'), Post::v('unsub_url'), |
| 228 | $flags, $globals->asso('id')); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | if ($_FILES['logo']['name']) { |
| 233 | $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true); |
| 234 | if (!$upload) { |
| 235 | $page->trigError("Impossible de télécharger le logo"); |
| 236 | } else { |
| 237 | XDB::execute('UPDATE groupex.asso |
| 238 | SET logo={?}, logo_mime={?} |
| 239 | WHERE id={?}', $upload->getContents(), $upload->contentType(), |
| 240 | $globals->asso('id')); |
| 241 | $upload->rm(); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); |
| 246 | } |
| 247 | |
| 248 | if (S::has_perms()) { |
| 249 | $dom = XDB::iterator('SELECT * FROM groupex.dom ORDER BY nom'); |
| 250 | $page->assign('dom', $dom); |
| 251 | $page->assign('super', true); |
| 252 | } |
| 253 | if (!$globals->asso('wiki_desc') && $globals->asso('descr')) { |
| 254 | $page->trigWarning("Attention, le format de la description a changé et utilise désormais la syntaxe wiki " |
| 255 | . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour " |
| 256 | . "qu'il s'affiche correctement avec cette nouvelle syntaxe."); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | function handler_mail(&$page) |
| 261 | { |
| 262 | global $globals; |
| 263 | |
| 264 | $page->changeTpl('xnetgrp/mail.tpl'); |
| 265 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
| 266 | $globals->asso('mail_domain')); |
| 267 | $page->assign('listes', $mmlist->get_lists()); |
| 268 | $page->assign('user', S::user()); |
| 269 | $page->addJsLink('ajax.js'); |
| 270 | |
| 271 | if (Post::has('send')) { |
| 272 | S::assert_xsrf_token(); |
| 273 | $from = Post::v('from'); |
| 274 | $sujet = Post::v('sujet'); |
| 275 | $body = Post::v('body'); |
| 276 | |
| 277 | $mls = array_keys(Env::v('ml', array())); |
| 278 | $mbr = array_keys(Env::v('membres', array())); |
| 279 | |
| 280 | $this->load('mail.inc.php'); |
| 281 | set_time_limit(120); |
| 282 | $tos = get_all_redirects($mbr, $mls, $mmlist); |
| 283 | $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true); |
| 284 | send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']); |
| 285 | if ($upload) { |
| 286 | $upload->rm(); |
| 287 | } |
| 288 | $page->killSuccess("Email envoyé !"); |
| 289 | $page->assign('sent', true); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | function handler_forum(&$page, $group = null, $artid = null) |
| 294 | { |
| 295 | global $globals; |
| 296 | $page->changeTpl('xnetgrp/forum.tpl'); |
| 297 | if (!$globals->asso('forum')) { |
| 298 | return PL_NOT_FOUND; |
| 299 | } |
| 300 | require_once 'banana/forum.inc.php'; |
| 301 | $get = array(); |
| 302 | get_banana_params($get, $globals->asso('forum'), $group, $artid); |
| 303 | run_banana($page, 'ForumsBanana', $get); |
| 304 | } |
| 305 | |
| 306 | function handler_annuaire(&$page, $action = null, $subaction = null) |
| 307 | { |
| 308 | global $globals; |
| 309 | |
| 310 | if ($action == 'search') { |
| 311 | http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}" |
| 312 | . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid')); |
| 313 | } else if ($action == 'geoloc' || $action == 'trombi') { |
| 314 | $view = new UserSet(); |
| 315 | $view->addMod('trombi', 'Trombinoscope'); |
| 316 | $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search')); |
| 317 | $view->apply('annuaire', $page, $action, $subaction); |
| 318 | if ($action == 'geoloc' && $subaction) { |
| 319 | return; |
| 320 | } |
| 321 | } |
| 322 | $page->changeTpl('xnetgrp/annuaire.tpl'); |
| 323 | |
| 324 | $sort = Env::s('order', 'directory_name'); |
| 325 | $ofs = Env::i('offset'); |
| 326 | if ($ofs < 0) { |
| 327 | $ofs = 0; |
| 328 | } |
| 329 | |
| 330 | $sdesc = $sort{0} == '-'; |
| 331 | $sf = $sdesc ? substr($sort, 1) : $sort; |
| 332 | if ($sf == 'promo') { |
| 333 | $se = new UFO_Promo(null, $sdesc); |
| 334 | } else { |
| 335 | $se = new UFO_Name($sf, null, null, $sdesc); |
| 336 | } |
| 337 | |
| 338 | if (Env::b('admin')) { |
| 339 | $uf = $globals->asso()->getAdmins(null, $se); |
| 340 | } else { |
| 341 | $uf = $globals->asso()->getMembers(null, $se); |
| 342 | } |
| 343 | $users = $uf->getUsers(NB_PER_PAGE, $ofs * NB_PER_PAGE); |
| 344 | $count = $uf->getTotalCount(); |
| 345 | |
| 346 | $page->assign('pages', floor(($count + NB_PER_PAGE - 1) / NB_PER_PAGE)); |
| 347 | $page->assign('current', $ofs); |
| 348 | $page->assign('order', $sort); |
| 349 | $page->assign('users', $users); |
| 350 | $page->assign('only_admin', Env::b('admin')); |
| 351 | } |
| 352 | |
| 353 | function handler_trombi(&$page) |
| 354 | { |
| 355 | pl_redirect('annuaire/trombi'); |
| 356 | } |
| 357 | |
| 358 | function handler_geoloc(&$page) |
| 359 | { |
| 360 | pl_redirect('annuaire/geoloc'); |
| 361 | } |
| 362 | |
| 363 | function handler_vcard(&$page, $photos = null) |
| 364 | { |
| 365 | global $globals; |
| 366 | $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); |
| 367 | $vcard->addUsers($globals->asso()->getMembers()->getUIDs()); |
| 368 | $vcard->show(); |
| 369 | } |
| 370 | |
| 371 | function handler_csv(&$page, $filename = null) |
| 372 | { |
| 373 | global $globals; |
| 374 | if (is_null($filename)) { |
| 375 | $filename = $globals->asso('diminutif') . '.csv'; |
| 376 | } |
| 377 | $users = $globals->asso()->getMembers(null, new UFO_Name('directory_name'))->getUsers(); |
| 378 | header('Content-Type: text/x-csv; charset=utf-8;'); |
| 379 | header('Pragma: '); |
| 380 | header('Cache-Control: '); |
| 381 | $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN); |
| 382 | $page->assign('users', $users); |
| 383 | } |
| 384 | |
| 385 | private function removeSubscriptionRequest($uid) |
| 386 | { |
| 387 | global $globals; |
| 388 | XDB::execute("DELETE FROM groupex.membres_sub_requests |
| 389 | WHERE asso_id = {?} AND uid = {?}", |
| 390 | $globals->asso('id'), $uid); |
| 391 | } |
| 392 | |
| 393 | private function validSubscription(User &$user) |
| 394 | { |
| 395 | global $globals; |
| 396 | $this->removeSubscriptionRequest($user->id()); |
| 397 | XDB::execute("INSERT IGNORE INTO groupex.membres (asso_id, uid) |
| 398 | VALUES ({?}, {?})", |
| 399 | $globals->asso('id'), $user->id()); |
| 400 | if (XDB::affectedRows() == 1) { |
| 401 | $mailer = new PlMailer(); |
| 402 | $mailer->addTo($user->forlifeEmail()); |
| 403 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
| 404 | $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); |
| 405 | $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n" |
| 406 | . "\n" |
| 407 | . " Suite à ta demande d'adhésion à " . $globals->asso('nom') . ",\n" |
| 408 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" |
| 409 | . "\n" |
| 410 | . "Bien cordialement,\n" |
| 411 | . "-- \n" |
| 412 | . S::user()->fullName() . '.'; |
| 413 | $mailer->setTxtBody($message); |
| 414 | $mailer->send(); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | function handler_subscribe(&$page, $u = null) |
| 419 | { |
| 420 | global $globals; |
| 421 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
| 422 | |
| 423 | if (!$globals->asso('inscriptible')) |
| 424 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
| 425 | ."groupe. Essaie de joindre le contact indiqué " |
| 426 | ."sur la page de présentation."); |
| 427 | |
| 428 | if (!is_null($u) && may_update()) { |
| 429 | $user = User::get($u); |
| 430 | if (!$user) { |
| 431 | return PL_NOT_FOUND; |
| 432 | } else { |
| 433 | $page->assign('user', $user); |
| 434 | } |
| 435 | |
| 436 | // Retrieves the subscription status, and the reason. |
| 437 | $res = XDB::query("SELECT reason |
| 438 | FROM groupex.membres_sub_requests |
| 439 | WHERE asso_id = {?} AND uid = {?}", |
| 440 | $globals->asso('id'), $user->id()); |
| 441 | $reason = ($res->numRows() ? $res->fetchOneCell() : null); |
| 442 | |
| 443 | $res = XDB::query("SELECT COUNT(*) |
| 444 | FROM groupex.membres |
| 445 | WHERE asso_id = {?} AND uid = {?}", |
| 446 | $globals->asso('id'), $user->id()); |
| 447 | $already_member = ($res->fetchOneCell() > 0); |
| 448 | |
| 449 | // Handles the membership request. |
| 450 | if ($already_member) { |
| 451 | $this->removeSubscriptionRequest($user->id()); |
| 452 | $page->kill($user->fullName() . " est déjà membre du groupe !"); |
| 453 | } elseif (Env::has('accept')) { |
| 454 | S::assert_xsrf_token(); |
| 455 | |
| 456 | $this->validSubscription($user); |
| 457 | pl_redirect("member/" . $user->login()); |
| 458 | } elseif (Env::has('refuse')) { |
| 459 | S::assert_xsrf_token(); |
| 460 | |
| 461 | $this->removeSubscriptionRequest($user->id()); |
| 462 | $mailer = new PlMailer(); |
| 463 | $mailer->addTo($user->forlifeEmail()); |
| 464 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
| 465 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); |
| 466 | $mailer->setTxtBody(Env::v('motif')); |
| 467 | $mailer->send(); |
| 468 | $page->kill("La demande de {$user->fullName()} a bien été refusée."); |
| 469 | } else { |
| 470 | $page->assign('show_form', true); |
| 471 | $page->assign('reason', $reason); |
| 472 | } |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | if (is_member()) { |
| 477 | $page->kill("Tu es déjà membre !"); |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | $res = XDB::query("SELECT uid |
| 482 | FROM groupex.membres_sub_requests |
| 483 | WHERE uid = {?} AND asso_id = {?}", |
| 484 | S::i('uid'), $globals->asso('id')); |
| 485 | if ($res->numRows() != 0) { |
| 486 | $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation."); |
| 487 | return; |
| 488 | } |
| 489 | |
| 490 | if (Post::has('inscrire')) { |
| 491 | S::assert_xsrf_token(); |
| 492 | |
| 493 | XDB::execute("INSERT INTO groupex.membres_sub_requests (asso_id, uid, ts, reason) |
| 494 | VALUES ({?}, {?}, NOW(), {?})", |
| 495 | $globals->asso('id'), S::i('uid'), Post::v('message')); |
| 496 | $res = XDB::query('SELECT IF(m.email IS NULL, |
| 497 | CONCAT(al.alias,"@polytechnique.org"), |
| 498 | m.email) |
| 499 | FROM groupex.membres AS m |
| 500 | INNER JOIN aliases AS al ON (al.type = "a_vie" |
| 501 | AND al.id = m.uid) |
| 502 | WHERE perms="admin" AND m.asso_id = {?}', |
| 503 | $globals->asso('id')); |
| 504 | $emails = $res->fetchColumn(); |
| 505 | $to = implode(',', $emails); |
| 506 | |
| 507 | $append = "\n" |
| 508 | . "-- \n" |
| 509 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
| 510 | . S::user()->fullName() . ' (X' . S::v('promo') . ")\n" |
| 511 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
| 512 | . "de refuser sa demande d'inscription depuis la page :\n" |
| 513 | . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n" |
| 514 | . "\n" |
| 515 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
| 516 | . "à l'adresse : support@polytechnique.org\n"; |
| 517 | |
| 518 | if (!$to) { |
| 519 | $to = $globals->asso("mail").", support@polytechnique.org"; |
| 520 | $append = "\n-- \nLe groupe ".$globals->asso("nom") |
| 521 | ." n'a pas d'administrateur, l'équipe de" |
| 522 | ." Polytechnique.org a été prévenue et va rapidement" |
| 523 | ." résoudre ce problème.\n"; |
| 524 | } |
| 525 | |
| 526 | $mailer = new PlMailer(); |
| 527 | $mailer->addTo($to); |
| 528 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
| 529 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
| 530 | $mailer->setTxtBody(Post::v('message').$append); |
| 531 | $mailer->send(); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | function handler_subscribe_valid(&$page) |
| 536 | { |
| 537 | global $globals; |
| 538 | |
| 539 | if (Post::has('valid')) { |
| 540 | S::assert_xsrf_token(); |
| 541 | $subs = Post::v('subs'); |
| 542 | if (is_array($subs)) { |
| 543 | $users = array(); |
| 544 | foreach ($subs as $hruid => $val) { |
| 545 | if ($val == '1') { |
| 546 | $user = User::get($hruid); |
| 547 | if ($user) { |
| 548 | $this->validSubscription($user); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date |
| 556 | FROM groupex.membres_sub_requests AS s |
| 557 | INNER JOIN accounts AS a ON(s.uid = a.uid) |
| 558 | WHERE s.asso_id = {?} |
| 559 | ORDER BY s.ts', $globals->asso('id')); |
| 560 | $page->changeTpl('xnetgrp/subscribe-valid.tpl'); |
| 561 | $page->assign('valid', $it); |
| 562 | } |
| 563 | |
| 564 | function handler_change_rights(&$page) |
| 565 | { |
| 566 | if (Env::has('right') && (may_update() || S::suid())) { |
| 567 | switch (Env::v('right')) { |
| 568 | case 'admin': |
| 569 | Platal::session()->stopSUID(); |
| 570 | break; |
| 571 | case 'anim': |
| 572 | Platal::session()->doSelfSuid(); |
| 573 | may_update(true); |
| 574 | is_member(true); |
| 575 | break; |
| 576 | case 'member': |
| 577 | Platal::session()->doSelfSuid(); |
| 578 | may_update(false, true); |
| 579 | is_member(true); |
| 580 | break; |
| 581 | case 'logged': |
| 582 | Platal::session()->doSelfSuid(); |
| 583 | may_update(false, true); |
| 584 | is_member(false, true); |
| 585 | break; |
| 586 | } |
| 587 | } |
| 588 | http_redirect($_SERVER['HTTP_REFERER']); |
| 589 | } |
| 590 | |
| 591 | function handler_admin_annuaire(&$page) |
| 592 | { |
| 593 | global $globals; |
| 594 | |
| 595 | $this->load('mail.inc.php'); |
| 596 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
| 597 | $user = S::user(); |
| 598 | $mmlist = new MMList($user, $globals->asso('mail_domain')); |
| 599 | $lists = $mmlist->get_lists(); |
| 600 | if (!$lists) $lists = array(); |
| 601 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); |
| 602 | |
| 603 | $subscribers = array(); |
| 604 | |
| 605 | foreach ($listes as $list) { |
| 606 | list(,$members) = $mmlist->get_members($list); |
| 607 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
| 608 | $subscribers = array_unique(array_merge($subscribers, $mails)); |
| 609 | } |
| 610 | |
| 611 | $not_in_group_x = array(); |
| 612 | $not_in_group_ext = array(); |
| 613 | |
| 614 | foreach ($subscribers as $mail) { |
| 615 | $uf = new UserFilter(new UFC_And(new UFC_Group($globals->asso('id')), |
| 616 | new UFC_Email($mail))); |
| 617 | if ($uf->getTotalCount() == 0) { |
| 618 | if (User::isForeignEmailAddress($mail)) { |
| 619 | $not_in_group_ext[] = $mail; |
| 620 | } else { |
| 621 | $not_in_group_x[] = $mail; |
| 622 | } |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | $page->assign('not_in_group_ext', $not_in_group_ext); |
| 627 | $page->assign('not_in_group_x', $not_in_group_x); |
| 628 | $page->assign('lists', $lists); |
| 629 | } |
| 630 | |
| 631 | function handler_admin_member_new(&$page, $email = null) |
| 632 | { |
| 633 | global $globals; |
| 634 | |
| 635 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
| 636 | $page->addJsLink('ajax.js'); |
| 637 | |
| 638 | if (is_null($email)) { |
| 639 | return; |
| 640 | } else { |
| 641 | S::assert_xsrf_token(); |
| 642 | } |
| 643 | |
| 644 | if (!User::isForeignEmailAddress($email)) { |
| 645 | $user = User::get($email); |
| 646 | if ($user) { |
| 647 | XDB::execute("REPLACE INTO groupex.membres (uid, asso_id, origine) |
| 648 | VALUES ({?}, {?}, 'X')", |
| 649 | $user->id(), $globals->asso('id')); |
| 650 | pl_redirect("member/" . $user->login()); |
| 651 | } |
| 652 | } else { |
| 653 | if (isvalid_email($email)) { |
| 654 | if (Env::v('x') && Env::i('userid')) { |
| 655 | $uid = Env::i('userid'); |
| 656 | $user = User::getWithUID($uid); |
| 657 | if ($user && $user->state == 'pending') { |
| 658 | if (Env::v('market')) { |
| 659 | $market = Marketing::get($uid, $email); |
| 660 | if (!$market) { |
| 661 | $market = new Marketing($uid, $email, 'group', $globals->asso('nom'), |
| 662 | Env::v('market_from'), S::v('uid')); |
| 663 | $market->add(); |
| 664 | } |
| 665 | } |
| 666 | XDB::execute('REPLACE INTO groupex.membres (uid, asso_id, origine, email) |
| 667 | VALUES ({?}, {?}, "X", {?})', |
| 668 | $uid, $globals->asso('id'), $email); |
| 669 | $this->removeSubscriptionRequest($uid); |
| 670 | pl_redirect("member/$email"); |
| 671 | } |
| 672 | $page->trigError("Utilisateur invalide"); |
| 673 | } else { |
| 674 | $res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres'); |
| 675 | $uid = max(intval($res->fetchOneCell()), 50001); |
| 676 | XDB::execute('REPLACE INTO groupex.membres (uid, asso_id, origine, email) |
| 677 | VALUES ({?}, {?}, "ext", {?})', |
| 678 | $uid, $globals->asso('id'), $email); |
| 679 | pl_redirect("member/$email"); |
| 680 | } |
| 681 | } else { |
| 682 | $page->trigError("« <strong>$email</strong> » n'est pas une adresse email valide."); |
| 683 | } |
| 684 | } |
| 685 | } |
| 686 | |
| 687 | function handler_admin_member_new_ajax(&$page) |
| 688 | { |
| 689 | header('Content-Type: text/html; charset="UTF-8"'); |
| 690 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
| 691 | $users = array(); |
| 692 | if (Env::has('login')) { |
| 693 | $user = User::getSilent(Env::t('login')); |
| 694 | if ($user && $user->state != 'pending') { |
| 695 | $users = array($user); |
| 696 | } |
| 697 | } |
| 698 | if (empty($users)) { |
| 699 | list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); |
| 700 | $cond = new UFC_And(new UFC_Not(new UFC_Registered())); |
| 701 | if (!empty($nom)) { |
| 702 | $cond->addChild(new UFC_Name(UserFilter::LASTNAME, $nom, UFC_Name::CONTAINS)); |
| 703 | } |
| 704 | if (!empty($prenom)) { |
| 705 | $cond->addChild(new UFC_Name(UserFilter::FIRSTNAME, $prenom, UFC_Name::CONTAINS)); |
| 706 | } |
| 707 | if (Env::i('promo')) { |
| 708 | $cond->addChild(new UFC_Promo('=', UserFilter::GRADE_ING, Env::i('promo'))); |
| 709 | } |
| 710 | $uf = new UserFilter($cond); |
| 711 | $users = $uf->getUsers(30); |
| 712 | if ($uf->getTotalCount() > 30) { |
| 713 | $page->assign('too_many', true); |
| 714 | $users = array(); |
| 715 | } |
| 716 | } |
| 717 | $page->assign('users', $users); |
| 718 | } |
| 719 | |
| 720 | function unsubscribe(PlUser &$user) |
| 721 | { |
| 722 | global $globals; |
| 723 | XDB::execute("DELETE FROM groupex.membres |
| 724 | WHERE uid = {?} AND asso_id = {?}", |
| 725 | $user->id(), $globals->asso('id')); |
| 726 | |
| 727 | if ($globals->asso('notif_unsub')) { |
| 728 | $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); |
| 729 | foreach ($globals->asso()->getMembers()->getUsers() as $user) { |
| 730 | $mailer->addTo($user); |
| 731 | } |
| 732 | $mailer->assign('group', $globals->asso('nom')); |
| 733 | $mailer->assign('user', $user); |
| 734 | $mailer->assign('selfdone', $user->id() == S::i('uid')); |
| 735 | $mailer->send(); |
| 736 | } |
| 737 | |
| 738 | $domain = $globals->asso('mail_domain'); |
| 739 | if (!$domain) { |
| 740 | return true; |
| 741 | } |
| 742 | |
| 743 | $mmlist = new MMList($user, $domain); |
| 744 | $listes = $mmlist->get_lists($user->forlifeEmail()); |
| 745 | |
| 746 | $may_update = may_update(); |
| 747 | $warning = false; |
| 748 | foreach ($listes as $liste) { |
| 749 | if ($liste['sub'] == 2) { |
| 750 | if ($may_update) { |
| 751 | $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail())); |
| 752 | } else { |
| 753 | $mmlist->unsubscribe($liste['list']); |
| 754 | } |
| 755 | } elseif ($liste['sub']) { |
| 756 | Platal::page()->trigWarning($user->fullName() . " a une" |
| 757 | ." demande d'inscription en cours sur la" |
| 758 | ." liste {$liste['list']}@ !"); |
| 759 | $warning = true; |
| 760 | } |
| 761 | } |
| 762 | |
| 763 | XDB::execute("DELETE FROM virtual_redirect |
| 764 | USING virtual_redirect |
| 765 | INNER JOIN virtual USING(vid) |
| 766 | WHERE redirect={?} AND alias LIKE {?}", |
| 767 | $user->forlifeEmail(), '%@'.$domain); |
| 768 | return !$warning; |
| 769 | } |
| 770 | |
| 771 | function handler_unsubscribe(&$page) |
| 772 | { |
| 773 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
| 774 | $user = S::user()->id(); |
| 775 | if (empty($user)) { |
| 776 | return PL_NOT_FOUND; |
| 777 | } |
| 778 | $page->assign('self', true); |
| 779 | $page->assign('user', $user); |
| 780 | |
| 781 | if (!Post::has('confirm')) { |
| 782 | return; |
| 783 | } else { |
| 784 | S::assert_xsrf_token(); |
| 785 | } |
| 786 | |
| 787 | if ($this->unsubscribe($user)) { |
| 788 | $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.'); |
| 789 | } else { |
| 790 | $page->trigWarning('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.'); |
| 791 | } |
| 792 | $page->assign('is_member', is_member(true)); |
| 793 | } |
| 794 | |
| 795 | function handler_admin_member_del(&$page, $user = null) |
| 796 | { |
| 797 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
| 798 | $user = User::getSilent($user); |
| 799 | if (empty($user)) { |
| 800 | return PL_NOT_FOUND; |
| 801 | } |
| 802 | $page->assign('user', $user); |
| 803 | |
| 804 | if (!Post::has('confirm')) { |
| 805 | return; |
| 806 | } else { |
| 807 | S::assert_xsrf_token(); |
| 808 | } |
| 809 | |
| 810 | if ($this->unsubscribe($user)) { |
| 811 | $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !"); |
| 812 | } else { |
| 813 | $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !"); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login) |
| 818 | { |
| 819 | require_once 'user.func.inc.php'; |
| 820 | // Search the uid of the user... |
| 821 | $res = XDB::query("SELECT f.id, f.alias |
| 822 | FROM aliases AS a |
| 823 | INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') |
| 824 | WHERE a.alias = {?}", |
| 825 | $login); |
| 826 | if ($res->numRows() == 0) { |
| 827 | $x = get_not_registered_user($login); |
| 828 | if (!$x) { |
| 829 | $page->trigError("Le login $login ne correspond à aucun X."); |
| 830 | return false; |
| 831 | } else if (count($x) > 1) { |
| 832 | $page->trigError("Le login $login correspond a plusieurs camarades."); |
| 833 | return false; |
| 834 | } |
| 835 | $uid = $x[0]['user_id']; |
| 836 | $sub = false; |
| 837 | } else { |
| 838 | list($uid, $login) = $res->fetchOneRow(); |
| 839 | $sub = true; |
| 840 | } |
| 841 | |
| 842 | // Check if the user is already in the group |
| 843 | global $globals; |
| 844 | $res = XDB::query("SELECT uid, email |
| 845 | FROM groupex.membres |
| 846 | WHERE uid = {?} AND asso_id = {?}", |
| 847 | $uid, $globals->asso('id')); |
| 848 | if ($res->numRows()) { |
| 849 | list($uid, $email) = $res->fetchOneRow(); |
| 850 | XDB::execute("DELETE FROM groupex.membres |
| 851 | WHERE uid = {?}", |
| 852 | $user['uid']); |
| 853 | } else { |
| 854 | $email = $user['email']; |
| 855 | XDB::execute("UPDATE groupex.membres |
| 856 | SET uid = {?}, origine = 'X' |
| 857 | WHERE uid = {?} AND asso_id = {?}", |
| 858 | $uid, $user['uid'], $globals->asso('id')); |
| 859 | } |
| 860 | if ($sub) { |
| 861 | $email = $login . '@' . $globals->mail->domain; |
| 862 | } |
| 863 | |
| 864 | // Update subscription to aliases |
| 865 | if ($email != $user['email']) { |
| 866 | XDB::execute("UPDATE IGNORE virtual_redirect AS vr |
| 867 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
| 868 | SET vr.redirect = {?} |
| 869 | WHERE vr.redirect = {?}", |
| 870 | $globals->asso('mail_domain'), $email, $user['email']); |
| 871 | XDB::execute("DELETE vr.* |
| 872 | FROM virtual_redirect AS vr |
| 873 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
| 874 | WHERE vr.redirect = {?}", |
| 875 | $globals->asso('mail_domain'), $user['email']); |
| 876 | foreach (Env::v('ml1', array()) as $ml => $state) { |
| 877 | $mmlist->replace_email($ml, $user['email'], $email); |
| 878 | } |
| 879 | } |
| 880 | if ($sub) { |
| 881 | return $login; |
| 882 | } |
| 883 | return $user['email']; |
| 884 | } |
| 885 | |
| 886 | function handler_admin_member(&$page, $user) |
| 887 | { |
| 888 | global $globals; |
| 889 | |
| 890 | $page->changeTpl('xnetgrp/membres-edit.tpl'); |
| 891 | |
| 892 | $user = User::getSilent($user); |
| 893 | if (empty($user)) { |
| 894 | return PL_NOT_FOUND; |
| 895 | } |
| 896 | |
| 897 | $mmlist = new MMList($user, $globals->asso('mail_domain')); |
| 898 | |
| 899 | if (Post::has('change')) { |
| 900 | S::assert_xsrf_token(); |
| 901 | |
| 902 | // Convert user status to X |
| 903 | if (Post::blank('login_X')) { |
| 904 | // TODO: Rewrite changeLogin!!! |
| 905 | $forlife = $this->changeLogin($page, $user, $mmlist, Post::t('login_X')); |
| 906 | if ($forlife) { |
| 907 | pl_redirect('member/' . $forlife); |
| 908 | } |
| 909 | } |
| 910 | |
| 911 | // Update user info |
| 912 | $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); |
| 913 | $from_email = $user['email']; |
| 914 | if ($user['origine'] != 'X') { |
| 915 | $user['nom'] = Post::v('nom'); |
| 916 | $user['prenom'] = (Post::v('origine') == 'ext') ? Post::v('prenom') : ''; |
| 917 | $user['sexe'] = (Post::v('origine') == 'ext') ? Post::v('sexe') : 0; |
| 918 | $user['origine'] = Post::v('origine'); |
| 919 | XDB::query('UPDATE groupex.membres |
| 920 | SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?} |
| 921 | WHERE uid={?} AND asso_id={?}', |
| 922 | $user['prenom'], $user['nom'], Post::v('email'), |
| 923 | $user['sexe'], $user['origine'], |
| 924 | $user['uid'], $globals->asso('id')); |
| 925 | $user['email'] = Post::v('email'); |
| 926 | $user['email2'] = Post::v('email'); |
| 927 | $page->trigSuccess('Données de l\'utilisateur mise à jour.'); |
| 928 | } |
| 929 | |
| 930 | $perms = Post::i('is_admin'); |
| 931 | $comm = Post::t('comm'); |
| 932 | if ($user['perms'] != $perms || $user['comm'] != $comm) { |
| 933 | XDB::query('UPDATE groupex.membres |
| 934 | SET perms={?}, comm={?} |
| 935 | WHERE uid={?} AND asso_id={?}', |
| 936 | $perms ? 'admin' : 'membre', $comm, |
| 937 | $user['uid'], $globals->asso('id')); |
| 938 | if ($perms != $user['perms']) { |
| 939 | $page->trigSuccess('Permissions modifiées !'); |
| 940 | } |
| 941 | if ($comm != $user['comm']) { |
| 942 | $page->trigSuccess('Commentaire mis à jour.'); |
| 943 | } |
| 944 | $user['perms'] = $perms; |
| 945 | $user['comm'] = $comm; |
| 946 | } |
| 947 | |
| 948 | // Update ML subscriptions |
| 949 | foreach (Env::v('ml1', array()) as $ml => $state) { |
| 950 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
| 951 | if ($ask == $state) { |
| 952 | if ($state && $email_changed) { |
| 953 | $mmlist->replace_email($ml, $from_email, $user['email2']); |
| 954 | $page->trigSuccess("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour."); |
| 955 | } |
| 956 | continue; |
| 957 | } |
| 958 | if ($state == '1') { |
| 959 | $page->trigWarning("{$user['prenom']} {$user['nom']} a " |
| 960 | ."actuellement une demande d'inscription en " |
| 961 | ."cours sur <strong>$ml@</strong> !!!"); |
| 962 | } elseif ($ask) { |
| 963 | $mmlist->mass_subscribe($ml, Array($user['email2'])); |
| 964 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml@."); |
| 965 | } else { |
| 966 | if ($email_changed) { |
| 967 | $mmlist->mass_unsubscribe($ml, Array($from_email)); |
| 968 | } else { |
| 969 | $mmlist->mass_unsubscribe($ml, Array($user['email2'])); |
| 970 | } |
| 971 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@."); |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | // Change subscriptioin to aliases |
| 976 | foreach (Env::v('ml3', array()) as $ml => $state) { |
| 977 | $ask = !empty($_REQUEST['ml4'][$ml]); |
| 978 | if($state == $ask) continue; |
| 979 | if($ask) { |
| 980 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
| 981 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
| 982 | $user['email'], $ml); |
| 983 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml."); |
| 984 | } else { |
| 985 | XDB::query("DELETE FROM virtual_redirect |
| 986 | USING virtual_redirect |
| 987 | INNER JOIN virtual USING(vid) |
| 988 | WHERE redirect={?} AND alias={?}", |
| 989 | $user['email'], $ml); |
| 990 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml."); |
| 991 | } |
| 992 | } |
| 993 | } |
| 994 | |
| 995 | $page->assign('user', $user); |
| 996 | $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); |
| 997 | $page->assign('alias', $user->emailAliases($globals->asso('mail_domain'), 'user', true)); |
| 998 | } |
| 999 | |
| 1000 | function handler_rss(&$page, $user = null, $hash = null) |
| 1001 | { |
| 1002 | global $globals; |
| 1003 | $page->assign('asso', $globals->asso()); |
| 1004 | |
| 1005 | $this->load('feed.inc.php'); |
| 1006 | $feed = new XnetGrpEventFeed(); |
| 1007 | return $feed->run($page, $user, $hash, false); |
| 1008 | } |
| 1009 | |
| 1010 | private function upload_image(PlPage &$page, PlUpload &$upload) |
| 1011 | { |
| 1012 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { |
| 1013 | return true; |
| 1014 | } |
| 1015 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { |
| 1016 | $page->trigError('Impossible de télécharger l\'image'); |
| 1017 | return false; |
| 1018 | } elseif (!$upload->isType('image')) { |
| 1019 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
| 1020 | $upload->rm(); |
| 1021 | return false; |
| 1022 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { |
| 1023 | $page->trigError('Impossible de retraiter l\'image'); |
| 1024 | return false; |
| 1025 | } |
| 1026 | return true; |
| 1027 | } |
| 1028 | |
| 1029 | function handler_photo_announce(&$page, $eid = null) { |
| 1030 | if ($eid) { |
| 1031 | $res = XDB::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid); |
| 1032 | if ($res->numRows()) { |
| 1033 | $photo = $res->fetchOneAssoc(); |
| 1034 | header('Content-Type: image/' . $photo['attachmime']); |
| 1035 | echo $photo['attach']; |
| 1036 | exit; |
| 1037 | } |
| 1038 | } else { |
| 1039 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
| 1040 | if ($upload->exists() && $upload->isType('image')) { |
| 1041 | header('Content-Type: ' . $upload->contentType()); |
| 1042 | echo $upload->getContents(); |
| 1043 | exit; |
| 1044 | } |
| 1045 | } |
| 1046 | global $globals; |
| 1047 | header('Content-Type: image/png'); |
| 1048 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); |
| 1049 | exit; |
| 1050 | } |
| 1051 | |
| 1052 | function handler_edit_announce(&$page, $aid = null) |
| 1053 | { |
| 1054 | global $globals, $platal; |
| 1055 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
| 1056 | $page->assign('new', is_null($aid)); |
| 1057 | $art = array(); |
| 1058 | |
| 1059 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
| 1060 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
| 1061 | S::assert_xsrf_token(); |
| 1062 | |
| 1063 | if (!is_null($aid)) { |
| 1064 | $art['id'] = $aid; |
| 1065 | } |
| 1066 | $art['titre'] = Post::v('titre'); |
| 1067 | $art['texte'] = Post::v('texte'); |
| 1068 | $art['contacts'] = Post::v('contacts'); |
| 1069 | $art['promo_min'] = Post::i('promo_min'); |
| 1070 | $art['promo_max'] = Post::i('promo_max'); |
| 1071 | $art['nom'] = S::v('nom'); |
| 1072 | $art['prenom'] = S::v('prenom'); |
| 1073 | $art['promo'] = S::v('promo'); |
| 1074 | $art['hruid'] = S::user()->login(); |
| 1075 | $art['peremption'] = Post::v('peremption'); |
| 1076 | $art['public'] = Post::has('public'); |
| 1077 | $art['xorg'] = Post::has('xorg'); |
| 1078 | $art['nl'] = Post::has('nl'); |
| 1079 | $art['event'] = Post::v('event'); |
| 1080 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
| 1081 | $this->upload_image($page, $upload); |
| 1082 | |
| 1083 | $art['contact_html'] = $art['contacts']; |
| 1084 | if ($art['event']) { |
| 1085 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; |
| 1086 | } |
| 1087 | |
| 1088 | if (!$art['public'] && |
| 1089 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
| 1090 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
| 1091 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) |
| 1092 | { |
| 1093 | $page->trigError("L'intervalle de promotions est invalide."); |
| 1094 | Post::kill('valid'); |
| 1095 | } |
| 1096 | |
| 1097 | if (!trim($art['titre']) || !trim($art['texte'])) { |
| 1098 | $page->trigError("L'article doit avoir un titre et un contenu."); |
| 1099 | Post::kill('valid'); |
| 1100 | } |
| 1101 | |
| 1102 | if (Post::v('valid') == 'Supprimer l\'image') { |
| 1103 | $upload->rm(); |
| 1104 | Post::kill('valid'); |
| 1105 | } |
| 1106 | $art['photo'] = $upload->exists() || Post::i('photo'); |
| 1107 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { |
| 1108 | XDB::query("DELETE FROM groupex.announces_photo WHERE eid = {?}", $aid); |
| 1109 | $upload->rm(); |
| 1110 | Post::kill('valid'); |
| 1111 | $art['photo'] = false; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | if (Post::v('valid') == 'Enregistrer') { |
| 1116 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
| 1117 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); |
| 1118 | $flags = new PlFlagSet(); |
| 1119 | if ($art['public']) { |
| 1120 | $flags->addFlag('public'); |
| 1121 | } |
| 1122 | if ($art['photo']) { |
| 1123 | $flags->addFlag('photo'); |
| 1124 | } |
| 1125 | if (is_null($aid)) { |
| 1126 | $fulltext = $art['texte']; |
| 1127 | if (!empty($art['contact_html'])) { |
| 1128 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; |
| 1129 | } |
| 1130 | $post = null;/* |
| 1131 | if ($globals->asso('forum')) { |
| 1132 | require_once 'banana/forum.inc.php'; |
| 1133 | $banana = new ForumsBanana(S::user()); |
| 1134 | $post = $banana->post($globals->asso('forum'), null, |
| 1135 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); |
| 1136 | }*/ |
| 1137 | XDB::query("INSERT INTO groupex.announces |
| 1138 | (user_id, asso_id, create_date, titre, texte, contacts, |
| 1139 | peremption, promo_min, promo_max, flags, post_id) |
| 1140 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", |
| 1141 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
| 1142 | $art['peremption'], $promo_min, $promo_max, $flags, $post); |
| 1143 | $aid = XDB::insertId(); |
| 1144 | if ($art['photo']) { |
| 1145 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); |
| 1146 | XDB::execute("INSERT INTO groupex.announces_photo |
| 1147 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", |
| 1148 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
| 1149 | } |
| 1150 | if ($art['xorg']) { |
| 1151 | require_once('validations.inc.php'); |
| 1152 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
| 1153 | $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(), |
| 1154 | $upload); |
| 1155 | $article->submit(); |
| 1156 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
| 1157 | } else if ($upload && $upload->exists()) { |
| 1158 | $upload->rm(); |
| 1159 | } |
| 1160 | if ($art['nl']) { |
| 1161 | require_once('validations.inc.php'); |
| 1162 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
| 1163 | $art['texte'], $art['contact_html']); |
| 1164 | $article->submit(); |
| 1165 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
| 1166 | } |
| 1167 | } else { |
| 1168 | XDB::query("UPDATE groupex.announces |
| 1169 | SET titre={?}, texte={?}, contacts={?}, peremption={?}, |
| 1170 | promo_min={?}, promo_max={?}, flags={?} |
| 1171 | WHERE id={?} AND asso_id={?}", |
| 1172 | $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], |
| 1173 | $promo_min, $promo_max, $flags, |
| 1174 | $art['id'], $globals->asso('id')); |
| 1175 | if ($art['photo'] && $upload->exists()) { |
| 1176 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); |
| 1177 | XDB::execute("REPLACE INTO groupex.announces_photo |
| 1178 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", |
| 1179 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
| 1180 | $upload->rm(); |
| 1181 | } |
| 1182 | } |
| 1183 | } |
| 1184 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { |
| 1185 | pl_redirect(""); |
| 1186 | } |
| 1187 | |
| 1188 | if (empty($art) && !is_null($aid)) { |
| 1189 | $res = XDB::query("SELECT a.*, FIND_IN_SET('public', a.flags) AS public, |
| 1190 | FIND_IN_SET('photo', a.flags) AS photo |
| 1191 | FROM groupex.announces AS a |
| 1192 | WHERE asso_id = {?} AND a.id = {?}", |
| 1193 | $globals->asso('id'), $aid); |
| 1194 | if ($res->numRows()) { |
| 1195 | $art = $res->fetchOneAssoc(); |
| 1196 | $art['contact_html'] = $art['contacts']; |
| 1197 | } else { |
| 1198 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
| 1199 | } |
| 1200 | } |
| 1201 | |
| 1202 | if (is_null($aid)) { |
| 1203 | $events = XDB::iterator("SELECT * |
| 1204 | FROM groupex.evenements |
| 1205 | WHERE asso_id = {?} AND archive = 0", |
| 1206 | $globals->asso('id')); |
| 1207 | if ($events->total()) { |
| 1208 | $page->assign('events', $events); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
| 1213 | $page->assign('art', $art); |
| 1214 | $page->assign_by_ref('upload', $upload); |
| 1215 | } |
| 1216 | |
| 1217 | function handler_admin_announce(&$page) |
| 1218 | { |
| 1219 | global $globals; |
| 1220 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
| 1221 | |
| 1222 | if (Env::has('del')) { |
| 1223 | S::assert_xsrf_token(); |
| 1224 | XDB::execute("DELETE FROM groupex.announces |
| 1225 | WHERE id = {?} AND asso_id = {?}", |
| 1226 | Env::i('del'), $globals->asso('id')); |
| 1227 | } |
| 1228 | $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime |
| 1229 | FROM groupex.announces AS a |
| 1230 | WHERE a.asso_id = {?} |
| 1231 | ORDER BY a.peremption DESC", |
| 1232 | $globals->asso('id')); |
| 1233 | $page->assign('articles', $res); |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
| 1238 | ?> |