Some clean up.
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 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(
2398e553
SJ
27 'photo' => $this->make_hook('photo', AUTH_PUBLIC),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP),
e49018a7 29
2398e553
SJ
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/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'),
34 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
35 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH),
36 'profile/ajax/tel' => $this->make_hook('ajax_tel', AUTH_COOKIE, 'user', NO_AUTH),
37 'profile/ajax/edu' => $this->make_hook('ajax_edu', AUTH_COOKIE, 'user', NO_AUTH),
38 'profile/ajax/medal' => $this->make_hook('ajax_medal', AUTH_COOKIE, 'user', NO_AUTH),
39 'profile/networking' => $this->make_hook('networking', AUTH_PUBLIC),
40 'profile/ajax/job' => $this->make_hook('ajax_job', AUTH_COOKIE, 'user', NO_AUTH),
41 'profile/ajax/secteur' => $this->make_hook('ajax_secteur', AUTH_COOKIE, 'user', NO_AUTH),
42 'profile/ajax/skill' => $this->make_hook('ajax_skill', AUTH_COOKIE, 'user', NO_AUTH),
43 'profile/ajax/searchname' => $this->make_hook('ajax_searchname', AUTH_COOKIE, 'user', NO_AUTH),
44 'javascript/applis.js' => $this->make_hook('applis_js', AUTH_COOKIE),
45 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE),
46 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC),
47 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
48 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP),
e49018a7 49
2398e553
SJ
50 'referent' => $this->make_hook('referent', AUTH_COOKIE),
51 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE),
52 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
53 'referent/ssect' => $this->make_hook('ref_sect', AUTH_COOKIE, 'user', NO_AUTH),
54 'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
2f678da1 55
2398e553 56 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
926f16d7 57
2398e553
SJ
58 'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS),
59 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
60 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
61 'admin/education' => $this->make_hook('admin_education', AUTH_MDP, 'admin'),
62 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_MDP, 'admin'),
63 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_MDP, 'admin'),
043bbacf 64 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_MDP, 'admin'),
2398e553
SJ
65 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
66 'admin/secteurs' => $this->make_hook('admin_secteurs', AUTH_MDP, 'admin'),
67 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'),
68 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
69 'admin/ss_secteurs' => $this->make_hook('admin_ss_secteurs', AUTH_MDP, 'admin'),
70 'admin/fonctions' => $this->make_hook('admin_fonctions', AUTH_MDP, 'admin'),
92423144 71
7d8b17cb 72 );
73 }
74
e8599c21 75 /* XXX COMPAT */
76 function handler_fiche(&$page)
77 {
5e2307dc 78 return $this->handler_profile($page, Env::v('user'));
e8599c21 79 }
80
adbdf493 81 function handler_photo(&$page, $x = null, $req = null)
82 {
83 if (is_null($x)) {
84 return PL_NOT_FOUND;
85 }
86
08cce2ff 87 $res = XDB::query("SELECT id, pub FROM aliases
adbdf493 88 LEFT JOIN photo ON(id = uid)
89 WHERE alias = {?}", $x);
90 list($uid, $photo_pub) = $res->fetchOneRow();
91
cab08090 92 if ($req && S::logged()) {
adbdf493 93 include 'validations.inc.php';
94 $myphoto = PhotoReq::get_request($uid);
95 Header('Content-type: image/'.$myphoto->mimetype);
96 echo $myphoto->data;
97 } else {
08cce2ff 98 $res = XDB::query(
adbdf493 99 "SELECT attachmime, attach
100 FROM photo
101 WHERE uid={?}", $uid);
102
2f678da1 103 if ((list($type, $data) = $res->fetchOneRow())
cab08090 104 && ($photo_pub == 'public' || S::logged())) {
adbdf493 105 Header("Content-type: image/$type");
106 echo $data;
107 } else {
108 Header('Content-type: image/png');
fb9a56cb 109 echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
adbdf493 110 }
111 }
112 exit;
113 }
114
85cc366b
FB
115 function handler_medal(&$page, $mid)
116 {
bd6a5fe3
VZ
117 $thumb = ($mid == 'thumb');
118 $mid = $thumb ? @func_get_arg(2) : $mid;
119
85cc366b
FB
120 $res = XDB::query("SELECT img
121 FROM profile_medals
122 WHERE id = {?}",
123 $mid);
bd6a5fe3
VZ
124 $img = $thumb ?
125 dirname(__FILE__).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() :
126 dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell();
85cc366b
FB
127 $type = mime_content_type($img);
128 header("Content-Type: $type");
129 echo file_get_contents($img);
130 exit;
131 }
132
40176c6c
GB
133 function handler_networking(&$page, $mid)
134 {
135 $res = XDB::query("SELECT icon
136 FROM profile_networking_enum
137 WHERE network_type = {?}",
138 $mid);
139 $img = dirname(__FILE__) . '/../htdocs/images/networking/' . $res->fetchOneCell();
140 $type = mime_content_type($img);
141 header("Content-Type: $type");
142 echo file_get_contents($img);
143 exit;
144 }
145
fb9a56cb 146 function handler_photo_change(&$page)
147 {
ebfdf077 148 global $globals;
8b1f8e12 149 $page->changeTpl('profile/trombino.tpl');
fb9a56cb 150
151 require_once('validations.inc.php');
152
cab08090 153 $trombi_x = '/home/web/trombino/photos'.S::v('promo')
154 .'/'.S::v('forlife').'.jpg';
fb9a56cb 155
156 if (Env::has('upload')) {
8827fc52
VZ
157 S::assert_xsrf_token();
158
abe7e055 159 $upload = new PlUpload(S::v('forlife'), 'photo');
160 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
a7d35093 161 $page->trigError('Une erreur est survenue lors du téléchargement du fichier');
abe7e055 162 } else {
163 $myphoto = new PhotoReq(S::v('uid'), $upload);
164 if ($myphoto->isValid()) {
165 $myphoto->submit();
fb9a56cb 166 }
fb9a56cb 167 }
168 } elseif (Env::has('trombi')) {
8827fc52
VZ
169 S::assert_xsrf_token();
170
abe7e055 171 $upload = new PlUpload(S::v('forlife'), 'photo');
172 if ($upload->copyFrom($trombi_x)) {
173 $myphoto = new PhotoReq(S::v('uid'), $upload);
174 if ($myphoto->isValid()) {
175 $myphoto->commit();
176 $myphoto->clean();
177 }
fb9a56cb 178 }
5e2307dc 179 } elseif (Env::v('suppr')) {
8827fc52
VZ
180 S::assert_xsrf_token();
181
84868ee9
FB
182 XDB::execute('DELETE FROM photo
183 WHERE uid = {?}',
184 S::v('uid'));
185 XDB::execute('DELETE FROM requests
186 WHERE user_id = {?} AND type="photo"',
187 S::v('uid'));
ebfdf077 188 $globals->updateNbValid();
5e2307dc 189 } elseif (Env::v('cancel')) {
8827fc52
VZ
190 S::assert_xsrf_token();
191
84868ee9
FB
192 $sql = XDB::query('DELETE FROM requests
193 WHERE user_id={?} AND type="photo"',
194 S::v('uid'));
ebfdf077 195 $globals->updateNbValid();
fb9a56cb 196 }
197
84868ee9
FB
198 $sql = XDB::query('SELECT COUNT(*)
199 FROM requests
200 WHERE user_id={?} AND type="photo"',
abe7e055 201 S::v('uid'));
fb9a56cb 202 $page->assign('submited', $sql->fetchOneCell());
203 $page->assign('has_trombi_x', file_exists($trombi_x));
fb9a56cb 204 }
205
e8599c21 206 function handler_profile(&$page, $x = null)
207 {
208 if (is_null($x)) {
209 return PL_NOT_FOUND;
210 }
211
212 global $globals;
213 require_once 'user.func.inc.php';
214
b13048df 215 $page->changeTpl('profile/profile.tpl', SIMPLE);
e8599c21 216
217 $view = 'private';
5e2307dc 218 if (!S::logged() || Env::v('view') == 'public') $view = 'public';
219 if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
e8599c21 220
221 if (is_numeric($x)) {
08cce2ff 222 $res = XDB::query(
e1635d16 223 "SELECT alias
e8599c21 224 FROM aliases AS a
225 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
226 WHERE matricule={?}", $x);
227 $login = $res->fetchOneCell();
228 } else {
5350d751
FB
229 $login = get_user_forlife($x, S::logged() ? '_default_user_callback'
230 : '_silent_user_callback');
e8599c21 231 }
232
233 if (empty($login)) {
ba25f663
FB
234 $user = get_not_registered_user($x, true);
235 if ($user->total() != 1) {
236 return PL_NOT_FOUND;
924b4ba7 237 }
ba25f663
FB
238 $user = $user->next();
239 if (S::logged()) {
240 pl_redirect('marketing/public/' . $user['user_id']);
241 }
242 $user['forlife'] = $x;
243 } else {
244 $new = Env::v('modif') == 'new';
245 $user = get_user_details($login, S::v('uid'), $view);
e8599c21 246 }
ba25f663 247
e31c1c3e 248 if (S::logged()) {
732e5855 249 S::logger()->log('view_profile', $login);
e8599c21 250 }
251
f45b6a99 252 $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] );
143ba7c9 253 $page->setTitle($title);
e8599c21 254
255 // photo
256
7da8ef90 257 $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
e8599c21 258
2f678da1 259 if (!isset($user['y']) and !isset($user['x'])) {
e8599c21 260 list($user['x'], $user['y']) = getimagesize("images/none.png");
261 }
2f678da1 262 if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
263 if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
264 if ($user['x'] > 240) {
e8599c21 265 $user['y'] = (integer)($user['y']*240/$user['x']);
266 $user['x'] = 240;
267 }
2f678da1 268 if ($user['y'] > 300) {
e8599c21 269 $user['x'] = (integer)($user['x']*300/$user['y']);
270 $user['y'] = 300;
271 }
2f678da1 272 if ($user['x'] < 160) {
e8599c21 273 $user['y'] = (integer)($user['y']*160/$user['x']);
274 $user['x'] = 160;
275 }
276
277 $page->assign('logged', has_user_right('private', $view));
278 if (!has_user_right($user['photo_pub'], $view)) {
279 $photo = "";
280 }
281
282 $page->assign_by_ref('x', $user);
283 $page->assign('photo_url', $photo);
284 // alias virtual
08cce2ff 285 $res = XDB::query(
e8599c21 286 "SELECT alias
287 FROM virtual
288 INNER JOIN virtual_redirect USING(vid)
289 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
290 WHERE ( redirect={?} OR redirect={?} )
291 AND alias LIKE '%@{$globals->mail->alias_dom}'",
660ca64a 292 $user['user_id'],
e8599c21 293 $user['forlife'].'@'.$globals->mail->domain,
294 $user['forlife'].'@'.$globals->mail->domain2);
295 $page->assign('virtualalias', $res->fetchOneCell());
24f4c06a 296 $page->assign('view', $view);
e8599c21 297
c99ef281 298 $page->addJsLink('close_on_esc.js');
6ce5dee4 299 header('Last-Modified: ' . date('r', strtotime($user['date'])));
e8599c21 300 }
301
5122b820 302 function handler_ax(&$page, $user = null)
303 {
304 require_once 'user.func.inc.php';
305 $user = get_user_forlife($user);
306 if (!$user) {
307 return PL_NOT_FOUND;
308 }
309 $res = XDB::query('SELECT matricule_ax
310 FROM auth_user_md5 AS u
311 INNER JOIN aliases AS a ON (a.type = "a_vie" AND a.id = u.user_id)
312 WHERE a.alias = {?}', $user);
313 $mat = $res->fetchOneCell();
314 if (!intval($mat)) {
315 $page->kill("Le matricule AX de $user est inconnu");
316 }
317 http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&anc_id=$mat");
318 }
319
46ae38a9 320 function handler_p_edit(&$page, $opened_tab = null, $mode = null)
2f678da1 321 {
322 global $globals;
323
e1635d16
FB
324 // AX Synchronization
325 require_once 'synchro_ax.inc.php';
2f678da1 326 if (is_ax_key_missing()) {
327 $page->assign('no_private_key', true);
328 }
5e2307dc 329 if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
cab08090 330 ax_synchronize(S::v('bestalias'), S::v('uid'));
a7d35093 331 $page->trigSuccess('Ton profil a été synchronisé avec celui du site polytechniciens.com');
2f678da1 332 }
333
7bff4cb0 334 // Build the page
c6a7beb2 335 $page->addJsLink('ajax.js');
46ae38a9
FB
336 $page->addJsLink('applis.js');
337 $page->addJsLink('grades.js');
16594a1a 338 $page->addJsLink('profile.js');
4b4b4b67 339 $page->addJsLink('jquery.autocomplete.js');
46ae38a9 340 $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true, true);
e1635d16
FB
341 require_once dirname(__FILE__) . '/profile/page.inc.php';
342 $wiz->addPage('ProfileGeneral', 'Général', 'general');
0b14f91d 343 $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
e1635d16 344 $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly');
a7c28fff 345 $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco');
3950bc21 346 $wiz->addPage('ProfileJobs', 'Informations professionnelles', 'emploi');
e1635d16
FB
347 $wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill');
348 $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor');
46ae38a9 349 $wiz->apply($page, 'profile/edit', $opened_tab, $mode);
35aedff2 350
7bff4cb0
FB
351 // Misc checks
352 $res = XDB::query("SELECT user_id
353 FROM auth_user_md5
354 WHERE user_id = {?} AND naissance = '0000-00-00'", S::i('uid'));
355 if ($res->numRows()) {
a7d35093 356 $page->trigWarning("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser"
7bff4cb0
FB
357 . " la procédure de récupération de mot de passe si un jour tu le perdais");
358 }
359
46f272fe 360 $page->setTitle('Mon Profil');
2f678da1 361 }
362
46ae38a9
FB
363 function handler_applis_js(&$page)
364 {
365 header('Content-Type: text/javascript; charset=utf-8');
366 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
367 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
368 header('Cache-Control: no-cache, must-revalidate');
369 header('Pragma: no-cache');
370 $page->changeTpl('profile/applis.js.tpl', NO_SKIN);
371 require_once "applis.func.inc.php";
372 }
373
374 function handler_grades_js(&$page)
375 {
376 header('Content-Type: text/javascript; charset=utf-8');
377 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
378 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
379 header('Cache-Control: no-cache, must-revalidate');
380 header('Pragma: no-cache');
381 $page->changeTpl('profile/grades.js.tpl', NO_SKIN);
382 $res = XDB::iterator("SELECT *
383 FROM profile_medals_grades
384 ORDER BY mid, pos");
385 $grades = array();
386 while ($tmp = $res->next()) {
387 $grades[$tmp['mid']][] = $tmp;
388 }
389 $page->assign('grades', $grades);
390
391 $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
392 FROM profile_medals
393 ORDER BY type, text");
394 $mlist = array();
395 while ($tmp = $res->next()) {
396 $mlist[$tmp['type']][] = $tmp;
397 }
398 $page->assign('medal_list', $mlist);
399 }
400
c6a7beb2
FB
401 function handler_ajax_address(&$page, $adid)
402 {
46ae38a9 403 header('Content-Type: text/html; charset=utf-8');
c6a7beb2
FB
404 $page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
405 $page->assign('i', $adid);
406 $page->assign('adr', array());
c6a7beb2
FB
407 }
408
bde2be3b 409 function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
c6a7beb2 410 {
46ae38a9 411 header('Content-Type: text/html; charset=utf-8');
bde2be3b
GB
412 $page->changeTpl('profile/phone.tpl', NO_SKIN);
413 $page->assign('prefid', $prefid);
414 $page->assign('prefname', $prefname);
415 $page->assign('telid', $telid);
c6a7beb2 416 $page->assign('tel', array());
c6a7beb2
FB
417 }
418
043bbacf
SJ
419 function handler_ajax_edu(&$page, $eduid)
420 {
421 header('Content-Type: text/html; charset=utf-8');
422 $page->changeTpl('profile/edu.tpl', NO_SKIN);
423 $res = XDB::iterator("SELECT id, field
424 FROM profile_education_field_enum
425 ORDER BY field");
426 $page->assign('edu_fields', $res->fetchAllAssoc());
427 $page->assign('eduid', $eduid);
428 require_once "applis.func.inc.php";
429 }
430
85cc366b
FB
431 function handler_ajax_medal(&$page, $id)
432 {
46ae38a9 433 header('Content-Type: text/html; charset=utf-8');
85cc366b
FB
434 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
435 $page->assign('id', $id);
436 $page->assign('medal', array('valid' => 0, 'grade' => 0));
85cc366b
FB
437 }
438
2dcac0f5
FB
439 function handler_ajax_job(&$page, $id)
440 {
46ae38a9 441 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
442 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN);
443 $page->assign('i', $id);
444 $page->assign('job', array());
2dcac0f5 445 $page->assign('new', true);
1879c7b2
FB
446 $page->assign('secteurs', XDB::iterator("SELECT id, label
447 FROM emploi_secteur"));
448 $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
449 FROM fonctions_def
450 ORDER BY id"));
2dcac0f5
FB
451 }
452
453 function handler_ajax_secteur(&$page, $id, $sect, $ssect = -1)
454 {
46ae38a9 455 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
456 $res = XDB::iterator("SELECT id, label
457 FROM emploi_ss_secteur
458 WHERE secteur = {?}", $sect);
459 $page->changeTpl('profile/jobs.secteur.tpl', NO_SKIN);
460 $page->assign('id', $id);
461 $page->assign('ssecteurs', $res);
462 $page->assign('sel', $ssect);
463 }
464
f25e1a56
FB
465 function handler_ajax_skill(&$page, $cat, $id)
466 {
46ae38a9 467 header('Content-Type: text/html; charset=utf-8');
f25e1a56 468 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN);
f25e1a56
FB
469 $page->assign('cat', $cat);
470 $page->assign('id', $id);
471 if ($cat == 'competences') {
472 $page->assign('levels', array('initié' => 'initié',
473 'bonne connaissance' => 'bonne connaissance',
474 'expert' => 'expert'));
475 } else {
476 $page->assign('levels', array(1 => 'connaissance basique',
477 2 => 'maîtrise des bases',
478 3 => 'maîtrise limitée',
479 4 => 'maîtrise générale',
480 5 => 'bonne maîtrise',
481 6 => 'maîtrise complète'));
482 }
483 }
484
b04882ff
PC
485 function handler_ajax_searchname(&$page, $snid)
486 {
487 header('Content-Type: text/html; charset=utf-8');
488 $page->changeTpl('profile/general.searchname.tpl', NO_SKIN);
489 $page->assign('i', $snid);
490 $page->assign('sn', array());
491 $page->assign('newsn', true);
492 }
493
9b0fa329 494 function handler_p_orange(&$page)
495 {
8b1f8e12 496 $page->changeTpl('profile/orange.tpl');
9b0fa329 497
498 require_once 'validations.inc.php';
9b0fa329 499
08cce2ff 500 $res = XDB::query(
2f678da1 501 "SELECT u.promo, u.promo_sortie
9b0fa329 502 FROM auth_user_md5 AS u
cab08090 503 WHERE user_id={?}", S::v('uid'));
9b0fa329 504
2f678da1 505 list($promo, $promo_sortie_old) = $res->fetchOneRow();
9b0fa329 506 $page->assign('promo_sortie_old', $promo_sortie_old);
507 $page->assign('promo', $promo);
508
509 if (!Env::has('promo_sortie')) {
fd8f77de 510 return;
8827fc52
VZ
511 } else {
512 S::assert_xsrf_token();
9b0fa329 513 }
514
5e2307dc 515 $promo_sortie = Env::i('promo_sortie');
9b0fa329 516
517 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
a7d35093 518 $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres');
9b0fa329 519 }
520 elseif ($promo_sortie < $promo + 3) {
a7d35093 521 $page->trigError('Trop tôt');
9b0fa329 522 }
523 elseif ($promo_sortie == $promo_sortie_old) {
a7d35093 524 $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 525 }
526 elseif ($promo_sortie == $promo + 3) {
08cce2ff 527 XDB::execute(
e1635d16 528 "UPDATE auth_user_md5 set promo_sortie={?}
cab08090 529 WHERE user_id={?}", $promo_sortie, S::v('uid'));
a7d35093 530 $page->trigSuccess('Ton statut "orange" a été supprimé.');
9b0fa329 531 $page->assign('promo_sortie_old', $promo_sortie);
532 }
533 else {
534 $page->assign('promo_sortie', $promo_sortie);
535
536 if (Env::has('submit')) {
cab08090 537 $myorange = new OrangeReq(S::v('uid'),
9b0fa329 538 $promo_sortie);
539 $myorange->submit();
540 $page->assign('myorange', $myorange);
541 }
542 }
9b0fa329 543 }
544
2f678da1 545 function handler_referent(&$page, $x = null)
28e16d4d 546 {
28e16d4d 547 require_once 'user.func.inc.php';
548
549 if (is_null($x)) {
550 return PL_NOT_FOUND;
551 }
552
8b1f8e12 553 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 554
08cce2ff 555 $res = XDB::query(
28e16d4d 556 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
557 FROM auth_user_md5 AS u
2f678da1 558 INNER JOIN aliases AS a ON (u.user_id=a.id
559 AND FIND_IN_SET('bestalias', a.flags))
28e16d4d 560 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
561 AND a1.alias = {?}
562 AND a1.type!='homonyme')", $x);
563
564 if ($res->numRows() != 1) {
565 return PL_NOT_FOUND;
566 }
567
568 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
569
570 $page->assign('prenom', $prenom);
571 $page->assign('nom', $nom);
572 $page->assign('promo', $promo);
37633309 573 $page->assign('cv', MiniWiki::WikiToHTML($cv, true));
28e16d4d 574 $page->assign('bestalias', $bestalias);
575 $page->assign('adr_pro', get_user_details_pro($user_id));
576
577 ///// recuperations infos referent
578
579 //expertise
08cce2ff 580 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
28e16d4d 581 $page->assign('expertise', $res->fetchOneCell());
582
583 //secteurs
584 $secteurs = $ss_secteurs = Array();
08cce2ff 585 $res = XDB::iterRow(
28e16d4d 586 "SELECT s.label, ss.label
587 FROM mentor_secteurs AS m
588 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
589 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
590 WHERE uid = {?}", $user_id);
591 while (list($sec, $ssec) = $res->next()) {
592 $secteurs[] = $sec;
593 $ss_secteurs[] = $ssec;
594 }
595 $page->assign_by_ref('secteurs', $secteurs);
596 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
597
598 //pays
08cce2ff 599 $res = XDB::query(
28e16d4d 600 "SELECT gp.pays
601 FROM mentor_pays AS m
602 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
603 WHERE uid = {?}", $user_id);
604 $page->assign('pays', $res->fetchColumn());
605
c99ef281 606 $page->addJsLink('close_on_esc.js');
28e16d4d 607 }
608
ff3eb9b7 609 function handler_ref_search(&$page, $action = null, $subaction = null)
2f678da1 610 {
8f201b69
FB
611 $wp = new PlWikiPage('Docs.Emploi');
612 $wp->buildCache();
613
46f272fe 614 $page->setTitle('Conseil Pro');
2f678da1 615
2f678da1 616 //recuperation des noms de secteurs
08cce2ff 617 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 618 $secteurs[''] = '';
619 while (list($tmp_id, $tmp_label) = $res->next()) {
620 $secteurs[$tmp_id] = $tmp_label;
621 }
622 $page->assign_by_ref('secteurs', $secteurs);
623
2f678da1 624 // nb de mentors
08cce2ff 625 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 626 $page->assign('mentors_number', $res->fetchOneCell());
627
2f678da1 628 // On vient d'un formulaire
ff3eb9b7 629 $where = array();
630 $pays_sel = XDB::escape(Env::v('pays_sel'));
631 $secteur_sel = XDB::escape(Env::v('secteur'));
632 $ss_secteur_sel = XDB::escape(Env::v('ss_secteur'));
633 $expertise_champ = XDB::escape(Env::v('expertise'));
634
635 if ($pays_sel != "''") {
636 $where[] = "mp.pid = $pays_sel";
637 }
638 if ($secteur_sel != "''") {
639 $where[] = "ms.secteur = $secteur_sel";
640 if ($ss_secteur_sel != "''") {
641 $where[] = "ms.ss_secteur = $ss_secteur_sel";
2f678da1 642 }
643 }
ff3eb9b7 644 if ($expertise_champ != "''") {
645 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 646 }
647
648 if ($where) {
649 $where = join(' AND ', $where);
650
e1635d16
FB
651 $set = new UserSet("INNER JOIN mentor AS m ON (m.uid = u.user_id)
652 LEFT JOIN mentor_pays AS mp ON (mp.uid = m.uid)
ff3eb9b7 653 LEFT JOIN mentor_secteurs AS ms ON (ms.uid = m.uid)",
654 $where);
655 $set->addMod('mentor', 'Référents');
656 $set->apply('referent/search', $page, $action, $subaction);
657 if ($set->count() > 100) {
e1635d16 658 $page->assign('recherche_trop_large', true);
2f678da1 659 }
ff3eb9b7 660 }
e1635d16 661 $page->changeTpl('profile/referent.tpl');
ff3eb9b7 662 }
2f678da1 663
e1635d16 664 function handler_ref_sect(&$page, $sect)
ff3eb9b7 665 {
666 header('Content-Type: text/html; charset=utf-8');
05cb05c0 667 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 668 $page->assign('onchange', 'setSSecteurs()');
669 $page->assign('id', 'ssect_field');
670 $page->assign('name', 'ss_secteur');
671 $it = XDB::iterator("SELECT id,label AS field
e1635d16 672 FROM emploi_ss_secteur
ff3eb9b7 673 WHERE secteur = {?}", $sect);
674 $page->assign('list', $it);
675 }
2f678da1 676
ff3eb9b7 677 function handler_ref_country(&$page, $sect, $ssect = '')
678 {
679 header('Content-Type: text/html; charset=utf-8');
05cb05c0 680 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 681 $page->assign('name', 'pays_sel');
682 $where = ($ssect ? ' AND ms.ss_secteur = {?}' : '');
683 $it = XDB::iterator("SELECT a2 AS id, pays AS field
684 FROM geoloc_pays AS g
685 INNER JOIN mentor_pays AS mp ON (mp.pid = g.a2)
686 INNER JOIN mentor_secteurs AS ms ON (ms.uid = mp.uid)
687 WHERE ms.secteur = {?} $where
688 GROUP BY a2
689 ORDER BY pays", $sect, $ssect);
690 $page->assign('list', $it);
2f678da1 691 }
692
926f16d7 693 function handler_p_usage(&$page)
694 {
8b1f8e12 695 $page->changeTpl('profile/nomusage.tpl');
926f16d7 696
697 require_once 'validations.inc.php';
926f16d7 698
08cce2ff 699 $res = XDB::query(
2f678da1 700 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 701 FROM auth_user_md5 AS u
2f678da1 702 LEFT JOIN aliases AS e ON(u.user_id = e.id
703 AND FIND_IN_SET('usage', e.flags))
cab08090 704 WHERE user_id={?}", S::v('uid'));
926f16d7 705
2f678da1 706 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
113f6de8 707 $flags = new PlFlagSet($flags);
926f16d7 708 $page->assign('usage_old', $usage_old);
709 $page->assign('alias_old', $alias_old);
710
e1635d16 711 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 712 $nom_usage = strtoupper($nom_usage);
713 $page->assign('usage_req', $nom_usage);
714
715 if (Env::has('submit') && ($nom_usage != $usage_old)) {
8827fc52
VZ
716 S::assert_xsrf_token();
717
926f16d7 718 // on vient de recevoir une requete, differente de l'ancien nom d'usage
719 if ($nom_usage == $nom) {
720 $page->assign('same', true);
a7de4ef7 721 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 722 // on calcule l'alias pour l'afficher
5e2307dc 723 $reason = Env::v('reason');
926f16d7 724 if ($reason == 'other') {
5e2307dc 725 $reason = Env::v('other_reason');
926f16d7 726 }
cab08090 727 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 728 $myusage->submit();
729 $page->assign('myusage', $myusage);
730 }
731 }
926f16d7 732 }
733
a1d79217 734 function handler_xnet(&$page)
735 {
8b1f8e12 736 $page->changeTpl('profile/groupesx.tpl');
46f272fe 737 $page->setTitle('Promo, Groupes X, Binets');
e1635d16 738
a1d79217 739 $req = XDB::query('
e1635d16 740 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
46e1d3ba 741 COUNT(e.eid) AS events, mail_domain AS lists
e1635d16 742 FROM groupex.membres AS m
46e1d3ba 743 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
744 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
745 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 746 $page->assign('assos', $req->fetchAllAssoc());
747 }
e1635d16 748
e49018a7 749 function handler_vcard(&$page, $x = null)
750 {
751 if (is_null($x)) {
752 return PL_NOT_FOUND;
753 }
754
755 global $globals;
756
757 if (substr($x, -4) == '.vcf') {
758 $x = substr($x, 0, strlen($x) - 4);
759 }
760
5e193297 761 $vcard = new VCard($x);
762 $vcard->do_page($page);
e49018a7 763 }
92423144 764
765 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 766 $page->changeTpl('profile/admin_trombino.tpl');
46f272fe 767 $page->setTitle('Administration - Trombino');
92423144 768 $page->assign('uid', $uid);
e1635d16 769
92423144 770 $q = XDB::query(
771 "SELECT a.alias,promo
772 FROM auth_user_md5 AS u
773 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
774 WHERE user_id = {?}", $uid);
775 list($forlife, $promo) = $q->fetchOneRow();
e1635d16 776
92423144 777 switch ($action) {
92423144 778 case "original":
779 header("Content-type: image/jpeg");
780 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
781 exit;
782 break;
e1635d16 783
92423144 784 case "new":
8827fc52
VZ
785 S::assert_xsrf_token();
786
92423144 787 $data = file_get_contents($_FILES['userfile']['tmp_name']);
788 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
789 $mimetype = substr($_FILES['userfile']['type'], 6);
790 unlink($_FILES['userfile']['tmp_name']);
791 XDB::execute(
792 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
793 $uid, $mimetype, $data, $x, $y);
794 break;
e1635d16 795
92423144 796 case "delete":
8827fc52
VZ
797 S::assert_xsrf_token();
798
92423144 799 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
800 break;
801 }
e1635d16 802
92423144 803 $page->assign('forlife', $forlife);
804 }
805 function handler_admin_binets(&$page, $action = 'list', $id = null) {
46f272fe 806 $page->setTitle('Administration - Binets');
92423144 807 $page->assign('title', 'Gestion des binets');
808 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
809 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 810 $table_editor->describe('text','intitulé',true);
92423144 811 $table_editor->apply($page, $action, $id);
812 }
043bbacf 813 function handler_admin_education(&$page, $action = 'list', $id = null) {
46f272fe 814 $page->setTitle('Administration - Formations');
92423144 815 $page->assign('title', 'Gestion des formations');
043bbacf
SJ
816 $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id');
817 $table_editor->add_join_table('profile_education', 'eduid', true);
818 $table_editor->add_join_table('profile_education_degree', 'eduid', true);
819 $table_editor->describe('name', 'intitulé', true);
820 $table_editor->describe('url', 'site web', false);
821 $table_editor->apply($page, $action, $id);
822 }
823 function handler_admin_education_field(&$page, $action = 'list', $id = null) {
824 $page->setTitle('Administration - Domaines de formation');
825 $page->assign('title', 'Gestion des domaines de formation');
826 $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true);
827 $table_editor->add_join_table('profile_education', 'fieldid', true);
828 $table_editor->describe('field', 'domaine', true);
829 $table_editor->apply($page, $action, $id);
830 }
831 function handler_admin_education_degree(&$page, $action = 'list', $id = null) {
832 $page->setTitle('Administration - Niveau de formation');
833 $page->assign('title', 'Gestion des niveau de formation');
834 $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id', true);
835 $table_editor->add_join_table('profile_education_degree', 'degreeid', true);
836 $table_editor->add_join_table('profile_education', 'degreeid', true);
837 $table_editor->describe('degree', 'niveau', true);
838 $table_editor->apply($page, $action, $id);
839 }
840 function handler_admin_education_degree_set(&$page, $action = 'list', $id = null) {
841 $page->setTitle('Administration - Correspondances formations - niveau de formation');
842 $page->assign('title', 'Gestion des correspondances formations - niveau de formation');
843 $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true);
844 $table_editor->describe('eduid', 'formation', true);
845 $table_editor->describe('degreeid', 'niveau', true);
92423144 846 $table_editor->apply($page, $action, $id);
e1635d16 847 }
b09690be 848 function handler_admin_sections(&$page, $action = 'list', $id = null) {
46f272fe 849 $page->setTitle('Administration - Sections');
a20aab02 850 $page->assign('title', 'Gestion des sections');
b09690be 851 $table_editor = new PLTableEditor('admin/sections','sections','id');
852 $table_editor->describe('text','intitulé',true);
853 $table_editor->apply($page, $action, $id);
e1635d16 854 }
a20aab02 855 function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 856 $page->setTitle('Administration - Sous-secteurs');
a20aab02
SJ
857 $page->assign('title', 'Gestion des sous-secteurs');
858 $table_editor = new PLTableEditor('admin/ss_secteurs', 'emploi_ss_secteur', 'id', true);
859 $table_editor->describe('label', 'intitulé', true);
860 $table_editor->apply($page, $action, $id);
861 }
862 function handler_admin_fonctions(&$page, $action = 'list', $id = null) {
46f272fe 863 $page->setTitle('Administration - Fonctions');
a20aab02
SJ
864 $page->assign('title', 'Gestion des fonctions');
865 $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true);
866 $table_editor->describe('fonction_fr', 'intitulé', true);
867 $table_editor->describe('fonction_en', 'intitulé (ang)', true);
868 $table_editor->describe('flags', 'titre', true);
869 $table_editor->apply($page, $action, $id);
870 }
b09690be 871 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 872 $page->setTitle('Administration - Secteurs');
a20aab02
SJ
873 $page->assign('title', 'Gestion des secteurs');
874 $table_editor = new PLTableEditor('admin/secteurs', 'emploi_secteur', 'id', true);
875 $table_editor->describe('label', 'intitulé', true);
b09690be 876 $table_editor->apply($page, $action, $id);
e1635d16 877 }
15beefb3
GB
878 function handler_admin_networking(&$page, $action = 'list', $id = null) {
879 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
880 $page->assign('title', 'Gestion des types de networking');
881 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
882 $table_editor->describe('name', 'intitulé', true);
883 $table_editor->describe('icon', 'nom de l\'icône', false);
dc6378df
GB
884 $table_editor->describe('filter', 'filtre', true);
885 $table_editor->describe('link', 'lien web', true);
15beefb3
GB
886 $table_editor->apply($page, $action, $id);
887 }
92423144 888 function handler_admin_medals(&$page, $action = 'list', $id = null) {
46f272fe 889 $page->setTitle('Administration - Distinctions');
92423144 890 $page->assign('title', 'Gestion des Distinctions');
891 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 892 $table_editor->describe('text', 'intitulé', true);
92423144 893 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 894 $table_editor->describe('flags', 'valider', true);
92423144 895 $table_editor->apply($page, $action, $id);
896 if ($id && $action == 'edit') {
8b1f8e12 897 $page->changeTpl('profile/admin_decos.tpl');
e1635d16 898
92423144 899 $mid = $id;
e1635d16 900
92423144 901 if (Post::v('act') == 'del') {
75a17710
FB
902 XDB::execute('DELETE FROM profile_medals_grades
903 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
92423144 904 } else {
905 foreach (Post::v('grades', array()) as $gid=>$text) {
154ee23a
OLF
906 if ($gid === 0) {
907 if (!empty($text)) {
908 $res = XDB::query('SELECT MAX(gid)
909 FROM profile_medals_grades
910 WHERE mid = {?}', $mid);
911 $gid = $res->fetchOneCell() + 1;
912
913 XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos)
914 VALUES ({?}, {?}, {?}, {?})',
915 $mid, $gid, $text, $_POST['pos']['0']);
916 }
917 } else {
918 XDB::execute('UPDATE profile_medals_grades
919 SET pos={?}, text={?}
920 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
921 }
92423144 922 }
923 }
924 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
925 $page->assign('grades', $res);
926 }
e1635d16 927 }
7d8b17cb 928}
929
a7de4ef7 930// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 931?>