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