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