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