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