2ecfc8730318da2a9b79def4674aa0f086848115
2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class ProfileModule
extends PLModule
27 'photo' => $this->make_hook('photo', AUTH_PUBLIC
),
28 'photo/change' => $this->make_hook('photo_change', AUTH_MDP
),
30 'profile/orange' => $this->make_hook('p_orange', AUTH_MDP
),
31 'profile/referent' => $this->make_hook('p_referent', AUTH_MDP
),
32 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP
),
34 'trombi' => $this->make_hook('trombi', AUTH_COOKIE
),
36 'vcard' => $this->make_hook('vcard', AUTH_COOKIE
),
40 function _trombi_getlist($offset, $limit)
44 $where = ( $this->promo
> 0 ?
"WHERE promo='{$this->promo}'" : "" );
46 $res = $globals->xdb
->query(
48 FROM auth_user_md5 AS u
49 RIGHT JOIN photo AS p ON u.user_id=p.uid
51 $pnb = $res->fetchOneCell();
53 $res = $globals->xdb
->query(
54 "SELECT promo,user_id,a.alias AS forlife,IF(nom_usage='', nom, nom_usage) AS nom,prenom
56 INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid
57 INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' )
59 ORDER BY promo,nom,prenom LIMIT {?}, {?}", $offset*$limit, $limit);
61 return array($pnb, $res->fetchAllAssoc());
64 function handler_photo(&$page, $x = null
, $req = null
)
72 $res = $globals->xdb
->query("SELECT id, pub FROM aliases
73 LEFT JOIN photo ON(id = uid)
74 WHERE alias = {?}", $x);
75 list($uid, $photo_pub) = $res->fetchOneRow();
77 if ($req && logged()) {
78 include 'validations.inc.php';
79 $myphoto = PhotoReq
::get_request($uid);
80 Header('Content-type: image/'.$myphoto->mimetype
);
83 $res = $globals->xdb
->query(
84 "SELECT attachmime, attach
86 WHERE uid={?}", $uid);
88 if ((list($type,$data) = $res->fetchOneRow()) && ($photo_pub == 'public' ||
logged())) {
89 Header("Content-type: image/$type");
92 Header('Content-type: image/png');
93 echo file_get_contents(dirname(__FILE__
).'/../htdocs/images/none.png');
99 function handler_photo_change(&$page)
103 $page->changeTpl('trombino.tpl');
105 require_once('validations.inc.php');
107 $trombi_x = '/home/web/trombino/photos'.Session
::get('promo')
108 .'/'.Session
::get('forlife').'.jpg';
110 if (Env
::has('upload')) {
111 $file = isset($_FILES['userfile']['tmp_name'])
112 ?
$_FILES['userfile']['tmp_name']
114 if ($data = file_get_contents($file)) {
115 if ($myphoto = new PhotoReq(Session
::getInt('uid'), $data)) {
119 $page->trig('Fichier inexistant ou vide');
121 } elseif (Env
::has('trombi')) {
122 $myphoto = new PhotoReq(Session
::getInt('uid'),
123 file_get_contents($trombi_x));
128 } elseif (Env
::get('suppr')) {
129 $globals->xdb
->execute('DELETE FROM photo WHERE uid = {?}',
130 Session
::getInt('uid'));
131 $globals->xdb
->execute('DELETE FROM requests
132 WHERE user_id = {?} AND type="photo"',
133 Session
::getInt('uid'));
134 } elseif (Env
::get('cancel')) {
135 $sql = $globals->xdb
->query('DELETE FROM requests
136 WHERE user_id={?} AND type="photo"',
137 Session
::getInt('uid'));
140 $sql = $globals->xdb
->query('SELECT COUNT(*) FROM requests
141 WHERE user_id={?} AND type="photo"',
142 Session
::getInt('uid'));
143 $page->assign('submited', $sql->fetchOneCell());
144 $page->assign('has_trombi_x', file_exists($trombi_x));
149 function handler_p_orange(&$page)
153 $page->changeTpl('orange.tpl');
155 require_once 'validations.inc.php';
156 require_once 'xorg.misc.inc.php';
158 $res = $globals->xdb
->query(
159 "SELECT u.promo,u.promo_sortie
160 FROM auth_user_md5 AS u
161 WHERE user_id={?}", Session
::getInt('uid'));
163 list($promo,$promo_sortie_old) = $res->fetchOneRow();
164 $page->assign('promo_sortie_old', $promo_sortie_old);
165 $page->assign('promo', $promo);
167 if (!Env
::has('promo_sortie')) {
171 $promo_sortie = Env
::getInt('promo_sortie');
173 if ($promo_sortie < 1000 ||
$promo_sortie > 9999) {
174 $page->trig('L\'année de sortie doit être un nombre de quatre chiffres');
176 elseif ($promo_sortie < $promo +
3) {
177 $page->trig('Trop tôt');
179 elseif ($promo_sortie == $promo_sortie_old) {
180 $page->trig('Tu appartiens déjà à la promotion correspondante à cette année de sortie.');
182 elseif ($promo_sortie == $promo +
3) {
183 $globals->xdb
->execute(
184 "UPDATE auth_user_md5 set promo_sortie={?}
185 WHERE user_id={?}",$promo_sortie,Session
::getInt('uid'));
186 $page->trig('Ton statut "orange" a été supprimé.');
187 $page->assign('promo_sortie_old', $promo_sortie);
190 $page->assign('promo_sortie', $promo_sortie);
192 if (Env
::has('submit')) {
193 $myorange = new OrangeReq(Session
::getInt('uid'),
196 $page->assign('myorange', $myorange);
203 function handler_p_referent(&$page, $x = null
)
207 require_once 'user.func.inc.php';
213 $page->changeTpl('fiche_referent.tpl');
214 $page->assign('simple', true
);
216 $res = $globals->xdb
->query(
217 "SELECT prenom, nom, user_id, promo, cv, a.alias AS bestalias
218 FROM auth_user_md5 AS u
219 INNER JOIN aliases AS a ON (u.user_id=a.id AND FIND_IN_SET('bestalias',a.flags))
220 INNER JOIN aliases AS a1 ON (u.user_id=a1.id
222 AND a1.type!='homonyme')", $x);
224 if ($res->numRows() != 1) {
228 list($prenom, $nom, $user_id, $promo, $cv, $bestalias) = $res->fetchOneRow();
230 $page->assign('prenom', $prenom);
231 $page->assign('nom', $nom);
232 $page->assign('promo', $promo);
233 $page->assign('cv', $cv);
234 $page->assign('bestalias', $bestalias);
235 $page->assign('adr_pro', get_user_details_pro($user_id));
237 ///// recuperations infos referent
240 $res = $globals->xdb
->query("SELECT expertise FROM mentor WHERE uid = {?}", $user_id);
241 $page->assign('expertise', $res->fetchOneCell());
244 $secteurs = $ss_secteurs = Array();
245 $res = $globals->xdb
->iterRow(
246 "SELECT s.label, ss.label
247 FROM mentor_secteurs AS m
248 LEFT JOIN emploi_secteur AS s ON(m.secteur = s.id)
249 LEFT JOIN emploi_ss_secteur AS ss ON(m.secteur = ss.secteur AND m.ss_secteur = ss.id)
250 WHERE uid = {?}", $user_id);
251 while (list($sec, $ssec) = $res->next()) {
253 $ss_secteurs[] = $ssec;
255 $page->assign_by_ref('secteurs', $secteurs);
256 $page->assign_by_ref('ss_secteurs', $ss_secteurs);
259 $res = $globals->xdb
->query(
261 FROM mentor_pays AS m
262 LEFT JOIN geoloc_pays AS gp ON(m.pid = gp.a2)
263 WHERE uid = {?}", $user_id);
264 $page->assign('pays', $res->fetchColumn());
266 $page->addJsLink('javascript/close_on_esc.js');
270 function handler_p_usage(&$page)
274 $page->changeTpl('nomusage.tpl');
276 require_once 'validations.inc.php';
277 require_once 'xorg.misc.inc.php';
279 $res = $globals->xdb
->query(
280 "SELECT u.nom,u.nom_usage,u.flags,e.alias
281 FROM auth_user_md5 AS u
282 LEFT JOIN aliases AS e ON(u.user_id = e.id AND FIND_IN_SET('usage',e.flags))
283 WHERE user_id={?}", Session
::getInt('uid'));
285 list($nom,$usage_old,$flags,$alias_old) = $res->fetchOneRow();
286 $flags = new flagset($flags);
287 $page->assign('usage_old', $usage_old);
288 $page->assign('alias_old', $alias_old);
290 $nom_usage = replace_accent(trim(Env
::get('nom_usage')));
291 $nom_usage = strtoupper($nom_usage);
292 $page->assign('usage_req', $nom_usage);
294 if (Env
::has('submit') && ($nom_usage != $usage_old)) {
295 // on vient de recevoir une requete, differente de l'ancien nom d'usage
296 if ($nom_usage == $nom) {
297 $page->assign('same', true
);
298 } else { // le nom de mariage est distinct du nom à l'X
299 // on calcule l'alias pour l'afficher
300 $reason = Env
::get('reason');
301 if ($reason == 'other') {
302 $reason = Env
::get('other_reason');
304 $myusage = new UsageReq(Session
::getInt('uid'), $nom_usage, $reason);
306 $page->assign('myusage', $myusage);
313 function handler_trombi(&$page, $promo = null
)
315 require_once 'trombi.inc.php';
317 $page->changeTpl('trombipromo.tpl');
318 $page->assign('xorg_title','Polytechnique.org - Trombi Promo');
320 if (is_null($promo)) {
324 $this->promo
= $promo = intval($promo);
326 if ($promo >= 1900 && $promo < intval(date('Y'))
327 ||
($promo == -1 && has_perms()))
329 $trombi = new Trombi(array($this, '_trombi_getlist'));
330 $trombi->hidePromo();
332 $page->assign_by_ref('trombi', $trombi);
334 $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.');
340 function format_adr($params, &$smarty)
342 // $adr1, $adr2, $adr3, $postcode, $city, $region, $country
343 extract($params['adr']);
345 $adr = trim("$adr\n$adr2");
346 $adr = trim("$adr\n$adr3");
347 return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country");
350 function handler_vcard(&$page, $x = null
)
358 if (substr($x, -4) == '.vcf') {
359 $x = substr($x, 0, strlen($x) - 4);
362 new_nonhtml_page('vcard.tpl', AUTH_COOKIE
);
363 require_once 'xorg.misc.inc.php';
364 require_once 'user.func.inc.php';
366 $page->register_modifier('qp_enc', 'quoted_printable_encode');
367 $page->register_function('format_adr', array($this, 'format_adr'));
369 $login = get_user_forlife($x);
370 $user = get_user_details($login);
373 $res = $globals->xdb
->query(
376 INNER JOIN virtual_redirect USING(vid)
377 INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' )
378 WHERE ( redirect={?} OR redirect={?} )
379 AND alias LIKE '%@{$globals->mail->alias_dom}'",
380 Session
::getInt('uid'),
381 $user['forlife'].'@'.$globals->mail
->domain
,
382 $user['forlife'].'@'.$globals->mail
->domain2
);
384 $user['virtualalias'] = $res->fetchOneCell();
386 $page->assign_by_ref('vcard', $user);
389 header("Cache-Control: ");
390 header("Content-type: text/x-vcard\n");
391 header("Content-Transfer-Encoding: Quoted-Printable\n");