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