Replace sectors by job terms in profile and search (job and mentoring).
[platal.git] / modules / profile.php
1 <?php
2 /***************************************************************************
3 * Copyright (C) 2003-2010 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 'profile/ajax/tree/jobterms' => $this->make_hook('ajax_tree_job_terms', AUTH_COOKIE, 'user', NO_AUTH),
48 'profile/jobterms' => $this->make_hook('jobterms', AUTH_COOKIE, 'user', NO_AUTH),
49 'javascript/education.js' => $this->make_hook('education_js', AUTH_COOKIE),
50 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE),
51 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC),
52 'profile/name_info' => $this->make_hook('name_info', AUTH_PUBLIC),
53
54 'referent' => $this->make_hook('referent', AUTH_COOKIE),
55 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE),
56 'jobs' => $this->make_hook('ref_search', AUTH_COOKIE),
57 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
58 'referent/ssect' => $this->make_hook('ref_sect', AUTH_COOKIE, 'user', NO_AUTH),
59 'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
60 'referent/autocomplete' => $this->make_hook('ref_autocomplete', AUTH_COOKIE, 'user', NO_AUTH),
61
62 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
63 'groupes-x/logo' => $this->make_hook('xnetlogo', AUTH_PUBLIC),
64
65 'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS),
66 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
67 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
68 'admin/education' => $this->make_hook('admin_education', AUTH_MDP, 'admin'),
69 'admin/education_field' => $this->make_hook('admin_education_field', AUTH_MDP, 'admin'),
70 'admin/education_degree' => $this->make_hook('admin_education_degree', AUTH_MDP, 'admin'),
71 'admin/education_degree_set' => $this->make_hook('admin_education_degree_set', AUTH_MDP, 'admin'),
72 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
73 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'),
74 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
75 'admin/sectors' => $this->make_hook('admin_sectors', AUTH_MDP, 'admin'),
76 'admin/corps_enum' => $this->make_hook('admin_corps_enum', AUTH_MDP, 'admin'),
77 'admin/corps_rank' => $this->make_hook('admin_corps_rank', AUTH_MDP, 'admin'),
78 'admin/names' => $this->make_hook('admin_names', AUTH_MDP, 'admin'),
79 );
80 }
81
82 /* Function needed for compatibility reasons.
83 * TODO: removes calls to fiche.php?user=blah.machin.2083 and then removes this.
84 */
85 function handler_fiche(&$page)
86 {
87 return $this->handler_profile($page, Env::v('user'));
88 }
89
90 function handler_photo(&$page, $x = null, $req = null)
91 {
92 if (!$x || !($profile = Profile::get($x))) {
93 return PL_NOT_FOUND;
94 }
95
96 // Retrieve the photo and its mime type.
97 if ($req && S::logged()) {
98 include 'validations.inc.php';
99 $myphoto = PhotoReq::get_request($profile->id());
100 $photo = PlImage::fromData($myphoto->data, $myphoto->mimetype);
101 } else {
102 $photo = $profile->getPhoto(true, true);
103 }
104
105 // Display the photo, or a default one when not available.
106 $photo->send();
107 }
108
109 function handler_medal(&$page, $mid)
110 {
111 $thumb = ($mid == 'thumb');
112 $mid = $thumb ? @func_get_arg(2) : $mid;
113
114 $res = XDB::query("SELECT img
115 FROM profile_medal_enum
116 WHERE id = {?}",
117 $mid);
118 $img = $thumb ?
119 dirname(__FILE__).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() :
120 dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell();
121 pl_cached_content_headers(mime_content_type($img));
122 echo file_get_contents($img);
123 exit;
124 }
125
126 function handler_name_info(&$page)
127 {
128 pl_content_headers("text/html");
129 $page->changeTpl('profile/name_info.tpl', SIMPLE);
130 $res = XDB::iterator("SELECT name, explanations,
131 FIND_IN_SET('public', flags) AS public,
132 FIND_IN_SET('has_particle', flags) AS has_particle
133 FROM profile_name_enum
134 WHERE NOT FIND_IN_SET('not_displayed', flags)
135 ORDER BY NOT FIND_IN_SET('public', flags)");
136 $page->assign('types', $res);
137 }
138
139 function handler_networking(&$page, $mid)
140 {
141 $res = XDB::query("SELECT icon
142 FROM profile_networking_enum
143 WHERE nwid = {?}",
144 $mid);
145 $img = dirname(__FILE__) . '/../htdocs/images/networking/' . $res->fetchOneCell();
146 pl_cached_content_headers(mime_content_type($img));
147 echo file_get_contents($img);
148 exit;
149 }
150
151 /** Tries to return the correct user from given hrpid
152 * Will redirect to $returnurl$hrpid if $hrpid was empty
153 */
154 private function findProfile($returnurl, $hrpid = null)
155 {
156 if (is_null($hrpid)) {
157 $user = S::user();
158 if (!$user->hasProfile()) {
159 return PL_NOT_FOUND;
160 } else {
161 pl_redirect($returnurl . $user->profile()->hrid());
162 }
163 } else {
164 $profile = Profile::get($hrpid);
165 if (!$profile) {
166 return PL_NOT_FOUND;
167 } else if (!S::user()->canEdit($profile) && Platal::notAllowed()) {
168 return PL_FORBIDDEN;
169 }
170 }
171 return $profile;
172 }
173
174 function handler_photo_change(&$page, $hrpid = null)
175 {
176 global $globals;
177 $profile = $this->findProfile('photo/change/', $hrpid);
178 if (! ($profile instanceof Profile) && ($profile == PL_NOT_FOUND || $profile == PL_FORBIDDEN)) {
179 return $profile;
180 }
181
182 $page->changeTpl('profile/trombino.tpl');
183 $page->assign('hrpid', $profile->hrid());
184
185 require_once('validations.inc.php');
186
187 $trombi_x = '/home/web/trombino/photos' . $profile->promo() . '/' . $profile->hrid() . '.jpg';
188 if (Env::has('upload')) {
189 S::assert_xsrf_token();
190
191 $upload = new PlUpload($profile->hrid(), 'photo');
192 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
193 $page->trigError('Une erreur est survenue lors du téléchargement du fichier');
194 } else {
195 $myphoto = new PhotoReq(S::user(), $profile, $upload);
196 if ($myphoto->isValid()) {
197 $myphoto->submit();
198 }
199 }
200 } elseif (Env::has('trombi')) {
201 S::assert_xsrf_token();
202
203 $upload = new PlUpload($profile->hrid(), 'photo');
204 if ($upload->copyFrom($trombi_x)) {
205 $myphoto = new PhotoReq(S::user(), $profile, $upload);
206 if ($myphoto->isValid()) {
207 $myphoto->commit();
208 $myphoto->clean();
209 }
210 }
211 } elseif (Env::v('suppr')) {
212 S::assert_xsrf_token();
213
214 XDB::execute('DELETE FROM profile_photos
215 WHERE pid = {?}',
216 $profile->id());
217 XDB::execute("DELETE FROM requests
218 WHERE pid = {?} AND type = 'photo'",
219 $profile->id());
220 $globals->updateNbValid();
221 $page->trigSuccess("Ta photo a bien été supprimée. Elle ne sera plus visible sur le site dans au plus une heure.");
222 } elseif (Env::v('cancel')) {
223 S::assert_xsrf_token();
224
225 $sql = XDB::query("DELETE FROM requests
226 WHERE pid = {?} AND type = 'photo'",
227 $profile->id());
228 $globals->updateNbValid();
229 }
230
231 $sql = XDB::query("SELECT COUNT(*)
232 FROM requests
233 WHERE pid = {?} AND type = 'photo'",
234 $profile->id());
235 $page->assign('submited', $sql->fetchOneCell());
236 $page->assign('has_trombi_x', file_exists($trombi_x));
237 }
238
239 function handler_profile(&$page, $id = null)
240 {
241 // Checks if the identifier corresponds to an actual profile. Numeric
242 // identifiers canonly be user by logged users.
243 if (is_null($id)) {
244 return PL_NOT_FOUND;
245 }
246 $pid = (!is_numeric($id) || S::admin()) ? Profile::getPID($id) : null;
247 if (is_null($pid)) {
248 if (S::logged()) {
249 $page->trigError($id . " inconnu dans l'annuaire.");
250 }
251 return PL_NOT_FOUND;
252 }
253
254 // Now that we know this is an existing profile, we can switch to the
255 // appropriate template.
256 $page->changeTpl('profile/profile.tpl', SIMPLE);
257
258 // Determines the access level at which the profile will be displayed.
259 if (!S::logged() || Env::v('view') == 'public') {
260 $view = 'public';
261 } else if (S::logged() && Env::v('view') == 'ax') {
262 $view = 'ax';
263 } else {
264 $view = 'private';
265 }
266
267 // Display pending picture
268 if (S::logged() && Env::v('modif') == 'new') {
269 $page->assign('with_pending_pic', true);
270 }
271
272 // Fetches profile's and profile's owner information and redirects to
273 // marketing if the owner has not subscribed and the requirer has logged in.
274 $profile = Profile::get($pid, Profile::FETCH_ALL, $view);
275 $owner = $profile->owner();
276 if (S::logged() && !is_null($owner) && $owner->state == 'pending') {
277 pl_redirect('marketing/public/' . $profile->hrid());
278 }
279
280 // Profile view are logged.
281 if (S::logged()) {
282 S::logger()->log('view_profile', $profile->hrid());
283 }
284
285 // Sets the title of the html page.
286 $page->setTitle($profile->fullName());
287
288 // Determines and displays the virtual alias.
289 if (!is_null($owner) && $profile->alias_pub == 'public') {
290 $page->assign('virtualalias', $owner->emailAlias());
291 }
292
293 $page->assign_by_ref('profile', $profile);
294 $page->assign_by_ref('owner', $owner);
295 $page->assign('view', $view);
296 $page->assign('logged', S::logged());
297
298 $page->addJsLink('close_on_esc.js');
299 header('Last-Modified: ' . date('r', strtotime($profile->last_change)));
300 }
301
302 function handler_ax(&$page, $user = null)
303 {
304 $user = Profile::get($user);
305 if (!$user) {
306 return PL_NOT_FOUND;
307 }
308 if (!$user->ax_id) {
309 $page->kill("Le matricule AX de {$user->hrid()} est inconnu");
310 }
311 http_redirect("http://www.polytechniciens.com/?page=AX_FICHE_ANCIEN&ancc_id=" . $user->ax_id);
312 }
313
314 function handler_p_edit(&$page, $hrpid = null, $opened_tab = null, $mode = null, $success = null)
315 {
316 global $globals;
317
318 $profile = $this->findProfile('profile/edit/', $hrpid);
319 if (! ($profile instanceof Profile) && ($profile == PL_NOT_FOUND || $profile == PL_FORBIDDEN)) {
320 return $profile;
321 }
322
323 // Build the page
324 $page->addJsLink('ajax.js');
325 $page->addJsLink('education.js', false); /* dynamic content */
326 $page->addJsLink('grades.js', false); /* dynamic content */
327 $page->addJsLink('profile.js');
328 $page->addJsLink('jquery.autocomplete.js');
329 $wiz = new PlWizard('Profil', PlPage::getCoreTpl('plwizard.tpl'), true, true, false);
330 $wiz->addUserData('profile', $profile);
331 $wiz->addUserData('owner', $profile->owner());
332 $this->load('page.inc.php');
333 $wiz->addPage('ProfileSettingGeneral', 'Général', 'general');
334 $wiz->addPage('ProfileSettingAddresses', 'Adresses personnelles', 'adresses');
335 $wiz->addPage('ProfileSettingGroups', 'Groupes X - Binets', 'poly');
336 $wiz->addPage('ProfileSettingDecos', 'Décorations - Medailles', 'deco');
337 $wiz->addPage('ProfileSettingJobs', 'Informations professionnelles', 'emploi');
338 $wiz->addPage('ProfileSettingSkills', 'Compétences diverses', 'skill');
339 $wiz->addPage('ProfileSettingMentor', 'Mentoring', 'mentor');
340 $wiz->apply($page, 'profile/edit/' . $profile->hrid(), $opened_tab, $mode);
341
342 if (!$profile->birthdate) {
343 $page->trigWarning("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser"
344 . " la procédure de récupération de mot de passe si un jour tu le perdais.");
345 }
346
347 $page->setTitle('Mon Profil');
348 if (isset($success) && $success) {
349 $page->trigSuccess('Ton profil a bien été mis à jour.');
350 }
351 }
352
353 function handler_education_js(&$page)
354 {
355 pl_cached_content_headers("text/javascript", "utf-8");
356 $page->changeTpl('profile/education.js.tpl', NO_SKIN);
357 require_once 'education.func.inc.php';
358 }
359
360 function handler_grades_js(&$page)
361 {
362 pl_cached_content_headers("text/javascript", "utf-8");
363 $page->changeTpl('profile/grades.js.tpl', NO_SKIN);
364 $res = XDB::iterator("SELECT *
365 FROM profile_medal_grade_enum
366 ORDER BY mid, pos");
367 $grades = array();
368 while ($tmp = $res->next()) {
369 $grades[$tmp['mid']][] = $tmp;
370 }
371 $page->assign('grades', $grades);
372
373 $res = XDB::iterator("SELECT *, FIND_IN_SET('validation', flags) AS validate
374 FROM profile_medal_enum
375 ORDER BY type, text");
376 $mlist = array();
377 while ($tmp = $res->next()) {
378 $mlist[$tmp['type']][] = $tmp;
379 }
380 $page->assign('medal_list', $mlist);
381 }
382
383 function handler_ajax_address(&$page, $id)
384 {
385 pl_content_headers("text/html");
386 $page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
387 $page->assign('i', $id);
388 $page->assign('address', array());
389 }
390
391 function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
392 {
393 pl_content_headers("text/html");
394 $page->changeTpl('profile/phone.tpl', NO_SKIN);
395 $page->assign('prefid', $prefid);
396 $page->assign('prefname', $prefname);
397 $page->assign('telid', $telid);
398 $page->assign('tel', array());
399 }
400
401 function handler_ajax_edu(&$page, $eduid, $class)
402 {
403 pl_content_headers("text/html");
404 $page->changeTpl('profile/general.edu.tpl', NO_SKIN);
405 $res = XDB::iterator("SELECT id, field
406 FROM profile_education_field_enum
407 ORDER BY field");
408 $page->assign('edu_fields', $res->fetchAllAssoc());
409 $page->assign('eduid', $eduid);
410 $page->assign('class', $class);
411 require_once "education.func.inc.php";
412 }
413
414 function handler_ajax_medal(&$page, $id)
415 {
416 pl_content_headers("text/html");
417 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
418 $page->assign('id', $id);
419 $page->assign('medal', array('valid' => 0, 'grade' => 0));
420 }
421
422 function handler_ajax_job(&$page, $id)
423 {
424 pl_content_headers("text/html");
425 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN);
426 $page->assign('i', $id);
427 $page->assign('job', array());
428 $page->assign('new', true);
429 $res = XDB::query("SELECT id, name AS label
430 FROM profile_job_sector_enum");
431 $page->assign('sectors', $res->fetchAllAssoc());
432 require_once "emails.combobox.inc.php";
433 fill_email_combobox($page);
434 }
435
436 function handler_ajax_sector(&$page, $id, $jobid, $jobpref, $sect, $ssect = -1)
437 {
438 pl_content_headers("text/html");
439 $res = XDB::iterator("SELECT id, name, FIND_IN_SET('optgroup', flags) AS optgroup
440 FROM profile_job_subsector_enum
441 WHERE sectorid = {?}", $sect);
442 $page->changeTpl('profile/jobs.sector.tpl', NO_SKIN);
443 $page->assign('id', $id);
444 $page->assign('subSectors', $res);
445 $page->assign('sel', $ssect);
446 if ($id != -1) {
447 $page->assign('change', 1);
448 $page->assign('jobid', $jobid);
449 $page->assign('jobpref', $jobpref);
450 }
451 }
452 function handler_ajax_sub_sector(&$page, $id, $ssect, $sssect = -1)
453 {
454 pl_content_headers("text/html");
455 $res = XDB::iterator("SELECT id, name
456 FROM profile_job_subsubsector_enum
457 WHERE subsectorid = {?}", $ssect);
458 $page->changeTpl('profile/jobs.sub_sector.tpl', NO_SKIN);
459 $page->assign('id', $id);
460 $page->assign('subSubSectors', $res);
461 $page->assign('sel', $sssect);
462 }
463
464 /**
465 * Page for url "profile/ajax/tree/jobterms". Display a JSon page containing
466 * the sub-branches of a branch in the job terms tree.
467 * @param $page the Platal page
468 * @param $filter filter helps to display only jobterms that are contained in jobs or in mentors
469 *
470 * @param Env::i('jtid') job term id of the parent branch, if none trunk will be used
471 * @param Env::v('attrfunc') the name of a javascript function that will be called when a branch
472 * is chosen
473 * @param Env::v('treeid') tree id that will be given as first argument of attrfunc function
474 * the second argument will be the chosen job term id and the third one the chosen job full name.
475 */
476 function handler_ajax_tree_job_terms(&$page, $filter = JobTerms::ALL)
477 {
478 JobTerms::ajaxGetBranch(&$page, $filter);
479 }
480
481 function handler_ajax_alternates(&$page, $id, $sssect)
482 {
483 pl_content_headers("text/html");
484 $res = XDB::iterator('SELECT name
485 FROM profile_job_alternates
486 WHERE subsubsectorid = {?}
487 ORDER BY id',
488 $sssect);
489 $page->changeTpl('profile/jobs.alternates.tpl', NO_SKIN);
490 $alternates = '';
491 if ($res->total() > 0) {
492 $alternate = $res->next();
493 $alternates = $alternate['name'];
494 while ($alternate = $res->next()) {
495 $alternates .= ', ' . $alternate['name'];
496 }
497 }
498 $page->assign('alternates', $alternates);
499 }
500
501 function handler_ajax_skill(&$page, $cat, $id)
502 {
503 pl_content_headers("text/html");
504 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN);
505 $page->assign('cat', $cat);
506 $page->assign('id', $id);
507 if ($cat == 'competences') {
508 $page->assign('levels', array('initié' => 'initié',
509 'bonne connaissance' => 'bonne connaissance',
510 'expert' => 'expert'));
511 } else {
512 $page->assign('levels', array(1 => 'connaissance basique',
513 2 => 'maîtrise des bases',
514 3 => 'maîtrise limitée',
515 4 => 'maîtrise générale',
516 5 => 'bonne maîtrise',
517 6 => 'maîtrise complète'));
518 }
519 }
520
521 function handler_ajax_searchname(&$page, $id, $isFemale)
522 {
523 pl_content_headers("text/html");
524 $page->changeTpl('profile/general.searchname.tpl', NO_SKIN);
525 $res = XDB::query("SELECT id, name, FIND_IN_SET('public', flags) AS pub
526 FROM profile_name_enum
527 WHERE NOT FIND_IN_SET('not_displayed', flags)
528 AND NOT FIND_IN_SET('always_displayed', flags)");
529 $page->assign('sn_type_list', $res->fetchAllAssoc());
530 $page->assign('isFemale', $isFemale);
531 $page->assign('i', $id);
532 }
533
534 function handler_ajax_buildnames(&$page, $data, $isFemale)
535 {
536 pl_content_headers("text/html");
537 $page->changeTpl('profile/general.buildnames.tpl', NO_SKIN);
538 require_once 'name.func.inc.php';
539 $page->assign('names', build_javascript_names($data, $isFemale));
540 }
541
542 function handler_referent(&$page, $pf)
543 {
544 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
545
546 $pf = Profile::get($pf);
547 if (!$pf) {
548 return PL_NOT_FOUND;
549 }
550
551 $page->assign_by_ref('profile', $pf);
552
553 ///// recuperations infos referent
554
555 // Sectors
556 $sectors = $subSectors = Array();
557 $res = XDB::iterRow(
558 "SELECT s.name AS label, ss.name AS label
559 FROM profile_mentor_sector AS m
560 LEFT JOIN profile_job_sector_enum AS s ON(m.sectorid = s.id)
561 LEFT JOIN profile_job_subsector_enum AS ss ON(m.sectorid = ss.sectorid AND m.subsectorid = ss.id)
562 WHERE pid = {?}", $pf->id());
563 while (list($sector, $subSector) = $res->next()) {
564 $sectors[] = $sector;
565 $subSectors[] = $subSector;
566 }
567 $page->assign_by_ref('sectors', $sectors);
568 $page->assign_by_ref('subSectors', $subSectors);
569
570 // Countries.
571 $res = XDB::query(
572 "SELECT gc.countryFR
573 FROM profile_mentor_country AS m
574 LEFT JOIN geoloc_countries AS gc ON (m.country = gc.iso_3166_1_a2)
575 WHERE pid = {?}", $pf->id());
576 $page->assign('pays', $res->fetchColumn());
577
578 $page->addJsLink('close_on_esc.js');
579 }
580
581 function handler_ref_search(&$page, $action = null, $subaction = null)
582 {
583 $wp = new PlWikiPage('Docs.Emploi');
584 $wp->buildCache();
585
586 $page->setTitle('Emploi et Carrières');
587
588 // nb de mentors
589 $res = XDB::query("SELECT count(distinct pid) FROM profile_mentor_term");
590 $page->assign('mentors_number', $res->fetchOneCell());
591
592 $page->addJsLink('jquery.autocomplete.js');
593
594 // On vient d'un formulaire
595 require_once 'ufbuilder.inc.php';
596 $ufb = new UFB_MentorSearch();
597 if (!$ufb->isEmpty()) {
598 require_once 'userset.inc.php';
599 $ufc = $ufb->getUFC();
600 $set = new ProfileSet($ufc);
601 $set->addMod('mentor', 'Référents');
602 $set->apply('referent/search', $page, $action, $subaction);
603 if ($set->count() > 100) {
604 $page->assign('recherche_trop_large', true);
605 }
606 }
607
608 $page->changeTpl('profile/referent.tpl');
609 }
610
611 function handler_ref_sect(&$page, $sect)
612 {
613 pl_content_headers("text/html");
614 $page->changeTpl('include/field.select.tpl', NO_SKIN);
615 $page->assign('onchange', 'setSSectors()');
616 $page->assign('id', 'ssect_field');
617 $page->assign('name', 'subSector');
618 $it = XDB::iterator("SELECT pjsse.id, pjsse.name AS field
619 FROM profile_job_subsector_enum AS pjsse
620 INNER JOIN profile_mentor_sector AS pms ON (pms.sectorid = pjsse.sectorid AND pms.subsectorid = pjsse.id)
621 WHERE pjsse.sectorid = {?}
622 GROUP BY pjsse.id
623 ORDER BY pjsse.name", $sect);
624 $page->assign('list', $it);
625 }
626
627 function handler_ref_country(&$page, $sect, $ssect = '')
628 {
629 pl_content_headers("text/html");
630 $page->changeTpl('include/field.select.tpl', NO_SKIN);
631 $page->assign('name', 'pays_sel');
632 $where = ($ssect ? ' AND ms.subsectorid = {?}' : '');
633 $it = XDB::iterator("SELECT gc.iso_3166_1_a2 AS id, gc.countryFR AS field
634 FROM geoloc_countries AS gc
635 INNER JOIN profile_mentor_country AS mp ON (mp.country = gc.iso_3166_1_a2)
636 INNER JOIN profile_mentor_sector AS ms ON (ms.pid = mp.pid)
637 WHERE ms.sectorid = {?} " . $where . "
638 GROUP BY iso_3166_1_a2
639 ORDER BY countryFR", $sect, $ssect);
640 $page->assign('list', $it);
641 }
642
643 /**
644 * Page for url "referent/autocomplete". Display an "autocomplete" page (plain/text with values
645 * separated by "|" chars) for jobterms in referent (mentor) search.
646 * @see handler_jobterms
647 */
648 function handler_ref_autocomplete(&$page)
649 {
650 $this->handler_jobterms(&$page, 'mentor');
651 }
652
653 /**
654 * Page for url "profile/jobterms" (function also used for "referent/autocomplete" @see
655 * handler_ref_autocomplete). Displays an "autocomplete" page (plain text with values
656 * separated by "|" chars) for jobterms to add in profile.
657 * @param $page the Platal page
658 * @param $type set to 'mentor' to display the number of mentors for each term and order
659 * by descending number of mentors.
660 *
661 * @param Env::v('q') the text that has been typed and to complete automatically
662 */
663 function handler_jobterms(&$page, $type = 'nomentor')
664 {
665 pl_content_headers("text/plain");
666
667 $q = Env::v('q').'%';
668 $tokens = JobTerms::tokenize($q);
669 if (count($tokens) == 0) {
670 exit;
671 }
672 sort($tokens);
673 $q_normalized = implode(' ', $tokens);
674
675 // try to look in cached results
676 $cache = XDB::query('SELECT result
677 FROM search_autocomplete
678 WHERE name = {?} AND
679 query = {?} AND
680 generated > NOW() - INTERVAL 1 DAY',
681 $type, $q_normalized);
682 if ($res = $cache->fetchOneCell()) {
683 echo $res;
684 die();
685 }
686
687 $joins = JobTerms::token_join_query($tokens, 'e');
688 if ($type == 'mentor') {
689 $count = ', COUNT(DISTINCT pid) AS nb';
690 $countjoin = ' LEFT JOIN profile_job_term_relation AS r ON(r.jtid_1 = e.jtid) LEFT JOIN profile_mentor_term AS m ON(r.jtid_2 = m.jtid)';
691 $countorder = 'nb DESC, ';
692 } else {
693 $count = $countjoin = $countorder = '';
694 }
695 $list = XDB::iterator('SELECT e.jtid AS id, e.full_name AS field'.$count.'
696 FROM profile_job_term_enum AS e '.$joins.$countjoin.'
697 GROUP BY e.jtid
698 ORDER BY '.$countorder.'field
699 LIMIT 11');
700 $nbResults = 0;
701 $res = '';
702 while ($result = $list->next()) {
703 $nbResults++;
704 if ($nbResults == 11) {
705 $res .= $q."|-1\n";
706 } else {
707 $res .= $result['field'].'|';
708 if ($count) {
709 $res .= $result['nb'].'|';
710 }
711 $res .= $result['id'];
712 }
713 $res .= "\n";
714 }
715 XDB::query('REPLACE INTO search_autocomplete
716 VALUES ({?}, {?}, {?}, NOW())',
717 $type, $q_normalized, $res);
718 echo $res;
719 exit();
720 }
721
722 function handler_xnet(&$page)
723 {
724 $page->changeTpl('profile/groupesx.tpl');
725 $page->setTitle('Promo, Groupes X, Binets');
726
727 $req = XDB::query('
728 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
729 COUNT(e.eid) AS events, mail_domain AS lists
730 FROM group_members AS m
731 INNER JOIN groups AS a ON(m.asso_id = a.id)
732 LEFT JOIN group_events AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
733 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
734 $page->assign('assos', $req->fetchAllAssoc());
735 }
736
737 function handler_xnetlogo(&$page, $id)
738 {
739 if (is_null($id)) {
740 return PL_NOT_FOUND;
741 }
742
743 $res = XDB::query('SELECT logo, logo_mime
744 FROM groups
745 WHERE id = {?}', $id);
746 list($logo, $logo_mime) = $res->fetchOneRow();
747
748 if (!empty($logo)) {
749 pl_cached_dynamic_content_headers($logo_mime);
750 echo $logo;
751 } else {
752 pl_cached_dynamic_content_headers("image/jpeg");
753 readfile(dirname(__FILE__) . '/../htdocs/images/dflt_carre.jpg');
754 }
755
756 exit;
757 }
758
759 function handler_vcard(&$page, $x = null)
760 {
761 if (is_null($x)) {
762 return PL_NOT_FOUND;
763 }
764
765 global $globals;
766
767 if (substr($x, -4) == '.vcf') {
768 $x = substr($x, 0, strlen($x) - 4);
769 }
770
771 $vcard = new VCard();
772 $vcard->addProfile(Profile::get($x));
773 $vcard->show();
774 }
775
776 function handler_admin_trombino(&$page, $login = null, $action = null) {
777 $page->changeTpl('profile/admin_trombino.tpl');
778 $page->setTitle('Administration - Trombino');
779
780 if (!$login || !($user = User::get($login))) {
781 return PL_NOT_FOUND;
782 } else {
783 $page->assign_by_ref('user', $user);
784 }
785
786 switch ($action) {
787 case "original":
788 PlImage::fromFile("/home/web/trombino/photos" . $user->promo() . "/" . $user->login() . ".jpg", "image/jpeg")->send();
789 exit;
790
791 case "new":
792 S::assert_xsrf_token();
793
794 $data = file_get_contents($_FILES['userfile']['tmp_name']);
795 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
796 $mimetype = substr($_FILES['userfile']['type'], 6);
797 unlink($_FILES['userfile']['tmp_name']);
798 XDB::execute(
799 "REPLACE INTO profile_photos SET pid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
800 $user->profile()->id(), $mimetype, $data, $x, $y);
801 break;
802
803 case "delete":
804 S::assert_xsrf_token();
805
806 XDB::execute('DELETE FROM profile_photos WHERE pid = {?}', $user->profile()->id());
807 break;
808 }
809 }
810 function handler_admin_names(&$page, $action = 'list', $id = null) {
811 $page->setTitle('Administration - Types de noms');
812 $page->assign('title', 'Gestion des types de noms');
813 $table_editor = new PLTableEditor('admin/names', 'profile_name_enum', 'id', true);
814 $table_editor->describe('name', 'Nom', true);
815 $table_editor->describe('explanations', 'Explications', true);
816 $table_editor->describe('type', 'Type', true);
817 $table_editor->describe('flags', 'Flags', true);
818 $table_editor->describe('score', 'Score', true);
819 $table_editor->apply($page, $action, $id);
820 }
821 function handler_admin_binets(&$page, $action = 'list', $id = null) {
822 $page->setTitle('Administration - Binets');
823 $page->assign('title', 'Gestion des binets');
824 $table_editor = new PLTableEditor('admin/binets', 'profile_binet_enum', 'id');
825 $table_editor->add_join_table('profile_binets','binet_id',true);
826 $table_editor->describe('text','intitulé',true);
827 $table_editor->apply($page, $action, $id);
828 }
829 function handler_admin_education(&$page, $action = 'list', $id = null) {
830 $page->setTitle('Administration - Formations');
831 $page->assign('title', 'Gestion des formations');
832 $table_editor = new PLTableEditor('admin/education', 'profile_education_enum', 'id');
833 $table_editor->add_join_table('profile_education', 'eduid', true);
834 $table_editor->add_join_table('profile_education_degree', 'eduid', true);
835 $table_editor->describe('name', 'intitulé', true);
836 $table_editor->describe('url', 'site web', false);
837 $table_editor->apply($page, $action, $id);
838 }
839 function handler_admin_education_field(&$page, $action = 'list', $id = null) {
840 $page->setTitle('Administration - Domaines de formation');
841 $page->assign('title', 'Gestion des domaines de formation');
842 $table_editor = new PLTableEditor('admin/education_field', 'profile_education_field_enum', 'id', true);
843 $table_editor->add_join_table('profile_education', 'fieldid', true);
844 $table_editor->describe('field', 'domaine', true);
845 $table_editor->apply($page, $action, $id);
846 }
847 function handler_admin_education_degree(&$page, $action = 'list', $id = null) {
848 $page->setTitle('Administration - Niveau de formation');
849 $page->assign('title', 'Gestion des niveau de formation');
850 $table_editor = new PLTableEditor('admin/education_degree', 'profile_education_degree_enum', 'id');
851 $table_editor->add_join_table('profile_education_degree', 'degreeid', true);
852 $table_editor->add_join_table('profile_education', 'degreeid', true);
853 $table_editor->describe('degree', 'niveau', true);
854 $table_editor->apply($page, $action, $id);
855 }
856 function handler_admin_education_degree_set(&$page, $action = 'list', $id = null) {
857 $page->setTitle('Administration - Correspondances formations - niveau de formation');
858 $page->assign('title', 'Gestion des correspondances formations - niveau de formation');
859 $table_editor = new PLTableEditor('admin/education_degree_set', 'profile_education_degree', 'eduid', true);
860 $table_editor->describe('eduid', 'id formation', true);
861 $table_editor->describe('degreeid', 'id niveau', true);
862
863 // Adds fields to show the names of education
864 $table_editor->add_option_table('profile_education_enum','profile_education_enum.id = eduid');
865 $table_editor->add_option_field('profile_education_enum.name', 'edu_name', 'formation', null, 'degreeid');
866 // Adds fields to show the names of degrees
867 $table_editor->add_option_table('profile_education_degree_enum','profile_education_degree_enum.id = t.degreeid');
868 $table_editor->add_option_field('profile_education_degree_enum.degree', 'degree_name', 'niveau');
869
870 $table_editor->apply($page, $action, $id);
871 }
872 function handler_admin_sections(&$page, $action = 'list', $id = null) {
873 $page->setTitle('Administration - Sections');
874 $page->assign('title', 'Gestion des sections');
875 $table_editor = new PLTableEditor('admin/sections','profile_section_enum','id');
876 $table_editor->describe('text','intitulé',true);
877 $table_editor->apply($page, $action, $id);
878 }
879 function handler_admin_sectors(&$page, $action = 'list', $id = null) {
880 $page->setTitle('Administration - Secteurs');
881 $page->assign('title', 'Gestion des secteurs');
882 $table_editor = new PLTableEditor('admin/sectors', 'profile_job_subsubsector_enum', 'id', true);
883 $table_editor->describe('sectorid', 'id du secteur', false);
884 $table_editor->describe('subsectorid', 'id du sous-secteur', false);
885 $table_editor->describe('name', 'nom', true);
886 $table_editor->describe('flags', 'affichage', true);
887 $table_editor->apply($page, $action, $id);
888 }
889 function handler_admin_networking(&$page, $action = 'list', $id = null) {
890 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
891 $page->assign('title', 'Gestion des types de networking');
892 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'nwid');
893 $table_editor->describe('name', 'intitulé', true);
894 $table_editor->describe('icon', 'nom de l\'icône', false);
895 $table_editor->describe('filter', 'filtre', true);
896 $table_editor->describe('link', 'lien web', true);
897 $table_editor->apply($page, $action, $id);
898 }
899 function handler_admin_corps_enum(&$page, $action = 'list', $id = null) {
900 $page->setTitle('Administration - Corps');
901 $page->assign('title', 'Gestion des Corps');
902 $table_editor = new PLTableEditor('admin/corps_enum', 'profile_corps_enum', 'id');
903 $table_editor->describe('name', 'intitulé', true);
904 $table_editor->describe('abbreviation', 'abbréviation', true);
905 $table_editor->describe('still_exists', 'existe encore ?', true);
906 $table_editor->apply($page, $action, $id);
907 }
908 function handler_admin_corps_rank(&$page, $action = 'list', $id = null) {
909 $page->setTitle('Administration - Grade dans les Corps');
910 $page->assign('title', 'Gestion des grade dans les Corps');
911 $table_editor = new PLTableEditor('admin/corps_rank', 'profile_corps_rank_enum', 'id');
912 $table_editor->describe('name', 'intitulé', true);
913 $table_editor->describe('abbreviation', 'abbréviation', true);
914 $table_editor->apply($page, $action, $id);
915 }
916 function handler_admin_medals(&$page, $action = 'list', $id = null) {
917 $page->setTitle('Administration - Distinctions');
918 $page->assign('title', 'Gestion des Distinctions');
919 $table_editor = new PLTableEditor('admin/medals','profile_medal_enum','id');
920 $table_editor->describe('text', 'intitulé', true);
921 $table_editor->describe('img', 'nom de l\'image', false);
922 $table_editor->describe('flags', 'valider', true);
923 $table_editor->apply($page, $action, $id);
924 if ($id && $action == 'edit') {
925 $page->changeTpl('profile/admin_decos.tpl');
926
927 $mid = $id;
928
929 if (Post::v('act') == 'del') {
930 XDB::execute('DELETE FROM profile_medal_grade_enum
931 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
932 } else {
933 foreach (Post::v('grades', array()) as $gid=>$text) {
934 if ($gid === 0) {
935 if (!empty($text)) {
936 $res = XDB::query('SELECT MAX(gid)
937 FROM profile_medal_grade_enum
938 WHERE mid = {?}', $mid);
939 $gid = $res->fetchOneCell() + 1;
940
941 XDB::execute('INSERT INTO profile_medal_grade_enum (mid, gid, text, pos)
942 VALUES ({?}, {?}, {?}, {?})',
943 $mid, $gid, $text, $_POST['pos']['0']);
944 }
945 } else {
946 XDB::execute('UPDATE profile_medal_grade_enum
947 SET pos={?}, text={?}
948 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
949 }
950 }
951 }
952 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medal_grade_enum WHERE mid={?} ORDER BY pos', $mid);
953 $page->assign('grades', $res);
954 }
955 }
956 }
957
958 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
959 ?>