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