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