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