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