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