92a01d6a612b488a3af1f19c73a752ee73eb840a
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)
54 $where = ( $this->promo
> 0 ?
"WHERE promo='{$this->promo}'" : "" );
58 FROM auth_user_md5 AS u
59 RIGHT JOIN photo AS p ON u.user_id=p.uid
61 $pnb = $res->fetchOneCell();
64 "SELECT promo, user_id, a.alias AS forlife,
65 IF (nom_usage='', nom, nom_usage) AS nom, prenom
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' )
70 ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit);
72 return array($pnb, $res->fetchAllAssoc());
75 function handler_photo(&$page, $x = null
, $req = null
)
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();
86 if ($req && logged()) {
87 include 'validations.inc.php';
88 $myphoto = PhotoReq
::get_request($uid);
89 Header('Content-type: image/'.$myphoto->mimetype
);
93 "SELECT attachmime, attach
95 WHERE uid={?}", $uid);
97 if ((list($type, $data) = $res->fetchOneRow())
98 && ($photo_pub == 'public' ||
logged())) {
99 Header("Content-type: image/$type");
102 Header('Content-type: image/png');
103 echo file_get_contents(dirname(__FILE__
).'/../htdocs/images/none.png');
109 function handler_photo_change(&$page)
111 $page->changeTpl('trombino.tpl');
113 require_once('validations.inc.php');
115 $trombi_x = '/home/web/trombino/photos'.Session
::get('promo')
116 .'/'.Session
::get('forlife').'.jpg';
118 if (Env
::has('upload')) {
119 $file = isset($_FILES['userfile']['tmp_name'])
120 ?
$_FILES['userfile']['tmp_name']
122 if ($data = file_get_contents($file)) {
123 if ($myphoto = new PhotoReq(Session
::getInt('uid'), $data)) {
127 $page->trig('Fichier inexistant ou vide');
129 } elseif (Env
::has('trombi')) {
130 $myphoto = new PhotoReq(Session
::getInt('uid'),
131 file_get_contents($trombi_x));
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'));
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));
155 function handler_profile(&$page, $x = null
)
162 require_once 'user.func.inc.php';
164 $page->changeTpl('fiche.tpl');
165 $page->assign('simple', true
);
168 if (!logged() || Env
::get('view') == 'public') $view = 'public';
169 if (logged() && Env
::get('view') == 'ax') $view = 'ax';
171 if (is_numeric($x)) {
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();
179 $login = get_user_forlife($x);
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);
193 $photo = $globals->baseurl
.'/photo/'.$user['forlife'].($new ?
'/req' : '');
195 if (!isset($user['y']) and !isset($user['x'])) {
196 list($user['x'], $user['y']) = getimagesize("images/none.png");
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']);
204 if ($user['y'] > 300) {
205 $user['x'] = (integer)($user['x']*300/$user['y']);
208 if ($user['x'] < 160) {
209 $user['y'] = (integer)($user['y']*160/$user['x']);
213 $page->assign('logged', has_user_right('private', $view));
214 if (!has_user_right($user['photo_pub'], $view)) {
218 $page->assign_by_ref('x', $user);
219 $page->assign('photo_url', $photo);
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());
233 $page->addJsLink('javascript/close_on_esc.js');
236 function handler_p_edit(&$page, $opened_tab = 'general')
240 $page->changeTpl('profil.tpl');
242 $page->addCssLink('css/profil.css');
243 $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
245 require_once 'tabs.inc.php';
246 require_once 'profil.func.inc.php';
247 require_once 'synchro_ax.inc.php';
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'));
256 if (is_ax_key_missing()) {
257 $page->assign('no_private_key', true
);
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');
265 // pour tous les tabs, la date de naissance pour verifier
266 // quelle est bien rentree et la date.
268 "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y')
270 WHERE user_id={?}", Session
::getInt('uid'));
271 list($naissance, $date_modif_profil) = $res->fetchOneRow();
273 // lorsqu'on n'a pas la date de naissance en base de données
275 // la date de naissance n'existait pas et vient d'être soumise dans la variable
276 if (Env
::has('birth')) {
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.');
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
290 WHERE user_id={?}", $birth,
291 Session
::getInt('uid'));
292 $page->assign('etat_naissance', 'ok');
296 $page->assign('etat_naissance', 'query');
297 return; // on affiche le formulaire pour naissance
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";
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");
312 $date=date("Y-m-j");//nouvelle date de mise a jour
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
318 XDB
::execute('REPLACE INTO user_changes SET user_id={?}',
319 Session
::getInt('uid'));
321 if (!Session
::has('suid')) {
322 require_once 'notifs.inc.php';
323 register_watch_op(Session
::getInt('uid'), WATCH_FICHE
);
326 // mise a jour des champs relatifs au tab ouvert
327 require_once "profil/update_{$opened_tab}.inc.php";
329 $log =& Session
::getMixed('log');
330 $log->log('profil', $opened_tab);
331 $page->assign('etat_update', 'ok');
334 if (Env
::has('suivant')) {
335 redirect($globals->baseurl
. '/profile/edit/' .
336 get_next_tab($opened_tab));
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";
343 $page->assign('onglet', $opened_tab);
344 $page->assign('onglet_tpl', "profil/$opened_tab.tpl");
349 function handler_p_orange(&$page)
351 $page->changeTpl('orange.tpl');
353 require_once 'validations.inc.php';
354 require_once 'xorg.misc.inc.php';
357 "SELECT u.promo, u.promo_sortie
358 FROM auth_user_md5 AS u
359 WHERE user_id={?}", Session
::getInt('uid'));
361 list($promo, $promo_sortie_old) = $res->fetchOneRow();
362 $page->assign('promo_sortie_old', $promo_sortie_old);
363 $page->assign('promo', $promo);
365 if (!Env
::has('promo_sortie')) {
369 $promo_sortie = Env
::getInt('promo_sortie');
371 if ($promo_sortie < 1000 ||
$promo_sortie > 9999) {
372 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
374 elseif ($promo_sortie < $promo +
3) {
375 $page->trig('Trop tôt');
377 elseif ($promo_sortie == $promo_sortie_old) {
378 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
380 elseif ($promo_sortie == $promo +
3) {
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);
388 $page->assign('promo_sortie', $promo_sortie);
390 if (Env
::has('submit')) {
391 $myorange = new OrangeReq(Session
::getInt('uid'),
394 $page->assign('myorange', $myorange);
399 function handler_referent(&$page, $x = null
)
401 require_once 'user.func.inc.php';
407 $page->changeTpl('fiche_referent.tpl');
408 $page->assign('simple', true
);
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
417 AND a1.type!='homonyme')", $x);
419 if ($res->numRows() != 1) {
423 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
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));
432 ///// recuperations infos referent
435 $res = XDB
::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
436 $page->assign('expertise', $res->fetchOneCell());
439 $secteurs = $ss_secteurs = Array();
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()) {
448 $ss_secteurs[] = $ssec;
450 $page->assign_by_ref('secteurs', $secteurs);
451 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
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());
461 $page->addJsLink('javascript/close_on_esc.js');
464 function handler_ref_search(&$page)
466 $page->changeTpl('referent.tpl');
468 $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
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');
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);
480 //recuperation des noms de secteurs
481 $res = XDB
::iterRow("SELECT id, label FROM emploi_secteur");
483 while (list($tmp_id, $tmp_label) = $res->next()) {
484 $secteurs[$tmp_id] = $tmp_label;
486 $page->assign_by_ref('secteurs', $secteurs);
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;
497 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
499 //recuperation des noms de pays
500 $res = XDB
::iterRow("SELECT a2, pays FROM geoloc_pays
501 WHERE pays <> '' ORDER BY pays");
503 while (list($tmp_id, $tmp_label) = $res->next()) {
504 $pays[$tmp_id] = $tmp_label;
506 $page->assign_by_ref('pays', $pays);
509 $res = XDB
::query("SELECT count(*) FROM mentor");
510 $page->assign('mentors_number', $res->fetchOneCell());
512 if (!Env
::has('Chercher')) {
516 // On vient d'un formulaire
519 if ($pays_sel != '00') {
520 $where[] = "mp.pid = '".addslashes($pays_sel)."'";
523 $where[] = "ms.secteur = '".addslashes($secteur_sel)."'";
524 if ($ss_secteur_sel) {
525 $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'";
528 if ($expertise_champ) {
529 $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')";
533 $where = join(' AND ', $where);
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
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)
547 $res = XDB
::iterator($sql, Session
::getInt('uid'));
549 if ($res->total() == 0) {
550 $page->assign('recherche_trop_large', true
);
554 $nb_max_res_total = 100;
555 $nb_max_res_ppage = 10;
557 $curpage = Env
::getInt('curpage', 1);
558 $personnes = array();
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;
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);
576 function handler_p_usage(&$page)
578 $page->changeTpl('nomusage.tpl');
580 require_once 'validations.inc.php';
581 require_once 'xorg.misc.inc.php';
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'));
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);
595 $nom_usage = replace_accent(trim(Env
::get('nom_usage')));
596 $nom_usage = strtoupper($nom_usage);
597 $page->assign('usage_req', $nom_usage);
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');
609 $myusage = new UsageReq(Session
::getInt('uid'), $nom_usage, $reason);
611 $page->assign('myusage', $myusage);
616 function handler_trombi(&$page, $promo = null
)
618 require_once 'trombi.inc.php';
620 $page->changeTpl('trombipromo.tpl');
621 $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo');
623 if (is_null($promo)) {
627 $this->promo
= $promo = intval($promo);
629 if ($promo >= 1900 && $promo < intval(date('Y'))
630 ||
($promo == -1 && has_perms()))
632 $trombi = new Trombi(array($this, '_trombi_getlist'));
633 $trombi->hidePromo();
635 $page->assign_by_ref('trombi', $trombi);
637 $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.');
641 function format_adr($params, &$smarty)
643 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
644 extract($params['adr']);
646 $adr = trim("$adr\n$adr2");
647 $adr = trim("$adr\n$adr3");
648 return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
651 function handler_vcard(&$page, $x = null
)
659 if (substr($x, -4) == '.vcf') {
660 $x = substr($x, 0, strlen($x) - 4);
663 new_nonhtml_page('vcard.tpl', AUTH_COOKIE
);
664 require_once 'xorg.misc.inc.php';
665 require_once 'user.func.inc.php';
667 $page->register_modifier('qp_enc', 'quoted_printable_encode');
668 $page->register_function('format_adr', array($this, 'format_adr'));
670 $login = get_user_forlife($x);
671 $user = get_user_details($login);
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
);
685 $user['virtualalias'] = $res->fetchOneCell();
687 $page->assign_by_ref('vcard', $user);
690 header("Cache-Control: ");
691 header("Content-type: text/x-vcard\n");
692 header("Content-Transfer-Encoding: Quoted-Printable\n");