| 1 | <?php |
| 2 | /*************************************************************************** |
| 3 | * Copyright (C) 2003-2006 Polytechnique.org * |
| 4 | * http://opensource.polytechnique.org/ * |
| 5 | * * |
| 6 | * This program is free software; you can redistribute it and/or modify * |
| 7 | * it under the terms of the GNU General Public License as published by * |
| 8 | * the Free Software Foundation; either version 2 of the License, or * |
| 9 | * (at your option) any later version. * |
| 10 | * * |
| 11 | * This program is distributed in the hope that it will be useful, * |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 | * GNU General Public License for more details. * |
| 15 | * * |
| 16 | * You should have received a copy of the GNU General Public License * |
| 17 | * along with this program; if not, write to the Free Software * |
| 18 | * Foundation, Inc., * |
| 19 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 20 | ***************************************************************************/ |
| 21 | |
| 22 | class ProfileModule extends PLModule |
| 23 | { |
| 24 | function handlers() |
| 25 | { |
| 26 | return array( |
| 27 | 'photo' => $this->make_hook('photo', AUTH_PUBLIC), |
| 28 | 'photo/change' => $this->make_hook('photo_change', AUTH_MDP), |
| 29 | |
| 30 | 'fiche.php' => $this->make_hook('fiche', AUTH_PUBLIC), |
| 31 | 'profile' => $this->make_hook('profile', AUTH_PUBLIC), |
| 32 | 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), |
| 33 | 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), |
| 34 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
| 35 | |
| 36 | 'referent' => $this->make_hook('referent', AUTH_COOKIE), |
| 37 | 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE), |
| 38 | |
| 39 | 'trombi' => $this->make_hook('trombi', AUTH_COOKIE), |
| 40 | |
| 41 | 'vcard' => $this->make_hook('vcard', AUTH_COOKIE), |
| 42 | 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'), |
| 43 | 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'), |
| 44 | 'admin/formations' => $this->make_hook('admin_formations', AUTH_MDP, 'admin'), |
| 45 | 'admin/groupes-x' => $this->make_hook('admin_groupesx', AUTH_MDP, 'admin'), |
| 46 | 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'), |
| 47 | |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | /* XXX COMPAT */ |
| 52 | function handler_fiche(&$page) |
| 53 | { |
| 54 | return $this->handler_profile($page, Env::v('user')); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | function _trombi_getlist($offset, $limit) |
| 59 | { |
| 60 | $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" ); |
| 61 | |
| 62 | $res = XDB::query( |
| 63 | "SELECT COUNT(*) |
| 64 | FROM auth_user_md5 AS u |
| 65 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
| 66 | $where"); |
| 67 | $pnb = $res->fetchOneCell(); |
| 68 | |
| 69 | $res = XDB::query( |
| 70 | "SELECT promo, user_id, a.alias AS forlife, |
| 71 | IF (nom_usage='', nom, nom_usage) AS nom, prenom |
| 72 | FROM photo AS p |
| 73 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
| 74 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
| 75 | $where |
| 76 | ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
| 77 | |
| 78 | return array($pnb, $res->fetchAllAssoc()); |
| 79 | } |
| 80 | |
| 81 | function handler_photo(&$page, $x = null, $req = null) |
| 82 | { |
| 83 | if (is_null($x)) { |
| 84 | return PL_NOT_FOUND; |
| 85 | } |
| 86 | |
| 87 | $res = XDB::query("SELECT id, pub FROM aliases |
| 88 | LEFT JOIN photo ON(id = uid) |
| 89 | WHERE alias = {?}", $x); |
| 90 | list($uid, $photo_pub) = $res->fetchOneRow(); |
| 91 | |
| 92 | if ($req && S::logged()) { |
| 93 | include 'validations.inc.php'; |
| 94 | $myphoto = PhotoReq::get_request($uid); |
| 95 | Header('Content-type: image/'.$myphoto->mimetype); |
| 96 | echo $myphoto->data; |
| 97 | } else { |
| 98 | $res = XDB::query( |
| 99 | "SELECT attachmime, attach |
| 100 | FROM photo |
| 101 | WHERE uid={?}", $uid); |
| 102 | |
| 103 | if ((list($type, $data) = $res->fetchOneRow()) |
| 104 | && ($photo_pub == 'public' || S::logged())) { |
| 105 | Header("Content-type: image/$type"); |
| 106 | echo $data; |
| 107 | } else { |
| 108 | Header('Content-type: image/png'); |
| 109 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
| 110 | } |
| 111 | } |
| 112 | exit; |
| 113 | } |
| 114 | |
| 115 | function handler_photo_change(&$page) |
| 116 | { |
| 117 | $page->changeTpl('trombino.tpl'); |
| 118 | |
| 119 | require_once('validations.inc.php'); |
| 120 | |
| 121 | $trombi_x = '/home/web/trombino/photos'.S::v('promo') |
| 122 | .'/'.S::v('forlife').'.jpg'; |
| 123 | |
| 124 | if (Env::has('upload')) { |
| 125 | $file = isset($_FILES['userfile']['tmp_name']) |
| 126 | ? $_FILES['userfile']['tmp_name'] |
| 127 | : Env::v('photo'); |
| 128 | if ($data = file_get_contents($file)) { |
| 129 | if ($myphoto = new PhotoReq(S::v('uid'), $data)) { |
| 130 | $myphoto->submit(); |
| 131 | } |
| 132 | } else { |
| 133 | $page->trig('Fichier inexistant ou vide'); |
| 134 | } |
| 135 | } elseif (Env::has('trombi')) { |
| 136 | $myphoto = new PhotoReq(S::v('uid'), |
| 137 | file_get_contents($trombi_x)); |
| 138 | if ($myphoto) { |
| 139 | $myphoto->commit(); |
| 140 | $myphoto->clean(); |
| 141 | } |
| 142 | } elseif (Env::v('suppr')) { |
| 143 | XDB::execute('DELETE FROM photo WHERE uid = {?}', |
| 144 | S::v('uid')); |
| 145 | XDB::execute('DELETE FROM requests |
| 146 | WHERE user_id = {?} AND type="photo"', |
| 147 | S::v('uid')); |
| 148 | } elseif (Env::v('cancel')) { |
| 149 | $sql = XDB::query('DELETE FROM requests |
| 150 | WHERE user_id={?} AND type="photo"', |
| 151 | S::v('uid')); |
| 152 | } |
| 153 | |
| 154 | $sql = XDB::query('SELECT COUNT(*) FROM requests |
| 155 | WHERE user_id={?} AND type="photo"', |
| 156 | S::v('uid')); |
| 157 | $page->assign('submited', $sql->fetchOneCell()); |
| 158 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
| 159 | } |
| 160 | |
| 161 | function handler_profile(&$page, $x = null) |
| 162 | { |
| 163 | if (is_null($x)) { |
| 164 | return PL_NOT_FOUND; |
| 165 | } |
| 166 | |
| 167 | global $globals; |
| 168 | require_once 'user.func.inc.php'; |
| 169 | |
| 170 | $page->changeTpl('fiche.tpl', SIMPLE); |
| 171 | |
| 172 | $view = 'private'; |
| 173 | if (!S::logged() || Env::v('view') == 'public') $view = 'public'; |
| 174 | if (S::logged() && Env::v('view') == 'ax') $view = 'ax'; |
| 175 | |
| 176 | if (is_numeric($x)) { |
| 177 | $res = XDB::query( |
| 178 | "SELECT alias |
| 179 | FROM aliases AS a |
| 180 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
| 181 | WHERE matricule={?}", $x); |
| 182 | $login = $res->fetchOneCell(); |
| 183 | } else { |
| 184 | $login = get_user_forlife($x); |
| 185 | } |
| 186 | |
| 187 | if (empty($login)) { |
| 188 | return PL_NOT_FOUND; |
| 189 | } |
| 190 | |
| 191 | $new = Env::v('modif') == 'new'; |
| 192 | $user = get_user_details($login, S::v('uid'), $view); |
| 193 | $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; |
| 194 | $page->assign('xorg_title', $title); |
| 195 | |
| 196 | // photo |
| 197 | |
| 198 | $photo = 'photo/'.$user['forlife'].($new ? '/req' : ''); |
| 199 | |
| 200 | if (!isset($user['y']) and !isset($user['x'])) { |
| 201 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
| 202 | } |
| 203 | if (!isset($user['y']) or $user['y'] < 1) $user['y']=1; |
| 204 | if (!isset($user['x']) or $user['x'] < 1) $user['x']=1; |
| 205 | if ($user['x'] > 240) { |
| 206 | $user['y'] = (integer)($user['y']*240/$user['x']); |
| 207 | $user['x'] = 240; |
| 208 | } |
| 209 | if ($user['y'] > 300) { |
| 210 | $user['x'] = (integer)($user['x']*300/$user['y']); |
| 211 | $user['y'] = 300; |
| 212 | } |
| 213 | if ($user['x'] < 160) { |
| 214 | $user['y'] = (integer)($user['y']*160/$user['x']); |
| 215 | $user['x'] = 160; |
| 216 | } |
| 217 | |
| 218 | $page->assign('logged', has_user_right('private', $view)); |
| 219 | if (!has_user_right($user['photo_pub'], $view)) { |
| 220 | $photo = ""; |
| 221 | } |
| 222 | |
| 223 | $page->assign_by_ref('x', $user); |
| 224 | $page->assign('photo_url', $photo); |
| 225 | // alias virtual |
| 226 | $res = XDB::query( |
| 227 | "SELECT alias |
| 228 | FROM virtual |
| 229 | INNER JOIN virtual_redirect USING(vid) |
| 230 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
| 231 | WHERE ( redirect={?} OR redirect={?} ) |
| 232 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
| 233 | S::v('uid'), |
| 234 | $user['forlife'].'@'.$globals->mail->domain, |
| 235 | $user['forlife'].'@'.$globals->mail->domain2); |
| 236 | $page->assign('virtualalias', $res->fetchOneCell()); |
| 237 | |
| 238 | $page->addJsLink('close_on_esc.js'); |
| 239 | } |
| 240 | |
| 241 | function handler_p_edit(&$page, $opened_tab = 'general') |
| 242 | { |
| 243 | global $globals; |
| 244 | |
| 245 | $page->changeTpl('profil.tpl'); |
| 246 | |
| 247 | $page->addCssLink('profil.css'); |
| 248 | $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); |
| 249 | |
| 250 | require_once 'tabs.inc.php'; |
| 251 | require_once 'profil.func.inc.php'; |
| 252 | require_once 'synchro_ax.inc.php'; |
| 253 | |
| 254 | if (Post::has('register_from_ax_question')) { |
| 255 | XDB::query('UPDATE auth_user_quick |
| 256 | SET profile_from_ax = 1 |
| 257 | WHERE user_id = {?}', |
| 258 | S::v('uid')); |
| 259 | } |
| 260 | |
| 261 | if (is_ax_key_missing()) { |
| 262 | $page->assign('no_private_key', true); |
| 263 | } |
| 264 | |
| 265 | if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) { |
| 266 | ax_synchronize(S::v('bestalias'), S::v('uid')); |
| 267 | $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com'); |
| 268 | } |
| 269 | |
| 270 | // pour tous les tabs, la date de naissance pour verifier |
| 271 | // quelle est bien rentree et la date. |
| 272 | $res = XDB::query( |
| 273 | "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y') |
| 274 | FROM auth_user_md5 |
| 275 | WHERE user_id={?}", S::v('uid')); |
| 276 | list($naissance, $date_modif_profil) = $res->fetchOneRow(); |
| 277 | |
| 278 | // lorsqu'on n'a pas la date de naissance en base de données |
| 279 | if (!$naissance) { |
| 280 | // la date de naissance n'existait pas et vient d'être soumise dans la variable |
| 281 | if (Env::has('birth')) { |
| 282 | //en cas d'erreur : |
| 283 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) { |
| 284 | $page->assign('etat_naissance', 'query'); |
| 285 | $page->trig('Date de naissance incorrecte ou incohérente.'); |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | //sinon |
| 290 | $birth = sprintf("%s-%s-%s", substr(Env::v('birth'), 4, 4), |
| 291 | substr(Env::v('birth'), 2, 2), |
| 292 | substr(Env::v('birth'), 0, 2)); |
| 293 | XDB::execute("UPDATE auth_user_md5 |
| 294 | SET naissance={?} |
| 295 | WHERE user_id={?}", $birth, |
| 296 | S::v('uid')); |
| 297 | $page->assign('etat_naissance', 'ok'); |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | $page->assign('etat_naissance', 'query'); |
| 302 | return; // on affiche le formulaire pour naissance |
| 303 | } |
| 304 | |
| 305 | //doit-on faire un update ? |
| 306 | if (Env::has('modifier') || Env::has('suivant')) { |
| 307 | require_once "profil/get_{$opened_tab}.inc.php"; |
| 308 | require_once "profil/verif_{$opened_tab}.inc.php"; |
| 309 | |
| 310 | if($page->nb_errs()) { |
| 311 | require_once "profil/assign_{$opened_tab}.inc.php"; |
| 312 | $page->assign('onglet', $opened_tab); |
| 313 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
| 314 | return; |
| 315 | } |
| 316 | |
| 317 | $date=date("Y-m-j");//nouvelle date de mise a jour |
| 318 | |
| 319 | //On sauvegarde l'uid pour l'AX |
| 320 | /* on sauvegarde les changements dans user_changes : |
| 321 | * on a juste besoin d'insérer le user_id de la personne dans la table |
| 322 | */ |
| 323 | XDB::execute('REPLACE INTO user_changes SET user_id={?}', |
| 324 | S::v('uid')); |
| 325 | |
| 326 | if (!S::has('suid')) { |
| 327 | require_once 'notifs.inc.php'; |
| 328 | register_watch_op(S::v('uid'), WATCH_FICHE); |
| 329 | } |
| 330 | |
| 331 | // mise a jour des champs relatifs au tab ouvert |
| 332 | require_once "profil/update_{$opened_tab}.inc.php"; |
| 333 | |
| 334 | $log =& S::v('log'); |
| 335 | $log->log('profil', $opened_tab); |
| 336 | $page->assign('etat_update', 'ok'); |
| 337 | } |
| 338 | |
| 339 | if (Env::has('suivant')) { |
| 340 | pl_redirect('profile/edit/' . get_next_tab($opened_tab)); |
| 341 | } |
| 342 | |
| 343 | require_once "profil/get_{$opened_tab}.inc.php"; |
| 344 | require_once "profil/verif_{$opened_tab}.inc.php"; |
| 345 | require_once "profil/assign_{$opened_tab}.inc.php"; |
| 346 | |
| 347 | $page->assign('onglet', $opened_tab); |
| 348 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
| 349 | |
| 350 | return; |
| 351 | } |
| 352 | |
| 353 | function handler_p_orange(&$page) |
| 354 | { |
| 355 | $page->changeTpl('orange.tpl'); |
| 356 | |
| 357 | require_once 'validations.inc.php'; |
| 358 | require_once 'xorg.misc.inc.php'; |
| 359 | |
| 360 | $res = XDB::query( |
| 361 | "SELECT u.promo, u.promo_sortie |
| 362 | FROM auth_user_md5 AS u |
| 363 | WHERE user_id={?}", S::v('uid')); |
| 364 | |
| 365 | list($promo, $promo_sortie_old) = $res->fetchOneRow(); |
| 366 | $page->assign('promo_sortie_old', $promo_sortie_old); |
| 367 | $page->assign('promo', $promo); |
| 368 | |
| 369 | if (!Env::has('promo_sortie')) { |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | $promo_sortie = Env::i('promo_sortie'); |
| 374 | |
| 375 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
| 376 | $page->trig('L\'année de sortie doit être un nombre de quatre chiffres'); |
| 377 | } |
| 378 | elseif ($promo_sortie < $promo + 3) { |
| 379 | $page->trig('Trop tôt'); |
| 380 | } |
| 381 | elseif ($promo_sortie == $promo_sortie_old) { |
| 382 | $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.'); |
| 383 | } |
| 384 | elseif ($promo_sortie == $promo + 3) { |
| 385 | XDB::execute( |
| 386 | "UPDATE auth_user_md5 set promo_sortie={?} |
| 387 | WHERE user_id={?}", $promo_sortie, S::v('uid')); |
| 388 | $page->trig('Ton statut "orange" a été supprimé.'); |
| 389 | $page->assign('promo_sortie_old', $promo_sortie); |
| 390 | } |
| 391 | else { |
| 392 | $page->assign('promo_sortie', $promo_sortie); |
| 393 | |
| 394 | if (Env::has('submit')) { |
| 395 | $myorange = new OrangeReq(S::v('uid'), |
| 396 | $promo_sortie); |
| 397 | $myorange->submit(); |
| 398 | $page->assign('myorange', $myorange); |
| 399 | } |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | function handler_referent(&$page, $x = null) |
| 404 | { |
| 405 | require_once 'user.func.inc.php'; |
| 406 | |
| 407 | if (is_null($x)) { |
| 408 | return PL_NOT_FOUND; |
| 409 | } |
| 410 | |
| 411 | $page->changeTpl('fiche_referent.tpl', SIMPLE); |
| 412 | |
| 413 | $res = XDB::query( |
| 414 | "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias |
| 415 | FROM auth_user_md5 AS u |
| 416 | INNER JOIN aliases AS a ON (u.user_id=a.id |
| 417 | AND FIND_IN_SET('bestalias', a.flags)) |
| 418 | INNER JOIN aliases AS a1 ON (u.user_id=a1.id |
| 419 | AND a1.alias = {?} |
| 420 | AND a1.type!='homonyme')", $x); |
| 421 | |
| 422 | if ($res->numRows() != 1) { |
| 423 | return PL_NOT_FOUND; |
| 424 | } |
| 425 | |
| 426 | list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow(); |
| 427 | |
| 428 | $page->assign('prenom', $prenom); |
| 429 | $page->assign('nom', $nom); |
| 430 | $page->assign('promo', $promo); |
| 431 | $page->assign('cv', $cv); |
| 432 | $page->assign('bestalias', $bestalias); |
| 433 | $page->assign('adr_pro', get_user_details_pro($user_id)); |
| 434 | |
| 435 | ///// recuperations infos referent |
| 436 | |
| 437 | //expertise |
| 438 | $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id); |
| 439 | $page->assign('expertise', $res->fetchOneCell()); |
| 440 | |
| 441 | //secteurs |
| 442 | $secteurs = $ss_secteurs = Array(); |
| 443 | $res = XDB::iterRow( |
| 444 | "SELECT s.label, ss.label |
| 445 | FROM mentor_secteurs AS m |
| 446 | LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) |
| 447 | LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id) |
| 448 | WHERE uid = {?}", $user_id); |
| 449 | while (list($sec, $ssec) = $res->next()) { |
| 450 | $secteurs[] = $sec; |
| 451 | $ss_secteurs[] = $ssec; |
| 452 | } |
| 453 | $page->assign_by_ref('secteurs', $secteurs); |
| 454 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
| 455 | |
| 456 | //pays |
| 457 | $res = XDB::query( |
| 458 | "SELECT gp.pays |
| 459 | FROM mentor_pays AS m |
| 460 | LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2) |
| 461 | WHERE uid = {?}", $user_id); |
| 462 | $page->assign('pays', $res->fetchColumn()); |
| 463 | |
| 464 | $page->addJsLink('close_on_esc.js'); |
| 465 | } |
| 466 | |
| 467 | function handler_ref_search(&$page) |
| 468 | { |
| 469 | $page->changeTpl('referent.tpl'); |
| 470 | |
| 471 | $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro'); |
| 472 | |
| 473 | $secteur_sel = Post::v('secteur'); |
| 474 | $ss_secteur_sel = Post::v('ss_secteur'); |
| 475 | $pays_sel = Post::v('pays', '00'); |
| 476 | $expertise_champ = Post::v('expertise'); |
| 477 | |
| 478 | $page->assign('pays_sel', $pays_sel); |
| 479 | $page->assign('expertise_champ', $expertise_champ); |
| 480 | $page->assign('secteur_sel', $secteur_sel); |
| 481 | $page->assign('ss_secteur_sel', $ss_secteur_sel); |
| 482 | |
| 483 | //recuperation des noms de secteurs |
| 484 | $res = XDB::iterRow("SELECT id, label FROM emploi_secteur"); |
| 485 | $secteurs[''] = ''; |
| 486 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 487 | $secteurs[$tmp_id] = $tmp_label; |
| 488 | } |
| 489 | $page->assign_by_ref('secteurs', $secteurs); |
| 490 | |
| 491 | //on recupere les sous-secteurs si necessaire |
| 492 | $ss_secteurs[''] = ''; |
| 493 | if (!empty($secteur_sel)) { |
| 494 | $res = XDB::iterRow("SELECT id, label FROM emploi_ss_secteur |
| 495 | WHERE secteur = {?}", $secteur_sel); |
| 496 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 497 | $ss_secteurs[$tmp_id] = $tmp_label; |
| 498 | } |
| 499 | } |
| 500 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
| 501 | |
| 502 | //recuperation des noms de pays |
| 503 | $res = XDB::iterRow("SELECT a2, pays FROM geoloc_pays |
| 504 | WHERE pays <> '' ORDER BY pays"); |
| 505 | $pays['00'] = ''; |
| 506 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 507 | $pays[$tmp_id] = $tmp_label; |
| 508 | } |
| 509 | $page->assign_by_ref('pays', $pays); |
| 510 | |
| 511 | // nb de mentors |
| 512 | $res = XDB::query("SELECT count(*) FROM mentor"); |
| 513 | $page->assign('mentors_number', $res->fetchOneCell()); |
| 514 | |
| 515 | if (!Env::has('Chercher')) { |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | // On vient d'un formulaire |
| 520 | $where = array(); |
| 521 | |
| 522 | if ($pays_sel != '00') { |
| 523 | $where[] = "mp.pid = '".addslashes($pays_sel)."'"; |
| 524 | } |
| 525 | if ($secteur_sel) { |
| 526 | $where[] = "ms.secteur = '".addslashes($secteur_sel)."'"; |
| 527 | if ($ss_secteur_sel) { |
| 528 | $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'"; |
| 529 | } |
| 530 | } |
| 531 | if ($expertise_champ) { |
| 532 | $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')"; |
| 533 | } |
| 534 | |
| 535 | if ($where) { |
| 536 | $where = join(' AND ', $where); |
| 537 | |
| 538 | $sql = "SELECT m.uid, a.prenom, a.nom, a.promo, |
| 539 | l.alias AS bestalias, m.expertise, mp.pid, |
| 540 | ms.secteur, ms.ss_secteur |
| 541 | FROM mentor AS m |
| 542 | LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id) |
| 543 | INNER JOIN aliases AS l ON (a.user_id=l.id AND |
| 544 | FIND_IN_SET('bestalias', l.flags)) |
| 545 | LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid) |
| 546 | LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid) |
| 547 | WHERE $where |
| 548 | GROUP BY uid |
| 549 | ORDER BY RAND({?})"; |
| 550 | $res = XDB::iterator($sql, S::v('uid')); |
| 551 | |
| 552 | if ($res->total() == 0) { |
| 553 | $page->assign('recherche_trop_large', true); |
| 554 | return; |
| 555 | } |
| 556 | |
| 557 | $nb_max_res_total = 100; |
| 558 | $nb_max_res_ppage = 10; |
| 559 | |
| 560 | $curpage = Env::i('curpage', 1); |
| 561 | $personnes = array(); |
| 562 | $i = 0; |
| 563 | |
| 564 | while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) { |
| 565 | $the_page = intval($i / $nb_max_res_ppage) + 1; |
| 566 | if ($the_page == $curpage) { |
| 567 | $personnes[] = $pers; |
| 568 | } |
| 569 | $i ++; |
| 570 | } |
| 571 | |
| 572 | $page->assign('personnes', $personnes); |
| 573 | $page->assign('curpage', $curpage); |
| 574 | $page->assign('nb_pages_total', |
| 575 | intval($res->total() / $nb_max_res_ppage) + 1); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | function handler_p_usage(&$page) |
| 580 | { |
| 581 | $page->changeTpl('nomusage.tpl'); |
| 582 | |
| 583 | require_once 'validations.inc.php'; |
| 584 | require_once 'xorg.misc.inc.php'; |
| 585 | require_once dirname(__FILE__).'/../classes/Flagset.php'; |
| 586 | |
| 587 | $res = XDB::query( |
| 588 | "SELECT u.nom, u.nom_usage, u.flags, e.alias |
| 589 | FROM auth_user_md5 AS u |
| 590 | LEFT JOIN aliases AS e ON(u.user_id = e.id |
| 591 | AND FIND_IN_SET('usage', e.flags)) |
| 592 | WHERE user_id={?}", S::v('uid')); |
| 593 | |
| 594 | list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow(); |
| 595 | $flags = new flagset($flags); |
| 596 | $page->assign('usage_old', $usage_old); |
| 597 | $page->assign('alias_old', $alias_old); |
| 598 | |
| 599 | $nom_usage = replace_accent(trim(Env::v('nom_usage'))); |
| 600 | $nom_usage = strtoupper($nom_usage); |
| 601 | $page->assign('usage_req', $nom_usage); |
| 602 | |
| 603 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
| 604 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
| 605 | if ($nom_usage == $nom) { |
| 606 | $page->assign('same', true); |
| 607 | } else { // le nom de mariage est distinct du nom à l'X |
| 608 | // on calcule l'alias pour l'afficher |
| 609 | $reason = Env::v('reason'); |
| 610 | if ($reason == 'other') { |
| 611 | $reason = Env::v('other_reason'); |
| 612 | } |
| 613 | $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason); |
| 614 | $myusage->submit(); |
| 615 | $page->assign('myusage', $myusage); |
| 616 | } |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | function handler_trombi(&$page, $promo = null) |
| 621 | { |
| 622 | require_once 'trombi.inc.php'; |
| 623 | |
| 624 | $page->changeTpl('trombipromo.tpl'); |
| 625 | $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo'); |
| 626 | |
| 627 | if (is_null($promo)) { |
| 628 | return; |
| 629 | } |
| 630 | |
| 631 | $this->promo = $promo = intval($promo); |
| 632 | |
| 633 | if ($promo >= 1900 && $promo < intval(date('Y')) |
| 634 | || ($promo == -1 && S::has_perms())) |
| 635 | { |
| 636 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
| 637 | $trombi->hidePromo(); |
| 638 | $trombi->setAdmin(); |
| 639 | $page->assign_by_ref('trombi', $trombi); |
| 640 | } else { |
| 641 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | function format_adr($params, &$smarty) |
| 646 | { |
| 647 | // $adr1, $adr2, $adr3, $postcode, $city, $region, $country |
| 648 | extract($params['adr']); |
| 649 | $adr = trim($adr1); |
| 650 | $adr = trim("$adr\n$adr2"); |
| 651 | $adr = trim("$adr\n$adr3"); |
| 652 | $adr = explode("\n", quoted_printable_encode(";;$adr;$city;$region;$postcode;$country")); |
| 653 | return implode("\n", array_map('trim', $adr)); |
| 654 | } |
| 655 | |
| 656 | function handler_vcard(&$page, $x = null) |
| 657 | { |
| 658 | if (is_null($x)) { |
| 659 | return PL_NOT_FOUND; |
| 660 | } |
| 661 | |
| 662 | global $globals; |
| 663 | |
| 664 | if (substr($x, -4) == '.vcf') { |
| 665 | $x = substr($x, 0, strlen($x) - 4); |
| 666 | } |
| 667 | |
| 668 | $page->changeTpl('vcard.tpl', NO_SKIN); |
| 669 | require_once 'xorg.misc.inc.php'; |
| 670 | require_once 'user.func.inc.php'; |
| 671 | |
| 672 | $page->register_modifier('qp_enc', 'quoted_printable_encode'); |
| 673 | $page->register_function('format_adr', array($this, 'format_adr')); |
| 674 | |
| 675 | $login = get_user_forlife($x); |
| 676 | $user = get_user_details($login); |
| 677 | |
| 678 | // alias virtual |
| 679 | $res = XDB::query( |
| 680 | "SELECT alias |
| 681 | FROM virtual |
| 682 | INNER JOIN virtual_redirect USING(vid) |
| 683 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
| 684 | WHERE ( redirect={?} OR redirect={?} ) |
| 685 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
| 686 | S::v('uid'), |
| 687 | $user['forlife'].'@'.$globals->mail->domain, |
| 688 | $user['forlife'].'@'.$globals->mail->domain2); |
| 689 | |
| 690 | $user['virtualalias'] = $res->fetchOneCell(); |
| 691 | |
| 692 | $page->assign_by_ref('vcard', $user); |
| 693 | |
| 694 | header("Pragma: "); |
| 695 | header("Cache-Control: "); |
| 696 | header("Content-type: text/x-vcard\n"); |
| 697 | header("Content-Transfer-Encoding: Quoted-Printable\n"); |
| 698 | } |
| 699 | |
| 700 | function handler_admin_trombino(&$page, $uid = null, $action = null) { |
| 701 | $page->changeTpl('admin/admin_trombino.tpl'); |
| 702 | $page->assign('xorg_title','Polytechnique.org - Administration - Trombino'); |
| 703 | $page->assign('uid', $uid); |
| 704 | |
| 705 | $q = XDB::query( |
| 706 | "SELECT a.alias,promo |
| 707 | FROM auth_user_md5 AS u |
| 708 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' ) |
| 709 | WHERE user_id = {?}", $uid); |
| 710 | list($forlife, $promo) = $q->fetchOneRow(); |
| 711 | |
| 712 | switch ($action) { |
| 713 | |
| 714 | case "original": |
| 715 | header("Content-type: image/jpeg"); |
| 716 | readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg"); |
| 717 | exit; |
| 718 | break; |
| 719 | |
| 720 | case "new": |
| 721 | $data = file_get_contents($_FILES['userfile']['tmp_name']); |
| 722 | list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); |
| 723 | $mimetype = substr($_FILES['userfile']['type'], 6); |
| 724 | unlink($_FILES['userfile']['tmp_name']); |
| 725 | XDB::execute( |
| 726 | "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", |
| 727 | $uid, $mimetype, $data, $x, $y); |
| 728 | break; |
| 729 | |
| 730 | case "delete": |
| 731 | XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid); |
| 732 | break; |
| 733 | } |
| 734 | |
| 735 | $page->assign('forlife', $forlife); |
| 736 | } |
| 737 | function handler_admin_binets(&$page, $action = 'list', $id = null) { |
| 738 | require_once('../classes/PLTableEditor.php'); |
| 739 | $page->assign('xorg_title','Polytechnique.org - Administration - Binets'); |
| 740 | $page->assign('title', 'Gestion des binets'); |
| 741 | $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id'); |
| 742 | $table_editor->add_join_table('binets_ins','binet_id',true); |
| 743 | $table_editor->describe('text','intitulé',true); |
| 744 | $table_editor->apply($page, $action, $id); |
| 745 | } |
| 746 | function handler_admin_formations(&$page, $action = 'list', $id = null) { |
| 747 | require_once('../classes/PLTableEditor.php'); |
| 748 | $page->assign('xorg_title','Polytechnique.org - Administration - Formations'); |
| 749 | $page->assign('title', 'Gestion des formations'); |
| 750 | $table_editor = new PLTableEditor('admin/formations','applis_def','id'); |
| 751 | $table_editor->add_join_table('applis_ins','aid',true); |
| 752 | $table_editor->describe('text','intitulé',true); |
| 753 | $table_editor->describe('url','site web',false); |
| 754 | $table_editor->apply($page, $action, $id); |
| 755 | } |
| 756 | function handler_admin_groupesx(&$page, $action = 'list', $id = null) { |
| 757 | require_once('../classes/PLTableEditor.php'); |
| 758 | $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X'); |
| 759 | $page->assign('title', 'Gestion des Groupes X'); |
| 760 | $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id'); |
| 761 | $table_editor->add_join_table('groupesx_ins','gid',true); |
| 762 | $table_editor->describe('text','intitulé',true); |
| 763 | $table_editor->describe('url','site web',false); |
| 764 | $table_editor->apply($page, $action, $id); |
| 765 | } |
| 766 | function handler_admin_medals(&$page, $action = 'list', $id = null) { |
| 767 | require_once('../classes/PLTableEditor.php'); |
| 768 | $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions'); |
| 769 | $page->assign('title', 'Gestion des Distinctions'); |
| 770 | $table_editor = new PLTableEditor('admin/medals','profile_medals','id'); |
| 771 | $table_editor->describe('text', 'intitulé', true); |
| 772 | $table_editor->describe('img', 'nom de l\'image', false); |
| 773 | $table_editor->apply($page, $action, $id); |
| 774 | if ($id && $action == 'edit') { |
| 775 | $page->changeTpl('admin/gerer_decos.tpl'); |
| 776 | |
| 777 | $mid = $id; |
| 778 | |
| 779 | if (Post::v('act') == 'del') { |
| 780 | XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid')); |
| 781 | } elseif (Post::v('act') == 'new') { |
| 782 | XDB::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})', |
| 783 | $mid, max(array_keys(Post::v('grades', array(0))))+1); |
| 784 | } else { |
| 785 | foreach (Post::v('grades', array()) as $gid=>$text) { |
| 786 | XDB::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid); |
| 787 | } |
| 788 | } |
| 789 | $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid); |
| 790 | $page->assign('grades', $res); |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | ?> |