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