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