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