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; | |
625 | } | |
626 | ||
bb88d138 PC |
627 | S::assert_xsrf_token(); |
628 | ||
629 | // Finds or creates account | |
a1642859 | 630 | if (!User::isForeignEmailAddress($email)) { |
bb88d138 | 631 | // standard x account |
a1642859 | 632 | $user = User::get($email); |
bb88d138 PC |
633 | } else if (!isvalid_email($email)) { |
634 | // email might not be a regular email but an alias or a hruid | |
635 | $user = User::get($email); | |
636 | if (!$user) { | |
637 | // need a valid email address | |
638 | $page->trigError("« <strong>$email</strong> » n'est pas une adresse email valide."); | |
639 | return; | |
ef7c8560 | 640 | } |
bb88d138 PC |
641 | } else if (Env::v('x') && Env::i('userid')) { |
642 | // user is an x but might not yet be registered | |
643 | $user = User::getWithUID(Env::i('userid')); | |
644 | if (!$user) { | |
645 | $page->trigError("Utilisateur invalide"); | |
646 | return; | |
647 | } | |
648 | // add email for marketing if unknown | |
649 | if ($user->state == 'pending' && Env::v('market')) { | |
650 | $market = Marketing::get($user->uid, $email); | |
651 | if (!$market) { | |
652 | $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), | |
653 | Env::v('market_from'), S::v('uid')); | |
654 | $market->add(); | |
dc2073c3 | 655 | } |
bb88d138 PC |
656 | } |
657 | } else { | |
658 | // user is not an x | |
659 | $hruid = strtolower(str_replace('@','.',$email).'.ext'); | |
660 | // might already exists (in another group for example) | |
661 | $user = User::get($hruid); | |
662 | if (empty($user)) { | |
663 | // creates new account: build names from email address | |
664 | $display_name = ucwords(strtolower(substr($hruid, strpos('.', $hruid)))); | |
665 | $full_name = ucwords(strtolower(str_replace('.', ' ',substr($email, strpos('@', $email))))); | |
666 | XDB::execute("INSERT INTO accounts (hruid, display_name, full_name, email, type) | |
667 | VALUES({?}, {?}, {?}, {?}, 'xnet')", | |
668 | $hruid, $display_name, $full_name, $email); | |
669 | $user = User::get($hruid); | |
ef7c8560 | 670 | } |
671 | } | |
bb88d138 PC |
672 | if ($user) { |
673 | XDB::execute("REPLACE INTO group_members (uid, asso_id) | |
674 | VALUES ({?}, {?})", | |
675 | $user->id(), $globals->asso('id')); | |
676 | $this->removeSubscriptionRequest($user->id()); | |
677 | pl_redirect("member/" . $user->login()); | |
678 | } | |
ef7c8560 | 679 | } |
680 | ||
dc2073c3 | 681 | function handler_admin_member_new_ajax(&$page) |
682 | { | |
3cb500d5 | 683 | pl_content_headers("text/html"); |
8b1f8e12 | 684 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
aa21c568 | 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'))); | |
c8763ca3 | 694 | $cond = new PFC_And(new PFC_Not(new UFC_Registered())); |
0baf0741 | 695 | if (!empty($nom)) { |
913a4e90 | 696 | $cond->addChild(new UFC_Name(Profile::LASTNAME, $nom, UFC_Name::CONTAINS)); |
0baf0741 | 697 | } |
698 | if (!empty($prenom)) { | |
913a4e90 | 699 | $cond->addChild(new UFC_Name(Profile::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); | |
e1406965 | 705 | $users = $uf->getUsers(new PlLimit(30)); |
aa21c568 FB |
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; |
eb41eda9 | 717 | XDB::execute("DELETE FROM group_members |
45dcd6dd FB |
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'); | |
57c1f1d7 SJ |
723 | $admins = $globals->asso()->iterAdmins(); |
724 | while ($admin = $admins->next()) { | |
725 | $mailer->addTo($admin); | |
fa9493fe FB |
726 | } |
727 | $mailer->assign('group', $globals->asso('nom')); | |
45dcd6dd FB |
728 | $mailer->assign('user', $user); |
729 | $mailer->assign('selfdone', $user->id() == S::i('uid')); | |
fa9493fe FB |
730 | $mailer->send(); |
731 | } | |
eca5d69f | 732 | |
30032578 | 733 | $domain = $globals->asso('mail_domain'); |
45dcd6dd | 734 | if (!$domain) { |
30032578 | 735 | return true; |
736 | } | |
ef7c8560 | 737 | |
45dcd6dd FB |
738 | $mmlist = new MMList($user, $domain); |
739 | $listes = $mmlist->get_lists($user->forlifeEmail()); | |
ef7c8560 | 740 | |
30032578 | 741 | $may_update = may_update(); |
742 | $warning = false; | |
23ba40c4 PC |
743 | if (is_array($listes)) { |
744 | foreach ($listes as $liste) { | |
745 | if ($liste['sub'] == 2) { | |
746 | if ($may_update) { | |
747 | $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail())); | |
748 | } else { | |
749 | $mmlist->unsubscribe($liste['list']); | |
750 | } | |
751 | } elseif ($liste['sub']) { | |
752 | Platal::page()->trigWarning($user->fullName() . " a une" | |
753 | ." demande d'inscription en cours sur la" | |
754 | ." liste {$liste['list']}@ !"); | |
755 | $warning = true; | |
ef7c8560 | 756 | } |
757 | } | |
30032578 | 758 | } |
ef7c8560 | 759 | |
45dcd6dd FB |
760 | XDB::execute("DELETE FROM virtual_redirect |
761 | USING virtual_redirect | |
762 | INNER JOIN virtual USING(vid) | |
763 | WHERE redirect={?} AND alias LIKE {?}", | |
764 | $user->forlifeEmail(), '%@'.$domain); | |
30032578 | 765 | return !$warning; |
766 | } | |
767 | ||
768 | function handler_unsubscribe(&$page) | |
769 | { | |
1490093c | 770 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
45dcd6dd | 771 | $user = S::user()->id(); |
30032578 | 772 | if (empty($user)) { |
773 | return PL_NOT_FOUND; | |
ef7c8560 | 774 | } |
30032578 | 775 | $page->assign('self', true); |
776 | $page->assign('user', $user); | |
ef7c8560 | 777 | |
30032578 | 778 | if (!Post::has('confirm')) { |
779 | return; | |
e7fdf9dd VZ |
780 | } else { |
781 | S::assert_xsrf_token(); | |
30032578 | 782 | } |
783 | ||
784 | if ($this->unsubscribe($user)) { | |
a7d35093 | 785 | $page->trigSuccess('Vous avez été désinscrit du groupe avec succès.'); |
30032578 | 786 | } else { |
9ec2213d | 787 | $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 | 788 | } |
c1863ee9 | 789 | $page->assign('is_member', is_member(true)); |
30032578 | 790 | } |
791 | ||
792 | function handler_admin_member_del(&$page, $user = null) | |
793 | { | |
1490093c | 794 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
45dcd6dd | 795 | $user = User::getSilent($user); |
30032578 | 796 | if (empty($user)) { |
797 | return PL_NOT_FOUND; | |
798 | } | |
799 | $page->assign('user', $user); | |
800 | ||
801 | if (!Post::has('confirm')) { | |
802 | return; | |
e7fdf9dd VZ |
803 | } else { |
804 | S::assert_xsrf_token(); | |
30032578 | 805 | } |
806 | ||
807 | if ($this->unsubscribe($user)) { | |
e46cf8c4 | 808 | $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !"); |
30032578 | 809 | } else { |
e46cf8c4 | 810 | $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !"); |
30032578 | 811 | } |
ef7c8560 | 812 | } |
813 | ||
45dcd6dd | 814 | private function changeLogin(PlPage &$page, PlUser &$user, MMList &$mmlist, $login) |
631565e1 | 815 | { |
631565e1 | 816 | // Search the uid of the user... |
bb88d138 PC |
817 | $xuser = User::getSilent($login); |
818 | if (!$xuser) { | |
61a7d279 SJ |
819 | $accounts = User::getPendingAccounts($login); |
820 | if (!$accounts) { | |
821 | $page->trigError("L'identifiant $login ne correspond à aucun X."); | |
631565e1 | 822 | return false; |
61a7d279 SJ |
823 | } else if (count($accounts) > 1) { |
824 | $page->trigError("L'identifiant $login correspond à plusieurs camarades."); | |
631565e1 FB |
825 | return false; |
826 | } | |
bb88d138 | 827 | $xuser = User::getSilent($accounts[0]['uid']); |
631565e1 | 828 | $sub = false; |
631565e1 FB |
829 | } |
830 | ||
bb88d138 PC |
831 | if (!$xuser) { |
832 | return false; | |
631565e1 FB |
833 | } |
834 | ||
ab06182d PC |
835 | $user->mergeIn($xuser); |
836 | ||
bb88d138 | 837 | return $xuser->login(); |
631565e1 FB |
838 | } |
839 | ||
ef7c8560 | 840 | function handler_admin_member(&$page, $user) |
841 | { | |
842 | global $globals; | |
843 | ||
1490093c | 844 | $page->changeTpl('xnetgrp/membres-edit.tpl'); |
ef7c8560 | 845 | |
45dcd6dd | 846 | $user = User::getSilent($user); |
ef7c8560 | 847 | if (empty($user)) { |
848 | return PL_NOT_FOUND; | |
849 | } | |
850 | ||
45dcd6dd | 851 | $mmlist = new MMList($user, $globals->asso('mail_domain')); |
ef7c8560 | 852 | |
853 | if (Post::has('change')) { | |
e7fdf9dd VZ |
854 | S::assert_xsrf_token(); |
855 | ||
631565e1 | 856 | // Convert user status to X |
bb88d138 | 857 | if (!Post::blank('login_X')) { |
45dcd6dd | 858 | $forlife = $this->changeLogin($page, $user, $mmlist, Post::t('login_X')); |
631565e1 FB |
859 | if ($forlife) { |
860 | pl_redirect('member/' . $forlife); | |
861 | } | |
862 | } | |
863 | ||
864 | // Update user info | |
bb88d138 PC |
865 | $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email'))); |
866 | $from_email = $user->forlifeEmail(); | |
867 | if (!$user->profile()) { | |
868 | XDB::query('UPDATE accounts | |
869 | SET full_name = {?}, display_name = {?}, sex = {?}, email = {?}, type = {?} | |
870 | WHERE uid = {?}', | |
871 | Post::v('full_name'), Post::v('display_name'), (Post::v('sex') == 'male')?'male':'female', Post::v('email'), (Post::v('type') == 'xnet')?'xnet':'virtual', | |
872 | $user->id()); | |
873 | if (XDB::affectedRows()) { | |
874 | $page->trigSuccess('Données de l\'utilisateur mise à jour.'); | |
875 | } | |
ef7c8560 | 876 | } |
877 | ||
bb88d138 PC |
878 | // Update group params for user |
879 | $perms = Post::v('group_perms'); | |
a6761ca9 | 880 | $comm = Post::t('comm'); |
bb88d138 | 881 | if ($user->group_perms != $perms || $user->group_comm != $comm) { |
eb41eda9 | 882 | XDB::query('UPDATE group_members |
00112b2e VZ |
883 | SET perms = {?}, comm = {?} |
884 | WHERE uid = {?} AND asso_id = {?}', | |
bb88d138 PC |
885 | ($perms == 'admin') ? 'admin' : 'membre', $comm, |
886 | $user->id(), $globals->asso('id')); | |
887 | if ($perms != $user->group_perms) { | |
6bb2f79a | 888 | $page->trigSuccess('Permissions modifiées !'); |
54b24ba2 | 889 | } |
bb88d138 | 890 | if ($comm != $user->group_comm) { |
54b24ba2 FB |
891 | $page->trigSuccess('Commentaire mis à jour.'); |
892 | } | |
ef7c8560 | 893 | } |
894 | ||
bb88d138 PC |
895 | // Gets user info again as they might have change |
896 | $user = User::getSilent($user->id()); | |
897 | ||
631565e1 | 898 | // Update ML subscriptions |
5e2307dc | 899 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 900 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 901 | if ($ask == $state) { |
06db561e | 902 | if ($state && $email_changed) { |
bb88d138 PC |
903 | $mmlist->replace_email($ml, $from_email, $user->forlifeEmail()); |
904 | $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour."); | |
c4d57bd8 | 905 | } |
906 | continue; | |
907 | } | |
ef7c8560 | 908 | if ($state == '1') { |
bb88d138 | 909 | $page->trigWarning("{$user->fullName()} a " |
ef7c8560 | 910 | ."actuellement une demande d'inscription en " |
911 | ."cours sur <strong>$ml@</strong> !!!"); | |
912 | } elseif ($ask) { | |
bb88d138 PC |
913 | $mmlist->mass_subscribe($ml, Array($user->forlifeEmail())); |
914 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml@."); | |
ef7c8560 | 915 | } else { |
c4d57bd8 | 916 | if ($email_changed) { |
917 | $mmlist->mass_unsubscribe($ml, Array($from_email)); | |
918 | } else { | |
bb88d138 | 919 | $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail())); |
c4d57bd8 | 920 | } |
bb88d138 | 921 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@."); |
ef7c8560 | 922 | } |
923 | } | |
924 | ||
631565e1 | 925 | // Change subscriptioin to aliases |
5e2307dc | 926 | foreach (Env::v('ml3', array()) as $ml => $state) { |
ef7c8560 | 927 | $ask = !empty($_REQUEST['ml4'][$ml]); |
bb88d138 PC |
928 | if($state == $ask) { |
929 | if ($state && $email_changed) { | |
930 | XDB::query("UPDATE virtual_redirect AS vr, virtual AS v | |
931 | SET vr.redirect = {?} | |
932 | WHERE vr.vid = v.vid AND v.alias = {?} AND vr.redirect = {?}", | |
933 | $user->forlifeEmail(), $ml, $from_email); | |
934 | $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour."); | |
935 | } | |
936 | } else if($ask) { | |
08cce2ff | 937 | XDB::query("INSERT INTO virtual_redirect (vid,redirect) |
dc2073c3 | 938 | SELECT vid,{?} FROM virtual WHERE alias={?}", |
bb88d138 PC |
939 | $user->forlifeEmail(), $ml); |
940 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml."); | |
ef7c8560 | 941 | } else { |
08cce2ff | 942 | XDB::query("DELETE FROM virtual_redirect |
dc2073c3 | 943 | USING virtual_redirect |
944 | INNER JOIN virtual USING(vid) | |
945 | WHERE redirect={?} AND alias={?}", | |
bb88d138 PC |
946 | $from_email, $ml); |
947 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml."); | |
ef7c8560 | 948 | } |
949 | } | |
950 | } | |
951 | ||
952 | $page->assign('user', $user); | |
a6761ca9 FB |
953 | $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); |
954 | $page->assign('alias', $user->emailAliases($globals->asso('mail_domain'), 'user', true)); | |
ef7c8560 | 955 | } |
24bcf50c | 956 | |
957 | function handler_rss(&$page, $user = null, $hash = null) | |
958 | { | |
959 | global $globals; | |
24bcf50c | 960 | $page->assign('asso', $globals->asso()); |
4f18bb11 | 961 | |
460d8f55 | 962 | $this->load('feed.inc.php'); |
4f18bb11 FB |
963 | $feed = new XnetGrpEventFeed(); |
964 | return $feed->run($page, $user, $hash, false); | |
24bcf50c | 965 | } |
966 | ||
04334c61 | 967 | private function upload_image(PlPage &$page, PlUpload &$upload) |
ff95a302 FB |
968 | { |
969 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
970 | return true; | |
971 | } | |
972 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
a7d35093 | 973 | $page->trigError('Impossible de télécharger l\'image'); |
ff95a302 FB |
974 | return false; |
975 | } elseif (!$upload->isType('image')) { | |
a7d35093 | 976 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
ff95a302 FB |
977 | $upload->rm(); |
978 | return false; | |
979 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
a7d35093 | 980 | $page->trigError('Impossible de retraiter l\'image'); |
ff95a302 FB |
981 | return false; |
982 | } | |
983 | return true; | |
984 | } | |
985 | ||
986 | function handler_photo_announce(&$page, $eid = null) { | |
987 | if ($eid) { | |
14bc135e SJ |
988 | $res = XDB::query('SELECT * |
989 | FROM group_announces_photo | |
990 | WHERE eid = {?}', $eid); | |
ff95a302 FB |
991 | if ($res->numRows()) { |
992 | $photo = $res->fetchOneAssoc(); | |
3cb500d5 | 993 | pl_cached_dynamic_content_headers("image/" . $photo['attachmime']); |
ff95a302 FB |
994 | echo $photo['attach']; |
995 | exit; | |
996 | } | |
997 | } else { | |
f3df6d38 | 998 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 999 | if ($upload->exists() && $upload->isType('image')) { |
3cb500d5 | 1000 | pl_cached_dynamic_content_headers($upload->contentType()); |
ff95a302 FB |
1001 | echo $upload->getContents(); |
1002 | exit; | |
1003 | } | |
1004 | } | |
1005 | global $globals; | |
3cb500d5 | 1006 | pl_cached_dynamic_content_headers("image/png"); |
ff95a302 FB |
1007 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); |
1008 | exit; | |
1009 | } | |
1010 | ||
24bcf50c | 1011 | function handler_edit_announce(&$page, $aid = null) |
1012 | { | |
1013 | global $globals, $platal; | |
1490093c | 1014 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1015 | $page->assign('new', is_null($aid)); |
1016 | $art = array(); | |
1017 | ||
ff95a302 | 1018 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
2f8677c2 | 1019 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
e7fdf9dd VZ |
1020 | S::assert_xsrf_token(); |
1021 | ||
24bcf50c | 1022 | if (!is_null($aid)) { |
1023 | $art['id'] = $aid; | |
1024 | } | |
1025 | $art['titre'] = Post::v('titre'); | |
1026 | $art['texte'] = Post::v('texte'); | |
1027 | $art['contacts'] = Post::v('contacts'); | |
1028 | $art['promo_min'] = Post::i('promo_min'); | |
1029 | $art['promo_max'] = Post::i('promo_max'); | |
1030 | $art['nom'] = S::v('nom'); | |
1031 | $art['prenom'] = S::v('prenom'); | |
1032 | $art['promo'] = S::v('promo'); | |
0fab5209 | 1033 | $art['hruid'] = S::user()->login(); |
b58e5ac2 | 1034 | $art['expiration'] = Post::v('expiration'); |
24bcf50c | 1035 | $art['public'] = Post::has('public'); |
1036 | $art['xorg'] = Post::has('xorg'); | |
1037 | $art['nl'] = Post::has('nl'); | |
1038 | $art['event'] = Post::v('event'); | |
f3df6d38 | 1039 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1040 | $this->upload_image($page, $upload); |
24bcf50c | 1041 | |
1042 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1043 | if ($art['event']) { |
1044 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1045 | } |
2a557a09 | 1046 | |
1047 | if (!$art['public'] && | |
d1c97e42 | 1048 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1049 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1050 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1051 | { | |
a7d35093 | 1052 | $page->trigError("L'intervalle de promotions est invalide."); |
2a557a09 | 1053 | Post::kill('valid'); |
1054 | } | |
1970c12b | 1055 | |
1056 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
a7d35093 | 1057 | $page->trigError("L'article doit avoir un titre et un contenu."); |
1970c12b | 1058 | Post::kill('valid'); |
1059 | } | |
ff95a302 FB |
1060 | |
1061 | if (Post::v('valid') == 'Supprimer l\'image') { | |
1062 | $upload->rm(); | |
1063 | Post::kill('valid'); | |
1064 | } | |
2f8677c2 FB |
1065 | $art['photo'] = $upload->exists() || Post::i('photo'); |
1066 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { | |
14bc135e SJ |
1067 | XDB::query('DELETE FROM group_announces_photo |
1068 | WHERE eid = {?}', $aid); | |
2f8677c2 FB |
1069 | $upload->rm(); |
1070 | Post::kill('valid'); | |
1071 | $art['photo'] = false; | |
1072 | } | |
24bcf50c | 1073 | } |
1074 | ||
1075 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1076 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1077 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
113f6de8 | 1078 | $flags = new PlFlagSet(); |
ff95a302 | 1079 | if ($art['public']) { |
77e786e1 | 1080 | $flags->addFlag('public'); |
ff95a302 FB |
1081 | } |
1082 | if ($art['photo']) { | |
77e786e1 | 1083 | $flags->addFlag('photo'); |
ff95a302 | 1084 | } |
24bcf50c | 1085 | if (is_null($aid)) { |
eaf30d86 PH |
1086 | $fulltext = $art['texte']; |
1087 | if (!empty($art['contact_html'])) { | |
1088 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1089 | } |
ff95a302 | 1090 | $post = null;/* |
e219710a | 1091 | if ($globals->asso('forum')) { |
1092 | require_once 'banana/forum.inc.php'; | |
e3a55098 | 1093 | $banana = new ForumsBanana(S::user()); |
e219710a | 1094 | $post = $banana->post($globals->asso('forum'), null, |
1095 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
ff95a302 | 1096 | }*/ |
14bc135e | 1097 | XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts, |
b58e5ac2 | 1098 | expiration, promo_min, promo_max, flags, post_id) |
14bc135e | 1099 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', |
24bcf50c | 1100 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
b58e5ac2 | 1101 | $art['expiration'], $promo_min, $promo_max, $flags, $post); |
8b83a166 | 1102 | $aid = XDB::insertId(); |
ff95a302 FB |
1103 | if ($art['photo']) { |
1104 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
14bc135e SJ |
1105 | XDB::execute('INSERT INTO group_announces_photo |
1106 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', | |
ff95a302 FB |
1107 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
1108 | } | |
24bcf50c | 1109 | if ($art['xorg']) { |
1110 | require_once('validations.inc.php'); | |
794feea7 | 1111 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
b58e5ac2 | 1112 | $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(), |
ff95a302 | 1113 | $upload); |
24bcf50c | 1114 | $article->submit(); |
a7d35093 | 1115 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
ff95a302 FB |
1116 | } else if ($upload && $upload->exists()) { |
1117 | $upload->rm(); | |
24bcf50c | 1118 | } |
1119 | if ($art['nl']) { | |
1120 | require_once('validations.inc.php'); | |
5daf68f6 | 1121 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
2a557a09 | 1122 | $art['texte'], $art['contact_html']); |
24bcf50c | 1123 | $article->submit(); |
a7d35093 | 1124 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
24bcf50c | 1125 | } |
1126 | } else { | |
14bc135e | 1127 | XDB::query('UPDATE group_announces |
b58e5ac2 | 1128 | SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?}, |
14bc135e SJ |
1129 | promo_min = {?}, promo_max = {?}, flags = {?} |
1130 | WHERE id = {?} AND asso_id = {?}', | |
b58e5ac2 | 1131 | $art['titre'], $art['texte'], $art['contacts'], $art['expiration'], |
ff95a302 | 1132 | $promo_min, $promo_max, $flags, |
24bcf50c | 1133 | $art['id'], $globals->asso('id')); |
2f8677c2 FB |
1134 | if ($art['photo'] && $upload->exists()) { |
1135 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
eb41eda9 | 1136 | XDB::execute("REPLACE INTO group_announces_photo |
00112b2e | 1137 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}", |
2f8677c2 FB |
1138 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
1139 | $upload->rm(); | |
1140 | } | |
24bcf50c | 1141 | } |
2a557a09 | 1142 | } |
1143 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1144 | pl_redirect(""); |
eaf30d86 | 1145 | } |
24bcf50c | 1146 | |
1147 | if (empty($art) && !is_null($aid)) { | |
14bc135e SJ |
1148 | $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public, |
1149 | FIND_IN_SET('photo', flags) AS photo | |
1150 | FROM group_announces | |
1151 | WHERE asso_id = {?} AND id = {?}", | |
24bcf50c | 1152 | $globals->asso('id'), $aid); |
1153 | if ($res->numRows()) { | |
1154 | $art = $res->fetchOneAssoc(); | |
1155 | $art['contact_html'] = $art['contacts']; | |
1156 | } else { | |
567553ac | 1157 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
24bcf50c | 1158 | } |
1159 | } | |
1160 | ||
24bcf50c | 1161 | if (is_null($aid)) { |
1162 | $events = XDB::iterator("SELECT * | |
eb41eda9 | 1163 | FROM group_events |
24bcf50c | 1164 | WHERE asso_id = {?} AND archive = 0", |
1165 | $globals->asso('id')); | |
1166 | if ($events->total()) { | |
1167 | $page->assign('events', $events); | |
1168 | } | |
eaf30d86 | 1169 | } |
24bcf50c | 1170 | |
72b2f8bb | 1171 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1172 | $page->assign('art', $art); |
ff95a302 | 1173 | $page->assign_by_ref('upload', $upload); |
24bcf50c | 1174 | } |
1175 | ||
1176 | function handler_admin_announce(&$page) | |
1177 | { | |
1178 | global $globals; | |
1490093c | 1179 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1180 | |
1181 | if (Env::has('del')) { | |
e7fdf9dd | 1182 | S::assert_xsrf_token(); |
14bc135e SJ |
1183 | XDB::execute('DELETE FROM group_announces |
1184 | WHERE id = {?} AND asso_id = {?}', | |
24bcf50c | 1185 | Env::i('del'), $globals->asso('id')); |
1186 | } | |
b58e5ac2 | 1187 | $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime |
14bc135e SJ |
1188 | FROM group_announces |
1189 | WHERE asso_id = {?} | |
b58e5ac2 | 1190 | ORDER BY expiration DESC', |
24bcf50c | 1191 | $globals->asso('id')); |
1192 | $page->assign('articles', $res); | |
1193 | } | |
ae7bb180 | 1194 | } |
1195 | ||
a7de4ef7 | 1196 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
ae7bb180 | 1197 | ?> |