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