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