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