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