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