7d8b17cb |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
22 | class 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), |
2f678da1 |
32 | 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), |
28e16d4d |
33 | 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), |
28e16d4d |
34 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
e49018a7 |
35 | |
2f678da1 |
36 | 'referent' => $this->make_hook('referent', AUTH_COOKIE), |
37 | 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE), |
38 | |
28e16d4d |
39 | 'trombi' => $this->make_hook('trombi', AUTH_COOKIE), |
926f16d7 |
40 | |
28e16d4d |
41 | 'vcard' => $this->make_hook('vcard', AUTH_COOKIE), |
7d8b17cb |
42 | ); |
43 | } |
44 | |
e8599c21 |
45 | /* XXX COMPAT */ |
46 | function handler_fiche(&$page) |
47 | { |
48 | return $this->handler_profile($page, Env::get('user')); |
49 | } |
50 | |
51 | |
7d8b17cb |
52 | function _trombi_getlist($offset, $limit) |
53 | { |
54 | global $globals; |
55 | |
56 | $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" ); |
57 | |
58 | $res = $globals->xdb->query( |
59 | "SELECT COUNT(*) |
60 | FROM auth_user_md5 AS u |
61 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
62 | $where"); |
63 | $pnb = $res->fetchOneCell(); |
64 | |
65 | $res = $globals->xdb->query( |
2f678da1 |
66 | "SELECT promo, user_id, a.alias AS forlife, |
67 | IF (nom_usage='', nom, nom_usage) AS nom, prenom |
7d8b17cb |
68 | FROM photo AS p |
69 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
70 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
71 | $where |
2f678da1 |
72 | ORDER BY promo, nom, prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
7d8b17cb |
73 | |
74 | return array($pnb, $res->fetchAllAssoc()); |
75 | } |
76 | |
adbdf493 |
77 | function handler_photo(&$page, $x = null, $req = null) |
78 | { |
79 | if (is_null($x)) { |
80 | return PL_NOT_FOUND; |
81 | } |
82 | |
83 | global $globals; |
84 | |
85 | $res = $globals->xdb->query("SELECT id, pub FROM aliases |
86 | LEFT JOIN photo ON(id = uid) |
87 | WHERE alias = {?}", $x); |
88 | list($uid, $photo_pub) = $res->fetchOneRow(); |
89 | |
90 | if ($req && logged()) { |
91 | include 'validations.inc.php'; |
92 | $myphoto = PhotoReq::get_request($uid); |
93 | Header('Content-type: image/'.$myphoto->mimetype); |
94 | echo $myphoto->data; |
95 | } else { |
96 | $res = $globals->xdb->query( |
97 | "SELECT attachmime, attach |
98 | FROM photo |
99 | WHERE uid={?}", $uid); |
100 | |
2f678da1 |
101 | if ((list($type, $data) = $res->fetchOneRow()) |
102 | && ($photo_pub == 'public' || logged())) { |
adbdf493 |
103 | Header("Content-type: image/$type"); |
104 | echo $data; |
105 | } else { |
106 | Header('Content-type: image/png'); |
fb9a56cb |
107 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
adbdf493 |
108 | } |
109 | } |
110 | exit; |
111 | } |
112 | |
fb9a56cb |
113 | function handler_photo_change(&$page) |
114 | { |
115 | global $globals; |
116 | |
117 | $page->changeTpl('trombino.tpl'); |
118 | |
119 | require_once('validations.inc.php'); |
120 | |
121 | $trombi_x = '/home/web/trombino/photos'.Session::get('promo') |
122 | .'/'.Session::get('forlife').'.jpg'; |
123 | |
124 | if (Env::has('upload')) { |
125 | $file = isset($_FILES['userfile']['tmp_name']) |
126 | ? $_FILES['userfile']['tmp_name'] |
127 | : Env::get('photo'); |
128 | if ($data = file_get_contents($file)) { |
129 | if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) { |
130 | $myphoto->submit(); |
131 | } |
132 | } else { |
133 | $page->trig('Fichier inexistant ou vide'); |
134 | } |
135 | } elseif (Env::has('trombi')) { |
136 | $myphoto = new PhotoReq(Session::getInt('uid'), |
137 | file_get_contents($trombi_x)); |
138 | if ($myphoto) { |
139 | $myphoto->commit(); |
140 | $myphoto->clean(); |
141 | } |
142 | } elseif (Env::get('suppr')) { |
143 | $globals->xdb->execute('DELETE FROM photo WHERE uid = {?}', |
144 | Session::getInt('uid')); |
145 | $globals->xdb->execute('DELETE FROM requests |
146 | WHERE user_id = {?} AND type="photo"', |
147 | Session::getInt('uid')); |
148 | } elseif (Env::get('cancel')) { |
149 | $sql = $globals->xdb->query('DELETE FROM requests |
150 | WHERE user_id={?} AND type="photo"', |
151 | Session::getInt('uid')); |
152 | } |
153 | |
154 | $sql = $globals->xdb->query('SELECT COUNT(*) FROM requests |
155 | WHERE user_id={?} AND type="photo"', |
156 | Session::getInt('uid')); |
157 | $page->assign('submited', $sql->fetchOneCell()); |
158 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
159 | |
160 | return PL_OK; |
161 | } |
162 | |
e8599c21 |
163 | function handler_profile(&$page, $x = null) |
164 | { |
165 | if (is_null($x)) { |
166 | return PL_NOT_FOUND; |
167 | } |
168 | |
169 | global $globals; |
170 | require_once 'user.func.inc.php'; |
171 | |
172 | $page->changeTpl('fiche.tpl'); |
173 | $page->assign('simple', true); |
174 | |
175 | $view = 'private'; |
176 | if (!logged() || Env::get('view') == 'public') $view = 'public'; |
177 | if (logged() && Env::get('view') == 'ax') $view = 'ax'; |
178 | |
179 | if (is_numeric($x)) { |
180 | $res = $globals->xdb->query( |
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)) { |
191 | return PL_NOT_FOUND; |
192 | } |
193 | |
194 | $new = Env::get('modif') == 'new'; |
195 | $user = get_user_details($login, Session::getInt('uid'), $view); |
196 | $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; |
197 | $page->assign('xorg_title', $title); |
198 | |
199 | // photo |
200 | |
201 | $photo = $globals->baseurl.'/photo/'.$user['forlife'].($new ? '/req' : ''); |
202 | |
2f678da1 |
203 | if (!isset($user['y']) and !isset($user['x'])) { |
e8599c21 |
204 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
205 | } |
2f678da1 |
206 | if (!isset($user['y']) or $user['y'] < 1) $user['y']=1; |
207 | if (!isset($user['x']) or $user['x'] < 1) $user['x']=1; |
208 | if ($user['x'] > 240) { |
e8599c21 |
209 | $user['y'] = (integer)($user['y']*240/$user['x']); |
210 | $user['x'] = 240; |
211 | } |
2f678da1 |
212 | if ($user['y'] > 300) { |
e8599c21 |
213 | $user['x'] = (integer)($user['x']*300/$user['y']); |
214 | $user['y'] = 300; |
215 | } |
2f678da1 |
216 | if ($user['x'] < 160) { |
e8599c21 |
217 | $user['y'] = (integer)($user['y']*160/$user['x']); |
218 | $user['x'] = 160; |
219 | } |
220 | |
221 | $page->assign('logged', has_user_right('private', $view)); |
222 | if (!has_user_right($user['photo_pub'], $view)) { |
223 | $photo = ""; |
224 | } |
225 | |
226 | $page->assign_by_ref('x', $user); |
227 | $page->assign('photo_url', $photo); |
228 | // alias virtual |
229 | $res = $globals->xdb->query( |
230 | "SELECT alias |
231 | FROM virtual |
232 | INNER JOIN virtual_redirect USING(vid) |
233 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
234 | WHERE ( redirect={?} OR redirect={?} ) |
235 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
236 | Session::getInt('uid'), |
237 | $user['forlife'].'@'.$globals->mail->domain, |
238 | $user['forlife'].'@'.$globals->mail->domain2); |
239 | $page->assign('virtualalias', $res->fetchOneCell()); |
240 | |
241 | $page->addJsLink('javascript/close_on_esc.js'); |
242 | |
243 | return PL_OK; |
244 | } |
245 | |
2f678da1 |
246 | function handler_p_edit(&$page, $opened_tab = 'general') |
247 | { |
248 | global $globals; |
249 | |
250 | $page->changeTpl('profil.tpl'); |
251 | |
252 | $page->addCssLink('css/profil.css'); |
253 | $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); |
254 | |
255 | require_once 'tabs.inc.php'; |
256 | require_once 'profil.func.inc.php'; |
257 | require_once 'synchro_ax.inc.php'; |
258 | |
259 | if (Post::has('register_from_ax_question')) { |
260 | $globals->xdb->query('UPDATE auth_user_quick |
261 | SET profile_from_ax = 1 |
262 | WHERE user_id = {?}', |
263 | Session::getInt('uid')); |
264 | } |
265 | |
266 | if (is_ax_key_missing()) { |
267 | $page->assign('no_private_key', true); |
268 | } |
269 | |
270 | if (Env::get('synchro_ax') == 'confirm' && !is_ax_key_missing()) { |
271 | ax_synchronize(Session::get('bestalias'), Session::getInt('uid')); |
272 | $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com'); |
273 | } |
274 | |
275 | // pour tous les tabs, la date de naissance pour verifier |
276 | // quelle est bien rentree et la date. |
277 | $res = $globals->xdb->query( |
278 | "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y') |
279 | FROM auth_user_md5 |
280 | WHERE user_id={?}", Session::getInt('uid')); |
281 | list($naissance, $date_modif_profil) = $res->fetchOneRow(); |
282 | |
283 | // lorsqu'on n'a pas la date de naissance en base de données |
284 | if (!$naissance) { |
285 | // la date de naissance n'existait pas et vient d'être soumise dans la variable |
286 | if (Env::has('birth')) { |
287 | //en cas d'erreur : |
288 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::get('birth'))) { |
289 | $page->assign('etat_naissance', 'query'); |
290 | $page->trig('Date de naissance incorrecte ou incohérente.'); |
291 | return PL_OK; |
292 | } |
293 | |
294 | //sinon |
295 | $birth = sprintf("%s-%s-%s", substr(Env::get('birth'), 4, 4), |
296 | substr(Env::get('birth'), 2, 2), |
297 | substr(Env::get('birth'), 0, 2)); |
298 | $globals->xdb->execute("UPDATE auth_user_md5 |
299 | SET naissance={?} |
300 | WHERE user_id={?}", $birth, |
301 | Session::getInt('uid')); |
302 | $page->assign('etat_naissance', 'ok'); |
303 | return PL_OK; |
304 | } |
305 | |
306 | $page->assign('etat_naissance', 'query'); |
307 | return PL_OK; // on affiche le formulaire pour naissance |
308 | } |
309 | |
310 | //doit-on faire un update ? |
311 | if (Env::has('modifier') || Env::has('suivant')) { |
312 | require_once "profil/get_{$opened_tab}.inc.php"; |
313 | require_once "profil/verif_{$opened_tab}.inc.php"; |
314 | |
315 | if($page->nb_errs()) { |
316 | require_once "profil/assign_{$opened_tab}.inc.php"; |
317 | $page->assign('onglet', $opened_tab); |
318 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
319 | return PL_OK; |
320 | } |
321 | |
322 | $date=date("Y-m-j");//nouvelle date de mise a jour |
323 | |
324 | //On sauvegarde l'uid pour l'AX |
325 | /* on sauvegarde les changements dans user_changes : |
326 | * on a juste besoin d'insérer le user_id de la personne dans la table |
327 | */ |
328 | $globals->xdb->execute('REPLACE INTO user_changes SET user_id={?}', |
329 | Session::getInt('uid')); |
330 | |
331 | if (!Session::has('suid')) { |
332 | require_once 'notifs.inc.php'; |
333 | register_watch_op(Session::getInt('uid'), WATCH_FICHE); |
334 | } |
335 | |
336 | // mise a jour des champs relatifs au tab ouvert |
337 | require_once "profil/update_{$opened_tab}.inc.php"; |
338 | |
339 | $log =& Session::getMixed('log'); |
340 | $log->log('profil', $opened_tab); |
341 | $page->assign('etat_update', 'ok'); |
342 | } |
343 | |
344 | if (Env::has('suivant')) { |
345 | redirect($globals->baseurl . '/profile/edit/' . |
346 | get_next_tab($opened_tab)); |
347 | } |
348 | |
349 | require_once "profil/get_{$opened_tab}.inc.php"; |
350 | require_once "profil/verif_{$opened_tab}.inc.php"; |
351 | require_once "profil/assign_{$opened_tab}.inc.php"; |
352 | |
353 | $page->assign('onglet', $opened_tab); |
354 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
355 | |
356 | return PL_OK; |
357 | } |
358 | |
9b0fa329 |
359 | function handler_p_orange(&$page) |
360 | { |
361 | global $globals; |
362 | |
363 | $page->changeTpl('orange.tpl'); |
364 | |
365 | require_once 'validations.inc.php'; |
366 | require_once 'xorg.misc.inc.php'; |
367 | |
368 | $res = $globals->xdb->query( |
2f678da1 |
369 | "SELECT u.promo, u.promo_sortie |
9b0fa329 |
370 | FROM auth_user_md5 AS u |
371 | WHERE user_id={?}", Session::getInt('uid')); |
372 | |
2f678da1 |
373 | list($promo, $promo_sortie_old) = $res->fetchOneRow(); |
9b0fa329 |
374 | $page->assign('promo_sortie_old', $promo_sortie_old); |
375 | $page->assign('promo', $promo); |
376 | |
377 | if (!Env::has('promo_sortie')) { |
378 | return PL_OK; |
379 | } |
380 | |
381 | $promo_sortie = Env::getInt('promo_sortie'); |
382 | |
383 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
384 | $page->trig('L\'année de sortie doit être un nombre de quatre chiffres'); |
385 | } |
386 | elseif ($promo_sortie < $promo + 3) { |
387 | $page->trig('Trop tôt'); |
388 | } |
389 | elseif ($promo_sortie == $promo_sortie_old) { |
390 | $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.'); |
391 | } |
392 | elseif ($promo_sortie == $promo + 3) { |
393 | $globals->xdb->execute( |
394 | "UPDATE auth_user_md5 set promo_sortie={?} |
2f678da1 |
395 | WHERE user_id={?}", $promo_sortie, Session::getInt('uid')); |
9b0fa329 |
396 | $page->trig('Ton statut "orange" a été supprimé.'); |
397 | $page->assign('promo_sortie_old', $promo_sortie); |
398 | } |
399 | else { |
400 | $page->assign('promo_sortie', $promo_sortie); |
401 | |
402 | if (Env::has('submit')) { |
403 | $myorange = new OrangeReq(Session::getInt('uid'), |
404 | $promo_sortie); |
405 | $myorange->submit(); |
406 | $page->assign('myorange', $myorange); |
407 | } |
408 | } |
409 | |
410 | return PL_OK; |
411 | } |
412 | |
2f678da1 |
413 | function handler_referent(&$page, $x = null) |
28e16d4d |
414 | { |
415 | global $globals; |
416 | |
417 | require_once 'user.func.inc.php'; |
418 | |
419 | if (is_null($x)) { |
420 | return PL_NOT_FOUND; |
421 | } |
422 | |
423 | $page->changeTpl('fiche_referent.tpl'); |
424 | $page->assign('simple', true); |
425 | |
426 | $res = $globals->xdb->query( |
427 | "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias |
428 | FROM auth_user_md5 AS u |
2f678da1 |
429 | INNER JOIN aliases AS a ON (u.user_id=a.id |
430 | AND FIND_IN_SET('bestalias', a.flags)) |
28e16d4d |
431 | INNER JOIN aliases AS a1 ON (u.user_id=a1.id |
432 | AND a1.alias = {?} |
433 | AND a1.type!='homonyme')", $x); |
434 | |
435 | if ($res->numRows() != 1) { |
436 | return PL_NOT_FOUND; |
437 | } |
438 | |
439 | list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow(); |
440 | |
441 | $page->assign('prenom', $prenom); |
442 | $page->assign('nom', $nom); |
443 | $page->assign('promo', $promo); |
444 | $page->assign('cv', $cv); |
445 | $page->assign('bestalias', $bestalias); |
446 | $page->assign('adr_pro', get_user_details_pro($user_id)); |
447 | |
448 | ///// recuperations infos referent |
449 | |
450 | //expertise |
451 | $res = $globals->xdb->query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id); |
452 | $page->assign('expertise', $res->fetchOneCell()); |
453 | |
454 | //secteurs |
455 | $secteurs = $ss_secteurs = Array(); |
456 | $res = $globals->xdb->iterRow( |
457 | "SELECT s.label, ss.label |
458 | FROM mentor_secteurs AS m |
459 | LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) |
460 | LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id) |
461 | WHERE uid = {?}", $user_id); |
462 | while (list($sec, $ssec) = $res->next()) { |
463 | $secteurs[] = $sec; |
464 | $ss_secteurs[] = $ssec; |
465 | } |
466 | $page->assign_by_ref('secteurs', $secteurs); |
467 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
468 | |
469 | //pays |
470 | $res = $globals->xdb->query( |
471 | "SELECT gp.pays |
472 | FROM mentor_pays AS m |
473 | LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2) |
474 | WHERE uid = {?}", $user_id); |
475 | $page->assign('pays', $res->fetchColumn()); |
476 | |
477 | $page->addJsLink('javascript/close_on_esc.js'); |
478 | return PL_OK; |
479 | } |
480 | |
2f678da1 |
481 | function handler_ref_search(&$page) |
482 | { |
483 | global $globals; |
484 | |
485 | $page->changeTpl('referent.tpl'); |
486 | |
487 | $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro'); |
488 | |
489 | $secteur_sel = Post::get('secteur'); |
490 | $ss_secteur_sel = Post::get('ss_secteur'); |
491 | $pays_sel = Post::get('pays', '00'); |
492 | $expertise_champ = Post::get('expertise'); |
493 | |
494 | $page->assign('pays_sel', $pays_sel); |
495 | $page->assign('expertise_champ', $expertise_champ); |
496 | $page->assign('secteur_sel', $secteur_sel); |
497 | $page->assign('ss_secteur_sel', $ss_secteur_sel); |
498 | |
499 | //recuperation des noms de secteurs |
500 | $res = $globals->xdb->iterRow("SELECT id, label FROM emploi_secteur"); |
501 | $secteurs[''] = ''; |
502 | while (list($tmp_id, $tmp_label) = $res->next()) { |
503 | $secteurs[$tmp_id] = $tmp_label; |
504 | } |
505 | $page->assign_by_ref('secteurs', $secteurs); |
506 | |
507 | //on recupere les sous-secteurs si necessaire |
508 | $ss_secteurs[''] = ''; |
509 | if (!empty($secteur_sel)) { |
510 | $res = $globals->xdb->iterRow("SELECT id, label FROM emploi_ss_secteur |
511 | WHERE secteur = {?}", $secteur_sel); |
512 | while (list($tmp_id, $tmp_label) = $res->next()) { |
513 | $ss_secteurs[$tmp_id] = $tmp_label; |
514 | } |
515 | } |
516 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
517 | |
518 | //recuperation des noms de pays |
519 | $res = $globals->xdb->iterRow("SELECT a2, pays FROM geoloc_pays |
520 | WHERE pays <> '' ORDER BY pays"); |
521 | $pays['00'] = ''; |
522 | while (list($tmp_id, $tmp_label) = $res->next()) { |
523 | $pays[$tmp_id] = $tmp_label; |
524 | } |
525 | $page->assign_by_ref('pays', $pays); |
526 | |
527 | // nb de mentors |
528 | $res = $globals->xdb->query("SELECT count(*) FROM mentor"); |
529 | $page->assign('mentors_number', $res->fetchOneCell()); |
530 | |
531 | if (!Env::has('Chercher')) { |
532 | return PL_OK; |
533 | } |
534 | |
535 | // On vient d'un formulaire |
536 | $where = array(); |
537 | |
538 | if ($pays_sel != '00') { |
539 | $where[] = "mp.pid = '".addslashes($pays_sel)."'"; |
540 | } |
541 | if ($secteur_sel) { |
542 | $where[] = "ms.secteur = '".addslashes($secteur_sel)."'"; |
543 | if ($ss_secteur_sel) { |
544 | $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'"; |
545 | } |
546 | } |
547 | if ($expertise_champ) { |
548 | $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')"; |
549 | } |
550 | |
551 | if ($where) { |
552 | $where = join(' AND ', $where); |
553 | |
554 | $sql = "SELECT m.uid, a.prenom, a.nom, a.promo, |
555 | l.alias AS bestalias, m.expertise, mp.pid, |
556 | ms.secteur, ms.ss_secteur |
557 | FROM mentor AS m |
558 | LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id) |
559 | INNER JOIN aliases AS l ON (a.user_id=l.id AND |
560 | FIND_IN_SET('bestalias', l.flags)) |
561 | LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid) |
562 | LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid) |
563 | WHERE $where |
564 | GROUP BY uid |
565 | ORDER BY RAND({?})"; |
566 | $res = $globals->xdb->iterator($sql, Session::getInt('uid')); |
567 | |
568 | if ($res->total() == 0) { |
569 | $page->assign('recherche_trop_large', true); |
570 | return PL_OK; |
571 | } |
572 | |
573 | $nb_max_res_total = 100; |
574 | $nb_max_res_ppage = 10; |
575 | |
576 | $curpage = Env::getInt('curpage', 1); |
577 | $personnes = array(); |
578 | $i = 0; |
579 | |
580 | while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) { |
581 | $the_page = intval($i / $nb_max_res_ppage) + 1; |
582 | if ($the_page == $curpage) { |
583 | $personnes[] = $pers; |
584 | } |
585 | $i ++; |
586 | } |
587 | |
588 | $page->assign('personnes', $personnes); |
589 | $page->assign('curpage', $curpage); |
590 | $page->assign('nb_pages_total', |
591 | intval($res->total() / $nb_max_res_ppage) + 1); |
592 | } |
593 | |
594 | return PL_OK; |
595 | } |
596 | |
926f16d7 |
597 | function handler_p_usage(&$page) |
598 | { |
599 | global $globals; |
600 | |
601 | $page->changeTpl('nomusage.tpl'); |
602 | |
603 | require_once 'validations.inc.php'; |
604 | require_once 'xorg.misc.inc.php'; |
605 | |
606 | $res = $globals->xdb->query( |
2f678da1 |
607 | "SELECT u.nom, u.nom_usage, u.flags, e.alias |
926f16d7 |
608 | FROM auth_user_md5 AS u |
2f678da1 |
609 | LEFT JOIN aliases AS e ON(u.user_id = e.id |
610 | AND FIND_IN_SET('usage', e.flags)) |
926f16d7 |
611 | WHERE user_id={?}", Session::getInt('uid')); |
612 | |
2f678da1 |
613 | list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow(); |
926f16d7 |
614 | $flags = new flagset($flags); |
615 | $page->assign('usage_old', $usage_old); |
616 | $page->assign('alias_old', $alias_old); |
617 | |
618 | $nom_usage = replace_accent(trim(Env::get('nom_usage'))); |
619 | $nom_usage = strtoupper($nom_usage); |
620 | $page->assign('usage_req', $nom_usage); |
621 | |
622 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
623 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
624 | if ($nom_usage == $nom) { |
625 | $page->assign('same', true); |
9b0fa329 |
626 | } else { // le nom de mariage est distinct du nom à l'X |
926f16d7 |
627 | // on calcule l'alias pour l'afficher |
628 | $reason = Env::get('reason'); |
629 | if ($reason == 'other') { |
630 | $reason = Env::get('other_reason'); |
631 | } |
632 | $myusage = new UsageReq(Session::getInt('uid'), $nom_usage, $reason); |
633 | $myusage->submit(); |
634 | $page->assign('myusage', $myusage); |
635 | } |
636 | } |
637 | |
638 | return PL_OK; |
639 | } |
640 | |
7d8b17cb |
641 | function handler_trombi(&$page, $promo = null) |
642 | { |
643 | require_once 'trombi.inc.php'; |
644 | |
645 | $page->changeTpl('trombipromo.tpl'); |
2f678da1 |
646 | $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo'); |
7d8b17cb |
647 | |
648 | if (is_null($promo)) { |
649 | return PL_OK; |
650 | } |
651 | |
652 | $this->promo = $promo = intval($promo); |
653 | |
654 | if ($promo >= 1900 && $promo < intval(date('Y')) |
655 | || ($promo == -1 && has_perms())) |
656 | { |
657 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
658 | $trombi->hidePromo(); |
659 | $trombi->setAdmin(); |
660 | $page->assign_by_ref('trombi', $trombi); |
661 | } else { |
662 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
663 | } |
664 | |
665 | return PL_OK; |
666 | } |
e49018a7 |
667 | |
668 | function format_adr($params, &$smarty) |
669 | { |
670 | // $adr1, $adr2, $adr3, $postcode, $city, $region, $country |
671 | extract($params['adr']); |
672 | $adr = $adr1; |
673 | $adr = trim("$adr\n$adr2"); |
674 | $adr = trim("$adr\n$adr3"); |
675 | return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country"); |
676 | } |
677 | |
678 | function handler_vcard(&$page, $x = null) |
679 | { |
680 | if (is_null($x)) { |
681 | return PL_NOT_FOUND; |
682 | } |
683 | |
684 | global $globals; |
685 | |
686 | if (substr($x, -4) == '.vcf') { |
687 | $x = substr($x, 0, strlen($x) - 4); |
688 | } |
689 | |
690 | new_nonhtml_page('vcard.tpl', AUTH_COOKIE); |
691 | require_once 'xorg.misc.inc.php'; |
692 | require_once 'user.func.inc.php'; |
693 | |
694 | $page->register_modifier('qp_enc', 'quoted_printable_encode'); |
695 | $page->register_function('format_adr', array($this, 'format_adr')); |
696 | |
697 | $login = get_user_forlife($x); |
698 | $user = get_user_details($login); |
699 | |
700 | // alias virtual |
701 | $res = $globals->xdb->query( |
702 | "SELECT alias |
703 | FROM virtual |
704 | INNER JOIN virtual_redirect USING(vid) |
705 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
706 | WHERE ( redirect={?} OR redirect={?} ) |
707 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
708 | Session::getInt('uid'), |
709 | $user['forlife'].'@'.$globals->mail->domain, |
710 | $user['forlife'].'@'.$globals->mail->domain2); |
711 | |
712 | $user['virtualalias'] = $res->fetchOneCell(); |
713 | |
714 | $page->assign_by_ref('vcard', $user); |
715 | |
716 | header("Pragma: "); |
717 | header("Cache-Control: "); |
718 | header("Content-type: text/x-vcard\n"); |
719 | header("Content-Transfer-Encoding: Quoted-Printable\n"); |
720 | |
721 | return PL_OK; |
722 | } |
7d8b17cb |
723 | } |
724 | |
725 | ?> |