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