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), |
28e16d4d |
32 | 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP), |
33 | 'profile/referent' => $this->make_hook('p_referent', AUTH_MDP), |
34 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
e49018a7 |
35 | |
28e16d4d |
36 | 'trombi' => $this->make_hook('trombi', AUTH_COOKIE), |
926f16d7 |
37 | |
28e16d4d |
38 | 'vcard' => $this->make_hook('vcard', AUTH_COOKIE), |
7d8b17cb |
39 | ); |
40 | } |
41 | |
e8599c21 |
42 | /* XXX COMPAT */ |
43 | function handler_fiche(&$page) |
44 | { |
45 | return $this->handler_profile($page, Env::get('user')); |
46 | } |
47 | |
48 | |
7d8b17cb |
49 | function _trombi_getlist($offset, $limit) |
50 | { |
51 | global $globals; |
52 | |
53 | $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" ); |
54 | |
55 | $res = $globals->xdb->query( |
56 | "SELECT COUNT(*) |
57 | FROM auth_user_md5 AS u |
58 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
59 | $where"); |
60 | $pnb = $res->fetchOneCell(); |
61 | |
62 | $res = $globals->xdb->query( |
63 | "SELECT promo,user_id,a.alias AS forlife,IF(nom_usage='', nom, nom_usage) AS nom,prenom |
64 | FROM photo AS p |
65 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
66 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
67 | $where |
68 | ORDER BY promo,nom,prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
69 | |
70 | return array($pnb, $res->fetchAllAssoc()); |
71 | } |
72 | |
adbdf493 |
73 | function handler_photo(&$page, $x = null, $req = null) |
74 | { |
75 | if (is_null($x)) { |
76 | return PL_NOT_FOUND; |
77 | } |
78 | |
79 | global $globals; |
80 | |
81 | $res = $globals->xdb->query("SELECT id, pub FROM aliases |
82 | LEFT JOIN photo ON(id = uid) |
83 | WHERE alias = {?}", $x); |
84 | list($uid, $photo_pub) = $res->fetchOneRow(); |
85 | |
86 | if ($req && logged()) { |
87 | include 'validations.inc.php'; |
88 | $myphoto = PhotoReq::get_request($uid); |
89 | Header('Content-type: image/'.$myphoto->mimetype); |
90 | echo $myphoto->data; |
91 | } else { |
92 | $res = $globals->xdb->query( |
93 | "SELECT attachmime, attach |
94 | FROM photo |
95 | WHERE uid={?}", $uid); |
96 | |
97 | if ((list($type,$data) = $res->fetchOneRow()) && ($photo_pub == 'public' || logged())) { |
98 | Header("Content-type: image/$type"); |
99 | echo $data; |
100 | } else { |
101 | Header('Content-type: image/png'); |
fb9a56cb |
102 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
adbdf493 |
103 | } |
104 | } |
105 | exit; |
106 | } |
107 | |
fb9a56cb |
108 | function handler_photo_change(&$page) |
109 | { |
110 | global $globals; |
111 | |
112 | $page->changeTpl('trombino.tpl'); |
113 | |
114 | require_once('validations.inc.php'); |
115 | |
116 | $trombi_x = '/home/web/trombino/photos'.Session::get('promo') |
117 | .'/'.Session::get('forlife').'.jpg'; |
118 | |
119 | if (Env::has('upload')) { |
120 | $file = isset($_FILES['userfile']['tmp_name']) |
121 | ? $_FILES['userfile']['tmp_name'] |
122 | : Env::get('photo'); |
123 | if ($data = file_get_contents($file)) { |
124 | if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) { |
125 | $myphoto->submit(); |
126 | } |
127 | } else { |
128 | $page->trig('Fichier inexistant ou vide'); |
129 | } |
130 | } elseif (Env::has('trombi')) { |
131 | $myphoto = new PhotoReq(Session::getInt('uid'), |
132 | file_get_contents($trombi_x)); |
133 | if ($myphoto) { |
134 | $myphoto->commit(); |
135 | $myphoto->clean(); |
136 | } |
137 | } elseif (Env::get('suppr')) { |
138 | $globals->xdb->execute('DELETE FROM photo WHERE uid = {?}', |
139 | Session::getInt('uid')); |
140 | $globals->xdb->execute('DELETE FROM requests |
141 | WHERE user_id = {?} AND type="photo"', |
142 | Session::getInt('uid')); |
143 | } elseif (Env::get('cancel')) { |
144 | $sql = $globals->xdb->query('DELETE FROM requests |
145 | WHERE user_id={?} AND type="photo"', |
146 | Session::getInt('uid')); |
147 | } |
148 | |
149 | $sql = $globals->xdb->query('SELECT COUNT(*) FROM requests |
150 | WHERE user_id={?} AND type="photo"', |
151 | Session::getInt('uid')); |
152 | $page->assign('submited', $sql->fetchOneCell()); |
153 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
154 | |
155 | return PL_OK; |
156 | } |
157 | |
e8599c21 |
158 | function handler_profile(&$page, $x = null) |
159 | { |
160 | if (is_null($x)) { |
161 | return PL_NOT_FOUND; |
162 | } |
163 | |
164 | global $globals; |
165 | require_once 'user.func.inc.php'; |
166 | |
167 | $page->changeTpl('fiche.tpl'); |
168 | $page->assign('simple', true); |
169 | |
170 | $view = 'private'; |
171 | if (!logged() || Env::get('view') == 'public') $view = 'public'; |
172 | if (logged() && Env::get('view') == 'ax') $view = 'ax'; |
173 | |
174 | if (is_numeric($x)) { |
175 | $res = $globals->xdb->query( |
176 | "SELECT alias |
177 | FROM aliases AS a |
178 | INNER JOIN auth_user_md5 AS u ON (a.id=u.user_id AND a.type='a_vie') |
179 | WHERE matricule={?}", $x); |
180 | $login = $res->fetchOneCell(); |
181 | } else { |
182 | $login = get_user_forlife($x); |
183 | } |
184 | |
185 | if (empty($login)) { |
186 | return PL_NOT_FOUND; |
187 | } |
188 | |
189 | $new = Env::get('modif') == 'new'; |
190 | $user = get_user_details($login, Session::getInt('uid'), $view); |
191 | $title = $user['prenom'] . ' ' . empty($user['nom_usage']) ? $user['nom'] : $user['nom_usage']; |
192 | $page->assign('xorg_title', $title); |
193 | |
194 | // photo |
195 | |
196 | $photo = $globals->baseurl.'/photo/'.$user['forlife'].($new ? '/req' : ''); |
197 | |
198 | if(!isset($user['y']) and !isset($user['x'])) { |
199 | list($user['x'], $user['y']) = getimagesize("images/none.png"); |
200 | } |
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){ |
204 | $user['y'] = (integer)($user['y']*240/$user['x']); |
205 | $user['x'] = 240; |
206 | } |
207 | if($user['y'] > 300){ |
208 | $user['x'] = (integer)($user['x']*300/$user['y']); |
209 | $user['y'] = 300; |
210 | } |
211 | if($user['x'] < 160){ |
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 |
224 | $res = $globals->xdb->query( |
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}'", |
231 | Session::getInt('uid'), |
232 | $user['forlife'].'@'.$globals->mail->domain, |
233 | $user['forlife'].'@'.$globals->mail->domain2); |
234 | $page->assign('virtualalias', $res->fetchOneCell()); |
235 | |
236 | $page->addJsLink('javascript/close_on_esc.js'); |
237 | |
238 | return PL_OK; |
239 | } |
240 | |
9b0fa329 |
241 | function handler_p_orange(&$page) |
242 | { |
243 | global $globals; |
244 | |
245 | $page->changeTpl('orange.tpl'); |
246 | |
247 | require_once 'validations.inc.php'; |
248 | require_once 'xorg.misc.inc.php'; |
249 | |
250 | $res = $globals->xdb->query( |
251 | "SELECT u.promo,u.promo_sortie |
252 | FROM auth_user_md5 AS u |
253 | WHERE user_id={?}", Session::getInt('uid')); |
254 | |
255 | list($promo,$promo_sortie_old) = $res->fetchOneRow(); |
256 | $page->assign('promo_sortie_old', $promo_sortie_old); |
257 | $page->assign('promo', $promo); |
258 | |
259 | if (!Env::has('promo_sortie')) { |
260 | return PL_OK; |
261 | } |
262 | |
263 | $promo_sortie = Env::getInt('promo_sortie'); |
264 | |
265 | if ($promo_sortie < 1000 || $promo_sortie > 9999) { |
266 | $page->trig('L\'année de sortie doit être un nombre de quatre chiffres'); |
267 | } |
268 | elseif ($promo_sortie < $promo + 3) { |
269 | $page->trig('Trop tôt'); |
270 | } |
271 | elseif ($promo_sortie == $promo_sortie_old) { |
272 | $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.'); |
273 | } |
274 | elseif ($promo_sortie == $promo + 3) { |
275 | $globals->xdb->execute( |
276 | "UPDATE auth_user_md5 set promo_sortie={?} |
277 | WHERE user_id={?}",$promo_sortie,Session::getInt('uid')); |
278 | $page->trig('Ton statut "orange" a été supprimé.'); |
279 | $page->assign('promo_sortie_old', $promo_sortie); |
280 | } |
281 | else { |
282 | $page->assign('promo_sortie', $promo_sortie); |
283 | |
284 | if (Env::has('submit')) { |
285 | $myorange = new OrangeReq(Session::getInt('uid'), |
286 | $promo_sortie); |
287 | $myorange->submit(); |
288 | $page->assign('myorange', $myorange); |
289 | } |
290 | } |
291 | |
292 | return PL_OK; |
293 | } |
294 | |
28e16d4d |
295 | function handler_p_referent(&$page, $x = null) |
296 | { |
297 | global $globals; |
298 | |
299 | require_once 'user.func.inc.php'; |
300 | |
301 | if (is_null($x)) { |
302 | return PL_NOT_FOUND; |
303 | } |
304 | |
305 | $page->changeTpl('fiche_referent.tpl'); |
306 | $page->assign('simple', true); |
307 | |
308 | $res = $globals->xdb->query( |
309 | "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias |
310 | FROM auth_user_md5 AS u |
311 | INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags)) |
312 | INNER JOIN aliases AS a1 ON (u.user_id=a1.id |
313 | AND a1.alias = {?} |
314 | AND a1.type!='homonyme')", $x); |
315 | |
316 | if ($res->numRows() != 1) { |
317 | return PL_NOT_FOUND; |
318 | } |
319 | |
320 | list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow(); |
321 | |
322 | $page->assign('prenom', $prenom); |
323 | $page->assign('nom', $nom); |
324 | $page->assign('promo', $promo); |
325 | $page->assign('cv', $cv); |
326 | $page->assign('bestalias', $bestalias); |
327 | $page->assign('adr_pro', get_user_details_pro($user_id)); |
328 | |
329 | ///// recuperations infos referent |
330 | |
331 | //expertise |
332 | $res = $globals->xdb->query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id); |
333 | $page->assign('expertise', $res->fetchOneCell()); |
334 | |
335 | //secteurs |
336 | $secteurs = $ss_secteurs = Array(); |
337 | $res = $globals->xdb->iterRow( |
338 | "SELECT s.label, ss.label |
339 | FROM mentor_secteurs AS m |
340 | LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id) |
341 | LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id) |
342 | WHERE uid = {?}", $user_id); |
343 | while (list($sec, $ssec) = $res->next()) { |
344 | $secteurs[] = $sec; |
345 | $ss_secteurs[] = $ssec; |
346 | } |
347 | $page->assign_by_ref('secteurs', $secteurs); |
348 | $page->assign_by_ref('ss_secteurs', $ss_secteurs); |
349 | |
350 | //pays |
351 | $res = $globals->xdb->query( |
352 | "SELECT gp.pays |
353 | FROM mentor_pays AS m |
354 | LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2) |
355 | WHERE uid = {?}", $user_id); |
356 | $page->assign('pays', $res->fetchColumn()); |
357 | |
358 | $page->addJsLink('javascript/close_on_esc.js'); |
359 | return PL_OK; |
360 | } |
361 | |
926f16d7 |
362 | function handler_p_usage(&$page) |
363 | { |
364 | global $globals; |
365 | |
366 | $page->changeTpl('nomusage.tpl'); |
367 | |
368 | require_once 'validations.inc.php'; |
369 | require_once 'xorg.misc.inc.php'; |
370 | |
371 | $res = $globals->xdb->query( |
372 | "SELECT u.nom,u.nom_usage,u.flags,e.alias |
373 | FROM auth_user_md5 AS u |
374 | LEFT JOIN aliases AS e ON(u.user_id = e.id AND FIND_IN_SET('usage',e.flags)) |
375 | WHERE user_id={?}", Session::getInt('uid')); |
376 | |
377 | list($nom,$usage_old,$flags,$alias_old) = $res->fetchOneRow(); |
378 | $flags = new flagset($flags); |
379 | $page->assign('usage_old', $usage_old); |
380 | $page->assign('alias_old', $alias_old); |
381 | |
382 | $nom_usage = replace_accent(trim(Env::get('nom_usage'))); |
383 | $nom_usage = strtoupper($nom_usage); |
384 | $page->assign('usage_req', $nom_usage); |
385 | |
386 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
387 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
388 | if ($nom_usage == $nom) { |
389 | $page->assign('same', true); |
9b0fa329 |
390 | } else { // le nom de mariage est distinct du nom à l'X |
926f16d7 |
391 | // on calcule l'alias pour l'afficher |
392 | $reason = Env::get('reason'); |
393 | if ($reason == 'other') { |
394 | $reason = Env::get('other_reason'); |
395 | } |
396 | $myusage = new UsageReq(Session::getInt('uid'), $nom_usage, $reason); |
397 | $myusage->submit(); |
398 | $page->assign('myusage', $myusage); |
399 | } |
400 | } |
401 | |
402 | return PL_OK; |
403 | } |
404 | |
7d8b17cb |
405 | function handler_trombi(&$page, $promo = null) |
406 | { |
407 | require_once 'trombi.inc.php'; |
408 | |
409 | $page->changeTpl('trombipromo.tpl'); |
410 | $page->assign('xorg_title','Polytechnique.org - Trombi Promo'); |
411 | |
412 | if (is_null($promo)) { |
413 | return PL_OK; |
414 | } |
415 | |
416 | $this->promo = $promo = intval($promo); |
417 | |
418 | if ($promo >= 1900 && $promo < intval(date('Y')) |
419 | || ($promo == -1 && has_perms())) |
420 | { |
421 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
422 | $trombi->hidePromo(); |
423 | $trombi->setAdmin(); |
424 | $page->assign_by_ref('trombi', $trombi); |
425 | } else { |
426 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
427 | } |
428 | |
429 | return PL_OK; |
430 | } |
e49018a7 |
431 | |
432 | function format_adr($params, &$smarty) |
433 | { |
434 | // $adr1, $adr2, $adr3, $postcode, $city, $region, $country |
435 | extract($params['adr']); |
436 | $adr = $adr1; |
437 | $adr = trim("$adr\n$adr2"); |
438 | $adr = trim("$adr\n$adr3"); |
439 | return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country"); |
440 | } |
441 | |
442 | function handler_vcard(&$page, $x = null) |
443 | { |
444 | if (is_null($x)) { |
445 | return PL_NOT_FOUND; |
446 | } |
447 | |
448 | global $globals; |
449 | |
450 | if (substr($x, -4) == '.vcf') { |
451 | $x = substr($x, 0, strlen($x) - 4); |
452 | } |
453 | |
454 | new_nonhtml_page('vcard.tpl', AUTH_COOKIE); |
455 | require_once 'xorg.misc.inc.php'; |
456 | require_once 'user.func.inc.php'; |
457 | |
458 | $page->register_modifier('qp_enc', 'quoted_printable_encode'); |
459 | $page->register_function('format_adr', array($this, 'format_adr')); |
460 | |
461 | $login = get_user_forlife($x); |
462 | $user = get_user_details($login); |
463 | |
464 | // alias virtual |
465 | $res = $globals->xdb->query( |
466 | "SELECT alias |
467 | FROM virtual |
468 | INNER JOIN virtual_redirect USING(vid) |
469 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
470 | WHERE ( redirect={?} OR redirect={?} ) |
471 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
472 | Session::getInt('uid'), |
473 | $user['forlife'].'@'.$globals->mail->domain, |
474 | $user['forlife'].'@'.$globals->mail->domain2); |
475 | |
476 | $user['virtualalias'] = $res->fetchOneCell(); |
477 | |
478 | $page->assign_by_ref('vcard', $user); |
479 | |
480 | header("Pragma: "); |
481 | header("Cache-Control: "); |
482 | header("Content-type: text/x-vcard\n"); |
483 | header("Content-Transfer-Encoding: Quoted-Printable\n"); |
484 | |
485 | return PL_OK; |
486 | } |
7d8b17cb |
487 | } |
488 | |
489 | ?> |