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