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