Commit | Line | Data |
---|---|---|
ae7bb180 | 1 | <?php |
2 | /*************************************************************************** | |
179afa7f | 3 | * Copyright (C) 2003-2008 Polytechnique.org * |
ae7bb180 | 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( |
54b24ba2 | 37 | "SELECT uid, nom, prenom, email, email AS email2, perms='admin', origine, comm, 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') { | |
010268b2 | 44 | $res = XDB::query("SELECT nom, prenom, promo, FIND_IN_SET('femme', flags) AS sexe |
dc2073c3 | 45 | FROM auth_user_md5 |
46 | WHERE user_id = {?}", $user['uid']); | |
47 | $user = array_merge($user, $res->fetchOneAssoc()); | |
48 | } | |
eaf30d86 | 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, | |
54b24ba2 | 57 | m.perms = 'admin' AS perms, m.origine, m.comm, |
010268b2 | 58 | FIND_IN_SET('femme', u.flags) 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' ) | |
e1594f65 | 62 | LEFT JOIN groupex.membres AS m ON ( m.uid = u.user_id AND asso_id={?}) |
ef7c8560 | 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), | |
d430f4d8 | 79 | '%grp/site' => $this->make_hook('site', AUTH_PUBLIC), |
c6c10b6b | 80 | '%grp/edit' => $this->make_hook('edit', AUTH_MDP, 'groupadmin'), |
81 | '%grp/mail' => $this->make_hook('mail', AUTH_MDP, 'groupadmin'), | |
1490093c | 82 | '%grp/forum' => $this->make_hook('forum', AUTH_MDP, 'groupmember'), |
35fa92e8 | 83 | '%grp/annuaire' => $this->make_hook('annuaire', AUTH_MDP, 'groupannu'), |
84 | '%grp/annuaire/vcard' => $this->make_hook('vcard', AUTH_MDP, 'groupmember:groupannu'), | |
102f4e64 | 85 | '%grp/annuaire/csv' => $this->make_hook('csv', AUTH_MDP, 'groupmember:groupannu'), |
35fa92e8 | 86 | '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'), |
a91fb584 | 87 | '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'), |
5e193297 | 88 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
4af7fd22 | 89 | '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'), |
1490093c | 90 | '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'), |
4e310c61 | 91 | |
b8e265bf | 92 | '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP), |
93 | ||
d1ebc57a | 94 | '%grp/admin/annuaire' |
35fa92e8 | 95 | => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'), |
ef7c8560 | 96 | |
d1ebc57a | 97 | '%grp/member' |
c6c10b6b | 98 | => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'), |
d1ebc57a | 99 | '%grp/member/new' |
c6c10b6b | 100 | => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'), |
dc2073c3 | 101 | '%grp/member/new/ajax' |
8fc4efa3 | 102 | => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH), |
d1ebc57a | 103 | '%grp/member/del' |
c6c10b6b | 104 | => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'), |
24bcf50c | 105 | |
8fc4efa3 | 106 | '%grp/rss' => $this->make_hook('rss', AUTH_PUBLIC, 'user', NO_HTTPS), |
c6c10b6b | 107 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), |
108 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), | |
ff95a302 | 109 | '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC), |
c6c10b6b | 110 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'), |
ae7bb180 | 111 | ); |
112 | } | |
113 | ||
2e94d2b8 | 114 | function handler_index(&$page, $arg = null) |
ae7bb180 | 115 | { |
24bcf50c | 116 | global $globals, $platal; |
ae7bb180 | 117 | |
2e94d2b8 | 118 | if (!is_null($arg)) { |
ae7bb180 | 119 | return PL_NOT_FOUND; |
120 | } | |
1490093c | 121 | $page->changeTpl('xnetgrp/asso.tpl'); |
ae7bb180 | 122 | |
24bcf50c | 123 | if (S::logged()) { |
124 | if (Env::has('read')) { | |
f5b3a6da | 125 | XDB::query('DELETE groupex.r.* |
24bcf50c | 126 | FROM groupex.announces_read AS r |
127 | INNER JOIN groupex.announces AS a ON a.id = r.announce_id | |
eaf30d86 | 128 | WHERE peremption < CURRENT_DATE()'); |
24bcf50c | 129 | XDB::query('INSERT INTO groupex.announces_read |
130 | VALUES ({?}, {?})', | |
131 | Env::i('read'), S::i('uid')); | |
132 | pl_redirect(""); | |
133 | } | |
134 | if (Env::has('unread')) { | |
135 | XDB::query('DELETE FROM groupex.announces_read | |
136 | WHERE announce_id={?} AND user_id={?}', | |
137 | Env::i('unread'), S::i('uid')); | |
138 | pl_redirect("#art" . Env::i('unread')); | |
139 | } | |
0fab5209 | 140 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid, |
ff95a302 | 141 | FIND_IN_SET('photo', a.flags) AS photo |
24bcf50c | 142 | FROM groupex.announces AS a |
143 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
24bcf50c | 144 | LEFT JOIN groupex.announces_read AS r ON (r.user_id = {?} AND r.announce_id = a.id) |
145 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
146 | AND (promo_min = 0 OR promo_min <= {?}) | |
147 | AND (promo_max = 0 OR promo_max >= {?}) | |
148 | AND r.announce_id IS NULL | |
149 | ORDER BY a.peremption", | |
150 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); | |
151 | $index = XDB::iterator("SELECT a.id, a.titre, r.user_id IS NULL AS nonlu | |
152 | FROM groupex.announces AS a | |
153 | LEFT JOIN groupex.announces_read AS r ON (a.id = r.announce_id AND r.user_id = {?}) | |
154 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
155 | AND (promo_min = 0 OR promo_min <= {?}) | |
156 | AND (promo_max = 0 OR promo_max >= {?}) | |
157 | ORDER BY a.peremption", | |
158 | S::i('uid'), $globals->asso('id'), S::i('promo'), S::i('promo')); | |
159 | $page->assign('article_index', $index); | |
160 | } else { | |
ff95a302 | 161 | $arts = XDB::iterator("SELECT a.*, u.nom, u.prenom, u.promo, FIND_IN_SET('photo', a.flags) AS photo |
24bcf50c | 162 | FROM groupex.announces AS a |
163 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
164 | WHERE asso_id = {?} AND peremption >= CURRENT_DATE() | |
010268b2 | 165 | AND FIND_IN_SET('public', u.flags)", |
24bcf50c | 166 | $globals->asso('id')); |
167 | } | |
4af7fd22 FB |
168 | if (may_update()) { |
169 | $subs_valid = XDB::query("SELECT uid | |
170 | FROM groupex.membres_sub_requests | |
171 | WHERE asso_id = {?}", | |
172 | $globals->asso('id')); | |
173 | $page->assign('requests', $subs_valid->numRows()); | |
174 | } | |
24bcf50c | 175 | |
176 | if (!S::has('core_rss_hash')) { | |
177 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", | |
5700a250 | 178 | $platal->ns . "rss/rss.xml"); |
24bcf50c | 179 | } else { |
180 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", | |
0fab5209 | 181 | $platal->ns . 'rss/'.S::v('hruid') .'/'.S::v('core_rss_hash').'/rss.xml'); |
24bcf50c | 182 | } |
eaf30d86 | 183 | |
24bcf50c | 184 | $page->assign('articles', $arts); |
ae7bb180 | 185 | } |
dd798f38 | 186 | |
187 | function handler_logo(&$page) | |
188 | { | |
189 | global $globals; | |
190 | ||
08cce2ff | 191 | $res = XDB::query("SELECT logo, logo_mime |
24bcf50c | 192 | FROM groupex.asso WHERE id = {?}", |
193 | $globals->asso('id')); | |
dd798f38 | 194 | list($logo, $logo_mime) = $res->fetchOneRow(); |
195 | ||
196 | if (!empty($logo)) { | |
197 | header("Content-type: $mime"); | |
198 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | |
199 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
200 | header('Cache-Control: no-cache, must-revalidate'); | |
201 | header('Pragma: no-cache'); | |
202 | echo $logo; | |
203 | } else { | |
204 | header('Content-type: image/jpeg'); | |
205 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); | |
206 | header('Last-Modified:' . gmdate('D, d M Y H:i:s') . ' GMT'); | |
207 | header('Cache-Control: no-cache, must-revalidate'); | |
208 | header('Pragma: no-cache'); | |
831fae47 | 209 | readfile(dirname(__FILE__).'/../htdocs/images/dflt_carre.jpg'); |
dd798f38 | 210 | } |
211 | ||
212 | exit; | |
213 | } | |
2e94d2b8 | 214 | |
d430f4d8 | 215 | function handler_site(&$page) |
216 | { | |
217 | global $globals; | |
218 | $site = $globals->asso('site'); | |
219 | if (!$site) { | |
a7d35093 | 220 | $page->trigError('Le groupe n\'a pas de site web.'); |
d430f4d8 | 221 | return $this->handler_index($page); |
222 | } | |
02838718 | 223 | http_redirect($site); |
d430f4d8 | 224 | exit; |
225 | } | |
226 | ||
2e94d2b8 | 227 | function handler_edit(&$page) |
228 | { | |
229 | global $globals; | |
1490093c | 230 | $page->changeTpl('xnetgrp/edit.tpl'); |
2e94d2b8 | 231 | |
40d428d8 VZ |
232 | if (Post::has('submit')) { |
233 | S::assert_xsrf_token(); | |
234 | ||
113f6de8 | 235 | $flags = new PlFlagSet('wiki_desc'); |
fa9493fe FB |
236 | if (Post::has('notif_unsub') && Post::i('notif_unsub') == 1) { |
237 | $flags->addFlag('notif_unsub'); | |
238 | } | |
cab08090 | 239 | if (S::has_perms()) { |
5e2307dc | 240 | if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { |
a7d35093 | 241 | $page->trigError("le domaine doit être un FQDN (aucune modif effectuée) !!!"); |
c9110c6c | 242 | return; |
2e94d2b8 | 243 | } |
08cce2ff | 244 | XDB::execute( |
2e94d2b8 | 245 | "UPDATE groupex.asso |
246 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, | |
247 | descr={?}, site={?}, mail={?}, resp={?}, | |
248 | forum={?}, mail_domain={?}, ax={?}, pub={?}, | |
794feea7 | 249 | sub_url={?}, inscriptible={?}, unsub_url={?}, |
fa9493fe | 250 | flags={?} |
2e94d2b8 | 251 | WHERE id={?}", |
5e2307dc | 252 | Post::v('nom'), Post::v('diminutif'), |
253 | Post::v('cat'), Post::i('dom'), | |
254 | Post::v('descr'), Post::v('site'), | |
255 | Post::v('mail'), Post::v('resp'), | |
256 | Post::v('forum'), Post::v('mail_domain'), | |
2c86d368 | 257 | Post::has('ax'), Post::v('pub'), |
5e2307dc | 258 | Post::v('sub_url'), Post::v('inscriptible'), |
d62d54f5 | 259 | Post::v('unsub_url'), $flags, $globals->asso('id')); |
5e2307dc | 260 | if (Post::v('mail_domain')) { |
d62d54f5 | 261 | XDB::execute('INSERT IGNORE INTO virtual_domains (domain) VALUES({?})', |
5e2307dc | 262 | Post::v('mail_domain')); |
2e94d2b8 | 263 | } |
264 | } else { | |
08cce2ff | 265 | XDB::execute( |
2e94d2b8 | 266 | "UPDATE groupex.asso |
267 | SET descr={?}, site={?}, mail={?}, resp={?}, | |
30032578 | 268 | forum={?}, ax={?}, pub= {?}, sub_url={?}, |
fa9493fe | 269 | unsub_url={?},flags={?} |
2e94d2b8 | 270 | WHERE id={?}", |
5e2307dc | 271 | Post::v('descr'), Post::v('site'), |
272 | Post::v('mail'), Post::v('resp'), | |
273 | Post::v('forum'), Post::has('ax'), | |
5b9b02ba | 274 | Post::v('pub'), |
30032578 | 275 | Post::v('sub_url'), Post::v('unsub_url'), |
d62d54f5 | 276 | $flags, $globals->asso('id')); |
2e94d2b8 | 277 | } |
278 | ||
279 | if ($_FILES['logo']['name']) { | |
280 | $logo = file_get_contents($_FILES['logo']['tmp_name']); | |
281 | $mime = $_FILES['logo']['type']; | |
08cce2ff | 282 | XDB::execute('UPDATE groupex.asso |
794feea7 FB |
283 | SET logo={?}, logo_mime={?} |
284 | WHERE id={?}', $logo, $mime, | |
285 | $globals->asso('id')); | |
2e94d2b8 | 286 | } |
287 | ||
5e2307dc | 288 | pl_redirect('../'.Post::v('diminutif', $globals->asso('diminutif')).'/edit'); |
2e94d2b8 | 289 | } |
290 | ||
cab08090 | 291 | if (S::has_perms()) { |
08cce2ff | 292 | $dom = XDB::iterator('SELECT * FROM groupex.dom ORDER BY nom'); |
2e94d2b8 | 293 | $page->assign('dom', $dom); |
294 | $page->assign('super', true); | |
295 | } | |
794feea7 | 296 | if (!$globals->asso('wiki_desc') && $globals->asso('descr')) { |
a7d35093 | 297 | $page->trigWarning("Attention, le format de la description a changé et utilise désormais la syntaxe wiki " |
da4195dc | 298 | . "intégrée au site. Il te faudra probablement adapter le formatage du texte actuel pour " |
794feea7 FB |
299 | . "qu'il s'affiche correctement avec cette nouvelle syntaxe."); |
300 | } | |
2e94d2b8 | 301 | } |
302 | ||
479d2787 | 303 | function handler_mail(&$page) |
304 | { | |
305 | global $globals; | |
306 | ||
1490093c | 307 | $page->changeTpl('xnetgrp/mail.tpl'); |
9bb8bf21 | 308 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
309 | $globals->asso('mail_domain')); | |
310 | $page->assign('listes', $mmlist->get_lists()); | |
fdbeba4f | 311 | $page->addJsLink('ajax.js'); |
479d2787 | 312 | |
313 | if (Post::has('send')) { | |
e7fdf9dd | 314 | S::assert_xsrf_token(); |
5e2307dc | 315 | $from = Post::v('from'); |
316 | $sujet = Post::v('sujet'); | |
317 | $body = Post::v('body'); | |
479d2787 | 318 | |
5e2307dc | 319 | $mls = array_keys(Env::v('ml', array())); |
06db561e | 320 | $mbr = array_keys(Env::v('membres', array())); |
479d2787 | 321 | |
460d8f55 | 322 | $this->load('mail.inc.php'); |
c974e61c | 323 | set_time_limit(120); |
06db561e | 324 | $tos = get_all_redirects($mbr, $mls, $mmlist); |
f3df6d38 | 325 | $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true); |
5b21237d | 326 | send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']); |
13627bef | 327 | if ($upload) { |
328 | $upload->rm(); | |
329 | } | |
faefdbb7 | 330 | $page->kill("Email envoyé !"); |
479d2787 | 331 | $page->assign('sent', true); |
332 | } | |
333 | } | |
334 | ||
4f355064 | 335 | function handler_forum(&$page, $group = null, $artid = null) |
336 | { | |
337 | global $globals; | |
1490093c | 338 | $page->changeTpl('xnetgrp/forum.tpl'); |
4f355064 | 339 | if (!$globals->asso('forum')) { |
340 | return PL_NOT_FOUND; | |
341 | } | |
342 | require_once 'banana/forum.inc.php'; | |
343 | $get = array(); | |
344 | get_banana_params($get, $globals->asso('forum'), $group, $artid); | |
345 | run_banana($page, 'ForumsBanana', $get); | |
346 | } | |
347 | ||
a91fb584 | 348 | function handler_annuaire(&$page, $action = null, $subaction = null) |
2e94d2b8 | 349 | { |
350 | global $globals; | |
a91fb584 | 351 | |
9ee54baf FB |
352 | if ($action == 'search') { |
353 | http_redirect("https://www.polytechnique.org/search/adv?rechercher=Chercher&groupex={$globals->asso('id')}" | |
354 | . "&cityid=" . Env::v('cityid') . "&mapid=" . Env::v('mapid')); | |
355 | } else if ($action == 'geoloc' || $action == 'trombi') { | |
a91fb584 | 356 | $view = new UserSet(); |
357 | $view->addMod('trombi', 'Trombinoscope'); | |
9ee54baf | 358 | $view->addMod('geoloc', 'Planisphère', false, array('with_annu' => 'annuaire/search')); |
a91fb584 | 359 | $view->apply('annuaire', $page, $action, $subaction); |
360 | if ($action == 'geoloc' && $subaction) { | |
361 | return; | |
362 | } | |
363 | } | |
35fa92e8 | 364 | $page->changeTpl('xnetgrp/annuaire.tpl'); |
2e94d2b8 | 365 | |
e02ecfce | 366 | $sort = Env::v('order'); |
5e2307dc | 367 | switch (Env::v('order')) { |
2e94d2b8 | 368 | case 'promo' : $group = 'promo'; $tri = 'promo_o DESC, nom, prenom'; break; |
369 | case 'promo_inv': $group = 'promo'; $tri = 'promo_o, nom, prenom'; break; | |
370 | case 'alpha_inv': $group = 'initiale'; $tri = 'nom DESC, prenom DESC, promo'; break; | |
e02ecfce | 371 | default : $group = 'initiale'; $tri = 'nom, prenom, promo'; $sort = 'alpha'; |
2e94d2b8 | 372 | } |
e02ecfce | 373 | $page->assign('sort', $sort); |
2e94d2b8 | 374 | |
06db561e | 375 | if ($group == 'initiale') { |
08cce2ff | 376 | $res = XDB::iterRow( |
2e94d2b8 | 377 | 'SELECT UPPER(SUBSTRING( |
dc2073c3 | 378 | IF(m.origine="X", IF(u.nom_usage<>"", u.nom_usage, u.nom),m.nom), |
2e94d2b8 | 379 | 1, 1)) as letter, COUNT(*) |
380 | FROM groupex.membres AS m | |
310d50da | 381 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid) |
0fe005cc | 382 | WHERE asso_id = {?} and (u.perms != \'pending\' OR m.email IS NOT NULL) |
2e94d2b8 | 383 | GROUP BY letter |
384 | ORDER BY letter', $globals->asso('id')); | |
06db561e | 385 | } else { |
08cce2ff | 386 | $res = XDB::iterRow( |
06db561e | 387 | 'SELECT IF(m.origine="X",u.promo, |
a7de4ef7 | 388 | IF(m.origine="ext", "extérieur", "personne morale")) AS promo, |
2e94d2b8 | 389 | COUNT(*), IF(m.origine="X",u.promo,"") AS promo_o |
390 | FROM groupex.membres AS m | |
391 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
392 | WHERE asso_id = {?} | |
393 | GROUP BY promo | |
394 | ORDER BY promo_o DESC', $globals->asso('id')); | |
06db561e | 395 | } |
2e94d2b8 | 396 | $alphabet = array(); |
397 | $nb_tot = 0; | |
398 | while (list($char, $nb) = $res->next()) { | |
399 | $alphabet[] = $char; | |
400 | $nb_tot += $nb; | |
5e2307dc | 401 | if (Env::has($group) && $char == strtoupper(Env::v($group))) { |
2e94d2b8 | 402 | $tot = $nb; |
403 | } | |
404 | } | |
405 | $page->assign('group', $group); | |
5e2307dc | 406 | $page->assign('request_group', Env::v($group)); |
f2900e25 | 407 | $page->assign('only_admin', Env::has('admin')); |
2e94d2b8 | 408 | $page->assign('alphabet', $alphabet); |
409 | $page->assign('nb_tot', $nb_tot); | |
410 | ||
5e2307dc | 411 | $ofs = Env::i('offset'); |
412 | $tot = Env::v($group) ? $tot : $nb_tot; | |
2e94d2b8 | 413 | $nbp = intval(($tot-1)/NB_PER_PAGE); |
414 | $links = array(); | |
415 | if ($ofs) { | |
a7de4ef7 | 416 | $links['précédent'] = $ofs-1; |
2e94d2b8 | 417 | } |
418 | for ($i = 0; $i <= $nbp; $i++) { | |
419 | $links[(string)($i+1)] = $i; | |
420 | } | |
421 | if ($ofs < $nbp) { | |
422 | $links['suivant'] = $ofs+1; | |
423 | } | |
424 | if (count($links)>1) { | |
425 | $page->assign('links', $links); | |
426 | } | |
427 | ||
428 | $ini = ''; | |
429 | if (Env::has('initiale')) { | |
430 | $ini = 'AND IF(m.origine="X", | |
431 | IF(u.nom_usage<>"", u.nom_usage, u.nom), | |
5e2307dc | 432 | m.nom) LIKE "'.addslashes(Env::v('initiale')).'%"'; |
2e94d2b8 | 433 | } elseif (Env::has('promo')) { |
a7de4ef7 | 434 | $ini = 'AND IF(m.origine="X", u.promo, IF(m.origine="ext", "extérieur", "personne morale")) = "' |
5e2307dc | 435 | .addslashes(Env::v('promo')).'"'; |
f2900e25 | 436 | } elseif (Env::has('admin')) { |
437 | $ini = 'AND m.perms = "admin"'; | |
2e94d2b8 | 438 | } |
439 | ||
08cce2ff | 440 | $ann = XDB::iterator( |
2e94d2b8 | 441 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, |
442 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, | |
a7de4ef7 | 443 | IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo, |
2e94d2b8 | 444 | IF(m.origine='X',u.promo,'') AS promo_o, |
dc2073c3 | 445 | IF(m.origine='X' AND u.perms != 'pending',a.alias,m.email) AS email, |
0cc4c07d | 446 | IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme, |
2e94d2b8 | 447 | m.perms='admin' AS admin, |
448 | m.origine='X' AS x, | |
dc2073c3 | 449 | u.perms!='pending' AS inscrit, |
54b24ba2 | 450 | m.comm as comm, |
0e5ec860 | 451 | m.uid, IF(e.email IS NULL AND FIND_IN_SET('googleapps', u.mail_storage) = 0, NULL, 1) AS actif |
2e94d2b8 | 452 | FROM groupex.membres AS m |
453 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
454 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type='a_vie' ) | |
e429fff0 | 455 | LEFT JOIN emails AS e ON ( e.flags = 'active' AND e.uid = m.uid) |
2e94d2b8 | 456 | WHERE m.asso_id = {?} $ini |
06db561e | 457 | AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL) |
eaf30d86 | 458 | GROUP BY m.uid |
2e94d2b8 | 459 | ORDER BY $tri |
460 | LIMIT {?},{?}", $globals->asso('id'), $ofs*NB_PER_PAGE, NB_PER_PAGE); | |
2e94d2b8 | 461 | $page->assign('ann', $ann); |
4a8a1e0a | 462 | $page->jsonAssign('ann', $ann); |
2e94d2b8 | 463 | } |
4e310c61 | 464 | |
a91fb584 | 465 | function handler_trombi(&$page) |
466 | { | |
467 | pl_redirect('annuaire/trombi'); | |
468 | } | |
469 | ||
470 | function handler_geoloc(&$page) | |
28929cf0 | 471 | { |
a91fb584 | 472 | pl_redirect('annuaire/geoloc'); |
28929cf0 | 473 | } |
eaf30d86 | 474 | |
917c4d11 | 475 | function handler_vcard(&$page, $photos = null) |
5e193297 | 476 | { |
477 | global $globals; | |
35fa92e8 | 478 | $res = XDB::query('SELECT uid |
479 | FROM groupex.membres | |
480 | WHERE asso_id = {?}', $globals->asso('id')); | |
5d42c993 FB |
481 | $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); |
482 | $vcard->addUsers($res->fetchColumn()); | |
483 | $vcard->show(); | |
5e193297 | 484 | } |
485 | ||
102f4e64 FB |
486 | function handler_csv(&$page, $filename = null) |
487 | { | |
488 | global $globals; | |
489 | if (is_null($filename)) { | |
490 | $filename = $globals->asso('diminutif') . '.csv'; | |
491 | } | |
492 | $ann = XDB::iterator( | |
493 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, | |
494 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, | |
495 | IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo, | |
496 | IF(m.origine='X' AND u.perms != 'pending',CONCAT(a.alias, '@', {?}), m.email) AS email, | |
497 | IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme, | |
498 | m.comm as comm | |
499 | FROM groupex.membres AS m | |
500 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
501 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type = 'a_vie' ) | |
502 | WHERE m.asso_id = {?} | |
503 | AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL) | |
504 | GROUP BY m.uid | |
505 | ORDER BY nom, prenom", | |
506 | $globals->mail->domain, $globals->asso('id')); | |
507 | header('Content-Type: text/x-csv; charset=utf-8;'); | |
508 | header('Pragma: '); | |
509 | header('Cache-Control: '); | |
510 | $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN); | |
511 | $page->assign('ann', $ann); | |
512 | } | |
513 | ||
4af7fd22 FB |
514 | private function removeSubscriptionRequest($uid) |
515 | { | |
516 | global $globals; | |
517 | XDB::execute("DELETE FROM groupex.membres_sub_requests | |
518 | WHERE asso_id = {?} AND uid = {?}", | |
519 | $globals->asso('id'), $uid); | |
520 | } | |
521 | ||
0fab5209 | 522 | private function validSubscription(User &$user) |
4af7fd22 FB |
523 | { |
524 | global $globals; | |
0fab5209 | 525 | $this->removeSubscriptionRequest($user->id()); |
4af7fd22 FB |
526 | XDB::execute("INSERT INTO groupex.membres (asso_id, uid) |
527 | VALUES ({?}, {?})", | |
0fab5209 | 528 | $globals->asso('id'), $user->id()); |
4af7fd22 | 529 | $mailer = new PlMailer(); |
0fab5209 VZ |
530 | $mailer->addTo($user->forlifeEmail()); |
531 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
4af7fd22 | 532 | $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); |
0fab5209 | 533 | $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n" |
4af7fd22 FB |
534 | . "\n" |
535 | . " Suite à ta demande d'adhésion à " . $globals->asso('nom') . ",\n" | |
536 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" | |
537 | . "\n" | |
538 | . "Bien cordialement,\n" | |
539 | . "-- \n" | |
0fab5209 | 540 | . S::user()->fullName() . '.'; |
4af7fd22 FB |
541 | $mailer->setTxtBody($message); |
542 | $mailer->send(); | |
543 | } | |
544 | ||
fdf0200a | 545 | function handler_subscribe(&$page, $u = null) |
546 | { | |
c8faf82a | 547 | global $globals; |
1490093c | 548 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
fdf0200a | 549 | |
550 | if (!$globals->asso('inscriptible')) | |
a7de4ef7 | 551 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
552 | ."groupe. Essaie de joindre le contact indiqué " | |
553 | ."sur la page de présentation."); | |
fdf0200a | 554 | |
555 | if (!is_null($u) && may_update()) { | |
0fab5209 VZ |
556 | $user = User::get($u); |
557 | if (!$user) { | |
558 | return PL_NOT_FOUND; | |
559 | } else { | |
560 | $page->assign('user', $user); | |
fdf0200a | 561 | } |
0fab5209 VZ |
562 | |
563 | // Retrieves the subscription status, and the reason. | |
564 | $res = XDB::query("SELECT reason | |
565 | FROM groupex.membres_sub_requests | |
566 | WHERE asso_id = {?} AND uid = {?}", | |
567 | $globals->asso('id'), $user->id()); | |
568 | $reason = ($res->numRows() ? $res->fetchOneCell() : null); | |
569 | ||
570 | $res = XDB::query("SELECT COUNT(*) | |
571 | FROM groupex.membres | |
572 | WHERE asso_id = {?} AND uid = {?}", | |
573 | $globals->asso('id'), $user->id()); | |
574 | $already_member = ($res->fetchOneCell() > 0); | |
575 | ||
576 | // Handles the membership request. | |
577 | if ($already_member) { | |
578 | $this->removeSubscriptionRequest($user->id()); | |
579 | $page->kill($user->fullName() . " est déjà membre du groupe !"); | |
580 | } elseif (Env::has('accept')) { | |
581 | S::assert_xsrf_token(); | |
582 | ||
583 | $this->validSubscription($user); | |
584 | pl_redirect("member/" . $user->login()); | |
585 | } elseif (Env::has('refuse')) { | |
586 | S::assert_xsrf_token(); | |
587 | ||
588 | $this->removeSubscriptionRequest($user->id()); | |
589 | $mailer = new PlMailer(); | |
590 | $mailer->addTo($user->forlifeEmail()); | |
591 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
592 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); | |
593 | $mailer->setTxtBody(Env::v('motif')); | |
594 | $mailer->send(); | |
595 | $page->kill("La demande de {$user->fullName()} a bien été refusée."); | |
596 | } else { | |
597 | $page->assign('show_form', true); | |
598 | $page->assign('reason', $reason); | |
599 | } | |
600 | return; | |
fdf0200a | 601 | } |
602 | ||
603 | if (is_member()) { | |
567553ac | 604 | $page->kill("Tu es déjà membre !"); |
fdf0200a | 605 | return; |
606 | } | |
607 | ||
4af7fd22 FB |
608 | $res = XDB::query("SELECT uid |
609 | FROM groupex.membres_sub_requests | |
610 | WHERE uid = {?} AND asso_id = {?}", | |
611 | S::i('uid'), $globals->asso('id')); | |
612 | if ($res->numRows() != 0) { | |
613 | $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation."); | |
614 | return; | |
615 | } | |
616 | ||
fdf0200a | 617 | if (Post::has('inscrire')) { |
e7fdf9dd VZ |
618 | S::assert_xsrf_token(); |
619 | ||
4af7fd22 FB |
620 | XDB::execute("INSERT INTO groupex.membres_sub_requests (asso_id, uid, ts, reason) |
621 | VALUES ({?}, {?}, NOW(), {?})", | |
622 | $globals->asso('id'), S::i('uid'), Post::v('message')); | |
08cce2ff | 623 | $res = XDB::query('SELECT IF(m.email IS NULL, |
4af7fd22 FB |
624 | CONCAT(al.alias,"@polytechnique.org"), |
625 | m.email) | |
626 | FROM groupex.membres AS m | |
627 | INNER JOIN aliases AS al ON (al.type = "a_vie" | |
628 | AND al.id = m.uid) | |
629 | WHERE perms="admin" AND m.asso_id = {?}', | |
630 | $globals->asso('id')); | |
fdf0200a | 631 | $emails = $res->fetchColumn(); |
632 | $to = implode(',', $emails); | |
633 | ||
634 | $append = "\n" | |
635 | . "-- \n" | |
a7de4ef7 | 636 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
0fab5209 | 637 | . S::user()->fullName() . ' (X' . S::v('promo') . ")\n" |
fdf0200a | 638 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
639 | . "de refuser sa demande d'inscription depuis la page :\n" | |
0fab5209 | 640 | . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n" |
fdf0200a | 641 | . "\n" |
a7de4ef7 | 642 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
643 | . "à l'adresse : support@polytechnique.org\n"; | |
fdf0200a | 644 | |
645 | if (!$to) { | |
646 | $to = $globals->asso("mail").", support@polytechnique.org"; | |
647 | $append = "\n-- \nLe groupe ".$globals->asso("nom") | |
a7de4ef7 | 648 | ." n'a pas d'administrateur, l'équipe de" |
649 | ." Polytechnique.org a été prévenue et va rapidement" | |
650 | ." résoudre ce problème.\n"; | |
fdf0200a | 651 | } |
652 | ||
1e33266a | 653 | $mailer = new PlMailer(); |
fdf0200a | 654 | $mailer->addTo($to); |
0fab5209 | 655 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
fdf0200a | 656 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc | 657 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a | 658 | $mailer->send(); |
659 | } | |
660 | } | |
661 | ||
4af7fd22 FB |
662 | function handler_subscribe_valid(&$page) |
663 | { | |
664 | global $globals; | |
665 | ||
666 | if (Post::has('valid')) { | |
667 | S::assert_xsrf_token(); | |
668 | $subs = Post::v('subs'); | |
669 | if (is_array($subs)) { | |
670 | $users = array(); | |
0fab5209 | 671 | foreach ($subs as $hruid => $val) { |
4af7fd22 | 672 | if ($val == '1') { |
0fab5209 VZ |
673 | $user = User::get($hruid); |
674 | if ($user) { | |
675 | $this->validSubscription($user); | |
4af7fd22 FB |
676 | } |
677 | } | |
678 | } | |
679 | } | |
680 | } | |
681 | ||
682 | $it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, | |
0fab5209 | 683 | u.prenom, u.promo, u.hruid, s.ts AS date |
4af7fd22 FB |
684 | FROM groupex.membres_sub_requests AS s |
685 | INNER JOIN auth_user_md5 AS u ON (s.uid = u.user_id) | |
4af7fd22 FB |
686 | WHERE asso_id = {?} |
687 | ORDER BY nom, prenom", | |
688 | $globals->asso('id')); | |
689 | ||
690 | $page->changeTpl('xnetgrp/subscribe-valid.tpl'); | |
691 | $page->assign('valid', $it); | |
692 | } | |
693 | ||
b8e265bf | 694 | function handler_change_rights(&$page) |
695 | { | |
696 | if (Env::has('right') && (may_update() || S::has('suid'))) { | |
697 | switch (Env::v('right')) { | |
eaf30d86 | 698 | case 'admin': |
ab694eb5 | 699 | Platal::session()->stopSUID(); |
b8e265bf | 700 | break; |
701 | case 'anim': | |
ab694eb5 | 702 | Platal::session()->doSelfSuid(); |
b8e265bf | 703 | may_update(true); |
704 | is_member(true); | |
705 | break; | |
706 | case 'member': | |
ab694eb5 | 707 | Platal::session()->doSelfSuid(); |
b8e265bf | 708 | may_update(false, true); |
709 | is_member(true); | |
710 | break; | |
711 | case 'logged': | |
ab694eb5 | 712 | Platal::session()->doSelfSuid(); |
b8e265bf | 713 | may_update(false, true); |
714 | is_member(false, true); | |
715 | break; | |
716 | } | |
717 | } | |
ab694eb5 | 718 | // var_dump($_SESSION); |
5603d2ce | 719 | http_redirect($_SERVER['HTTP_REFERER']); |
b8e265bf | 720 | } |
721 | ||
4e310c61 | 722 | function handler_admin_annuaire(&$page) |
723 | { | |
724 | global $globals; | |
725 | ||
460d8f55 | 726 | $this->load('mail.inc.php'); |
1490093c | 727 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
9bb8bf21 | 728 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
729 | $globals->asso('mail_domain')); | |
730 | $lists = $mmlist->get_lists(); | |
4e310c61 | 731 | if (!$lists) $lists = array(); |
732 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); | |
733 | ||
734 | $subscribers = array(); | |
735 | ||
736 | foreach ($listes as $list) { | |
9bb8bf21 | 737 | list(,$members) = $mmlist->get_members($list); |
4e310c61 | 738 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
739 | $subscribers = array_unique(array_merge($subscribers, $mails)); | |
740 | } | |
741 | ||
742 | $not_in_group_x = array(); | |
743 | $not_in_group_ext = array(); | |
744 | ||
745 | foreach ($subscribers as $mail) { | |
08cce2ff | 746 | $res = XDB::query( |
4e310c61 | 747 | 'SELECT COUNT(*) |
748 | FROM groupex.membres AS m | |
749 | LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) | |
750 | LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") | |
751 | WHERE asso_id = {?} AND | |
752 | (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', | |
753 | $globals->asso('id'), $mail, $mail); | |
754 | if ($res->fetchOneCell() == 0) { | |
755 | if (strstr($mail, '@polytechnique.org') === false) { | |
756 | $not_in_group_ext[] = $mail; | |
757 | } else { | |
758 | $not_in_group_x[] = $mail; | |
759 | } | |
760 | } | |
761 | } | |
762 | ||
763 | $page->assign('not_in_group_ext', $not_in_group_ext); | |
764 | $page->assign('not_in_group_x', $not_in_group_x); | |
765 | $page->assign('lists', $lists); | |
766 | } | |
ef7c8560 | 767 | |
768 | function handler_admin_member_new(&$page, $email = null) | |
769 | { | |
770 | global $globals; | |
771 | ||
1490093c | 772 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
dc2073c3 | 773 | $page->addJsLink('ajax.js'); |
ef7c8560 | 774 | |
775 | if (is_null($email)) { | |
776 | return; | |
e7fdf9dd VZ |
777 | } else { |
778 | S::assert_xsrf_token(); | |
ef7c8560 | 779 | } |
780 | ||
a1642859 VZ |
781 | if (!User::isForeignEmailAddress($email)) { |
782 | $user = User::get($email); | |
783 | if ($user) { | |
784 | XDB::execute("REPLACE INTO groupex.membres (uid, asso_id, origine) | |
785 | VALUES ({?}, {?}, 'X')", | |
786 | $user->id(), $globals->asso('id')); | |
787 | pl_redirect("member/" . $user->login()); | |
ef7c8560 | 788 | } |
789 | } else { | |
790 | if (isvalid_email($email)) { | |
dc2073c3 | 791 | if (Env::v('x') && Env::has('userid') && Env::i('userid')) { |
792 | $uid = Env::i('userid'); | |
793 | $res = XDB::query("SELECT * | |
794 | FROM auth_user_md5 | |
06db561e | 795 | WHERE user_id = {?} AND perms = 'pending'", $uid); |
dc2073c3 | 796 | if ($res->numRows() == 1) { |
dc2073c3 | 797 | if (Env::v('market')) { |
e654517d | 798 | $market = Marketing::get($uid, $email); |
799 | if (!$market) { | |
800 | $market = new Marketing($uid, $email, 'group', $globals->asso('nom'), | |
801 | Env::v('market_from'), S::v('uid')); | |
802 | $market->add(); | |
eaf30d86 | 803 | } |
dc2073c3 | 804 | } |
e654517d | 805 | XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email) |
806 | VALUES ({?}, {?}, "X", {?})', | |
807 | $uid, $globals->asso('id'), $email); | |
4af7fd22 | 808 | $this->removeSubscriptionRequest($uid); |
dc2073c3 | 809 | pl_redirect("member/$email"); |
810 | } | |
a7d35093 | 811 | $page->trigError("Utilisateur invalide"); |
dc2073c3 | 812 | } else { |
813 | $res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres'); | |
814 | $uid = max(intval($res->fetchOneCell()), 50001); | |
815 | XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email) | |
816 | VALUES({?},{?},"ext",{?})', $uid, | |
817 | $globals->asso('id'), $email); | |
818 | pl_redirect("member/$email"); | |
819 | } | |
ef7c8560 | 820 | } else { |
faefdbb7 | 821 | $page->trigError("« <strong>$email</strong> » n'est pas une adresse email valide."); |
ef7c8560 | 822 | } |
823 | } | |
824 | } | |
825 | ||
dc2073c3 | 826 | function handler_admin_member_new_ajax(&$page) |
827 | { | |
493b6abe | 828 | header('Content-Type: text/html; charset="UTF-8"'); |
8b1f8e12 | 829 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
e2b0a45c | 830 | $res = null; |
0baf0741 | 831 | if (Env::has('login')) { |
832 | require_once 'user.func.inc.php'; | |
833 | $res = get_not_registered_user(Env::v('login'), true); | |
e2b0a45c | 834 | } |
835 | if (is_null($res)) { | |
0baf0741 | 836 | list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); |
837 | $where = "perms = 'pending'"; | |
838 | if (!empty($nom)) { | |
839 | $where .= " AND nom LIKE '%$nom%'"; | |
840 | } | |
841 | if (!empty($prenom)) { | |
842 | $where .= " AND prenom LIKE '%$prenom%'"; | |
843 | } | |
844 | if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { | |
845 | $where .= " AND promo = " . Env::i('promo'); | |
846 | } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) { | |
847 | $where .= " AND MOD(promo, 100) = " . Env::i('promo'); | |
848 | } elseif (Env::has('promo')) { | |
849 | return; | |
850 | } | |
851 | $res = XDB::iterator("SELECT user_id, nom, prenom, promo | |
852 | FROM auth_user_md5 | |
853 | WHERE $where"); | |
dc2073c3 | 854 | } |
89d5acb4 | 855 | if ($res && $res->total() < 30) { |
dc2073c3 | 856 | $page->assign("choix", $res); |
857 | } | |
858 | } | |
859 | ||
30032578 | 860 | function unsubscribe(&$user) |
ef7c8560 | 861 | { |
d7610c35 | 862 | global $globals; |
08cce2ff | 863 | XDB::execute( |
ef7c8560 | 864 | "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}", |
865 | $user['uid'], $globals->asso('id')); | |
866 | ||
fa9493fe FB |
867 | if ($globals->asso('notif_unsub')) { |
868 | $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); | |
869 | $res = XDB::iterRow("SELECT a.alias, u.prenom, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom | |
870 | FROM groupex.membres AS m | |
871 | INNER JOIN aliases AS a ON (m.uid = a.id AND FIND_IN_SET('bestalias', a.flags)) | |
872 | INNER JOIn auth_user_md5 AS u ON (u.user_id = a.id) | |
873 | WHERE m.asso_id = {?} AND m.perms = 'admin'", | |
874 | $globals->asso('id')); | |
875 | while (list($alias, $prenom, $nom) = $res->next()) { | |
876 | $mailer->addTo("\"$prenom $nom\" <$alias@{$globals->mail->domain}>"); | |
877 | } | |
878 | $mailer->assign('group', $globals->asso('nom')); | |
879 | $mailer->assign('prenom', $user['prenom']); | |
880 | $mailer->assign('nom', $user['nom']); | |
881 | $mailer->assign('mail', $user['email2']); | |
882 | $mailer->assign('selfdone', $user['uid'] == S::i('uid')); | |
883 | $mailer->send(); | |
884 | } | |
eca5d69f | 885 | |
ef7c8560 | 886 | $user_same_email = get_infos($user['email']); |
30032578 | 887 | $domain = $globals->asso('mail_domain'); |
ef7c8560 | 888 | |
52ab632b | 889 | if (!$domain || (!empty($user_same_email) && $user_same_email['uid'] != $user['uid'])) { |
30032578 | 890 | return true; |
891 | } | |
ef7c8560 | 892 | |
30032578 | 893 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
894 | $listes = $mmlist->get_lists($user['email2']); | |
ef7c8560 | 895 | |
30032578 | 896 | $may_update = may_update(); |
897 | $warning = false; | |
898 | foreach ($listes as $liste) { | |
899 | if ($liste['sub'] == 2) { | |
900 | if ($may_update) { | |
9bb8bf21 | 901 | $mmlist->mass_unsubscribe($liste['list'], Array($user['email2'])); |
30032578 | 902 | } else { |
903 | $mmlist->unsubscribe($liste['list']); | |
ef7c8560 | 904 | } |
30032578 | 905 | } elseif ($liste['sub']) { |
d7610c35 FB |
906 | Platal::page()->trigWarning("{$user['prenom']} {$user['nom']} a une" |
907 | ." demande d'inscription en cours sur la" | |
908 | ." liste {$liste['list']}@ !"); | |
30032578 | 909 | $warning = true; |
ef7c8560 | 910 | } |
30032578 | 911 | } |
ef7c8560 | 912 | |
30032578 | 913 | XDB::execute( |
914 | "DELETE FROM virtual_redirect | |
915 | USING virtual_redirect | |
916 | INNER JOIN virtual USING(vid) | |
917 | WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain); | |
918 | return !$warning; | |
919 | } | |
920 | ||
921 | function handler_unsubscribe(&$page) | |
922 | { | |
1490093c | 923 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
0fab5209 | 924 | $user = get_infos(S::user()->id()); |
30032578 | 925 | if (empty($user)) { |
926 | return PL_NOT_FOUND; | |
ef7c8560 | 927 | } |
30032578 | 928 | $page->assign('self', true); |
929 | $page->assign('user', $user); | |
ef7c8560 | 930 | |
30032578 | 931 | if (!Post::has('confirm')) { |
932 | return; | |
e7fdf9dd VZ |
933 | } else { |
934 | S::assert_xsrf_token(); | |
30032578 | 935 | } |
936 | ||
937 | if ($this->unsubscribe($user)) { | |
a7d35093 | 938 | $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.'); |
30032578 | 939 | } else { |
9ec2213d | 940 | $page->trigWarning('Vous avez été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.'); |
30032578 | 941 | } |
c1863ee9 | 942 | $page->assign('is_member', is_member(true)); |
30032578 | 943 | } |
944 | ||
945 | function handler_admin_member_del(&$page, $user = null) | |
946 | { | |
1490093c | 947 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
30032578 | 948 | $user = get_infos($user); |
949 | if (empty($user)) { | |
950 | return PL_NOT_FOUND; | |
951 | } | |
952 | $page->assign('user', $user); | |
953 | ||
954 | if (!Post::has('confirm')) { | |
955 | return; | |
e7fdf9dd VZ |
956 | } else { |
957 | S::assert_xsrf_token(); | |
30032578 | 958 | } |
959 | ||
960 | if ($this->unsubscribe($user)) { | |
a7d35093 | 961 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné du groupe !"); |
30032578 | 962 | } else { |
a7d35093 | 963 | $page->trigWarning("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !"); |
30032578 | 964 | } |
ef7c8560 | 965 | } |
966 | ||
04334c61 | 967 | private function changeLogin(PlPage &$page, array &$user, MMList &$mmlist, $login) |
631565e1 FB |
968 | { |
969 | require_once 'user.func.inc.php'; | |
970 | // Search the uid of the user... | |
971 | $res = XDB::query("SELECT f.id, f.alias | |
972 | FROM aliases AS a | |
973 | INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') | |
974 | WHERE a.alias = {?}", | |
975 | $login); | |
976 | if ($res->numRows() == 0) { | |
977 | $x = get_not_registered_user($login); | |
978 | if (!$x) { | |
a7d35093 | 979 | $page->trigError("Le login $login ne correspond à aucun X."); |
631565e1 FB |
980 | return false; |
981 | } else if (count($x) > 1) { | |
a7d35093 | 982 | $page->trigError("Le login $login correspond a plusieurs camarades."); |
631565e1 FB |
983 | return false; |
984 | } | |
985 | $uid = $x[0]['user_id']; | |
986 | $sub = false; | |
987 | } else { | |
988 | list($uid, $login) = $res->fetchOneRow(); | |
989 | $sub = true; | |
990 | } | |
991 | ||
992 | // Check if the user is already in the group | |
993 | global $globals; | |
994 | $res = XDB::query("SELECT uid, email | |
995 | FROM groupex.membres | |
996 | WHERE uid = {?} AND asso_id = {?}", | |
997 | $uid, $globals->asso('id')); | |
998 | if ($res->numRows()) { | |
999 | list($uid, $email) = $res->fetchOneRow(); | |
1000 | XDB::execute("DELETE FROM groupex.membres | |
1001 | WHERE uid = {?}", | |
1002 | $user['uid']); | |
1003 | } else { | |
1004 | $email = $user['email']; | |
1005 | XDB::execute("UPDATE groupex.membres | |
1006 | SET uid = {?}, origine = 'X' | |
1007 | WHERE uid = {?} AND asso_id = {?}", | |
1008 | $uid, $user['uid'], $globals->asso('id')); | |
1009 | } | |
1010 | if ($sub) { | |
1011 | $email = $login . '@' . $globals->mail->domain; | |
1012 | } | |
1013 | ||
1014 | // Update subscription to aliases | |
1015 | if ($email != $user['email']) { | |
1016 | XDB::execute("UPDATE IGNORE virtual_redirect AS vr | |
148bf011 | 1017 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
631565e1 FB |
1018 | SET vr.redirect = {?} |
1019 | WHERE vr.redirect = {?}", | |
1020 | $globals->asso('mail_domain'), $email, $user['email']); | |
1021 | XDB::execute("DELETE vr.* | |
1022 | FROM virtual_redirect AS vr | |
148bf011 | 1023 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
631565e1 FB |
1024 | WHERE vr.redirect = {?}", |
1025 | $globals->asso('mail_domain'), $user['email']); | |
1026 | foreach (Env::v('ml1', array()) as $ml => $state) { | |
1027 | $mmlist->replace_email($ml, $user['email'], $email); | |
1028 | } | |
1029 | } | |
4478f12e FB |
1030 | if ($sub) { |
1031 | return $login; | |
1032 | } | |
1033 | return $user['email']; | |
631565e1 FB |
1034 | } |
1035 | ||
ef7c8560 | 1036 | function handler_admin_member(&$page, $user) |
1037 | { | |
1038 | global $globals; | |
1039 | ||
1490093c | 1040 | $page->changeTpl('xnetgrp/membres-edit.tpl'); |
ef7c8560 | 1041 | |
1042 | $user = get_infos($user); | |
1043 | if (empty($user)) { | |
1044 | return PL_NOT_FOUND; | |
1045 | } | |
1046 | ||
9bb8bf21 | 1047 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
1048 | $globals->asso('mail_domain')); | |
ef7c8560 | 1049 | |
1050 | if (Post::has('change')) { | |
e7fdf9dd VZ |
1051 | S::assert_xsrf_token(); |
1052 | ||
631565e1 FB |
1053 | // Convert user status to X |
1054 | if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) { | |
1055 | $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X'))); | |
1056 | if ($forlife) { | |
1057 | pl_redirect('member/' . $forlife); | |
1058 | } | |
1059 | } | |
1060 | ||
1061 | // Update user info | |
cf5e8ef1 | 1062 | $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); |
c4d57bd8 | 1063 | $from_email = $user['email']; |
ef7c8560 | 1064 | if ($user['origine'] != 'X') { |
06db561e | 1065 | $user['nom'] = Post::v('nom'); |
1066 | $user['prenom'] = (Post::v('origine') == 'ext') ? Post::v('prenom') : ''; | |
1067 | $user['sexe'] = (Post::v('origine') == 'ext') ? Post::v('sexe') : 0; | |
1068 | $user['origine'] = Post::v('origine'); | |
08cce2ff | 1069 | XDB::query('UPDATE groupex.membres |
06db561e | 1070 | SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?} |
0cc4c07d | 1071 | WHERE uid={?} AND asso_id={?}', |
06db561e | 1072 | $user['prenom'], $user['nom'], Post::v('email'), |
54b24ba2 FB |
1073 | $user['sexe'], $user['origine'], |
1074 | $user['uid'], $globals->asso('id')); | |
06db561e | 1075 | $user['email'] = Post::v('email'); |
1076 | $user['email2'] = Post::v('email'); | |
54b24ba2 | 1077 | $page->trigSuccess('Données de l\'utilisateur mise à jour.'); |
ef7c8560 | 1078 | } |
1079 | ||
5e2307dc | 1080 | $perms = Post::i('is_admin'); |
54b24ba2 FB |
1081 | $comm = trim(Post::s('comm')); |
1082 | if ($user['perms'] != $perms || $user['comm'] != $comm) { | |
1083 | XDB::query('UPDATE groupex.membres | |
1084 | SET perms={?}, comm={?} | |
0cc4c07d | 1085 | WHERE uid={?} AND asso_id={?}', |
54b24ba2 | 1086 | $perms ? 'admin' : 'membre', $comm, |
0cc4c07d | 1087 | $user['uid'], $globals->asso('id')); |
54b24ba2 FB |
1088 | if ($perms != $user['perms']) { |
1089 | $page->trigSuccess('Permissions modifiées !'); | |
1090 | } | |
1091 | if ($comm != $user['comm']) { | |
1092 | $page->trigSuccess('Commentaire mis à jour.'); | |
1093 | } | |
ef7c8560 | 1094 | $user['perms'] = $perms; |
54b24ba2 | 1095 | $user['comm'] = $comm; |
ef7c8560 | 1096 | } |
1097 | ||
631565e1 | 1098 | // Update ML subscriptions |
5e2307dc | 1099 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 1100 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 1101 | if ($ask == $state) { |
06db561e | 1102 | if ($state && $email_changed) { |
c4d57bd8 | 1103 | $mmlist->replace_email($ml, $from_email, $user['email2']); |
a7d35093 | 1104 | $page->trigSuccess("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour."); |
c4d57bd8 | 1105 | } |
1106 | continue; | |
1107 | } | |
ef7c8560 | 1108 | if ($state == '1') { |
a7d35093 | 1109 | $page->trigWarning("{$user['prenom']} {$user['nom']} a " |
ef7c8560 | 1110 | ."actuellement une demande d'inscription en " |
1111 | ."cours sur <strong>$ml@</strong> !!!"); | |
1112 | } elseif ($ask) { | |
9bb8bf21 | 1113 | $mmlist->mass_subscribe($ml, Array($user['email2'])); |
a7d35093 | 1114 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml@."); |
ef7c8560 | 1115 | } else { |
c4d57bd8 | 1116 | if ($email_changed) { |
1117 | $mmlist->mass_unsubscribe($ml, Array($from_email)); | |
1118 | } else { | |
1119 | $mmlist->mass_unsubscribe($ml, Array($user['email2'])); | |
1120 | } | |
a7d35093 | 1121 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@."); |
ef7c8560 | 1122 | } |
1123 | } | |
1124 | ||
631565e1 | 1125 | // Change subscriptioin to aliases |
5e2307dc | 1126 | foreach (Env::v('ml3', array()) as $ml => $state) { |
ef7c8560 | 1127 | $ask = !empty($_REQUEST['ml4'][$ml]); |
1128 | if($state == $ask) continue; | |
1129 | if($ask) { | |
08cce2ff | 1130 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
dc2073c3 | 1131 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
1132 | $user['email'], $ml); | |
a7d35093 | 1133 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml."); |
ef7c8560 | 1134 | } else { |
08cce2ff | 1135 | XDB::query("DELETE FROM virtual_redirect |
dc2073c3 | 1136 | USING virtual_redirect |
1137 | INNER JOIN virtual USING(vid) | |
1138 | WHERE redirect={?} AND alias={?}", | |
1139 | $user['email'], $ml); | |
a7d35093 | 1140 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml."); |
ef7c8560 | 1141 | } |
1142 | } | |
1143 | } | |
1144 | ||
1145 | $page->assign('user', $user); | |
9bb8bf21 | 1146 | $listes = $mmlist->get_lists($user['email2']); |
ef7c8560 | 1147 | $page->assign('listes', $listes); |
1148 | ||
08cce2ff | 1149 | $res = XDB::query( |
ef7c8560 | 1150 | 'SELECT alias, redirect IS NOT NULL as sub |
1151 | FROM virtual AS v | |
148bf011 | 1152 | LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND (redirect = {?} OR redirect = {?})) |
ef7c8560 | 1153 | WHERE alias LIKE {?} AND type="user"', |
148bf011 | 1154 | $user['email'], $user['email2'], '%@'.$globals->asso('mail_domain')); |
ef7c8560 | 1155 | $page->assign('alias', $res->fetchAllAssoc()); |
1156 | } | |
24bcf50c | 1157 | |
1158 | function handler_rss(&$page, $user = null, $hash = null) | |
1159 | { | |
1160 | global $globals; | |
24bcf50c | 1161 | $page->assign('asso', $globals->asso()); |
4f18bb11 | 1162 | |
460d8f55 | 1163 | $this->load('feed.inc.php'); |
4f18bb11 FB |
1164 | $feed = new XnetGrpEventFeed(); |
1165 | return $feed->run($page, $user, $hash, false); | |
24bcf50c | 1166 | } |
1167 | ||
04334c61 | 1168 | private function upload_image(PlPage &$page, PlUpload &$upload) |
ff95a302 FB |
1169 | { |
1170 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
1171 | return true; | |
1172 | } | |
1173 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
a7d35093 | 1174 | $page->trigError('Impossible de télécharger l\'image'); |
ff95a302 FB |
1175 | return false; |
1176 | } elseif (!$upload->isType('image')) { | |
a7d35093 | 1177 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
ff95a302 FB |
1178 | $upload->rm(); |
1179 | return false; | |
1180 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
a7d35093 | 1181 | $page->trigError('Impossible de retraiter l\'image'); |
ff95a302 FB |
1182 | return false; |
1183 | } | |
1184 | return true; | |
1185 | } | |
1186 | ||
1187 | function handler_photo_announce(&$page, $eid = null) { | |
1188 | if ($eid) { | |
1189 | $res = XDB::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid); | |
1190 | if ($res->numRows()) { | |
1191 | $photo = $res->fetchOneAssoc(); | |
1192 | header('Content-Type: image/' . $photo['attachmime']); | |
1193 | echo $photo['attach']; | |
1194 | exit; | |
1195 | } | |
1196 | } else { | |
f3df6d38 | 1197 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 FB |
1198 | if ($upload->exists() && $upload->isType('image')) { |
1199 | header('Content-Type: ' . $upload->contentType()); | |
1200 | echo $upload->getContents(); | |
1201 | exit; | |
1202 | } | |
1203 | } | |
1204 | global $globals; | |
1205 | header('Content-Type: image/png'); | |
1206 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); | |
1207 | exit; | |
1208 | } | |
1209 | ||
24bcf50c | 1210 | function handler_edit_announce(&$page, $aid = null) |
1211 | { | |
1212 | global $globals, $platal; | |
1490093c | 1213 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1214 | $page->assign('new', is_null($aid)); |
1215 | $art = array(); | |
1216 | ||
ff95a302 | 1217 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
2f8677c2 | 1218 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
e7fdf9dd VZ |
1219 | S::assert_xsrf_token(); |
1220 | ||
24bcf50c | 1221 | if (!is_null($aid)) { |
1222 | $art['id'] = $aid; | |
1223 | } | |
1224 | $art['titre'] = Post::v('titre'); | |
1225 | $art['texte'] = Post::v('texte'); | |
1226 | $art['contacts'] = Post::v('contacts'); | |
1227 | $art['promo_min'] = Post::i('promo_min'); | |
1228 | $art['promo_max'] = Post::i('promo_max'); | |
1229 | $art['nom'] = S::v('nom'); | |
1230 | $art['prenom'] = S::v('prenom'); | |
1231 | $art['promo'] = S::v('promo'); | |
0fab5209 | 1232 | $art['hruid'] = S::user()->login(); |
24bcf50c | 1233 | $art['peremption'] = Post::v('peremption'); |
1234 | $art['public'] = Post::has('public'); | |
1235 | $art['xorg'] = Post::has('xorg'); | |
1236 | $art['nl'] = Post::has('nl'); | |
1237 | $art['event'] = Post::v('event'); | |
f3df6d38 | 1238 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1239 | $this->upload_image($page, $upload); |
24bcf50c | 1240 | |
1241 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1242 | if ($art['event']) { |
1243 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1244 | } |
2a557a09 | 1245 | |
1246 | if (!$art['public'] && | |
d1c97e42 | 1247 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1248 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1249 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1250 | { | |
a7d35093 | 1251 | $page->trigError("L'intervalle de promotions est invalide."); |
2a557a09 | 1252 | Post::kill('valid'); |
1253 | } | |
1970c12b | 1254 | |
1255 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
a7d35093 | 1256 | $page->trigError("L'article doit avoir un titre et un contenu."); |
1970c12b | 1257 | Post::kill('valid'); |
1258 | } | |
ff95a302 FB |
1259 | |
1260 | if (Post::v('valid') == 'Supprimer l\'image') { | |
1261 | $upload->rm(); | |
1262 | Post::kill('valid'); | |
1263 | } | |
2f8677c2 FB |
1264 | $art['photo'] = $upload->exists() || Post::i('photo'); |
1265 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { | |
1266 | XDB::query("DELETE FROM groupex.announces_photo WHERE eid = {?}", $aid); | |
1267 | $upload->rm(); | |
1268 | Post::kill('valid'); | |
1269 | $art['photo'] = false; | |
1270 | } | |
24bcf50c | 1271 | } |
1272 | ||
1273 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1274 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1275 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
113f6de8 | 1276 | $flags = new PlFlagSet(); |
ff95a302 | 1277 | if ($art['public']) { |
77e786e1 | 1278 | $flags->addFlag('public'); |
ff95a302 FB |
1279 | } |
1280 | if ($art['photo']) { | |
77e786e1 | 1281 | $flags->addFlag('photo'); |
ff95a302 | 1282 | } |
24bcf50c | 1283 | if (is_null($aid)) { |
eaf30d86 PH |
1284 | $fulltext = $art['texte']; |
1285 | if (!empty($art['contact_html'])) { | |
1286 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1287 | } |
ff95a302 | 1288 | $post = null;/* |
e219710a | 1289 | if ($globals->asso('forum')) { |
1290 | require_once 'banana/forum.inc.php'; | |
e3a55098 | 1291 | $banana = new ForumsBanana(S::user()); |
e219710a | 1292 | $post = $banana->post($globals->asso('forum'), null, |
1293 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
ff95a302 | 1294 | }*/ |
24bcf50c | 1295 | XDB::query("INSERT INTO groupex.announces |
1296 | (user_id, asso_id, create_date, titre, texte, contacts, | |
e219710a | 1297 | peremption, promo_min, promo_max, flags, post_id) |
1298 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
24bcf50c | 1299 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
ff95a302 | 1300 | $art['peremption'], $promo_min, $promo_max, $flags, $post); |
8b83a166 | 1301 | $aid = XDB::insertId(); |
ff95a302 FB |
1302 | if ($art['photo']) { |
1303 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
1304 | XDB::execute("INSERT INTO groupex.announces_photo | |
1305 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", | |
1306 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); | |
1307 | } | |
24bcf50c | 1308 | if ($art['xorg']) { |
1309 | require_once('validations.inc.php'); | |
794feea7 | 1310 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
5daf68f6 | 1311 | $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(), |
ff95a302 | 1312 | $upload); |
24bcf50c | 1313 | $article->submit(); |
a7d35093 | 1314 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
ff95a302 FB |
1315 | } else if ($upload && $upload->exists()) { |
1316 | $upload->rm(); | |
24bcf50c | 1317 | } |
1318 | if ($art['nl']) { | |
1319 | require_once('validations.inc.php'); | |
5daf68f6 | 1320 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
2a557a09 | 1321 | $art['texte'], $art['contact_html']); |
24bcf50c | 1322 | $article->submit(); |
a7d35093 | 1323 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
24bcf50c | 1324 | } |
1325 | } else { | |
1326 | XDB::query("UPDATE groupex.announces | |
1327 | SET titre={?}, texte={?}, contacts={?}, peremption={?}, | |
1328 | promo_min={?}, promo_max={?}, flags={?} | |
1329 | WHERE id={?} AND asso_id={?}", | |
1330 | $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], | |
ff95a302 | 1331 | $promo_min, $promo_max, $flags, |
24bcf50c | 1332 | $art['id'], $globals->asso('id')); |
2f8677c2 FB |
1333 | if ($art['photo'] && $upload->exists()) { |
1334 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
1335 | XDB::execute("REPLACE INTO groupex.announces_photo | |
1336 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", | |
1337 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); | |
1338 | $upload->rm(); | |
1339 | } | |
24bcf50c | 1340 | } |
2a557a09 | 1341 | } |
1342 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1343 | pl_redirect(""); |
eaf30d86 | 1344 | } |
24bcf50c | 1345 | |
1346 | if (empty($art) && !is_null($aid)) { | |
0fab5209 | 1347 | $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid, |
2f8677c2 FB |
1348 | FIND_IN_SET('public', a.flags) AS public, |
1349 | FIND_IN_SET('photo', a.flags) AS photo | |
24bcf50c | 1350 | FROM groupex.announces AS a |
1351 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
24bcf50c | 1352 | WHERE asso_id = {?} AND a.id = {?}", |
1353 | $globals->asso('id'), $aid); | |
1354 | if ($res->numRows()) { | |
1355 | $art = $res->fetchOneAssoc(); | |
1356 | $art['contact_html'] = $art['contacts']; | |
1357 | } else { | |
567553ac | 1358 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
24bcf50c | 1359 | } |
1360 | } | |
1361 | ||
24bcf50c | 1362 | if (is_null($aid)) { |
1363 | $events = XDB::iterator("SELECT * | |
1364 | FROM groupex.evenements | |
1365 | WHERE asso_id = {?} AND archive = 0", | |
1366 | $globals->asso('id')); | |
1367 | if ($events->total()) { | |
1368 | $page->assign('events', $events); | |
1369 | } | |
eaf30d86 | 1370 | } |
24bcf50c | 1371 | |
72b2f8bb | 1372 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1373 | $page->assign('art', $art); |
ff95a302 | 1374 | $page->assign_by_ref('upload', $upload); |
24bcf50c | 1375 | } |
1376 | ||
1377 | function handler_admin_announce(&$page) | |
1378 | { | |
1379 | global $globals; | |
1490093c | 1380 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1381 | |
1382 | if (Env::has('del')) { | |
e7fdf9dd | 1383 | S::assert_xsrf_token(); |
e219710a | 1384 | XDB::execute("DELETE FROM groupex.announces |
1385 | WHERE id = {?} AND asso_id = {?}", | |
24bcf50c | 1386 | Env::i('del'), $globals->asso('id')); |
1387 | } | |
e219710a | 1388 | $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime |
1389 | FROM groupex.announces AS a | |
1390 | WHERE a.asso_id = {?} | |
1391 | ORDER BY a.peremption DESC", | |
24bcf50c | 1392 | $globals->asso('id')); |
1393 | $page->assign('articles', $res); | |
1394 | } | |
ae7bb180 | 1395 | } |
1396 | ||
a7de4ef7 | 1397 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
ae7bb180 | 1398 | ?> |