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')); | |
481 | $vcard = new VCard($res->fetchColumn(), $photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); | |
482 | $vcard->do_page($page); | |
5e193297 | 483 | } |
484 | ||
102f4e64 FB |
485 | function handler_csv(&$page, $filename = null) |
486 | { | |
487 | global $globals; | |
488 | if (is_null($filename)) { | |
489 | $filename = $globals->asso('diminutif') . '.csv'; | |
490 | } | |
491 | $ann = XDB::iterator( | |
492 | "SELECT IF(m.origine='X',IF(u.nom_usage<>'', u.nom_usage, u.nom) ,m.nom) AS nom, | |
493 | IF(m.origine='X',u.prenom,m.prenom) AS prenom, | |
494 | IF(m.origine='X', u.promo, IF(m.origine='ext', 'extérieur', 'personne morale')) AS promo, | |
495 | IF(m.origine='X' AND u.perms != 'pending',CONCAT(a.alias, '@', {?}), m.email) AS email, | |
496 | IF(m.origine='X',FIND_IN_SET('femme', u.flags), m.sexe) AS femme, | |
497 | m.comm as comm | |
498 | FROM groupex.membres AS m | |
499 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = m.uid ) | |
500 | LEFT JOIN aliases AS a ON ( a.id = m.uid AND a.type = 'a_vie' ) | |
501 | WHERE m.asso_id = {?} | |
502 | AND (m.origine != 'X' OR u.perms != 'pending' OR m.email IS NOT NULL) | |
503 | GROUP BY m.uid | |
504 | ORDER BY nom, prenom", | |
505 | $globals->mail->domain, $globals->asso('id')); | |
506 | header('Content-Type: text/x-csv; charset=utf-8;'); | |
507 | header('Pragma: '); | |
508 | header('Cache-Control: '); | |
509 | $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN); | |
510 | $page->assign('ann', $ann); | |
511 | } | |
512 | ||
4af7fd22 FB |
513 | private function removeSubscriptionRequest($uid) |
514 | { | |
515 | global $globals; | |
516 | XDB::execute("DELETE FROM groupex.membres_sub_requests | |
517 | WHERE asso_id = {?} AND uid = {?}", | |
518 | $globals->asso('id'), $uid); | |
519 | } | |
520 | ||
0fab5209 | 521 | private function validSubscription(User &$user) |
4af7fd22 FB |
522 | { |
523 | global $globals; | |
0fab5209 | 524 | $this->removeSubscriptionRequest($user->id()); |
4af7fd22 FB |
525 | XDB::execute("INSERT INTO groupex.membres (asso_id, uid) |
526 | VALUES ({?}, {?})", | |
0fab5209 | 527 | $globals->asso('id'), $user->id()); |
4af7fd22 | 528 | $mailer = new PlMailer(); |
0fab5209 VZ |
529 | $mailer->addTo($user->forlifeEmail()); |
530 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
4af7fd22 | 531 | $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); |
0fab5209 | 532 | $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n" |
4af7fd22 FB |
533 | . "\n" |
534 | . " Suite à ta demande d'adhésion à " . $globals->asso('nom') . ",\n" | |
535 | . "j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" | |
536 | . "\n" | |
537 | . "Bien cordialement,\n" | |
538 | . "-- \n" | |
0fab5209 | 539 | . S::user()->fullName() . '.'; |
4af7fd22 FB |
540 | $mailer->setTxtBody($message); |
541 | $mailer->send(); | |
542 | } | |
543 | ||
fdf0200a | 544 | function handler_subscribe(&$page, $u = null) |
545 | { | |
c8faf82a | 546 | global $globals; |
1490093c | 547 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
fdf0200a | 548 | |
549 | if (!$globals->asso('inscriptible')) | |
a7de4ef7 | 550 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
551 | ."groupe. Essaie de joindre le contact indiqué " | |
552 | ."sur la page de présentation."); | |
fdf0200a | 553 | |
554 | if (!is_null($u) && may_update()) { | |
0fab5209 VZ |
555 | $user = User::get($u); |
556 | if (!$user) { | |
557 | return PL_NOT_FOUND; | |
558 | } else { | |
559 | $page->assign('user', $user); | |
fdf0200a | 560 | } |
0fab5209 VZ |
561 | |
562 | // Retrieves the subscription status, and the reason. | |
563 | $res = XDB::query("SELECT reason | |
564 | FROM groupex.membres_sub_requests | |
565 | WHERE asso_id = {?} AND uid = {?}", | |
566 | $globals->asso('id'), $user->id()); | |
567 | $reason = ($res->numRows() ? $res->fetchOneCell() : null); | |
568 | ||
569 | $res = XDB::query("SELECT COUNT(*) | |
570 | FROM groupex.membres | |
571 | WHERE asso_id = {?} AND uid = {?}", | |
572 | $globals->asso('id'), $user->id()); | |
573 | $already_member = ($res->fetchOneCell() > 0); | |
574 | ||
575 | // Handles the membership request. | |
576 | if ($already_member) { | |
577 | $this->removeSubscriptionRequest($user->id()); | |
578 | $page->kill($user->fullName() . " est déjà membre du groupe !"); | |
579 | } elseif (Env::has('accept')) { | |
580 | S::assert_xsrf_token(); | |
581 | ||
582 | $this->validSubscription($user); | |
583 | pl_redirect("member/" . $user->login()); | |
584 | } elseif (Env::has('refuse')) { | |
585 | S::assert_xsrf_token(); | |
586 | ||
587 | $this->removeSubscriptionRequest($user->id()); | |
588 | $mailer = new PlMailer(); | |
589 | $mailer->addTo($user->forlifeEmail()); | |
590 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
591 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); | |
592 | $mailer->setTxtBody(Env::v('motif')); | |
593 | $mailer->send(); | |
594 | $page->kill("La demande de {$user->fullName()} a bien été refusée."); | |
595 | } else { | |
596 | $page->assign('show_form', true); | |
597 | $page->assign('reason', $reason); | |
598 | } | |
599 | return; | |
fdf0200a | 600 | } |
601 | ||
602 | if (is_member()) { | |
567553ac | 603 | $page->kill("Tu es déjà membre !"); |
fdf0200a | 604 | return; |
605 | } | |
606 | ||
4af7fd22 FB |
607 | $res = XDB::query("SELECT uid |
608 | FROM groupex.membres_sub_requests | |
609 | WHERE uid = {?} AND asso_id = {?}", | |
610 | S::i('uid'), $globals->asso('id')); | |
611 | if ($res->numRows() != 0) { | |
612 | $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation."); | |
613 | return; | |
614 | } | |
615 | ||
fdf0200a | 616 | if (Post::has('inscrire')) { |
e7fdf9dd VZ |
617 | S::assert_xsrf_token(); |
618 | ||
4af7fd22 FB |
619 | XDB::execute("INSERT INTO groupex.membres_sub_requests (asso_id, uid, ts, reason) |
620 | VALUES ({?}, {?}, NOW(), {?})", | |
621 | $globals->asso('id'), S::i('uid'), Post::v('message')); | |
08cce2ff | 622 | $res = XDB::query('SELECT IF(m.email IS NULL, |
4af7fd22 FB |
623 | CONCAT(al.alias,"@polytechnique.org"), |
624 | m.email) | |
625 | FROM groupex.membres AS m | |
626 | INNER JOIN aliases AS al ON (al.type = "a_vie" | |
627 | AND al.id = m.uid) | |
628 | WHERE perms="admin" AND m.asso_id = {?}', | |
629 | $globals->asso('id')); | |
fdf0200a | 630 | $emails = $res->fetchColumn(); |
631 | $to = implode(',', $emails); | |
632 | ||
633 | $append = "\n" | |
634 | . "-- \n" | |
a7de4ef7 | 635 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
0fab5209 | 636 | . S::user()->fullName() . ' (X' . S::v('promo') . ")\n" |
fdf0200a | 637 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
638 | . "de refuser sa demande d'inscription depuis la page :\n" | |
0fab5209 | 639 | . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n" |
fdf0200a | 640 | . "\n" |
a7de4ef7 | 641 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
642 | . "à l'adresse : support@polytechnique.org\n"; | |
fdf0200a | 643 | |
644 | if (!$to) { | |
645 | $to = $globals->asso("mail").", support@polytechnique.org"; | |
646 | $append = "\n-- \nLe groupe ".$globals->asso("nom") | |
a7de4ef7 | 647 | ." n'a pas d'administrateur, l'équipe de" |
648 | ." Polytechnique.org a été prévenue et va rapidement" | |
649 | ." résoudre ce problème.\n"; | |
fdf0200a | 650 | } |
651 | ||
1e33266a | 652 | $mailer = new PlMailer(); |
fdf0200a | 653 | $mailer->addTo($to); |
0fab5209 | 654 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
fdf0200a | 655 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc | 656 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a | 657 | $mailer->send(); |
658 | } | |
659 | } | |
660 | ||
4af7fd22 FB |
661 | function handler_subscribe_valid(&$page) |
662 | { | |
663 | global $globals; | |
664 | ||
665 | if (Post::has('valid')) { | |
666 | S::assert_xsrf_token(); | |
667 | $subs = Post::v('subs'); | |
668 | if (is_array($subs)) { | |
669 | $users = array(); | |
0fab5209 | 670 | foreach ($subs as $hruid => $val) { |
4af7fd22 | 671 | if ($val == '1') { |
0fab5209 VZ |
672 | $user = User::get($hruid); |
673 | if ($user) { | |
674 | $this->validSubscription($user); | |
4af7fd22 FB |
675 | } |
676 | } | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | $it = XDB::iterator("SELECT IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom, | |
0fab5209 | 682 | u.prenom, u.promo, u.hruid, s.ts AS date |
4af7fd22 FB |
683 | FROM groupex.membres_sub_requests AS s |
684 | INNER JOIN auth_user_md5 AS u ON (s.uid = u.user_id) | |
4af7fd22 FB |
685 | WHERE asso_id = {?} |
686 | ORDER BY nom, prenom", | |
687 | $globals->asso('id')); | |
688 | ||
689 | $page->changeTpl('xnetgrp/subscribe-valid.tpl'); | |
690 | $page->assign('valid', $it); | |
691 | } | |
692 | ||
b8e265bf | 693 | function handler_change_rights(&$page) |
694 | { | |
695 | if (Env::has('right') && (may_update() || S::has('suid'))) { | |
696 | switch (Env::v('right')) { | |
eaf30d86 | 697 | case 'admin': |
ab694eb5 | 698 | Platal::session()->stopSUID(); |
b8e265bf | 699 | break; |
700 | case 'anim': | |
ab694eb5 | 701 | Platal::session()->doSelfSuid(); |
b8e265bf | 702 | may_update(true); |
703 | is_member(true); | |
704 | break; | |
705 | case 'member': | |
ab694eb5 | 706 | Platal::session()->doSelfSuid(); |
b8e265bf | 707 | may_update(false, true); |
708 | is_member(true); | |
709 | break; | |
710 | case 'logged': | |
ab694eb5 | 711 | Platal::session()->doSelfSuid(); |
b8e265bf | 712 | may_update(false, true); |
713 | is_member(false, true); | |
714 | break; | |
715 | } | |
716 | } | |
ab694eb5 | 717 | // var_dump($_SESSION); |
5603d2ce | 718 | http_redirect($_SERVER['HTTP_REFERER']); |
b8e265bf | 719 | } |
720 | ||
4e310c61 | 721 | function handler_admin_annuaire(&$page) |
722 | { | |
723 | global $globals; | |
724 | ||
460d8f55 | 725 | $this->load('mail.inc.php'); |
1490093c | 726 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
9bb8bf21 | 727 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
728 | $globals->asso('mail_domain')); | |
729 | $lists = $mmlist->get_lists(); | |
4e310c61 | 730 | if (!$lists) $lists = array(); |
731 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); | |
732 | ||
733 | $subscribers = array(); | |
734 | ||
735 | foreach ($listes as $list) { | |
9bb8bf21 | 736 | list(,$members) = $mmlist->get_members($list); |
4e310c61 | 737 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
738 | $subscribers = array_unique(array_merge($subscribers, $mails)); | |
739 | } | |
740 | ||
741 | $not_in_group_x = array(); | |
742 | $not_in_group_ext = array(); | |
743 | ||
744 | foreach ($subscribers as $mail) { | |
08cce2ff | 745 | $res = XDB::query( |
4e310c61 | 746 | 'SELECT COUNT(*) |
747 | FROM groupex.membres AS m | |
748 | LEFT JOIN auth_user_md5 AS u ON (m.uid=u.user_id AND m.uid<50000) | |
749 | LEFT JOIN aliases AS a ON (a.id=u.user_id and a.type="a_vie") | |
750 | WHERE asso_id = {?} AND | |
751 | (m.email = {?} OR CONCAT(a.alias, "@polytechnique.org") = {?})', | |
752 | $globals->asso('id'), $mail, $mail); | |
753 | if ($res->fetchOneCell() == 0) { | |
754 | if (strstr($mail, '@polytechnique.org') === false) { | |
755 | $not_in_group_ext[] = $mail; | |
756 | } else { | |
757 | $not_in_group_x[] = $mail; | |
758 | } | |
759 | } | |
760 | } | |
761 | ||
762 | $page->assign('not_in_group_ext', $not_in_group_ext); | |
763 | $page->assign('not_in_group_x', $not_in_group_x); | |
764 | $page->assign('lists', $lists); | |
765 | } | |
ef7c8560 | 766 | |
767 | function handler_admin_member_new(&$page, $email = null) | |
768 | { | |
769 | global $globals; | |
770 | ||
1490093c | 771 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
dc2073c3 | 772 | $page->addJsLink('ajax.js'); |
ef7c8560 | 773 | |
774 | if (is_null($email)) { | |
775 | return; | |
e7fdf9dd VZ |
776 | } else { |
777 | S::assert_xsrf_token(); | |
ef7c8560 | 778 | } |
779 | ||
a1642859 VZ |
780 | if (!User::isForeignEmailAddress($email)) { |
781 | $user = User::get($email); | |
782 | if ($user) { | |
783 | XDB::execute("REPLACE INTO groupex.membres (uid, asso_id, origine) | |
784 | VALUES ({?}, {?}, 'X')", | |
785 | $user->id(), $globals->asso('id')); | |
786 | pl_redirect("member/" . $user->login()); | |
ef7c8560 | 787 | } |
788 | } else { | |
789 | if (isvalid_email($email)) { | |
dc2073c3 | 790 | if (Env::v('x') && Env::has('userid') && Env::i('userid')) { |
791 | $uid = Env::i('userid'); | |
792 | $res = XDB::query("SELECT * | |
793 | FROM auth_user_md5 | |
06db561e | 794 | WHERE user_id = {?} AND perms = 'pending'", $uid); |
dc2073c3 | 795 | if ($res->numRows() == 1) { |
dc2073c3 | 796 | if (Env::v('market')) { |
e654517d | 797 | $market = Marketing::get($uid, $email); |
798 | if (!$market) { | |
799 | $market = new Marketing($uid, $email, 'group', $globals->asso('nom'), | |
800 | Env::v('market_from'), S::v('uid')); | |
801 | $market->add(); | |
eaf30d86 | 802 | } |
dc2073c3 | 803 | } |
e654517d | 804 | XDB::execute('INSERT INTO groupex.membres (uid, asso_id, origine, email) |
805 | VALUES ({?}, {?}, "X", {?})', | |
806 | $uid, $globals->asso('id'), $email); | |
4af7fd22 | 807 | $this->removeSubscriptionRequest($uid); |
dc2073c3 | 808 | pl_redirect("member/$email"); |
809 | } | |
a7d35093 | 810 | $page->trigError("Utilisateur invalide"); |
dc2073c3 | 811 | } else { |
812 | $res = XDB::query('SELECT MAX(uid)+1 FROM groupex.membres'); | |
813 | $uid = max(intval($res->fetchOneCell()), 50001); | |
814 | XDB::execute('INSERT INTO groupex.membres (uid,asso_id,origine,email) | |
815 | VALUES({?},{?},"ext",{?})', $uid, | |
816 | $globals->asso('id'), $email); | |
817 | pl_redirect("member/$email"); | |
818 | } | |
ef7c8560 | 819 | } else { |
faefdbb7 | 820 | $page->trigError("« <strong>$email</strong> » n'est pas une adresse email valide."); |
ef7c8560 | 821 | } |
822 | } | |
823 | } | |
824 | ||
dc2073c3 | 825 | function handler_admin_member_new_ajax(&$page) |
826 | { | |
493b6abe | 827 | header('Content-Type: text/html; charset="UTF-8"'); |
8b1f8e12 | 828 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
e2b0a45c | 829 | $res = null; |
0baf0741 | 830 | if (Env::has('login')) { |
831 | require_once 'user.func.inc.php'; | |
832 | $res = get_not_registered_user(Env::v('login'), true); | |
e2b0a45c | 833 | } |
834 | if (is_null($res)) { | |
0baf0741 | 835 | list($nom, $prenom) = str_replace(array('-', ' ', "'"), '%', array(Env::v('nom'), Env::v('prenom'))); |
836 | $where = "perms = 'pending'"; | |
837 | if (!empty($nom)) { | |
838 | $where .= " AND nom LIKE '%$nom%'"; | |
839 | } | |
840 | if (!empty($prenom)) { | |
841 | $where .= " AND prenom LIKE '%$prenom%'"; | |
842 | } | |
843 | if (preg_match('/^[0-9]{4}$/', Env::v('promo'))) { | |
844 | $where .= " AND promo = " . Env::i('promo'); | |
845 | } elseif (preg_match('/^[0-9]{2}$/', Env::v('promo'))) { | |
846 | $where .= " AND MOD(promo, 100) = " . Env::i('promo'); | |
847 | } elseif (Env::has('promo')) { | |
848 | return; | |
849 | } | |
850 | $res = XDB::iterator("SELECT user_id, nom, prenom, promo | |
851 | FROM auth_user_md5 | |
852 | WHERE $where"); | |
dc2073c3 | 853 | } |
89d5acb4 | 854 | if ($res && $res->total() < 30) { |
dc2073c3 | 855 | $page->assign("choix", $res); |
856 | } | |
857 | } | |
858 | ||
30032578 | 859 | function unsubscribe(&$user) |
ef7c8560 | 860 | { |
d7610c35 | 861 | global $globals; |
08cce2ff | 862 | XDB::execute( |
ef7c8560 | 863 | "DELETE FROM groupex.membres WHERE uid={?} AND asso_id={?}", |
864 | $user['uid'], $globals->asso('id')); | |
865 | ||
fa9493fe FB |
866 | if ($globals->asso('notif_unsub')) { |
867 | $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); | |
868 | $res = XDB::iterRow("SELECT a.alias, u.prenom, IF(u.nom_usage != '', u.nom_usage, u.nom) AS nom | |
869 | FROM groupex.membres AS m | |
870 | INNER JOIN aliases AS a ON (m.uid = a.id AND FIND_IN_SET('bestalias', a.flags)) | |
871 | INNER JOIn auth_user_md5 AS u ON (u.user_id = a.id) | |
872 | WHERE m.asso_id = {?} AND m.perms = 'admin'", | |
873 | $globals->asso('id')); | |
874 | while (list($alias, $prenom, $nom) = $res->next()) { | |
875 | $mailer->addTo("\"$prenom $nom\" <$alias@{$globals->mail->domain}>"); | |
876 | } | |
877 | $mailer->assign('group', $globals->asso('nom')); | |
878 | $mailer->assign('prenom', $user['prenom']); | |
879 | $mailer->assign('nom', $user['nom']); | |
880 | $mailer->assign('mail', $user['email2']); | |
881 | $mailer->assign('selfdone', $user['uid'] == S::i('uid')); | |
882 | $mailer->send(); | |
883 | } | |
eca5d69f | 884 | |
ef7c8560 | 885 | $user_same_email = get_infos($user['email']); |
30032578 | 886 | $domain = $globals->asso('mail_domain'); |
ef7c8560 | 887 | |
52ab632b | 888 | if (!$domain || (!empty($user_same_email) && $user_same_email['uid'] != $user['uid'])) { |
30032578 | 889 | return true; |
890 | } | |
ef7c8560 | 891 | |
30032578 | 892 | $mmlist = new MMList(S::v('uid'), S::v('password'), $domain); |
893 | $listes = $mmlist->get_lists($user['email2']); | |
ef7c8560 | 894 | |
30032578 | 895 | $may_update = may_update(); |
896 | $warning = false; | |
897 | foreach ($listes as $liste) { | |
898 | if ($liste['sub'] == 2) { | |
899 | if ($may_update) { | |
9bb8bf21 | 900 | $mmlist->mass_unsubscribe($liste['list'], Array($user['email2'])); |
30032578 | 901 | } else { |
902 | $mmlist->unsubscribe($liste['list']); | |
ef7c8560 | 903 | } |
30032578 | 904 | } elseif ($liste['sub']) { |
d7610c35 FB |
905 | Platal::page()->trigWarning("{$user['prenom']} {$user['nom']} a une" |
906 | ." demande d'inscription en cours sur la" | |
907 | ." liste {$liste['list']}@ !"); | |
30032578 | 908 | $warning = true; |
ef7c8560 | 909 | } |
30032578 | 910 | } |
ef7c8560 | 911 | |
30032578 | 912 | XDB::execute( |
913 | "DELETE FROM virtual_redirect | |
914 | USING virtual_redirect | |
915 | INNER JOIN virtual USING(vid) | |
916 | WHERE redirect={?} AND alias LIKE {?}", $user['email'], '%@'.$domain); | |
917 | return !$warning; | |
918 | } | |
919 | ||
920 | function handler_unsubscribe(&$page) | |
921 | { | |
1490093c | 922 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
0fab5209 | 923 | $user = get_infos(S::user()->id()); |
30032578 | 924 | if (empty($user)) { |
925 | return PL_NOT_FOUND; | |
ef7c8560 | 926 | } |
30032578 | 927 | $page->assign('self', true); |
928 | $page->assign('user', $user); | |
ef7c8560 | 929 | |
30032578 | 930 | if (!Post::has('confirm')) { |
931 | return; | |
e7fdf9dd VZ |
932 | } else { |
933 | S::assert_xsrf_token(); | |
30032578 | 934 | } |
935 | ||
936 | if ($this->unsubscribe($user)) { | |
a7d35093 | 937 | $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.'); |
30032578 | 938 | } else { |
9ec2213d | 939 | $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 | 940 | } |
c1863ee9 | 941 | $page->assign('is_member', is_member(true)); |
30032578 | 942 | } |
943 | ||
944 | function handler_admin_member_del(&$page, $user = null) | |
945 | { | |
1490093c | 946 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
30032578 | 947 | $user = get_infos($user); |
948 | if (empty($user)) { | |
949 | return PL_NOT_FOUND; | |
950 | } | |
951 | $page->assign('user', $user); | |
952 | ||
953 | if (!Post::has('confirm')) { | |
954 | return; | |
e7fdf9dd VZ |
955 | } else { |
956 | S::assert_xsrf_token(); | |
30032578 | 957 | } |
958 | ||
959 | if ($this->unsubscribe($user)) { | |
a7d35093 | 960 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné du groupe !"); |
30032578 | 961 | } else { |
a7d35093 | 962 | $page->trigWarning("{$user['prenom']} {$user['nom']} a été désabonné du groupe, mais des erreurs subsistent !"); |
30032578 | 963 | } |
ef7c8560 | 964 | } |
965 | ||
04334c61 | 966 | private function changeLogin(PlPage &$page, array &$user, MMList &$mmlist, $login) |
631565e1 FB |
967 | { |
968 | require_once 'user.func.inc.php'; | |
969 | // Search the uid of the user... | |
970 | $res = XDB::query("SELECT f.id, f.alias | |
971 | FROM aliases AS a | |
972 | INNER JOIN aliases AS f ON (f.id = a.id AND f.type = 'a_vie') | |
973 | WHERE a.alias = {?}", | |
974 | $login); | |
975 | if ($res->numRows() == 0) { | |
976 | $x = get_not_registered_user($login); | |
977 | if (!$x) { | |
a7d35093 | 978 | $page->trigError("Le login $login ne correspond à aucun X."); |
631565e1 FB |
979 | return false; |
980 | } else if (count($x) > 1) { | |
a7d35093 | 981 | $page->trigError("Le login $login correspond a plusieurs camarades."); |
631565e1 FB |
982 | return false; |
983 | } | |
984 | $uid = $x[0]['user_id']; | |
985 | $sub = false; | |
986 | } else { | |
987 | list($uid, $login) = $res->fetchOneRow(); | |
988 | $sub = true; | |
989 | } | |
990 | ||
991 | // Check if the user is already in the group | |
992 | global $globals; | |
993 | $res = XDB::query("SELECT uid, email | |
994 | FROM groupex.membres | |
995 | WHERE uid = {?} AND asso_id = {?}", | |
996 | $uid, $globals->asso('id')); | |
997 | if ($res->numRows()) { | |
998 | list($uid, $email) = $res->fetchOneRow(); | |
999 | XDB::execute("DELETE FROM groupex.membres | |
1000 | WHERE uid = {?}", | |
1001 | $user['uid']); | |
1002 | } else { | |
1003 | $email = $user['email']; | |
1004 | XDB::execute("UPDATE groupex.membres | |
1005 | SET uid = {?}, origine = 'X' | |
1006 | WHERE uid = {?} AND asso_id = {?}", | |
1007 | $uid, $user['uid'], $globals->asso('id')); | |
1008 | } | |
1009 | if ($sub) { | |
1010 | $email = $login . '@' . $globals->mail->domain; | |
1011 | } | |
1012 | ||
1013 | // Update subscription to aliases | |
1014 | if ($email != $user['email']) { | |
1015 | XDB::execute("UPDATE IGNORE virtual_redirect AS vr | |
148bf011 | 1016 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
631565e1 FB |
1017 | SET vr.redirect = {?} |
1018 | WHERE vr.redirect = {?}", | |
1019 | $globals->asso('mail_domain'), $email, $user['email']); | |
1020 | XDB::execute("DELETE vr.* | |
1021 | FROM virtual_redirect AS vr | |
148bf011 | 1022 | INNER JOIN virtual AS v ON(vr.vid = v.vid AND SUBSTRING_INDEX(alias, '@', -1) = {?}) |
631565e1 FB |
1023 | WHERE vr.redirect = {?}", |
1024 | $globals->asso('mail_domain'), $user['email']); | |
1025 | foreach (Env::v('ml1', array()) as $ml => $state) { | |
1026 | $mmlist->replace_email($ml, $user['email'], $email); | |
1027 | } | |
1028 | } | |
4478f12e FB |
1029 | if ($sub) { |
1030 | return $login; | |
1031 | } | |
1032 | return $user['email']; | |
631565e1 FB |
1033 | } |
1034 | ||
ef7c8560 | 1035 | function handler_admin_member(&$page, $user) |
1036 | { | |
1037 | global $globals; | |
1038 | ||
1490093c | 1039 | $page->changeTpl('xnetgrp/membres-edit.tpl'); |
ef7c8560 | 1040 | |
1041 | $user = get_infos($user); | |
1042 | if (empty($user)) { | |
1043 | return PL_NOT_FOUND; | |
1044 | } | |
1045 | ||
9bb8bf21 | 1046 | $mmlist = new MMList(S::v('uid'), S::v('password'), |
1047 | $globals->asso('mail_domain')); | |
ef7c8560 | 1048 | |
1049 | if (Post::has('change')) { | |
e7fdf9dd VZ |
1050 | S::assert_xsrf_token(); |
1051 | ||
631565e1 FB |
1052 | // Convert user status to X |
1053 | if ($user['origine'] == 'ext' && trim(Post::v('login_X'))) { | |
1054 | $forlife = $this->changeLogin($page, $user, $mmlist, trim(Post::v('login_X'))); | |
1055 | if ($forlife) { | |
1056 | pl_redirect('member/' . $forlife); | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | // Update user info | |
cf5e8ef1 | 1061 | $email_changed = ($user['origine'] != 'X' && strtolower($user['email']) != strtolower(Post::v('email'))); |
c4d57bd8 | 1062 | $from_email = $user['email']; |
ef7c8560 | 1063 | if ($user['origine'] != 'X') { |
06db561e | 1064 | $user['nom'] = Post::v('nom'); |
1065 | $user['prenom'] = (Post::v('origine') == 'ext') ? Post::v('prenom') : ''; | |
1066 | $user['sexe'] = (Post::v('origine') == 'ext') ? Post::v('sexe') : 0; | |
1067 | $user['origine'] = Post::v('origine'); | |
08cce2ff | 1068 | XDB::query('UPDATE groupex.membres |
06db561e | 1069 | SET prenom={?}, nom={?}, email={?}, sexe={?}, origine={?} |
0cc4c07d | 1070 | WHERE uid={?} AND asso_id={?}', |
06db561e | 1071 | $user['prenom'], $user['nom'], Post::v('email'), |
54b24ba2 FB |
1072 | $user['sexe'], $user['origine'], |
1073 | $user['uid'], $globals->asso('id')); | |
06db561e | 1074 | $user['email'] = Post::v('email'); |
1075 | $user['email2'] = Post::v('email'); | |
54b24ba2 | 1076 | $page->trigSuccess('Données de l\'utilisateur mise à jour.'); |
ef7c8560 | 1077 | } |
1078 | ||
5e2307dc | 1079 | $perms = Post::i('is_admin'); |
54b24ba2 FB |
1080 | $comm = trim(Post::s('comm')); |
1081 | if ($user['perms'] != $perms || $user['comm'] != $comm) { | |
1082 | XDB::query('UPDATE groupex.membres | |
1083 | SET perms={?}, comm={?} | |
0cc4c07d | 1084 | WHERE uid={?} AND asso_id={?}', |
54b24ba2 | 1085 | $perms ? 'admin' : 'membre', $comm, |
0cc4c07d | 1086 | $user['uid'], $globals->asso('id')); |
54b24ba2 FB |
1087 | if ($perms != $user['perms']) { |
1088 | $page->trigSuccess('Permissions modifiées !'); | |
1089 | } | |
1090 | if ($comm != $user['comm']) { | |
1091 | $page->trigSuccess('Commentaire mis à jour.'); | |
1092 | } | |
ef7c8560 | 1093 | $user['perms'] = $perms; |
54b24ba2 | 1094 | $user['comm'] = $comm; |
ef7c8560 | 1095 | } |
1096 | ||
631565e1 | 1097 | // Update ML subscriptions |
5e2307dc | 1098 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 1099 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 1100 | if ($ask == $state) { |
06db561e | 1101 | if ($state && $email_changed) { |
c4d57bd8 | 1102 | $mmlist->replace_email($ml, $from_email, $user['email2']); |
a7d35093 | 1103 | $page->trigSuccess("L'abonnement de {$user['prenom']} {$user['nom']} à $ml@ a été mis à jour."); |
c4d57bd8 | 1104 | } |
1105 | continue; | |
1106 | } | |
ef7c8560 | 1107 | if ($state == '1') { |
a7d35093 | 1108 | $page->trigWarning("{$user['prenom']} {$user['nom']} a " |
ef7c8560 | 1109 | ."actuellement une demande d'inscription en " |
1110 | ."cours sur <strong>$ml@</strong> !!!"); | |
1111 | } elseif ($ask) { | |
9bb8bf21 | 1112 | $mmlist->mass_subscribe($ml, Array($user['email2'])); |
a7d35093 | 1113 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml@."); |
ef7c8560 | 1114 | } else { |
c4d57bd8 | 1115 | if ($email_changed) { |
1116 | $mmlist->mass_unsubscribe($ml, Array($from_email)); | |
1117 | } else { | |
1118 | $mmlist->mass_unsubscribe($ml, Array($user['email2'])); | |
1119 | } | |
a7d35093 | 1120 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml@."); |
ef7c8560 | 1121 | } |
1122 | } | |
1123 | ||
631565e1 | 1124 | // Change subscriptioin to aliases |
5e2307dc | 1125 | foreach (Env::v('ml3', array()) as $ml => $state) { |
ef7c8560 | 1126 | $ask = !empty($_REQUEST['ml4'][$ml]); |
1127 | if($state == $ask) continue; | |
1128 | if($ask) { | |
08cce2ff | 1129 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
dc2073c3 | 1130 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
1131 | $user['email'], $ml); | |
a7d35093 | 1132 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été abonné à $ml."); |
ef7c8560 | 1133 | } else { |
08cce2ff | 1134 | XDB::query("DELETE FROM virtual_redirect |
dc2073c3 | 1135 | USING virtual_redirect |
1136 | INNER JOIN virtual USING(vid) | |
1137 | WHERE redirect={?} AND alias={?}", | |
1138 | $user['email'], $ml); | |
a7d35093 | 1139 | $page->trigSuccess("{$user['prenom']} {$user['nom']} a été désabonné de $ml."); |
ef7c8560 | 1140 | } |
1141 | } | |
1142 | } | |
1143 | ||
1144 | $page->assign('user', $user); | |
9bb8bf21 | 1145 | $listes = $mmlist->get_lists($user['email2']); |
ef7c8560 | 1146 | $page->assign('listes', $listes); |
1147 | ||
08cce2ff | 1148 | $res = XDB::query( |
ef7c8560 | 1149 | 'SELECT alias, redirect IS NOT NULL as sub |
1150 | FROM virtual AS v | |
148bf011 | 1151 | LEFT JOIN virtual_redirect AS vr ON(v.vid=vr.vid AND (redirect = {?} OR redirect = {?})) |
ef7c8560 | 1152 | WHERE alias LIKE {?} AND type="user"', |
148bf011 | 1153 | $user['email'], $user['email2'], '%@'.$globals->asso('mail_domain')); |
ef7c8560 | 1154 | $page->assign('alias', $res->fetchAllAssoc()); |
1155 | } | |
24bcf50c | 1156 | |
1157 | function handler_rss(&$page, $user = null, $hash = null) | |
1158 | { | |
1159 | global $globals; | |
24bcf50c | 1160 | $page->assign('asso', $globals->asso()); |
4f18bb11 | 1161 | |
460d8f55 | 1162 | $this->load('feed.inc.php'); |
4f18bb11 FB |
1163 | $feed = new XnetGrpEventFeed(); |
1164 | return $feed->run($page, $user, $hash, false); | |
24bcf50c | 1165 | } |
1166 | ||
04334c61 | 1167 | private function upload_image(PlPage &$page, PlUpload &$upload) |
ff95a302 FB |
1168 | { |
1169 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
1170 | return true; | |
1171 | } | |
1172 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
a7d35093 | 1173 | $page->trigError('Impossible de télécharger l\'image'); |
ff95a302 FB |
1174 | return false; |
1175 | } elseif (!$upload->isType('image')) { | |
a7d35093 | 1176 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
ff95a302 FB |
1177 | $upload->rm(); |
1178 | return false; | |
1179 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
a7d35093 | 1180 | $page->trigError('Impossible de retraiter l\'image'); |
ff95a302 FB |
1181 | return false; |
1182 | } | |
1183 | return true; | |
1184 | } | |
1185 | ||
1186 | function handler_photo_announce(&$page, $eid = null) { | |
1187 | if ($eid) { | |
1188 | $res = XDB::query("SELECT * FROM groupex.announces_photo WHERE eid = {?}", $eid); | |
1189 | if ($res->numRows()) { | |
1190 | $photo = $res->fetchOneAssoc(); | |
1191 | header('Content-Type: image/' . $photo['attachmime']); | |
1192 | echo $photo['attach']; | |
1193 | exit; | |
1194 | } | |
1195 | } else { | |
f3df6d38 | 1196 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 FB |
1197 | if ($upload->exists() && $upload->isType('image')) { |
1198 | header('Content-Type: ' . $upload->contentType()); | |
1199 | echo $upload->getContents(); | |
1200 | exit; | |
1201 | } | |
1202 | } | |
1203 | global $globals; | |
1204 | header('Content-Type: image/png'); | |
1205 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); | |
1206 | exit; | |
1207 | } | |
1208 | ||
24bcf50c | 1209 | function handler_edit_announce(&$page, $aid = null) |
1210 | { | |
1211 | global $globals, $platal; | |
1490093c | 1212 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1213 | $page->assign('new', is_null($aid)); |
1214 | $art = array(); | |
1215 | ||
ff95a302 | 1216 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
2f8677c2 | 1217 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
e7fdf9dd VZ |
1218 | S::assert_xsrf_token(); |
1219 | ||
24bcf50c | 1220 | if (!is_null($aid)) { |
1221 | $art['id'] = $aid; | |
1222 | } | |
1223 | $art['titre'] = Post::v('titre'); | |
1224 | $art['texte'] = Post::v('texte'); | |
1225 | $art['contacts'] = Post::v('contacts'); | |
1226 | $art['promo_min'] = Post::i('promo_min'); | |
1227 | $art['promo_max'] = Post::i('promo_max'); | |
1228 | $art['nom'] = S::v('nom'); | |
1229 | $art['prenom'] = S::v('prenom'); | |
1230 | $art['promo'] = S::v('promo'); | |
0fab5209 | 1231 | $art['hruid'] = S::user()->login(); |
24bcf50c | 1232 | $art['peremption'] = Post::v('peremption'); |
1233 | $art['public'] = Post::has('public'); | |
1234 | $art['xorg'] = Post::has('xorg'); | |
1235 | $art['nl'] = Post::has('nl'); | |
1236 | $art['event'] = Post::v('event'); | |
f3df6d38 | 1237 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1238 | $this->upload_image($page, $upload); |
24bcf50c | 1239 | |
1240 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1241 | if ($art['event']) { |
1242 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1243 | } |
2a557a09 | 1244 | |
1245 | if (!$art['public'] && | |
d1c97e42 | 1246 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1247 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1248 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1249 | { | |
a7d35093 | 1250 | $page->trigError("L'intervalle de promotions est invalide."); |
2a557a09 | 1251 | Post::kill('valid'); |
1252 | } | |
1970c12b | 1253 | |
1254 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
a7d35093 | 1255 | $page->trigError("L'article doit avoir un titre et un contenu."); |
1970c12b | 1256 | Post::kill('valid'); |
1257 | } | |
ff95a302 FB |
1258 | |
1259 | if (Post::v('valid') == 'Supprimer l\'image') { | |
1260 | $upload->rm(); | |
1261 | Post::kill('valid'); | |
1262 | } | |
2f8677c2 FB |
1263 | $art['photo'] = $upload->exists() || Post::i('photo'); |
1264 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { | |
1265 | XDB::query("DELETE FROM groupex.announces_photo WHERE eid = {?}", $aid); | |
1266 | $upload->rm(); | |
1267 | Post::kill('valid'); | |
1268 | $art['photo'] = false; | |
1269 | } | |
24bcf50c | 1270 | } |
1271 | ||
1272 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1273 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1274 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
113f6de8 | 1275 | $flags = new PlFlagSet(); |
ff95a302 | 1276 | if ($art['public']) { |
77e786e1 | 1277 | $flags->addFlag('public'); |
ff95a302 FB |
1278 | } |
1279 | if ($art['photo']) { | |
77e786e1 | 1280 | $flags->addFlag('photo'); |
ff95a302 | 1281 | } |
24bcf50c | 1282 | if (is_null($aid)) { |
eaf30d86 PH |
1283 | $fulltext = $art['texte']; |
1284 | if (!empty($art['contact_html'])) { | |
1285 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1286 | } |
ff95a302 | 1287 | $post = null;/* |
e219710a | 1288 | if ($globals->asso('forum')) { |
1289 | require_once 'banana/forum.inc.php'; | |
e3a55098 | 1290 | $banana = new ForumsBanana(S::user()); |
e219710a | 1291 | $post = $banana->post($globals->asso('forum'), null, |
1292 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
ff95a302 | 1293 | }*/ |
24bcf50c | 1294 | XDB::query("INSERT INTO groupex.announces |
1295 | (user_id, asso_id, create_date, titre, texte, contacts, | |
e219710a | 1296 | peremption, promo_min, promo_max, flags, post_id) |
1297 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})", | |
24bcf50c | 1298 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
ff95a302 | 1299 | $art['peremption'], $promo_min, $promo_max, $flags, $post); |
8b83a166 | 1300 | $aid = XDB::insertId(); |
ff95a302 FB |
1301 | if ($art['photo']) { |
1302 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
1303 | XDB::execute("INSERT INTO groupex.announces_photo | |
1304 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", | |
1305 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); | |
1306 | } | |
24bcf50c | 1307 | if ($art['xorg']) { |
1308 | require_once('validations.inc.php'); | |
794feea7 | 1309 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
5daf68f6 | 1310 | $art['promo_min'], $art['promo_max'], $art['peremption'], "", S::user(), |
ff95a302 | 1311 | $upload); |
24bcf50c | 1312 | $article->submit(); |
a7d35093 | 1313 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
ff95a302 FB |
1314 | } else if ($upload && $upload->exists()) { |
1315 | $upload->rm(); | |
24bcf50c | 1316 | } |
1317 | if ($art['nl']) { | |
1318 | require_once('validations.inc.php'); | |
5daf68f6 | 1319 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
2a557a09 | 1320 | $art['texte'], $art['contact_html']); |
24bcf50c | 1321 | $article->submit(); |
a7d35093 | 1322 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
24bcf50c | 1323 | } |
1324 | } else { | |
1325 | XDB::query("UPDATE groupex.announces | |
1326 | SET titre={?}, texte={?}, contacts={?}, peremption={?}, | |
1327 | promo_min={?}, promo_max={?}, flags={?} | |
1328 | WHERE id={?} AND asso_id={?}", | |
1329 | $art['titre'], $art['texte'], $art['contacts'], $art['peremption'], | |
ff95a302 | 1330 | $promo_min, $promo_max, $flags, |
24bcf50c | 1331 | $art['id'], $globals->asso('id')); |
2f8677c2 FB |
1332 | if ($art['photo'] && $upload->exists()) { |
1333 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
1334 | XDB::execute("REPLACE INTO groupex.announces_photo | |
1335 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", | |
1336 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); | |
1337 | $upload->rm(); | |
1338 | } | |
24bcf50c | 1339 | } |
2a557a09 | 1340 | } |
1341 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1342 | pl_redirect(""); |
eaf30d86 | 1343 | } |
24bcf50c | 1344 | |
1345 | if (empty($art) && !is_null($aid)) { | |
0fab5209 | 1346 | $res = XDB::query("SELECT a.*, u.nom, u.prenom, u.promo, u.hruid, |
2f8677c2 FB |
1347 | FIND_IN_SET('public', a.flags) AS public, |
1348 | FIND_IN_SET('photo', a.flags) AS photo | |
24bcf50c | 1349 | FROM groupex.announces AS a |
1350 | INNER JOIN auth_user_md5 AS u USING(user_id) | |
24bcf50c | 1351 | WHERE asso_id = {?} AND a.id = {?}", |
1352 | $globals->asso('id'), $aid); | |
1353 | if ($res->numRows()) { | |
1354 | $art = $res->fetchOneAssoc(); | |
1355 | $art['contact_html'] = $art['contacts']; | |
1356 | } else { | |
567553ac | 1357 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
24bcf50c | 1358 | } |
1359 | } | |
1360 | ||
24bcf50c | 1361 | if (is_null($aid)) { |
1362 | $events = XDB::iterator("SELECT * | |
1363 | FROM groupex.evenements | |
1364 | WHERE asso_id = {?} AND archive = 0", | |
1365 | $globals->asso('id')); | |
1366 | if ($events->total()) { | |
1367 | $page->assign('events', $events); | |
1368 | } | |
eaf30d86 | 1369 | } |
24bcf50c | 1370 | |
72b2f8bb | 1371 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1372 | $page->assign('art', $art); |
ff95a302 | 1373 | $page->assign_by_ref('upload', $upload); |
24bcf50c | 1374 | } |
1375 | ||
1376 | function handler_admin_announce(&$page) | |
1377 | { | |
1378 | global $globals; | |
1490093c | 1379 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1380 | |
1381 | if (Env::has('del')) { | |
e7fdf9dd | 1382 | S::assert_xsrf_token(); |
e219710a | 1383 | XDB::execute("DELETE FROM groupex.announces |
1384 | WHERE id = {?} AND asso_id = {?}", | |
24bcf50c | 1385 | Env::i('del'), $globals->asso('id')); |
1386 | } | |
e219710a | 1387 | $res = XDB::iterator("SELECT a.id, a.titre, a.peremption, a.peremption < CURRENT_DATE() AS perime |
1388 | FROM groupex.announces AS a | |
1389 | WHERE a.asso_id = {?} | |
1390 | ORDER BY a.peremption DESC", | |
24bcf50c | 1391 | $globals->asso('id')); |
1392 | $page->assign('articles', $res); | |
1393 | } | |
ae7bb180 | 1394 | } |
1395 | ||
a7de4ef7 | 1396 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
ae7bb180 | 1397 | ?> |