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));
163 function handler_profile(&$page, $x = null
)
170 require_once 'user.func.inc.php';
172 $page->changeTpl('fiche.tpl');
173 $page->assign('simple', true
);
176 if (!logged() || Env
::get('view') == 'public') $view = 'public';
177 if (logged() && Env
::get('view') == 'ax') $view = 'ax';
179 if (is_numeric($x)) {
180 $res = $globals->xdb
->query(
183 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
184 WHERE matricule={?}", $x);
185 $login = $res->fetchOneCell();
187 $login = get_user_forlife($x);
194 $new = Env
::get('modif') == 'new';
195 $user = get_user_details($login, Session
::getInt('uid'), $view);
196 $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ?
$user['nom'] : $user['nom_usage'];
197 $page->assign('xorg_title', $title);
201 $photo = $globals->baseurl
.'/photo/'.$user['forlife'].($new ?
'/req' : '');
203 if (!isset($user['y']) and !isset($user['x'])) {
204 list($user['x'], $user['y']) = getimagesize("images/none.png");
206 if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
207 if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
208 if ($user['x'] > 240) {
209 $user['y'] = (integer)($user['y']*240/$user['x']);
212 if ($user['y'] > 300) {
213 $user['x'] = (integer)($user['x']*300/$user['y']);
216 if ($user['x'] < 160) {
217 $user['y'] = (integer)($user['y']*160/$user['x']);
221 $page->assign('logged', has_user_right('private', $view));
222 if (!has_user_right($user['photo_pub'], $view)) {
226 $page->assign_by_ref('x', $user);
227 $page->assign('photo_url', $photo);
229 $res = $globals->xdb
->query(
232 INNER JOIN virtual_redirect USING(vid)
233 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
234 WHERE ( redirect={?} OR redirect={?} )
235 AND alias LIKE '%@{$globals->mail->alias_dom}'",
236 Session
::getInt('uid'),
237 $user['forlife'].'@'.$globals->mail
->domain
,
238 $user['forlife'].'@'.$globals->mail
->domain2
);
239 $page->assign('virtualalias', $res->fetchOneCell());
241 $page->addJsLink('javascript/close_on_esc.js');
246 function handler_p_edit(&$page, $opened_tab = 'general')
250 $page->changeTpl('profil.tpl');
252 $page->addCssLink('css/profil.css');
253 $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
255 require_once 'tabs.inc.php';
256 require_once 'profil.func.inc.php';
257 require_once 'synchro_ax.inc.php';
259 if (Post
::has('register_from_ax_question')) {
260 $globals->xdb
->query('UPDATE auth_user_quick
261 SET profile_from_ax = 1
262 WHERE user_id = {?}',
263 Session
::getInt('uid'));
266 if (is_ax_key_missing()) {
267 $page->assign('no_private_key', true
);
270 if (Env
::get('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
271 ax_synchronize(Session
::get('bestalias'), Session
::getInt('uid'));
272 $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com');
275 // pour tous les tabs, la date de naissance pour verifier
276 // quelle est bien rentree et la date.
277 $res = $globals->xdb
->query(
278 "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y')
280 WHERE user_id={?}", Session
::getInt('uid'));
281 list($naissance, $date_modif_profil) = $res->fetchOneRow();
283 // lorsqu'on n'a pas la date de naissance en base de données
285 // la date de naissance n'existait pas et vient d'être soumise dans la variable
286 if (Env
::has('birth')) {
288 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env
::get('birth'))) {
289 $page->assign('etat_naissance', 'query');
290 $page->trig('Date de naissance incorrecte ou incohérente.');
295 $birth = sprintf("%s-%s-%s", substr(Env
::get('birth'), 4, 4),
296 substr(Env
::get('birth'), 2, 2),
297 substr(Env
::get('birth'), 0, 2));
298 $globals->xdb
->execute("UPDATE auth_user_md5
300 WHERE user_id={?}", $birth,
301 Session
::getInt('uid'));
302 $page->assign('etat_naissance', 'ok');
306 $page->assign('etat_naissance', 'query');
307 return PL_OK
; // on affiche le formulaire pour naissance
310 //doit-on faire un update ?
311 if (Env
::has('modifier') || Env
::has('suivant')) {
312 require_once "profil/get_{$opened_tab}.inc.php";
313 require_once "profil/verif_{$opened_tab}.inc.php";
315 if($page->nb_errs()) {
316 require_once "profil/assign_{$opened_tab}.inc.php";
317 $page->assign('onglet', $opened_tab);
318 $page->assign('onglet_tpl', "profil/$opened_tab.tpl");
322 $date=date("Y-m-j");//nouvelle date de mise a jour
324 //On sauvegarde l'uid pour l'AX
325 /* on sauvegarde les changements dans user_changes :
326 * on a juste besoin d'insérer le user_id de la personne dans la table
328 $globals->xdb
->execute('REPLACE INTO user_changes SET user_id={?}',
329 Session
::getInt('uid'));
331 if (!Session
::has('suid')) {
332 require_once 'notifs.inc.php';
333 register_watch_op(Session
::getInt('uid'), WATCH_FICHE
);
336 // mise a jour des champs relatifs au tab ouvert
337 require_once "profil/update_{$opened_tab}.inc.php";
339 $log =& Session
::getMixed('log');
340 $log->log('profil', $opened_tab);
341 $page->assign('etat_update', 'ok');
344 if (Env
::has('suivant')) {
345 redirect($globals->baseurl
. '/profile/edit/' .
346 get_next_tab($opened_tab));
349 require_once "profil/get_{$opened_tab}.inc.php";
350 require_once "profil/verif_{$opened_tab}.inc.php";
351 require_once "profil/assign_{$opened_tab}.inc.php";
353 $page->assign('onglet', $opened_tab);
354 $page->assign('onglet_tpl', "profil/$opened_tab.tpl");
359 function handler_p_orange(&$page)
363 $page->changeTpl('orange.tpl');
365 require_once 'validations.inc.php';
366 require_once 'xorg.misc.inc.php';
368 $res = $globals->xdb
->query(
369 "SELECT u.promo, u.promo_sortie
370 FROM auth_user_md5 AS u
371 WHERE user_id={?}", Session
::getInt('uid'));
373 list($promo, $promo_sortie_old) = $res->fetchOneRow();
374 $page->assign('promo_sortie_old', $promo_sortie_old);
375 $page->assign('promo', $promo);
377 if (!Env
::has('promo_sortie')) {
381 $promo_sortie = Env
::getInt('promo_sortie');
383 if ($promo_sortie < 1000 ||
$promo_sortie > 9999) {
384 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
386 elseif ($promo_sortie < $promo +
3) {
387 $page->trig('Trop tôt');
389 elseif ($promo_sortie == $promo_sortie_old) {
390 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
392 elseif ($promo_sortie == $promo +
3) {
393 $globals->xdb
->execute(
394 "UPDATE auth_user_md5 set promo_sortie={?}
395 WHERE user_id={?}", $promo_sortie, Session
::getInt('uid'));
396 $page->trig('Ton statut "orange" a été supprimé.');
397 $page->assign('promo_sortie_old', $promo_sortie);
400 $page->assign('promo_sortie', $promo_sortie);
402 if (Env
::has('submit')) {
403 $myorange = new OrangeReq(Session
::getInt('uid'),
406 $page->assign('myorange', $myorange);
413 function handler_referent(&$page, $x = null
)
417 require_once 'user.func.inc.php';
423 $page->changeTpl('fiche_referent.tpl');
424 $page->assign('simple', true
);
426 $res = $globals->xdb
->query(
427 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
428 FROM auth_user_md5 AS u
429 INNER JOIN aliases AS a ON (u.user_id=a.id
430 AND FIND_IN_SET('bestalias', a.flags))
431 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
433 AND a1.type!='homonyme')", $x);
435 if ($res->numRows() != 1) {
439 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
441 $page->assign('prenom', $prenom);
442 $page->assign('nom', $nom);
443 $page->assign('promo', $promo);
444 $page->assign('cv', $cv);
445 $page->assign('bestalias', $bestalias);
446 $page->assign('adr_pro', get_user_details_pro($user_id));
448 ///// recuperations infos referent
451 $res = $globals->xdb
->query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
452 $page->assign('expertise', $res->fetchOneCell());
455 $secteurs = $ss_secteurs = Array();
456 $res = $globals->xdb
->iterRow(
457 "SELECT s.label, ss.label
458 FROM mentor_secteurs AS m
459 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
460 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
461 WHERE uid = {?}", $user_id);
462 while (list($sec, $ssec) = $res->next()) {
464 $ss_secteurs[] = $ssec;
466 $page->assign_by_ref('secteurs', $secteurs);
467 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
470 $res = $globals->xdb
->query(
472 FROM mentor_pays AS m
473 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
474 WHERE uid = {?}", $user_id);
475 $page->assign('pays', $res->fetchColumn());
477 $page->addJsLink('javascript/close_on_esc.js');
481 function handler_ref_search(&$page)
485 $page->changeTpl('referent.tpl');
487 $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
489 $secteur_sel = Post
::get('secteur');
490 $ss_secteur_sel = Post
::get('ss_secteur');
491 $pays_sel = Post
::get('pays', '00');
492 $expertise_champ = Post
::get('expertise');
494 $page->assign('pays_sel', $pays_sel);
495 $page->assign('expertise_champ', $expertise_champ);
496 $page->assign('secteur_sel', $secteur_sel);
497 $page->assign('ss_secteur_sel', $ss_secteur_sel);
499 //recuperation des noms de secteurs
500 $res = $globals->xdb
->iterRow("SELECT id, label FROM emploi_secteur");
502 while (list($tmp_id, $tmp_label) = $res->next()) {
503 $secteurs[$tmp_id] = $tmp_label;
505 $page->assign_by_ref('secteurs', $secteurs);
507 //on recupere les sous-secteurs si necessaire
508 $ss_secteurs[''] = '';
509 if (!empty($secteur_sel)) {
510 $res = $globals->xdb
->iterRow("SELECT id, label FROM emploi_ss_secteur
511 WHERE secteur = {?}", $secteur_sel);
512 while (list($tmp_id, $tmp_label) = $res->next()) {
513 $ss_secteurs[$tmp_id] = $tmp_label;
516 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
518 //recuperation des noms de pays
519 $res = $globals->xdb
->iterRow("SELECT a2, pays FROM geoloc_pays
520 WHERE pays <> '' ORDER BY pays");
522 while (list($tmp_id, $tmp_label) = $res->next()) {
523 $pays[$tmp_id] = $tmp_label;
525 $page->assign_by_ref('pays', $pays);
528 $res = $globals->xdb
->query("SELECT count(*) FROM mentor");
529 $page->assign('mentors_number', $res->fetchOneCell());
531 if (!Env
::has('Chercher')) {
535 // On vient d'un formulaire
538 if ($pays_sel != '00') {
539 $where[] = "mp.pid = '".addslashes($pays_sel)."'";
542 $where[] = "ms.secteur = '".addslashes($secteur_sel)."'";
543 if ($ss_secteur_sel) {
544 $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'";
547 if ($expertise_champ) {
548 $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')";
552 $where = join(' AND ', $where);
554 $sql = "SELECT m.uid, a.prenom, a.nom, a.promo,
555 l.alias AS bestalias, m.expertise, mp.pid,
556 ms.secteur, ms.ss_secteur
558 LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id)
559 INNER JOIN aliases AS l ON (a.user_id=l.id AND
560 FIND_IN_SET('bestalias', l.flags))
561 LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid)
562 LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid)
566 $res = $globals->xdb
->iterator($sql, Session
::getInt('uid'));
568 if ($res->total() == 0) {
569 $page->assign('recherche_trop_large', true
);
573 $nb_max_res_total = 100;
574 $nb_max_res_ppage = 10;
576 $curpage = Env
::getInt('curpage', 1);
577 $personnes = array();
580 while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) {
581 $the_page = intval($i / $nb_max_res_ppage) +
1;
582 if ($the_page == $curpage) {
583 $personnes[] = $pers;
588 $page->assign('personnes', $personnes);
589 $page->assign('curpage', $curpage);
590 $page->assign('nb_pages_total',
591 intval($res->total() / $nb_max_res_ppage) +
1);
597 function handler_p_usage(&$page)
601 $page->changeTpl('nomusage.tpl');
603 require_once 'validations.inc.php';
604 require_once 'xorg.misc.inc.php';
606 $res = $globals->xdb
->query(
607 "SELECT u.nom, u.nom_usage, u.flags, e.alias
608 FROM auth_user_md5 AS u
609 LEFT JOIN aliases AS e ON(u.user_id = e.id
610 AND FIND_IN_SET('usage', e.flags))
611 WHERE user_id={?}", Session
::getInt('uid'));
613 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
614 $flags = new flagset($flags);
615 $page->assign('usage_old', $usage_old);
616 $page->assign('alias_old', $alias_old);
618 $nom_usage = replace_accent(trim(Env
::get('nom_usage')));
619 $nom_usage = strtoupper($nom_usage);
620 $page->assign('usage_req', $nom_usage);
622 if (Env
::has('submit') && ($nom_usage != $usage_old)) {
623 // on vient de recevoir une requete, differente de l'ancien nom d'usage
624 if ($nom_usage == $nom) {
625 $page->assign('same', true
);
626 } else { // le nom de mariage est distinct du nom à l'X
627 // on calcule l'alias pour l'afficher
628 $reason = Env
::get('reason');
629 if ($reason == 'other') {
630 $reason = Env
::get('other_reason');
632 $myusage = new UsageReq(Session
::getInt('uid'), $nom_usage, $reason);
634 $page->assign('myusage', $myusage);
641 function handler_trombi(&$page, $promo = null
)
643 require_once 'trombi.inc.php';
645 $page->changeTpl('trombipromo.tpl');
646 $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo');
648 if (is_null($promo)) {
652 $this->promo
= $promo = intval($promo);
654 if ($promo >= 1900 && $promo < intval(date('Y'))
655 ||
($promo == -1 && has_perms()))
657 $trombi = new Trombi(array($this, '_trombi_getlist'));
658 $trombi->hidePromo();
660 $page->assign_by_ref('trombi', $trombi);
662 $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.');
668 function format_adr($params, &$smarty)
670 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
671 extract($params['adr']);
673 $adr = trim("$adr\n$adr2");
674 $adr = trim("$adr\n$adr3");
675 return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
678 function handler_vcard(&$page, $x = null
)
686 if (substr($x, -4) == '.vcf') {
687 $x = substr($x, 0, strlen($x) - 4);
690 new_nonhtml_page('vcard.tpl', AUTH_COOKIE
);
691 require_once 'xorg.misc.inc.php';
692 require_once 'user.func.inc.php';
694 $page->register_modifier('qp_enc', 'quoted_printable_encode');
695 $page->register_function('format_adr', array($this, 'format_adr'));
697 $login = get_user_forlife($x);
698 $user = get_user_details($login);
701 $res = $globals->xdb
->query(
704 INNER JOIN virtual_redirect USING(vid)
705 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
706 WHERE ( redirect={?} OR redirect={?} )
707 AND alias LIKE '%@{$globals->mail->alias_dom}'",
708 Session
::getInt('uid'),
709 $user['forlife'].'@'.$globals->mail
->domain
,
710 $user['forlife'].'@'.$globals->mail
->domain2
);
712 $user['virtualalias'] = $res->fetchOneCell();
714 $page->assign_by_ref('vcard', $user);
717 header("Cache-Control: ");
718 header("Content-type: text/x-vcard\n");
719 header("Content-Transfer-Encoding: Quoted-Printable\n");