merge with master
[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
143ba7c9 356 $page->setTitle('Polytechnique.org - 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 {
f5c5b741 595 require_once 'wiki.inc.php';
596 wiki_require_page('Docs.Emploi');
143ba7c9 597 $page->setTitle('Polytechnique.org - Conseil Pro');
2f678da1 598
2f678da1 599 //recuperation des noms de secteurs
08cce2ff 600 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 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
2f678da1 607 // nb de mentors
08cce2ff 608 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 609 $page->assign('mentors_number', $res->fetchOneCell());
610
2f678da1 611 // On vient d'un formulaire
ff3eb9b7 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";
2f678da1 625 }
626 }
ff3eb9b7 627 if ($expertise_champ != "''") {
628 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 629 }
630
631 if ($where) {
632 $where = join(' AND ', $where);
633
e1635d16
FB
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)
ff3eb9b7 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) {
e1635d16 641 $page->assign('recherche_trop_large', true);
2f678da1 642 }
ff3eb9b7 643 }
e1635d16 644 $page->changeTpl('profile/referent.tpl');
ff3eb9b7 645 }
2f678da1 646
e1635d16 647 function handler_ref_sect(&$page, $sect)
ff3eb9b7 648 {
649 header('Content-Type: text/html; charset=utf-8');
05cb05c0 650 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 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
e1635d16 655 FROM emploi_ss_secteur
ff3eb9b7 656 WHERE secteur = {?}", $sect);
657 $page->assign('list', $it);
658 }
2f678da1 659
ff3eb9b7 660 function handler_ref_country(&$page, $sect, $ssect = '')
661 {
662 header('Content-Type: text/html; charset=utf-8');
05cb05c0 663 $page->changeTpl('include/field.select.tpl', NO_SKIN);
ff3eb9b7 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);
2f678da1 674 }
675
926f16d7 676 function handler_p_usage(&$page)
677 {
8b1f8e12 678 $page->changeTpl('profile/nomusage.tpl');
926f16d7 679
680 require_once 'validations.inc.php';
926f16d7 681
08cce2ff 682 $res = XDB::query(
2f678da1 683 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 684 FROM auth_user_md5 AS u
2f678da1 685 LEFT JOIN aliases AS e ON(u.user_id = e.id
686 AND FIND_IN_SET('usage', e.flags))
cab08090 687 WHERE user_id={?}", S::v('uid'));
926f16d7 688
2f678da1 689 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
113f6de8 690 $flags = new PlFlagSet($flags);
926f16d7 691 $page->assign('usage_old', $usage_old);
692 $page->assign('alias_old', $alias_old);
693
e1635d16 694 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 695 $nom_usage = strtoupper($nom_usage);
696 $page->assign('usage_req', $nom_usage);
697
698 if (Env::has('submit') && ($nom_usage != $usage_old)) {
8827fc52
VZ
699 S::assert_xsrf_token();
700
926f16d7 701 // on vient de recevoir une requete, differente de l'ancien nom d'usage
702 if ($nom_usage == $nom) {
703 $page->assign('same', true);
a7de4ef7 704 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 705 // on calcule l'alias pour l'afficher
5e2307dc 706 $reason = Env::v('reason');
926f16d7 707 if ($reason == 'other') {
5e2307dc 708 $reason = Env::v('other_reason');
926f16d7 709 }
cab08090 710 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 711 $myusage->submit();
712 $page->assign('myusage', $myusage);
713 }
714 }
926f16d7 715 }
716
a1d79217 717 function handler_xnet(&$page)
718 {
8b1f8e12 719 $page->changeTpl('profile/groupesx.tpl');
143ba7c9 720 $page->setTitle('Polytechnique.org - Promo, Groupes X, Binets');
e1635d16 721
a1d79217 722 $req = XDB::query('
e1635d16 723 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
46e1d3ba 724 COUNT(e.eid) AS events, mail_domain AS lists
e1635d16 725 FROM groupex.membres AS m
46e1d3ba 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'));
a1d79217 729 $page->assign('assos', $req->fetchAllAssoc());
730 }
e1635d16 731
e49018a7 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
5e193297 744 $vcard = new VCard($x);
745 $vcard->do_page($page);
e49018a7 746 }
92423144 747
748 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 749 $page->changeTpl('profile/admin_trombino.tpl');
143ba7c9 750 $page->setTitle('Polytechnique.org - Administration - Trombino');
92423144 751 $page->assign('uid', $uid);
e1635d16 752
92423144 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();
e1635d16 759
92423144 760 switch ($action) {
92423144 761 case "original":
762 header("Content-type: image/jpeg");
763 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
764 exit;
765 break;
e1635d16 766
92423144 767 case "new":
8827fc52
VZ
768 S::assert_xsrf_token();
769
92423144 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;
e1635d16 778
92423144 779 case "delete":
8827fc52
VZ
780 S::assert_xsrf_token();
781
92423144 782 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
783 break;
784 }
e1635d16 785
92423144 786 $page->assign('forlife', $forlife);
787 }
788 function handler_admin_binets(&$page, $action = 'list', $id = null) {
143ba7c9 789 $page->setTitle('Polytechnique.org - Administration - Binets');
92423144 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);
a7de4ef7 793 $table_editor->describe('text','intitulé',true);
92423144 794 $table_editor->apply($page, $action, $id);
795 }
796 function handler_admin_formations(&$page, $action = 'list', $id = null) {
143ba7c9 797 $page->setTitle('Polytechnique.org - Administration - Formations');
92423144 798 $page->assign('title', 'Gestion des formations');
799 $table_editor = new PLTableEditor('admin/formations','applis_def','id');
e1635d16 800 $table_editor->add_join_table('applis_ins','aid',true);
a7de4ef7 801 $table_editor->describe('text','intitulé',true);
92423144 802 $table_editor->describe('url','site web',false);
803 $table_editor->apply($page, $action, $id);
e1635d16 804 }
b09690be 805 function handler_admin_sections(&$page, $action = 'list', $id = null) {
143ba7c9 806 $page->setTitle('Polytechnique.org - Administration - Sections');
a20aab02 807 $page->assign('title', 'Gestion des sections');
b09690be 808 $table_editor = new PLTableEditor('admin/sections','sections','id');
809 $table_editor->describe('text','intitulé',true);
810 $table_editor->apply($page, $action, $id);
e1635d16 811 }
a20aab02 812 function handler_admin_ss_secteurs(&$page, $action = 'list', $id = null) {
143ba7c9 813 $page->setTitle('Polytechnique.org - Administration - Sous-secteurs');
a20aab02
SJ
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) {
143ba7c9 820 $page->setTitle('Polytechnique.org - Administration - Fonctions');
a20aab02
SJ
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 }
b09690be 828 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
143ba7c9 829 $page->setTitle('Polytechnique.org - Administration - Secteurs');
a20aab02
SJ
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);
b09690be 833 $table_editor->apply($page, $action, $id);
e1635d16 834 }
15beefb3
GB
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);
dc6378df
GB
841 $table_editor->describe('filter', 'filtre', true);
842 $table_editor->describe('link', 'lien web', true);
15beefb3
GB
843 $table_editor->apply($page, $action, $id);
844 }
92423144 845 function handler_admin_medals(&$page, $action = 'list', $id = null) {
143ba7c9 846 $page->setTitle('Polytechnique.org - Administration - Distinctions');
92423144 847 $page->assign('title', 'Gestion des Distinctions');
848 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 849 $table_editor->describe('text', 'intitulé', true);
92423144 850 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 851 $table_editor->describe('flags', 'valider', true);
92423144 852 $table_editor->apply($page, $action, $id);
853 if ($id && $action == 'edit') {
8b1f8e12 854 $page->changeTpl('profile/admin_decos.tpl');
e1635d16 855
92423144 856 $mid = $id;
e1635d16 857
92423144 858 if (Post::v('act') == 'del') {
75a17710
FB
859 XDB::execute('DELETE FROM profile_medals_grades
860 WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
92423144 861 } else {
862 foreach (Post::v('grades', array()) as $gid=>$text) {
154ee23a
OLF
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 }
92423144 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 }
e1635d16 884 }
7d8b17cb 885}
886
a7de4ef7 887// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 888?>