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