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