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