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