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