Commit | Line | Data |
---|---|---|
ae7bb180 | 1 | <?php |
2 | /*************************************************************************** | |
5e1513f6 | 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), | |
5ae3e9a9 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'), | |
52366335 | 38 | '%grp/directory/sync' => $this->make_hook('directory_sync', AUTH_MDP, 'groupadmin'), |
c329751f | 39 | '%grp/directory/unact' => $this->make_hook('non_active', AUTH_MDP, 'groupadmin'), |
5ae3e9a9 SJ |
40 | '%grp/trombi' => $this->make_hook('trombi', AUTH_MDP, 'groupannu'), |
41 | '%grp/geoloc' => $this->make_hook('geoloc', AUTH_MDP, 'groupannu'), | |
020c8ed0 | 42 | '%grp/subscribe' => $this->make_hook('subscribe', AUTH_MDP), |
5ae3e9a9 SJ |
43 | '%grp/subscribe/valid' => $this->make_hook('subscribe_valid', AUTH_MDP, 'groupadmin'), |
44 | '%grp/unsubscribe' => $this->make_hook('unsubscribe', AUTH_MDP, 'groupmember'), | |
4e310c61 | 45 | |
020c8ed0 | 46 | '%grp/change_rights' => $this->make_hook('change_rights', AUTH_MDP), |
5ae3e9a9 SJ |
47 | '%grp/admin/annuaire' => $this->make_hook('admin_annuaire', AUTH_MDP, 'groupadmin'), |
48 | '%grp/member' => $this->make_hook('admin_member', AUTH_MDP, 'groupadmin'), | |
49 | '%grp/member/new' => $this->make_hook('admin_member_new', AUTH_MDP, 'groupadmin'), | |
50 | '%grp/member/new/ajax' => $this->make_hook('admin_member_new_ajax', AUTH_MDP, 'user', NO_AUTH), | |
51 | '%grp/member/del' => $this->make_hook('admin_member_del', AUTH_MDP, 'groupadmin'), | |
52 | '%grp/member/suggest' => $this->make_hook('admin_member_suggest', AUTH_MDP, 'groupadmin'), | |
b8e265bf | 53 | |
190efb3a | 54 | '%grp/rss' => $this->make_token_hook('rss', AUTH_PUBLIC), |
5ae3e9a9 SJ |
55 | '%grp/announce/new' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), |
56 | '%grp/announce/edit' => $this->make_hook('edit_announce', AUTH_MDP, 'groupadmin'), | |
020c8ed0 | 57 | '%grp/announce/photo' => $this->make_hook('photo_announce', AUTH_PUBLIC), |
5ae3e9a9 | 58 | '%grp/admin/announces' => $this->make_hook('admin_announce', AUTH_MDP, 'groupadmin'), |
ae7bb180 | 59 | ); |
60 | } | |
61 | ||
26ba053e | 62 | function handler_index($page, $arg = null) |
ae7bb180 | 63 | { |
24bcf50c | 64 | global $globals, $platal; |
2e94d2b8 | 65 | if (!is_null($arg)) { |
ae7bb180 | 66 | return PL_NOT_FOUND; |
67 | } | |
1490093c | 68 | $page->changeTpl('xnetgrp/asso.tpl'); |
ae7bb180 | 69 | |
24bcf50c | 70 | if (S::logged()) { |
71 | if (Env::has('read')) { | |
14bc135e SJ |
72 | XDB::query('DELETE r.* |
73 | FROM group_announces_read AS r | |
74 | INNER JOIN group_announces AS a ON (a.id = r.announce_id) | |
b58e5ac2 | 75 | WHERE expiration < CURRENT_DATE()'); |
14bc135e SJ |
76 | XDB::query('INSERT INTO group_announces_read |
77 | VALUES ({?}, {?})', | |
24bcf50c | 78 | Env::i('read'), S::i('uid')); |
79 | pl_redirect(""); | |
80 | } | |
81 | if (Env::has('unread')) { | |
14bc135e SJ |
82 | XDB::query('DELETE FROM group_announces_read |
83 | WHERE announce_id = {?} AND uid = {?}', | |
24bcf50c | 84 | Env::i('unread'), S::i('uid')); |
85 | pl_redirect("#art" . Env::i('unread')); | |
86 | } | |
5a9ad4b0 SJ |
87 | |
88 | /* TODO: refines this filter on promotions by using userfilter. */ | |
89 | $user = S::user(); | |
90 | if ($user->hasProfile()) { | |
91 | $promo = XDB::format('{?}', $user->profile()->entry_year); | |
92 | $minCondition = ' OR promo_min <= ' . $promo; | |
93 | $maxCondition = ' OR promo_max >= ' . $promo; | |
94 | } else { | |
95 | $minCondition = ''; | |
96 | $maxCondition = ''; | |
97 | } | |
98 | $arts = XDB::iterator('SELECT a.*, FIND_IN_SET(\'photo\', a.flags) AS photo | |
14bc135e SJ |
99 | FROM group_announces AS a |
100 | LEFT JOIN group_announces_read AS r ON (r.uid = {?} AND r.announce_id = a.id) | |
b58e5ac2 | 101 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
5a9ad4b0 SJ |
102 | AND (promo_min = 0' . $minCondition . ') |
103 | AND (promo_max = 0' . $maxCondition . ') | |
5660032a | 104 | AND r.announce_id IS NULL |
5a9ad4b0 SJ |
105 | ORDER BY a.expiration', |
106 | S::i('uid'), $globals->asso('id')); | |
107 | $index = XDB::iterator('SELECT a.id, a.titre, r.uid IS NULL AS nonlu | |
14bc135e SJ |
108 | FROM group_announces AS a |
109 | LEFT JOIN group_announces_read AS r ON (a.id = r.announce_id AND r.uid = {?}) | |
b58e5ac2 | 110 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
5a9ad4b0 SJ |
111 | AND (promo_min = 0' . $minCondition . ') |
112 | AND (promo_max = 0' . $maxCondition . ') | |
113 | ORDER BY a.expiration', | |
114 | S::i('uid'), $globals->asso('id')); | |
24bcf50c | 115 | $page->assign('article_index', $index); |
116 | } else { | |
14bc135e SJ |
117 | $arts = XDB::iterator("SELECT *, FIND_IN_SET('photo', flags) AS photo |
118 | FROM group_announces | |
b58e5ac2 | 119 | WHERE asso_id = {?} AND expiration >= CURRENT_DATE() |
14bc135e | 120 | AND FIND_IN_SET('public', flags)", |
24bcf50c | 121 | $globals->asso('id')); |
122 | } | |
4af7fd22 FB |
123 | if (may_update()) { |
124 | $subs_valid = XDB::query("SELECT uid | |
eb41eda9 | 125 | FROM group_member_sub_requests |
4af7fd22 FB |
126 | WHERE asso_id = {?}", |
127 | $globals->asso('id')); | |
128 | $page->assign('requests', $subs_valid->numRows()); | |
129 | } | |
24bcf50c | 130 | |
84fc72ff | 131 | if (!S::hasAuthToken()) { |
24bcf50c | 132 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News publiques", |
5700a250 | 133 | $platal->ns . "rss/rss.xml"); |
24bcf50c | 134 | } else { |
135 | $page->setRssLink("Polytechnique.net :: {$globals->asso("nom")} :: News", | |
2ab3486b | 136 | $platal->ns . 'rss/' . S::v('hruid') . '/' . S::user()->token . '/rss.xml'); |
24bcf50c | 137 | } |
eaf30d86 | 138 | |
24bcf50c | 139 | $page->assign('articles', $arts); |
ae7bb180 | 140 | } |
dd798f38 | 141 | |
26ba053e | 142 | function handler_logo($page) |
dd798f38 | 143 | { |
144 | global $globals; | |
833a6e86 | 145 | $globals->asso()->getLogo()->send(); |
dd798f38 | 146 | } |
2e94d2b8 | 147 | |
26ba053e | 148 | function handler_site($page) |
d430f4d8 | 149 | { |
150 | global $globals; | |
151 | $site = $globals->asso('site'); | |
152 | if (!$site) { | |
a7d35093 | 153 | $page->trigError('Le groupe n\'a pas de site web.'); |
d430f4d8 | 154 | return $this->handler_index($page); |
155 | } | |
02838718 | 156 | http_redirect($site); |
d430f4d8 | 157 | exit; |
158 | } | |
159 | ||
26ba053e | 160 | function handler_edit($page) |
2e94d2b8 | 161 | { |
162 | global $globals; | |
1490093c | 163 | $page->changeTpl('xnetgrp/edit.tpl'); |
2e94d2b8 | 164 | |
40d428d8 VZ |
165 | if (Post::has('submit')) { |
166 | S::assert_xsrf_token(); | |
167 | ||
113f6de8 | 168 | $flags = new PlFlagSet('wiki_desc'); |
a6761ca9 FB |
169 | $flags->addFlag('notif_unsub', Post::i('notif_unsub') == 1); |
170 | $site = Post::t('site'); | |
ffe73cf7 SJ |
171 | if ($site && ($site != "http://")) { |
172 | $scheme = parse_url($site, PHP_URL_SCHEME); | |
173 | if (!$scheme) { | |
174 | $site = "http://" . $site; | |
175 | } | |
176 | } else { | |
177 | $site = ""; | |
178 | } | |
23ff6dd6 | 179 | if (S::admin()) { |
c3d959ce SJ |
180 | $page->assign('super', true); |
181 | ||
5e2307dc | 182 | if (Post::v('mail_domain') && (strstr(Post::v('mail_domain'), '.') === false)) { |
6bb2f79a | 183 | $page->trigError('Le domaine doit être un FQDN (aucune modification effectuée) !!!'); |
c9110c6c | 184 | return; |
2e94d2b8 | 185 | } |
c3d959ce SJ |
186 | if (Post::t('nom') == '' || Post::t('diminutif') == '') { |
187 | $page->trigError('Ni le nom ni le diminutif du groupe ne peuvent être vide.'); | |
188 | return; | |
189 | } | |
004ff79e SJ |
190 | $axDate = make_datetime(Post::v('axDate')); |
191 | if (Post::t('axDate') != '') { | |
192 | $axDate = make_datetime(Post::v('axDate'))->format('Y-m-d'); | |
193 | } else { | |
194 | $axDate = null; | |
195 | } | |
08cce2ff | 196 | XDB::execute( |
eb41eda9 | 197 | "UPDATE groups |
2e94d2b8 | 198 | SET nom={?}, diminutif={?}, cat={?}, dom={?}, |
199 | descr={?}, site={?}, mail={?}, resp={?}, | |
004ff79e | 200 | forum={?}, mail_domain={?}, ax={?}, axDate = {?}, pub={?}, |
794feea7 | 201 | sub_url={?}, inscriptible={?}, unsub_url={?}, |
73ac0916 | 202 | flags = {?}, welcome_msg = {?} |
2e94d2b8 | 203 | WHERE id={?}", |
5e2307dc | 204 | Post::v('nom'), Post::v('diminutif'), |
ca46cc12 | 205 | Post::v('cat'), (Post::i('dom') == 0) ? null : Post::i('dom'), |
ffe73cf7 | 206 | Post::v('descr'), $site, |
5e2307dc | 207 | Post::v('mail'), Post::v('resp'), |
208 | Post::v('forum'), Post::v('mail_domain'), | |
004ff79e | 209 | Post::has('ax'), $axDate, Post::v('pub'), |
5e2307dc | 210 | Post::v('sub_url'), Post::v('inscriptible'), |
73ac0916 SJ |
211 | Post::v('unsub_url'), $flags, Post::t('welcome_msg'), |
212 | $globals->asso('id')); | |
5e2307dc | 213 | if (Post::v('mail_domain')) { |
831aa467 SJ |
214 | XDB::execute('INSERT IGNORE INTO email_virtual_domains (name) |
215 | VALUES ({?})', | |
216 | Post::t('mail_domain')); | |
217 | XDB::execute('UPDATE email_virtual_domains | |
218 | SET aliasing = id | |
219 | WHERE name = {?}', | |
220 | Post::t('mail_domain')); | |
2e94d2b8 | 221 | } |
222 | } else { | |
08cce2ff | 223 | XDB::execute( |
eb41eda9 | 224 | "UPDATE groups |
2e94d2b8 | 225 | SET descr={?}, site={?}, mail={?}, resp={?}, |
c2f19630 | 226 | forum={?}, pub= {?}, sub_url={?}, |
73ac0916 | 227 | unsub_url = {?}, flags = {?}, welcome_msg = {?} |
2e94d2b8 | 228 | WHERE id={?}", |
ffe73cf7 | 229 | Post::v('descr'), $site, |
5e2307dc | 230 | Post::v('mail'), Post::v('resp'), |
c2f19630 | 231 | Post::v('forum'), Post::v('pub'), |
30032578 | 232 | Post::v('sub_url'), Post::v('unsub_url'), |
73ac0916 SJ |
233 | $flags, Post::t('welcome_msg'), |
234 | $globals->asso('id')); | |
2e94d2b8 | 235 | } |
236 | ||
a174a707 SJ |
237 | Phone::deletePhones(0, Phone::LINK_GROUP, $globals->asso('id')); |
238 | $phone = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 0, | |
239 | 'type' => 'fixed', 'display' => Post::v('phone'), 'pub' => 'public')); | |
240 | $fax = new Phone(array('link_type' => 'group', 'link_id' => $globals->asso('id'), 'id' => 1, | |
241 | 'type' => 'fax', 'display' => Post::v('fax'), 'pub' => 'public')); | |
242 | $phone->save(); | |
243 | $fax->save(); | |
baab50c7 SJ |
244 | Address::deleteAddresses(null, Address::LINK_GROUP, null, $globals->asso('id')); |
245 | $address = new Address(array('groupid' => $globals->asso('id'), 'type' => Address::LINK_GROUP, 'text' => Post::v('address'))); | |
246 | $address->save(); | |
a6761ca9 | 247 | |
2e94d2b8 | 248 | if ($_FILES['logo']['name']) { |
a6761ca9 FB |
249 | $upload = PlUpload::get($_FILES['logo'], $globals->asso('id'), 'asso.logo', true); |
250 | if (!$upload) { | |
5660032a | 251 | $page->trigError("Impossible de télécharger le logo."); |
a6761ca9 | 252 | } else { |
eb41eda9 | 253 | XDB::execute('UPDATE groups |
5660032a SJ |
254 | SET logo = {?}, logo_mime = {?} |
255 | WHERE id = {?}', $upload->getContents(), $upload->contentType(), | |
a6761ca9 FB |
256 | $globals->asso('id')); |
257 | $upload->rm(); | |
258 | } | |
2e94d2b8 | 259 | } |
260 | ||
fc4714d6 SJ |
261 | pl_redirect('../' . Post::v('diminutif', $globals->asso('diminutif')) . '/edit'); |
262 | } | |
263 | ||
264 | if (S::admin()) { | |
265 | $dom = XDB::iterator('SELECT * | |
266 | FROM group_dom | |
267 | ORDER BY nom'); | |
268 | $page->assign('dom', $dom); | |
269 | $page->assign('super', true); | |
2e94d2b8 | 270 | } |
2e94d2b8 | 271 | } |
272 | ||
26ba053e | 273 | function handler_mail($page) |
479d2787 | 274 | { |
275 | global $globals; | |
276 | ||
1490093c | 277 | $page->changeTpl('xnetgrp/mail.tpl'); |
5c36f345 | 278 | $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); |
9bb8bf21 | 279 | $page->assign('listes', $mmlist->get_lists()); |
7912097e | 280 | $page->assign('user', S::user()); |
479d2787 | 281 | |
282 | if (Post::has('send')) { | |
e7fdf9dd | 283 | S::assert_xsrf_token(); |
5e2307dc | 284 | $from = Post::v('from'); |
285 | $sujet = Post::v('sujet'); | |
286 | $body = Post::v('body'); | |
479d2787 | 287 | |
5e2307dc | 288 | $mls = array_keys(Env::v('ml', array())); |
06db561e | 289 | $mbr = array_keys(Env::v('membres', array())); |
479d2787 | 290 | |
460d8f55 | 291 | $this->load('mail.inc.php'); |
c974e61c | 292 | set_time_limit(120); |
06db561e | 293 | $tos = get_all_redirects($mbr, $mls, $mmlist); |
eab2f6f5 | 294 | |
f3df6d38 | 295 | $upload = PlUpload::get($_FILES['uploaded'], S::user()->login(), 'xnet.emails', true); |
eab2f6f5 VZ |
296 | if (!$upload && @$_FILES['uploaded']['name'] && PlUpload::$lastError != null) { |
297 | $page->trigError(PlUpload::$lastError); | |
298 | return; | |
299 | } | |
300 | ||
5b21237d | 301 | send_xnet_mails($from, $sujet, $body, Env::v('wiki'), $tos, Post::v('replyto'), $upload, @$_FILES['uploaded']['name']); |
13627bef | 302 | if ($upload) { |
303 | $upload->rm(); | |
304 | } | |
6bb2f79a | 305 | $page->killSuccess("Email envoyé !"); |
479d2787 | 306 | $page->assign('sent', true); |
307 | } | |
308 | } | |
309 | ||
26ba053e | 310 | function handler_forum($page, $group = null, $artid = null) |
4f355064 | 311 | { |
312 | global $globals; | |
1490093c | 313 | $page->changeTpl('xnetgrp/forum.tpl'); |
4f355064 | 314 | if (!$globals->asso('forum')) { |
315 | return PL_NOT_FOUND; | |
316 | } | |
317 | require_once 'banana/forum.inc.php'; | |
318 | $get = array(); | |
319 | get_banana_params($get, $globals->asso('forum'), $group, $artid); | |
320 | run_banana($page, 'ForumsBanana', $get); | |
321 | } | |
322 | ||
26ba053e | 323 | function handler_annuaire($page, $action = null, $subaction = null) |
2e94d2b8 | 324 | { |
325 | global $globals; | |
a91fb584 | 326 | |
4b866888 RB |
327 | __autoload('userset'); |
328 | $admins = false; | |
316120eb | 329 | if ($action == 'trombi') { |
4b866888 RB |
330 | $view = new ProfileSet(new UFC_Group($globals->asso('id'))); |
331 | } else { | |
332 | if ($action == 'admins') { | |
333 | $admins = true; | |
334 | $action = $subaction; | |
8ae9dd2f | 335 | } |
4b866888 | 336 | $view = new UserSet(new UFC_Group($globals->asso('id'), $admins)); |
a91fb584 | 337 | } |
4b866888 RB |
338 | $view->addMod('xnetfiche', 'Annuaire'); |
339 | $view->addMod('trombi', 'Trombinoscope'); | |
340 | $view->apply('annuaire', $page, $action); | |
341 | $page->assign('only_admin', $admins); | |
316120eb | 342 | $page->changeTpl('xnetgrp/annuaire.tpl'); |
2e94d2b8 | 343 | } |
4e310c61 | 344 | |
26ba053e | 345 | function handler_trombi($page) |
a91fb584 | 346 | { |
347 | pl_redirect('annuaire/trombi'); | |
348 | } | |
349 | ||
26ba053e | 350 | function handler_geoloc($page) |
28929cf0 | 351 | { |
a91fb584 | 352 | pl_redirect('annuaire/geoloc'); |
28929cf0 | 353 | } |
eaf30d86 | 354 | |
26ba053e | 355 | function handler_vcard($page, $photos = null) |
5e193297 | 356 | { |
357 | global $globals; | |
5d42c993 | 358 | $vcard = new VCard($photos == 'photos', 'Membre du groupe ' . $globals->asso('nom')); |
801adeec | 359 | $vcard->addProfiles($globals->asso()->getMembersFilter()->getProfiles(null, Profile::FETCH_ALL)); |
5d42c993 | 360 | $vcard->show(); |
5e193297 | 361 | } |
362 | ||
26ba053e | 363 | function handler_csv($page, $filename = null) |
102f4e64 FB |
364 | { |
365 | global $globals; | |
366 | if (is_null($filename)) { | |
367 | $filename = $globals->asso('diminutif') . '.csv'; | |
368 | } | |
184b012d | 369 | $users = $globals->asso()->getMembersFilter(null, new UFO_Name('directory_name'))->getUsers(); |
023c46fb | 370 | pl_cached_content_headers('text/x-csv', 1); |
102f4e64 | 371 | $page->changeTpl('xnetgrp/annuaire-csv.tpl', NO_SKIN); |
a6761ca9 | 372 | $page->assign('users', $users); |
102f4e64 FB |
373 | } |
374 | ||
52366335 SJ |
375 | function handler_directory_sync($page) |
376 | { | |
377 | global $globals; | |
378 | require_once 'emails.inc.php'; | |
379 | ||
380 | $page->changeTpl('xnetgrp/sync.tpl'); | |
381 | Platal::load('lists', 'lists.inc.php'); | |
382 | ||
383 | if (Env::has('add_users')) { | |
384 | S::assert_xsrf_token(); | |
385 | ||
386 | $users = array_keys(Env::v('add_users')); | |
387 | $data = array(); | |
388 | foreach ($users as $uid) { | |
389 | $data[] = XDB::format('({?}, {?})', $globals->asso('id'), $uid); | |
390 | } | |
391 | XDB::rawExecute('INSERT INTO group_members (asso_id, uid) | |
392 | VALUES ' . implode(',', $data)); | |
393 | } | |
394 | ||
395 | if (Env::has('add_nonusers')) { | |
396 | S::assert_xsrf_token(); | |
397 | ||
398 | $nonusers = array_keys(Env::v('add_nonusers')); | |
399 | foreach ($nonusers as $email) { | |
400 | if ($user = User::getSilent($email) || !isvalid_email($email)) { | |
401 | continue; | |
402 | } | |
403 | ||
404 | list($local_part, $domain) = explode('@', strtolower($email)); | |
405 | $hruid = User::makeHrid($local_part, $domain, 'ext'); | |
406 | if ($user = User::getSilent($hruid)) { | |
407 | continue; | |
408 | } | |
409 | ||
410 | $parts = explode('.', $local_part); | |
411 | if (count($parts) == 1) { | |
412 | $lastname = $display_name = $full_name = $directory_name = ucfirst($local_part); | |
413 | $firstname = ''; | |
414 | } else { | |
415 | $firstname = ucfirst($parts[0]); | |
416 | $lastname = ucwords(implode(' ', array_slice($parts, 1))); | |
417 | $display_name = $firstname; | |
418 | $full_name = $firstname . ' ' . $lastname; | |
419 | $directory_name = strtoupper($lastname) . ' ' . $firstname; | |
420 | } | |
421 | XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state) | |
422 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', | |
423 | $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email); | |
424 | $uid = XDB::insertId(); | |
425 | XDB::execute('INSERT INTO group_members (asso_id, uid) | |
426 | VALUES ({?}, {?})', | |
427 | $globals->asso('id'), $uid); | |
428 | } | |
429 | } | |
430 | ||
431 | if (Env::has('add_users') || Env::has('add_nonusers')) { | |
432 | $page->trigSuccess('Ajouts réalisés avec succès.'); | |
433 | } | |
434 | ||
435 | $user = S::user(); | |
436 | $client = new MMList($user, $globals->asso('mail_domain')); | |
437 | $lists = $client->get_lists(); | |
438 | $members = array(); | |
439 | foreach ($lists as $list) { | |
440 | $details = $client->get_members($list['list']); | |
441 | $members = array_merge($members, list_extract_members($details[1])); | |
442 | } | |
443 | $members = array_unique($members); | |
444 | $uids = array(); | |
445 | $users = array(); | |
446 | $nonusers = array(); | |
447 | foreach ($members as $email) { | |
448 | if ($user = User::getSilent($email)) { | |
449 | $uids[] = $user->id(); | |
450 | } else { | |
451 | $nonusers[] = $email; | |
452 | } | |
453 | } | |
454 | ||
455 | $aliases = iterate_list_alias($globals->asso('mail_domain')); | |
456 | foreach ($aliases as $alias) { | |
457 | list($local_part, $domain) = explode('@', $alias); | |
458 | $aliases_members = list_alias_members($local_part, $domain); | |
459 | $users = array_merge($users, $aliases_members['users']); | |
460 | $nonusers = array_merge($nonusers, $aliases_members['nonusers']); | |
461 | } | |
462 | foreach ($users as $user) { | |
463 | $uids[] = $user->id(); | |
464 | } | |
465 | $nonusers = array_unique($nonusers); | |
466 | $uids = array_unique($uids); | |
467 | $uids = XDB::fetchColumn('SELECT a.uid | |
468 | FROM accounts AS a | |
469 | WHERE a.uid IN {?} AND NOT EXISTS (SELECT * | |
470 | FROM group_members AS g | |
471 | WHERE a.uid = g.uid AND g.asso_id = {?})', | |
472 | $uids, $globals->asso('id')); | |
473 | ||
474 | $users = User::getBulkUsersWithUIDs($uids); | |
475 | usort($users, 'User::compareDirectoryName'); | |
476 | sort($nonusers); | |
477 | ||
478 | $page->assign('users', $users); | |
479 | $page->assign('nonusers', $nonusers); | |
480 | } | |
481 | ||
c329751f SJ |
482 | function handler_non_active($page) |
483 | { | |
484 | global $globals; | |
485 | $page->changeTpl('xnetgrp/non_active.tpl'); | |
486 | ||
487 | $uids = XDB::fetchColumn('SELECT g.uid | |
488 | FROM group_members AS g | |
489 | INNER JOIN accounts AS a ON (a.uid = g.uid) | |
490 | LEFT JOIN register_pending_xnet AS p ON (p.uid = g.uid) | |
491 | WHERE a.uid = g.uid AND g.asso_id = {?} AND a.type = \'xnet\' AND a.state = \'disabled\' AND p.uid IS NULL', | |
492 | $globals->asso('id')); | |
493 | foreach ($uids as $key => $uid) { | |
494 | if (AccountReq::isPending($uid) || BulkAccountsReq::isPending($uid)) { | |
495 | unset($uids[$key]); | |
496 | } | |
497 | } | |
498 | ||
499 | if (Post::has('enable_accounts')) { | |
500 | S::assert_xsrf_token(); | |
501 | ||
502 | $uids_to_enable = array_intersect(array_keys(Post::v('enable_accounts')), $uids); | |
503 | ||
504 | $user = S::user(); | |
505 | $group = Platal::globals()->asso('nom'); | |
506 | $request = new BulkAccountsReq($user, $uids_to_enable, $group); | |
507 | $request->submit(); | |
508 | $page->trigSuccess('Un email va bientôt être envoyé aux personnes sélectionnées pour l\'activation de leur compte.'); | |
509 | ||
510 | foreach ($uids as $key => $uid) { | |
511 | if (in_array($uid, $uids_to_enable)) { | |
512 | unset($uids[$key]); | |
513 | } | |
514 | } | |
515 | } | |
516 | ||
517 | $users = User::getBulkUsersWithUIDs($uids); | |
518 | $page->assign('users', $users); | |
519 | } | |
520 | ||
4af7fd22 FB |
521 | private function removeSubscriptionRequest($uid) |
522 | { | |
523 | global $globals; | |
eb41eda9 | 524 | XDB::execute("DELETE FROM group_member_sub_requests |
4af7fd22 FB |
525 | WHERE asso_id = {?} AND uid = {?}", |
526 | $globals->asso('id'), $uid); | |
527 | } | |
528 | ||
26ba053e | 529 | private function validSubscription(User $user) |
4af7fd22 FB |
530 | { |
531 | global $globals; | |
0fab5209 | 532 | $this->removeSubscriptionRequest($user->id()); |
eb41eda9 | 533 | XDB::execute("INSERT IGNORE INTO group_members (asso_id, uid) |
cac7dc37 | 534 | VALUES ({?}, {?})", |
0fab5209 | 535 | $globals->asso('id'), $user->id()); |
cac7dc37 FB |
536 | if (XDB::affectedRows() == 1) { |
537 | $mailer = new PlMailer(); | |
538 | $mailer->addTo($user->forlifeEmail()); | |
539 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
540 | $mailer->setSubject('[' . $globals->asso('nom') . '] Demande d\'inscription'); | |
541 | $message = ($user->isFemale() ? 'Chère' : 'Cher') . " Camarade,\n" | |
542 | . "\n" | |
f41e70e9 SJ |
543 | . " Suite à ta demande d'adhésion à " . $globals->asso('nom') |
544 | . ", j'ai le plaisir de t'annoncer que ton inscription a été validée !\n" | |
73ac0916 | 545 | . (is_null($globals->asso('welcome_msg')) ? '' : "\n" . $globals->asso('welcome_msg') . "\n") |
cac7dc37 FB |
546 | . "\n" |
547 | . "Bien cordialement,\n" | |
548 | . "-- \n" | |
549 | . S::user()->fullName() . '.'; | |
f41e70e9 | 550 | $mailer->setTxtBody(wordwrap($message, 72)); |
cac7dc37 FB |
551 | $mailer->send(); |
552 | } | |
4af7fd22 FB |
553 | } |
554 | ||
26ba053e | 555 | function handler_subscribe($page, $u = null) |
fdf0200a | 556 | { |
c8faf82a | 557 | global $globals; |
1490093c | 558 | $page->changeTpl('xnetgrp/inscrire.tpl'); |
fdf0200a | 559 | |
560 | if (!$globals->asso('inscriptible')) | |
a7de4ef7 | 561 | $page->kill("Il n'est pas possible de s'inscire en ligne à ce " |
562 | ."groupe. Essaie de joindre le contact indiqué " | |
563 | ."sur la page de présentation."); | |
fdf0200a | 564 | |
565 | if (!is_null($u) && may_update()) { | |
0fab5209 VZ |
566 | $user = User::get($u); |
567 | if (!$user) { | |
568 | return PL_NOT_FOUND; | |
569 | } else { | |
570 | $page->assign('user', $user); | |
fdf0200a | 571 | } |
0fab5209 VZ |
572 | |
573 | // Retrieves the subscription status, and the reason. | |
574 | $res = XDB::query("SELECT reason | |
eb41eda9 | 575 | FROM group_member_sub_requests |
0fab5209 VZ |
576 | WHERE asso_id = {?} AND uid = {?}", |
577 | $globals->asso('id'), $user->id()); | |
578 | $reason = ($res->numRows() ? $res->fetchOneCell() : null); | |
579 | ||
580 | $res = XDB::query("SELECT COUNT(*) | |
eb41eda9 | 581 | FROM group_members |
0fab5209 VZ |
582 | WHERE asso_id = {?} AND uid = {?}", |
583 | $globals->asso('id'), $user->id()); | |
584 | $already_member = ($res->fetchOneCell() > 0); | |
585 | ||
586 | // Handles the membership request. | |
587 | if ($already_member) { | |
588 | $this->removeSubscriptionRequest($user->id()); | |
6bb2f79a | 589 | $page->kill($user->fullName() . ' est déjà membre du groupe !'); |
0fab5209 VZ |
590 | } elseif (Env::has('accept')) { |
591 | S::assert_xsrf_token(); | |
592 | ||
593 | $this->validSubscription($user); | |
594 | pl_redirect("member/" . $user->login()); | |
595 | } elseif (Env::has('refuse')) { | |
596 | S::assert_xsrf_token(); | |
597 | ||
598 | $this->removeSubscriptionRequest($user->id()); | |
599 | $mailer = new PlMailer(); | |
600 | $mailer->addTo($user->forlifeEmail()); | |
601 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); | |
602 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription annulée'); | |
603 | $mailer->setTxtBody(Env::v('motif')); | |
604 | $mailer->send(); | |
354adb18 | 605 | $page->killSuccess("La demande de {$user->fullName()} a bien été refusée."); |
0fab5209 VZ |
606 | } else { |
607 | $page->assign('show_form', true); | |
608 | $page->assign('reason', $reason); | |
609 | } | |
610 | return; | |
fdf0200a | 611 | } |
612 | ||
613 | if (is_member()) { | |
6bb2f79a | 614 | $page->kill("Tu es déjà membre !"); |
fdf0200a | 615 | return; |
616 | } | |
617 | ||
4af7fd22 | 618 | $res = XDB::query("SELECT uid |
eb41eda9 | 619 | FROM group_member_sub_requests |
4af7fd22 FB |
620 | WHERE uid = {?} AND asso_id = {?}", |
621 | S::i('uid'), $globals->asso('id')); | |
622 | if ($res->numRows() != 0) { | |
623 | $page->kill("Tu as déjà demandé ton inscription à ce groupe. Cette demande est actuellement en attente de validation."); | |
624 | return; | |
625 | } | |
626 | ||
fdf0200a | 627 | if (Post::has('inscrire')) { |
e7fdf9dd VZ |
628 | S::assert_xsrf_token(); |
629 | ||
eb41eda9 | 630 | XDB::execute("INSERT INTO group_member_sub_requests (asso_id, uid, ts, reason) |
4af7fd22 FB |
631 | VALUES ({?}, {?}, NOW(), {?})", |
632 | $globals->asso('id'), S::i('uid'), Post::v('message')); | |
ae775de9 SJ |
633 | $uf = New UserFilter(New UFC_Group($globals->asso('id'), true)); |
634 | $admins = $uf->iterUsers(); | |
635 | $admin = $admins->next(); | |
11d8c704 | 636 | $to = $admin->bestEmail(); |
ae775de9 | 637 | while ($admin = $admins->next()) { |
11d8c704 | 638 | $to .= ', ' . $admin->bestEmail(); |
ae775de9 | 639 | } |
fdf0200a | 640 | |
641 | $append = "\n" | |
642 | . "-- \n" | |
a7de4ef7 | 643 | . "Ce message a été envoyé suite à la demande d'inscription de\n" |
0fab5209 | 644 | . S::user()->fullName() . ' (X' . S::v('promo') . ")\n" |
fdf0200a | 645 | . "Via le site www.polytechnique.net. Tu peux choisir de valider ou\n" |
646 | . "de refuser sa demande d'inscription depuis la page :\n" | |
0fab5209 | 647 | . "http://www.polytechnique.net/" . $globals->asso("diminutif") . "/subscribe/" . S::user()->login() . "\n" |
fdf0200a | 648 | . "\n" |
a7de4ef7 | 649 | . "En cas de problème, contacter l'équipe de Polytechnique.org\n" |
650 | . "à l'adresse : support@polytechnique.org\n"; | |
fdf0200a | 651 | |
652 | if (!$to) { | |
6f2b23a4 SJ |
653 | $to = ($globals->asso('mail') != '') ? $globals->asso('mail') . ', ' : ''; |
654 | $to .= 'support@polytechnique.org'; | |
fdf0200a | 655 | $append = "\n-- \nLe groupe ".$globals->asso("nom") |
a7de4ef7 | 656 | ." n'a pas d'administrateur, l'équipe de" |
657 | ." Polytechnique.org a été prévenue et va rapidement" | |
658 | ." résoudre ce problème.\n"; | |
fdf0200a | 659 | } |
660 | ||
1e33266a | 661 | $mailer = new PlMailer(); |
fdf0200a | 662 | $mailer->addTo($to); |
0fab5209 | 663 | $mailer->setFrom('"' . S::user()->fullName() . '" <' . S::user()->forlifeEmail() . '>'); |
fdf0200a | 664 | $mailer->setSubject('['.$globals->asso('nom').'] Demande d\'inscription'); |
5e2307dc | 665 | $mailer->setTxtBody(Post::v('message').$append); |
fdf0200a | 666 | $mailer->send(); |
667 | } | |
668 | } | |
669 | ||
26ba053e | 670 | function handler_subscribe_valid($page) |
4af7fd22 FB |
671 | { |
672 | global $globals; | |
673 | ||
674 | if (Post::has('valid')) { | |
675 | S::assert_xsrf_token(); | |
676 | $subs = Post::v('subs'); | |
677 | if (is_array($subs)) { | |
678 | $users = array(); | |
0fab5209 | 679 | foreach ($subs as $hruid => $val) { |
4af7fd22 | 680 | if ($val == '1') { |
0fab5209 VZ |
681 | $user = User::get($hruid); |
682 | if ($user) { | |
683 | $this->validSubscription($user); | |
4af7fd22 FB |
684 | } |
685 | } | |
686 | } | |
687 | } | |
688 | } | |
689 | ||
aa21c568 | 690 | $it = XDB::iterator('SELECT s.uid, a.hruid, s.ts AS date |
eb41eda9 | 691 | FROM group_member_sub_requests AS s |
c8d75c58 | 692 | INNER JOIN accounts AS a ON(s.uid = a.uid) |
aa21c568 FB |
693 | WHERE s.asso_id = {?} |
694 | ORDER BY s.ts', $globals->asso('id')); | |
4af7fd22 FB |
695 | $page->changeTpl('xnetgrp/subscribe-valid.tpl'); |
696 | $page->assign('valid', $it); | |
697 | } | |
698 | ||
26ba053e | 699 | function handler_change_rights($page) |
b8e265bf | 700 | { |
0c02607e | 701 | if (Env::has('right') && (may_update() || S::suid())) { |
b8e265bf | 702 | switch (Env::v('right')) { |
eaf30d86 | 703 | case 'admin': |
ab694eb5 | 704 | Platal::session()->stopSUID(); |
b8e265bf | 705 | break; |
706 | case 'anim': | |
ab694eb5 | 707 | Platal::session()->doSelfSuid(); |
b8e265bf | 708 | may_update(true); |
709 | is_member(true); | |
710 | break; | |
711 | case 'member': | |
ab694eb5 | 712 | Platal::session()->doSelfSuid(); |
b8e265bf | 713 | may_update(false, true); |
714 | is_member(true); | |
715 | break; | |
716 | case 'logged': | |
ab694eb5 | 717 | Platal::session()->doSelfSuid(); |
b8e265bf | 718 | may_update(false, true); |
719 | is_member(false, true); | |
720 | break; | |
721 | } | |
722 | } | |
5603d2ce | 723 | http_redirect($_SERVER['HTTP_REFERER']); |
b8e265bf | 724 | } |
725 | ||
26ba053e | 726 | function handler_admin_annuaire($page) |
4e310c61 | 727 | { |
728 | global $globals; | |
729 | ||
460d8f55 | 730 | $this->load('mail.inc.php'); |
1490093c | 731 | $page->changeTpl('xnetgrp/annuaire-admin.tpl'); |
aa21c568 FB |
732 | $user = S::user(); |
733 | $mmlist = new MMList($user, $globals->asso('mail_domain')); | |
9bb8bf21 | 734 | $lists = $mmlist->get_lists(); |
4e310c61 | 735 | if (!$lists) $lists = array(); |
736 | $listes = array_map(create_function('$arr', 'return $arr["list"];'), $lists); | |
737 | ||
738 | $subscribers = array(); | |
739 | ||
740 | foreach ($listes as $list) { | |
9bb8bf21 | 741 | list(,$members) = $mmlist->get_members($list); |
4e310c61 | 742 | $mails = array_map(create_function('$arr', 'return $arr[1];'), $members); |
743 | $subscribers = array_unique(array_merge($subscribers, $mails)); | |
744 | } | |
745 | ||
746 | $not_in_group_x = array(); | |
747 | $not_in_group_ext = array(); | |
748 | ||
749 | foreach ($subscribers as $mail) { | |
c8763ca3 | 750 | $uf = new UserFilter(new PFC_And(new UFC_Group($globals->asso('id')), |
aa21c568 FB |
751 | new UFC_Email($mail))); |
752 | if ($uf->getTotalCount() == 0) { | |
753 | if (User::isForeignEmailAddress($mail)) { | |
4e310c61 | 754 | $not_in_group_ext[] = $mail; |
755 | } else { | |
756 | $not_in_group_x[] = $mail; | |
757 | } | |
758 | } | |
759 | } | |
760 | ||
761 | $page->assign('not_in_group_ext', $not_in_group_ext); | |
762 | $page->assign('not_in_group_x', $not_in_group_x); | |
763 | $page->assign('lists', $lists); | |
764 | } | |
ef7c8560 | 765 | |
26ba053e | 766 | function handler_admin_member_new($page, $email = null) |
ef7c8560 | 767 | { |
768 | global $globals; | |
769 | ||
1490093c | 770 | $page->changeTpl('xnetgrp/membres-add.tpl'); |
ef7c8560 | 771 | |
772 | if (is_null($email)) { | |
773 | return; | |
774 | } | |
775 | ||
bb88d138 | 776 | S::assert_xsrf_token(); |
bc6e8005 | 777 | $suggest_account_activation = false; |
bb88d138 | 778 | |
41905adf RB |
779 | // FS#703 : $_GET is urldecoded twice, hence |
780 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
781 | // Since there can be no spaces in emails, we can fix this with : | |
782 | $email = str_replace(' ', '+', $email); | |
783 | ||
33a4f3f9 | 784 | // Finds or creates account: first cases are for users with an account. |
a1642859 | 785 | if (!User::isForeignEmailAddress($email)) { |
33a4f3f9 | 786 | // Standard account |
5142a832 | 787 | $user = User::getSilent($email); |
bb88d138 PC |
788 | } else if (!isvalid_email($email)) { |
789 | // email might not be a regular email but an alias or a hruid | |
5142a832 | 790 | $user = User::getSilent($email); |
bb88d138 PC |
791 | if (!$user) { |
792 | // need a valid email address | |
33a4f3f9 | 793 | $page->trigError('« <strong>' . $email . '</strong> » n\'est pas une adresse email valide.'); |
bb88d138 | 794 | return; |
ef7c8560 | 795 | } |
bb88d138 | 796 | } else if (Env::v('x') && Env::i('userid')) { |
5142a832 | 797 | $user = User::getSilentWithUID(Env::i('userid')); |
bb88d138 | 798 | if (!$user) { |
33a4f3f9 | 799 | $page->trigError('Utilisateur invalide.'); |
bb88d138 PC |
800 | return; |
801 | } | |
33a4f3f9 SJ |
802 | |
803 | // User has an account but is not yet registered. | |
804 | if ($user->state == 'pending') { | |
805 | // Add email in account table. | |
806 | XDB::query('UPDATE accounts | |
807 | SET email = {?} | |
808 | WHERE uid = {?} AND email IS NULL', | |
809 | Post::t('email'), $user->id()); | |
810 | // Add email for marketing if required. | |
811 | if (Env::v('market')) { | |
812 | $market = Marketing::get($user->uid, $email); | |
813 | if (!$market) { | |
814 | $market = new Marketing($user->uid, $email, 'group', $globals->asso('nom'), | |
815 | Env::v('market_from'), S::v('uid')); | |
816 | $market->add(); | |
817 | } | |
dc2073c3 | 818 | } |
bb88d138 PC |
819 | } |
820 | } else { | |
bc6e8005 SJ |
821 | // User is of type xnet. There are 3 possible cases: |
822 | // * the email is not known yet: we create a new account and | |
823 | // propose to send an email to the user so he can activate | |
824 | // his account, | |
825 | // * the email is known but the user was not contacted in order to | |
826 | // activate yet: we propose to send an email to the user so he | |
827 | // can activate his account, | |
828 | // * the email is known and the user was already contacted or has | |
829 | // an active account: nothing to be done. | |
445d244c RB |
830 | list($mbox, $domain) = explode('@', strtolower($email)); |
831 | $hruid = User::makeHrid($mbox, $domain, 'ext'); | |
33a4f3f9 | 832 | // User might already have an account (in another group for example). |
5142a832 | 833 | $user = User::getSilent($hruid); |
33a4f3f9 SJ |
834 | |
835 | // If the user has no account yet, creates new account: build names from email address. | |
bb88d138 | 836 | if (empty($user)) { |
445d244c RB |
837 | $parts = explode('.', $mbox); |
838 | if (count($parts) == 1) { | |
b7753795 SJ |
839 | $lastname = $display_name = $full_name = $directory_name = ucfirst($mbox); |
840 | $firstname = ''; | |
445d244c RB |
841 | } else { |
842 | $firstname = ucfirst($parts[0]); | |
843 | $lastname = ucwords(implode(' ', array_slice($parts, 1))); | |
844 | $display_name = $firstname; | |
845 | $full_name = "$firstname $lastname"; | |
846 | $directory_name = strtoupper($lastname) . " " . $firstname; | |
847 | } | |
b7753795 | 848 | XDB::execute('INSERT INTO accounts (hruid, display_name, full_name, directory_name, firstname, lastname, email, type, state) |
5142a832 | 849 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, \'xnet\', \'disabled\')', |
b7753795 | 850 | $hruid, $display_name, $full_name, $directory_name, $firstname, $lastname, $email); |
5142a832 | 851 | $user = User::getSilent($hruid); |
ef7c8560 | 852 | } |
bc6e8005 | 853 | |
fb422cab | 854 | $suggest_account_activation = $this->suggest($user); |
ef7c8560 | 855 | } |
33a4f3f9 | 856 | |
bb88d138 | 857 | if ($user) { |
00ba8a74 SJ |
858 | XDB::execute('INSERT IGNORE INTO group_members (uid, asso_id) |
859 | VALUES ({?}, {?})', | |
bb88d138 PC |
860 | $user->id(), $globals->asso('id')); |
861 | $this->removeSubscriptionRequest($user->id()); | |
bc6e8005 SJ |
862 | if ($suggest_account_activation) { |
863 | pl_redirect('member/suggest/' . $user->login() . '/' . $email . '/' . $globals->asso('nom')); | |
864 | } else { | |
865 | pl_redirect('member/' . $user->login()); | |
866 | } | |
867 | } | |
868 | } | |
869 | ||
fb422cab SJ |
870 | // Check if the user has a pending or active account, and thus if we should her account's activation. |
871 | private function suggest(PlUser $user) | |
872 | { | |
873 | $active = XDB::fetchOneCell('SELECT state = \'active\' | |
874 | FROM accounts | |
875 | WHERE uid = {?}', | |
876 | $user->id()); | |
877 | $pending = XDB::fetchOneCell('SELECT uid | |
878 | FROM register_pending_xnet | |
879 | WHERE uid = {?}', | |
880 | $user->id()); | |
c329751f | 881 | $requested = AccountReq::isPending($user->id()) || BulkAccountsReq::isPending($user->id()); |
fb422cab SJ |
882 | |
883 | if ($active || $pending || $requested) { | |
884 | return false; | |
885 | } | |
886 | return true; | |
887 | } | |
888 | ||
bc6e8005 SJ |
889 | function handler_admin_member_suggest($page, $hruid, $email) |
890 | { | |
891 | $page->changeTpl('xnetgrp/membres-suggest.tpl'); | |
41905adf RB |
892 | |
893 | // FS#703 : $_GET is urldecoded twice, hence | |
894 | // + (the data) => %2B (in the url) => + (first decoding) => ' ' (second decoding) | |
895 | // Since there can be no spaces in emails, we can fix this with : | |
896 | $email = str_replace(' ', '+', $email); | |
bc6e8005 SJ |
897 | |
898 | if (Post::has('suggest')) { | |
899 | if (Post::t('suggest') == 'yes') { | |
900 | $user = S::user(); | |
901 | $group = Platal::globals()->asso('nom'); | |
902 | $request = new AccountReq($user, $hruid, $email, $group); | |
903 | $request->submit(); | |
904 | $page->trigSuccessRedirect('Un email va bien être envoyé à ' . $email . ' pour l\'activation de son compte.', | |
905 | $group . '/member/' . $hruid); | |
906 | } else { | |
907 | pl_redirect('member/' . $hruid); | |
908 | } | |
bb88d138 | 909 | } |
bc6e8005 SJ |
910 | $page->assign('email', $email); |
911 | $page->assign('hruid', $hruid); | |
ef7c8560 | 912 | } |
913 | ||
26ba053e | 914 | function handler_admin_member_new_ajax($page) |
dc2073c3 | 915 | { |
3cb500d5 | 916 | pl_content_headers("text/html"); |
8b1f8e12 | 917 | $page->changeTpl('xnetgrp/membres-new-search.tpl', NO_SKIN); |
aa21c568 | 918 | $users = array(); |
0baf0741 | 919 | if (Env::has('login')) { |
aa21c568 FB |
920 | $user = User::getSilent(Env::t('login')); |
921 | if ($user && $user->state != 'pending') { | |
922 | $users = array($user); | |
923 | } | |
e2b0a45c | 924 | } |
aa21c568 | 925 | if (empty($users)) { |
33a4f3f9 | 926 | list($lastname, $firstname) = str_replace(array('-', ' ', "'"), '%', array(Env::t('nom'), Env::t('prenom'))); |
c8763ca3 | 927 | $cond = new PFC_And(new PFC_Not(new UFC_Registered())); |
33a4f3f9 SJ |
928 | if (!empty($lastname)) { |
929 | $cond->addChild(new UFC_Name(Profile::LASTNAME, $lastname, UFC_Name::CONTAINS)); | |
0baf0741 | 930 | } |
33a4f3f9 SJ |
931 | if (!empty($firstname)) { |
932 | $cond->addChild(new UFC_Name(Profile::FIRSTNAME, $firstname, UFC_Name::CONTAINS)); | |
0baf0741 | 933 | } |
33a4f3f9 SJ |
934 | if (Env::t('promo')) { |
935 | $cond->addChild(new UFC_Promo('=', UserFilter::DISPLAY, Env::t('promo'))); | |
aa21c568 FB |
936 | } |
937 | $uf = new UserFilter($cond); | |
e1406965 | 938 | $users = $uf->getUsers(new PlLimit(30)); |
aa21c568 FB |
939 | if ($uf->getTotalCount() > 30) { |
940 | $page->assign('too_many', true); | |
941 | $users = array(); | |
0baf0741 | 942 | } |
dc2073c3 | 943 | } |
aa21c568 | 944 | $page->assign('users', $users); |
dc2073c3 | 945 | } |
946 | ||
26ba053e | 947 | function unsubscribe(PlUser $user) |
ef7c8560 | 948 | { |
d7610c35 | 949 | global $globals; |
eb41eda9 | 950 | XDB::execute("DELETE FROM group_members |
45dcd6dd FB |
951 | WHERE uid = {?} AND asso_id = {?}", |
952 | $user->id(), $globals->asso('id')); | |
ef7c8560 | 953 | |
fa9493fe FB |
954 | if ($globals->asso('notif_unsub')) { |
955 | $mailer = new PlMailer('xnetgrp/unsubscription-notif.mail.tpl'); | |
57c1f1d7 SJ |
956 | $admins = $globals->asso()->iterAdmins(); |
957 | while ($admin = $admins->next()) { | |
958 | $mailer->addTo($admin); | |
fa9493fe FB |
959 | } |
960 | $mailer->assign('group', $globals->asso('nom')); | |
45dcd6dd FB |
961 | $mailer->assign('user', $user); |
962 | $mailer->assign('selfdone', $user->id() == S::i('uid')); | |
fa9493fe FB |
963 | $mailer->send(); |
964 | } | |
eca5d69f | 965 | |
30032578 | 966 | $domain = $globals->asso('mail_domain'); |
45dcd6dd | 967 | if (!$domain) { |
30032578 | 968 | return true; |
969 | } | |
ef7c8560 | 970 | |
dc81a0b2 | 971 | $mmlist = new MMList(S::user(), $domain); |
45dcd6dd | 972 | $listes = $mmlist->get_lists($user->forlifeEmail()); |
ef7c8560 | 973 | |
30032578 | 974 | $may_update = may_update(); |
975 | $warning = false; | |
23ba40c4 PC |
976 | if (is_array($listes)) { |
977 | foreach ($listes as $liste) { | |
978 | if ($liste['sub'] == 2) { | |
979 | if ($may_update) { | |
980 | $mmlist->mass_unsubscribe($liste['list'], Array($user->forlifeEmail())); | |
981 | } else { | |
982 | $mmlist->unsubscribe($liste['list']); | |
983 | } | |
984 | } elseif ($liste['sub']) { | |
985 | Platal::page()->trigWarning($user->fullName() . " a une" | |
986 | ." demande d'inscription en cours sur la" | |
987 | ." liste {$liste['list']}@ !"); | |
988 | $warning = true; | |
ef7c8560 | 989 | } |
990 | } | |
30032578 | 991 | } |
ef7c8560 | 992 | |
831aa467 SJ |
993 | XDB::execute('DELETE v |
994 | FROM email_virtual AS v | |
995 | INNER JOIN email_virtual_domains AS d ON (v.domain = d.id) | |
996 | WHERE v.redirect = {?} AND d.name = {?}', | |
997 | $user->forlifeEmail(), $domain); | |
30032578 | 998 | return !$warning; |
999 | } | |
1000 | ||
26ba053e | 1001 | function handler_unsubscribe($page) |
30032578 | 1002 | { |
1490093c | 1003 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
035de9c1 | 1004 | $user = S::user(); |
cb1f5408 | 1005 | if (empty($user)) { |
30032578 | 1006 | return PL_NOT_FOUND; |
ef7c8560 | 1007 | } |
30032578 | 1008 | $page->assign('self', true); |
cb1f5408 | 1009 | $page->assign('user', $user); |
ef7c8560 | 1010 | |
30032578 | 1011 | if (!Post::has('confirm')) { |
1012 | return; | |
e7fdf9dd VZ |
1013 | } else { |
1014 | S::assert_xsrf_token(); | |
30032578 | 1015 | } |
1016 | ||
9a7f3d8e | 1017 | $hasSingleGroup = ($user->groupCount() == 1); |
cb1f5408 | 1018 | |
30032578 | 1019 | if ($this->unsubscribe($user)) { |
cb1f5408 | 1020 | $page->trigSuccess('Tu as été désinscrit du groupe avec succès.'); |
30032578 | 1021 | } else { |
cb1f5408 SJ |
1022 | $page->trigWarning('Tu as été désinscrit du groupe, mais des erreurs se sont produites lors des désinscriptions des alias et des listes de diffusion.'); |
1023 | } | |
8d014576 SJ |
1024 | |
1025 | // If user is of type xnet account and this was her last group, disable the account. | |
1026 | if ($user->type == 'xnet' && $hasSingleGroup) { | |
1027 | $user->clear(true); | |
30032578 | 1028 | } |
c1863ee9 | 1029 | $page->assign('is_member', is_member(true)); |
30032578 | 1030 | } |
1031 | ||
26ba053e | 1032 | function handler_admin_member_del($page, $user = null) |
30032578 | 1033 | { |
1490093c | 1034 | $page->changeTpl('xnetgrp/membres-del.tpl'); |
45dcd6dd | 1035 | $user = User::getSilent($user); |
30032578 | 1036 | if (empty($user)) { |
1037 | return PL_NOT_FOUND; | |
1038 | } | |
4a648e80 SJ |
1039 | |
1040 | global $globals; | |
1041 | ||
1042 | if (!$user->inGroup($globals->asso('id'))) { | |
1043 | pl_redirect('annuaire'); | |
1044 | } | |
1045 | ||
cb1f5408 | 1046 | $page->assign('self', false); |
30032578 | 1047 | $page->assign('user', $user); |
1048 | ||
1049 | if (!Post::has('confirm')) { | |
1050 | return; | |
e7fdf9dd VZ |
1051 | } else { |
1052 | S::assert_xsrf_token(); | |
30032578 | 1053 | } |
1054 | ||
9a7f3d8e | 1055 | $hasSingleGroup = ($user->groupCount() == 1); |
91d2135c | 1056 | |
30032578 | 1057 | if ($this->unsubscribe($user)) { |
e46cf8c4 | 1058 | $page->trigSuccess("{$user->fullName()} a été désinscrit du groupe !"); |
30032578 | 1059 | } else { |
e46cf8c4 | 1060 | $page->trigWarning("{$user->fullName()} a été désinscrit du groupe, mais des erreurs subsistent !"); |
30032578 | 1061 | } |
91d2135c | 1062 | |
8d014576 | 1063 | // If user is of type xnet account and this was her last group, disable the account. |
91d2135c | 1064 | if ($user->type == 'xnet' && $hasSingleGroup) { |
8d014576 | 1065 | $user->clear(true); |
91d2135c | 1066 | } |
ef7c8560 | 1067 | } |
1068 | ||
2a1cd4ab | 1069 | private function changeLogin(PlPage $page, PlUser $user, $login) |
631565e1 | 1070 | { |
33a4f3f9 | 1071 | // Search the user's uid. |
bb88d138 PC |
1072 | $xuser = User::getSilent($login); |
1073 | if (!$xuser) { | |
61a7d279 SJ |
1074 | $accounts = User::getPendingAccounts($login); |
1075 | if (!$accounts) { | |
1076 | $page->trigError("L'identifiant $login ne correspond à aucun X."); | |
631565e1 | 1077 | return false; |
61a7d279 SJ |
1078 | } else if (count($accounts) > 1) { |
1079 | $page->trigError("L'identifiant $login correspond à plusieurs camarades."); | |
631565e1 FB |
1080 | return false; |
1081 | } | |
bb88d138 | 1082 | $xuser = User::getSilent($accounts[0]['uid']); |
631565e1 FB |
1083 | } |
1084 | ||
bb88d138 PC |
1085 | if (!$xuser) { |
1086 | return false; | |
631565e1 FB |
1087 | } |
1088 | ||
33a4f3f9 SJ |
1089 | if ($user->mergeIn($xuser)) { |
1090 | return $xuser->login(); | |
1091 | } | |
1092 | return $user->login(); | |
631565e1 FB |
1093 | } |
1094 | ||
26ba053e | 1095 | function handler_admin_member($page, $user) |
ef7c8560 | 1096 | { |
1097 | global $globals; | |
1098 | ||
45dcd6dd | 1099 | $user = User::getSilent($user); |
ef7c8560 | 1100 | if (empty($user)) { |
1101 | return PL_NOT_FOUND; | |
1102 | } | |
1103 | ||
7ae5c545 SJ |
1104 | if (!$user->inGroup($globals->asso('id'))) { |
1105 | pl_redirect('annuaire'); | |
1106 | } | |
1107 | ||
1108 | $page->changeTpl('xnetgrp/membres-edit.tpl'); | |
1109 | ||
dc81a0b2 | 1110 | $mmlist = new MMList(S::user(), $globals->asso('mail_domain')); |
ef7c8560 | 1111 | |
1112 | if (Post::has('change')) { | |
ca6980dc | 1113 | require_once 'emails.inc.php'; |
e7fdf9dd VZ |
1114 | S::assert_xsrf_token(); |
1115 | ||
631565e1 | 1116 | // Convert user status to X |
bb88d138 | 1117 | if (!Post::blank('login_X')) { |
bb94f7b6 | 1118 | $forlife = $this->changeLogin($page, $user, Post::t('login_X')); |
631565e1 FB |
1119 | if ($forlife) { |
1120 | pl_redirect('member/' . $forlife); | |
1121 | } | |
1122 | } | |
1123 | ||
1124 | // Update user info | |
bb88d138 PC |
1125 | $email_changed = (!$user->profile() && strtolower($user->forlifeEmail()) != strtolower(Post::v('email'))); |
1126 | $from_email = $user->forlifeEmail(); | |
1d6870e1 | 1127 | if ($user->type == 'virtual' || ($user->type == 'xnet' && !$user->perms)) { |
b7753795 SJ |
1128 | $lastname = Post::s('lastname'); |
1129 | if (Post::s('type') != 'virtual') { | |
1130 | $firstname = Post::s('firstname'); | |
1131 | $full_name = $firstname . ' ' . $lastname; | |
1132 | $directory_name = mb_strtoupper($lastname) . ' ' . $firstname; | |
1133 | } else { | |
1134 | $firstname = ''; | |
1135 | $full_name = $lastname; | |
1136 | $directory_name = mb_strtoupper($lastname); | |
1137 | } | |
bb88d138 | 1138 | XDB::query('UPDATE accounts |
33a4f3f9 | 1139 | SET full_name = {?}, directory_name = {?}, display_name = {?}, |
b7753795 | 1140 | firstname = {?}, lastname = {?}, sex = {?}, email = {?}, type = {?} |
bb88d138 | 1141 | WHERE uid = {?}', |
b7753795 | 1142 | $full_name, $directory_name, Post::t('display_name'), $firstname, $lastname, |
33a4f3f9 SJ |
1143 | (Post::t('sex') == 'male') ? 'male' : 'female', Post::t('email'), |
1144 | (Post::t('type') == 'xnet') ? 'xnet' : 'virtual', $user->id()); | |
1145 | } else if (!$user->perms) { | |
1146 | XDB::query('UPDATE accounts | |
1147 | SET email = {?} | |
1148 | WHERE uid = {?}', | |
1149 | Post::t('email'), $user->id()); | |
1150 | } | |
ca6980dc SJ |
1151 | if (require_email_update($user, Post::t('email'))) { |
1152 | $listClient = new MMList(S::user()); | |
1153 | $listClient->change_user_email($user->forlifeEmail(), Post::t('email')); | |
1154 | update_alias_user($user->forlifeEmail(), Post::t('email')); | |
1155 | } | |
33a4f3f9 | 1156 | if (XDB::affectedRows()) { |
94bf736e | 1157 | $page->trigSuccess('Données de l\'utilisateur mises à jour.'); |
ef7c8560 | 1158 | } |
1159 | ||
fb422cab SJ |
1160 | if (($user->type == 'xnet' && !$user->perms) && Post::b('suggest')) { |
1161 | $request = new AccountReq(S::user(), $user->hruid, Post::t('email'), $globals->asso('nom')); | |
1162 | $request->submit(); | |
1163 | $page->trigSuccess('Le compte va bientôt être activé.'); | |
1164 | } | |
1165 | ||
bb88d138 PC |
1166 | // Update group params for user |
1167 | $perms = Post::v('group_perms'); | |
a6761ca9 | 1168 | $comm = Post::t('comm'); |
33fcb12c SJ |
1169 | $position = (Post::t('group_position') == '') ? null : Post::v('group_position'); |
1170 | if ($user->group_perms != $perms || $user->group_comm != $comm || $user->group_position != $position) { | |
eb41eda9 | 1171 | XDB::query('UPDATE group_members |
33fcb12c | 1172 | SET perms = {?}, comm = {?}, position = {?} |
00112b2e | 1173 | WHERE uid = {?} AND asso_id = {?}', |
33fcb12c | 1174 | ($perms == 'admin') ? 'admin' : 'membre', $comm, $position, |
bb88d138 | 1175 | $user->id(), $globals->asso('id')); |
33a4f3f9 SJ |
1176 | if (XDB::affectedRows()) { |
1177 | if ($perms != $user->group_perms) { | |
1178 | $page->trigSuccess('Permissions modifiées !'); | |
1179 | } | |
1180 | if ($comm != $user->group_comm) { | |
1181 | $page->trigSuccess('Commentaire mis à jour.'); | |
1182 | } | |
58149849 SJ |
1183 | if ($position != $user->group_position) { |
1184 | $page->trigSuccess('Poste mis à jour.'); | |
1185 | } | |
54b24ba2 | 1186 | } |
ef7c8560 | 1187 | } |
1188 | ||
bb88d138 PC |
1189 | // Gets user info again as they might have change |
1190 | $user = User::getSilent($user->id()); | |
1191 | ||
631565e1 | 1192 | // Update ML subscriptions |
5e2307dc | 1193 | foreach (Env::v('ml1', array()) as $ml => $state) { |
ef7c8560 | 1194 | $ask = empty($_REQUEST['ml2'][$ml]) ? 0 : 2; |
c4d57bd8 | 1195 | if ($ask == $state) { |
06db561e | 1196 | if ($state && $email_changed) { |
bb88d138 PC |
1197 | $mmlist->replace_email($ml, $from_email, $user->forlifeEmail()); |
1198 | $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml@ a été mis à jour."); | |
c4d57bd8 | 1199 | } |
1200 | continue; | |
1201 | } | |
ef7c8560 | 1202 | if ($state == '1') { |
bb88d138 | 1203 | $page->trigWarning("{$user->fullName()} a " |
ef7c8560 | 1204 | ."actuellement une demande d'inscription en " |
1205 | ."cours sur <strong>$ml@</strong> !!!"); | |
1206 | } elseif ($ask) { | |
bb88d138 PC |
1207 | $mmlist->mass_subscribe($ml, Array($user->forlifeEmail())); |
1208 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml@."); | |
ef7c8560 | 1209 | } else { |
c4d57bd8 | 1210 | if ($email_changed) { |
1211 | $mmlist->mass_unsubscribe($ml, Array($from_email)); | |
1212 | } else { | |
bb88d138 | 1213 | $mmlist->mass_unsubscribe($ml, Array($user->forlifeEmail())); |
c4d57bd8 | 1214 | } |
bb88d138 | 1215 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml@."); |
ef7c8560 | 1216 | } |
1217 | } | |
1218 | ||
631565e1 | 1219 | // Change subscriptioin to aliases |
5e2307dc | 1220 | foreach (Env::v('ml3', array()) as $ml => $state) { |
831aa467 | 1221 | require_once 'emails.inc.php'; |
ef7c8560 | 1222 | $ask = !empty($_REQUEST['ml4'][$ml]); |
7e82b545 | 1223 | list($local_part, ) = explode('@', $ml); |
bb88d138 PC |
1224 | if($state == $ask) { |
1225 | if ($state && $email_changed) { | |
7e82b545 | 1226 | update_list_alias($user->id(), $from_email, $local_part, $globals->asso('mail_domain')); |
bb88d138 PC |
1227 | $page->trigSuccess("L'abonnement de {$user->fullName()} à $ml a été mis à jour."); |
1228 | } | |
1229 | } else if($ask) { | |
7e82b545 | 1230 | add_to_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); |
bb88d138 | 1231 | $page->trigSuccess("{$user->fullName()} a été abonné à $ml."); |
ef7c8560 | 1232 | } else { |
7e82b545 | 1233 | delete_from_list_alias($user->id(), $local_part, $globals->asso('mail_domain')); |
bb88d138 | 1234 | $page->trigSuccess("{$user->fullName()} a été désabonné de $ml."); |
ef7c8560 | 1235 | } |
1236 | } | |
1237 | } | |
1238 | ||
33fcb12c SJ |
1239 | $res = XDB::rawFetchAllAssoc('SHOW COLUMNS FROM group_members LIKE \'position\''); |
1240 | $positions = str_replace(array('enum(', ')', '\''), '', $res[0]['Type']); | |
1241 | ||
ef7c8560 | 1242 | $page->assign('user', $user); |
fb422cab | 1243 | $page->assign('suggest', $this->suggest($user)); |
a6761ca9 | 1244 | $page->assign('listes', $mmlist->get_lists($user->forlifeEmail())); |
06a548e5 | 1245 | $page->assign('alias', $user->emailGroupAliases($globals->asso('mail_domain'))); |
33fcb12c | 1246 | $page->assign('positions', explode(',', $positions)); |
ef7c8560 | 1247 | } |
24bcf50c | 1248 | |
82af3fc3 | 1249 | function handler_rss(PlPage $page, PlUser $user) |
24bcf50c | 1250 | { |
1251 | global $globals; | |
24bcf50c | 1252 | $page->assign('asso', $globals->asso()); |
4f18bb11 | 1253 | |
460d8f55 | 1254 | $this->load('feed.inc.php'); |
4f18bb11 | 1255 | $feed = new XnetGrpEventFeed(); |
190efb3a | 1256 | return $feed->run($page, $user, false); |
24bcf50c | 1257 | } |
1258 | ||
26ba053e | 1259 | private function upload_image(PlPage $page, PlUpload $upload) |
ff95a302 FB |
1260 | { |
1261 | if (@!$_FILES['image']['tmp_name'] && !Env::v('image_url')) { | |
1262 | return true; | |
1263 | } | |
1264 | if (!$upload->upload($_FILES['image']) && !$upload->download(Env::v('image_url'))) { | |
a7d35093 | 1265 | $page->trigError('Impossible de télécharger l\'image'); |
ff95a302 FB |
1266 | return false; |
1267 | } elseif (!$upload->isType('image')) { | |
a7d35093 | 1268 | $page->trigError('Le fichier n\'est pas une image valide au format JPEG, GIF ou PNG.'); |
ff95a302 FB |
1269 | $upload->rm(); |
1270 | return false; | |
1271 | } elseif (!$upload->resizeImage(200, 300, 100, 100, 32284)) { | |
a7d35093 | 1272 | $page->trigError('Impossible de retraiter l\'image'); |
ff95a302 FB |
1273 | return false; |
1274 | } | |
1275 | return true; | |
1276 | } | |
1277 | ||
26ba053e | 1278 | function handler_photo_announce($page, $eid = null) { |
ff95a302 | 1279 | if ($eid) { |
14bc135e SJ |
1280 | $res = XDB::query('SELECT * |
1281 | FROM group_announces_photo | |
1282 | WHERE eid = {?}', $eid); | |
ff95a302 FB |
1283 | if ($res->numRows()) { |
1284 | $photo = $res->fetchOneAssoc(); | |
3cb500d5 | 1285 | pl_cached_dynamic_content_headers("image/" . $photo['attachmime']); |
ff95a302 FB |
1286 | echo $photo['attach']; |
1287 | exit; | |
1288 | } | |
1289 | } else { | |
f3df6d38 | 1290 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1291 | if ($upload->exists() && $upload->isType('image')) { |
3cb500d5 | 1292 | pl_cached_dynamic_content_headers($upload->contentType()); |
ff95a302 FB |
1293 | echo $upload->getContents(); |
1294 | exit; | |
1295 | } | |
1296 | } | |
1297 | global $globals; | |
3cb500d5 | 1298 | pl_cached_dynamic_content_headers("image/png"); |
ff95a302 FB |
1299 | echo file_get_contents($globals->spoolroot . '/htdocs/images/logo.png'); |
1300 | exit; | |
1301 | } | |
1302 | ||
26ba053e | 1303 | function handler_edit_announce($page, $aid = null) |
24bcf50c | 1304 | { |
1305 | global $globals, $platal; | |
1490093c | 1306 | $page->changeTpl('xnetgrp/announce-edit.tpl'); |
24bcf50c | 1307 | $page->assign('new', is_null($aid)); |
1308 | $art = array(); | |
1309 | ||
ff95a302 | 1310 | if (Post::v('valid') == 'Visualiser' || Post::v('valid') == 'Enregistrer' |
2f8677c2 | 1311 | || Post::v('valid') == 'Supprimer l\'image' || Post::v('valid') == 'Pas d\'image') { |
e7fdf9dd VZ |
1312 | S::assert_xsrf_token(); |
1313 | ||
24bcf50c | 1314 | if (!is_null($aid)) { |
1315 | $art['id'] = $aid; | |
1316 | } | |
1317 | $art['titre'] = Post::v('titre'); | |
1318 | $art['texte'] = Post::v('texte'); | |
1319 | $art['contacts'] = Post::v('contacts'); | |
1320 | $art['promo_min'] = Post::i('promo_min'); | |
1321 | $art['promo_max'] = Post::i('promo_max'); | |
1322 | $art['nom'] = S::v('nom'); | |
1323 | $art['prenom'] = S::v('prenom'); | |
1324 | $art['promo'] = S::v('promo'); | |
0fab5209 | 1325 | $art['hruid'] = S::user()->login(); |
79e610a9 | 1326 | $art['uid'] = S::user()->id(); |
b58e5ac2 | 1327 | $art['expiration'] = Post::v('expiration'); |
24bcf50c | 1328 | $art['public'] = Post::has('public'); |
1329 | $art['xorg'] = Post::has('xorg'); | |
1330 | $art['nl'] = Post::has('nl'); | |
1331 | $art['event'] = Post::v('event'); | |
f3df6d38 | 1332 | $upload = new PlUpload(S::user()->login(), 'xnetannounce'); |
ff95a302 | 1333 | $this->upload_image($page, $upload); |
24bcf50c | 1334 | |
1335 | $art['contact_html'] = $art['contacts']; | |
b9a1ba64 | 1336 | if ($art['event']) { |
1337 | $art['contact_html'] .= "\n{$globals->baseurl}/{$platal->ns}events/sub/{$art['event']}"; | |
24bcf50c | 1338 | } |
2a557a09 | 1339 | |
1340 | if (!$art['public'] && | |
d1c97e42 | 1341 | (($art['promo_min'] > $art['promo_max'] && $art['promo_max'] != 0) || |
2a557a09 | 1342 | ($art['promo_min'] != 0 && ($art['promo_min'] <= 1900 || $art['promo_min'] >= 2020)) || |
1343 | ($art['promo_max'] != 0 && ($art['promo_max'] <= 1900 || $art['promo_max'] >= 2020)))) | |
1344 | { | |
a7d35093 | 1345 | $page->trigError("L'intervalle de promotions est invalide."); |
2a557a09 | 1346 | Post::kill('valid'); |
1347 | } | |
1970c12b | 1348 | |
1349 | if (!trim($art['titre']) || !trim($art['texte'])) { | |
a7d35093 | 1350 | $page->trigError("L'article doit avoir un titre et un contenu."); |
1970c12b | 1351 | Post::kill('valid'); |
1352 | } | |
ff95a302 FB |
1353 | |
1354 | if (Post::v('valid') == 'Supprimer l\'image') { | |
1355 | $upload->rm(); | |
1356 | Post::kill('valid'); | |
1357 | } | |
2f8677c2 FB |
1358 | $art['photo'] = $upload->exists() || Post::i('photo'); |
1359 | if (Post::v('valid') == 'Pas d\'image' && !is_null($aid)) { | |
14bc135e SJ |
1360 | XDB::query('DELETE FROM group_announces_photo |
1361 | WHERE eid = {?}', $aid); | |
2f8677c2 FB |
1362 | $upload->rm(); |
1363 | Post::kill('valid'); | |
1364 | $art['photo'] = false; | |
1365 | } | |
24bcf50c | 1366 | } |
1367 | ||
1368 | if (Post::v('valid') == 'Enregistrer') { | |
2a557a09 | 1369 | $promo_min = ($art['public'] ? 0 : $art['promo_min']); |
1370 | $promo_max = ($art['public'] ? 0 : $art['promo_max']); | |
113f6de8 | 1371 | $flags = new PlFlagSet(); |
ff95a302 | 1372 | if ($art['public']) { |
77e786e1 | 1373 | $flags->addFlag('public'); |
ff95a302 FB |
1374 | } |
1375 | if ($art['photo']) { | |
77e786e1 | 1376 | $flags->addFlag('photo'); |
ff95a302 | 1377 | } |
24bcf50c | 1378 | if (is_null($aid)) { |
eaf30d86 PH |
1379 | $fulltext = $art['texte']; |
1380 | if (!empty($art['contact_html'])) { | |
1381 | $fulltext .= "\n\n'''Contacts :'''\\\\\n" . $art['contact_html']; | |
e219710a | 1382 | } |
91cf1bdb | 1383 | $post = null; |
e219710a | 1384 | if ($globals->asso('forum')) { |
1385 | require_once 'banana/forum.inc.php'; | |
e3a55098 | 1386 | $banana = new ForumsBanana(S::user()); |
e219710a | 1387 | $post = $banana->post($globals->asso('forum'), null, |
1388 | $art['titre'], MiniWiki::wikiToText($fulltext, false, 0, 80)); | |
91cf1bdb | 1389 | } |
14bc135e | 1390 | XDB::query('INSERT INTO group_announces (uid, asso_id, create_date, titre, texte, contacts, |
b58e5ac2 | 1391 | expiration, promo_min, promo_max, flags, post_id) |
14bc135e | 1392 | VALUES ({?}, {?}, NOW(), {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?})', |
24bcf50c | 1393 | S::i('uid'), $globals->asso('id'), $art['titre'], $art['texte'], $art['contact_html'], |
b58e5ac2 | 1394 | $art['expiration'], $promo_min, $promo_max, $flags, $post); |
8b83a166 | 1395 | $aid = XDB::insertId(); |
ff95a302 FB |
1396 | if ($art['photo']) { |
1397 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
14bc135e SJ |
1398 | XDB::execute('INSERT INTO group_announces_photo |
1399 | SET eid = {?}, attachmime = {?}, x = {?}, y = {?}, attach = {?}', | |
ff95a302 FB |
1400 | $aid, $imgtype, $imgx, $imgy, $upload->getContents()); |
1401 | } | |
24bcf50c | 1402 | if ($art['xorg']) { |
794feea7 | 1403 | $article = new EvtReq("[{$globals->asso('nom')}] " . $art['titre'], $fulltext, |
b58e5ac2 | 1404 | $art['promo_min'], $art['promo_max'], $art['expiration'], "", S::user(), |
ff95a302 | 1405 | $upload); |
24bcf50c | 1406 | $article->submit(); |
a7d35093 | 1407 | $page->trigWarning("L'affichage sur la page d'accueil de Polytechnique.org est en attente de validation."); |
ff95a302 FB |
1408 | } else if ($upload && $upload->exists()) { |
1409 | $upload->rm(); | |
24bcf50c | 1410 | } |
1411 | if ($art['nl']) { | |
5daf68f6 | 1412 | $article = new NLReq(S::user(), $globals->asso('nom') . " : " .$art['titre'], |
2a557a09 | 1413 | $art['texte'], $art['contact_html']); |
24bcf50c | 1414 | $article->submit(); |
a7d35093 | 1415 | $page->trigWarning("La parution dans la Lettre Mensuelle est en attente de validation."); |
24bcf50c | 1416 | } |
1417 | } else { | |
14bc135e | 1418 | XDB::query('UPDATE group_announces |
b58e5ac2 | 1419 | SET titre = {?}, texte = {?}, contacts = {?}, expiration = {?}, |
14bc135e SJ |
1420 | promo_min = {?}, promo_max = {?}, flags = {?} |
1421 | WHERE id = {?} AND asso_id = {?}', | |
b58e5ac2 | 1422 | $art['titre'], $art['texte'], $art['contacts'], $art['expiration'], |
ff95a302 | 1423 | $promo_min, $promo_max, $flags, |
24bcf50c | 1424 | $art['id'], $globals->asso('id')); |
2f8677c2 FB |
1425 | if ($art['photo'] && $upload->exists()) { |
1426 | list($imgx, $imgy, $imgtype) = $upload->imageInfo(); | |
00ba8a74 SJ |
1427 | XDB::execute('INSERT INTO group_announces_photo (eid, attachmime, attach, x, y) |
1428 | VALUES ({?}, {?}, {?}, {?}, {?}) | |
1429 | ON DUPLICATE KEY UPDATE attachmime = VALUES(attachmime), attach = VALUES(attach), x = VALUES(x), y = VALUES(y)', | |
1430 | $aid, $imgtype, $upload->getContents(), $imgx, $imgy); | |
2f8677c2 FB |
1431 | $upload->rm(); |
1432 | } | |
24bcf50c | 1433 | } |
2a557a09 | 1434 | } |
1435 | if (Post::v('valid') == 'Enregistrer' || Post::v('valid') == 'Annuler') { | |
24bcf50c | 1436 | pl_redirect(""); |
eaf30d86 | 1437 | } |
24bcf50c | 1438 | |
1439 | if (empty($art) && !is_null($aid)) { | |
14bc135e SJ |
1440 | $res = XDB::query("SELECT *, FIND_IN_SET('public', flags) AS public, |
1441 | FIND_IN_SET('photo', flags) AS photo | |
1442 | FROM group_announces | |
1443 | WHERE asso_id = {?} AND id = {?}", | |
24bcf50c | 1444 | $globals->asso('id'), $aid); |
1445 | if ($res->numRows()) { | |
1446 | $art = $res->fetchOneAssoc(); | |
1447 | $art['contact_html'] = $art['contacts']; | |
1448 | } else { | |
567553ac | 1449 | $page->kill("Aucun article correspond à l'identifiant indiqué."); |
24bcf50c | 1450 | } |
1451 | } | |
1452 | ||
24bcf50c | 1453 | if (is_null($aid)) { |
1454 | $events = XDB::iterator("SELECT * | |
eb41eda9 | 1455 | FROM group_events |
24bcf50c | 1456 | WHERE asso_id = {?} AND archive = 0", |
1457 | $globals->asso('id')); | |
1458 | if ($events->total()) { | |
1459 | $page->assign('events', $events); | |
1460 | } | |
eaf30d86 | 1461 | } |
24bcf50c | 1462 | |
72b2f8bb | 1463 | $art['contact_html'] = @MiniWiki::WikiToHTML($art['contact_html']); |
24bcf50c | 1464 | $page->assign('art', $art); |
ff95a302 | 1465 | $page->assign_by_ref('upload', $upload); |
24bcf50c | 1466 | } |
1467 | ||
26ba053e | 1468 | function handler_admin_announce($page) |
24bcf50c | 1469 | { |
1470 | global $globals; | |
1490093c | 1471 | $page->changeTpl('xnetgrp/announce-admin.tpl'); |
24bcf50c | 1472 | |
1473 | if (Env::has('del')) { | |
e7fdf9dd | 1474 | S::assert_xsrf_token(); |
14bc135e SJ |
1475 | XDB::execute('DELETE FROM group_announces |
1476 | WHERE id = {?} AND asso_id = {?}', | |
24bcf50c | 1477 | Env::i('del'), $globals->asso('id')); |
1478 | } | |
b58e5ac2 | 1479 | $res = XDB::iterator('SELECT id, titre, expiration, expiration < CURRENT_DATE() AS perime |
14bc135e SJ |
1480 | FROM group_announces |
1481 | WHERE asso_id = {?} | |
b58e5ac2 | 1482 | ORDER BY expiration DESC', |
24bcf50c | 1483 | $globals->asso('id')); |
1484 | $page->assign('articles', $res); | |
1485 | } | |
ae7bb180 | 1486 | } |
1487 | ||
a7de4ef7 | 1488 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: |
ae7bb180 | 1489 | ?> |