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