Updates fusionax scripts for better compliance and to get them working right.
[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),
f711b03f 44 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE),
2398e553
SJ
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');
f711b03f 336 $page->addJsLink('education.js');
46ae38a9 337 $page->addJsLink('grades.js');
16594a1a 338 $page->addJsLink('profile.js');
4b4b4b67 339 $page->addJsLink('jquery.autocomplete.js');
6d20fb1d 340 $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true);
460d8f55 341 $this->load('page.inc.php');
e1635d16 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
f711b03f 363 function handler_education_js(&$page)
46ae38a9
FB
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');
f711b03f
SJ
370 $page->changeTpl('profile/education.js.tpl', NO_SKIN);
371 require_once "education.func.inc.php";
46ae38a9
FB
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
58acfe8b 419 function handler_ajax_edu(&$page, $eduid, $class)
043bbacf
SJ
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);
58acfe8b 428 $page->assign('class', $class);
f711b03f 429 require_once "education.func.inc.php";
043bbacf
SJ
430 }
431
85cc366b
FB
432 function handler_ajax_medal(&$page, $id)
433 {
46ae38a9 434 header('Content-Type: text/html; charset=utf-8');
85cc366b
FB
435 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
436 $page->assign('id', $id);
437 $page->assign('medal', array('valid' => 0, 'grade' => 0));
85cc366b
FB
438 }
439
2dcac0f5
FB
440 function handler_ajax_job(&$page, $id)
441 {
46ae38a9 442 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
443 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN);
444 $page->assign('i', $id);
445 $page->assign('job', array());
2dcac0f5 446 $page->assign('new', true);
1879c7b2
FB
447 $page->assign('secteurs', XDB::iterator("SELECT id, label
448 FROM emploi_secteur"));
449 $page->assign('fonctions', XDB::iterator("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
450 FROM fonctions_def
451 ORDER BY id"));
2dcac0f5
FB
452 }
453
454 function handler_ajax_secteur(&$page, $id, $sect, $ssect = -1)
455 {
46ae38a9 456 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
457 $res = XDB::iterator("SELECT id, label
458 FROM emploi_ss_secteur
459 WHERE secteur = {?}", $sect);
460 $page->changeTpl('profile/jobs.secteur.tpl', NO_SKIN);
461 $page->assign('id', $id);
462 $page->assign('ssecteurs', $res);
463 $page->assign('sel', $ssect);
464 }
465
f25e1a56
FB
466 function handler_ajax_skill(&$page, $cat, $id)
467 {
46ae38a9 468 header('Content-Type: text/html; charset=utf-8');
f25e1a56 469 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN);
f25e1a56
FB
470 $page->assign('cat', $cat);
471 $page->assign('id', $id);
472 if ($cat == 'competences') {
473 $page->assign('levels', array('initié' => 'initié',
474 'bonne connaissance' => 'bonne connaissance',
475 'expert' => 'expert'));
476 } else {
477 $page->assign('levels', array(1 => 'connaissance basique',
478 2 => 'maîtrise des bases',
479 3 => 'maîtrise limitée',
480 4 => 'maîtrise générale',
481 5 => 'bonne maîtrise',
482 6 => 'maîtrise complète'));
483 }
484 }
485
b04882ff
PC
486 function handler_ajax_searchname(&$page, $snid)
487 {
488 header('Content-Type: text/html; charset=utf-8');
489 $page->changeTpl('profile/general.searchname.tpl', NO_SKIN);
490 $page->assign('i', $snid);
491 $page->assign('sn', array());
492 $page->assign('newsn', true);
493 }
494
9b0fa329 495 function handler_p_orange(&$page)
496 {
8b1f8e12 497 $page->changeTpl('profile/orange.tpl');
9b0fa329 498
499 require_once 'validations.inc.php';
9b0fa329 500
08cce2ff 501 $res = XDB::query(
2f678da1 502 "SELECT u.promo, u.promo_sortie
9b0fa329 503 FROM auth_user_md5 AS u
cab08090 504 WHERE user_id={?}", S::v('uid'));
9b0fa329 505
2f678da1 506 list($promo, $promo_sortie_old) = $res->fetchOneRow();
9b0fa329 507 $page->assign('promo_sortie_old', $promo_sortie_old);
508 $page->assign('promo', $promo);
509
510 if (!Env::has('promo_sortie')) {
fd8f77de 511 return;
8827fc52
VZ
512 } else {
513 S::assert_xsrf_token();
9b0fa329 514 }
515
5e2307dc 516 $promo_sortie = Env::i('promo_sortie');
9b0fa329 517
518 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
a7d35093 519 $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres');
9b0fa329 520 }
521 elseif ($promo_sortie < $promo + 3) {
a7d35093 522 $page->trigError('Trop tôt');
9b0fa329 523 }
524 elseif ($promo_sortie == $promo_sortie_old) {
a7d35093 525 $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 526 }
527 elseif ($promo_sortie == $promo + 3) {
08cce2ff 528 XDB::execute(
e1635d16 529 "UPDATE auth_user_md5 set promo_sortie={?}
cab08090 530 WHERE user_id={?}", $promo_sortie, S::v('uid'));
a7d35093 531 $page->trigSuccess('Ton statut "orange" a été supprimé.');
9b0fa329 532 $page->assign('promo_sortie_old', $promo_sortie);
533 }
534 else {
535 $page->assign('promo_sortie', $promo_sortie);
536
537 if (Env::has('submit')) {
cab08090 538 $myorange = new OrangeReq(S::v('uid'),
9b0fa329 539 $promo_sortie);
540 $myorange->submit();
541 $page->assign('myorange', $myorange);
542 }
543 }
9b0fa329 544 }
545
2f678da1 546 function handler_referent(&$page, $x = null)
28e16d4d 547 {
28e16d4d 548 require_once 'user.func.inc.php';
549
550 if (is_null($x)) {
551 return PL_NOT_FOUND;
552 }
553
8b1f8e12 554 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 555
08cce2ff 556 $res = XDB::query(
28e16d4d 557 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
558 FROM auth_user_md5 AS u
2f678da1 559 INNER JOIN aliases AS a ON (u.user_id=a.id
560 AND FIND_IN_SET('bestalias', a.flags))
28e16d4d 561 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
562 AND a1.alias = {?}
563 AND a1.type!='homonyme')", $x);
564
565 if ($res->numRows() != 1) {
566 return PL_NOT_FOUND;
567 }
568
569 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
570
571 $page->assign('prenom', $prenom);
572 $page->assign('nom', $nom);
573 $page->assign('promo', $promo);
37633309 574 $page->assign('cv', MiniWiki::WikiToHTML($cv, true));
28e16d4d 575 $page->assign('bestalias', $bestalias);
576 $page->assign('adr_pro', get_user_details_pro($user_id));
577
578 ///// recuperations infos referent
579
580 //expertise
08cce2ff 581 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
28e16d4d 582 $page->assign('expertise', $res->fetchOneCell());
583
584 //secteurs
585 $secteurs = $ss_secteurs = Array();
08cce2ff 586 $res = XDB::iterRow(
28e16d4d 587 "SELECT s.label, ss.label
588 FROM mentor_secteurs AS m
589 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
590 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
591 WHERE uid = {?}", $user_id);
592 while (list($sec, $ssec) = $res->next()) {
593 $secteurs[] = $sec;
594 $ss_secteurs[] = $ssec;
595 }
596 $page->assign_by_ref('secteurs', $secteurs);
597 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
598
599 //pays
08cce2ff 600 $res = XDB::query(
28e16d4d 601 "SELECT gp.pays
602 FROM mentor_pays AS m
603 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
604 WHERE uid = {?}", $user_id);
605 $page->assign('pays', $res->fetchColumn());
606
c99ef281 607 $page->addJsLink('close_on_esc.js');
28e16d4d 608 }
609
ff3eb9b7 610 function handler_ref_search(&$page, $action = null, $subaction = null)
2f678da1 611 {
8f201b69
FB
612 $wp = new PlWikiPage('Docs.Emploi');
613 $wp->buildCache();
614
46f272fe 615 $page->setTitle('Conseil Pro');
2f678da1 616
2f678da1 617 //recuperation des noms de secteurs
08cce2ff 618 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 619 $secteurs[''] = '';
620 while (list($tmp_id, $tmp_label) = $res->next()) {
621 $secteurs[$tmp_id] = $tmp_label;
622 }
623 $page->assign_by_ref('secteurs', $secteurs);
624
2f678da1 625 // nb de mentors
08cce2ff 626 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 627 $page->assign('mentors_number', $res->fetchOneCell());
628
2f678da1 629 // On vient d'un formulaire
ff3eb9b7 630 $where = array();
631 $pays_sel = XDB::escape(Env::v('pays_sel'));
632 $secteur_sel = XDB::escape(Env::v('secteur'));
633 $ss_secteur_sel = XDB::escape(Env::v('ss_secteur'));
634 $expertise_champ = XDB::escape(Env::v('expertise'));
635
636 if ($pays_sel != "''") {
637 $where[] = "mp.pid = $pays_sel";
638 }
639 if ($secteur_sel != "''") {
640 $where[] = "ms.secteur = $secteur_sel";
641 if ($ss_secteur_sel != "''") {
642 $where[] = "ms.ss_secteur = $ss_secteur_sel";
2f678da1 643 }
644 }
ff3eb9b7 645 if ($expertise_champ != "''") {
646 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 647 }
648
649 if ($where) {
650 $where = join(' AND ', $where);
651
e1635d16
FB
652 $set = new UserSet("INNER JOIN mentor AS m ON (m.uid = u.user_id)
653 LEFT JOIN mentor_pays AS mp ON (mp.uid = m.uid)
ff3eb9b7 654 LEFT JOIN mentor_secteurs AS ms ON (ms.uid = m.uid)",
655 $where);
656 $set->addMod('mentor', 'Référents');
657 $set->apply('referent/search', $page, $action, $subaction);
658 if ($set->count() > 100) {
e1635d16 659 $page->assign('recherche_trop_large', true);
2f678da1 660 }
ff3eb9b7 661 }
e1635d16 662 $page->changeTpl('profile/referent.tpl');
ff3eb9b7 663 }
2f678da1 664
e1635d16 665 function handler_ref_sect(&$page, $sect)
ff3eb9b7 666 {
667 header('Content-Type: text/html; charset=utf-8');
05cb05c0 668 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 669 $page->assign('onchange', 'setSSecteurs()');
670 $page->assign('id', 'ssect_field');
671 $page->assign('name', 'ss_secteur');
672 $it = XDB::iterator("SELECT id,label AS field
e1635d16 673 FROM emploi_ss_secteur
ff3eb9b7 674 WHERE secteur = {?}", $sect);
675 $page->assign('list', $it);
676 }
2f678da1 677
ff3eb9b7 678 function handler_ref_country(&$page, $sect, $ssect = '')
679 {
680 header('Content-Type: text/html; charset=utf-8');
05cb05c0 681 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 682 $page->assign('name', 'pays_sel');
683 $where = ($ssect ? ' AND ms.ss_secteur = {?}' : '');
684 $it = XDB::iterator("SELECT a2 AS id, pays AS field
685 FROM geoloc_pays AS g
686 INNER JOIN mentor_pays AS mp ON (mp.pid = g.a2)
687 INNER JOIN mentor_secteurs AS ms ON (ms.uid = mp.uid)
688 WHERE ms.secteur = {?} $where
689 GROUP BY a2
690 ORDER BY pays", $sect, $ssect);
691 $page->assign('list', $it);
2f678da1 692 }
693
926f16d7 694 function handler_p_usage(&$page)
695 {
8b1f8e12 696 $page->changeTpl('profile/nomusage.tpl');
926f16d7 697
698 require_once 'validations.inc.php';
926f16d7 699
08cce2ff 700 $res = XDB::query(
2f678da1 701 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 702 FROM auth_user_md5 AS u
2f678da1 703 LEFT JOIN aliases AS e ON(u.user_id = e.id
704 AND FIND_IN_SET('usage', e.flags))
cab08090 705 WHERE user_id={?}", S::v('uid'));
926f16d7 706
2f678da1 707 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
113f6de8 708 $flags = new PlFlagSet($flags);
926f16d7 709 $page->assign('usage_old', $usage_old);
710 $page->assign('alias_old', $alias_old);
711
e1635d16 712 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 713 $nom_usage = strtoupper($nom_usage);
714 $page->assign('usage_req', $nom_usage);
715
716 if (Env::has('submit') && ($nom_usage != $usage_old)) {
8827fc52
VZ
717 S::assert_xsrf_token();
718
926f16d7 719 // on vient de recevoir une requete, differente de l'ancien nom d'usage
720 if ($nom_usage == $nom) {
721 $page->assign('same', true);
a7de4ef7 722 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 723 // on calcule l'alias pour l'afficher
5e2307dc 724 $reason = Env::v('reason');
926f16d7 725 if ($reason == 'other') {
5e2307dc 726 $reason = Env::v('other_reason');
926f16d7 727 }
cab08090 728 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 729 $myusage->submit();
730 $page->assign('myusage', $myusage);
731 }
732 }
926f16d7 733 }
734
a1d79217 735 function handler_xnet(&$page)
736 {
8b1f8e12 737 $page->changeTpl('profile/groupesx.tpl');
46f272fe 738 $page->setTitle('Promo, Groupes X, Binets');
e1635d16 739
a1d79217 740 $req = XDB::query('
e1635d16 741 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
46e1d3ba 742 COUNT(e.eid) AS events, mail_domain AS lists
e1635d16 743 FROM groupex.membres AS m
46e1d3ba 744 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
745 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
746 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 747 $page->assign('assos', $req->fetchAllAssoc());
748 }
e1635d16 749
e49018a7 750 function handler_vcard(&$page, $x = null)
751 {
752 if (is_null($x)) {
753 return PL_NOT_FOUND;
754 }
755
756 global $globals;
757
758 if (substr($x, -4) == '.vcf') {
759 $x = substr($x, 0, strlen($x) - 4);
760 }
761
5d42c993
FB
762 $vcard = new VCard();
763 $vcard->addUser($x);
764 $vcard->show();
e49018a7 765 }
92423144 766
767 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 768 $page->changeTpl('profile/admin_trombino.tpl');
46f272fe 769 $page->setTitle('Administration - Trombino');
92423144 770 $page->assign('uid', $uid);
e1635d16 771
92423144 772 $q = XDB::query(
773 "SELECT a.alias,promo
774 FROM auth_user_md5 AS u
775 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
776 WHERE user_id = {?}", $uid);
777 list($forlife, $promo) = $q->fetchOneRow();
e1635d16 778
92423144 779 switch ($action) {
92423144 780 case "original":
781 header("Content-type: image/jpeg");
782 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
783 exit;
784 break;
e1635d16 785
92423144 786 case "new":
8827fc52
VZ
787 S::assert_xsrf_token();
788
92423144 789 $data = file_get_contents($_FILES['userfile']['tmp_name']);
790 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
791 $mimetype = substr($_FILES['userfile']['type'], 6);
792 unlink($_FILES['userfile']['tmp_name']);
793 XDB::execute(
794 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
795 $uid, $mimetype, $data, $x, $y);
796 break;
e1635d16 797
92423144 798 case "delete":
8827fc52
VZ
799 S::assert_xsrf_token();
800
92423144 801 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
802 break;
803 }
e1635d16 804
92423144 805 $page->assign('forlife', $forlife);
806 }
807 function handler_admin_binets(&$page, $action = 'list', $id = null) {
46f272fe 808 $page->setTitle('Administration - Binets');
92423144 809 $page->assign('title', 'Gestion des binets');
810 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
811 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 812 $table_editor->describe('text','intitulé',true);
92423144 813 $table_editor->apply($page, $action, $id);
814 }
043bbacf 815 function handler_admin_education(&$page, $action = 'list', $id = null) {
46f272fe 816 $page->setTitle('Administration - Formations');
92423144 817 $page->assign('title', 'Gestion des formations');
043bbacf
SJ
818 $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id');
819 $table_editor->add_join_table('profile_education', 'eduid', true);
820 $table_editor->add_join_table('profile_education_degree', 'eduid', true);
821 $table_editor->describe('name', 'intitulé', true);
822 $table_editor->describe('url', 'site web', false);
823 $table_editor->apply($page, $action, $id);
824 }
825 function handler_admin_education_field(&$page, $action = 'list', $id = null) {
826 $page->setTitle('Administration - Domaines de formation');
827 $page->assign('title', 'Gestion des domaines de formation');
828 $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true);
829 $table_editor->add_join_table('profile_education', 'fieldid', true);
830 $table_editor->describe('field', 'domaine', true);
831 $table_editor->apply($page, $action, $id);
832 }
833 function handler_admin_education_degree(&$page, $action = 'list', $id = null) {
834 $page->setTitle('Administration - Niveau de formation');
835 $page->assign('title', 'Gestion des niveau de formation');
836 $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id', true);
837 $table_editor->add_join_table('profile_education_degree', 'degreeid', true);
838 $table_editor->add_join_table('profile_education', 'degreeid', true);
839 $table_editor->describe('degree', 'niveau', true);
840 $table_editor->apply($page, $action, $id);
841 }
842 function handler_admin_education_degree_set(&$page, $action = 'list', $id = null) {
843 $page->setTitle('Administration - Correspondances formations - niveau de formation');
844 $page->assign('title', 'Gestion des correspondances formations - niveau de formation');
845 $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true);
846 $table_editor->describe('eduid', 'formation', true);
847 $table_editor->describe('degreeid', 'niveau', true);
92423144 848 $table_editor->apply($page, $action, $id);
e1635d16 849 }
b09690be 850 function handler_admin_sections(&$page, $action = 'list', $id = null) {
46f272fe 851 $page->setTitle('Administration - Sections');
a20aab02 852 $page->assign('title', 'Gestion des sections');
b09690be 853 $table_editor = new PLTableEditor('admin/sections','sections','id');
854 $table_editor->describe('text','intitulé',true);
855 $table_editor->apply($page, $action, $id);
e1635d16 856 }
a20aab02 857 function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 858 $page->setTitle('Administration - Sous-secteurs');
a20aab02
SJ
859 $page->assign('title', 'Gestion des sous-secteurs');
860 $table_editor = new PLTableEditor('admin/ss_secteurs', 'emploi_ss_secteur', 'id', true);
861 $table_editor->describe('label', 'intitulé', true);
862 $table_editor->apply($page, $action, $id);
863 }
864 function handler_admin_fonctions(&$page, $action = 'list', $id = null) {
46f272fe 865 $page->setTitle('Administration - Fonctions');
a20aab02
SJ
866 $page->assign('title', 'Gestion des fonctions');
867 $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true);
868 $table_editor->describe('fonction_fr', 'intitulé', true);
869 $table_editor->describe('fonction_en', 'intitulé (ang)', true);
870 $table_editor->describe('flags', 'titre', true);
871 $table_editor->apply($page, $action, $id);
872 }
b09690be 873 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 874 $page->setTitle('Administration - Secteurs');
a20aab02
SJ
875 $page->assign('title', 'Gestion des secteurs');
876 $table_editor = new PLTableEditor('admin/secteurs', 'emploi_secteur', 'id', true);
877 $table_editor->describe('label', 'intitulé', true);
b09690be 878 $table_editor->apply($page, $action, $id);
e1635d16 879 }
15beefb3
GB
880 function handler_admin_networking(&$page, $action = 'list', $id = null) {
881 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
882 $page->assign('title', 'Gestion des types de networking');
883 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
884 $table_editor->describe('name', 'intitulé', true);
885 $table_editor->describe('icon', 'nom de l\'icône', false);
dc6378df
GB
886 $table_editor->describe('filter', 'filtre', true);
887 $table_editor->describe('link', 'lien web', true);
15beefb3
GB
888 $table_editor->apply($page, $action, $id);
889 }
92423144 890 function handler_admin_medals(&$page, $action = 'list', $id = null) {
46f272fe 891 $page->setTitle('Administration - Distinctions');
92423144 892 $page->assign('title', 'Gestion des Distinctions');
893 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 894 $table_editor->describe('text', 'intitulé', true);
92423144 895 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 896 $table_editor->describe('flags', 'valider', true);
92423144 897 $table_editor->apply($page, $action, $id);
898 if ($id && $action == 'edit') {
8b1f8e12 899 $page->changeTpl('profile/admin_decos.tpl');
e1635d16 900
92423144 901 $mid = $id;
e1635d16 902
92423144 903 if (Post::v('act') == 'del') {
75a17710
FB
904 XDB::execute('DELETE FROM profile_medals_grades
905 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
92423144 906 } else {
907 foreach (Post::v('grades', array()) as $gid=>$text) {
154ee23a
OLF
908 if ($gid === 0) {
909 if (!empty($text)) {
910 $res = XDB::query('SELECT MAX(gid)
911 FROM profile_medals_grades
912 WHERE mid = {?}', $mid);
913 $gid = $res->fetchOneCell() + 1;
914
915 XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos)
916 VALUES ({?}, {?}, {?}, {?})',
917 $mid, $gid, $text, $_POST['pos']['0']);
918 }
919 } else {
920 XDB::execute('UPDATE profile_medals_grades
921 SET pos={?}, text={?}
922 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
923 }
92423144 924 }
925 }
926 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
927 $page->assign('grades', $res);
928 }
e1635d16 929 }
7d8b17cb 930}
931
a7de4ef7 932// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 933?>