Oops
[platal.git] / modules / profile.php
CommitLineData
7d8b17cb 1<?php
2/***************************************************************************
5ddeb07c 3 * Copyright (C) 2003-2007 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),
2f678da1 33 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP),
28e16d4d 34 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP),
28e16d4d 35 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP),
e49018a7 36
2f678da1 37 'referent' => $this->make_hook('referent', AUTH_COOKIE),
f5c5b741 38 'emploi' => $this->make_hook('ref_search', AUTH_COOKIE),
2f678da1 39 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE),
ff3eb9b7 40 'referent/ssect' => $this->make_hook('ref_sect', AUTH_COOKIE, 'user', NO_AUTH),
41 'referent/country' => $this->make_hook('ref_country', AUTH_COOKIE, 'user', NO_AUTH),
2f678da1 42
a1d79217 43 'groupes-x' => $this->make_hook('xnet', AUTH_COOKIE),
926f16d7 44
28e16d4d 45 'vcard' => $this->make_hook('vcard', AUTH_COOKIE),
92423144 46 'admin/binets' => $this->make_hook('admin_binets', AUTH_MDP, 'admin'),
47 'admin/medals' => $this->make_hook('admin_medals', AUTH_MDP, 'admin'),
48 'admin/formations' => $this->make_hook('admin_formations', AUTH_MDP, 'admin'),
49 'admin/groupes-x' => $this->make_hook('admin_groupesx', AUTH_MDP, 'admin'),
b09690be 50 'admin/sections' => $this->make_hook('admin_sections', AUTH_MDP, 'admin'),
51 'admin/secteurs' => $this->make_hook('admin_secteurs', AUTH_MDP, 'admin'),
92423144 52 'admin/trombino' => $this->make_hook('admin_trombino', AUTH_MDP, 'admin'),
53
7d8b17cb 54 );
55 }
56
e8599c21 57 /* XXX COMPAT */
58 function handler_fiche(&$page)
59 {
5e2307dc 60 return $this->handler_profile($page, Env::v('user'));
e8599c21 61 }
62
adbdf493 63 function handler_photo(&$page, $x = null, $req = null)
64 {
65 if (is_null($x)) {
66 return PL_NOT_FOUND;
67 }
68
08cce2ff 69 $res = XDB::query("SELECT id, pub FROM aliases
adbdf493 70 LEFT JOIN photo ON(id = uid)
71 WHERE alias = {?}", $x);
72 list($uid, $photo_pub) = $res->fetchOneRow();
73
cab08090 74 if ($req && S::logged()) {
adbdf493 75 include 'validations.inc.php';
76 $myphoto = PhotoReq::get_request($uid);
77 Header('Content-type: image/'.$myphoto->mimetype);
78 echo $myphoto->data;
79 } else {
08cce2ff 80 $res = XDB::query(
adbdf493 81 "SELECT attachmime, attach
82 FROM photo
83 WHERE uid={?}", $uid);
84
2f678da1 85 if ((list($type, $data) = $res->fetchOneRow())
cab08090 86 && ($photo_pub == 'public' || S::logged())) {
adbdf493 87 Header("Content-type: image/$type");
88 echo $data;
89 } else {
90 Header('Content-type: image/png');
fb9a56cb 91 echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png');
adbdf493 92 }
93 }
94 exit;
95 }
96
fb9a56cb 97 function handler_photo_change(&$page)
98 {
8b1f8e12 99 $page->changeTpl('profile/trombino.tpl');
fb9a56cb 100
101 require_once('validations.inc.php');
102
cab08090 103 $trombi_x = '/home/web/trombino/photos'.S::v('promo')
104 .'/'.S::v('forlife').'.jpg';
fb9a56cb 105
106 if (Env::has('upload')) {
abe7e055 107 $upload = new PlUpload(S::v('forlife'), 'photo');
108 if (!$upload->upload($_FILES['userfile']) && !$upload->download(Env::v('photo'))) {
109 $page->trig('Une erreur est survenue lors du téléchargement du fichier');
110 } else {
111 $myphoto = new PhotoReq(S::v('uid'), $upload);
112 if ($myphoto->isValid()) {
113 $myphoto->submit();
fb9a56cb 114 }
fb9a56cb 115 }
116 } elseif (Env::has('trombi')) {
abe7e055 117 $upload = new PlUpload(S::v('forlife'), 'photo');
118 if ($upload->copyFrom($trombi_x)) {
119 $myphoto = new PhotoReq(S::v('uid'), $upload);
120 if ($myphoto->isValid()) {
121 $myphoto->commit();
122 $myphoto->clean();
123 }
fb9a56cb 124 }
5e2307dc 125 } elseif (Env::v('suppr')) {
08cce2ff 126 XDB::execute('DELETE FROM photo WHERE uid = {?}',
cab08090 127 S::v('uid'));
08cce2ff 128 XDB::execute('DELETE FROM requests
fb9a56cb 129 WHERE user_id = {?} AND type="photo"',
cab08090 130 S::v('uid'));
5e2307dc 131 } elseif (Env::v('cancel')) {
08cce2ff 132 $sql = XDB::query('DELETE FROM requests
fb9a56cb 133 WHERE user_id={?} AND type="photo"',
cab08090 134 S::v('uid'));
fb9a56cb 135 }
136
08cce2ff 137 $sql = XDB::query('SELECT COUNT(*) FROM requests
abe7e055 138 WHERE user_id={?} AND type="photo"',
139 S::v('uid'));
fb9a56cb 140 $page->assign('submited', $sql->fetchOneCell());
141 $page->assign('has_trombi_x', file_exists($trombi_x));
fb9a56cb 142 }
143
e8599c21 144 function handler_profile(&$page, $x = null)
145 {
146 if (is_null($x)) {
147 return PL_NOT_FOUND;
148 }
149
150 global $globals;
151 require_once 'user.func.inc.php';
152
b13048df 153 $page->changeTpl('profile/profile.tpl', SIMPLE);
e8599c21 154
155 $view = 'private';
5e2307dc 156 if (!S::logged() || Env::v('view') == 'public') $view = 'public';
157 if (S::logged() && Env::v('view') == 'ax') $view = 'ax';
e8599c21 158
159 if (is_numeric($x)) {
08cce2ff 160 $res = XDB::query(
e8599c21 161 "SELECT alias
162 FROM aliases AS a
163 INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie')
164 WHERE matricule={?}", $x);
165 $login = $res->fetchOneCell();
166 } else {
167 $login = get_user_forlife($x);
168 }
169
170 if (empty($login)) {
924b4ba7 171 if (preg_match('/([-a-z]+)\.([-a-z]+)\.([0-9]{4})/i', $x, $matches)) {
172 $matches = str_replace('-', '_', $matches);
173 $res = XDB::query("SELECT user_id
174 FROM auth_user_md5
175 WHERE prenom LIKE {?} AND nom LIKE {?} AND promo = {?}
176 AND perms = 'pending'",
177 $matches[1], $matches[2], $matches[3]);
178 if ($res->numRows() == 1) {
179 $uid = $res->fetchOneCell();
180 pl_redirect('marketing/public/' . $uid);
181 }
182 }
e8599c21 183 return PL_NOT_FOUND;
184 }
185
5e2307dc 186 $new = Env::v('modif') == 'new';
cab08090 187 $user = get_user_details($login, S::v('uid'), $view);
3c85da85 188 $user['freetext'] = MiniWiki::WikiToHTML($user['freetext']);
60979eb7 189 $user['cv'] = MiniWiki::WikiToHTML($user['cv']);
e8599c21 190 $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage'];
191 $page->assign('xorg_title', $title);
192
193 // photo
194
7da8ef90 195 $photo = 'photo/'.$user['forlife'].($new ? '/req' : '');
e8599c21 196
2f678da1 197 if (!isset($user['y']) and !isset($user['x'])) {
e8599c21 198 list($user['x'], $user['y']) = getimagesize("images/none.png");
199 }
2f678da1 200 if (!isset($user['y']) or $user['y'] < 1) $user['y']=1;
201 if (!isset($user['x']) or $user['x'] < 1) $user['x']=1;
202 if ($user['x'] > 240) {
e8599c21 203 $user['y'] = (integer)($user['y']*240/$user['x']);
204 $user['x'] = 240;
205 }
2f678da1 206 if ($user['y'] > 300) {
e8599c21 207 $user['x'] = (integer)($user['x']*300/$user['y']);
208 $user['y'] = 300;
209 }
2f678da1 210 if ($user['x'] < 160) {
e8599c21 211 $user['y'] = (integer)($user['y']*160/$user['x']);
212 $user['x'] = 160;
213 }
214
215 $page->assign('logged', has_user_right('private', $view));
216 if (!has_user_right($user['photo_pub'], $view)) {
217 $photo = "";
218 }
219
220 $page->assign_by_ref('x', $user);
221 $page->assign('photo_url', $photo);
222 // alias virtual
08cce2ff 223 $res = XDB::query(
e8599c21 224 "SELECT alias
225 FROM virtual
226 INNER JOIN virtual_redirect USING(vid)
227 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
228 WHERE ( redirect={?} OR redirect={?} )
229 AND alias LIKE '%@{$globals->mail->alias_dom}'",
cab08090 230 S::v('uid'),
e8599c21 231 $user['forlife'].'@'.$globals->mail->domain,
232 $user['forlife'].'@'.$globals->mail->domain2);
233 $page->assign('virtualalias', $res->fetchOneCell());
234
c99ef281 235 $page->addJsLink('close_on_esc.js');
6ce5dee4 236 header('Last-Modified: ' . date('r', strtotime($user['date'])));
e8599c21 237 }
238
2f678da1 239 function handler_p_edit(&$page, $opened_tab = 'general')
240 {
241 global $globals;
242
8b1f8e12 243 $page->changeTpl('profile/edit.tpl');
2f678da1 244
c99ef281 245 $page->addCssLink('profil.css');
2f678da1 246 $page->assign('xorg_title', 'Polytechnique.org - Mon Profil');
247
f62bd784 248 require_once dirname(__FILE__) . '/profile/tabs.inc.php';
2f678da1 249 require_once 'profil.func.inc.php';
250 require_once 'synchro_ax.inc.php';
251
3845b131 252 if (Post::v('register_from_ax_question')) {
253 XDB::execute('UPDATE auth_user_quick
2f678da1 254 SET profile_from_ax = 1
255 WHERE user_id = {?}',
cab08090 256 S::v('uid'));
2f678da1 257 }
3845b131 258 if (Post::v('add_to_nl')) {
259 require_once 'newsletter.inc.php';
714bc242 260 NewsLetter::subscribe();
261 }
262 if (Post::v('add_to_ax')) {
263 require_once dirname(__FILE__) . '/axletter/axletter.inc.php';
264 AXLetter::subscribe();
3845b131 265 }
266 if (Post::v('add_to_promo')) {
267 $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}',
268 S::v('promo'));
269 $asso_id = $r->fetchOneCell();
270 XDB::execute('REPLACE INTO groupex.membres (uid,asso_id)
271 VALUES ({?}, {?})',
272 S::v('uid'), $asso_id);
9bb8bf21 273 $mmlist = new MMList(S::v('uid'), S::v('password'));
274 $mmlist->subscribe("promo".S::v('promo'));
3845b131 275 }
0baf0741 276 if (Post::v('sub_ml')) {
277 $subs = array_keys(Post::v('sub_ml'));
278 $current_domain = null;
279 foreach ($subs as $list) {
280 list($sub, $domain) = explode('@', $list);
281 if ($domain != $current_domain) {
282 $current_domain = $domain;
283 $client = new MMList(S::v('uid'), S::v('password'), $domain);
284 }
285 $client->subscribe($sub);
286 }
287 }
2f678da1 288
289 if (is_ax_key_missing()) {
290 $page->assign('no_private_key', true);
291 }
292
5e2307dc 293 if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) {
cab08090 294 ax_synchronize(S::v('bestalias'), S::v('uid'));
a7de4ef7 295 $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com');
2f678da1 296 }
297
298 // pour tous les tabs, la date de naissance pour verifier
299 // quelle est bien rentree et la date.
08cce2ff 300 $res = XDB::query(
2f678da1 301 "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y')
302 FROM auth_user_md5
cab08090 303 WHERE user_id={?}", S::v('uid'));
2f678da1 304 list($naissance, $date_modif_profil) = $res->fetchOneRow();
305
a7de4ef7 306 // lorsqu'on n'a pas la date de naissance en base de données
2f678da1 307 if (!$naissance) {
a7de4ef7 308 // la date de naissance n'existait pas et vient d'être soumise dans la variable
2f678da1 309 if (Env::has('birth')) {
310 //en cas d'erreur :
5e2307dc 311 if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) {
2f678da1 312 $page->assign('etat_naissance', 'query');
a7de4ef7 313 $page->trig('Date de naissance incorrecte ou incohérente.');
fd8f77de 314 return;
2f678da1 315 }
316
317 //sinon
5e2307dc 318 $birth = sprintf("%s-%s-%s", substr(Env::v('birth'), 4, 4),
319 substr(Env::v('birth'), 2, 2),
320 substr(Env::v('birth'), 0, 2));
08cce2ff 321 XDB::execute("UPDATE auth_user_md5
2f678da1 322 SET naissance={?}
323 WHERE user_id={?}", $birth,
cab08090 324 S::v('uid'));
2f678da1 325 $page->assign('etat_naissance', 'ok');
fd8f77de 326 return;
2f678da1 327 }
328
329 $page->assign('etat_naissance', 'query');
fd8f77de 330 return; // on affiche le formulaire pour naissance
2f678da1 331 }
332
333 //doit-on faire un update ?
334 if (Env::has('modifier') || Env::has('suivant')) {
28bda7c5 335 require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
336 require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
2f678da1 337
338 if($page->nb_errs()) {
28bda7c5 339 require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
2f678da1 340 $page->assign('onglet', $opened_tab);
8b1f8e12 341 $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
fd8f77de 342 return;
2f678da1 343 }
344
345 $date=date("Y-m-j");//nouvelle date de mise a jour
346
347 //On sauvegarde l'uid pour l'AX
348 /* on sauvegarde les changements dans user_changes :
a7de4ef7 349 * on a juste besoin d'insérer le user_id de la personne dans la table
2f678da1 350 */
08cce2ff 351 XDB::execute('REPLACE INTO user_changes SET user_id={?}',
cab08090 352 S::v('uid'));
2f678da1 353
cab08090 354 if (!S::has('suid')) {
2f678da1 355 require_once 'notifs.inc.php';
cab08090 356 register_watch_op(S::v('uid'), WATCH_FICHE);
2f678da1 357 }
358
359 // mise a jour des champs relatifs au tab ouvert
28bda7c5 360 require_once dirname(__FILE__) . "/profile/update_{$opened_tab}.inc.php";
2f678da1 361
5ee95138 362 $log =& $_SESSION['log'];
2f678da1 363 $log->log('profil', $opened_tab);
364 $page->assign('etat_update', 'ok');
365 }
366
367 if (Env::has('suivant')) {
8b00e0e0 368 pl_redirect('profile/edit/' . get_next_tab($opened_tab));
2f678da1 369 }
370
28bda7c5 371 require_once dirname(__FILE__) . "/profile/get_{$opened_tab}.inc.php";
372 require_once dirname(__FILE__) . "/profile/verif_{$opened_tab}.inc.php";
373 require_once dirname(__FILE__) . "/profile/assign_{$opened_tab}.inc.php";
2f678da1 374
375 $page->assign('onglet', $opened_tab);
8b1f8e12 376 $page->assign('onglet_tpl', "profile/$opened_tab.tpl");
2f678da1 377
fd8f77de 378 return;
2f678da1 379 }
380
9b0fa329 381 function handler_p_orange(&$page)
382 {
8b1f8e12 383 $page->changeTpl('profile/orange.tpl');
9b0fa329 384
385 require_once 'validations.inc.php';
386 require_once 'xorg.misc.inc.php';
387
08cce2ff 388 $res = XDB::query(
2f678da1 389 "SELECT u.promo, u.promo_sortie
9b0fa329 390 FROM auth_user_md5 AS u
cab08090 391 WHERE user_id={?}", S::v('uid'));
9b0fa329 392
2f678da1 393 list($promo, $promo_sortie_old) = $res->fetchOneRow();
9b0fa329 394 $page->assign('promo_sortie_old', $promo_sortie_old);
395 $page->assign('promo', $promo);
396
397 if (!Env::has('promo_sortie')) {
fd8f77de 398 return;
9b0fa329 399 }
400
5e2307dc 401 $promo_sortie = Env::i('promo_sortie');
9b0fa329 402
403 if ($promo_sortie < 1000 || $promo_sortie > 9999) {
a7de4ef7 404 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
9b0fa329 405 }
406 elseif ($promo_sortie < $promo + 3) {
a7de4ef7 407 $page->trig('Trop tôt');
9b0fa329 408 }
409 elseif ($promo_sortie == $promo_sortie_old) {
a7de4ef7 410 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
9b0fa329 411 }
412 elseif ($promo_sortie == $promo + 3) {
08cce2ff 413 XDB::execute(
9b0fa329 414 "UPDATE auth_user_md5 set promo_sortie={?}
cab08090 415 WHERE user_id={?}", $promo_sortie, S::v('uid'));
a7de4ef7 416 $page->trig('Ton statut "orange" a été supprimé.');
9b0fa329 417 $page->assign('promo_sortie_old', $promo_sortie);
418 }
419 else {
420 $page->assign('promo_sortie', $promo_sortie);
421
422 if (Env::has('submit')) {
cab08090 423 $myorange = new OrangeReq(S::v('uid'),
9b0fa329 424 $promo_sortie);
425 $myorange->submit();
426 $page->assign('myorange', $myorange);
427 }
428 }
9b0fa329 429 }
430
2f678da1 431 function handler_referent(&$page, $x = null)
28e16d4d 432 {
28e16d4d 433 require_once 'user.func.inc.php';
434
435 if (is_null($x)) {
436 return PL_NOT_FOUND;
437 }
438
8b1f8e12 439 $page->changeTpl('profile/fiche_referent.tpl', SIMPLE);
28e16d4d 440
08cce2ff 441 $res = XDB::query(
28e16d4d 442 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
443 FROM auth_user_md5 AS u
2f678da1 444 INNER JOIN aliases AS a ON (u.user_id=a.id
445 AND FIND_IN_SET('bestalias', a.flags))
28e16d4d 446 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
447 AND a1.alias = {?}
448 AND a1.type!='homonyme')", $x);
449
450 if ($res->numRows() != 1) {
451 return PL_NOT_FOUND;
452 }
453
454 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
455
456 $page->assign('prenom', $prenom);
457 $page->assign('nom', $nom);
458 $page->assign('promo', $promo);
459 $page->assign('cv', $cv);
460 $page->assign('bestalias', $bestalias);
461 $page->assign('adr_pro', get_user_details_pro($user_id));
462
463 ///// recuperations infos referent
464
465 //expertise
08cce2ff 466 $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
28e16d4d 467 $page->assign('expertise', $res->fetchOneCell());
468
469 //secteurs
470 $secteurs = $ss_secteurs = Array();
08cce2ff 471 $res = XDB::iterRow(
28e16d4d 472 "SELECT s.label, ss.label
473 FROM mentor_secteurs AS m
474 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
475 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
476 WHERE uid = {?}", $user_id);
477 while (list($sec, $ssec) = $res->next()) {
478 $secteurs[] = $sec;
479 $ss_secteurs[] = $ssec;
480 }
481 $page->assign_by_ref('secteurs', $secteurs);
482 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
483
484 //pays
08cce2ff 485 $res = XDB::query(
28e16d4d 486 "SELECT gp.pays
487 FROM mentor_pays AS m
488 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
489 WHERE uid = {?}", $user_id);
490 $page->assign('pays', $res->fetchColumn());
491
c99ef281 492 $page->addJsLink('close_on_esc.js');
28e16d4d 493 }
494
ff3eb9b7 495 function handler_ref_search(&$page, $action = null, $subaction = null)
2f678da1 496 {
f5c5b741 497 require_once 'wiki.inc.php';
498 wiki_require_page('Docs.Emploi');
2f678da1 499 $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro');
500
2f678da1 501 //recuperation des noms de secteurs
08cce2ff 502 $res = XDB::iterRow("SELECT id, label FROM emploi_secteur");
2f678da1 503 $secteurs[''] = '';
504 while (list($tmp_id, $tmp_label) = $res->next()) {
505 $secteurs[$tmp_id] = $tmp_label;
506 }
507 $page->assign_by_ref('secteurs', $secteurs);
508
2f678da1 509 // nb de mentors
08cce2ff 510 $res = XDB::query("SELECT count(*) FROM mentor");
2f678da1 511 $page->assign('mentors_number', $res->fetchOneCell());
512
2f678da1 513 // On vient d'un formulaire
ff3eb9b7 514 $where = array();
515 $pays_sel = XDB::escape(Env::v('pays_sel'));
516 $secteur_sel = XDB::escape(Env::v('secteur'));
517 $ss_secteur_sel = XDB::escape(Env::v('ss_secteur'));
518 $expertise_champ = XDB::escape(Env::v('expertise'));
519
520 if ($pays_sel != "''") {
521 $where[] = "mp.pid = $pays_sel";
522 }
523 if ($secteur_sel != "''") {
524 $where[] = "ms.secteur = $secteur_sel";
525 if ($ss_secteur_sel != "''") {
526 $where[] = "ms.ss_secteur = $ss_secteur_sel";
2f678da1 527 }
528 }
ff3eb9b7 529 if ($expertise_champ != "''") {
530 $where[] = "MATCH(m.expertise) AGAINST($expertise_champ)";
2f678da1 531 }
532
533 if ($where) {
534 $where = join(' AND ', $where);
535
ff3eb9b7 536 $set = new UserSet("INNER JOIN mentor AS m ON (m.uid = u.user_id)
537 LEFT JOIN mentor_pays AS mp ON (mp.uid = m.uid)
538 LEFT JOIN mentor_secteurs AS ms ON (ms.uid = m.uid)",
539 $where);
540 $set->addMod('mentor', 'Référents');
541 $set->apply('referent/search', $page, $action, $subaction);
542 if ($set->count() > 100) {
543 $page->assign('recherche_trop_large', true);
2f678da1 544 }
ff3eb9b7 545 }
546 $page->changeTpl('profile/referent.tpl');
547 }
2f678da1 548
ff3eb9b7 549 function handler_ref_sect(&$page, $sect)
550 {
551 header('Content-Type: text/html; charset=utf-8');
552 $page->changeTpl('include/select.field.tpl', NO_SKIN);
553 $page->assign('onchange', 'setSSecteurs()');
554 $page->assign('id', 'ssect_field');
555 $page->assign('name', 'ss_secteur');
556 $it = XDB::iterator("SELECT id,label AS field
557 FROM emploi_ss_secteur
558 WHERE secteur = {?}", $sect);
559 $page->assign('list', $it);
560 }
2f678da1 561
ff3eb9b7 562 function handler_ref_country(&$page, $sect, $ssect = '')
563 {
564 header('Content-Type: text/html; charset=utf-8');
565 $page->changeTpl('include/select.field.tpl', NO_SKIN);
566 $page->assign('name', 'pays_sel');
567 $where = ($ssect ? ' AND ms.ss_secteur = {?}' : '');
568 $it = XDB::iterator("SELECT a2 AS id, pays AS field
569 FROM geoloc_pays AS g
570 INNER JOIN mentor_pays AS mp ON (mp.pid = g.a2)
571 INNER JOIN mentor_secteurs AS ms ON (ms.uid = mp.uid)
572 WHERE ms.secteur = {?} $where
573 GROUP BY a2
574 ORDER BY pays", $sect, $ssect);
575 $page->assign('list', $it);
2f678da1 576 }
577
926f16d7 578 function handler_p_usage(&$page)
579 {
8b1f8e12 580 $page->changeTpl('profile/nomusage.tpl');
926f16d7 581
582 require_once 'validations.inc.php';
583 require_once 'xorg.misc.inc.php';
584
08cce2ff 585 $res = XDB::query(
2f678da1 586 "SELECT u.nom, u.nom_usage, u.flags, e.alias
926f16d7 587 FROM auth_user_md5 AS u
2f678da1 588 LEFT JOIN aliases AS e ON(u.user_id = e.id
589 AND FIND_IN_SET('usage', e.flags))
cab08090 590 WHERE user_id={?}", S::v('uid'));
926f16d7 591
2f678da1 592 list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow();
926f16d7 593 $flags = new flagset($flags);
594 $page->assign('usage_old', $usage_old);
595 $page->assign('alias_old', $alias_old);
596
5e2307dc 597 $nom_usage = replace_accent(trim(Env::v('nom_usage')));
926f16d7 598 $nom_usage = strtoupper($nom_usage);
599 $page->assign('usage_req', $nom_usage);
600
601 if (Env::has('submit') && ($nom_usage != $usage_old)) {
602 // on vient de recevoir une requete, differente de l'ancien nom d'usage
603 if ($nom_usage == $nom) {
604 $page->assign('same', true);
a7de4ef7 605 } else { // le nom de mariage est distinct du nom à l'X
926f16d7 606 // on calcule l'alias pour l'afficher
5e2307dc 607 $reason = Env::v('reason');
926f16d7 608 if ($reason == 'other') {
5e2307dc 609 $reason = Env::v('other_reason');
926f16d7 610 }
cab08090 611 $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason);
926f16d7 612 $myusage->submit();
613 $page->assign('myusage', $myusage);
614 }
615 }
926f16d7 616 }
617
a1d79217 618 function handler_xnet(&$page)
619 {
8b1f8e12 620 $page->changeTpl('profile/groupesx.tpl');
a1d79217 621 $page->assign('xorg_title', 'Polytechnique.org - Promo, Groupes X, Binets');
622
623 $req = XDB::query('
46e1d3ba 624 SELECT m.asso_id, a.nom, diminutif, a.logo IS NOT NULL AS has_logo,
625 COUNT(e.eid) AS events, mail_domain AS lists
626 FROM groupex.membres AS m
627 INNER JOIN groupex.asso AS a ON(m.asso_id = a.id)
628 LEFT JOIN groupex.evenements AS e ON(e.asso_id = m.asso_id AND e.archive = 0)
629 WHERE uid = {?} GROUP BY m.asso_id ORDER BY a.nom', S::i('uid'));
a1d79217 630 $page->assign('assos', $req->fetchAllAssoc());
631 }
632
e49018a7 633 function handler_vcard(&$page, $x = null)
634 {
635 if (is_null($x)) {
636 return PL_NOT_FOUND;
637 }
638
639 global $globals;
640
641 if (substr($x, -4) == '.vcf') {
642 $x = substr($x, 0, strlen($x) - 4);
643 }
644
5e193297 645 $vcard = new VCard($x);
646 $vcard->do_page($page);
e49018a7 647 }
92423144 648
649 function handler_admin_trombino(&$page, $uid = null, $action = null) {
8b1f8e12 650 $page->changeTpl('profile/admin_trombino.tpl');
92423144 651 $page->assign('xorg_title','Polytechnique.org - Administration - Trombino');
652 $page->assign('uid', $uid);
653
654 $q = XDB::query(
655 "SELECT a.alias,promo
656 FROM auth_user_md5 AS u
657 INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' )
658 WHERE user_id = {?}", $uid);
659 list($forlife, $promo) = $q->fetchOneRow();
660
661 switch ($action) {
662
663 case "original":
664 header("Content-type: image/jpeg");
665 readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg");
666 exit;
667 break;
668
669 case "new":
670 $data = file_get_contents($_FILES['userfile']['tmp_name']);
671 list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']);
672 $mimetype = substr($_FILES['userfile']['type'], 6);
673 unlink($_FILES['userfile']['tmp_name']);
674 XDB::execute(
675 "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}",
676 $uid, $mimetype, $data, $x, $y);
677 break;
678
679 case "delete":
680 XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid);
681 break;
682 }
683
684 $page->assign('forlife', $forlife);
685 }
686 function handler_admin_binets(&$page, $action = 'list', $id = null) {
92423144 687 $page->assign('xorg_title','Polytechnique.org - Administration - Binets');
688 $page->assign('title', 'Gestion des binets');
689 $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id');
690 $table_editor->add_join_table('binets_ins','binet_id',true);
a7de4ef7 691 $table_editor->describe('text','intitulé',true);
92423144 692 $table_editor->apply($page, $action, $id);
693 }
694 function handler_admin_formations(&$page, $action = 'list', $id = null) {
92423144 695 $page->assign('xorg_title','Polytechnique.org - Administration - Formations');
696 $page->assign('title', 'Gestion des formations');
697 $table_editor = new PLTableEditor('admin/formations','applis_def','id');
698 $table_editor->add_join_table('applis_ins','aid',true);
a7de4ef7 699 $table_editor->describe('text','intitulé',true);
92423144 700 $table_editor->describe('url','site web',false);
701 $table_editor->apply($page, $action, $id);
702 }
703 function handler_admin_groupesx(&$page, $action = 'list', $id = null) {
92423144 704 $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X');
705 $page->assign('title', 'Gestion des Groupes X');
706 $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id');
707 $table_editor->add_join_table('groupesx_ins','gid',true);
a7de4ef7 708 $table_editor->describe('text','intitulé',true);
92423144 709 $table_editor->describe('url','site web',false);
710 $table_editor->apply($page, $action, $id);
711 }
b09690be 712 function handler_admin_sections(&$page, $action = 'list', $id = null) {
713 $page->assign('xorg_title','Polytechnique.org - Administration - Sections');
714 $page->assign('title', 'Gestion des Sections');
715 $table_editor = new PLTableEditor('admin/sections','sections','id');
716 $table_editor->describe('text','intitulé',true);
717 $table_editor->apply($page, $action, $id);
718 }
719 function handler_admin_secteurs(&$page, $action = 'list', $id = null) {
720 $page->assign('xorg_title','Polytechnique.org - Administration - Secteurs');
721 $page->assign('title', 'Gestion des Secteurs');
722 $table_editor = new PLTableEditor('admin/secteurs','emploi_secteur','id');
723 $table_editor->describe('label','intitulé',true);
724 $table_editor->apply($page, $action, $id);
725 }
92423144 726 function handler_admin_medals(&$page, $action = 'list', $id = null) {
92423144 727 $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions');
728 $page->assign('title', 'Gestion des Distinctions');
729 $table_editor = new PLTableEditor('admin/medals','profile_medals','id');
a7de4ef7 730 $table_editor->describe('text', 'intitulé', true);
92423144 731 $table_editor->describe('img', 'nom de l\'image', false);
d02b8359 732 $table_editor->describe('flags', 'valider', true);
92423144 733 $table_editor->apply($page, $action, $id);
734 if ($id && $action == 'edit') {
8b1f8e12 735 $page->changeTpl('profile/admin_decos.tpl');
92423144 736
737 $mid = $id;
738
739 if (Post::v('act') == 'del') {
740 XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid'));
741 } elseif (Post::v('act') == 'new') {
742 XDB::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})',
743 $mid, max(array_keys(Post::v('grades', array(0))))+1);
744 } else {
745 foreach (Post::v('grades', array()) as $gid=>$text) {
746 XDB::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid);
747 }
748 }
749 $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid);
750 $page->assign('grades', $res);
751 }
752 }
7d8b17cb 753}
754
a7de4ef7 755// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
7d8b17cb 756?>