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