2 /***************************************************************************
3 * Copyright (C) 2003-2009 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileModule
extends PLModule
27 'photo' => $this->make_hook('photo', AUTH_PUBLIC
),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP
),
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/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
),
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
),
58 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE
),
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/networking' => $this->make_hook('admin_networking', AUTH_MDP
, 'admin'),
69 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP
, 'admin'),
70 'admin/fonctions' => $this->make_hook('admin_fonctions', AUTH_MDP
, 'admin'),
71 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_MDP
, 'admin'),
72 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_MDP
, 'admin'),
73 'admin/names' => $this->make_hook('admin_names', AUTH_MDP
, 'admin'),
79 function handler_fiche(&$page)
81 return $this->handler_profile($page, Env
::v('user'));
84 function handler_photo(&$page, $x = null
, $req = null
)
86 if (!$x ||
!($user = User
::getSilent($x))) {
90 // Retrieve the photo and its mime type.
94 if ($req && S
::logged()) {
95 include 'validations.inc.php';
96 $myphoto = PhotoReq
::get_request($user->id());
98 $photo_data = $myphoto->data
;
99 $photo_type = $myphoto->mimetype
;
103 "SELECT attachmime, attach, pub
105 WHERE uid = {?}", $user->id());
106 list($photo_type, $photo_data, $photo_pub) = $res->fetchOneRow();
107 if ($photo_pub != 'public' && !S
::logged()) {
108 $photo_type = $photo_data = null
;
112 // Display the photo, or a default one when not available.
113 if ($photo_type && $photo_data != null
) {
114 header('Content-type: image/' . $photo_type);
117 header('Content-type: image/png');
118 echo file_get_contents(dirname(__FILE__
).'/../htdocs/images/none.png');
123 function handler_medal(&$page, $mid)
125 $thumb = ($mid == 'thumb');
126 $mid = $thumb ? @func_get_arg
(2) : $mid;
128 $res = XDB
::query("SELECT img
133 dirname(__FILE__
).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() :
134 dirname(__FILE__
).'/../htdocs/images/medals/' . $res->fetchOneCell();
135 $type = mime_content_type($img);
136 header("Content-Type: $type");
137 echo file_get_contents($img);
141 function handler_name_info(&$page)
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);
154 function handler_networking(&$page, $mid)
156 $res = XDB
::query("SELECT icon
157 FROM profile_networking_enum
158 WHERE network_type = {?}",
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);
167 function handler_photo_change(&$page)
170 $page->changeTpl('profile/trombino.tpl');
172 require_once('validations.inc.php');
174 $trombi_x = '/home/web/trombino/photos' . S
::v('promo') . '/' . S
::user()->login() . '.jpg';
175 if (Env
::has('upload')) {
176 S
::assert_xsrf_token();
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');
182 $myphoto = new PhotoReq(S
::user(), $upload);
183 if ($myphoto->isValid()) {
187 } elseif (Env
::has('trombi')) {
188 S
::assert_xsrf_token();
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()) {
198 } elseif (Env
::v('suppr')) {
199 S
::assert_xsrf_token();
201 XDB
::execute('DELETE FROM photo
204 XDB
::execute('DELETE FROM requests
205 WHERE user_id = {?} AND type="photo"',
207 $globals->updateNbValid();
208 } elseif (Env
::v('cancel')) {
209 S
::assert_xsrf_token();
211 $sql = XDB
::query('DELETE FROM requests
212 WHERE user_id={?} AND type="photo"',
214 $globals->updateNbValid();
217 $sql = XDB
::query('SELECT COUNT(*)
219 WHERE user_id={?} AND type="photo"',
221 $page->assign('submited', $sql->fetchOneCell());
222 $page->assign('has_trombi_x', file_exists($trombi_x));
225 function handler_profile(&$page, $x = null
)
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).
233 // Determines which user to display the profile of, and retrieves basic
234 // information on this user.
239 $login = S
::logged() ? User
::get($x) : User
::getSilent($x);
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';
249 // Determines the access level at which the profile will be displayed.
250 if (!S
::logged() || Env
::v('view') == 'public') {
252 } else if (S
::logged() && Env
::v('view') == 'ax') {
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')
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);
270 pl_redirect('marketing/public/' . $login->login());
274 // Profile view are logged.
276 S
::logger()->log('view_profile', $login->login());
279 // Sets the title of the html page.
280 $page->setTitle($login->fullName());
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)) {
287 $page->assign('photo_url', $photo);
289 if (!isset($user['y']) and !isset($user['x'])) {
290 list($user['x'], $user['y']) = getimagesize("images/none.png");
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']);
298 if ($user['y'] > 300) {
299 $user['x'] = (integer)($user['x']*300/$user['y']);
302 if ($user['x'] < 160) {
303 $user['y'] = (integer)($user['y']*160/$user['x']);
307 // Determines and displays the virtual alias.
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}'",
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());
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);
330 $page->addJsLink('close_on_esc.js');
331 if (isset($user['date'])) {
332 header('Last-Modified: ' . date('r', strtotime($user['date'])));
336 function handler_ax(&$page, $user = null
)
338 $user = User
::get($user);
343 $res = XDB
::query("SELECT matricule_ax
345 WHERE user_id = {?}", $user->id());
346 $mat = $res->fetchOneCell();
348 $page->kill("Le matricule AX de {$user->login()} est inconnu");
350 http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&anc_id=$mat");
353 function handler_p_edit(&$page, $opened_tab = null
, $mode = null
)
357 // AX Synchronization
358 require_once 'synchro_ax.inc.php';
359 if (is_ax_key_missing()) {
360 $page->assign('no_private_key', true
);
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');
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);
385 $res = XDB
::query("SELECT user_id
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.");
393 $page->setTitle('Mon Profil');
396 function handler_education_js(&$page)
398 header('Content-Type: text/javascript; charset=utf-8');
399 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
400 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
401 header('Cache-Control: no-cache, must-revalidate');
402 header('Pragma: no-cache');
403 $page->changeTpl('profile/education.js.tpl', NO_SKIN
);
404 require_once "education.func.inc.php";
407 function handler_grades_js(&$page)
409 header('Content-Type: text/javascript; charset=utf-8');
410 header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
411 header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT');
412 header('Cache-Control: no-cache, must-revalidate');
413 header('Pragma: no-cache');
414 $page->changeTpl('profile/grades.js.tpl', NO_SKIN
);
415 $res = XDB
::iterator("SELECT *
416 FROM profile_medals_grades
419 while ($tmp = $res->next()) {
420 $grades[$tmp['mid']][] = $tmp;
422 $page->assign('grades', $grades);
424 $res = XDB
::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
426 ORDER BY type, text");
428 while ($tmp = $res->next()) {
429 $mlist[$tmp['type']][] = $tmp;
431 $page->assign('medal_list', $mlist);
434 function handler_ajax_address(&$page, $id)
436 header('Content-Type: text/html; charset=utf-8');
437 $page->changeTpl('profile/adresses.address.tpl', NO_SKIN
);
438 $page->assign('i', $id);
439 $page->assign('address', array());
442 function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
444 header('Content-Type: text/html; charset=utf-8');
445 $page->changeTpl('profile/phone.tpl', NO_SKIN
);
446 $page->assign('prefid', $prefid);
447 $page->assign('prefname', $prefname);
448 $page->assign('telid', $telid);
449 $page->assign('tel', array());
452 function handler_ajax_edu(&$page, $eduid, $class)
454 header('Content-Type: text/html; charset=utf-8');
455 $page->changeTpl('profile/general.edu.tpl', NO_SKIN
);
456 $res = XDB
::iterator("SELECT id, field
457 FROM profile_education_field_enum
459 $page->assign('edu_fields', $res->fetchAllAssoc());
460 $page->assign('eduid', $eduid);
461 $page->assign('class', $class);
462 require_once "education.func.inc.php";
465 function handler_ajax_medal(&$page, $id)
467 header('Content-Type: text/html; charset=utf-8');
468 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN
);
469 $page->assign('id', $id);
470 $page->assign('medal', array('valid' => 0, 'grade' => 0));
473 function handler_ajax_job(&$page, $id)
475 header('Content-Type: text/html; charset=utf-8');
476 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN
);
477 $page->assign('i', $id);
478 $page->assign('job', array());
479 $page->assign('new', true
);
480 $res = XDB
::query("SELECT id, name
481 FROM profile_job_sector_enum");
482 $page->assign('sectors', $res->fetchAllAssoc());
483 $res = XDB
::query("SELECT id, fonction_fr, FIND_IN_SET('titre', flags) AS title
486 $page->assign('fonctions', $res->fetchAllAssoc());
487 require_once "emails.combobox.inc.php";
488 fill_email_combobox($page);
491 function handler_ajax_sector(&$page, $id, $jobid, $jobpref, $sect, $ssect = -1)
493 header('Content-Type: text/html; charset=utf-8');
494 $res = XDB
::iterator("SELECT id, name, FIND_IN_SET('optgroup', flags) AS optgroup
495 FROM profile_job_subsector_enum
496 WHERE sectorid = {?}", $sect);
497 $page->changeTpl('profile/jobs.sector.tpl', NO_SKIN
);
498 $page->assign('id', $id);
499 $page->assign('subSectors', $res);
500 $page->assign('sel', $ssect);
502 $page->assign('change', 1);
503 $page->assign('jobid', $jobid);
504 $page->assign('jobpref', $jobpref);
508 function handler_ajax_sub_sector(&$page, $id, $ssect, $sssect = -1)
510 header('Content-Type: text/html; charset=utf-8');
511 $res = XDB
::iterator("SELECT id, name
512 FROM profile_job_subsubsector_enum
513 WHERE subsectorid = {?}", $ssect);
514 $page->changeTpl('profile/jobs.sub_sector.tpl', NO_SKIN
);
515 $page->assign('id', $id);
516 $page->assign('subSubSectors', $res);
517 $page->assign('sel', $sssect);
520 function handler_ajax_skill(&$page, $cat, $id)
522 header('Content-Type: text/html; charset=utf-8');
523 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN
);
524 $page->assign('cat', $cat);
525 $page->assign('id', $id);
526 if ($cat == 'competences') {
527 $page->assign('levels', array('initié' => 'initié',
528 'bonne connaissance' => 'bonne connaissance',
529 'expert' => 'expert'));
531 $page->assign('levels', array(1 => 'connaissance basique',
532 2 => 'maîtrise des bases',
533 3 => 'maîtrise limitée',
534 4 => 'maîtrise générale',
535 5 => 'bonne maîtrise',
536 6 => 'maîtrise complète'));
540 function handler_ajax_searchname(&$page, $id)
542 header('Content-Type: text/html; charset=utf-8');
543 $page->changeTpl('profile/general.searchname.tpl', NO_SKIN
);
544 $res = XDB
::query("SELECT id, name, FIND_IN_SET('public', flags) AS pub
545 FROM profile_name_enum
546 WHERE NOT FIND_IN_SET('not_displayed', flags)
547 AND NOT FIND_IN_SET('always_displayed', flags)");
548 $page->assign('sn_type_list', $res->fetchAllAssoc());
549 $page->assign('i', $id);
552 function handler_ajax_buildnames(&$page, $data)
554 header('Content-Type: text/html; charset=utf-8');
555 $page->changeTpl('profile/general.buildnames.tpl', NO_SKIN
);
556 require_once 'name.func.inc.php';
557 $page->assign('names', build_javascript_names($data));
560 function handler_p_orange(&$page)
562 $page->changeTpl('profile/orange.tpl');
564 require_once 'validations.inc.php';
566 $res = XDB
::query("SELECT e.entry_year, e.grad_year, d.promo, FIND_IN_SET('femme', u.flags) AS sexe
567 FROM auth_user_md5 AS u
568 INNER JOIN profile_display AS d ON (d.pid = u.user_id)
569 INNER JOIN profile_education AS e ON (e.uid = u.user_id AND FIND_IN_SET('primary', e.flags))
570 WHERE u.user_id = {?}", S
::v('uid'));
572 list($promo, $promo_sortie_old, $promo_display, $sexe) = $res->fetchOneRow();
573 $page->assign('promo_sortie_old', $promo_sortie_old);
574 $page->assign('promo', $promo);
575 $page->assign('promo_display', $promo_display);
576 $page->assign('sexe', $sexe);
578 if (!Env
::has('promo_sortie')) {
581 S
::assert_xsrf_token();
584 $promo_sortie = Env
::i('promo_sortie');
586 if ($promo_sortie < 1000 ||
$promo_sortie > 9999) {
587 $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres.');
589 elseif ($promo_sortie < $promo +
3) {
590 $page->trigError('Trop tôt !');
592 elseif ($promo_sortie == $promo_sortie_old) {
593 $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
595 elseif ($promo_sortie == $promo +
3) {
596 XDB
::execute("UPDATE profile_education
598 WHERE uid = {?} AND FIND_IN_SET('primary', flags)", $promo_sortie, S
::v('uid'));
599 $page->trigSuccess('Ton statut "orange" a été supprimé.');
600 $page->assign('promo_sortie_old', $promo_sortie);
603 $page->assign('promo_sortie', $promo_sortie);
605 if (Env
::has('submit')) {
606 $myorange = new OrangeReq(S
::user(), $promo_sortie);
608 $page->assign('myorange', $myorange);
613 function handler_referent(&$page, $x = null
)
615 require_once 'user.func.inc.php';
616 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE
);
618 $user = User
::get($x);
623 $res = XDB
::query("SELECT cv FROM auth_user_md5 WHERE user_id = {?}", $user->id());
624 $cv = $res->fetchOneCell();
626 $page->assign_by_ref('user', $user);
627 $page->assign('cv', MiniWiki
::WikiToHTML($cv, true
));
628 $page->assign('adr_pro', get_user_details_pro($user->id()));
630 ///// recuperations infos referent
633 $res = XDB
::query("SELECT expertise FROM profile_mentor WHERE uid = {?}", $user->id());
634 $page->assign('expertise', $res->fetchOneCell());
637 $sectors = $subSectors = Array();
639 "SELECT s.name AS label, ss.name AS label
640 FROM profile_mentor_sector AS m
641 LEFT JOIN profile_job_sector_enum AS s ON(m.sectorid = s.id)
642 LEFT JOIN profile_job_subsector_enum AS ss ON(m.sectorid = ss.sectorid AND m.subsectorid = ss.id)
643 WHERE uid = {?}", $user->id());
644 while (list($sector, $subSector) = $res->next()) {
645 $sectors[] = $sector;
646 $subSectors[] = $subSector;
648 $page->assign_by_ref('sectors', $sectors);
649 $page->assign_by_ref('subSectors', $subSectors);
654 FROM profile_mentor_country AS m
655 LEFT JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2)
656 WHERE uid = {?}", $user->id());
657 $page->assign('pays', $res->fetchColumn());
659 $page->addJsLink('close_on_esc.js');
662 function handler_ref_search(&$page, $action = null
, $subaction = null
)
664 $wp = new PlWikiPage('Docs.Emploi');
667 $page->setTitle('Conseil Pro');
669 // Retrieval of sector names
670 $res = XDB
::iterRow("SELECT id, name AS label
671 FROM profile_job_sector_enum");
673 while (list($tmp_id, $tmp_label) = $res->next()) {
674 $sectors[$tmp_id] = $tmp_label;
676 $page->assign_by_ref('sectors', $sectors);
679 $res = XDB
::query("SELECT count(*) FROM profile_mentor");
680 $page->assign('mentors_number', $res->fetchOneCell());
682 // On vient d'un formulaire
684 $pays_sel = XDB
::escape(Env
::v('pays_sel'));
685 $sectorSelection = XDB
::escape(Env
::v('sector'));
686 $subSectorSelection = XDB
::escape(Env
::v('subSector'));
687 $expertise_champ = XDB
::escape(Env
::v('expertise'));
689 if ($pays_sel != "''") {
690 $where[] = "mp.country = $pays_sel";
692 if ($sectorSelection != "''") {
693 $where[] = "ms.sectorid = " . $sectorSelection;
694 if ($selectedSubSector != "''") {
695 $where[] = "ms.subsectorid = " . $subSectorSelection;
698 if ($expertise_champ != "''") {
699 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
703 $where = join(' AND ', $where);
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)",
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
);
715 $page->changeTpl('profile/referent.tpl');
718 function handler_ref_sect(&$page, $sect)
720 header('Content-Type: text/html; charset=utf-8');
721 $page->changeTpl('include/field.select.tpl', NO_SKIN
);
722 $page->assign('onchange', 'setSSectors()');
723 $page->assign('id', 'ssect_field');
724 $page->assign('name', 'subSector');
725 $it = XDB
::iterator("SELECT id, name AS field
726 FROM profile_job_subsector_enum
727 WHERE sectorid = {?}", $sect);
728 $page->assign('list', $it);
731 function handler_ref_country(&$page, $sect, $ssect = '')
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 gc.iso_3166_1_a2 AS id, gc.countryFR AS field
738 FROM geoloc_countries AS gc
739 INNER JOIN profile_mentor_country AS mp ON (mp.country = gc.iso_3166_1_a2)
740 INNER JOIN profile_mentor_sector AS ms ON (ms.uid = mp.uid)
741 WHERE ms.sectorid = {?} " . $where . "
742 GROUP BY iso_3166_1_a2
743 ORDER BY countryFR", $sect, $ssect);
744 $page->assign('list', $it);
747 function handler_xnet(&$page)
749 $page->changeTpl('profile/groupesx.tpl');
750 $page->setTitle('Promo, Groupes X, Binets');
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());
762 function handler_vcard(&$page, $x = null
)
770 if (substr($x, -4) == '.vcf') {
771 $x = substr($x, 0, strlen($x) - 4);
774 $vcard = new VCard();
779 function handler_admin_trombino(&$page, $login = null
, $action = null
) {
780 $page->changeTpl('profile/admin_trombino.tpl');
781 $page->setTitle('Administration - Trombino');
783 if (!$login ||
!($user = User
::get($login))) {
786 $page->assign_by_ref('user', $user);
791 header("Content-type: image/jpeg");
792 readfile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg");
797 S
::assert_xsrf_token();
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']);
804 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
805 $user->id(), $mimetype, $data, $x, $y);
809 S
::assert_xsrf_token();
811 XDB
::execute('DELETE FROM photo WHERE uid = {?}', $user->id());
815 function handler_admin_names(&$page, $action = 'list', $id = null
) {
816 $page->setTitle('Administration - Types de noms');
817 $page->assign('title', 'Gestion des types de noms');
818 $table_editor = new PLTableEditor('admin/names', 'profile_name_enum', 'id', true
);
819 $table_editor->describe('name', 'Nom', true
);
820 $table_editor->describe('explanations', 'Explications', true
);
821 $table_editor->describe('type', 'Type', true
);
822 $table_editor->describe('flags', 'Flags', true
);
823 $table_editor->describe('score', 'Score', true
);
824 $table_editor->apply($page, $action, $id);
826 function handler_admin_binets(&$page, $action = 'list', $id = null
) {
827 $page->setTitle('Administration - Binets');
828 $page->assign('title', 'Gestion des binets');
829 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
830 $table_editor->add_join_table('binets_ins','binet_id',true
);
831 $table_editor->describe('text','intitulé',true
);
832 $table_editor->apply($page, $action, $id);
834 function handler_admin_education(&$page, $action = 'list', $id = null
) {
835 $page->setTitle('Administration - Formations');
836 $page->assign('title', 'Gestion des formations');
837 $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id');
838 $table_editor->add_join_table('profile_education', 'eduid', true
);
839 $table_editor->add_join_table('profile_education_degree', 'eduid', true
);
840 $table_editor->describe('name', 'intitulé', true
);
841 $table_editor->describe('url', 'site web', false
);
842 $table_editor->apply($page, $action, $id);
844 function handler_admin_education_field(&$page, $action = 'list', $id = null
) {
845 $page->setTitle('Administration - Domaines de formation');
846 $page->assign('title', 'Gestion des domaines de formation');
847 $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true
);
848 $table_editor->add_join_table('profile_education', 'fieldid', true
);
849 $table_editor->describe('field', 'domaine', true
);
850 $table_editor->apply($page, $action, $id);
852 function handler_admin_education_degree(&$page, $action = 'list', $id = null
) {
853 $page->setTitle('Administration - Niveau de formation');
854 $page->assign('title', 'Gestion des niveau de formation');
855 $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id', true
);
856 $table_editor->add_join_table('profile_education_degree', 'degreeid', true
);
857 $table_editor->add_join_table('profile_education', 'degreeid', true
);
858 $table_editor->describe('degree', 'niveau', true
);
859 $table_editor->apply($page, $action, $id);
861 function handler_admin_education_degree_set(&$page, $action = 'list', $id = null
) {
862 $page->setTitle('Administration - Correspondances formations - niveau de formation');
863 $page->assign('title', 'Gestion des correspondances formations - niveau de formation');
864 $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true
);
865 $table_editor->describe('eduid', 'formation', true
);
866 $table_editor->describe('degreeid', 'niveau', true
);
867 $table_editor->apply($page, $action, $id);
869 function handler_admin_sections(&$page, $action = 'list', $id = null
) {
870 $page->setTitle('Administration - Sections');
871 $page->assign('title', 'Gestion des sections');
872 $table_editor = new PLTableEditor('admin/sections','sections','id');
873 $table_editor->describe('text','intitulé',true
);
874 $table_editor->apply($page, $action, $id);
876 function handler_admin_fonctions(&$page, $action = 'list', $id = null
) {
877 $page->setTitle('Administration - Fonctions');
878 $page->assign('title', 'Gestion des fonctions');
879 $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true
);
880 $table_editor->describe('fonction_fr', 'intitulé', true
);
881 $table_editor->describe('fonction_en', 'intitulé (ang)', true
);
882 $table_editor->describe('flags', 'titre', true
);
883 $table_editor->apply($page, $action, $id);
885 function handler_admin_networking(&$page, $action = 'list', $id = null
) {
886 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
887 $page->assign('title', 'Gestion des types de networking');
888 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
889 $table_editor->describe('name', 'intitulé', true
);
890 $table_editor->describe('icon', 'nom de l\'icône', false
);
891 $table_editor->describe('filter', 'filtre', true
);
892 $table_editor->describe('link', 'lien web', true
);
893 $table_editor->apply($page, $action, $id);
895 function handler_admin_corps_enum(&$page, $action = 'list', $id = null
) {
896 $page->setTitle('Administration - Corps');
897 $page->assign('title', 'Gestion des Corps');
898 $table_editor = new PLTableEditor('admin/corps_enum', 'profile_corps_enum', 'id');
899 $table_editor->describe('name', 'intitulé', true
);
900 $table_editor->describe('abbreviation', 'abbréviation', true
);
901 $table_editor->describe('still_exists', 'existe encore ?', true
);
902 $table_editor->apply($page, $action, $id);
904 function handler_admin_corps_rank(&$page, $action = 'list', $id = null
) {
905 $page->setTitle('Administration - Grade dans les Corps');
906 $page->assign('title', 'Gestion des grade dans les Corps');
907 $table_editor = new PLTableEditor('admin/corps_rank', 'profile_corps_rank_enum', 'id');
908 $table_editor->describe('name', 'intitulé', true
);
909 $table_editor->describe('abbreviation', 'abbréviation', true
);
910 $table_editor->apply($page, $action, $id);
912 function handler_admin_medals(&$page, $action = 'list', $id = null
) {
913 $page->setTitle('Administration - Distinctions');
914 $page->assign('title', 'Gestion des Distinctions');
915 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
916 $table_editor->describe('text', 'intitulé', true
);
917 $table_editor->describe('img', 'nom de l\'image', false
);
918 $table_editor->describe('flags', 'valider', true
);
919 $table_editor->apply($page, $action, $id);
920 if ($id && $action == 'edit') {
921 $page->changeTpl('profile/admin_decos.tpl');
925 if (Post
::v('act') == 'del') {
926 XDB
::execute('DELETE FROM profile_medals_grades
927 WHERE mid={?} AND gid={?}', $mid, Post
::i('gid'));
929 foreach (Post
::v('grades', array()) as $gid=>$text) {
932 $res = XDB
::query('SELECT MAX(gid)
933 FROM profile_medals_grades
934 WHERE mid = {?}', $mid);
935 $gid = $res->fetchOneCell() +
1;
937 XDB
::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos)
938 VALUES ({?}, {?}, {?}, {?})',
939 $mid, $gid, $text, $_POST['pos']['0']);
942 XDB
::execute('UPDATE profile_medals_grades
943 SET pos={?}, text={?}
944 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
948 $res = XDB
::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
949 $page->assign('grades', $res);
954 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: