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