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( |
926f16d7 |
27 | 'photo' => $this->make_hook('photo', AUTH_PUBLIC), |
28 | 'photo/change' => $this->make_hook('photo_change', AUTH_MDP), |
e49018a7 |
29 | |
926f16d7 |
30 | 'profile/usage' => $this->make_hook('p_usage', AUTH_MDP), |
e49018a7 |
31 | |
926f16d7 |
32 | 'trombi' => $this->make_hook('trombi', AUTH_COOKIE), |
33 | |
34 | 'vcard' => $this->make_hook('vcard', AUTH_COOKIE), |
7d8b17cb |
35 | ); |
36 | } |
37 | |
38 | function _trombi_getlist($offset, $limit) |
39 | { |
40 | global $globals; |
41 | |
42 | $where = ( $this->promo > 0 ? "WHERE promo='{$this->promo}'" : "" ); |
43 | |
44 | $res = $globals->xdb->query( |
45 | "SELECT COUNT(*) |
46 | FROM auth_user_md5 AS u |
47 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
48 | $where"); |
49 | $pnb = $res->fetchOneCell(); |
50 | |
51 | $res = $globals->xdb->query( |
52 | "SELECT promo,user_id,a.alias AS forlife,IF(nom_usage='', nom, nom_usage) AS nom,prenom |
53 | FROM photo AS p |
54 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
55 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
56 | $where |
57 | ORDER BY promo,nom,prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
58 | |
59 | return array($pnb, $res->fetchAllAssoc()); |
60 | } |
61 | |
adbdf493 |
62 | function handler_photo(&$page, $x = null, $req = null) |
63 | { |
64 | if (is_null($x)) { |
65 | return PL_NOT_FOUND; |
66 | } |
67 | |
68 | global $globals; |
69 | |
70 | $res = $globals->xdb->query("SELECT id, pub FROM aliases |
71 | LEFT JOIN photo ON(id = uid) |
72 | WHERE alias = {?}", $x); |
73 | list($uid, $photo_pub) = $res->fetchOneRow(); |
74 | |
75 | if ($req && logged()) { |
76 | include 'validations.inc.php'; |
77 | $myphoto = PhotoReq::get_request($uid); |
78 | Header('Content-type: image/'.$myphoto->mimetype); |
79 | echo $myphoto->data; |
80 | } else { |
81 | $res = $globals->xdb->query( |
82 | "SELECT attachmime, attach |
83 | FROM photo |
84 | WHERE uid={?}", $uid); |
85 | |
86 | if ((list($type,$data) = $res->fetchOneRow()) && ($photo_pub == 'public' || logged())) { |
87 | Header("Content-type: image/$type"); |
88 | echo $data; |
89 | } else { |
90 | Header('Content-type: image/png'); |
fb9a56cb |
91 | echo file_get_contents(dirname(__FILE__).'/../htdocs/images/none.png'); |
adbdf493 |
92 | } |
93 | } |
94 | exit; |
95 | } |
96 | |
fb9a56cb |
97 | function handler_photo_change(&$page) |
98 | { |
99 | global $globals; |
100 | |
101 | $page->changeTpl('trombino.tpl'); |
102 | |
103 | require_once('validations.inc.php'); |
104 | |
105 | $trombi_x = '/home/web/trombino/photos'.Session::get('promo') |
106 | .'/'.Session::get('forlife').'.jpg'; |
107 | |
108 | if (Env::has('upload')) { |
109 | $file = isset($_FILES['userfile']['tmp_name']) |
110 | ? $_FILES['userfile']['tmp_name'] |
111 | : Env::get('photo'); |
112 | if ($data = file_get_contents($file)) { |
113 | if ($myphoto = new PhotoReq(Session::getInt('uid'), $data)) { |
114 | $myphoto->submit(); |
115 | } |
116 | } else { |
117 | $page->trig('Fichier inexistant ou vide'); |
118 | } |
119 | } elseif (Env::has('trombi')) { |
120 | $myphoto = new PhotoReq(Session::getInt('uid'), |
121 | file_get_contents($trombi_x)); |
122 | if ($myphoto) { |
123 | $myphoto->commit(); |
124 | $myphoto->clean(); |
125 | } |
126 | } elseif (Env::get('suppr')) { |
127 | $globals->xdb->execute('DELETE FROM photo WHERE uid = {?}', |
128 | Session::getInt('uid')); |
129 | $globals->xdb->execute('DELETE FROM requests |
130 | WHERE user_id = {?} AND type="photo"', |
131 | Session::getInt('uid')); |
132 | } elseif (Env::get('cancel')) { |
133 | $sql = $globals->xdb->query('DELETE FROM requests |
134 | WHERE user_id={?} AND type="photo"', |
135 | Session::getInt('uid')); |
136 | } |
137 | |
138 | $sql = $globals->xdb->query('SELECT COUNT(*) FROM requests |
139 | WHERE user_id={?} AND type="photo"', |
140 | Session::getInt('uid')); |
141 | $page->assign('submited', $sql->fetchOneCell()); |
142 | $page->assign('has_trombi_x', file_exists($trombi_x)); |
143 | |
144 | return PL_OK; |
145 | } |
146 | |
926f16d7 |
147 | function handler_p_usage(&$page) |
148 | { |
149 | global $globals; |
150 | |
151 | $page->changeTpl('nomusage.tpl'); |
152 | |
153 | require_once 'validations.inc.php'; |
154 | require_once 'xorg.misc.inc.php'; |
155 | |
156 | $res = $globals->xdb->query( |
157 | "SELECT u.nom,u.nom_usage,u.flags,e.alias |
158 | FROM auth_user_md5 AS u |
159 | LEFT JOIN aliases AS e ON(u.user_id = e.id AND FIND_IN_SET('usage',e.flags)) |
160 | WHERE user_id={?}", Session::getInt('uid')); |
161 | |
162 | list($nom,$usage_old,$flags,$alias_old) = $res->fetchOneRow(); |
163 | $flags = new flagset($flags); |
164 | $page->assign('usage_old', $usage_old); |
165 | $page->assign('alias_old', $alias_old); |
166 | |
167 | $nom_usage = replace_accent(trim(Env::get('nom_usage'))); |
168 | $nom_usage = strtoupper($nom_usage); |
169 | $page->assign('usage_req', $nom_usage); |
170 | |
171 | if (Env::has('submit') && ($nom_usage != $usage_old)) { |
172 | // on vient de recevoir une requete, differente de l'ancien nom d'usage |
173 | if ($nom_usage == $nom) { |
174 | $page->assign('same', true); |
175 | } else { // le nom de mariage est distinct du nom à l'X |
176 | // on calcule l'alias pour l'afficher |
177 | $reason = Env::get('reason'); |
178 | if ($reason == 'other') { |
179 | $reason = Env::get('other_reason'); |
180 | } |
181 | $myusage = new UsageReq(Session::getInt('uid'), $nom_usage, $reason); |
182 | $myusage->submit(); |
183 | $page->assign('myusage', $myusage); |
184 | } |
185 | } |
186 | |
187 | return PL_OK; |
188 | } |
189 | |
7d8b17cb |
190 | function handler_trombi(&$page, $promo = null) |
191 | { |
192 | require_once 'trombi.inc.php'; |
193 | |
194 | $page->changeTpl('trombipromo.tpl'); |
195 | $page->assign('xorg_title','Polytechnique.org - Trombi Promo'); |
196 | |
197 | if (is_null($promo)) { |
198 | return PL_OK; |
199 | } |
200 | |
201 | $this->promo = $promo = intval($promo); |
202 | |
203 | if ($promo >= 1900 && $promo < intval(date('Y')) |
204 | || ($promo == -1 && has_perms())) |
205 | { |
206 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
207 | $trombi->hidePromo(); |
208 | $trombi->setAdmin(); |
209 | $page->assign_by_ref('trombi', $trombi); |
210 | } else { |
211 | $page->trig('Promotion incorrecte (saisir au format YYYY). Recommence.'); |
212 | } |
213 | |
214 | return PL_OK; |
215 | } |
e49018a7 |
216 | |
217 | function format_adr($params, &$smarty) |
218 | { |
219 | // $adr1, $adr2, $adr3, $postcode, $city, $region, $country |
220 | extract($params['adr']); |
221 | $adr = $adr1; |
222 | $adr = trim("$adr\n$adr2"); |
223 | $adr = trim("$adr\n$adr3"); |
224 | return quoted_printable_encode(";;$adr;$city;$region;$postcode;$country"); |
225 | } |
226 | |
227 | function handler_vcard(&$page, $x = null) |
228 | { |
229 | if (is_null($x)) { |
230 | return PL_NOT_FOUND; |
231 | } |
232 | |
233 | global $globals; |
234 | |
235 | if (substr($x, -4) == '.vcf') { |
236 | $x = substr($x, 0, strlen($x) - 4); |
237 | } |
238 | |
239 | new_nonhtml_page('vcard.tpl', AUTH_COOKIE); |
240 | require_once 'xorg.misc.inc.php'; |
241 | require_once 'user.func.inc.php'; |
242 | |
243 | $page->register_modifier('qp_enc', 'quoted_printable_encode'); |
244 | $page->register_function('format_adr', array($this, 'format_adr')); |
245 | |
246 | $login = get_user_forlife($x); |
247 | $user = get_user_details($login); |
248 | |
249 | // alias virtual |
250 | $res = $globals->xdb->query( |
251 | "SELECT alias |
252 | FROM virtual |
253 | INNER JOIN virtual_redirect USING(vid) |
254 | INNER JOIN auth_user_quick ON ( user_id = {?} AND emails_alias_pub = 'public' ) |
255 | WHERE ( redirect={?} OR redirect={?} ) |
256 | AND alias LIKE '%@{$globals->mail->alias_dom}'", |
257 | Session::getInt('uid'), |
258 | $user['forlife'].'@'.$globals->mail->domain, |
259 | $user['forlife'].'@'.$globals->mail->domain2); |
260 | |
261 | $user['virtualalias'] = $res->fetchOneCell(); |
262 | |
263 | $page->assign_by_ref('vcard', $user); |
264 | |
265 | header("Pragma: "); |
266 | header("Cache-Control: "); |
267 | header("Content-type: text/x-vcard\n"); |
268 | header("Content-Transfer-Encoding: Quoted-Printable\n"); |
269 | |
270 | return PL_OK; |
271 | } |
7d8b17cb |
272 | } |
273 | |
274 | ?> |