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