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