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