Merge commit 'origin/master' into fusionax
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
179afa7f 3 * Copyright (C) 2003-2008 Polytechnique.org *
7d8b17cb 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(
28e16d4d 27 'photo' => $this->make_hook('photo', AUTH_PUBLIC),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP),
e49018a7 29
e8599c21 30 'fiche.php' => $this->make_hook('fiche', AUTH_PUBLIC),
31 'profile' => $this->make_hook('profile', AUTH_PUBLIC),
9643d877 32 'profile/private' => $this->make_hook('profile', AUTH_COOKIE),
5122b820 33 'profile/ax' => $this->make_hook('ax', AUTH_COOKIE, 'admin'),
2f678da1 34 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
85cc366b 35 'profile/ajax/address' => $this->make_hook('ajax_address', AUTH_COOKIE, 'user', NO_AUTH),
2dcac0f5
FB
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),
40176c6c 38 'profile/networking' => $this->make_hook('networking', AUTH_PUBLIC),
2dcac0f5
FB
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),
f25e1a56 41 'profile/ajax/skill' => $this->make_hook('ajax_skill', AUTH_COOKIE, 'user', NO_AUTH),
b04882ff 42 'profile/ajax/searchname' => $this->make_hook('ajax_searchname', AUTH_COOKIE, 'user', NO_AUTH),
46ae38a9
FB
43 'javascript/applis.js' => $this->make_hook('applis_js', AUTH_COOKIE),
44 'javascript/grades.js' => $this->make_hook('grades_js', AUTH_COOKIE),
85cc366b 45 'profile/medal' => $this->make_hook('medal', AUTH_PUBLIC),
28e16d4d 46 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
28e16d4d 47 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP),
e49018a7 48
2f678da1 49 'referent' => $this->make_hook('referent', AUTH_COOKIE),
f5c5b741 50 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE),
2f678da1 51 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
ff3eb9b7 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),
2f678da1 54
a1d79217 55 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
926f16d7 56
8fc4efa3 57 'vcard' => $this->make_hook('vcard', AUTH_COOKIE, 'user', NO_HTTPS),
92423144 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'),
b09690be 61 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
62 'admin/secteurs' => $this->make_hook('admin_secteurs', AUTH_MDP, 'admin'),
15beefb3 63 'admin/networking' => $this->make_hook('admin_networking', AUTH_MDP, 'admin'),
92423144 64 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
a20aab02
SJ
65 'admin/ss_secteurs' => $this->make_hook('admin_ss_secteurs', AUTH_MDP, 'admin'),
66 'admin/fonctions' => $this->make_hook('admin_fonctions', AUTH_MDP, 'admin'),
92423144 67
7d8b17cb 68 );
69 }
70
e8599c21 71 /* XXX COMPAT */
72 function handler_fiche(&$page)
73 {
5e2307dc 74 return $this->handler_profile($page, Env::v('user'));
e8599c21 75 }
76
adbdf493 77 function handler_photo(&$page, $x = null, $req = null)
78 {
79 if (is_null($x)) {
80 return PL_NOT_FOUND;
81 }
82
08cce2ff 83 $res = XDB::query("SELECT id, pub FROM aliases
adbdf493 84 LEFT JOIN photo ON(id = uid)
85 WHERE alias = {?}", $x);
86 list($uid, $photo_pub) = $res->fetchOneRow();
87
cab08090 88 if ($req && S::logged()) {
adbdf493 89 include 'validations.inc.php';
90 $myphoto = PhotoReq::get_request($uid);
91 Header('Content-type: image/'.$myphoto->mimetype);
92 echo $myphoto->data;
93 } else {
08cce2ff 94 $res = XDB::query(
adbdf493 95 "SELECT attachmime, attach
96 FROM photo
97 WHERE uid={?}", $uid);
98
2f678da1 99 if ((list($type, $data) = $res->fetchOneRow())
cab08090 100 && ($photo_pub == 'public' || S::logged())) {
adbdf493 101 Header("Content-type: image/$type");
102 echo $data;
103 } else {
104 Header('Content-type: image/png');
fb9a56cb 105 echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
adbdf493 106 }
107 }
108 exit;
109 }
110
85cc366b
FB
111 function handler_medal(&$page, $mid)
112 {
bd6a5fe3
VZ
113 $thumb = ($mid == 'thumb');
114 $mid = $thumb ? @func_get_arg(2) : $mid;
115
85cc366b
FB
116 $res = XDB::query("SELECT img
117 FROM profile_medals
118 WHERE id = {?}",
119 $mid);
bd6a5fe3
VZ
120 $img = $thumb ?
121 dirname(__FILE__).'/../htdocs/images/medals/thumb/' . $res->fetchOneCell() :
122 dirname(__FILE__).'/../htdocs/images/medals/' . $res->fetchOneCell();
85cc366b
FB
123 $type = mime_content_type($img);
124 header("Content-Type: $type");
125 echo file_get_contents($img);
126 exit;
127 }
128
40176c6c
GB
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
fb9a56cb 142 function handler_photo_change(&$page)
143 {
ebfdf077 144 global $globals;
8b1f8e12 145 $page->changeTpl('profile/trombino.tpl');
fb9a56cb 146
147 require_once('validations.inc.php');
148
cab08090 149 $trombi_x = '/home/web/trombino/photos'.S::v('promo')
150 .'/'.S::v('forlife').'.jpg';
fb9a56cb 151
152 if (Env::has('upload')) {
8827fc52
VZ
153 S::assert_xsrf_token();
154
abe7e055 155 $upload = new PlUpload(S::v('forlife'), 'photo');
156 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
a7d35093 157 $page->trigError('Une erreur est survenue lors du téléchargement du fichier');
abe7e055 158 } else {
159 $myphoto = new PhotoReq(S::v('uid'), $upload);
160 if ($myphoto->isValid()) {
161 $myphoto->submit();
fb9a56cb 162 }
fb9a56cb 163 }
164 } elseif (Env::has('trombi')) {
8827fc52
VZ
165 S::assert_xsrf_token();
166
abe7e055 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 }
fb9a56cb 174 }
5e2307dc 175 } elseif (Env::v('suppr')) {
8827fc52
VZ
176 S::assert_xsrf_token();
177
84868ee9
FB
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'));
ebfdf077 184 $globals->updateNbValid();
5e2307dc 185 } elseif (Env::v('cancel')) {
8827fc52
VZ
186 S::assert_xsrf_token();
187
84868ee9
FB
188 $sql = XDB::query('DELETE FROM requests
189 WHERE user_id={?} AND type="photo"',
190 S::v('uid'));
ebfdf077 191 $globals->updateNbValid();
fb9a56cb 192 }
193
84868ee9
FB
194 $sql = XDB::query('SELECT COUNT(*)
195 FROM requests
196 WHERE user_id={?} AND type="photo"',
abe7e055 197 S::v('uid'));
fb9a56cb 198 $page->assign('submited', $sql->fetchOneCell());
199 $page->assign('has_trombi_x', file_exists($trombi_x));
fb9a56cb 200 }
201
e8599c21 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
b13048df 211 $page->changeTpl('profile/profile.tpl', SIMPLE);
e8599c21 212
213 $view = 'private';
5e2307dc 214 if (!S::logged() || Env::v('view') == 'public') $view = 'public';
215 if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
e8599c21 216
217 if (is_numeric($x)) {
08cce2ff 218 $res = XDB::query(
e1635d16 219 "SELECT alias
e8599c21 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 {
5350d751
FB
225 $login = get_user_forlife($x, S::logged() ? '_default_user_callback'
226 : '_silent_user_callback');
e8599c21 227 }
228
229 if (empty($login)) {
ba25f663
FB
230 $user = get_not_registered_user($x, true);
231 if ($user->total() != 1) {
232 return PL_NOT_FOUND;
924b4ba7 233 }
ba25f663
FB
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);
e8599c21 242 }
ba25f663 243
e31c1c3e 244 if (S::logged()) {
732e5855 245 S::logger()->log('view_profile', $login);
e8599c21 246 }
247
f45b6a99 248 $title = $user['prenom'] . ' ' . ( empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'] );
143ba7c9 249 $page->setTitle($title);
e8599c21 250
251 // photo
252
7da8ef90 253 $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
e8599c21 254
2f678da1 255 if (!isset($user['y']) and !isset($user['x'])) {
e8599c21 256 list($user['x'], $user['y']) = getimagesize("images/none.png");
257 }
2f678da1 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) {
e8599c21 261 $user['y'] = (integer)($user['y']*240/$user['x']);
262 $user['x'] = 240;
263 }
2f678da1 264 if ($user['y'] > 300) {
e8599c21 265 $user['x'] = (integer)($user['x']*300/$user['y']);
266 $user['y'] = 300;
267 }
2f678da1 268 if ($user['x'] < 160) {
e8599c21 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
08cce2ff 281 $res = XDB::query(
e8599c21 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}'",
660ca64a 288 $user['user_id'],
e8599c21 289 $user['forlife'].'@'.$globals->mail->domain,
290 $user['forlife'].'@'.$globals->mail->domain2);
291 $page->assign('virtualalias', $res->fetchOneCell());
24f4c06a 292 $page->assign('view', $view);
e8599c21 293
c99ef281 294 $page->addJsLink('close_on_esc.js');
6ce5dee4 295 header('Last-Modified: ' . date('r', strtotime($user['date'])));
e8599c21 296 }
297
5122b820 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
46ae38a9 316 function handler_p_edit(&$page, $opened_tab = null, $mode = null)
2f678da1 317 {
318 global $globals;
319
e1635d16
FB
320 // AX Synchronization
321 require_once 'synchro_ax.inc.php';
2f678da1 322 if (is_ax_key_missing()) {
323 $page->assign('no_private_key', true);
324 }
5e2307dc 325 if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
cab08090 326 ax_synchronize(S::v('bestalias'), S::v('uid'));
a7d35093 327 $page->trigSuccess('Ton profil a été synchronisé avec celui du site polytechniciens.com');
2f678da1 328 }
329
7bff4cb0 330 // Build the page
c6a7beb2 331 $page->addJsLink('ajax.js');
46ae38a9
FB
332 $page->addJsLink('applis.js');
333 $page->addJsLink('grades.js');
16594a1a 334 $page->addJsLink('profile.js');
4b4b4b67 335 $page->addJsLink('jquery.autocomplete.js');
46ae38a9 336 $wiz = new PlWizard('Profil', 'core/plwizard.tpl', true, true);
e1635d16
FB
337 require_once dirname(__FILE__) . '/profile/page.inc.php';
338 $wiz->addPage('ProfileGeneral', 'Général', 'general');
0b14f91d 339 $wiz->addPage('ProfileAddresses', 'Adresses personnelles', 'adresses');
e1635d16 340 $wiz->addPage('ProfileGroups', 'Groupes X - Binets', 'poly');
a7c28fff 341 $wiz->addPage('ProfileDecos', 'Décorations - Medailles', 'deco');
3950bc21 342 $wiz->addPage('ProfileJobs', 'Informations professionnelles', 'emploi');
e1635d16
FB
343 $wiz->addPage('ProfileSkills', 'Compétences diverses', 'skill');
344 $wiz->addPage('ProfileMentor', 'Mentoring', 'mentor');
46ae38a9 345 $wiz->apply($page, 'profile/edit', $opened_tab, $mode);
35aedff2 346
7bff4cb0
FB
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()) {
a7d35093 352 $page->trigWarning("Ta date de naissance n'est pas renseignée, ce qui t'empêcheras de réaliser"
7bff4cb0
FB
353 . " la procédure de récupération de mot de passe si un jour tu le perdais");
354 }
355
46f272fe 356 $page->setTitle('Mon Profil');
2f678da1 357 }
358
46ae38a9
FB
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
c6a7beb2
FB
397 function handler_ajax_address(&$page, $adid)
398 {
46ae38a9 399 header('Content-Type: text/html; charset=utf-8');
c6a7beb2
FB
400 $page->changeTpl('profile/adresses.address.tpl', NO_SKIN);
401 $page->assign('i', $adid);
402 $page->assign('adr', array());
c6a7beb2
FB
403 }
404
bde2be3b 405 function handler_ajax_tel(&$page, $prefid, $prefname, $telid)
c6a7beb2 406 {
46ae38a9 407 header('Content-Type: text/html; charset=utf-8');
bde2be3b
GB
408 $page->changeTpl('profile/phone.tpl', NO_SKIN);
409 $page->assign('prefid', $prefid);
410 $page->assign('prefname', $prefname);
411 $page->assign('telid', $telid);
c6a7beb2 412 $page->assign('tel', array());
c6a7beb2
FB
413 }
414
85cc366b
FB
415 function handler_ajax_medal(&$page, $id)
416 {
46ae38a9 417 header('Content-Type: text/html; charset=utf-8');
85cc366b
FB
418 $page->changeTpl('profile/deco.medal.tpl', NO_SKIN);
419 $page->assign('id', $id);
420 $page->assign('medal', array('valid' => 0, 'grade' => 0));
85cc366b
FB
421 }
422
2dcac0f5
FB
423 function handler_ajax_job(&$page, $id)
424 {
46ae38a9 425 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
426 $page->changeTpl('profile/jobs.job.tpl', NO_SKIN);
427 $page->assign('i', $id);
428 $page->assign('job', array());
2dcac0f5 429 $page->assign('new', true);
1879c7b2
FB
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"));
2dcac0f5
FB
435 }
436
437 function handler_ajax_secteur(&$page, $id, $sect, $ssect = -1)
438 {
46ae38a9 439 header('Content-Type: text/html; charset=utf-8');
2dcac0f5
FB
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
f25e1a56
FB
449 function handler_ajax_skill(&$page, $cat, $id)
450 {
46ae38a9 451 header('Content-Type: text/html; charset=utf-8');
f25e1a56 452 $page->changeTpl('profile/skill.skill.tpl', NO_SKIN);
f25e1a56
FB
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
b04882ff
PC
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
9b0fa329 478 function handler_p_orange(&$page)
479 {
8b1f8e12 480 $page->changeTpl('profile/orange.tpl');
9b0fa329 481
482 require_once 'validations.inc.php';
9b0fa329 483
08cce2ff 484 $res = XDB::query(
2f678da1 485 "SELECT u.promo, u.promo_sortie
9b0fa329 486 FROM auth_user_md5 AS u
cab08090 487 WHERE user_id={?}", S::v('uid'));
9b0fa329 488
2f678da1 489 list($promo, $promo_sortie_old) = $res->fetchOneRow();
9b0fa329 490 $page->assign('promo_sortie_old', $promo_sortie_old);
491 $page->assign('promo', $promo);
492
493 if (!Env::has('promo_sortie')) {
fd8f77de 494 return;
8827fc52
VZ
495 } else {
496 S::assert_xsrf_token();
9b0fa329 497 }
498
5e2307dc 499 $promo_sortie = Env::i('promo_sortie');
9b0fa329 500
501 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
a7d35093 502 $page->trigError('L\'année de sortie doit être un nombre de quatre chiffres');
9b0fa329 503 }
504 elseif ($promo_sortie < $promo + 3) {
a7d35093 505 $page->trigError('Trop tôt');
9b0fa329 506 }
507 elseif ($promo_sortie == $promo_sortie_old) {
a7d35093 508 $page->trigWarning('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 509 }
510 elseif ($promo_sortie == $promo + 3) {
08cce2ff 511 XDB::execute(
e1635d16 512 "UPDATE auth_user_md5 set promo_sortie={?}
cab08090 513 WHERE user_id={?}", $promo_sortie, S::v('uid'));
a7d35093 514 $page->trigSuccess('Ton statut "orange" a été supprimé.');
9b0fa329 515 $page->assign('promo_sortie_old', $promo_sortie);
516 }
517 else {
518 $page->assign('promo_sortie', $promo_sortie);
519
520 if (Env::has('submit')) {
cab08090 521 $myorange = new OrangeReq(S::v('uid'),
9b0fa329 522 $promo_sortie);
523 $myorange->submit();
524 $page->assign('myorange', $myorange);
525 }
526 }
9b0fa329 527 }
528
2f678da1 529 function handler_referent(&$page, $x = null)
28e16d4d 530 {
28e16d4d 531 require_once 'user.func.inc.php';
532
533 if (is_null($x)) {
534 return PL_NOT_FOUND;
535 }
536
8b1f8e12 537 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 538
08cce2ff 539 $res = XDB::query(
28e16d4d 540 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
541 FROM auth_user_md5 AS u
2f678da1 542 INNER JOIN aliases AS a ON (u.user_id=a.id
543 AND FIND_IN_SET('bestalias', a.flags))
28e16d4d 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);
37633309 557 $page->assign('cv', MiniWiki::WikiToHTML($cv, true));
28e16d4d 558 $page->assign('bestalias', $bestalias);
559 $page->assign('adr_pro', get_user_details_pro($user_id));
560
561 ///// recuperations infos referent
562
563 //expertise
08cce2ff 564 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
28e16d4d 565 $page->assign('expertise', $res->fetchOneCell());
566
567 //secteurs
568 $secteurs = $ss_secteurs = Array();
08cce2ff 569 $res = XDB::iterRow(
28e16d4d 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
08cce2ff 583 $res = XDB::query(
28e16d4d 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
c99ef281 590 $page->addJsLink('close_on_esc.js');
28e16d4d 591 }
592
ff3eb9b7 593 function handler_ref_search(&$page, $action = null, $subaction = null)
2f678da1 594 {
8f201b69
FB
595 $wp = new PlWikiPage('Docs.Emploi');
596 $wp->buildCache();
597
46f272fe 598 $page->setTitle('Conseil Pro');
2f678da1 599
2f678da1 600 //recuperation des noms de secteurs
08cce2ff 601 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 602 $secteurs[''] = '';
603 while (list($tmp_id, $tmp_label) = $res->next()) {
604 $secteurs[$tmp_id] = $tmp_label;
605 }
606 $page->assign_by_ref('secteurs', $secteurs);
607
2f678da1 608 // nb de mentors
08cce2ff 609 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 610 $page->assign('mentors_number', $res->fetchOneCell());
611
2f678da1 612 // On vient d'un formulaire
ff3eb9b7 613 $where = array();
614 $pays_sel = XDB::escape(Env::v('pays_sel'));
615 $secteur_sel = XDB::escape(Env::v('secteur'));
616 $ss_secteur_sel = XDB::escape(Env::v('ss_secteur'));
617 $expertise_champ = XDB::escape(Env::v('expertise'));
618
619 if ($pays_sel != "''") {
620 $where[] = "mp.pid = $pays_sel";
621 }
622 if ($secteur_sel != "''") {
623 $where[] = "ms.secteur = $secteur_sel";
624 if ($ss_secteur_sel != "''") {
625 $where[] = "ms.ss_secteur = $ss_secteur_sel";
2f678da1 626 }
627 }
ff3eb9b7 628 if ($expertise_champ != "''") {
629 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 630 }
631
632 if ($where) {
633 $where = join(' AND ', $where);
634
e1635d16
FB
635 $set = new UserSet("INNER JOIN mentor AS m ON (m.uid = u.user_id)
636 LEFT JOIN mentor_pays AS mp ON (mp.uid = m.uid)
ff3eb9b7 637 LEFT JOIN mentor_secteurs AS ms ON (ms.uid = m.uid)",
638 $where);
639 $set->addMod('mentor', 'Référents');
640 $set->apply('referent/search', $page, $action, $subaction);
641 if ($set->count() > 100) {
e1635d16 642 $page->assign('recherche_trop_large', true);
2f678da1 643 }
ff3eb9b7 644 }
e1635d16 645 $page->changeTpl('profile/referent.tpl');
ff3eb9b7 646 }
2f678da1 647
e1635d16 648 function handler_ref_sect(&$page, $sect)
ff3eb9b7 649 {
650 header('Content-Type: text/html; charset=utf-8');
05cb05c0 651 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 652 $page->assign('onchange', 'setSSecteurs()');
653 $page->assign('id', 'ssect_field');
654 $page->assign('name', 'ss_secteur');
655 $it = XDB::iterator("SELECT id,label AS field
e1635d16 656 FROM emploi_ss_secteur
ff3eb9b7 657 WHERE secteur = {?}", $sect);
658 $page->assign('list', $it);
659 }
2f678da1 660
ff3eb9b7 661 function handler_ref_country(&$page, $sect, $ssect = '')
662 {
663 header('Content-Type: text/html; charset=utf-8');
05cb05c0 664 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 665 $page->assign('name', 'pays_sel');
666 $where = ($ssect ? ' AND ms.ss_secteur = {?}' : '');
667 $it = XDB::iterator("SELECT a2 AS id, pays AS field
668 FROM geoloc_pays AS g
669 INNER JOIN mentor_pays AS mp ON (mp.pid = g.a2)
670 INNER JOIN mentor_secteurs AS ms ON (ms.uid = mp.uid)
671 WHERE ms.secteur = {?} $where
672 GROUP BY a2
673 ORDER BY pays", $sect, $ssect);
674 $page->assign('list', $it);
2f678da1 675 }
676
926f16d7 677 function handler_p_usage(&$page)
678 {
8b1f8e12 679 $page->changeTpl('profile/nomusage.tpl');
926f16d7 680
681 require_once 'validations.inc.php';
926f16d7 682
08cce2ff 683 $res = XDB::query(
2f678da1 684 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 685 FROM auth_user_md5 AS u
2f678da1 686 LEFT JOIN aliases AS e ON(u.user_id = e.id
687 AND FIND_IN_SET('usage', e.flags))
cab08090 688 WHERE user_id={?}", S::v('uid'));
926f16d7 689
2f678da1 690 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
113f6de8 691 $flags = new PlFlagSet($flags);
926f16d7 692 $page->assign('usage_old', $usage_old);
693 $page->assign('alias_old', $alias_old);
694
e1635d16 695 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 696 $nom_usage = strtoupper($nom_usage);
697 $page->assign('usage_req', $nom_usage);
698
699 if (Env::has('submit') && ($nom_usage != $usage_old)) {
8827fc52
VZ
700 S::assert_xsrf_token();
701
926f16d7 702 // on vient de recevoir une requete, differente de l'ancien nom d'usage
703 if ($nom_usage == $nom) {
704 $page->assign('same', true);
a7de4ef7 705 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 706 // on calcule l'alias pour l'afficher
5e2307dc 707 $reason = Env::v('reason');
926f16d7 708 if ($reason == 'other') {
5e2307dc 709 $reason = Env::v('other_reason');
926f16d7 710 }
cab08090 711 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 712 $myusage->submit();
713 $page->assign('myusage', $myusage);
714 }
715 }
926f16d7 716 }
717
a1d79217 718 function handler_xnet(&$page)
719 {
8b1f8e12 720 $page->changeTpl('profile/groupesx.tpl');
46f272fe 721 $page->setTitle('Promo, Groupes X, Binets');
e1635d16 722
a1d79217 723 $req = XDB::query('
e1635d16 724 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
46e1d3ba 725 COUNT(e.eid) AS events, mail_domain AS lists
e1635d16 726 FROM groupex.membres AS m
46e1d3ba 727 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
728 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
729 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 730 $page->assign('assos', $req->fetchAllAssoc());
731 }
e1635d16 732
e49018a7 733 function handler_vcard(&$page, $x = null)
734 {
735 if (is_null($x)) {
736 return PL_NOT_FOUND;
737 }
738
739 global $globals;
740
741 if (substr($x, -4) == '.vcf') {
742 $x = substr($x, 0, strlen($x) - 4);
743 }
744
5e193297 745 $vcard = new VCard($x);
746 $vcard->do_page($page);
e49018a7 747 }
92423144 748
749 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 750 $page->changeTpl('profile/admin_trombino.tpl');
46f272fe 751 $page->setTitle('Administration - Trombino');
92423144 752 $page->assign('uid', $uid);
e1635d16 753
92423144 754 $q = XDB::query(
755 "SELECT a.alias,promo
756 FROM auth_user_md5 AS u
757 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
758 WHERE user_id = {?}", $uid);
759 list($forlife, $promo) = $q->fetchOneRow();
e1635d16 760
92423144 761 switch ($action) {
92423144 762 case "original":
763 header("Content-type: image/jpeg");
764 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
765 exit;
766 break;
e1635d16 767
92423144 768 case "new":
8827fc52
VZ
769 S::assert_xsrf_token();
770
92423144 771 $data = file_get_contents($_FILES['userfile']['tmp_name']);
772 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
773 $mimetype = substr($_FILES['userfile']['type'], 6);
774 unlink($_FILES['userfile']['tmp_name']);
775 XDB::execute(
776 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
777 $uid, $mimetype, $data, $x, $y);
778 break;
e1635d16 779
92423144 780 case "delete":
8827fc52
VZ
781 S::assert_xsrf_token();
782
92423144 783 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
784 break;
785 }
e1635d16 786
92423144 787 $page->assign('forlife', $forlife);
788 }
789 function handler_admin_binets(&$page, $action = 'list', $id = null) {
46f272fe 790 $page->setTitle('Administration - Binets');
92423144 791 $page->assign('title', 'Gestion des binets');
792 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
793 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 794 $table_editor->describe('text','intitulé',true);
92423144 795 $table_editor->apply($page, $action, $id);
796 }
797 function handler_admin_formations(&$page, $action = 'list', $id = null) {
46f272fe 798 $page->setTitle('Administration - Formations');
92423144 799 $page->assign('title', 'Gestion des formations');
800 $table_editor = new PLTableEditor('admin/formations','applis_def','id');
e1635d16 801 $table_editor->add_join_table('applis_ins','aid',true);
a7de4ef7 802 $table_editor->describe('text','intitulé',true);
92423144 803 $table_editor->describe('url','site web',false);
804 $table_editor->apply($page, $action, $id);
e1635d16 805 }
b09690be 806 function handler_admin_sections(&$page, $action = 'list', $id = null) {
46f272fe 807 $page->setTitle('Administration - Sections');
a20aab02 808 $page->assign('title', 'Gestion des sections');
b09690be 809 $table_editor = new PLTableEditor('admin/sections','sections','id');
810 $table_editor->describe('text','intitulé',true);
811 $table_editor->apply($page, $action, $id);
e1635d16 812 }
a20aab02 813 function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 814 $page->setTitle('Administration - Sous-secteurs');
a20aab02
SJ
815 $page->assign('title', 'Gestion des sous-secteurs');
816 $table_editor = new PLTableEditor('admin/ss_secteurs', 'emploi_ss_secteur', 'id', true);
817 $table_editor->describe('label', 'intitulé', true);
818 $table_editor->apply($page, $action, $id);
819 }
820 function handler_admin_fonctions(&$page, $action = 'list', $id = null) {
46f272fe 821 $page->setTitle('Administration - Fonctions');
a20aab02
SJ
822 $page->assign('title', 'Gestion des fonctions');
823 $table_editor = new PLTableEditor('admin/fonctions', 'fonctions_def', 'id', true);
824 $table_editor->describe('fonction_fr', 'intitulé', true);
825 $table_editor->describe('fonction_en', 'intitulé (ang)', true);
826 $table_editor->describe('flags', 'titre', true);
827 $table_editor->apply($page, $action, $id);
828 }
b09690be 829 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
46f272fe 830 $page->setTitle('Administration - Secteurs');
a20aab02
SJ
831 $page->assign('title', 'Gestion des secteurs');
832 $table_editor = new PLTableEditor('admin/secteurs', 'emploi_secteur', 'id', true);
833 $table_editor->describe('label', 'intitulé', true);
b09690be 834 $table_editor->apply($page, $action, $id);
e1635d16 835 }
15beefb3
GB
836 function handler_admin_networking(&$page, $action = 'list', $id = null) {
837 $page->assign('xorg_title', 'Polytechnique.org - Administration - Networking');
838 $page->assign('title', 'Gestion des types de networking');
839 $table_editor = new PLTableEditor('admin/networking', 'profile_networking_enum', 'network_type');
840 $table_editor->describe('name', 'intitulé', true);
841 $table_editor->describe('icon', 'nom de l\'icône', false);
dc6378df
GB
842 $table_editor->describe('filter', 'filtre', true);
843 $table_editor->describe('link', 'lien web', true);
15beefb3
GB
844 $table_editor->apply($page, $action, $id);
845 }
92423144 846 function handler_admin_medals(&$page, $action = 'list', $id = null) {
46f272fe 847 $page->setTitle('Administration - Distinctions');
92423144 848 $page->assign('title', 'Gestion des Distinctions');
849 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 850 $table_editor->describe('text', 'intitulé', true);
92423144 851 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 852 $table_editor->describe('flags', 'valider', true);
92423144 853 $table_editor->apply($page, $action, $id);
854 if ($id && $action == 'edit') {
8b1f8e12 855 $page->changeTpl('profile/admin_decos.tpl');
e1635d16 856
92423144 857 $mid = $id;
e1635d16 858
92423144 859 if (Post::v('act') == 'del') {
75a17710
FB
860 XDB::execute('DELETE FROM profile_medals_grades
861 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
92423144 862 } else {
863 foreach (Post::v('grades', array()) as $gid=>$text) {
154ee23a
OLF
864 if ($gid === 0) {
865 if (!empty($text)) {
866 $res = XDB::query('SELECT MAX(gid)
867 FROM profile_medals_grades
868 WHERE mid = {?}', $mid);
869 $gid = $res->fetchOneCell() + 1;
870
871 XDB::execute('INSERT INTO profile_medals_grades (mid, gid, text, pos)
872 VALUES ({?}, {?}, {?}, {?})',
873 $mid, $gid, $text, $_POST['pos']['0']);
874 }
875 } else {
876 XDB::execute('UPDATE profile_medals_grades
877 SET pos={?}, text={?}
878 WHERE gid={?} AND mid={?}', $_POST['pos'][$gid], $text, $gid, $mid);
879 }
92423144 880 }
881 }
882 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
883 $page->assign('grades', $res);
884 }
e1635d16 885 }
7d8b17cb 886}
887
a7de4ef7 888// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 889?>