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