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