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