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