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