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