Commit | Line | Data |
---|---|---|
4f10a058 | 1 | <?php |
2 | /*************************************************************************** | |
c441aabe | 3 | * Copyright (C) 2003-2014 Polytechnique.org * |
4f10a058 | 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 | ||
ed21e24a | 22 | define('NB_PER_PAGE', 25); |
23 | ||
4f10a058 | 24 | class XnetEventsModule extends PLModule |
25 | { | |
26 | function handlers() | |
27 | { | |
28 | return array( | |
bfe9f4c7 SJ |
29 | '%grp/events' => $this->make_hook('events', AUTH_PASSWD, 'groups'), |
30 | '%grp/events/sub' => $this->make_hook('sub', AUTH_PASSWD, 'groups'), | |
31 | '%grp/events/csv' => $this->make_hook('csv', AUTH_PASSWD, 'groups', NO_HTTPS), | |
32 | '%grp/events/ical' => $this->make_hook('ical', AUTH_PASSWD, 'groups', NO_HTTPS), | |
33 | '%grp/events/edit' => $this->make_hook('edit', AUTH_PASSWD, 'groupadmin'), | |
34 | '%grp/events/admin' => $this->make_hook('admin', AUTH_PASSWD, 'groupmember'), | |
4f10a058 | 35 | ); |
36 | } | |
37 | ||
26ba053e | 38 | function handler_events($page, $archive = null) |
4f10a058 | 39 | { |
40 | global $globals; | |
41 | ||
1490093c | 42 | $page->changeTpl('xnetevents/index.tpl'); |
aa3ef74f AL |
43 | $this->load('xnetevents.inc.php'); |
44 | ||
f02eefd4 | 45 | $action = null; |
1490093c | 46 | $archive = ($archive == 'archive' && may_update()); |
47 | ||
2b9e5fd3 | 48 | if (Post::has('del')) { |
f02eefd4 | 49 | $action = 'del'; |
50 | $eid = Post::v('del'); | |
51 | } elseif (Post::has('archive')) { | |
52 | $action = 'archive'; | |
53 | $eid = Post::v('archive'); | |
54 | } elseif (Post::has('unarchive')) { | |
55 | $action = 'unarchive'; | |
56 | $eid = Post::v('unarchive'); | |
57 | } | |
58 | ||
59 | if (!is_null($action)) { | |
2b9e5fd3 | 60 | if (!may_update()) { |
73fdb1e8 | 61 | return PL_FORBIDDEN; |
2b9e5fd3 | 62 | } |
4fcbb455 | 63 | S::assert_xsrf_token(); |
2b9e5fd3 | 64 | |
eb41eda9 | 65 | $res = XDB::query("SELECT asso_id, short_name FROM group_events |
3cabafae | 66 | WHERE eid = {?} AND asso_id = {?}", |
67 | $eid, $globals->asso('id')); | |
2b9e5fd3 | 68 | |
69 | $tmp = $res->fetchOneRow(); | |
70 | if (!$tmp) { | |
73fdb1e8 | 71 | return PL_FORBIDDEN; |
2b9e5fd3 | 72 | } |
f02eefd4 | 73 | } |
2b9e5fd3 | 74 | |
f02eefd4 | 75 | if ($action == 'del') { |
2b9e5fd3 | 76 | // deletes the event mailing aliases |
77 | if ($tmp[1]) { | |
7852229b SJ |
78 | require_once 'emails.inc.php'; |
79 | foreach (explode(',', $globals->xnet->event_lists) as $suffix) { | |
80 | delete_list_alias($tmp[1] . $suffix, $globals->xnet->evts_domain, 'event'); | |
9ff5b337 | 81 | } |
2b9e5fd3 | 82 | } |
83 | ||
cf337669 AL |
84 | // archive le paiement associé si il existe |
85 | $pay_id = XDB::fetchOneCell("SELECT paiement_id | |
86 | FROM group_events | |
87 | WHERE eid = {?} AND asso_id = {?}", | |
88 | $eid, $globals->asso('id')); | |
89 | if (!$pay_id=='') { | |
90 | XDB::execute("UPDATE payments | |
91 | SET flags = 'old' | |
92 | WHERE id = {?}", | |
93 | $pay_id); | |
94 | } | |
2b9e5fd3 | 95 | // deletes the event items |
eb41eda9 | 96 | XDB::execute('DELETE FROM group_event_items |
9ff5b337 | 97 | WHERE eid = {?}', $eid); |
2b9e5fd3 | 98 | |
99 | // deletes the event participants | |
eb41eda9 | 100 | XDB::execute('DELETE FROM group_event_participants |
9ff5b337 | 101 | WHERE eid = {?}', $eid); |
2b9e5fd3 | 102 | |
103 | // deletes the event | |
eb41eda9 | 104 | XDB::execute('DELETE FROM group_events |
9ff5b337 SJ |
105 | WHERE eid = {?} AND asso_id = {?}', |
106 | $eid, $globals->asso('id')); | |
2b9e5fd3 | 107 | |
108 | // delete the requests for payments | |
9ff5b337 SJ |
109 | XDB::execute("DELETE FROM requests |
110 | WHERE type = 'paiements' AND data LIKE {?}", | |
111 | PayReq::same_event($eid, $globals->asso('id'))); | |
ebfdf077 | 112 | $globals->updateNbValid(); |
2b9e5fd3 | 113 | } |
114 | ||
f02eefd4 | 115 | if ($action == 'archive') { |
cf337669 AL |
116 | $pay_id = XDB::fetchOneCell("SELECT paiement_id |
117 | FROM group_events | |
118 | WHERE eid = {?} AND asso_id = {?}", | |
119 | $eid, $globals->asso('id')); | |
120 | if (!$pay_id=='') { | |
121 | XDB::execute("UPDATE payments | |
122 | SET flags = 'old' | |
123 | WHERE id = {?}", | |
124 | $pay_id); | |
125 | } | |
eb41eda9 | 126 | XDB::execute("UPDATE group_events |
f02eefd4 | 127 | SET archive = 1 |
128 | WHERE eid = {?} AND asso_id = {?}", | |
cf337669 | 129 | $eid, $globals->asso('id')); |
f02eefd4 | 130 | } |
131 | ||
132 | if ($action == 'unarchive') { | |
cf337669 AL |
133 | $pay_id = XDB::fetchOneCell("SELECT paiement_id FROM group_events |
134 | WHERE eid = {?} AND asso_id = {?}", | |
135 | $eid, $globals->asso('id')); | |
136 | if (!$pay_id=='') { | |
137 | XDB::execute("UPDATE payments | |
138 | SET flags = '' | |
139 | WHERE id = {?}", | |
140 | $pay_id); | |
141 | } | |
eb41eda9 | 142 | XDB::execute("UPDATE group_events |
f02eefd4 | 143 | SET archive = 0 |
144 | WHERE eid = {?} AND asso_id = {?}", | |
145 | $eid, $globals->asso('id')); | |
146 | } | |
ab02e9bc | 147 | |
f02eefd4 | 148 | $page->assign('archive', $archive); |
30002fc8 AL |
149 | |
150 | if (Post::has('order')) { | |
151 | $order = Post::v('order'); | |
152 | XDB::execute("UPDATE groups | |
153 | SET event_order = {?} | |
154 | WHERE id = {?}", | |
155 | $order, $globals->asso('id')); | |
30002fc8 | 156 | } |
aa3ef74f AL |
157 | $order = get_event_order($globals->asso('id')); |
158 | $evts = get_events($globals->asso('id'), $order); | |
30002fc8 | 159 | $page->assign('order', $order); |
4f10a058 | 160 | |
fbfc01a1 | 161 | $undisplayed_events = 0; |
aa3ef74f | 162 | foreach ($evts as $eid => &$e) { |
fbfc01a1 SJ |
163 | if (!is_member() && !may_update() && !$e['accept_nonmembre']) { |
164 | $undisplayed_events ++; | |
165 | continue; | |
166 | } | |
167 | ||
3cabafae | 168 | $e['show_participants'] = ($e['show_participants'] && (is_member() || may_update())); |
aa3ef74f | 169 | $e['items'] = get_event_items($eid); |
d6d580ec | 170 | $e['topay'] = 0; |
f523d1a0 | 171 | $e['paid'] = 0; |
aa3ef74f AL |
172 | $sub = get_event_subscription($eid, S::i('uid')); |
173 | if (empty($sub)) { | |
174 | $e['inscrit'] = false; | |
175 | } else { | |
176 | $e['inscrit'] = true; | |
177 | foreach ($e['items'] as $item_id => $m) { | |
178 | if (isset($sub[$item_id])) { | |
179 | $e['topay'] += $sub[$item_id]['nb'] * $m['montant']; | |
180 | $e['paid'] += $sub[$item_id]['paid']; | |
181 | } | |
182 | } | |
183 | } | |
184 | $e['sub'] = $sub; | |
185 | ||
186 | $telepaid = get_event_telepaid($eid, S::i('uid')); | |
187 | $e['paid'] += $telepaid; | |
188 | ||
189 | $e['date'] = make_event_date($e['debut'], $e['fin']); | |
190 | if ($e['deadline_inscription'] == null || strtotime($e['deadline_inscription']) >= time()) { | |
191 | $e['inscr_open'] = true; | |
192 | } else { | |
193 | $e['inscr_open'] = false; | |
d6d580ec | 194 | } |
20c5c7e6 | 195 | |
1f5b0b59 | 196 | if (Env::has('updated') && $e['eid'] == Env::i('updated')) { |
197 | $page->assign('updated', $e); | |
198 | } | |
4f10a058 | 199 | } |
ab02e9bc | 200 | |
4f10a058 | 201 | $page->assign('evenements', $evts); |
fbfc01a1 | 202 | $page->assign('undisplayed_events', $undisplayed_events); |
4f10a058 | 203 | } |
204 | ||
26ba053e | 205 | function handler_sub($page, $eid = null) |
d6d580ec | 206 | { |
460d8f55 | 207 | $this->load('xnetevents.inc.php'); |
1490093c | 208 | $page->changeTpl('xnetevents/subscribe.tpl'); |
d6d580ec | 209 | |
aa3ef74f | 210 | $evt = get_event($eid); |
df1cf596 | 211 | if (is_null($evt)) { |
d6d580ec | 212 | return PL_NOT_FOUND; |
213 | } | |
aa3ef74f AL |
214 | |
215 | global $globals; | |
216 | ||
217 | if (!$evt['inscr_open']) { | |
218 | $page->kill('Les inscriptions pour cet événement sont closes'); | |
219 | } | |
220 | if (!$evt['accept_nonmembre'] && !is_member() && !may_update()) { | |
df1cf596 FB |
221 | $url = $globals->asso('sub_url'); |
222 | if (empty($url)) { | |
223 | $url = $platal->ns . 'subscribe'; | |
224 | } | |
225 | $page->kill('Cet événement est reservé aux membres du groupe ' . $globals->asso('nom') . | |
226 | '. Pour devenir membre, rends-toi sur la page de <a href="' . $url . '">demande d\'inscripton</a>.'); | |
227 | } | |
d6d580ec | 228 | |
257ae408 SJ |
229 | $res = XDB::query("SELECT stamp |
230 | FROM requests | |
2ac0bcee | 231 | WHERE type = 'paiements' AND data LIKE {?}", |
aa3ef74f | 232 | PayReq::same_event($eid, $globals->asso('id'))); |
2ac0bcee | 233 | $page->assign('validation', $res->numRows()); |
aa3ef74f AL |
234 | |
235 | $page->assign('eid', $eid); | |
d6d580ec | 236 | $page->assign('event', $evt); |
aa3ef74f AL |
237 | |
238 | $items = get_event_items($eid); | |
239 | $subs = get_event_subscription($eid, S::v('uid')); | |
240 | var_dump($subs); | |
241 | // count what the user must pay | |
242 | $topay = 0; | |
243 | foreach ($items as $item_id => $item) { | |
244 | if (array_key_exists($item_id, $subs)) { | |
245 | $topay += $item['montant']*$subs[$item_id]['nb']; | |
246 | } | |
247 | } | |
248 | $page->assign('moments', $items); | |
249 | $page->assign('subs', $subs); | |
250 | $page->assign('topay', $topay); | |
251 | $page->assign('telepaid', get_event_telepaid($eid, S::v('uid'))); | |
d6d580ec | 252 | |
253 | if (!Post::has('submit')) { | |
254 | return; | |
4fcbb455 VZ |
255 | } else { |
256 | S::assert_xsrf_token(); | |
d6d580ec | 257 | } |
258 | ||
5e2307dc | 259 | $moments = Post::v('moment', array()); |
260 | $pers = Post::v('personnes', array()); | |
d6d580ec | 261 | $subs = array(); |
262 | ||
263 | foreach ($moments as $j => $v) { | |
264 | $subs[$j] = intval($v); | |
265 | ||
427ef707 | 266 | // retrieve other field when more than one person |
d6d580ec | 267 | if ($subs[$j] == 2) { |
e0422197 | 268 | if (!isset($pers[$j]) || !is_numeric($pers[$j]) || $pers[$j] < 0) { |
6bb2f79a | 269 | $page->trigError("Tu dois choisir un nombre d'invités correct !"); |
d6d580ec | 270 | return; |
271 | } | |
5dcca1b1 | 272 | $subs[$j] = $pers[$j]; |
d6d580ec | 273 | } |
274 | } | |
275 | ||
276 | // impossible to unsubscribe if you already paid sthing | |
98a7e9dc | 277 | if (!array_sum($subs) && $evt['paid'] != 0) { |
9ff5b337 SJ |
278 | $page->trigError("Impossible de te désinscrire complètement " . |
279 | "parce que tu as fait un paiement par " . | |
280 | "chèque ou par liquide. Contacte un " . | |
281 | "administrateur du groupe si tu es sûr de " . | |
282 | "ne pas venir."); | |
d6d580ec | 283 | return; |
284 | } | |
285 | ||
286 | // update actual inscriptions | |
aa3ef74f AL |
287 | $updated = subscribe(S::v('uid'), $eid, $subs); |
288 | /* foreach ($subs as $j => $nb) { | |
9193e8f7 | 289 | if ($nb >= 0) { |
e0422197 SJ |
290 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
291 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}) | |
00ba8a74 SJ |
292 | ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', |
293 | $eid, S::v('uid'), $j, $nb, (Env::has('notify_payment') ? 'notify_payment' : ''), | |
7c5d90fb | 294 | ((!$paid_inserted) ? $paid - $telepaid : 0)); |
1f5b0b59 | 295 | $updated = $eid; |
7c5d90fb | 296 | $paid_inserted = true; |
d6d580ec | 297 | } else { |
08cce2ff | 298 | XDB::execute( |
eb41eda9 | 299 | "DELETE FROM group_event_participants |
d6d580ec | 300 | WHERE eid = {?} AND uid = {?} AND item_id = {?}", |
2847640f | 301 | $eid, S::v("uid"), $j); |
1f5b0b59 | 302 | $updated = $eid; |
d6d580ec | 303 | } |
9193e8f7 | 304 | $total += $nb; |
aa3ef74f AL |
305 | } |
306 | */ | |
307 | if ($updated) { | |
427ef707 AL |
308 | $evt = get_event_detail($eid); |
309 | if ($evt['topay'] > 0) { | |
310 | $page->trigSuccess('Ton inscription à l\'événement a été mise à jour avec succès, tu peux payer ta participation en cliquant ci-dessous'); | |
311 | } else { | |
312 | $page->trigSuccess('Ton inscription à l\'événement a été mise à jour avec succès.'); | |
313 | } | |
57cc5e63 | 314 | |
96074354 SJ |
315 | if ($evt['subscription_notification'] != 'nobody') { |
316 | $mailer = new PlMailer('xnetevents/subscription-notif.mail.tpl'); | |
317 | if ($evt['subscription_notification'] != 'creator') { | |
318 | $admins = $globals->asso()->iterAdmins(); | |
319 | while ($admin = $admins->next()) { | |
320 | $mailer->addTo($admin); | |
321 | } | |
322 | } | |
323 | if ($evt['subscription_notification'] != 'animator') { | |
324 | $mailer->addTo($evt['organizer']); | |
325 | } | |
326 | $mailer->assign('group', $globals->asso('nom')); | |
327 | $mailer->assign('event', $evt['intitule']); | |
328 | $mailer->assign('subs', $subs); | |
329 | $mailer->assign('moments', $evt['moments']); | |
330 | $mailer->assign('name', S::user()->fullName('promo')); | |
331 | $mailer->send(); | |
57cc5e63 | 332 | } |
1f5b0b59 | 333 | } |
d6d580ec | 334 | $page->assign('event', get_event_detail($eid)); |
335 | } | |
336 | ||
26ba053e | 337 | function handler_csv($page, $eid = null, $item_id = null) |
4f10a058 | 338 | { |
460d8f55 | 339 | $this->load('xnetevents.inc.php'); |
4f10a058 | 340 | |
bd46a8e4 | 341 | if (!is_numeric($item_id)) { |
342 | $item_id = null; | |
343 | } | |
344 | ||
4f10a058 | 345 | $evt = get_event_detail($eid, $item_id); |
346 | if (!$evt) { | |
347 | return PL_NOT_FOUND; | |
348 | } | |
349 | ||
ee923b43 | 350 | pl_cached_content_headers('text/x-csv', 'iso-8859-1', 1); |
801fcad8 | 351 | $page->changeTpl('xnetevents/csv.tpl', NO_SKIN); |
4f10a058 | 352 | |
353 | $admin = may_update(); | |
07eb5b0e | 354 | $tri = (Env::v('order') == 'alpha' ? UserFilter::sortByPromo() : UserFilter::sortByName()); |
ee923b43 | 355 | $all = !Env::v('item_id', false); |
4f10a058 | 356 | |
ee923b43 | 357 | $participants = get_event_participants($evt, $item_id, $tri); |
a507867b | 358 | $title = 'Nom;Prénom;Promotion;Email'; |
5dcca1b1 AL |
359 | if ($admin) { |
360 | $title .=';Société;Poste'; | |
361 | } | |
ee923b43 SJ |
362 | if ($all) { |
363 | foreach ($evt['moments'] as $moment) { | |
364 | $title .= ';' . $moment['titre']; | |
365 | } | |
366 | } | |
367 | if ($admin && $evt['money']) { | |
368 | $title .= ';À payer;'; | |
369 | if ($evt['paiement_id']) { | |
370 | $title .= 'Télépaiement;Liquide/Chèque;'; | |
371 | } | |
372 | $title .= 'Payé'; | |
373 | } else { | |
374 | $title .= ';Nombre'; | |
5dcca1b1 | 375 | } |
ee923b43 SJ |
376 | echo utf8_decode($title) . "\n"; |
377 | ||
378 | if ($participants) { | |
379 | foreach ($participants as $participant) { | |
380 | $user = $participant['user']; | |
a507867b | 381 | $line = $user->lastName() . ';' . $user->firstName() . ';' . $user->promo() . ';' . $user->bestEmail(); |
5dcca1b1 AL |
382 | if ($admin && $user->hasProfile()) { |
383 | $line .= ';' . $user->profile()->getMainJob()->company->name . ';' . $user->profile()->getMainJob()->description; | |
384 | } else { | |
385 | $line .= ';;'; | |
386 | } | |
ee923b43 SJ |
387 | if ($all) { |
388 | foreach ($evt['moments'] as $moment) { | |
389 | $line .= ';' . $participant[$moment['item_id']]; | |
390 | } | |
391 | } | |
392 | if ($admin && $evt['money']) { | |
393 | $line .= ';' . $participant['montant'] . ';'; | |
394 | if ($evt['paiement_id']) { | |
395 | $line .= $participant['telepayment'] . ';' . $participant['adminpaid'] . ';'; | |
396 | } | |
397 | $line .= $participant['paid']; | |
398 | } else { | |
399 | $line .= ';' . $participant['nb']; | |
400 | } | |
4f10a058 | 401 | |
ee923b43 SJ |
402 | echo utf8_decode($line) . "\n"; |
403 | } | |
404 | } | |
405 | exit(); | |
4f10a058 | 406 | } |
bd46a8e4 | 407 | |
26ba053e | 408 | function handler_ical($page, $eid = null) |
11d8a183 | 409 | { |
410 | global $globals; | |
411 | ||
460d8f55 | 412 | $this->load('xnetevents.inc.php'); |
11d8a183 | 413 | $evt = get_event_detail($eid); |
414 | if (!$evt) { | |
73fdb1e8 | 415 | return PL_FORBIDDEN; |
11d8a183 | 416 | } |
417 | $evt['debut'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['debut']); | |
418 | $evt['fin'] = preg_replace('/(\d+)-(\d+)-(\d+) (\d+):(\d+):(\d+)/', "\\1\\2\\3T\\4\\5\\6", $evt['fin']); | |
419 | ||
99544d53 | 420 | foreach ($evt['moments'] as $m) { |
421 | $evt['descriptif'] .= "\n\n** " . $m['titre'] . " **\n" . $m['details']; | |
422 | } | |
423 | ||
11d8a183 | 424 | $page->changeTpl('xnetevents/calendar.tpl', NO_SKIN); |
425 | ||
99544d53 | 426 | require_once('ical.inc.php'); |
11d8a183 | 427 | $page->assign('asso', $globals->asso()); |
428 | $page->assign('timestamp', time()); | |
99544d53 | 429 | $page->assign('admin', may_update()); |
430 | ||
431 | if (may_update()) { | |
07eb5b0e | 432 | $page->assign('participants', get_event_participants($evt, null, UserFilter::sortByPromo())); |
99544d53 | 433 | } |
11d8a183 | 434 | $page->register_function('display_ical', 'display_ical'); |
435 | $page->assign_by_ref('e', $evt); | |
ab02e9bc | 436 | |
3cb500d5 | 437 | pl_content_headers("text/calendar"); |
11d8a183 | 438 | } |
439 | ||
26ba053e | 440 | function handler_edit($page, $eid = null) |
bd46a8e4 | 441 | { |
442 | global $globals; | |
443 | ||
5cbb1fad | 444 | // get eid if the the given one is a short name |
445 | if (!is_null($eid) && !is_numeric($eid)) { | |
446 | $res = XDB::query("SELECT eid | |
eb41eda9 | 447 | FROM group_events |
5cbb1fad | 448 | WHERE asso_id = {?} AND short_name = {?}", |
449 | $globals->asso('id'), $eid); | |
450 | if ($res->numRows()) { | |
451 | $eid = (int)$res->fetchOneCell(); | |
452 | } | |
453 | } | |
454 | ||
5070a22d | 455 | // check the event is in our group |
bd46a8e4 | 456 | if (!is_null($eid)) { |
73fdb1e8 | 457 | $res = XDB::query("SELECT short_name |
eb41eda9 | 458 | FROM group_events |
73fdb1e8 | 459 | WHERE eid = {?} AND asso_id = {?}", |
460 | $eid, $globals->asso('id')); | |
461 | if ($res->numRows()) { | |
462 | $infos = $res->fetchOneAssoc(); | |
463 | } else { | |
464 | return PL_FORBIDDEN; | |
bd46a8e4 | 465 | } |
466 | } | |
467 | ||
1490093c | 468 | $page->changeTpl('xnetevents/edit.tpl'); |
bd46a8e4 | 469 | |
58d0edab | 470 | $moments = range(1, 4); |
f56e5e53 | 471 | $error = false; |
5070a22d | 472 | $page->assign('moments', $moments); |
bd46a8e4 | 473 | |
5e2307dc | 474 | if (Post::v('intitule')) { |
4fcbb455 VZ |
475 | S::assert_xsrf_token(); |
476 | ||
460d8f55 | 477 | $this->load('xnetevents.inc.php'); |
2847640f VZ |
478 | $short_name = event_change_shortname($page, $eid, |
479 | $infos['short_name'], | |
5e2307dc | 480 | Env::v('short_name', '')); |
f56e5e53 | 481 | if ($short_name != Env::v('short_name')) { |
482 | $error = true; | |
483 | } | |
5070a22d | 484 | $evt = array( |
485 | 'eid' => $eid, | |
486 | 'asso_id' => $globals->asso('id'), | |
5e2307dc | 487 | 'paiement_id' => Post::v('paiement_id') > 0 ? Post::v('paiement_id') : null, |
488 | 'debut' => Post::v('deb_Year').'-'.Post::v('deb_Month') | |
489 | .'-'.Post::v('deb_Day').' '.Post::v('deb_Hour') | |
490 | .':'.Post::v('deb_Minute').':00', | |
491 | 'fin' => Post::v('fin_Year').'-'.Post::v('fin_Month') | |
492 | .'-'.Post::v('fin_Day').' '.Post::v('fin_Hour') | |
493 | .':'.Post::v('fin_Minute').':00', | |
f56e5e53 | 494 | 'short_name' => $short_name, |
5070a22d | 495 | ); |
496 | ||
96074354 | 497 | $trivial = array('intitule', 'descriptif', 'noinvite', 'subscription_notification', |
7f376ae0 | 498 | 'show_participants', 'accept_nonmembre', 'uid'); |
5070a22d | 499 | foreach ($trivial as $k) { |
5e2307dc | 500 | $evt[$k] = Post::v($k); |
bd46a8e4 | 501 | } |
25412aa4 | 502 | if (!$eid) { |
7f376ae0 | 503 | $evt['uid'] = S::v('uid'); |
25412aa4 | 504 | } |
bd46a8e4 | 505 | |
5e2307dc | 506 | if (Post::v('deadline')) { |
507 | $evt['deadline_inscription'] = Post::v('inscr_Year').'-' | |
508 | . Post::v('inscr_Month').'-' | |
509 | . Post::v('inscr_Day'); | |
5070a22d | 510 | } else { |
511 | $evt['deadline_inscription'] = null; | |
9ece1588 | 512 | } |
bd46a8e4 | 513 | |
514 | // Store the modifications in the database | |
e0422197 SJ |
515 | XDB::execute('INSERT INTO group_events (eid, asso_id, uid, intitule, paiement_id, |
516 | descriptif, debut, fin, show_participants, | |
517 | short_name, deadline_inscription, noinvite, | |
96074354 SJ |
518 | accept_nonmembre, subscription_notification) |
519 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}, {?}) | |
00ba8a74 SJ |
520 | ON DUPLICATE KEY UPDATE asso_id = VALUES(asso_id), uid = VALUES(uid), intitule = VALUES(intitule), |
521 | paiement_id = VALUES(paiement_id), descriptif = VALUES(descriptif), debut = VALUES(debut), | |
522 | fin = VALUES(fin), show_participants = VALUES(show_participants), short_name = VALUES(short_name), | |
d7a53199 | 523 | deadline_inscription = VALUES(deadline_inscription), noinvite = VALUES(noinvite), |
96074354 | 524 | accept_nonmembre = VALUES(accept_nonmembre), subscription_notification = VALUES(subscription_notification)', |
7f376ae0 SJ |
525 | $evt['eid'], $evt['asso_id'], $evt['uid'], |
526 | $evt['intitule'], $evt['paiement_id'], $evt['descriptif'], | |
527 | $evt['debut'], $evt['fin'], $evt['show_participants'], | |
528 | $evt['short_name'], $evt['deadline_inscription'], | |
96074354 | 529 | $evt['noinvite'], $evt['accept_nonmembre'], $evt['subscription_notification']); |
bd46a8e4 | 530 | |
531 | // if new event, get its id | |
532 | if (!$eid) { | |
8b83a166 | 533 | $eid = XDB::insertId(); |
bd46a8e4 | 534 | } |
535 | ||
bd46a8e4 | 536 | foreach ($moments as $i) { |
e0422197 | 537 | if (Post::v('titre' . $i)) { |
bd46a8e4 | 538 | $nb_moments++; |
5070a22d | 539 | |
e0422197 | 540 | $montant = strtr(Post::v('montant' . $i), ',', '.'); |
5070a22d | 541 | $money_defaut += (float)$montant; |
e0422197 SJ |
542 | XDB::execute('INSERT INTO group_event_items (eid, item_id, titre, details, montant) |
543 | VALUES ({?}, {?}, {?}, {?}, {?}) | |
00ba8a74 SJ |
544 | ON DUPLICATE KEY UPDATE titre = VALUES(titre), details = VALUES(details), montant = VALUES(montant)', |
545 | $eid, $i, Post::v('titre' . $i), Post::v('details' . $i), $montant); | |
bd46a8e4 | 546 | } else { |
e0422197 SJ |
547 | XDB::execute('DELETE FROM group_event_items |
548 | WHERE eid = {?} AND item_id = {?}', $eid, $i); | |
bd46a8e4 | 549 | } |
550 | } | |
bd46a8e4 | 551 | // request for a new payment |
5e2307dc | 552 | if (Post::v('paiement_id') == -1 && $money_defaut >= 0) { |
5daf68f6 | 553 | $p = new PayReq(S::user(), |
5dcca1b1 | 554 | $globals->asso('nom')." - ".Post::v('intitule'), |
5e2307dc | 555 | Post::v('site'), $money_defaut, |
556 | Post::v('confirmation'), 0, 999, | |
0a9d877e | 557 | $globals->asso('id'), $eid, Post::v('payment_public') == 'yes'); |
20934085 | 558 | if ($p->accept()) { |
559 | $p->submit(); | |
560 | } else { | |
dd4f932d SJ |
561 | $page->assign('payment_message', Post::v('confirmation')); |
562 | $page->assign('payment_site', Post::v('site')); | |
563 | $page->assign('payment_public', Post::v('payment_public') == 'yes'); | |
564 | $page->assign('error', true); | |
20934085 | 565 | $error = true; |
566 | } | |
bd46a8e4 | 567 | } |
568 | ||
d9687e80 | 569 | // events with no sub-event: add a sub-event with default name |
bd46a8e4 | 570 | if ($nb_moments == 0) { |
eb41eda9 | 571 | XDB::execute("INSERT INTO group_event_items |
d9687e80 | 572 | VALUES ({?}, {?}, 'Événement', '', 0)", $eid, 1); |
bd46a8e4 | 573 | } |
bd46a8e4 | 574 | |
f56e5e53 | 575 | if (!$error) { |
58d0edab | 576 | pl_redirect('events'); |
577 | } | |
bd46a8e4 | 578 | } |
579 | ||
580 | // get a list of all the payment for this asso | |
c54b27c7 SJ |
581 | $res = XDB::iterator("SELECT id, text |
582 | FROM payments | |
583 | WHERE asso_id = {?} AND NOT FIND_IN_SET('old', flags)", | |
584 | $globals->asso('id')); | |
bd46a8e4 | 585 | $paiements = array(); |
586 | while ($a = $res->next()) $paiements[$a['id']] = $a['text']; { | |
587 | $page->assign('paiements', $paiements); | |
588 | } | |
589 | ||
590 | // when modifying an old event retreive the old datas | |
591 | if ($eid) { | |
08cce2ff | 592 | $res = XDB::query( |
7f376ae0 | 593 | "SELECT eid, intitule, descriptif, debut, fin, uid, |
00112b2e | 594 | show_participants, paiement_id, short_name, |
96074354 | 595 | deadline_inscription, noinvite, accept_nonmembre, subscription_notification |
eb41eda9 | 596 | FROM group_events |
bd46a8e4 | 597 | WHERE eid = {?}", $eid); |
598 | $evt = $res->fetchOneAssoc(); | |
599 | // find out if there is already a request for a payment for this event | |
257ae408 SJ |
600 | $res = XDB::query("SELECT stamp |
601 | FROM requests | |
602 | WHERE type = 'paiements' AND data LIKE {?}", | |
dd4f932d | 603 | PayReq::same_event($eid, $globals->asso('id'))); |
bd46a8e4 | 604 | $stamp = $res->fetchOneCell(); |
605 | if ($stamp) { | |
f56e5e53 | 606 | $evt['paiement_id'] = -2; |
bd46a8e4 | 607 | $evt['paiement_req'] = $stamp; |
608 | } | |
609 | $page->assign('evt', $evt); | |
610 | // get all the different moments infos | |
08cce2ff | 611 | $res = XDB::iterator( |
00112b2e | 612 | "SELECT item_id, titre, details, montant |
eb41eda9 FB |
613 | FROM group_event_items AS ei |
614 | INNER JOIN group_events AS e ON(e.eid = ei.eid) | |
00112b2e | 615 | WHERE e.eid = {?} |
bd46a8e4 | 616 | ORDER BY item_id", $eid); |
617 | $items = array(); | |
618 | while ($item = $res->next()) { | |
619 | $items[$item['item_id']] = $item; | |
620 | } | |
621 | $page->assign('items', $items); | |
622 | } | |
5cbb1fad | 623 | $page->assign('url_ref', $eid); |
bd46a8e4 | 624 | } |
625 | ||
26ba053e | 626 | function handler_admin($page, $eid = null, $item_id = null) |
bd46a8e4 | 627 | { |
628 | global $globals; | |
629 | ||
460d8f55 | 630 | $this->load('xnetevents.inc.php'); |
bd46a8e4 | 631 | |
632 | $evt = get_event_detail($eid, $item_id); | |
bd46a8e4 | 633 | if (!$evt) { |
634 | return PL_NOT_FOUND; | |
635 | } | |
636 | ||
1490093c | 637 | $page->changeTpl('xnetevents/admin.tpl'); |
638 | if (!$evt['show_participants'] && !may_update()) { | |
639 | return PL_FORBIDDEN; | |
bd46a8e4 | 640 | } |
641 | ||
5e2307dc | 642 | if (may_update() && Post::v('adm')) { |
4fcbb455 VZ |
643 | S::assert_xsrf_token(); |
644 | ||
4bf97262 | 645 | $member = User::getSilent(Post::v('mail')); |
ed21e24a | 646 | if (!$member) { |
a7d35093 | 647 | $page->trigError("Membre introuvable"); |
bd46a8e4 | 648 | } |
bd46a8e4 | 649 | |
ed21e24a | 650 | // change the price paid by a participant |
5e2307dc | 651 | if (Env::v('adm') == 'prix' && $member) { |
50208d22 | 652 | $amount = strtr(Env::v('montant'), ',', '.'); |
eb41eda9 | 653 | XDB::execute("UPDATE group_event_participants |
d4fd2f8a | 654 | SET paid = paid + {?} |
51f1911c BG |
655 | WHERE uid = {?} AND eid = {?} AND nb > 0 |
656 | ORDER BY item_id ASC | |
657 | LIMIT 1", | |
50208d22 | 658 | $amount, $member->uid, $evt['eid']); |
7852229b | 659 | subscribe_lists_event($member->uid, $evt['short_name'], 1, $amount); |
ed21e24a | 660 | } |
bd46a8e4 | 661 | |
ed21e24a | 662 | // change the number of personns coming with a participant |
5e2307dc | 663 | if (Env::v('adm') == 'nbs' && $member) { |
2ec25d62 | 664 | $res = XDB::query("SELECT SUM(paid) |
eb41eda9 | 665 | FROM group_event_participants |
dc2073c3 | 666 | WHERE uid = {?} AND eid = {?}", |
4bf97262 | 667 | $member->uid, $evt['eid']); |
ed21e24a | 668 | |
7c5d90fb | 669 | $paid = $res->fetchOneCell(); |
1f170710 RB |
670 | |
671 | // Ensure we have an integer | |
672 | if ($paid == null) { | |
673 | $paid = 0; | |
674 | } | |
675 | ||
5e2307dc | 676 | $nbs = Post::v('nb', array()); |
ed21e24a | 677 | |
7c5d90fb | 678 | $paid_inserted = false; |
ed21e24a | 679 | foreach ($nbs as $id => $nb) { |
5070a22d | 680 | $nb = max(intval($nb), 0); |
7c5d90fb BG |
681 | if (!$paid_inserted && $nb > 0) { |
682 | $item_paid = $paid; | |
683 | $paid_inserted = true; | |
684 | } else { | |
685 | $item_paid = 0; | |
686 | } | |
e0422197 SJ |
687 | XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) |
688 | VALUES ({?}, {?}, {?}, {?}, {?}, {?}) | |
00ba8a74 | 689 | ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', |
7c5d90fb | 690 | $evt['eid'], $member->uid, $id, $nb, '', $item_paid); |
bd46a8e4 | 691 | } |
ed21e24a | 692 | |
50208d22 SJ |
693 | $res = XDB::query('SELECT COUNT(uid) AS cnt, SUM(nb) AS nb |
694 | FROM group_event_participants | |
695 | WHERE uid = {?} AND eid = {?} | |
696 | GROUP BY uid', | |
697 | $member->uid, $evt['eid']); | |
9193e8f7 | 698 | $u = $res->fetchOneAssoc(); |
2ec25d62 | 699 | if ($paid == 0 && Post::v('cancel')) { |
3bfa0e8d PC |
700 | XDB::execute("DELETE FROM group_event_participants |
701 | WHERE uid = {?} AND eid = {?}", | |
702 | $member->uid, $evt['eid']); | |
703 | $u = 0; | |
7852229b | 704 | subscribe_lists_event($member->uid, $evt['short_name'], -1, $paid); |
3bfa0e8d PC |
705 | } else { |
706 | $u = $u['cnt'] ? $u['nb'] : null; | |
7852229b | 707 | subscribe_lists_event($member->uid, $evt['short_name'], ($u > 0 ? 1 : 0), $paid); |
3bfa0e8d | 708 | } |
bd46a8e4 | 709 | } |
ed21e24a | 710 | |
bd46a8e4 | 711 | $evt = get_event_detail($eid, $item_id); |
712 | } | |
713 | ||
e01ebe65 | 714 | $page->assign_by_ref('evt', $evt); |
1f3362a3 | 715 | $page->assign('tout', is_null($item_id)); |
bd46a8e4 | 716 | |
ed21e24a | 717 | if (count($evt['moments'])) { |
718 | $page->assign('moments', $evt['moments']); | |
719 | } | |
bd46a8e4 | 720 | |
bd46a8e4 | 721 | if ($evt['paiement_id']) { |
07eb5b0e | 722 | $infos = User::getBulkUsersWithUIDs( |
b3cd1320 DB |
723 | XDB::fetchAllAssoc('SELECT t.uid, t.amount |
724 | FROM payment_transactions AS t | |
eb41eda9 | 725 | LEFT JOIN group_event_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?}) |
07eb5b0e FB |
726 | WHERE t.ref = {?} AND ep.uid IS NULL', |
727 | $evt['eid'], $evt['paiement_id']), | |
728 | 'uid', 'user'); | |
729 | $page->assign('oublis', count($infos)); | |
730 | $page->assign('oubliinscription', $infos); | |
731 | } | |
732 | ||
733 | $absents = User::getBulkUsersFromDB('SELECT p.uid | |
eb41eda9 FB |
734 | FROM group_event_participants AS p |
735 | LEFT JOIN group_event_participants AS p2 ON (p2.uid = p.uid | |
07eb5b0e FB |
736 | AND p2.eid = p.eid |
737 | AND p2.nb != 0) | |
738 | WHERE p.eid = {?} AND p2.eid IS NULL | |
739 | GROUP BY p.uid', $evt['eid']); | |
ab02e9bc | 740 | |
6601ea70 | 741 | $ofs = Env::i('offset'); |
f9e8637a FB |
742 | $part = get_event_participants($evt, $item_id, UserFilter::sortByName(), |
743 | NB_PER_PAGE, $ofs * NB_PER_PAGE); | |
744 | ||
e48b1c76 | 745 | $nbp = ceil($evt['user_count'] / NB_PER_PAGE); |
037b02c8 FB |
746 | if ($nbp > 1) { |
747 | $links = array(); | |
748 | if ($ofs) { | |
749 | $links['précédent'] = $ofs - 1; | |
750 | } | |
751 | for ($i = 1 ; $i <= $nbp; $i++) { | |
752 | $links[(string)$i] = $i - 1; | |
753 | } | |
6601ea70 | 754 | if ($ofs < $nbp - 1) { |
037b02c8 FB |
755 | $links['suivant'] = $ofs+1; |
756 | } | |
ab02e9bc | 757 | $page->assign('links', $links); |
758 | } | |
759 | ||
61664f8b | 760 | $page->assign('absents', $absents); |
f9e8637a | 761 | $page->assign('participants', $part); |
bd46a8e4 | 762 | } |
4f10a058 | 763 | } |
764 | ||
448c8cdc | 765 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: |
4f10a058 | 766 | ?> |