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