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