autocomplete improvements: can find pierre-yves when looking for yves
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 Polytechnique.org *
7d8b17cb 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),
9643d877 32 'profile/private' => $this->make_hook('profile', AUTH_COOKIE),
2f678da1 33 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
28e16d4d 34 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
28e16d4d 35 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP),
e49018a7 36
2f678da1 37 'referent' => $this->make_hook('referent', AUTH_COOKIE),
38 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
39
a1d79217 40 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
926f16d7 41
28e16d4d 42 'vcard' => $this->make_hook('vcard', AUTH_COOKIE),
92423144 43 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
44 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
45 'admin/formations' => $this->make_hook('admin_formations', AUTH_MDP, 'admin'),
46 'admin/groupes-x' => $this->make_hook('admin_groupesx', AUTH_MDP, 'admin'),
47 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
48
7d8b17cb 49 );
50 }
51
e8599c21 52 /* XXX COMPAT */
53 function handler_fiche(&$page)
54 {
5e2307dc 55 return $this->handler_profile($page, Env::v('user'));
e8599c21 56 }
57
58
7d8b17cb 59 function _trombi_getlist($offset, $limit)
60 {
7d8b17cb 61 $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" );
62
08cce2ff 63 $res = XDB::query(
7d8b17cb 64 "SELECT COUNT(*)
65 FROM auth_user_md5 AS u
66 RIGHT JOIN photo AS p ON u.user_id=p.uid
67 $where");
68 $pnb = $res->fetchOneCell();
69
08cce2ff 70 $res = XDB::query(
2f678da1 71 "SELECT promo, user_id, a.alias AS forlife,
72 IF (nom_usage='', nom, nom_usage) AS nom, prenom
7d8b17cb 73 FROM photo AS p
74 INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
75 INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
76 $where
2f678da1 77 ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit);
7d8b17cb 78
79 return array($pnb, $res->fetchAllAssoc());
80 }
81
adbdf493 82 function handler_photo(&$page, $x = null, $req = null)
83 {
84 if (is_null($x)) {
85 return PL_NOT_FOUND;
86 }
87
08cce2ff 88 $res = XDB::query("SELECT id, pub FROM aliases
adbdf493 89 LEFT JOIN photo ON(id = uid)
90 WHERE alias = {?}", $x);
91 list($uid, $photo_pub) = $res->fetchOneRow();
92
cab08090 93 if ($req && S::logged()) {
adbdf493 94 include 'validations.inc.php';
95 $myphoto = PhotoReq::get_request($uid);
96 Header('Content-type: image/'.$myphoto->mimetype);
97 echo $myphoto->data;
98 } else {
08cce2ff 99 $res = XDB::query(
adbdf493 100 "SELECT attachmime, attach
101 FROM photo
102 WHERE uid={?}", $uid);
103
2f678da1 104 if ((list($type, $data) = $res->fetchOneRow())
cab08090 105 && ($photo_pub == 'public' || S::logged())) {
adbdf493 106 Header("Content-type: image/$type");
107 echo $data;
108 } else {
109 Header('Content-type: image/png');
fb9a56cb 110 echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
adbdf493 111 }
112 }
113 exit;
114 }
115
fb9a56cb 116 function handler_photo_change(&$page)
117 {
8b1f8e12 118 $page->changeTpl('profile/trombino.tpl');
fb9a56cb 119
120 require_once('validations.inc.php');
121
cab08090 122 $trombi_x = '/home/web/trombino/photos'.S::v('promo')
123 .'/'.S::v('forlife').'.jpg';
fb9a56cb 124
125 if (Env::has('upload')) {
abe7e055 126 $upload = new PlUpload(S::v('forlife'), 'photo');
127 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
128 $page->trig('Une erreur est survenue lors du téléchargement du fichier');
129 } else {
130 $myphoto = new PhotoReq(S::v('uid'), $upload);
131 if ($myphoto->isValid()) {
132 $myphoto->submit();
fb9a56cb 133 }
fb9a56cb 134 }
135 } elseif (Env::has('trombi')) {
abe7e055 136 $upload = new PlUpload(S::v('forlife'), 'photo');
137 if ($upload->copyFrom($trombi_x)) {
138 $myphoto = new PhotoReq(S::v('uid'), $upload);
139 if ($myphoto->isValid()) {
140 $myphoto->commit();
141 $myphoto->clean();
142 }
fb9a56cb 143 }
5e2307dc 144 } elseif (Env::v('suppr')) {
08cce2ff 145 XDB::execute('DELETE FROM photo WHERE uid = {?}',
cab08090 146 S::v('uid'));
08cce2ff 147 XDB::execute('DELETE FROM requests
fb9a56cb 148 WHERE user_id = {?} AND type="photo"',
cab08090 149 S::v('uid'));
5e2307dc 150 } elseif (Env::v('cancel')) {
08cce2ff 151 $sql = XDB::query('DELETE FROM requests
fb9a56cb 152 WHERE user_id={?} AND type="photo"',
cab08090 153 S::v('uid'));
fb9a56cb 154 }
155
08cce2ff 156 $sql = XDB::query('SELECT COUNT(*) FROM requests
abe7e055 157 WHERE user_id={?} AND type="photo"',
158 S::v('uid'));
fb9a56cb 159 $page->assign('submited', $sql->fetchOneCell());
160 $page->assign('has_trombi_x', file_exists($trombi_x));
fb9a56cb 161 }
162
e8599c21 163 function handler_profile(&$page, $x = null)
164 {
165 if (is_null($x)) {
166 return PL_NOT_FOUND;
167 }
168
169 global $globals;
170 require_once 'user.func.inc.php';
171
b13048df 172 $page->changeTpl('profile/profile.tpl', SIMPLE);
e8599c21 173
174 $view = 'private';
5e2307dc 175 if (!S::logged() || Env::v('view') == 'public') $view = 'public';
176 if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
e8599c21 177
178 if (is_numeric($x)) {
08cce2ff 179 $res = XDB::query(
e8599c21 180 "SELECT alias
181 FROM aliases AS a
182 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
183 WHERE matricule={?}", $x);
184 $login = $res->fetchOneCell();
185 } else {
186 $login = get_user_forlife($x);
187 }
188
189 if (empty($login)) {
924b4ba7 190 if (preg_match('/([-a-z]+)\.([-a-z]+)\.([0-9]{4})/i', $x, $matches)) {
191 $matches = str_replace('-', '_', $matches);
192 $res = XDB::query("SELECT user_id
193 FROM auth_user_md5
194 WHERE prenom LIKE {?} AND nom LIKE {?} AND promo = {?}
195 AND perms = 'pending'",
196 $matches[1], $matches[2], $matches[3]);
197 if ($res->numRows() == 1) {
198 $uid = $res->fetchOneCell();
199 pl_redirect('marketing/public/' . $uid);
200 }
201 }
e8599c21 202 return PL_NOT_FOUND;
203 }
204
5e2307dc 205 $new = Env::v('modif') == 'new';
cab08090 206 $user = get_user_details($login, S::v('uid'), $view);
3c85da85 207 $user['freetext'] = MiniWiki::WikiToHTML($user['freetext']);
60979eb7 208 $user['cv'] = MiniWiki::WikiToHTML($user['cv']);
e8599c21 209 $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'];
210 $page->assign('xorg_title', $title);
211
212 // photo
213
7da8ef90 214 $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
e8599c21 215
2f678da1 216 if (!isset($user['y']) and !isset($user['x'])) {
e8599c21 217 list($user['x'], $user['y']) = getimagesize("images/none.png");
218 }
2f678da1 219 if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
220 if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
221 if ($user['x'] > 240) {
e8599c21 222 $user['y'] = (integer)($user['y']*240/$user['x']);
223 $user['x'] = 240;
224 }
2f678da1 225 if ($user['y'] > 300) {
e8599c21 226 $user['x'] = (integer)($user['x']*300/$user['y']);
227 $user['y'] = 300;
228 }
2f678da1 229 if ($user['x'] < 160) {
e8599c21 230 $user['y'] = (integer)($user['y']*160/$user['x']);
231 $user['x'] = 160;
232 }
233
234 $page->assign('logged', has_user_right('private', $view));
235 if (!has_user_right($user['photo_pub'], $view)) {
236 $photo = "";
237 }
238
239 $page->assign_by_ref('x', $user);
240 $page->assign('photo_url', $photo);
241 // alias virtual
08cce2ff 242 $res = XDB::query(
e8599c21 243 "SELECT alias
244 FROM virtual
245 INNER JOIN virtual_redirect USING(vid)
246 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
247 WHERE ( redirect={?} OR redirect={?} )
248 AND alias LIKE '%@{$globals->mail->alias_dom}'",
cab08090 249 S::v('uid'),
e8599c21 250 $user['forlife'].'@'.$globals->mail->domain,
251 $user['forlife'].'@'.$globals->mail->domain2);
252 $page->assign('virtualalias', $res->fetchOneCell());
253
c99ef281 254 $page->addJsLink('close_on_esc.js');
6ce5dee4 255 header('Last-Modified: ' . date('r', strtotime($user['date'])));
e8599c21 256 }
257
2f678da1 258 function handler_p_edit(&$page, $opened_tab = 'general')
259 {
260 global $globals;
261
8b1f8e12 262 $page->changeTpl('profile/edit.tpl');
2f678da1 263
c99ef281 264 $page->addCssLink('profil.css');
2f678da1 265 $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
266
f62bd784 267 require_once dirname(__FILE__) . '/profile/tabs.inc.php';
2f678da1 268 require_once 'profil.func.inc.php';
269 require_once 'synchro_ax.inc.php';
270
3845b131 271 if (Post::v('register_from_ax_question')) {
272 XDB::execute('UPDATE auth_user_quick
2f678da1 273 SET profile_from_ax = 1
274 WHERE user_id = {?}',
cab08090 275 S::v('uid'));
2f678da1 276 }
3845b131 277 if (Post::v('add_to_nl')) {
278 require_once 'newsletter.inc.php';
714bc242 279 NewsLetter::subscribe();
280 }
281 if (Post::v('add_to_ax')) {
282 require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
283 AXLetter::subscribe();
3845b131 284 }
285 if (Post::v('add_to_promo')) {
286 $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
287 S::v('promo'));
288 $asso_id = $r->fetchOneCell();
289 XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
290 VALUES ({?}, {?})',
291 S::v('uid'), $asso_id);
9bb8bf21 292 $mmlist = new MMList(S::v('uid'), S::v('password'));
293 $mmlist->subscribe("promo".S::v('promo'));
3845b131 294 }
0baf0741 295 if (Post::v('sub_ml')) {
296 $subs = array_keys(Post::v('sub_ml'));
297 $current_domain = null;
298 foreach ($subs as $list) {
299 list($sub, $domain) = explode('@', $list);
300 if ($domain != $current_domain) {
301 $current_domain = $domain;
302 $client = new MMList(S::v('uid'), S::v('password'), $domain);
303 }
304 $client->subscribe($sub);
305 }
306 }
2f678da1 307
308 if (is_ax_key_missing()) {
309 $page->assign('no_private_key', true);
310 }
311
5e2307dc 312 if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
cab08090 313 ax_synchronize(S::v('bestalias'), S::v('uid'));
a7de4ef7 314 $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com');
2f678da1 315 }
316
317 // pour tous les tabs, la date de naissance pour verifier
318 // quelle est bien rentree et la date.
08cce2ff 319 $res = XDB::query(
2f678da1 320 "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y')
321 FROM auth_user_md5
cab08090 322 WHERE user_id={?}", S::v('uid'));
2f678da1 323 list($naissance, $date_modif_profil) = $res->fetchOneRow();
324
a7de4ef7 325 // lorsqu'on n'a pas la date de naissance en base de données
2f678da1 326 if (!$naissance) {
a7de4ef7 327 // la date de naissance n'existait pas et vient d'être soumise dans la variable
2f678da1 328 if (Env::has('birth')) {
329 //en cas d'erreur :
5e2307dc 330 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) {
2f678da1 331 $page->assign('etat_naissance', 'query');
a7de4ef7 332 $page->trig('Date de naissance incorrecte ou incohérente.');
fd8f77de 333 return;
2f678da1 334 }
335
336 //sinon
5e2307dc 337 $birth = sprintf("%s-%s-%s", substr(Env::v('birth'), 4, 4),
338 substr(Env::v('birth'), 2, 2),
339 substr(Env::v('birth'), 0, 2));
08cce2ff 340 XDB::execute("UPDATE auth_user_md5
2f678da1 341 SET naissance={?}
342 WHERE user_id={?}", $birth,
cab08090 343 S::v('uid'));
2f678da1 344 $page->assign('etat_naissance', 'ok');
fd8f77de 345 return;
2f678da1 346 }
347
348 $page->assign('etat_naissance', 'query');
fd8f77de 349 return; // on affiche le formulaire pour naissance
2f678da1 350 }
351
352 //doit-on faire un update ?
353 if (Env::has('modifier') || Env::has('suivant')) {
28bda7c5 354 require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
355 require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
2f678da1 356
357 if($page->nb_errs()) {
28bda7c5 358 require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
2f678da1 359 $page->assign('onglet', $opened_tab);
8b1f8e12 360 $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
fd8f77de 361 return;
2f678da1 362 }
363
364 $date=date("Y-m-j");//nouvelle date de mise a jour
365
366 //On sauvegarde l'uid pour l'AX
367 /* on sauvegarde les changements dans user_changes :
a7de4ef7 368 * on a juste besoin d'insérer le user_id de la personne dans la table
2f678da1 369 */
08cce2ff 370 XDB::execute('REPLACE INTO user_changes SET user_id={?}',
cab08090 371 S::v('uid'));
2f678da1 372
cab08090 373 if (!S::has('suid')) {
2f678da1 374 require_once 'notifs.inc.php';
cab08090 375 register_watch_op(S::v('uid'), WATCH_FICHE);
2f678da1 376 }
377
378 // mise a jour des champs relatifs au tab ouvert
28bda7c5 379 require_once dirname(__FILE__) . "/profile/update_{$opened_tab}.inc.php";
2f678da1 380
5ee95138 381 $log =& $_SESSION['log'];
2f678da1 382 $log->log('profil', $opened_tab);
383 $page->assign('etat_update', 'ok');
384 }
385
386 if (Env::has('suivant')) {
8b00e0e0 387 pl_redirect('profile/edit/' . get_next_tab($opened_tab));
2f678da1 388 }
389
28bda7c5 390 require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
391 require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
392 require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
2f678da1 393
394 $page->assign('onglet', $opened_tab);
8b1f8e12 395 $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
2f678da1 396
fd8f77de 397 return;
2f678da1 398 }
399
9b0fa329 400 function handler_p_orange(&$page)
401 {
8b1f8e12 402 $page->changeTpl('profile/orange.tpl');
9b0fa329 403
404 require_once 'validations.inc.php';
405 require_once 'xorg.misc.inc.php';
406
08cce2ff 407 $res = XDB::query(
2f678da1 408 "SELECT u.promo, u.promo_sortie
9b0fa329 409 FROM auth_user_md5 AS u
cab08090 410 WHERE user_id={?}", S::v('uid'));
9b0fa329 411
2f678da1 412 list($promo, $promo_sortie_old) = $res->fetchOneRow();
9b0fa329 413 $page->assign('promo_sortie_old', $promo_sortie_old);
414 $page->assign('promo', $promo);
415
416 if (!Env::has('promo_sortie')) {
fd8f77de 417 return;
9b0fa329 418 }
419
5e2307dc 420 $promo_sortie = Env::i('promo_sortie');
9b0fa329 421
422 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
a7de4ef7 423 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
9b0fa329 424 }
425 elseif ($promo_sortie < $promo + 3) {
a7de4ef7 426 $page->trig('Trop tôt');
9b0fa329 427 }
428 elseif ($promo_sortie == $promo_sortie_old) {
a7de4ef7 429 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 430 }
431 elseif ($promo_sortie == $promo + 3) {
08cce2ff 432 XDB::execute(
9b0fa329 433 "UPDATE auth_user_md5 set promo_sortie={?}
cab08090 434 WHERE user_id={?}", $promo_sortie, S::v('uid'));
a7de4ef7 435 $page->trig('Ton statut "orange" a été supprimé.');
9b0fa329 436 $page->assign('promo_sortie_old', $promo_sortie);
437 }
438 else {
439 $page->assign('promo_sortie', $promo_sortie);
440
441 if (Env::has('submit')) {
cab08090 442 $myorange = new OrangeReq(S::v('uid'),
9b0fa329 443 $promo_sortie);
444 $myorange->submit();
445 $page->assign('myorange', $myorange);
446 }
447 }
9b0fa329 448 }
449
2f678da1 450 function handler_referent(&$page, $x = null)
28e16d4d 451 {
28e16d4d 452 require_once 'user.func.inc.php';
453
454 if (is_null($x)) {
455 return PL_NOT_FOUND;
456 }
457
8b1f8e12 458 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 459
08cce2ff 460 $res = XDB::query(
28e16d4d 461 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
462 FROM auth_user_md5 AS u
2f678da1 463 INNER JOIN aliases AS a ON (u.user_id=a.id
464 AND FIND_IN_SET('bestalias', a.flags))
28e16d4d 465 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
466 AND a1.alias = {?}
467 AND a1.type!='homonyme')", $x);
468
469 if ($res->numRows() != 1) {
470 return PL_NOT_FOUND;
471 }
472
473 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
474
475 $page->assign('prenom', $prenom);
476 $page->assign('nom', $nom);
477 $page->assign('promo', $promo);
478 $page->assign('cv', $cv);
479 $page->assign('bestalias', $bestalias);
480 $page->assign('adr_pro', get_user_details_pro($user_id));
481
482 ///// recuperations infos referent
483
484 //expertise
08cce2ff 485 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
28e16d4d 486 $page->assign('expertise', $res->fetchOneCell());
487
488 //secteurs
489 $secteurs = $ss_secteurs = Array();
08cce2ff 490 $res = XDB::iterRow(
28e16d4d 491 "SELECT s.label, ss.label
492 FROM mentor_secteurs AS m
493 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
494 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
495 WHERE uid = {?}", $user_id);
496 while (list($sec, $ssec) = $res->next()) {
497 $secteurs[] = $sec;
498 $ss_secteurs[] = $ssec;
499 }
500 $page->assign_by_ref('secteurs', $secteurs);
501 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
502
503 //pays
08cce2ff 504 $res = XDB::query(
28e16d4d 505 "SELECT gp.pays
506 FROM mentor_pays AS m
507 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
508 WHERE uid = {?}", $user_id);
509 $page->assign('pays', $res->fetchColumn());
510
c99ef281 511 $page->addJsLink('close_on_esc.js');
28e16d4d 512 }
513
2f678da1 514 function handler_ref_search(&$page)
515 {
8b1f8e12 516 $page->changeTpl('profile/referent.tpl');
2f678da1 517
518 $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
519
5e2307dc 520 $secteur_sel = Post::v('secteur');
521 $ss_secteur_sel = Post::v('ss_secteur');
522 $pays_sel = Post::v('pays', '00');
523 $expertise_champ = Post::v('expertise');
2f678da1 524
525 $page->assign('pays_sel', $pays_sel);
526 $page->assign('expertise_champ', $expertise_champ);
527 $page->assign('secteur_sel', $secteur_sel);
528 $page->assign('ss_secteur_sel', $ss_secteur_sel);
529
530 //recuperation des noms de secteurs
08cce2ff 531 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 532 $secteurs[''] = '';
533 while (list($tmp_id, $tmp_label) = $res->next()) {
534 $secteurs[$tmp_id] = $tmp_label;
535 }
536 $page->assign_by_ref('secteurs', $secteurs);
537
538 //on recupere les sous-secteurs si necessaire
539 $ss_secteurs[''] = '';
540 if (!empty($secteur_sel)) {
08cce2ff 541 $res = XDB::iterRow("SELECT id, label FROM emploi_ss_secteur
2f678da1 542 WHERE secteur = {?}", $secteur_sel);
543 while (list($tmp_id, $tmp_label) = $res->next()) {
544 $ss_secteurs[$tmp_id] = $tmp_label;
545 }
546 }
547 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
548
549 //recuperation des noms de pays
08cce2ff 550 $res = XDB::iterRow("SELECT a2, pays FROM geoloc_pays
2f678da1 551 WHERE pays <> '' ORDER BY pays");
552 $pays['00'] = '';
553 while (list($tmp_id, $tmp_label) = $res->next()) {
554 $pays[$tmp_id] = $tmp_label;
555 }
556 $page->assign_by_ref('pays', $pays);
557
558 // nb de mentors
08cce2ff 559 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 560 $page->assign('mentors_number', $res->fetchOneCell());
561
562 if (!Env::has('Chercher')) {
fd8f77de 563 return;
2f678da1 564 }
565
566 // On vient d'un formulaire
567 $where = array();
568
569 if ($pays_sel != '00') {
570 $where[] = "mp.pid = '".addslashes($pays_sel)."'";
571 }
572 if ($secteur_sel) {
573 $where[] = "ms.secteur = '".addslashes($secteur_sel)."'";
574 if ($ss_secteur_sel) {
575 $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'";
576 }
577 }
578 if ($expertise_champ) {
579 $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')";
580 }
581
582 if ($where) {
583 $where = join(' AND ', $where);
584
585 $sql = "SELECT m.uid, a.prenom, a.nom, a.promo,
586 l.alias AS bestalias, m.expertise, mp.pid,
587 ms.secteur, ms.ss_secteur
588 FROM mentor AS m
589 LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id)
590 INNER JOIN aliases AS l ON (a.user_id=l.id AND
591 FIND_IN_SET('bestalias', l.flags))
592 LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid)
593 LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid)
594 WHERE $where
595 GROUP BY uid
596 ORDER BY RAND({?})";
cab08090 597 $res = XDB::iterator($sql, S::v('uid'));
2f678da1 598
599 if ($res->total() == 0) {
600 $page->assign('recherche_trop_large', true);
fd8f77de 601 return;
2f678da1 602 }
603
604 $nb_max_res_total = 100;
605 $nb_max_res_ppage = 10;
606
5e2307dc 607 $curpage = Env::i('curpage', 1);
2f678da1 608 $personnes = array();
609 $i = 0;
610
611 while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) {
612 $the_page = intval($i / $nb_max_res_ppage) + 1;
613 if ($the_page == $curpage) {
614 $personnes[] = $pers;
615 }
616 $i ++;
617 }
618
619 $page->assign('personnes', $personnes);
620 $page->assign('curpage', $curpage);
621 $page->assign('nb_pages_total',
622 intval($res->total() / $nb_max_res_ppage) + 1);
623 }
2f678da1 624 }
625
926f16d7 626 function handler_p_usage(&$page)
627 {
8b1f8e12 628 $page->changeTpl('profile/nomusage.tpl');
926f16d7 629
630 require_once 'validations.inc.php';
631 require_once 'xorg.misc.inc.php';
632
08cce2ff 633 $res = XDB::query(
2f678da1 634 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 635 FROM auth_user_md5 AS u
2f678da1 636 LEFT JOIN aliases AS e ON(u.user_id = e.id
637 AND FIND_IN_SET('usage', e.flags))
cab08090 638 WHERE user_id={?}", S::v('uid'));
926f16d7 639
2f678da1 640 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
926f16d7 641 $flags = new flagset($flags);
642 $page->assign('usage_old', $usage_old);
643 $page->assign('alias_old', $alias_old);
644
5e2307dc 645 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 646 $nom_usage = strtoupper($nom_usage);
647 $page->assign('usage_req', $nom_usage);
648
649 if (Env::has('submit') && ($nom_usage != $usage_old)) {
650 // on vient de recevoir une requete, differente de l'ancien nom d'usage
651 if ($nom_usage == $nom) {
652 $page->assign('same', true);
a7de4ef7 653 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 654 // on calcule l'alias pour l'afficher
5e2307dc 655 $reason = Env::v('reason');
926f16d7 656 if ($reason == 'other') {
5e2307dc 657 $reason = Env::v('other_reason');
926f16d7 658 }
cab08090 659 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 660 $myusage->submit();
661 $page->assign('myusage', $myusage);
662 }
663 }
926f16d7 664 }
665
a1d79217 666 function handler_xnet(&$page)
667 {
8b1f8e12 668 $page->changeTpl('profile/groupesx.tpl');
a1d79217 669 $page->assign('xorg_title', 'Polytechnique.org - Promo, Groupes X, Binets');
670
671 $req = XDB::query('
46e1d3ba 672 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
673 COUNT(e.eid) AS events, mail_domain AS lists
674 FROM groupex.membres AS m
675 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
676 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
677 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 678 $page->assign('assos', $req->fetchAllAssoc());
679 }
680
e49018a7 681 function handler_vcard(&$page, $x = null)
682 {
683 if (is_null($x)) {
684 return PL_NOT_FOUND;
685 }
686
687 global $globals;
688
689 if (substr($x, -4) == '.vcf') {
690 $x = substr($x, 0, strlen($x) - 4);
691 }
692
5e193297 693 $vcard = new VCard($x);
694 $vcard->do_page($page);
e49018a7 695 }
92423144 696
697 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 698 $page->changeTpl('profile/admin_trombino.tpl');
92423144 699 $page->assign('xorg_title','Polytechnique.org - Administration - Trombino');
700 $page->assign('uid', $uid);
701
702 $q = XDB::query(
703 "SELECT a.alias,promo
704 FROM auth_user_md5 AS u
705 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
706 WHERE user_id = {?}", $uid);
707 list($forlife, $promo) = $q->fetchOneRow();
708
709 switch ($action) {
710
711 case "original":
712 header("Content-type: image/jpeg");
713 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
714 exit;
715 break;
716
717 case "new":
718 $data = file_get_contents($_FILES['userfile']['tmp_name']);
719 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
720 $mimetype = substr($_FILES['userfile']['type'], 6);
721 unlink($_FILES['userfile']['tmp_name']);
722 XDB::execute(
723 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
724 $uid, $mimetype, $data, $x, $y);
725 break;
726
727 case "delete":
728 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
729 break;
730 }
731
732 $page->assign('forlife', $forlife);
733 }
734 function handler_admin_binets(&$page, $action = 'list', $id = null) {
92423144 735 $page->assign('xorg_title','Polytechnique.org - Administration - Binets');
736 $page->assign('title', 'Gestion des binets');
737 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
738 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 739 $table_editor->describe('text','intitulé',true);
92423144 740 $table_editor->apply($page, $action, $id);
741 }
742 function handler_admin_formations(&$page, $action = 'list', $id = null) {
92423144 743 $page->assign('xorg_title','Polytechnique.org - Administration - Formations');
744 $page->assign('title', 'Gestion des formations');
745 $table_editor = new PLTableEditor('admin/formations','applis_def','id');
746 $table_editor->add_join_table('applis_ins','aid',true);
a7de4ef7 747 $table_editor->describe('text','intitulé',true);
92423144 748 $table_editor->describe('url','site web',false);
749 $table_editor->apply($page, $action, $id);
750 }
751 function handler_admin_groupesx(&$page, $action = 'list', $id = null) {
92423144 752 $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X');
753 $page->assign('title', 'Gestion des Groupes X');
754 $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id');
755 $table_editor->add_join_table('groupesx_ins','gid',true);
a7de4ef7 756 $table_editor->describe('text','intitulé',true);
92423144 757 $table_editor->describe('url','site web',false);
758 $table_editor->apply($page, $action, $id);
759 }
760 function handler_admin_medals(&$page, $action = 'list', $id = null) {
92423144 761 $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions');
762 $page->assign('title', 'Gestion des Distinctions');
763 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 764 $table_editor->describe('text', 'intitulé', true);
92423144 765 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 766 $table_editor->describe('flags', 'valider', true);
92423144 767 $table_editor->apply($page, $action, $id);
768 if ($id && $action == 'edit') {
8b1f8e12 769 $page->changeTpl('profile/admin_decos.tpl');
92423144 770
771 $mid = $id;
772
773 if (Post::v('act') == 'del') {
774 XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
775 } elseif (Post::v('act') == 'new') {
776 XDB::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})',
777 $mid, max(array_keys(Post::v('grades', array(0))))+1);
778 } else {
779 foreach (Post::v('grades', array()) as $gid=>$text) {
780 XDB::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid);
781 }
782 }
783 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
784 $page->assign('grades', $res);
785 }
786 }
7d8b17cb 787}
788
a7de4ef7 789// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 790?>