ae7bb180 |
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 | |
ef7c8560 |
22 | function get_infos($email) |
23 | { |
24 | global $globals; |
25 | // look for uid instead of email if numeric |
ed21e24a |
26 | $field = is_numeric($email) ? 'uid' : 'email'; |
ef7c8560 |
27 | |
28 | if ($field == 'email') { |
29 | $email = strtolower($email); |
30 | if (strpos($email, '@') === false) { |
31 | $email .= '@m4x.org'; |
32 | } |
33 | list($mbox,$dom) = explode('@', $email); |
34 | } |
35 | |
08cce2ff |
36 | $res = XDB::query( |
dc2073c3 |
37 | "SELECT uid, nom, prenom, email, email AS email2, perms='admin', origine, sexe |
ef7c8560 |
38 | FROM groupex.membres |
39 | WHERE $field = {?} AND asso_id = {?}", $email, $globals->asso('id')); |
40 | |
41 | if ($res->numRows()) { |
dc2073c3 |
42 | $user = $res->fetchOneAssoc(); |
43 | if ($user['origine'] == 'X') { |
44 | $res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET(flags, 'femme') AS sexe |
45 | FROM auth_user_md5 |
46 | WHERE user_id = {?}", $user['uid']); |
47 | $user = array_merge($user, $res->fetchOneAssoc()); |
48 | } |
49 | return $user; |
ef7c8560 |
50 | } elseif ($dom == 'polytechnique.org' || $dom == 'm4x.org') { |
08cce2ff |
51 | $res = XDB::query( |
ef7c8560 |
52 | "SELECT user_id AS uid, u.promo, |
53 | IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, |
54 | u.prenom, b.alias, |
55 | CONCAT(b.alias, '@m4x.org') AS email, |
56 | CONCAT(b.alias, '@polytechnique.org') AS email2, |
dc2073c3 |
57 | m.perms='admin' AS perms, m.origine, |
b94c80bd |
58 | FIND_IN_SET(u.flags, 'femme') AS sexe |
ef7c8560 |
59 | FROM auth_user_md5 AS u |
60 | INNER JOIN aliases AS a ON ( u.user_id = a.id AND a.type != 'homonyme' ) |
61 | INNER JOIN aliases AS b ON ( u.user_id = b.id AND b.type = 'a_vie' ) |
62 | INNER JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?}) |
63 | WHERE a.alias = {?} AND u.user_id < 50000", $globals->asso('id'), $mbox); |
64 | return $res->fetchOneAssoc(); |
65 | } |
66 | |
67 | return null; |
68 | } |
69 | |
70 | |
ae7bb180 |
71 | class XnetGrpModule extends PLModule |
72 | { |
73 | function handlers() |
74 | { |
75 | return array( |
5e193297 |
76 | '%grp' => $this->make_hook('index', AUTH_PUBLIC), |
77 | '%grp/asso.php' => $this->make_hook('index', AUTH_PUBLIC), |
78 | '%grp/logo' => $this->make_hook('logo', AUTH_PUBLIC), |
79 | '%grp/edit' => $this->make_hook('edit', AUTH_MDP), |
80 | '%grp/mail' => $this->make_hook('mail', AUTH_MDP), |
81 | '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP), |
82 | '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP), |
28929cf0 |
83 | '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP), |
5e193297 |
84 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
85 | '%grp/paiement' => $this->make_hook('paiement', AUTH_MDP), |
4e310c61 |
86 | |
d1ebc57a |
87 | '%grp/admin/annuaire' |
4e310c61 |
88 | => $this->make_hook('admin_annuaire', AUTH_MDP), |
ef7c8560 |
89 | |
d1ebc57a |
90 | '%grp/member' |
ef7c8560 |
91 | => $this->make_hook('admin_member', AUTH_MDP), |
d1ebc57a |
92 | '%grp/member/new' |
ef7c8560 |
93 | => $this->make_hook('admin_member_new', AUTH_MDP), |
dc2073c3 |
94 | '%grp/member/new/ajax' |
95 | => $this->make_hook('admin_member_new_ajax', AUTH_MDP, '', NO_AUTH), |
d1ebc57a |
96 | '%grp/member/del' |
ef7c8560 |
97 | => $this->make_hook('admin_member_del', AUTH_MDP), |
24bcf50c |
98 | |
99 | '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC), |
100 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP), |
101 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP), |
102 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP), |
ae7bb180 |
103 | ); |
104 | } |
105 | |
2e94d2b8 |
106 | function handler_index(&$page, $arg = null) |
ae7bb180 |
107 | { |
24bcf50c |
108 | global $globals, $platal; |
ae7bb180 |
109 | |
2e94d2b8 |
110 | if (!is_null($arg)) { |
ae7bb180 |
111 | return PL_NOT_FOUND; |
112 | } |
113 | |
d24c8a11 |
114 | new_group_open_page('xnet/groupe/asso.tpl'); |
ae7bb180 |
115 | |
24bcf50c |
116 | if (S::logged()) { |
117 | if (Env::has('read')) { |
118 | XDB::query('DELETE r.* |
119 | FROM groupex.announces_read AS r |
120 | INNER JOIN groupex.announces AS a ON a.id = r.announce_id |
121 | WHERE peremption < CURRENT_DATE()'); |
122 | XDB::query('INSERT INTO groupex.announces_read |
123 | VALUES ({?}, {?})', |
124 | Env::i('read'), S::i('uid')); |
125 | pl_redirect(""); |
126 | } |
127 | if (Env::has('unread')) { |
128 | XDB::query('DELETE FROM groupex.announces_read |
129 | WHERE announce_id={?} AND user_id={?}', |
130 | Env::i('unread'), S::i('uid')); |
131 | pl_redirect("#art" . Env::i('unread')); |
132 | } |
133 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife |
134 | FROM groupex.announces AS a |
135 | INNER JOIN auth_user_md5 AS u USING(user_id) |
136 | INNER JOIN aliases AS l ON (u.user_id = l.id AND l.type = 'a_vie') |
137 | LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id) |
138 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
139 | AND (promo_min = 0 OR promo_min <= {?}) |
140 | AND (promo_max = 0 OR promo_max >= {?}) |
141 | AND r.announce_id IS NULL |
142 | ORDER BY a.peremption", |
143 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); |
144 | $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu |
145 | FROM groupex.announces AS a |
146 | LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?}) |
147 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
148 | AND (promo_min = 0 OR promo_min <= {?}) |
149 | AND (promo_max = 0 OR promo_max >= {?}) |
150 | ORDER BY a.peremption", |
151 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); |
152 | $page->assign('article_index', $index); |
153 | } else { |
154 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo |
155 | FROM groupex.announces AS a |
156 | INNER JOIN auth_user_md5 AS u USING(user_id) |
157 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() |
2a557a09 |
158 | AND FIND_IN_SET(a.flags, 'public')", |
24bcf50c |
159 | $globals->asso('id')); |
160 | } |
161 | |
162 | if (!S::has('core_rss_hash')) { |
163 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", |
164 | "rss/rss.xml"); |
165 | } else { |
166 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", |
167 | 'rss/'.S::v('forlife') .'/'.S::v('core_rss_hash').'/rss.xml'); |
168 | } |
169 | |
170 | require_once('url_catcher.inc.php'); |
171 | $page->register_modifier('url_catcher', 'url_catcher'); |
172 | $page->assign('articles', $arts); |
173 | |
ae7bb180 |
174 | $page->assign('asso', $globals->asso()); |
175 | } |
dd798f38 |
176 | |
177 | function handler_logo(&$page) |
178 | { |
179 | global $globals; |
180 | |
08cce2ff |
181 | $res = XDB::query("SELECT logo, logo_mime |
24bcf50c |
182 | FROM groupex.asso WHERE id = {?}", |
183 | $globals->asso('id')); |
dd798f38 |
184 | list($logo, $logo_mime) = $res->fetchOneRow(); |
185 | |
186 | if (!empty($logo)) { |
187 | header("Content-type: $mime"); |
188 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
189 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
190 | header('Cache-Control: no-cache, must-revalidate'); |
191 | header('Pragma: no-cache'); |
192 | echo $logo; |
193 | } else { |
194 | header('Content-type: image/jpeg'); |
195 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
196 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); |
197 | header('Cache-Control: no-cache, must-revalidate'); |
198 | header('Pragma: no-cache'); |
831fae47 |
199 | readfile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg'); |
dd798f38 |
200 | } |
201 | |
202 | exit; |
203 | } |
2e94d2b8 |
204 | |
205 | function handler_edit(&$page) |
206 | { |
207 | global $globals; |
208 | |
209 | new_groupadmin_page('xnet/groupe/edit.tpl'); |
210 | |
211 | if (Post::has('submit')) { |
cab08090 |
212 | if (S::has_perms()) { |
5e2307dc |
213 | if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { |
c9110c6c |
214 | $page->trig("le domaine doit être un FQDN (aucune modif effectuée) !!!"); |
215 | return; |
2e94d2b8 |
216 | } |
08cce2ff |
217 | XDB::execute( |
2e94d2b8 |
218 | "UPDATE groupex.asso |
219 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, |
220 | descr={?}, site={?}, mail={?}, resp={?}, |
221 | forum={?}, mail_domain={?}, ax={?}, pub={?}, |
222 | sub_url={?}, inscriptible={?} |
223 | WHERE id={?}", |
5e2307dc |
224 | Post::v('nom'), Post::v('diminutif'), |
225 | Post::v('cat'), Post::i('dom'), |
226 | Post::v('descr'), Post::v('site'), |
227 | Post::v('mail'), Post::v('resp'), |
228 | Post::v('forum'), Post::v('mail_domain'), |
2e94d2b8 |
229 | Post::has('ax'), Post::has('pub')?'private':'public', |
5e2307dc |
230 | Post::v('sub_url'), Post::v('inscriptible'), |
2e94d2b8 |
231 | $globals->asso('id')); |
5e2307dc |
232 | if (Post::v('mail_domain')) { |
08cce2ff |
233 | XDB::execute('INSERT INTO virtual_domains (domain) VALUES({?})', |
5e2307dc |
234 | Post::v('mail_domain')); |
2e94d2b8 |
235 | } |
236 | } else { |
08cce2ff |
237 | XDB::execute( |
2e94d2b8 |
238 | "UPDATE groupex.asso |
239 | SET descr={?}, site={?}, mail={?}, resp={?}, |
240 | forum={?}, ax={?}, pub= {?}, sub_url={?} |
241 | WHERE id={?}", |
5e2307dc |
242 | Post::v('descr'), Post::v('site'), |
243 | Post::v('mail'), Post::v('resp'), |
244 | Post::v('forum'), Post::has('ax'), |
2e94d2b8 |
245 | Post::has('pub')?'private':'public', |
5e2307dc |
246 | Post::v('sub_url'), $globals->asso('id')); |
2e94d2b8 |
247 | } |
248 | |
249 | if ($_FILES['logo']['name']) { |
250 | $logo = file_get_contents($_FILES['logo']['tmp_name']); |
251 | $mime = $_FILES['logo']['type']; |
08cce2ff |
252 | XDB::execute('UPDATE groupex.asso |
2e94d2b8 |
253 | SET logo={?}, logo_mime={?} |
254 | WHERE id={?}', $logo, $mime, |
255 | $globals->asso('id')); |
256 | } |
257 | |
5e2307dc |
258 | pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); |
2e94d2b8 |
259 | } |
260 | |
cab08090 |
261 | if (S::has_perms()) { |
08cce2ff |
262 | $dom = XDB::iterator('SELECT * FROM groupex.dom ORDER BY nom'); |
2e94d2b8 |
263 | $page->assign('dom', $dom); |
264 | $page->assign('super', true); |
265 | } |
266 | } |
267 | |
479d2787 |
268 | function handler_mail(&$page) |
269 | { |
270 | global $globals; |
271 | |
479d2787 |
272 | new_groupadmin_page('xnet/groupe/mail.tpl'); |
9bb8bf21 |
273 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
274 | $globals->asso('mail_domain')); |
275 | $page->assign('listes', $mmlist->get_lists()); |
479d2787 |
276 | |
277 | if (Post::has('send')) { |
5e2307dc |
278 | $from = Post::v('from'); |
279 | $sujet = Post::v('sujet'); |
280 | $body = Post::v('body'); |
479d2787 |
281 | |
5e2307dc |
282 | $mls = array_keys(Env::v('ml', array())); |
479d2787 |
283 | |
284 | require_once 'xnet/mail.inc.php'; |
9bb8bf21 |
285 | $tos = get_all_redirects(Post::has('membres'), $mls, $mmlist); |
5e2307dc |
286 | send_xnet_mails($from, $sujet, $body, $tos, Post::v('replyto')); |
ef7c8560 |
287 | $page->kill("Mail envoyé !"); |
479d2787 |
288 | $page->assign('sent', true); |
289 | } |
290 | } |
291 | |
2e94d2b8 |
292 | function handler_annuaire(&$page) |
293 | { |
294 | global $globals; |
d24c8a11 |
295 | new_annu_page('xnet/groupe/annuaire.tpl'); |
2e94d2b8 |
296 | |
e02ecfce |
297 | $sort = Env::v('order'); |
5e2307dc |
298 | switch (Env::v('order')) { |
2e94d2b8 |
299 | case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break; |
300 | case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break; |
301 | case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break; |
e02ecfce |
302 | default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha'; |
2e94d2b8 |
303 | } |
e02ecfce |
304 | $page->assign('sort', $sort); |
2e94d2b8 |
305 | |
306 | if ($group == 'initiale') |
08cce2ff |
307 | $res = XDB::iterRow( |
2e94d2b8 |
308 | 'SELECT UPPER(SUBSTRING( |
dc2073c3 |
309 | IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom), |
2e94d2b8 |
310 | 1, 1)) as letter, COUNT(*) |
311 | FROM groupex.membres AS m |
312 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
313 | WHERE asso_id = {?} |
314 | GROUP BY letter |
315 | ORDER BY letter', $globals->asso('id')); |
316 | else |
08cce2ff |
317 | $res = XDB::iterRow( |
ef7c8560 |
318 | 'SELECT IF(m.origine="X",u.promo,"extérieur") AS promo, |
2e94d2b8 |
319 | COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o |
320 | FROM groupex.membres AS m |
321 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
322 | WHERE asso_id = {?} |
323 | GROUP BY promo |
324 | ORDER BY promo_o DESC', $globals->asso('id')); |
325 | |
326 | $alphabet = array(); |
327 | $nb_tot = 0; |
328 | while (list($char, $nb) = $res->next()) { |
329 | $alphabet[] = $char; |
330 | $nb_tot += $nb; |
5e2307dc |
331 | if (Env::has($group) && $char == strtoupper(Env::v($group))) { |
2e94d2b8 |
332 | $tot = $nb; |
333 | } |
334 | } |
335 | $page->assign('group', $group); |
5e2307dc |
336 | $page->assign('request_group', Env::v($group)); |
f2900e25 |
337 | $page->assign('only_admin', Env::has('admin')); |
2e94d2b8 |
338 | $page->assign('alphabet', $alphabet); |
339 | $page->assign('nb_tot', $nb_tot); |
340 | |
5e2307dc |
341 | $ofs = Env::i('offset'); |
342 | $tot = Env::v($group) ? $tot : $nb_tot; |
2e94d2b8 |
343 | $nbp = intval(($tot-1)/NB_PER_PAGE); |
344 | $links = array(); |
345 | if ($ofs) { |
ef7c8560 |
346 | $links['précédent'] = $ofs-1; |
2e94d2b8 |
347 | } |
348 | for ($i = 0; $i <= $nbp; $i++) { |
349 | $links[(string)($i+1)] = $i; |
350 | } |
351 | if ($ofs < $nbp) { |
352 | $links['suivant'] = $ofs+1; |
353 | } |
354 | if (count($links)>1) { |
355 | $page->assign('links', $links); |
356 | } |
357 | |
358 | $ini = ''; |
359 | if (Env::has('initiale')) { |
360 | $ini = 'AND IF(m.origine="X", |
361 | IF(u.nom_usage<>"", u.nom_usage, u.nom), |
5e2307dc |
362 | m.nom) LIKE "'.addslashes(Env::v('initiale')).'%"'; |
2e94d2b8 |
363 | } elseif (Env::has('promo')) { |
ef7c8560 |
364 | $ini = 'AND IF(m.origine="X", u.promo, "extérieur") = "' |
5e2307dc |
365 | .addslashes(Env::v('promo')).'"'; |
f2900e25 |
366 | } elseif (Env::has('admin')) { |
367 | $ini = 'AND m.perms = "admin"'; |
2e94d2b8 |
368 | } |
369 | |
08cce2ff |
370 | $ann = XDB::iterator( |
2e94d2b8 |
371 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, |
372 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, |
ef7c8560 |
373 | IF(m.origine='X',u.promo,'extérieur') AS promo, |
2e94d2b8 |
374 | IF(m.origine='X',u.promo,'') AS promo_o, |
dc2073c3 |
375 | IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email, |
0cc4c07d |
376 | IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme, |
2e94d2b8 |
377 | m.perms='admin' AS admin, |
378 | m.origine='X' AS x, |
dc2073c3 |
379 | u.perms!='pending' AS inscrit, |
2e94d2b8 |
380 | m.uid |
381 | FROM groupex.membres AS m |
382 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) |
383 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' ) |
384 | WHERE m.asso_id = {?} $ini |
dc2073c3 |
385 | AND (m.origine = 'ext' OR u.perms != 'pending' OR m.email IS NOT NULL) |
2e94d2b8 |
386 | ORDER BY $tri |
387 | LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE); |
2e94d2b8 |
388 | $page->assign('ann', $ann); |
389 | } |
4e310c61 |
390 | |
28929cf0 |
391 | function handler_trombi(&$page, $num = 1) |
392 | { |
393 | global $globals; |
d24c8a11 |
394 | new_annu_page('xnet/groupe/trombi.tpl'); |
e02a82bc |
395 | |
28929cf0 |
396 | $page->assign('urlmainsite', "https://www.polytechnique.org/"); |
397 | $trombi = new Trombi(array($this, '_trombi_getlist')); |
398 | $trombi->hidePromo(); |
399 | $trombi->setAdmin(); |
400 | $page->assign_by_ref('trombi', $trombi); |
401 | } |
402 | |
403 | function _trombi_getlist($offset, $limit) |
404 | { |
405 | global $globals; |
406 | $where = "WHERE m.asso_id= '".addslashes($globals->asso('id'))."'"; |
407 | |
408 | $res = XDB::query( |
409 | "SELECT COUNT(*) |
410 | FROM auth_user_md5 AS u |
411 | RIGHT JOIN photo AS p ON u.user_id=p.uid |
412 | INNER JOIN groupex.membres AS m ON (m.uid = u.user_id) |
413 | $where"); |
414 | $pnb = $res->fetchOneCell(); |
415 | |
416 | $res = XDB::query("SELECT promo, user_id, a.alias AS forlife, |
417 | IF (nom_usage='', u.nom, nom_usage) AS nom, u.prenom |
418 | FROM photo AS p |
419 | INNER JOIN auth_user_md5 AS u ON u.user_id=p.uid |
420 | INNER JOIN aliases AS a ON ( u.user_id=a.id AND a.type='a_vie' ) |
421 | INNER JOIN groupex.membres AS m ON (m.uid = u.user_id) |
422 | $where |
423 | ORDER BY promo, u.nom, u.prenom LIMIT {?}, {?}", $offset*$limit, $limit); |
424 | |
425 | return array($pnb, $res->fetchAllAssoc()); |
426 | } |
427 | |
917c4d11 |
428 | function handler_vcard(&$page, $photos = null) |
5e193297 |
429 | { |
430 | global $globals; |
431 | |
432 | if (($globals->asso('pub') == 'public' && is_member()) || may_update()) { |
433 | $res = XDB::query('SELECT uid |
434 | FROM groupex.membres |
435 | WHERE asso_id = {?}', $globals->asso('id')); |
436 | require_once('vcard.inc.php'); |
917c4d11 |
437 | $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); |
5e193297 |
438 | $vcard->do_page($page); |
439 | } else { |
440 | return PL_NOTALLOWED; |
441 | } |
442 | } |
443 | |
fdf0200a |
444 | function handler_subscribe(&$page, $u = null) |
445 | { |
c8faf82a |
446 | global $globals; |
447 | |
d24c8a11 |
448 | new_group_open_page('xnet/groupe/inscrire.tpl'); |
fdf0200a |
449 | |
450 | if (!$globals->asso('inscriptible')) |
ef7c8560 |
451 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
452 | ."groupe. Essaie de joindre le contact indiqué " |
453 | ."sur la page de présentation."); |
fdf0200a |
454 | |
455 | if (!is_null($u) && may_update()) { |
456 | $page->assign('u', $u); |
08cce2ff |
457 | $res = XDB::query("SELECT nom, prenom, promo, user_id |
fdf0200a |
458 | FROM auth_user_md5 AS u |
459 | INNER JOIN aliases AS al ON (al.id = u.user_id |
460 | AND al.type != 'liste') |
461 | WHERE al.alias = {?}", $u); |
462 | |
463 | if (list($nom, $prenom, $promo, $uid) = $res->fetchOneRow()) { |
08cce2ff |
464 | $res = XDB::query("SELECT COUNT(*) |
fdf0200a |
465 | FROM groupex.membres AS m |
466 | INNER JOIN aliases AS a ON (m.uid = a.id |
467 | AND a.type != 'homonyme') |
468 | WHERE a.alias = {?} AND m.asso_id = {?}", |
469 | $u, $globals->asso('id')); |
470 | $n = $res->fetchOneCell(); |
471 | if ($n) { |
7192cdc5 |
472 | $page->kill("$prenom $nom est déjà membre du groupe !"); |
c9110c6c |
473 | return; |
fdf0200a |
474 | } |
475 | elseif (Env::has('accept')) |
476 | { |
08cce2ff |
477 | XDB::execute("INSERT INTO groupex.membres |
d501656a |
478 | VALUES ({?}, {?}, 'membre', 'X', NULL, NULL, NULL, NULL, NULL)", |
fdf0200a |
479 | $globals->asso('id'), $uid); |
480 | require_once 'diogenes/diogenes.hermes.inc.php'; |
481 | $mailer = new HermesMailer(); |
482 | $mailer->addTo("$u@polytechnique.org"); |
cab08090 |
483 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
484 | .'" <'.S::v('forlife').'@polytechnique.org>'); |
fdf0200a |
485 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
486 | $message = "Cher Camarade,\n" |
487 | . "\n" |
ef7c8560 |
488 | . " Suite à ta demande d'adhésion à ".$globals->asso('nom').",\n" |
489 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" |
fdf0200a |
490 | . "\n" |
491 | . "Bien cordialement,\n" |
492 | . "{$_SESSION["prenom"]} {$_SESSION["nom"]}."; |
493 | $mailer->setTxtBody($message); |
494 | $mailer->send(); |
ef7c8560 |
495 | $page->kill("$prenom $nom a bien été inscrit"); |
fdf0200a |
496 | } |
497 | elseif (Env::has('refuse')) |
498 | { |
499 | require_once 'diogenes/diogenes.hermes.inc.php'; |
500 | $mailer = new HermesMailer(); |
501 | $mailer->addTo("$u@polytechnique.org"); |
cab08090 |
502 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
503 | .'" <'.S::v('forlife').'@polytechnique.org>'); |
ef7c8560 |
504 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); |
5e2307dc |
505 | $mailer->setTxtBody(Env::v('motif')); |
fdf0200a |
506 | $mailer->send(); |
ef7c8560 |
507 | $page->kill("la demande $prenom $nom a bien été refusée"); |
fdf0200a |
508 | } else { |
509 | $page->assign('show_form', true); |
510 | $page->assign('prenom', $prenom); |
511 | $page->assign('nom', $nom); |
512 | $page->assign('promo', $promo); |
513 | $page->assign('uid', $uid); |
514 | } |
515 | return; |
516 | } |
517 | return PL_NOT_FOUND; |
518 | } |
519 | |
520 | if (is_member()) { |
ef7c8560 |
521 | $page->kill("tu es déjà membre !"); |
fdf0200a |
522 | return; |
523 | } |
524 | |
525 | if (Post::has('inscrire')) { |
08cce2ff |
526 | $res = XDB::query('SELECT IF(m.email IS NULL, |
fdf0200a |
527 | CONCAT(al.alias,"@polytechnique.org"), |
528 | m.email) |
529 | FROM groupex.membres AS m |
530 | INNER JOIN aliases AS al ON (al.type = "a_vie" |
531 | AND al.id = m.uid) |
532 | WHERE perms="admin" AND m.asso_id = {?}', |
533 | $globals->asso('id')); |
534 | $emails = $res->fetchColumn(); |
535 | $to = implode(',', $emails); |
536 | |
537 | $append = "\n" |
538 | . "-- \n" |
ef7c8560 |
539 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
cab08090 |
540 | . S::v('prenom').' '.S::v('nom').' (X'.S::v('promo').")\n" |
fdf0200a |
541 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
542 | . "de refuser sa demande d'inscription depuis la page :\n" |
543 | . |
544 | "http://www.polytechnique.net/".$globals->asso("diminutif")."/subscribe/" |
cab08090 |
545 | .S::v('forlife')."\n" |
fdf0200a |
546 | . "\n" |
ef7c8560 |
547 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
548 | . "à l'adresse : support@polytechnique.org\n"; |
fdf0200a |
549 | |
550 | if (!$to) { |
551 | $to = $globals->asso("mail").", support@polytechnique.org"; |
552 | $append = "\n-- \nLe groupe ".$globals->asso("nom") |
ef7c8560 |
553 | ." n'a pas d'administrateur, l'équipe de" |
554 | ." Polytechnique.org a été prévenue et va rapidement" |
555 | ." résoudre ce problème.\n"; |
fdf0200a |
556 | } |
557 | |
558 | require_once 'diogenes/diogenes.hermes.inc.php'; |
559 | $mailer = new HermesMailer(); |
560 | $mailer->addTo($to); |
cab08090 |
561 | $mailer->setFrom('"'.S::v('prenom').' '.S::v('nom') |
562 | .'" <'.S::v('forlife').'@polytechnique.org>'); |
fdf0200a |
563 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc |
564 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a |
565 | $mailer->send(); |
566 | } |
567 | } |
568 | |
75687bb9 |
569 | function handler_paiement(&$page) |
570 | { |
571 | global $globals; |
572 | |
573 | new_group_page('xnet/groupe/telepaiement.tpl'); |
574 | |
08cce2ff |
575 | $res = XDB::query( |
75687bb9 |
576 | "SELECT id, text |
577 | FROM {$globals->money->mpay_tprefix}paiements |
578 | WHERE asso_id = {?} AND NOT FIND_IN_SET(flags, 'old') |
579 | ORDER BY id DESC", $globals->asso('id')); |
580 | $tit = $res->fetchAllAssoc(); |
581 | $page->assign('titres', $tit); |
582 | |
5e2307dc |
583 | $order = Env::v('order', 'timestamp'); |
75687bb9 |
584 | $orders = array('timestamp', 'nom', 'promo', 'montant'); |
585 | if (!in_array($order, $orders)) { |
586 | $order = 'timestamp'; |
587 | } |
5e2307dc |
588 | $inv_order = Env::v('order_inv', 0); |
75687bb9 |
589 | $page->assign('order', $order); |
590 | $page->assign('order_inv', !$inv_order); |
591 | |
592 | if ($order == 'timestamp') { |
593 | $inv_order = !$inv_order; |
594 | } |
595 | |
596 | if ($inv_order) { |
597 | $inv_order = ' DESC'; |
598 | } else { |
599 | $inv_order = ''; |
600 | } |
601 | if ($order == 'montant') { |
602 | $order = 'LENGTH(montant) '.$inv_order.', montant'; |
603 | } |
604 | |
605 | $orderby = 'ORDER BY '.$order.$inv_order; |
606 | if ($order != 'nom') { |
607 | $orderby .= ', nom'; $inv_order = ''; |
608 | } |
609 | $orderby .= ', prenom'.$inv_order; |
610 | if ($order != 'timestamp') { |
611 | $orderby .= ', timestamp DESC'; |
612 | } |
613 | |
614 | if (may_update()) { |
615 | $trans = array(); |
616 | foreach($tit as $foo) { |
617 | $pid = $foo['id']; |
08cce2ff |
618 | $res = XDB::query( |
75687bb9 |
619 | "SELECT IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, |
620 | u.prenom, u.promo, a.alias, timestamp AS `date`, montant |
621 | FROM {$globals->money->mpay_tprefix}transactions AS t |
622 | INNER JOIN auth_user_md5 AS u ON ( t.uid = u.user_id ) |
623 | INNER JOIN aliases AS a ON ( t.uid = a.id AND a.type='a_vie' ) |
624 | WHERE ref = {?} ".$orderby, $pid); |
625 | $trans[$pid] = $res->fetchAllAssoc(); |
626 | $sum = 0; |
627 | foreach ($trans[$pid] as $i => $t) { |
628 | $sum += strtr(substr($t['montant'], 0, strpos($t['montant'], 'EUR')), ',', '.'); |
629 | } |
630 | $trans[$pid][] = array('nom' => 'somme totale', |
631 | 'montant' => strtr($sum, '.', ',').' EUR'); |
632 | } |
633 | $page->assign('trans', $trans); |
634 | } |
635 | } |
636 | |
4e310c61 |
637 | function handler_admin_annuaire(&$page) |
638 | { |
639 | global $globals; |
640 | |
4e310c61 |
641 | require_once 'xnet/mail.inc.php'; |
642 | |
643 | new_groupadmin_page('xnet/groupe/annuaire-admin.tpl'); |
9bb8bf21 |
644 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
645 | $globals->asso('mail_domain')); |
646 | $lists = $mmlist->get_lists(); |
4e310c61 |
647 | if (!$lists) $lists = array(); |
648 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); |
649 | |
650 | $subscribers = array(); |
651 | |
652 | foreach ($listes as $list) { |
9bb8bf21 |
653 | list(,$members) = $mmlist->get_members($list); |
4e310c61 |
654 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
655 | $subscribers = array_unique(array_merge($subscribers, $mails)); |
656 | } |
657 | |
658 | $not_in_group_x = array(); |
659 | $not_in_group_ext = array(); |
660 | |
661 | foreach ($subscribers as $mail) { |
08cce2ff |
662 | $res = XDB::query( |
4e310c61 |
663 | 'SELECT COUNT(*) |
664 | FROM groupex.membres AS m |
665 | LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) |
666 | LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") |
667 | WHERE asso_id = {?} AND |
668 | (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', |
669 | $globals->asso('id'), $mail, $mail); |
670 | if ($res->fetchOneCell() == 0) { |
671 | if (strstr($mail, '@polytechnique.org') === false) { |
672 | $not_in_group_ext[] = $mail; |
673 | } else { |
674 | $not_in_group_x[] = $mail; |
675 | } |
676 | } |
677 | } |
678 | |
679 | $page->assign('not_in_group_ext', $not_in_group_ext); |
680 | $page->assign('not_in_group_x', $not_in_group_x); |
681 | $page->assign('lists', $lists); |
682 | } |
ef7c8560 |
683 | |
684 | function handler_admin_member_new(&$page, $email = null) |
685 | { |
686 | global $globals; |
687 | |
688 | new_groupadmin_page('xnet/groupe/membres-add.tpl'); |
dc2073c3 |
689 | $page->addJsLink('ajax.js'); |
ef7c8560 |
690 | |
691 | if (is_null($email)) { |
692 | return; |
693 | } |
694 | |
695 | list(,$fqdn) = explode('@', $email); |
696 | $fqdn = strtolower($fqdn); |
697 | $x = ($fqdn == 'polytechnique.org' || $fqdn == 'melix.org' || |
698 | $fqdn == 'm4x.org' || $fqdn == 'melix.net'); |
699 | |
700 | if ($x) { |
701 | require_once 'user.func.inc.php'; |
702 | if ($forlife = get_user_forlife($email)) { |
08cce2ff |
703 | XDB::execute( |
ef7c8560 |
704 | 'INSERT INTO groupex.membres (uid,asso_id,origine) |
ed21e24a |
705 | SELECT user_id,{?},"X" |
706 | FROM auth_user_md5 AS u |
707 | INNER JOIN aliases AS a ON (u.user_id = a.id) |
708 | WHERE a.alias={?}', $globals->asso('id'), $forlife); |
8b00e0e0 |
709 | pl_redirect("member/$email"); |
ef7c8560 |
710 | } else { |
711 | $page->trig($email." n'est pas un alias polytechnique.org valide"); |
712 | } |
713 | } else { |
714 | if (isvalid_email($email)) { |
dc2073c3 |
715 | if (Env::v('x') && Env::has('userid') && Env::i('userid')) { |
716 | $uid = Env::i('userid'); |
717 | $res = XDB::query("SELECT * |
718 | FROM auth_user_md5 |
719 | WHERE user_id = {?} AND perms = 'pending'", $uid); |
720 | if ($res->numRows() == 1) { |
721 | XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email) |
722 | VALUES ({?}, {?}, "X", {?})', |
723 | $uid, $globals->asso('id'), $email); |
724 | if (Env::v('market')) { |
725 | $res = XDB::query('SELECT COUNT(*) |
726 | FROM register_marketing |
727 | WHERE uid={?} AND email={?}', $uid, $email); |
728 | if (!$res->fetchOneCell()) { |
729 | XDB::execute("INSERT INTO register_marketing (uid,sender,email,date,last,nb,type,hash) |
730 | VALUES ({?}, {?}, {?}, NOW(), 0, 0, {?}, '')", |
731 | $uid, S::v('uid'), $email, Env::v('market_from')); |
732 | require_once('validations.inc.php'); |
733 | $req = new MarkReq(S::v('uid'), $uid, $email, Env::v('market_from') == 'user'); |
734 | $req->submit(); |
735 | } |
736 | } |
737 | pl_redirect("member/$email"); |
738 | } |
739 | $page->trig("Utilisateur invalide"); |
740 | } else { |
741 | $res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres'); |
742 | $uid = max(intval($res->fetchOneCell()), 50001); |
743 | XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email) |
744 | VALUES({?},{?},"ext",{?})', $uid, |
745 | $globals->asso('id'), $email); |
746 | pl_redirect("member/$email"); |
747 | } |
ef7c8560 |
748 | } else { |
749 | $page->trig("« <strong>$email</strong> » n'est pas une adresse mail valide"); |
750 | } |
751 | } |
752 | } |
753 | |
dc2073c3 |
754 | function handler_admin_member_new_ajax(&$page) |
755 | { |
2aa20e30 |
756 | header('Content-Type: text/html; charset="iso-8859-15"'); |
dc2073c3 |
757 | $page->changeTpl('xnet/groupe/membres-new-search.tpl', NO_SKIN); |
758 | list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); |
759 | $where = "perms = 'pending'"; |
760 | if (!empty($nom)) { |
761 | $where .= " AND nom LIKE '%$nom%'"; |
762 | } |
763 | if (!empty($prenom)) { |
764 | $where .= " AND prenom LIKE '%$prenom%'"; |
765 | } |
7cdecf88 |
766 | if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { |
dc2073c3 |
767 | $where .= " AND promo = " . Env::i('promo'); |
7cdecf88 |
768 | } elseif (Env::has('promo')) { |
769 | return; |
dc2073c3 |
770 | } |
771 | $res = XDB::iterator("SELECT user_id, nom, prenom, promo |
772 | FROM auth_user_md5 |
773 | WHERE $where"); |
774 | if ($res->total() < 30) { |
775 | $page->assign("choix", $res); |
776 | } |
777 | } |
778 | |
ef7c8560 |
779 | function handler_admin_member_del(&$page, $user = null) |
780 | { |
781 | global $globals; |
782 | |
783 | new_groupadmin_page('xnet/groupe/membres-del.tpl'); |
784 | $user = get_infos($user); |
785 | if (empty($user)) { |
786 | return PL_NOT_FOUND; |
787 | } |
788 | $page->assign('user', $user); |
789 | |
790 | if (!Post::has('confirm')) { |
791 | return; |
792 | } |
793 | |
08cce2ff |
794 | XDB::execute( |
ef7c8560 |
795 | "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}", |
796 | $user['uid'], $globals->asso('id')); |
797 | |
798 | // don't unsubscribe email from list if other user use same email |
799 | $user_same_email = get_infos($user['email']); |
800 | |
801 | if (($domain = $globals->asso('mail_domain')) && empty($user_same_email)) { |
802 | |
9bb8bf21 |
803 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
804 | $listes = $mmlist->get_lists($user['email2']); |
ef7c8560 |
805 | |
806 | foreach ($listes as $liste) { |
807 | if ($liste['sub'] == 2) { |
9bb8bf21 |
808 | $mmlist->mass_unsubscribe($liste['list'], Array($user['email2'])); |
ef7c8560 |
809 | $page->trig("{$user['prenom']} {$user['nom']} a été" |
810 | ." désinscrit de {$liste['list']}"); |
811 | } elseif ($liste['sub']) { |
812 | $page->trig("{$user['prenom']} {$user['nom']} a une" |
813 | ." demande d'inscription en cours sur la" |
814 | ." liste {$liste['list']}@ !"); |
815 | } |
816 | } |
817 | |
08cce2ff |
818 | XDB::execute( |
ef7c8560 |
819 | "DELETE FROM virtual_redirect |
820 | USING virtual_redirect |
821 | INNER JOIN virtual USING(vid) |
822 | WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain); |
823 | if (mysql_affected_rows()) { |
824 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné des alias du groupe !"); |
825 | } |
826 | } |
827 | |
828 | $page->trig("{$user['prenom']} {$user['nom']} a été retiré du groupe !"); |
829 | } |
830 | |
831 | function handler_admin_member(&$page, $user) |
832 | { |
833 | global $globals; |
834 | |
835 | new_groupadmin_page('xnet/groupe/membres-edit.tpl'); |
836 | |
837 | $user = get_infos($user); |
838 | if (empty($user)) { |
839 | return PL_NOT_FOUND; |
840 | } |
841 | |
9bb8bf21 |
842 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
843 | $globals->asso('mail_domain')); |
ef7c8560 |
844 | |
845 | if (Post::has('change')) { |
cf5e8ef1 |
846 | $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); |
c4d57bd8 |
847 | $from_email = $user['email']; |
ef7c8560 |
848 | if ($user['origine'] != 'X') { |
08cce2ff |
849 | XDB::query('UPDATE groupex.membres |
0cc4c07d |
850 | SET prenom={?}, nom={?}, email={?}, sexe={?} |
851 | WHERE uid={?} AND asso_id={?}', |
852 | Post::v('prenom'), Post::v('nom'), |
853 | Post::v('email'), Post::v('sexe'), |
854 | $user['uid'], $globals->asso('id')); |
5e2307dc |
855 | $user['nom'] = Post::v('nom'); |
856 | $user['prenom'] = Post::v('prenom'); |
0cc4c07d |
857 | $user['sexe'] = Post::v('sexe'); |
5e2307dc |
858 | $user['email'] = Post::v('email'); |
859 | $user['email2'] = Post::v('email'); |
ef7c8560 |
860 | } |
861 | |
5e2307dc |
862 | $perms = Post::i('is_admin'); |
ef7c8560 |
863 | if ($user['perms'] != $perms) { |
08cce2ff |
864 | XDB::query('UPDATE groupex.membres SET perms={?} |
0cc4c07d |
865 | WHERE uid={?} AND asso_id={?}', |
866 | $perms ? 'admin' : 'membre', |
867 | $user['uid'], $globals->asso('id')); |
ef7c8560 |
868 | $user['perms'] = $perms; |
869 | $page->trig('permissions modifiées'); |
870 | } |
871 | |
5e2307dc |
872 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 |
873 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 |
874 | if ($ask == $state) { |
875 | if ($state) { |
876 | $mmlist->replace_email($ml, $from_email, $user['email2']); |
877 | $page->trig("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour"); |
878 | } |
879 | continue; |
880 | } |
ef7c8560 |
881 | if ($state == '1') { |
882 | $page->trig("{$user['prenom']} {$user['nom']} a " |
883 | ."actuellement une demande d'inscription en " |
884 | ."cours sur <strong>$ml@</strong> !!!"); |
885 | } elseif ($ask) { |
9bb8bf21 |
886 | $mmlist->mass_subscribe($ml, Array($user['email2'])); |
ef7c8560 |
887 | $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml@"); |
888 | } else { |
c4d57bd8 |
889 | if ($email_changed) { |
890 | $mmlist->mass_unsubscribe($ml, Array($from_email)); |
891 | } else { |
892 | $mmlist->mass_unsubscribe($ml, Array($user['email2'])); |
893 | } |
ef7c8560 |
894 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml@"); |
895 | } |
896 | } |
897 | |
5e2307dc |
898 | foreach (Env::v('ml3', array()) as $ml => $state) { |
ef7c8560 |
899 | $ask = !empty($_REQUEST['ml4'][$ml]); |
900 | if($state == $ask) continue; |
901 | if($ask) { |
08cce2ff |
902 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
dc2073c3 |
903 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
904 | $user['email'], $ml); |
ef7c8560 |
905 | $page->trig("{$user['prenom']} {$user['nom']} a été abonné à $ml"); |
906 | } else { |
08cce2ff |
907 | XDB::query("DELETE FROM virtual_redirect |
dc2073c3 |
908 | USING virtual_redirect |
909 | INNER JOIN virtual USING(vid) |
910 | WHERE redirect={?} AND alias={?}", |
911 | $user['email'], $ml); |
ef7c8560 |
912 | $page->trig("{$user['prenom']} {$user['nom']} a été désabonné de $ml"); |
913 | } |
914 | } |
915 | } |
916 | |
917 | $page->assign('user', $user); |
9bb8bf21 |
918 | $listes = $mmlist->get_lists($user['email2']); |
ef7c8560 |
919 | $page->assign('listes', $listes); |
920 | |
08cce2ff |
921 | $res = XDB::query( |
ef7c8560 |
922 | 'SELECT alias, redirect IS NOT NULL as sub |
923 | FROM virtual AS v |
924 | LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND redirect={?}) |
925 | WHERE alias LIKE {?} AND type="user"', |
926 | $user['email'], '%@'.$globals->asso('mail_domain')); |
927 | $page->assign('alias', $res->fetchAllAssoc()); |
928 | } |
24bcf50c |
929 | |
930 | function handler_rss(&$page, $user = null, $hash = null) |
931 | { |
932 | global $globals; |
933 | require_once('rss.inc.php'); |
934 | require_once('url_catcher.inc.php'); |
935 | $uid = init_rss('xnet/groupe/announce-rss.tpl', $user, $hash, false); |
936 | $page->register_modifier('url_catcher', 'url_catcher'); |
937 | |
938 | if ($uid) { |
939 | $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.contacts, a.create_date, |
940 | IF(u2.nom_usage != '', u2.nom_usage, u2.nom) AS nom, u2.prenom, u2.promo |
941 | FROM auth_user_md5 AS u |
942 | INNER JOIN groupex.announces AS a ON ( (a.promo_min = 0 OR a.promo_min <= u.promo) |
943 | AND (a.promo_max = 0 OR a.promo_max <= u.promo)) |
944 | INNER JOIN auth_user_md5 AS u2 ON (u2.user_id = a.user_id) |
945 | WHERE u.user_id = {?} AND peremption >= NOW()", $uid); |
946 | } else { |
947 | $rss = XDB::iterator("SELECT a.id, a.titre, a.texte, a.create_date, |
948 | IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, u.prenom, u.promo |
949 | FROM groupex.announces AS a |
950 | INNER JOIN auth_user_md5 AS u USING(user_id) |
951 | WHERE FIND_IN_SET(a.flags, 'public') AND peremption >= NOW()"); |
952 | } |
953 | $page->assign('asso', $globals->asso()); |
954 | $page->assign('rss', $rss); |
955 | } |
956 | |
957 | function handler_edit_announce(&$page, $aid = null) |
958 | { |
959 | global $globals, $platal; |
960 | new_groupadmin_page('xnet/groupe/announce-edit.tpl'); |
961 | $page->assign('new', is_null($aid)); |
962 | $art = array(); |
963 | |
964 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer') { |
965 | if (!is_null($aid)) { |
966 | $art['id'] = $aid; |
967 | } |
968 | $art['titre'] = Post::v('titre'); |
969 | $art['texte'] = Post::v('texte'); |
970 | $art['contacts'] = Post::v('contacts'); |
971 | $art['promo_min'] = Post::i('promo_min'); |
972 | $art['promo_max'] = Post::i('promo_max'); |
973 | $art['nom'] = S::v('nom'); |
974 | $art['prenom'] = S::v('prenom'); |
975 | $art['promo'] = S::v('promo'); |
976 | $art['forlife'] = S::v('forlife'); |
977 | $art['peremption'] = Post::v('peremption'); |
978 | $art['public'] = Post::has('public'); |
979 | $art['xorg'] = Post::has('xorg'); |
980 | $art['nl'] = Post::has('nl'); |
981 | $art['event'] = Post::v('event'); |
982 | |
983 | $art['contact_html'] = $art['contacts']; |
b9a1ba64 |
984 | if ($art['event']) { |
985 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; |
24bcf50c |
986 | } |
2a557a09 |
987 | |
988 | if (!$art['public'] && |
989 | ($art['promo_min'] > $art['promo_max'] || |
990 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
991 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) |
992 | { |
993 | $page->trig("L'intervalle de promotions est invalide"); |
994 | Post::kill('valid'); |
995 | } |
24bcf50c |
996 | } |
997 | |
998 | if (Post::v('valid') == 'Enregistrer') { |
2a557a09 |
999 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1000 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); |
24bcf50c |
1001 | if (is_null($aid)) { |
1002 | XDB::query("INSERT INTO groupex.announces |
1003 | (user_id, asso_id, create_date, titre, texte, contacts, |
1004 | peremption, promo_min, promo_max, flags) |
1005 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?})", |
1006 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
2a557a09 |
1007 | $art['peremption'], $promo_min, $promo_max, $art['public'] ? 'public' : ''); |
8b83a166 |
1008 | $aid = XDB::insertId(); |
24bcf50c |
1009 | if ($art['xorg']) { |
1010 | require_once('validations.inc.php'); |
1011 | require_once('url_catcher.inc.php'); |
2a557a09 |
1012 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], |
b9a1ba64 |
1013 | url_catcher($art['texte'] . (!empty($art['contact_html']) ? "\n\nContacts :\n" . $art['contact_html'] : "")), |
24bcf50c |
1014 | $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::v('uid')); |
1015 | $article->submit(); |
1016 | $page->trig("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation"); |
1017 | } |
1018 | if ($art['nl']) { |
1019 | require_once('validations.inc.php'); |
2a557a09 |
1020 | $article = new NLReq(S::v('uid'), $globals->asso('nom') . " : " .$art['titre'], |
1021 | $art['texte'], $art['contact_html']); |
24bcf50c |
1022 | $article->submit(); |
1023 | $page->trig("La parution dans la Lettre Mensuelle est en attente de validation"); |
1024 | } |
1025 | } else { |
1026 | XDB::query("UPDATE groupex.announces |
1027 | SET titre={?}, texte={?}, contacts={?}, peremption={?}, |
1028 | promo_min={?}, promo_max={?}, flags={?} |
1029 | WHERE id={?} AND asso_id={?}", |
1030 | $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], |
2a557a09 |
1031 | $promo_min, $promo_max, $art['public'] ? 'public' : '', |
24bcf50c |
1032 | $art['id'], $globals->asso('id')); |
1033 | } |
2a557a09 |
1034 | } |
1035 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { |
24bcf50c |
1036 | pl_redirect(""); |
1037 | } |
1038 | |
1039 | if (empty($art) && !is_null($aid)) { |
1040 | $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, l.alias AS forlife, |
1041 | FIND_IN_SET(a.flags, 'public') AS public |
1042 | FROM groupex.announces AS a |
1043 | INNER JOIN auth_user_md5 AS u USING(user_id) |
1044 | INNER JOIN aliases AS l ON (l.id = u.user_id AND l.type = 'a_vie') |
1045 | WHERE asso_id = {?} AND a.id = {?}", |
1046 | $globals->asso('id'), $aid); |
1047 | if ($res->numRows()) { |
1048 | $art = $res->fetchOneAssoc(); |
1049 | $art['contact_html'] = $art['contacts']; |
1050 | } else { |
1051 | $page->kill("Aucun article correspond à l'identifiant indiqué"); |
1052 | } |
1053 | } |
1054 | |
1055 | $select = ''; |
1056 | for ($i = 1 ; $i < 30 ; $i++) { |
1057 | $time = time() + 3600 * 24 * $i; |
1058 | $p_stamp = date('Ymd', $time); |
1059 | $year = date('Y', $time); |
1060 | $month = date('m', $time); |
1061 | $day = date('d', $time); |
1062 | |
1063 | $select .= "<option value=\"$p_stamp\""; |
1064 | if ($p_stamp == strtr(@$art['peremption'], array("-" => ""))) { |
1065 | $select .= " selected='selected'"; |
1066 | } |
1067 | $select .= "> $day / $month / $year</option>\n"; |
1068 | } |
1069 | $page->assign('select', $select); |
1070 | |
1071 | if (is_null($aid)) { |
1072 | $events = XDB::iterator("SELECT * |
1073 | FROM groupex.evenements |
1074 | WHERE asso_id = {?} AND archive = 0", |
1075 | $globals->asso('id')); |
1076 | if ($events->total()) { |
1077 | $page->assign('events', $events); |
1078 | } |
1079 | } |
1080 | |
1081 | require_once('url_catcher.inc.php'); |
1082 | $art['contact_html'] = url_catcher($art['contact_html']); |
1083 | $page->assign('art', $art); |
1084 | } |
1085 | |
1086 | function handler_admin_announce(&$page) |
1087 | { |
1088 | global $globals; |
1089 | new_groupadmin_page('xnet/groupe/announce-admin.tpl'); |
1090 | |
1091 | if (Env::has('del')) { |
1092 | XDB::execute("DELETE FROM groupex.announces |
1093 | WHERE id = {?} AND asso_id = {?}", |
1094 | Env::i('del'), $globals->asso('id')); |
1095 | } |
1096 | $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime |
1097 | FROM groupex.announces AS a |
1098 | WHERE a.asso_id = {?} |
1099 | ORDER BY a.peremption DESC", |
1100 | $globals->asso('id')); |
1101 | $page->assign('articles', $res); |
1102 | } |
ae7bb180 |
1103 | } |
1104 | |
1105 | ?> |