| 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 | ); |
| 43 | } |
| 44 | |
| 45 | /* XXX COMPAT */ |
| 46 | function handler_fiche(&$page) |
| 47 | { |
| 48 | return $this->handler_profile($page, Env::get('user')); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | function _trombi_getlist($offset, $limit) |
| 53 | { |
| 54 | $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" ); |
| 55 | |
| 56 | $res = XDB::query( |
| 57 | "SELECT COUNT(*) |
| 58 | FROM auth_user_md5 AS u |
| 59 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
| 60 | $where"); |
| 61 | $pnb = $res->fetchOneCell(); |
| 62 | |
| 63 | $res = XDB::query( |
| 64 | "SELECT promo, user_id, a.alias AS forlife, |
| 65 | IF (nom_usage='', nom, nom_usage) AS nom, prenom |
| 66 | FROM photo AS p |
| 67 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
| 68 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
| 69 | $where |
| 70 | ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
| 71 | |
| 72 | return array($pnb, $res->fetchAllAssoc()); |
| 73 | } |
| 74 | |
| 75 | function handler_photo(&$page, $x = null, $req = null) |
| 76 | { |
| 77 | if (is_null($x)) { |
| 78 | return PL_NOT_FOUND; |
| 79 | } |
| 80 | |
| 81 | $res = XDB::query("SELECT id, pub FROM aliases |
| 82 | LEFT JOIN photo ON(id = uid) |
| 83 | WHERE alias = {?}", $x); |
| 84 | list($uid, $photo_pub) = $res->fetchOneRow(); |
| 85 | |
| 86 | if ($req && logged()) { |
| 87 | include 'validations.inc.php'; |
| 88 | $myphoto = PhotoReq::get_request($uid); |
| 89 | Header('Content-type: image/'.$myphoto->mimetype); |
| 90 | echo $myphoto->data; |
| 91 | } else { |
| 92 | $res = XDB::query( |
| 93 | "SELECT attachmime, attach |
| 94 | FROM photo |
| 95 | WHERE uid={?}", $uid); |
| 96 | |
| 97 | if ((list($type, $data) = $res->fetchOneRow()) |
| 98 | && ($photo_pub == 'public' || logged())) { |
| 99 | Header("Content-type: image/$type"); |
| 100 | echo $data; |
| 101 | } else { |
| 102 | Header('Content-type: image/png'); |
| 103 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
| 104 | } |
| 105 | } |
| 106 | exit; |
| 107 | } |
| 108 | |
| 109 | function handler_photo_change(&$page) |
| 110 | { |
| 111 | $page->changeTpl('trombino.tpl'); |
| 112 | |
| 113 | require_once('validations.inc.php'); |
| 114 | |
| 115 | $trombi_x = '/home/web/trombino/photos'.Session::get('promo') |
| 116 | .'/'.Session::get('forlife').'.jpg'; |
| 117 | |
| 118 | if (Env::has('upload')) { |
| 119 | $file = isset($_FILES['userfile']['tmp_name']) |
| 120 | ? $_FILES['userfile']['tmp_name'] |
| 121 | : Env::get('photo'); |
| 122 | if ($data = file_get_contents($file)) { |
| 123 | if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) { |
| 124 | $myphoto->submit(); |
| 125 | } |
| 126 | } else { |
| 127 | $page->trig('Fichier inexistant ou vide'); |
| 128 | } |
| 129 | } elseif (Env::has('trombi')) { |
| 130 | $myphoto = new PhotoReq(Session::getInt('uid'), |
| 131 | file_get_contents($trombi_x)); |
| 132 | if ($myphoto) { |
| 133 | $myphoto->commit(); |
| 134 | $myphoto->clean(); |
| 135 | } |
| 136 | } elseif (Env::get('suppr')) { |
| 137 | XDB::execute('DELETE FROM photo WHERE uid = {?}', |
| 138 | Session::getInt('uid')); |
| 139 | XDB::execute('DELETE FROM requests |
| 140 | WHERE user_id = {?} AND type="photo"', |
| 141 | Session::getInt('uid')); |
| 142 | } elseif (Env::get('cancel')) { |
| 143 | $sql = XDB::query('DELETE FROM requests |
| 144 | WHERE user_id={?} AND type="photo"', |
| 145 | Session::getInt('uid')); |
| 146 | } |
| 147 | |
| 148 | $sql = XDB::query('SELECT COUNT(*) FROM requests |
| 149 | WHERE user_id={?} AND type="photo"', |
| 150 | Session::getInt('uid')); |
| 151 | $page->assign('submited', $sql->fetchOneCell()); |
| 152 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
| 153 | } |
| 154 | |
| 155 | function handler_profile(&$page, $x = null) |
| 156 | { |
| 157 | if (is_null($x)) { |
| 158 | return PL_NOT_FOUND; |
| 159 | } |
| 160 | |
| 161 | global $globals; |
| 162 | require_once 'user.func.inc.php'; |
| 163 | |
| 164 | $page->changeTpl('fiche.tpl'); |
| 165 | $page->assign('simple', true); |
| 166 | |
| 167 | $view = 'private'; |
| 168 | if (!logged() || Env::get('view') == 'public') $view = 'public'; |
| 169 | if (logged() && Env::get('view') == 'ax') $view = 'ax'; |
| 170 | |
| 171 | if (is_numeric($x)) { |
| 172 | $res = XDB::query( |
| 173 | "SELECT alias |
| 174 | FROM aliases AS a |
| 175 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
| 176 | WHERE matricule={?}", $x); |
| 177 | $login = $res->fetchOneCell(); |
| 178 | } else { |
| 179 | $login = get_user_forlife($x); |
| 180 | } |
| 181 | |
| 182 | if (empty($login)) { |
| 183 | return PL_NOT_FOUND; |
| 184 | } |
| 185 | |
| 186 | $new = Env::get('modif') == 'new'; |
| 187 | $user = get_user_details($login, Session::getInt('uid'), $view); |
| 188 | $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; |
| 189 | $page->assign('xorg_title', $title); |
| 190 | |
| 191 | // photo |
| 192 | |
| 193 | $photo = $globals->baseurl.'/photo/'.$user['forlife'].($new ? '/req' : ''); |
| 194 | |
| 195 | if (!isset($user['y']) and !isset($user['x'])) { |
| 196 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
| 197 | } |
| 198 | if (!isset($user['y']) or $user['y'] < 1) $user['y']=1; |
| 199 | if (!isset($user['x']) or $user['x'] < 1) $user['x']=1; |
| 200 | if ($user['x'] > 240) { |
| 201 | $user['y'] = (integer)($user['y']*240/$user['x']); |
| 202 | $user['x'] = 240; |
| 203 | } |
| 204 | if ($user['y'] > 300) { |
| 205 | $user['x'] = (integer)($user['x']*300/$user['y']); |
| 206 | $user['y'] = 300; |
| 207 | } |
| 208 | if ($user['x'] < 160) { |
| 209 | $user['y'] = (integer)($user['y']*160/$user['x']); |
| 210 | $user['x'] = 160; |
| 211 | } |
| 212 | |
| 213 | $page->assign('logged', has_user_right('private', $view)); |
| 214 | if (!has_user_right($user['photo_pub'], $view)) { |
| 215 | $photo = ""; |
| 216 | } |
| 217 | |
| 218 | $page->assign_by_ref('x', $user); |
| 219 | $page->assign('photo_url', $photo); |
| 220 | // alias virtual |
| 221 | $res = XDB::query( |
| 222 | "SELECT alias |
| 223 | FROM virtual |
| 224 | INNER JOIN virtual_redirect USING(vid) |
| 225 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
| 226 | WHERE ( redirect={?} OR redirect={?} ) |
| 227 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
| 228 | Session::getInt('uid'), |
| 229 | $user['forlife'].'@'.$globals->mail->domain, |
| 230 | $user['forlife'].'@'.$globals->mail->domain2); |
| 231 | $page->assign('virtualalias', $res->fetchOneCell()); |
| 232 | |
| 233 | $page->addJsLink('javascript/close_on_esc.js'); |
| 234 | } |
| 235 | |
| 236 | function handler_p_edit(&$page, $opened_tab = 'general') |
| 237 | { |
| 238 | global $globals; |
| 239 | |
| 240 | $page->changeTpl('profil.tpl'); |
| 241 | |
| 242 | $page->addCssLink('css/profil.css'); |
| 243 | $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); |
| 244 | |
| 245 | require_once 'tabs.inc.php'; |
| 246 | require_once 'profil.func.inc.php'; |
| 247 | require_once 'synchro_ax.inc.php'; |
| 248 | |
| 249 | if (Post::has('register_from_ax_question')) { |
| 250 | XDB::query('UPDATE auth_user_quick |
| 251 | SET profile_from_ax = 1 |
| 252 | WHERE user_id = {?}', |
| 253 | Session::getInt('uid')); |
| 254 | } |
| 255 | |
| 256 | if (is_ax_key_missing()) { |
| 257 | $page->assign('no_private_key', true); |
| 258 | } |
| 259 | |
| 260 | if (Env::get('synchro_ax') == 'confirm' && !is_ax_key_missing()) { |
| 261 | ax_synchronize(Session::get('bestalias'), Session::getInt('uid')); |
| 262 | $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com'); |
| 263 | } |
| 264 | |
| 265 | // pour tous les tabs, la date de naissance pour verifier |
| 266 | // quelle est bien rentree et la date. |
| 267 | $res = XDB::query( |
| 268 | "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y') |
| 269 | FROM auth_user_md5 |
| 270 | WHERE user_id={?}", Session::getInt('uid')); |
| 271 | list($naissance, $date_modif_profil) = $res->fetchOneRow(); |
| 272 | |
| 273 | // lorsqu'on n'a pas la date de naissance en base de données |
| 274 | if (!$naissance) { |
| 275 | // la date de naissance n'existait pas et vient d'être soumise dans la variable |
| 276 | if (Env::has('birth')) { |
| 277 | //en cas d'erreur : |
| 278 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) { |
| 279 | $page->assign('etat_naissance', 'query'); |
| 280 | $page->trig('Date de naissance incorrecte ou incohérente.'); |
| 281 | return; |
| 282 | } |
| 283 | |
| 284 | //sinon |
| 285 | $birth = sprintf("%s-%s-%s", substr(Env::get('birth'), 4, 4), |
| 286 | substr(Env::get('birth'), 2, 2), |
| 287 | substr(Env::get('birth'), 0, 2)); |
| 288 | XDB::execute("UPDATE auth_user_md5 |
| 289 | SET naissance={?} |
| 290 | WHERE user_id={?}", $birth, |
| 291 | Session::getInt('uid')); |
| 292 | $page->assign('etat_naissance', 'ok'); |
| 293 | return; |
| 294 | } |
| 295 | |
| 296 | $page->assign('etat_naissance', 'query'); |
| 297 | return; // on affiche le formulaire pour naissance |
| 298 | } |
| 299 | |
| 300 | //doit-on faire un update ? |
| 301 | if (Env::has('modifier') || Env::has('suivant')) { |
| 302 | require_once "profil/get_{$opened_tab}.inc.php"; |
| 303 | require_once "profil/verif_{$opened_tab}.inc.php"; |
| 304 | |
| 305 | if($page->nb_errs()) { |
| 306 | require_once "profil/assign_{$opened_tab}.inc.php"; |
| 307 | $page->assign('onglet', $opened_tab); |
| 308 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
| 309 | return; |
| 310 | } |
| 311 | |
| 312 | $date=date("Y-m-j");//nouvelle date de mise a jour |
| 313 | |
| 314 | //On sauvegarde l'uid pour l'AX |
| 315 | /* on sauvegarde les changements dans user_changes : |
| 316 | * on a juste besoin d'insérer le user_id de la personne dans la table |
| 317 | */ |
| 318 | XDB::execute('REPLACE INTO user_changes SET user_id={?}', |
| 319 | Session::getInt('uid')); |
| 320 | |
| 321 | if (!Session::has('suid')) { |
| 322 | require_once 'notifs.inc.php'; |
| 323 | register_watch_op(Session::getInt('uid'), WATCH_FICHE); |
| 324 | } |
| 325 | |
| 326 | // mise a jour des champs relatifs au tab ouvert |
| 327 | require_once "profil/update_{$opened_tab}.inc.php"; |
| 328 | |
| 329 | $log =& Session::getMixed('log'); |
| 330 | $log->log('profil', $opened_tab); |
| 331 | $page->assign('etat_update', 'ok'); |
| 332 | } |
| 333 | |
| 334 | if (Env::has('suivant')) { |
| 335 | redirect($globals->baseurl . '/profile/edit/' . |
| 336 | get_next_tab($opened_tab)); |
| 337 | } |
| 338 | |
| 339 | require_once "profil/get_{$opened_tab}.inc.php"; |
| 340 | require_once "profil/verif_{$opened_tab}.inc.php"; |
| 341 | require_once "profil/assign_{$opened_tab}.inc.php"; |
| 342 | |
| 343 | $page->assign('onglet', $opened_tab); |
| 344 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
| 345 | |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | function handler_p_orange(&$page) |
| 350 | { |
| 351 | $page->changeTpl('orange.tpl'); |
| 352 | |
| 353 | require_once 'validations.inc.php'; |
| 354 | require_once 'xorg.misc.inc.php'; |
| 355 | |
| 356 | $res = XDB::query( |
| 357 | "SELECT u.promo, u.promo_sortie |
| 358 | FROM auth_user_md5 AS u |
| 359 | WHERE user_id={?}", Session::getInt('uid')); |
| 360 | |
| 361 | list($promo, $promo_sortie_old) = $res->fetchOneRow(); |
| 362 | $page->assign('promo_sortie_old', $promo_sortie_old); |
| 363 | $page->assign('promo', $promo); |
| 364 | |
| 365 | if (!Env::has('promo_sortie')) { |
| 366 | return; |
| 367 | } |
| 368 | |
| 369 | $promo_sortie = Env::getInt('promo_sortie'); |
| 370 | |
| 371 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
| 372 | $page->trig('L\'année de sortie doit être un nombre de quatre chiffres'); |
| 373 | } |
| 374 | elseif ($promo_sortie < $promo + 3) { |
| 375 | $page->trig('Trop tôt'); |
| 376 | } |
| 377 | elseif ($promo_sortie == $promo_sortie_old) { |
| 378 | $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.'); |
| 379 | } |
| 380 | elseif ($promo_sortie == $promo + 3) { |
| 381 | XDB::execute( |
| 382 | "UPDATE auth_user_md5 set promo_sortie={?} |
| 383 | WHERE user_id={?}", $promo_sortie, Session::getInt('uid')); |
| 384 | $page->trig('Ton statut "orange" a été supprimé.'); |
| 385 | $page->assign('promo_sortie_old', $promo_sortie); |
| 386 | } |
| 387 | else { |
| 388 | $page->assign('promo_sortie', $promo_sortie); |
| 389 | |
| 390 | if (Env::has('submit')) { |
| 391 | $myorange = new OrangeReq(Session::getInt('uid'), |
| 392 | $promo_sortie); |
| 393 | $myorange->submit(); |
| 394 | $page->assign('myorange', $myorange); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | function handler_referent(&$page, $x = null) |
| 400 | { |
| 401 | require_once 'user.func.inc.php'; |
| 402 | |
| 403 | if (is_null($x)) { |
| 404 | return PL_NOT_FOUND; |
| 405 | } |
| 406 | |
| 407 | $page->changeTpl('fiche_referent.tpl'); |
| 408 | $page->assign('simple', true); |
| 409 | |
| 410 | $res = XDB::query( |
| 411 | "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias |
| 412 | FROM auth_user_md5 AS u |
| 413 | INNER JOIN aliases AS a ON (u.user_id=a.id |
| 414 | AND FIND_IN_SET('bestalias', a.flags)) |
| 415 | INNER JOIN aliases AS a1 ON (u.user_id=a1.id |
| 416 | AND a1.alias = {?} |
| 417 | AND a1.type!='homonyme')", $x); |
| 418 | |
| 419 | if ($res->numRows() != 1) { |
| 420 | return PL_NOT_FOUND; |
| 421 | } |
| 422 | |
| 423 | list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow(); |
| 424 | |
| 425 | $page->assign('prenom', $prenom); |
| 426 | $page->assign('nom', $nom); |
| 427 | $page->assign('promo', $promo); |
| 428 | $page->assign('cv', $cv); |
| 429 | $page->assign('bestalias', $bestalias); |
| 430 | $page->assign('adr_pro', get_user_details_pro($user_id)); |
| 431 | |
| 432 | ///// recuperations infos referent |
| 433 | |
| 434 | //expertise |
| 435 | $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id); |
| 436 | $page->assign('expertise', $res->fetchOneCell()); |
| 437 | |
| 438 | //secteurs |
| 439 | $secteurs = $ss_secteurs = Array(); |
| 440 | $res = XDB::iterRow( |
| 441 | "SELECT s.label, ss.label |
| 442 | FROM mentor_secteurs AS m |
| 443 | LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) |
| 444 | LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id) |
| 445 | WHERE uid = {?}", $user_id); |
| 446 | while (list($sec, $ssec) = $res->next()) { |
| 447 | $secteurs[] = $sec; |
| 448 | $ss_secteurs[] = $ssec; |
| 449 | } |
| 450 | $page->assign_by_ref('secteurs', $secteurs); |
| 451 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
| 452 | |
| 453 | //pays |
| 454 | $res = XDB::query( |
| 455 | "SELECT gp.pays |
| 456 | FROM mentor_pays AS m |
| 457 | LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2) |
| 458 | WHERE uid = {?}", $user_id); |
| 459 | $page->assign('pays', $res->fetchColumn()); |
| 460 | |
| 461 | $page->addJsLink('javascript/close_on_esc.js'); |
| 462 | } |
| 463 | |
| 464 | function handler_ref_search(&$page) |
| 465 | { |
| 466 | $page->changeTpl('referent.tpl'); |
| 467 | |
| 468 | $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro'); |
| 469 | |
| 470 | $secteur_sel = Post::get('secteur'); |
| 471 | $ss_secteur_sel = Post::get('ss_secteur'); |
| 472 | $pays_sel = Post::get('pays', '00'); |
| 473 | $expertise_champ = Post::get('expertise'); |
| 474 | |
| 475 | $page->assign('pays_sel', $pays_sel); |
| 476 | $page->assign('expertise_champ', $expertise_champ); |
| 477 | $page->assign('secteur_sel', $secteur_sel); |
| 478 | $page->assign('ss_secteur_sel', $ss_secteur_sel); |
| 479 | |
| 480 | //recuperation des noms de secteurs |
| 481 | $res = XDB::iterRow("SELECT id, label FROM emploi_secteur"); |
| 482 | $secteurs[''] = ''; |
| 483 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 484 | $secteurs[$tmp_id] = $tmp_label; |
| 485 | } |
| 486 | $page->assign_by_ref('secteurs', $secteurs); |
| 487 | |
| 488 | //on recupere les sous-secteurs si necessaire |
| 489 | $ss_secteurs[''] = ''; |
| 490 | if (!empty($secteur_sel)) { |
| 491 | $res = XDB::iterRow("SELECT id, label FROM emploi_ss_secteur |
| 492 | WHERE secteur = {?}", $secteur_sel); |
| 493 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 494 | $ss_secteurs[$tmp_id] = $tmp_label; |
| 495 | } |
| 496 | } |
| 497 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
| 498 | |
| 499 | //recuperation des noms de pays |
| 500 | $res = XDB::iterRow("SELECT a2, pays FROM geoloc_pays |
| 501 | WHERE pays <> '' ORDER BY pays"); |
| 502 | $pays['00'] = ''; |
| 503 | while (list($tmp_id, $tmp_label) = $res->next()) { |
| 504 | $pays[$tmp_id] = $tmp_label; |
| 505 | } |
| 506 | $page->assign_by_ref('pays', $pays); |
| 507 | |
| 508 | // nb de mentors |
| 509 | $res = XDB::query("SELECT count(*) FROM mentor"); |
| 510 | $page->assign('mentors_number', $res->fetchOneCell()); |
| 511 | |
| 512 | if (!Env::has('Chercher')) { |
| 513 | return; |
| 514 | } |
| 515 | |
| 516 | // On vient d'un formulaire |
| 517 | $where = array(); |
| 518 | |
| 519 | if ($pays_sel != '00') { |
| 520 | $where[] = "mp.pid = '".addslashes($pays_sel)."'"; |
| 521 | } |
| 522 | if ($secteur_sel) { |
| 523 | $where[] = "ms.secteur = '".addslashes($secteur_sel)."'"; |
| 524 | if ($ss_secteur_sel) { |
| 525 | $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'"; |
| 526 | } |
| 527 | } |
| 528 | if ($expertise_champ) { |
| 529 | $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')"; |
| 530 | } |
| 531 | |
| 532 | if ($where) { |
| 533 | $where = join(' AND ', $where); |
| 534 | |
| 535 | $sql = "SELECT m.uid, a.prenom, a.nom, a.promo, |
| 536 | l.alias AS bestalias, m.expertise, mp.pid, |
| 537 | ms.secteur, ms.ss_secteur |
| 538 | FROM mentor AS m |
| 539 | LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id) |
| 540 | INNER JOIN aliases AS l ON (a.user_id=l.id AND |
| 541 | FIND_IN_SET('bestalias', l.flags)) |
| 542 | LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid) |
| 543 | LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid) |
| 544 | WHERE $where |
| 545 | GROUP BY uid |
| 546 | ORDER BY RAND({?})"; |
| 547 | $res = XDB::iterator($sql, Session::getInt('uid')); |
| 548 | |
| 549 | if ($res->total() == 0) { |
| 550 | $page->assign('recherche_trop_large', true); |
| 551 | return; |
| 552 | } |
| 553 | |
| 554 | $nb_max_res_total = 100; |
| 555 | $nb_max_res_ppage = 10; |
| 556 | |
| 557 | $curpage = Env::getInt('curpage', 1); |
| 558 | $personnes = array(); |
| 559 | $i = 0; |
| 560 | |
| 561 | while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) { |
| 562 | $the_page = intval($i / $nb_max_res_ppage) + 1; |
| 563 | if ($the_page == $curpage) { |
| 564 | $personnes[] = $pers; |
| 565 | } |
| 566 | $i ++; |
| 567 | } |
| 568 | |
| 569 | $page->assign('personnes', $personnes); |
| 570 | $page->assign('curpage', $curpage); |
| 571 | $page->assign('nb_pages_total', |
| 572 | intval($res->total() / $nb_max_res_ppage) + 1); |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | function handler_p_usage(&$page) |
| 577 | { |
| 578 | $page->changeTpl('nomusage.tpl'); |
| 579 | |
| 580 | require_once 'validations.inc.php'; |
| 581 | require_once 'xorg.misc.inc.php'; |
| 582 | |
| 583 | $res = XDB::query( |
| 584 | "SELECT u.nom, u.nom_usage, u.flags, e.alias |
| 585 | FROM auth_user_md5 AS u |
| 586 | LEFT JOIN aliases AS e ON(u.user_id = e.id |
| 587 | AND FIND_IN_SET('usage', e.flags)) |
| 588 | WHERE user_id={?}", Session::getInt('uid')); |
| 589 | |
| 590 | list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow(); |
| 591 | $flags = new flagset($flags); |
| 592 | $page->assign('usage_old', $usage_old); |
| 593 | $page->assign('alias_old', $alias_old); |
| 594 | |
| 595 | $nom_usage = replace_accent(trim(Env::get('nom_usage'))); |
| 596 | $nom_usage = strtoupper($nom_usage); |
| 597 | $page->assign('usage_req', $nom_usage); |
| 598 | |
| 599 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
| 600 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
| 601 | if ($nom_usage == $nom) { |
| 602 | $page->assign('same', true); |
| 603 | } else { // le nom de mariage est distinct du nom à l'X |
| 604 | // on calcule l'alias pour l'afficher |
| 605 | $reason = Env::get('reason'); |
| 606 | if ($reason == 'other') { |
| 607 | $reason = Env::get('other_reason'); |
| 608 | } |
| 609 | $myusage = new UsageReq(Session::getInt('uid'), $nom_usage, $reason); |
| 610 | $myusage->submit(); |
| 611 | $page->assign('myusage', $myusage); |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | function handler_trombi(&$page, $promo = null) |
| 617 | { |
| 618 | require_once 'trombi.inc.php'; |
| 619 | |
| 620 | $page->changeTpl('trombipromo.tpl'); |
| 621 | $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo'); |
| 622 | |
| 623 | if (is_null($promo)) { |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | $this->promo = $promo = intval($promo); |
| 628 | |
| 629 | if ($promo >= 1900 && $promo < intval(date('Y')) |
| 630 | || ($promo == -1 && has_perms())) |
| 631 | { |
| 632 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
| 633 | $trombi->hidePromo(); |
| 634 | $trombi->setAdmin(); |
| 635 | $page->assign_by_ref('trombi', $trombi); |
| 636 | } else { |
| 637 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | function format_adr($params, &$smarty) |
| 642 | { |
| 643 | // $adr1, $adr2, $adr3, $postcode, $city, $region, $country |
| 644 | extract($params['adr']); |
| 645 | $adr = $adr1; |
| 646 | $adr = trim("$adr\n$adr2"); |
| 647 | $adr = trim("$adr\n$adr3"); |
| 648 | return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country"); |
| 649 | } |
| 650 | |
| 651 | function handler_vcard(&$page, $x = null) |
| 652 | { |
| 653 | if (is_null($x)) { |
| 654 | return PL_NOT_FOUND; |
| 655 | } |
| 656 | |
| 657 | global $globals; |
| 658 | |
| 659 | if (substr($x, -4) == '.vcf') { |
| 660 | $x = substr($x, 0, strlen($x) - 4); |
| 661 | } |
| 662 | |
| 663 | new_nonhtml_page('vcard.tpl', AUTH_COOKIE); |
| 664 | require_once 'xorg.misc.inc.php'; |
| 665 | require_once 'user.func.inc.php'; |
| 666 | |
| 667 | $page->register_modifier('qp_enc', 'quoted_printable_encode'); |
| 668 | $page->register_function('format_adr', array($this, 'format_adr')); |
| 669 | |
| 670 | $login = get_user_forlife($x); |
| 671 | $user = get_user_details($login); |
| 672 | |
| 673 | // alias virtual |
| 674 | $res = XDB::query( |
| 675 | "SELECT alias |
| 676 | FROM virtual |
| 677 | INNER JOIN virtual_redirect USING(vid) |
| 678 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
| 679 | WHERE ( redirect={?} OR redirect={?} ) |
| 680 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
| 681 | Session::getInt('uid'), |
| 682 | $user['forlife'].'@'.$globals->mail->domain, |
| 683 | $user['forlife'].'@'.$globals->mail->domain2); |
| 684 | |
| 685 | $user['virtualalias'] = $res->fetchOneCell(); |
| 686 | |
| 687 | $page->assign_by_ref('vcard', $user); |
| 688 | |
| 689 | header("Pragma: "); |
| 690 | header("Cache-Control: "); |
| 691 | header("Content-type: text/x-vcard\n"); |
| 692 | header("Content-Transfer-Encoding: Quoted-Printable\n"); |
| 693 | } |
| 694 | } |
| 695 | |
| 696 | ?> |