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), |
9643d877 |
32 | 'profile/private' => $this->make_hook('profile', AUTH_COOKIE), |
2f678da1 |
33 | 'profile/edit' => $this->make_hook('p_edit', AUTH_MDP), |
28e16d4d |
34 | 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), |
28e16d4d |
35 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
e49018a7 |
36 | |
2f678da1 |
37 | 'referent' => $this->make_hook('referent', AUTH_COOKIE), |
38 | 'referent/search' => $this->make_hook('ref_search', AUTH_COOKIE), |
39 | |
28e16d4d |
40 | 'trombi' => $this->make_hook('trombi', AUTH_COOKIE), |
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)) { |
924b4ba7 |
189 | if (preg_match('/([-a-z]+)\.([-a-z]+)\.([0-9]{4})/i', $x, $matches)) { |
190 | $matches = str_replace('-', '_', $matches); |
191 | $res = XDB::query("SELECT user_id |
192 | FROM auth_user_md5 |
193 | WHERE prenom LIKE {?} AND nom LIKE {?} AND promo = {?} |
194 | AND perms = 'pending'", |
195 | $matches[1], $matches[2], $matches[3]); |
196 | if ($res->numRows() == 1) { |
197 | $uid = $res->fetchOneCell(); |
198 | pl_redirect('marketing/public/' . $uid); |
199 | } |
200 | } |
e8599c21 |
201 | return PL_NOT_FOUND; |
202 | } |
203 | |
5e2307dc |
204 | $new = Env::v('modif') == 'new'; |
cab08090 |
205 | $user = get_user_details($login, S::v('uid'), $view); |
25412aa4 |
206 | require_once('url_catcher.inc.php'); |
207 | $user['freetext'] = url_catcher($user['freetext'], false); |
e8599c21 |
208 | $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; |
209 | $page->assign('xorg_title', $title); |
210 | |
211 | // photo |
212 | |
7da8ef90 |
213 | $photo = 'photo/'.$user['forlife'].($new ? '/req' : ''); |
e8599c21 |
214 | |
2f678da1 |
215 | if (!isset($user['y']) and !isset($user['x'])) { |
e8599c21 |
216 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
217 | } |
2f678da1 |
218 | if (!isset($user['y']) or $user['y'] < 1) $user['y']=1; |
219 | if (!isset($user['x']) or $user['x'] < 1) $user['x']=1; |
220 | if ($user['x'] > 240) { |
e8599c21 |
221 | $user['y'] = (integer)($user['y']*240/$user['x']); |
222 | $user['x'] = 240; |
223 | } |
2f678da1 |
224 | if ($user['y'] > 300) { |
e8599c21 |
225 | $user['x'] = (integer)($user['x']*300/$user['y']); |
226 | $user['y'] = 300; |
227 | } |
2f678da1 |
228 | if ($user['x'] < 160) { |
e8599c21 |
229 | $user['y'] = (integer)($user['y']*160/$user['x']); |
230 | $user['x'] = 160; |
231 | } |
232 | |
233 | $page->assign('logged', has_user_right('private', $view)); |
234 | if (!has_user_right($user['photo_pub'], $view)) { |
235 | $photo = ""; |
236 | } |
237 | |
238 | $page->assign_by_ref('x', $user); |
239 | $page->assign('photo_url', $photo); |
240 | // alias virtual |
08cce2ff |
241 | $res = XDB::query( |
e8599c21 |
242 | "SELECT alias |
243 | FROM virtual |
244 | INNER JOIN virtual_redirect USING(vid) |
245 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
246 | WHERE ( redirect={?} OR redirect={?} ) |
247 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
cab08090 |
248 | S::v('uid'), |
e8599c21 |
249 | $user['forlife'].'@'.$globals->mail->domain, |
250 | $user['forlife'].'@'.$globals->mail->domain2); |
251 | $page->assign('virtualalias', $res->fetchOneCell()); |
252 | |
c99ef281 |
253 | $page->addJsLink('close_on_esc.js'); |
e8599c21 |
254 | } |
255 | |
2f678da1 |
256 | function handler_p_edit(&$page, $opened_tab = 'general') |
257 | { |
258 | global $globals; |
259 | |
260 | $page->changeTpl('profil.tpl'); |
261 | |
c99ef281 |
262 | $page->addCssLink('profil.css'); |
2f678da1 |
263 | $page->assign('xorg_title', 'Polytechnique.org - Mon Profil'); |
264 | |
265 | require_once 'tabs.inc.php'; |
266 | require_once 'profil.func.inc.php'; |
267 | require_once 'synchro_ax.inc.php'; |
268 | |
3845b131 |
269 | if (Post::v('register_from_ax_question')) { |
270 | XDB::execute('UPDATE auth_user_quick |
2f678da1 |
271 | SET profile_from_ax = 1 |
272 | WHERE user_id = {?}', |
cab08090 |
273 | S::v('uid')); |
2f678da1 |
274 | } |
3845b131 |
275 | if (Post::v('add_to_nl')) { |
276 | require_once 'newsletter.inc.php'; |
277 | subscribe_nl(); |
278 | } |
279 | if (Post::v('add_to_promo')) { |
280 | $r = XDB::query('SELECT id FROM groupex.asso WHERE diminutif = {?}', |
281 | S::v('promo')); |
282 | $asso_id = $r->fetchOneCell(); |
283 | XDB::execute('REPLACE INTO groupex.membres (uid,asso_id) |
284 | VALUES ({?}, {?})', |
285 | S::v('uid'), $asso_id); |
9bb8bf21 |
286 | $mmlist = new MMList(S::v('uid'), S::v('password')); |
287 | $mmlist->subscribe("promo".S::v('promo')); |
3845b131 |
288 | } |
2f678da1 |
289 | |
290 | if (is_ax_key_missing()) { |
291 | $page->assign('no_private_key', true); |
292 | } |
293 | |
5e2307dc |
294 | if (Env::v('synchro_ax') == 'confirm' && !is_ax_key_missing()) { |
cab08090 |
295 | ax_synchronize(S::v('bestalias'), S::v('uid')); |
2f678da1 |
296 | $page->trig('Ton profil a été synchronisé avec celui du site polytechniciens.com'); |
297 | } |
298 | |
299 | // pour tous les tabs, la date de naissance pour verifier |
300 | // quelle est bien rentree et la date. |
08cce2ff |
301 | $res = XDB::query( |
2f678da1 |
302 | "SELECT naissance, DATE_FORMAT(date, '%d.%m.%Y') |
303 | FROM auth_user_md5 |
cab08090 |
304 | WHERE user_id={?}", S::v('uid')); |
2f678da1 |
305 | list($naissance, $date_modif_profil) = $res->fetchOneRow(); |
306 | |
307 | // lorsqu'on n'a pas la date de naissance en base de données |
308 | if (!$naissance) { |
309 | // la date de naissance n'existait pas et vient d'ętre soumise dans la variable |
310 | if (Env::has('birth')) { |
311 | //en cas d'erreur : |
5e2307dc |
312 | if (!ereg('[0-3][0-9][0-1][0-9][1][9]([0-9]{2})', Env::v('birth'))) { |
2f678da1 |
313 | $page->assign('etat_naissance', 'query'); |
314 | $page->trig('Date de naissance incorrecte ou incohérente.'); |
fd8f77de |
315 | return; |
2f678da1 |
316 | } |
317 | |
318 | //sinon |
5e2307dc |
319 | $birth = sprintf("%s-%s-%s", substr(Env::v('birth'), 4, 4), |
320 | substr(Env::v('birth'), 2, 2), |
321 | substr(Env::v('birth'), 0, 2)); |
08cce2ff |
322 | XDB::execute("UPDATE auth_user_md5 |
2f678da1 |
323 | SET naissance={?} |
324 | WHERE user_id={?}", $birth, |
cab08090 |
325 | S::v('uid')); |
2f678da1 |
326 | $page->assign('etat_naissance', 'ok'); |
fd8f77de |
327 | return; |
2f678da1 |
328 | } |
329 | |
330 | $page->assign('etat_naissance', 'query'); |
fd8f77de |
331 | return; // on affiche le formulaire pour naissance |
2f678da1 |
332 | } |
333 | |
334 | //doit-on faire un update ? |
335 | if (Env::has('modifier') || Env::has('suivant')) { |
336 | require_once "profil/get_{$opened_tab}.inc.php"; |
337 | require_once "profil/verif_{$opened_tab}.inc.php"; |
338 | |
339 | if($page->nb_errs()) { |
340 | require_once "profil/assign_{$opened_tab}.inc.php"; |
341 | $page->assign('onglet', $opened_tab); |
342 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
fd8f77de |
343 | return; |
2f678da1 |
344 | } |
345 | |
346 | $date=date("Y-m-j");//nouvelle date de mise a jour |
347 | |
348 | //On sauvegarde l'uid pour l'AX |
349 | /* on sauvegarde les changements dans user_changes : |
350 | * on a juste besoin d'insérer le user_id de la personne dans la table |
351 | */ |
08cce2ff |
352 | XDB::execute('REPLACE INTO user_changes SET user_id={?}', |
cab08090 |
353 | S::v('uid')); |
2f678da1 |
354 | |
cab08090 |
355 | if (!S::has('suid')) { |
2f678da1 |
356 | require_once 'notifs.inc.php'; |
cab08090 |
357 | register_watch_op(S::v('uid'), WATCH_FICHE); |
2f678da1 |
358 | } |
359 | |
360 | // mise a jour des champs relatifs au tab ouvert |
361 | require_once "profil/update_{$opened_tab}.inc.php"; |
362 | |
5ee95138 |
363 | $log =& $_SESSION['log']; |
2f678da1 |
364 | $log->log('profil', $opened_tab); |
365 | $page->assign('etat_update', 'ok'); |
366 | } |
367 | |
368 | if (Env::has('suivant')) { |
8b00e0e0 |
369 | pl_redirect('profile/edit/' . get_next_tab($opened_tab)); |
2f678da1 |
370 | } |
371 | |
372 | require_once "profil/get_{$opened_tab}.inc.php"; |
373 | require_once "profil/verif_{$opened_tab}.inc.php"; |
374 | require_once "profil/assign_{$opened_tab}.inc.php"; |
375 | |
376 | $page->assign('onglet', $opened_tab); |
377 | $page->assign('onglet_tpl', "profil/$opened_tab.tpl"); |
378 | |
fd8f77de |
379 | return; |
2f678da1 |
380 | } |
381 | |
9b0fa329 |
382 | function handler_p_orange(&$page) |
383 | { |
9b0fa329 |
384 | $page->changeTpl('orange.tpl'); |
385 | |
386 | require_once 'validations.inc.php'; |
387 | require_once 'xorg.misc.inc.php'; |
388 | |
08cce2ff |
389 | $res = XDB::query( |
2f678da1 |
390 | "SELECT u.promo, u.promo_sortie |
9b0fa329 |
391 | FROM auth_user_md5 AS u |
cab08090 |
392 | WHERE user_id={?}", S::v('uid')); |
9b0fa329 |
393 | |
2f678da1 |
394 | list($promo, $promo_sortie_old) = $res->fetchOneRow(); |
9b0fa329 |
395 | $page->assign('promo_sortie_old', $promo_sortie_old); |
396 | $page->assign('promo', $promo); |
397 | |
398 | if (!Env::has('promo_sortie')) { |
fd8f77de |
399 | return; |
9b0fa329 |
400 | } |
401 | |
5e2307dc |
402 | $promo_sortie = Env::i('promo_sortie'); |
9b0fa329 |
403 | |
404 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
405 | $page->trig('L\'année de sortie doit ętre un nombre de quatre chiffres'); |
406 | } |
407 | elseif ($promo_sortie < $promo + 3) { |
408 | $page->trig('Trop tôt'); |
409 | } |
410 | elseif ($promo_sortie == $promo_sortie_old) { |
411 | $page->trig('Tu appartiens déjŕ ŕ la promotion correspondante ŕ cette année de sortie.'); |
412 | } |
413 | elseif ($promo_sortie == $promo + 3) { |
08cce2ff |
414 | XDB::execute( |
9b0fa329 |
415 | "UPDATE auth_user_md5 set promo_sortie={?} |
cab08090 |
416 | WHERE user_id={?}", $promo_sortie, S::v('uid')); |
9b0fa329 |
417 | $page->trig('Ton statut "orange" a été supprimé.'); |
418 | $page->assign('promo_sortie_old', $promo_sortie); |
419 | } |
420 | else { |
421 | $page->assign('promo_sortie', $promo_sortie); |
422 | |
423 | if (Env::has('submit')) { |
cab08090 |
424 | $myorange = new OrangeReq(S::v('uid'), |
9b0fa329 |
425 | $promo_sortie); |
426 | $myorange->submit(); |
427 | $page->assign('myorange', $myorange); |
428 | } |
429 | } |
9b0fa329 |
430 | } |
431 | |
2f678da1 |
432 | function handler_referent(&$page, $x = null) |
28e16d4d |
433 | { |
28e16d4d |
434 | require_once 'user.func.inc.php'; |
435 | |
436 | if (is_null($x)) { |
437 | return PL_NOT_FOUND; |
438 | } |
439 | |
62a66dfc |
440 | $page->changeTpl('fiche_referent.tpl', SIMPLE); |
28e16d4d |
441 | |
08cce2ff |
442 | $res = XDB::query( |
28e16d4d |
443 | "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias |
444 | FROM auth_user_md5 AS u |
2f678da1 |
445 | INNER JOIN aliases AS a ON (u.user_id=a.id |
446 | AND FIND_IN_SET('bestalias', a.flags)) |
28e16d4d |
447 | INNER JOIN aliases AS a1 ON (u.user_id=a1.id |
448 | AND a1.alias = {?} |
449 | AND a1.type!='homonyme')", $x); |
450 | |
451 | if ($res->numRows() != 1) { |
452 | return PL_NOT_FOUND; |
453 | } |
454 | |
455 | list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow(); |
456 | |
457 | $page->assign('prenom', $prenom); |
458 | $page->assign('nom', $nom); |
459 | $page->assign('promo', $promo); |
460 | $page->assign('cv', $cv); |
461 | $page->assign('bestalias', $bestalias); |
462 | $page->assign('adr_pro', get_user_details_pro($user_id)); |
463 | |
464 | ///// recuperations infos referent |
465 | |
466 | //expertise |
08cce2ff |
467 | $res = XDB::query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id); |
28e16d4d |
468 | $page->assign('expertise', $res->fetchOneCell()); |
469 | |
470 | //secteurs |
471 | $secteurs = $ss_secteurs = Array(); |
08cce2ff |
472 | $res = XDB::iterRow( |
28e16d4d |
473 | "SELECT s.label, ss.label |
474 | FROM mentor_secteurs AS m |
475 | LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) |
476 | LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id) |
477 | WHERE uid = {?}", $user_id); |
478 | while (list($sec, $ssec) = $res->next()) { |
479 | $secteurs[] = $sec; |
480 | $ss_secteurs[] = $ssec; |
481 | } |
482 | $page->assign_by_ref('secteurs', $secteurs); |
483 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
484 | |
485 | //pays |
08cce2ff |
486 | $res = XDB::query( |
28e16d4d |
487 | "SELECT gp.pays |
488 | FROM mentor_pays AS m |
489 | LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2) |
490 | WHERE uid = {?}", $user_id); |
491 | $page->assign('pays', $res->fetchColumn()); |
492 | |
c99ef281 |
493 | $page->addJsLink('close_on_esc.js'); |
28e16d4d |
494 | } |
495 | |
2f678da1 |
496 | function handler_ref_search(&$page) |
497 | { |
2f678da1 |
498 | $page->changeTpl('referent.tpl'); |
499 | |
500 | $page->assign('xorg_title', 'Polytechnique.org - Conseil Pro'); |
501 | |
5e2307dc |
502 | $secteur_sel = Post::v('secteur'); |
503 | $ss_secteur_sel = Post::v('ss_secteur'); |
504 | $pays_sel = Post::v('pays', '00'); |
505 | $expertise_champ = Post::v('expertise'); |
2f678da1 |
506 | |
507 | $page->assign('pays_sel', $pays_sel); |
508 | $page->assign('expertise_champ', $expertise_champ); |
509 | $page->assign('secteur_sel', $secteur_sel); |
510 | $page->assign('ss_secteur_sel', $ss_secteur_sel); |
511 | |
512 | //recuperation des noms de secteurs |
08cce2ff |
513 | $res = XDB::iterRow("SELECT id, label FROM emploi_secteur"); |
2f678da1 |
514 | $secteurs[''] = ''; |
515 | while (list($tmp_id, $tmp_label) = $res->next()) { |
516 | $secteurs[$tmp_id] = $tmp_label; |
517 | } |
518 | $page->assign_by_ref('secteurs', $secteurs); |
519 | |
520 | //on recupere les sous-secteurs si necessaire |
521 | $ss_secteurs[''] = ''; |
522 | if (!empty($secteur_sel)) { |
08cce2ff |
523 | $res = XDB::iterRow("SELECT id, label FROM emploi_ss_secteur |
2f678da1 |
524 | WHERE secteur = {?}", $secteur_sel); |
525 | while (list($tmp_id, $tmp_label) = $res->next()) { |
526 | $ss_secteurs[$tmp_id] = $tmp_label; |
527 | } |
528 | } |
529 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
530 | |
531 | //recuperation des noms de pays |
08cce2ff |
532 | $res = XDB::iterRow("SELECT a2, pays FROM geoloc_pays |
2f678da1 |
533 | WHERE pays <> '' ORDER BY pays"); |
534 | $pays['00'] = ''; |
535 | while (list($tmp_id, $tmp_label) = $res->next()) { |
536 | $pays[$tmp_id] = $tmp_label; |
537 | } |
538 | $page->assign_by_ref('pays', $pays); |
539 | |
540 | // nb de mentors |
08cce2ff |
541 | $res = XDB::query("SELECT count(*) FROM mentor"); |
2f678da1 |
542 | $page->assign('mentors_number', $res->fetchOneCell()); |
543 | |
544 | if (!Env::has('Chercher')) { |
fd8f77de |
545 | return; |
2f678da1 |
546 | } |
547 | |
548 | // On vient d'un formulaire |
549 | $where = array(); |
550 | |
551 | if ($pays_sel != '00') { |
552 | $where[] = "mp.pid = '".addslashes($pays_sel)."'"; |
553 | } |
554 | if ($secteur_sel) { |
555 | $where[] = "ms.secteur = '".addslashes($secteur_sel)."'"; |
556 | if ($ss_secteur_sel) { |
557 | $where[] = "ms.ss_secteur = '".addslashes($ss_secteur_sel)."'"; |
558 | } |
559 | } |
560 | if ($expertise_champ) { |
561 | $where[] = "MATCH(m.expertise) AGAINST('".addslashes($expertise_champ)."')"; |
562 | } |
563 | |
564 | if ($where) { |
565 | $where = join(' AND ', $where); |
566 | |
567 | $sql = "SELECT m.uid, a.prenom, a.nom, a.promo, |
568 | l.alias AS bestalias, m.expertise, mp.pid, |
569 | ms.secteur, ms.ss_secteur |
570 | FROM mentor AS m |
571 | LEFT JOIN auth_user_md5 AS a ON(m.uid = a.user_id) |
572 | INNER JOIN aliases AS l ON (a.user_id=l.id AND |
573 | FIND_IN_SET('bestalias', l.flags)) |
574 | LEFT JOIN mentor_pays AS mp ON(m.uid = mp.uid) |
575 | LEFT JOIN mentor_secteurs AS ms ON(m.uid = ms.uid) |
576 | WHERE $where |
577 | GROUP BY uid |
578 | ORDER BY RAND({?})"; |
cab08090 |
579 | $res = XDB::iterator($sql, S::v('uid')); |
2f678da1 |
580 | |
581 | if ($res->total() == 0) { |
582 | $page->assign('recherche_trop_large', true); |
fd8f77de |
583 | return; |
2f678da1 |
584 | } |
585 | |
586 | $nb_max_res_total = 100; |
587 | $nb_max_res_ppage = 10; |
588 | |
5e2307dc |
589 | $curpage = Env::i('curpage', 1); |
2f678da1 |
590 | $personnes = array(); |
591 | $i = 0; |
592 | |
593 | while (($pers = $res->next()) && count($personnes) < $nb_max_res_total) { |
594 | $the_page = intval($i / $nb_max_res_ppage) + 1; |
595 | if ($the_page == $curpage) { |
596 | $personnes[] = $pers; |
597 | } |
598 | $i ++; |
599 | } |
600 | |
601 | $page->assign('personnes', $personnes); |
602 | $page->assign('curpage', $curpage); |
603 | $page->assign('nb_pages_total', |
604 | intval($res->total() / $nb_max_res_ppage) + 1); |
605 | } |
2f678da1 |
606 | } |
607 | |
926f16d7 |
608 | function handler_p_usage(&$page) |
609 | { |
926f16d7 |
610 | $page->changeTpl('nomusage.tpl'); |
611 | |
612 | require_once 'validations.inc.php'; |
613 | require_once 'xorg.misc.inc.php'; |
614 | |
08cce2ff |
615 | $res = XDB::query( |
2f678da1 |
616 | "SELECT u.nom, u.nom_usage, u.flags, e.alias |
926f16d7 |
617 | FROM auth_user_md5 AS u |
2f678da1 |
618 | LEFT JOIN aliases AS e ON(u.user_id = e.id |
619 | AND FIND_IN_SET('usage', e.flags)) |
cab08090 |
620 | WHERE user_id={?}", S::v('uid')); |
926f16d7 |
621 | |
2f678da1 |
622 | list($nom, $usage_old, $flags, $alias_old) = $res->fetchOneRow(); |
926f16d7 |
623 | $flags = new flagset($flags); |
624 | $page->assign('usage_old', $usage_old); |
625 | $page->assign('alias_old', $alias_old); |
626 | |
5e2307dc |
627 | $nom_usage = replace_accent(trim(Env::v('nom_usage'))); |
926f16d7 |
628 | $nom_usage = strtoupper($nom_usage); |
629 | $page->assign('usage_req', $nom_usage); |
630 | |
631 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
632 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
633 | if ($nom_usage == $nom) { |
634 | $page->assign('same', true); |
9b0fa329 |
635 | } else { // le nom de mariage est distinct du nom ŕ l'X |
926f16d7 |
636 | // on calcule l'alias pour l'afficher |
5e2307dc |
637 | $reason = Env::v('reason'); |
926f16d7 |
638 | if ($reason == 'other') { |
5e2307dc |
639 | $reason = Env::v('other_reason'); |
926f16d7 |
640 | } |
cab08090 |
641 | $myusage = new UsageReq(S::v('uid'), $nom_usage, $reason); |
926f16d7 |
642 | $myusage->submit(); |
643 | $page->assign('myusage', $myusage); |
644 | } |
645 | } |
926f16d7 |
646 | } |
647 | |
7d8b17cb |
648 | function handler_trombi(&$page, $promo = null) |
649 | { |
7d8b17cb |
650 | $page->changeTpl('trombipromo.tpl'); |
2f678da1 |
651 | $page->assign('xorg_title', 'Polytechnique.org - Trombi Promo'); |
7d8b17cb |
652 | |
653 | if (is_null($promo)) { |
fd8f77de |
654 | return; |
7d8b17cb |
655 | } |
656 | |
657 | $this->promo = $promo = intval($promo); |
658 | |
9fe6c39d |
659 | if ($promo >= 1900 && ($promo < intval(date('Y')) || ($promo == intval(date('Y')) && intval(date('m')) >= 9)) |
cab08090 |
660 | || ($promo == -1 && S::has_perms())) |
7d8b17cb |
661 | { |
662 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
663 | $trombi->hidePromo(); |
664 | $trombi->setAdmin(); |
665 | $page->assign_by_ref('trombi', $trombi); |
666 | } else { |
667 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
668 | } |
7d8b17cb |
669 | } |
e49018a7 |
670 | |
e49018a7 |
671 | function handler_vcard(&$page, $x = null) |
672 | { |
673 | if (is_null($x)) { |
674 | return PL_NOT_FOUND; |
675 | } |
676 | |
677 | global $globals; |
678 | |
679 | if (substr($x, -4) == '.vcf') { |
680 | $x = substr($x, 0, strlen($x) - 4); |
681 | } |
682 | |
5e193297 |
683 | require_once('vcard.inc.php'); |
684 | $vcard = new VCard($x); |
685 | $vcard->do_page($page); |
e49018a7 |
686 | } |
92423144 |
687 | |
688 | function handler_admin_trombino(&$page, $uid = null, $action = null) { |
689 | $page->changeTpl('admin/admin_trombino.tpl'); |
690 | $page->assign('xorg_title','Polytechnique.org - Administration - Trombino'); |
691 | $page->assign('uid', $uid); |
692 | |
693 | $q = XDB::query( |
694 | "SELECT a.alias,promo |
695 | FROM auth_user_md5 AS u |
696 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND type='a_vie' ) |
697 | WHERE user_id = {?}", $uid); |
698 | list($forlife, $promo) = $q->fetchOneRow(); |
699 | |
700 | switch ($action) { |
701 | |
702 | case "original": |
703 | header("Content-type: image/jpeg"); |
704 | readfile("/home/web/trombino/photos".$promo."/".$forlife.".jpg"); |
705 | exit; |
706 | break; |
707 | |
708 | case "new": |
709 | $data = file_get_contents($_FILES['userfile']['tmp_name']); |
710 | list($x, $y) = getimagesize($_FILES['userfile']['tmp_name']); |
711 | $mimetype = substr($_FILES['userfile']['type'], 6); |
712 | unlink($_FILES['userfile']['tmp_name']); |
713 | XDB::execute( |
714 | "REPLACE INTO photo SET uid={?}, attachmime = {?}, attach={?}, x={?}, y={?}", |
715 | $uid, $mimetype, $data, $x, $y); |
716 | break; |
717 | |
718 | case "delete": |
719 | XDB::execute('DELETE FROM photo WHERE uid = {?}', $uid); |
720 | break; |
721 | } |
722 | |
723 | $page->assign('forlife', $forlife); |
724 | } |
725 | function handler_admin_binets(&$page, $action = 'list', $id = null) { |
92423144 |
726 | $page->assign('xorg_title','Polytechnique.org - Administration - Binets'); |
727 | $page->assign('title', 'Gestion des binets'); |
728 | $table_editor = new PLTableEditor('admin/binets', 'binets_def', 'id'); |
729 | $table_editor->add_join_table('binets_ins','binet_id',true); |
730 | $table_editor->describe('text','intitulé',true); |
731 | $table_editor->apply($page, $action, $id); |
732 | } |
733 | function handler_admin_formations(&$page, $action = 'list', $id = null) { |
92423144 |
734 | $page->assign('xorg_title','Polytechnique.org - Administration - Formations'); |
735 | $page->assign('title', 'Gestion des formations'); |
736 | $table_editor = new PLTableEditor('admin/formations','applis_def','id'); |
737 | $table_editor->add_join_table('applis_ins','aid',true); |
738 | $table_editor->describe('text','intitulé',true); |
739 | $table_editor->describe('url','site web',false); |
740 | $table_editor->apply($page, $action, $id); |
741 | } |
742 | function handler_admin_groupesx(&$page, $action = 'list', $id = null) { |
92423144 |
743 | $page->assign('xorg_title','Polytechnique.org - Administration - Groupes X'); |
744 | $page->assign('title', 'Gestion des Groupes X'); |
745 | $table_editor = new PLTableEditor('admin/groupes-x','groupesx_def','id'); |
746 | $table_editor->add_join_table('groupesx_ins','gid',true); |
747 | $table_editor->describe('text','intitulé',true); |
748 | $table_editor->describe('url','site web',false); |
749 | $table_editor->apply($page, $action, $id); |
750 | } |
751 | function handler_admin_medals(&$page, $action = 'list', $id = null) { |
92423144 |
752 | $page->assign('xorg_title','Polytechnique.org - Administration - Distinctions'); |
753 | $page->assign('title', 'Gestion des Distinctions'); |
754 | $table_editor = new PLTableEditor('admin/medals','profile_medals','id'); |
755 | $table_editor->describe('text', 'intitulé', true); |
756 | $table_editor->describe('img', 'nom de l\'image', false); |
757 | $table_editor->apply($page, $action, $id); |
758 | if ($id && $action == 'edit') { |
759 | $page->changeTpl('admin/gerer_decos.tpl'); |
760 | |
761 | $mid = $id; |
762 | |
763 | if (Post::v('act') == 'del') { |
764 | XDB::execute('DELETE FROM profile_medals_grades WHERE mid={?} AND gid={?}', $mid, Post::i('gid')); |
765 | } elseif (Post::v('act') == 'new') { |
766 | XDB::execute('INSERT INTO profile_medals_grades (mid,gid) VALUES({?},{?})', |
767 | $mid, max(array_keys(Post::v('grades', array(0))))+1); |
768 | } else { |
769 | foreach (Post::v('grades', array()) as $gid=>$text) { |
770 | XDB::execute('UPDATE profile_medals_grades SET pos={?}, text={?} WHERE gid={?}', $_POST['pos'][$gid], $text, $gid); |
771 | } |
772 | } |
773 | $res = XDB::iterator('SELECT gid, text, pos FROM profile_medals_grades WHERE mid={?} ORDER BY pos', $mid); |
774 | $page->assign('grades', $res); |
775 | } |
776 | } |
7d8b17cb |
777 | } |
778 | |
779 | ?> |