fb92fd912de9e84f5f53df494ccb8e16ab0f9dfe
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileModule
extends PLModule
27 'photo' => $this->make_hook('photo', AUTH_PUBLIC
),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP
),
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
),
36 'referent' => $this->make_hook('referent', AUTH_COOKIE
),
37 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE
),
39 'trombi' => $this->make_hook('trombi', AUTH_COOKIE
),
41 'vcard' => $this->make_hook('vcard', AUTH_COOKIE
),
46 function handler_fiche(&$page)
48 return $this->handler_profile($page, Env
::get('user'));
52 function _trombi_getlist($offset, $limit)
56 $where = ( $this->promo
> 0 ?
"WHERE promo='{$this->promo}'" : "" );
58 $res = $globals->xdb
->query(
60 FROM auth_user_md5 AS u
61 RIGHT JOIN photo AS p ON u.user_id=p.uid
63 $pnb = $res->fetchOneCell();
65 $res = $globals->xdb
->query(
66 "SELECT promo, user_id, a.alias AS forlife,
67 IF (nom_usage='', nom, nom_usage) AS nom, prenom
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' )
72 ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit);
74 return array($pnb, $res->fetchAllAssoc());
77 function handler_photo(&$page, $x = null
, $req = null
)
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();
90 if ($req && logged()) {
91 include 'validations.inc.php';
92 $myphoto = PhotoReq
::get_request($uid);
93 Header('Content-type: image/'.$myphoto->mimetype
);
96 $res = $globals->xdb
->query(
97 "SELECT attachmime, attach
99 WHERE uid={?}", $uid);
101 if ((list($type, $data) = $res->fetchOneRow())
102 && ($photo_pub == 'public' ||
logged())) {
103 Header("Content-type: image/$type");
106 Header('Content-type: image/png');
107 echo file_get_contents(dirname(__FILE__
).'/../htdocs/images/none.png');
113 function handler_photo_change(&$page)
117 $page->changeTpl('trombino.tpl');
119 require_once('validations.inc.php');
121 $trombi_x = '/home/web/trombino/photos'.Session
::get('promo')
122 .'/'.Session
::get('forlife').'.jpg';
124 if (Env
::has('upload')) {
125 $file = isset($_FILES['userfile']['tmp_name'])
126 ?
$_FILES['userfile']['tmp_name']
128 if ($data = file_get_contents($file)) {
129 if ($myphoto = new PhotoReq(Session
::getInt('uid'), $data)) {
133 $page->trig('Fichier inexistant ou vide');
135 } elseif (Env
::has('trombi')) {
136 $myphoto = new PhotoReq(Session
::getInt('uid'),
137 file_get_contents($trombi_x));
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'));
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));
161 function handler_profile(&$page, $x = null
)
168 require_once 'user.func.inc.php';
170 $page->changeTpl('fiche.tpl');
171 $page->assign('simple', true
);
174 if (!logged() || Env
::get('view') == 'public') $view = 'public';
175 if (logged() && Env
::get('view') == 'ax') $view = 'ax';
177 if (is_numeric($x)) {
178 $res = $globals->xdb
->query(
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();
185 $login = get_user_forlife($x);
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);
199 $photo = $globals->baseurl
.'/photo/'.$user['forlife'].($new ?
'/req' : '');
201 if (!isset($user['y']) and !isset($user['x'])) {
202 list($user['x'], $user['y']) = getimagesize("images/none.png");
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) {
207 $user['y'] = (integer)($user['y']*240/$user['x']);
210 if ($user['y'] > 300) {
211 $user['x'] = (integer)($user['x']*300/$user['y']);
214 if ($user['x'] < 160) {
215 $user['y'] = (integer)($user['y']*160/$user['x']);
219 $page->assign('logged', has_user_right('private', $view));
220 if (!has_user_right($user['photo_pub'], $view)) {
224 $page->assign_by_ref('x', $user);
225 $page->assign('photo_url', $photo);
227 $res = $globals->xdb
->query(
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());
239 $page->addJsLink('javascript/close_on_esc.js');
242 function handler_p_edit(&$page, $opened_tab = 'general')
246 $page->changeTpl('profil.tpl');
248 $page->addCssLink('css/profil.css');
249 $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
251 require_once 'tabs.inc.php';
252 require_once 'profil.func.inc.php';
253 require_once 'synchro_ax.inc.php';
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'));
262 if (is_ax_key_missing()) {
263 $page->assign('no_private_key', true
);
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');
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')
276 WHERE user_id={?}", Session
::getInt('uid'));
277 list($naissance, $date_modif_profil) = $res->fetchOneRow();
279 // lorsqu'on n'a pas la date de naissance en base de données
281 // la date de naissance n'existait pas et vient d'être soumise dans la variable
282 if (Env
::has('birth')) {
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.');
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
296 WHERE user_id={?}", $birth,
297 Session
::getInt('uid'));
298 $page->assign('etat_naissance', 'ok');
302 $page->assign('etat_naissance', 'query');
303 return; // on affiche le formulaire pour naissance
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";
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");
318 $date=date("Y-m-j");//nouvelle date de mise a jour
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
324 $globals->xdb
->execute('REPLACE INTO user_changes SET user_id={?}',
325 Session
::getInt('uid'));
327 if (!Session
::has('suid')) {
328 require_once 'notifs.inc.php';
329 register_watch_op(Session
::getInt('uid'), WATCH_FICHE
);
332 // mise a jour des champs relatifs au tab ouvert
333 require_once "profil/update_{$opened_tab}.inc.php";
335 $log =& Session
::getMixed('log');
336 $log->log('profil', $opened_tab);
337 $page->assign('etat_update', 'ok');
340 if (Env
::has('suivant')) {
341 redirect($globals->baseurl
. '/profile/edit/' .
342 get_next_tab($opened_tab));
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";
349 $page->assign('onglet', $opened_tab);
350 $page->assign('onglet_tpl', "profil/$opened_tab.tpl");
355 function handler_p_orange(&$page)
359 $page->changeTpl('orange.tpl');
361 require_once 'validations.inc.php';
362 require_once 'xorg.misc.inc.php';
364 $res = $globals->xdb
->query(
365 "SELECT u.promo, u.promo_sortie
366 FROM auth_user_md5 AS u
367 WHERE user_id={?}", Session
::getInt('uid'));
369 list($promo, $promo_sortie_old) = $res->fetchOneRow();
370 $page->assign('promo_sortie_old', $promo_sortie_old);
371 $page->assign('promo', $promo);
373 if (!Env
::has('promo_sortie')) {
377 $promo_sortie = Env
::getInt('promo_sortie');
379 if ($promo_sortie < 1000 ||
$promo_sortie > 9999) {
380 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
382 elseif ($promo_sortie < $promo +
3) {
383 $page->trig('Trop tôt');
385 elseif ($promo_sortie == $promo_sortie_old) {
386 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
388 elseif ($promo_sortie == $promo +
3) {
389 $globals->xdb
->execute(
390 "UPDATE auth_user_md5 set promo_sortie={?}
391 WHERE user_id={?}", $promo_sortie, Session
::getInt('uid'));
392 $page->trig('Ton statut "orange" a été supprimé.');
393 $page->assign('promo_sortie_old', $promo_sortie);
396 $page->assign('promo_sortie', $promo_sortie);
398 if (Env
::has('submit')) {
399 $myorange = new OrangeReq(Session
::getInt('uid'),
402 $page->assign('myorange', $myorange);
407 function handler_referent(&$page, $x = null
)
411 require_once 'user.func.inc.php';
417 $page->changeTpl('fiche_referent.tpl');
418 $page->assign('simple', true
);
420 $res = $globals->xdb
->query(
421 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
422 FROM auth_user_md5 AS u
423 INNER JOIN aliases AS a ON (u.user_id=a.id
424 AND FIND_IN_SET('bestalias', a.flags))
425 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
427 AND a1.type!='homonyme')", $x);
429 if ($res->numRows() != 1) {
433 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
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));
442 ///// recuperations infos referent
445 $res = $globals->xdb
->query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
446 $page->assign('expertise', $res->fetchOneCell());
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()) {
458 $ss_secteurs[] = $ssec;
460 $page->assign_by_ref('secteurs', $secteurs);
461 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
464 $res = $globals->xdb
->query(
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());
471 $page->addJsLink('javascript/close_on_esc.js');
474 function handler_ref_search(&$page)
478 $page->changeTpl('referent.tpl');
480 $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
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');
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);
492 //recuperation des noms de secteurs
493 $res = $globals->xdb
->iterRow("SELECT id, label FROM emploi_secteur");
495 while (list($tmp_id, $tmp_label) = $res->next()) {
496 $secteurs[$tmp_id] = $tmp_label;
498 $page->assign_by_ref('secteurs', $secteurs);
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;
509 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
511 //recuperation des noms de pays
512 $res = $globals->xdb
->iterRow("SELECT a2, pays FROM geoloc_pays
513 WHERE pays <> '' ORDER BY pays");
515 while (list($tmp_id, $tmp_label) = $res->next()) {
516 $pays[$tmp_id] = $tmp_label;
518 $page->assign_by_ref('pays', $pays);
521 $res = $globals->xdb
->query("SELECT count(*) FROM mentor");
522 $page->assign('mentors_number', $res->fetchOneCell());
524 if (!Env
::has('Chercher')) {
528 // On vient d'un formulaire
531 if ($pays_sel != '00') {
532 $where[] = "mp.pid = '".addslashes($pays_sel)."'";
535 $where[] = "ms.secteur = '".addslashes($secteur_sel)."'";
536 if ($ss_secteur_sel) {
537 $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'";
540 if ($expertise_champ) {
541 $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')";
545 $where = join(' AND ', $where);
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
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)
559 $res = $globals->xdb
->iterator($sql, Session
::getInt('uid'));
561 if ($res->total() == 0) {
562 $page->assign('recherche_trop_large', true
);
566 $nb_max_res_total = 100;
567 $nb_max_res_ppage = 10;
569 $curpage = Env
::getInt('curpage', 1);
570 $personnes = array();
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;
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);
588 function handler_p_usage(&$page)
592 $page->changeTpl('nomusage.tpl');
594 require_once 'validations.inc.php';
595 require_once 'xorg.misc.inc.php';
597 $res = $globals->xdb
->query(
598 "SELECT u.nom, u.nom_usage, u.flags, e.alias
599 FROM auth_user_md5 AS u
600 LEFT JOIN aliases AS e ON(u.user_id = e.id
601 AND FIND_IN_SET('usage', e.flags))
602 WHERE user_id={?}", Session
::getInt('uid'));
604 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
605 $flags = new flagset($flags);
606 $page->assign('usage_old', $usage_old);
607 $page->assign('alias_old', $alias_old);
609 $nom_usage = replace_accent(trim(Env
::get('nom_usage')));
610 $nom_usage = strtoupper($nom_usage);
611 $page->assign('usage_req', $nom_usage);
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
);
617 } else { // le nom de mariage est distinct du nom à l'X
618 // on calcule l'alias pour l'afficher
619 $reason = Env
::get('reason');
620 if ($reason == 'other') {
621 $reason = Env
::get('other_reason');
623 $myusage = new UsageReq(Session
::getInt('uid'), $nom_usage, $reason);
625 $page->assign('myusage', $myusage);
630 function handler_trombi(&$page, $promo = null
)
632 require_once 'trombi.inc.php';
634 $page->changeTpl('trombipromo.tpl');
635 $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo');
637 if (is_null($promo)) {
641 $this->promo
= $promo = intval($promo);
643 if ($promo >= 1900 && $promo < intval(date('Y'))
644 ||
($promo == -1 && has_perms()))
646 $trombi = new Trombi(array($this, '_trombi_getlist'));
647 $trombi->hidePromo();
649 $page->assign_by_ref('trombi', $trombi);
651 $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.');
655 function format_adr($params, &$smarty)
657 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
658 extract($params['adr']);
660 $adr = trim("$adr\n$adr2");
661 $adr = trim("$adr\n$adr3");
662 return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
665 function handler_vcard(&$page, $x = null
)
673 if (substr($x, -4) == '.vcf') {
674 $x = substr($x, 0, strlen($x) - 4);
677 new_nonhtml_page('vcard.tpl', AUTH_COOKIE
);
678 require_once 'xorg.misc.inc.php';
679 require_once 'user.func.inc.php';
681 $page->register_modifier('qp_enc', 'quoted_printable_encode');
682 $page->register_function('format_adr', array($this, 'format_adr'));
684 $login = get_user_forlife($x);
685 $user = get_user_details($login);
688 $res = $globals->xdb
->query(
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
);
699 $user['virtualalias'] = $res->fetchOneCell();
701 $page->assign_by_ref('vcard', $user);
704 header("Cache-Control: ");
705 header("Content-type: text/x-vcard\n");
706 header("Content-Transfer-Encoding: Quoted-Printable\n");