4f10a058 |
1 | <?php |
2 | /*************************************************************************** |
3 | * Copyright (C) 2003-2006 Polytechnique.org * |
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 | |
22 | class XnetEventsModule extends PLModule |
23 | { |
24 | function handlers() |
25 | { |
26 | return array( |
bd46a8e4 |
27 | 'grp/events' => $this->make_hook('events', AUTH_MDP), |
28 | 'grp/events/csv' => $this->make_hook('csv', AUTH_MDP), |
29 | 'grp/events/edit' => $this->make_hook('edit', AUTH_MDP), |
30 | 'grp/events/admin' => $this->make_hook('admin', AUTH_MDP), |
4f10a058 |
31 | ); |
32 | } |
33 | |
34 | function handler_events(&$page) |
35 | { |
36 | global $globals; |
37 | |
38 | new_group_page('xnet/groupe/evenements.tpl'); |
39 | |
40 | /**** manage inscriptions ****/ |
41 | // inscription to events |
42 | if (Env::has('ins')) { |
43 | for ($i=1; Env::has('evt_'.$i); $i++) { |
44 | $eid = Env::get('evt_'.$i); |
45 | $res = $globals->xdb->query(" |
46 | SELECT deadline_inscription, |
47 | LEFT(NOW(), 10) AS now, |
48 | noinvite, |
49 | membres_only |
50 | FROM groupex.evenements |
51 | WHERE eid = {?}", $eid); |
52 | $e = $res->fetchOneAssoc(); |
53 | // impossible to change inscription: either inscription closed or members only |
54 | if ($e['deadline_inscription'] && $e['deadline_inscription'] < $e['now']) |
55 | { |
56 | $page->trig("Les inscriptions sont closes"); |
57 | continue; |
58 | } |
59 | |
60 | if ($e['membres_only'] && !is_member()) |
61 | { |
62 | $page->trig("Les inscriptions à cet événement ne sont pas publiques"); |
63 | continue; |
64 | } |
65 | |
66 | // impossible to unsubscribe if you already paid sthing |
67 | $total_inscr = 0; |
68 | $inscriptions = array(); |
69 | for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++) |
70 | { |
71 | $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j); |
72 | // retreive ohter field when more than one person |
73 | if ($inscriptions[$j] == 2) |
74 | $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0); |
75 | // avoid negative count if other field incorrect |
76 | if ($inscriptions[$j] < 0) |
77 | $inscriptions[$j] = 0; |
78 | // avoid floating count if other field incorrect |
79 | $inscriptions[$j] = floor($inscriptions[$j]); |
80 | // avoid invite if no invite allowed |
81 | if ($inscriptions[$j] > 1 && $e['noinvite']) |
82 | $inscriptions[$j] = 1; |
83 | $total_inscr += $inscriptions[$j]; |
84 | } |
85 | $unsubscribing = ($total_inscr == 0); |
86 | |
87 | // retreive the amount already paid for this event in cash |
88 | $res = $globals->xdb->query(" |
89 | SELECT paid |
90 | FROM groupex.evenements_participants |
91 | WHERE eid = {?} AND uid = {?} |
92 | LIMIT 1", |
93 | $eid, Session::get("uid")); |
94 | $paid = $res->fetchOneCell(); |
95 | if (!$paid) $paid = 0; |
96 | |
97 | if ($unsubscribing && $paid != 0) { |
98 | $page->trig("Impossible de te désinscrire complètement ". |
99 | "parce que tu as fait un paiement par ". |
100 | "chèque ou par liquide. Contacte un ". |
101 | "administrateur du groupe si tu es sûr de ". |
102 | "ne pas venir"); |
103 | continue; |
104 | } |
105 | |
106 | // update actual inscriptions |
107 | foreach ($inscriptions as $j=>$nb) { |
108 | if ($nb > 0) { |
109 | $globals->xdb->execute( |
110 | "REPLACE INTO groupex.evenements_participants |
111 | VALUES ({?}, {?}, {?}, {?}, {?})", |
112 | $eid, Session::get("uid"), $j, $nb, $paid); |
113 | } else { |
114 | $globals->xdb->execute( |
115 | "DELETE FROM groupex.evenements_participants |
116 | WHERE eid = {?} AND uid = {?} AND item_id = {?}", |
117 | $eid, Session::get("uid"), $j); |
118 | } |
119 | } |
120 | } |
121 | } |
122 | |
123 | /**** retreive all infos about all events ****/ |
124 | $page->assign('logged', logged()); |
125 | $page->assign('admin', may_update()); |
126 | |
127 | $evenements = $globals->xdb->iterator( |
bd46a8e4 |
128 | "SELECT e.eid, IF(e.intitule = '', ' ', e.intitule) AS intitule, |
129 | IF(e.descriptif = '', ' ', e.descriptif) AS descriptif, |
130 | e.debut, e.fin, LEFT(10,e.debut) AS debut_day, |
131 | LEFT(10,e.fin) AS fin_day, e.paiement_id, e.membres_only, |
132 | e.noinvite, e.show_participants, u.nom, u.prenom, |
133 | u.promo, a.alias, MAX(ep.nb) AS inscrit, |
134 | MAX(ep.paid) AS paid, e.short_name, |
135 | IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), |
136 | 1) AS inscr_open, e.deadline_inscription |
4f10a058 |
137 | FROM groupex.evenements AS e |
138 | INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid |
139 | LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) |
140 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) |
141 | WHERE asso_id = {?} |
142 | GROUP BY e.eid |
bd46a8e4 |
143 | ORDER BY debut", Session::get('uid'), $globals->asso('id')); |
4f10a058 |
144 | |
145 | $evts = array(); |
146 | while ($e = $evenements->next()) { |
147 | $e['moments'] = $globals->xdb->iterator( |
148 | "SELECT titre, details, montant, ei.item_id, nb |
149 | FROM groupex.evenements_items AS ei |
150 | LEFT JOIN groupex.evenements_participants AS ep |
151 | ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?}) |
152 | WHERE ei.eid = {?}", |
153 | Session::get('uid'), $e['eid']); |
154 | $query = $globals->xdb->query( |
155 | "SELECT montant |
156 | FROM {$globals->money->mpay_tprefix}transactions AS t |
157 | WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid')); |
158 | $montants = $query->fetchColumn(); |
159 | foreach ($montants as $m) { |
160 | $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); |
161 | $e['paid'] += trim($p); |
162 | } |
163 | $evts[] = $e; |
164 | } |
165 | |
166 | $page->assign('evenements', $evts); |
167 | $page->assign('is_member', is_member()); |
168 | } |
169 | |
170 | function handler_csv(&$page, $eid = null, $item_id = null) |
171 | { |
172 | require_once('xnet/evenements.php'); |
173 | |
bd46a8e4 |
174 | if (!is_numeric($item_id)) { |
175 | $item_id = null; |
176 | } |
177 | |
4f10a058 |
178 | $evt = get_event_detail($eid, $item_id); |
179 | if (!$evt) { |
180 | return PL_NOT_FOUND; |
181 | } |
182 | |
183 | header('Content-type: text/x-csv'); |
184 | header('Pragma: '); |
185 | header('Cache-Control: '); |
186 | |
187 | new_nonhtml_page('xnet/groupe/evt-csv.tpl'); |
188 | |
189 | $admin = may_update(); |
190 | |
191 | $tri = (Env::get('order') == 'alpha' ? 'promo, nom, prenom' : 'nom, prenom, promo'); |
192 | |
193 | if (Env::has('initiale')) { |
194 | $ini = 'AND IF(u.nom IS NULL, m.nom, |
195 | IF(u.nom_usage<>"", u.nom_usage, u.nom)) |
196 | LIKE "'.addslashes(Env::get('initiale')).'%"'; |
197 | } else { |
198 | $ini = ''; |
199 | } |
200 | |
201 | $participants = get_event_participants($eid, $item_id, $ini, $tri, "", |
202 | $evt['money'] && $admin, |
203 | $evt['paiement_id']); |
204 | |
205 | $page->assign('participants', $participants); |
206 | $page->assign('admin', $admin); |
207 | $page->assign('moments', $evt['moments']); |
208 | $page->assign('money', $evt['money']); |
209 | $page->assign('tout', !Env::get('item_id', false)); |
210 | } |
bd46a8e4 |
211 | |
212 | function handler_edit(&$page, $eid = null) |
213 | { |
214 | global $globals; |
215 | |
216 | new_groupadmin_page('xnet/groupe/evt-modif.tpl'); |
217 | |
218 | $page->assign('logged', logged()); |
219 | $page->assign('admin', may_update()); |
220 | |
221 | $moments = range(1, 4); |
222 | $page->assign('moments', $moments); |
223 | |
224 | if (!is_null($eid)) { |
225 | $res = $globals->xdb->query("SELECT short_name, asso_id |
226 | FROM groupex.evenements |
227 | WHERE eid = {?}", $eid); |
228 | $infos = $res->fetchOneAssoc(); |
229 | if ($infos['asso_id'] != $globals->asso('id')) { |
230 | return PL_NOT_ALLOWED; |
231 | } |
232 | } |
233 | |
234 | $get_form = true; |
235 | |
236 | if (Post::get('intitule')) { |
237 | $get_form = false; |
238 | $short_name = Env::get('short_name'); |
239 | |
240 | // Quelques vérifications sur l'alias (caractères spéciaux) |
241 | if ($short_name && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $short_name)) { |
242 | $page->trig("Le raccourci demandé n'est pas valide. |
243 | Vérifie qu'il comporte entre 3 et 20 caractères |
244 | et qu'il ne contient que des lettres non accentuées, |
245 | des chiffres ou les caractères - et ."); |
246 | $short_name = $infos['short_name']; |
247 | $get_form = true; |
248 | } |
249 | |
250 | //vérifier que l'alias n'est pas déja pris |
251 | if ($short_name && $short_name != $infos['short_name']) { |
252 | $res = $globals->xdb->query('SELECT COUNT(*) FROM virtual WHERE alias LIKE {?}', $short_name."-%"); |
253 | if ($res->fetchOneCell() > 0) { |
254 | $page->trig("Le raccourci demandé est déjà utilisé. Choisis en un autre."); |
255 | $short_name = $infos['short_name']; |
256 | $get_form = true; |
257 | } |
258 | } |
259 | |
260 | // if had a previous shortname change the old lists |
261 | if ($short_name && $infos['short_name'] && $short_name != $infos['short_name']) { |
262 | $globals->xdb->execute("UPDATE virtual |
263 | SET alias = REPLACE(alias, {?}, {?}) |
264 | WHERE type = 'evt' AND alias LIKE {?}", |
265 | $infos['short_name'], $short_name, |
266 | $infos['short_name']."-%"); |
267 | } |
268 | elseif ($short_name && !$infos['short_name']) { |
269 | // if we have a first new short_name create the lists |
270 | // |
271 | $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", |
272 | $short_name."-participants@".$globals->xnet->evts_domain); |
273 | |
274 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
275 | $globals->xdb->execute("INSERT INTO virtual_redirect ( |
276 | SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect |
277 | FROM groupex.evenements_participants AS ep |
278 | LEFT JOIN groupex.membres AS m ON (ep.uid = m.uid) |
279 | LEFT JOIN auth_user_md5 AS u ON (u.user_id = ep.uid) |
280 | LEFT JOIN aliases AS a ON (a.id = ep.uid AND a.type = 'a_vie') |
281 | WHERE ep.eid = {?} |
282 | GROUP BY ep.uid)", |
283 | $res->fetchOneCell(), "@".$globals->mail->domain, $eid); |
284 | |
285 | $globals->xdb->execute("INSERT INTO virtual SET type = 'evt', alias = {?}", |
286 | $short_name."-absents@".$globals->xnet->evts_domain); |
287 | |
288 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
289 | $globals->xdb->execute("INSERT INTO virtual_redirect ( |
290 | SELECT {?} AS vid, IF(u.nom IS NULL, m.email, CONCAT(a.alias, {?})) AS redirect |
291 | FROM groupex.membres AS m |
292 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid) |
293 | LEFT JOIN auth_user_md5 AS u ON (u.user_id = m.uid) |
294 | LEFT JOIN aliases AS a ON (a.id = m.uid AND a.type = 'a_vie') |
295 | WHERE m.asso_id = {?} AND ep.uid IS NULL |
296 | GROUP BY m.uid)", |
297 | $res->fetchOneCell(), "@".$globals->mail->domain, $globals->asso('id')); |
298 | } |
299 | elseif (!$short_name && $infos['short_name']) { |
300 | // if we delete the old short name, delete the lists |
301 | $globals->xdb->execute("DELETE virtual, virtual_redirect FROM virtual |
302 | LEFT JOIN virtual_redirect USING(vid) |
303 | WHERE virtual.alias LIKE {?}", |
304 | $infos['short_name']."-%"); |
305 | } |
306 | |
307 | $evt = array(); |
308 | $evt['eid'] = $eid; |
309 | $evt['asso_id'] = $globals->asso('id'); |
310 | $evt['organisateur_uid'] = Session::get('uid'); |
311 | $evt['intitule'] = Post::get('intitule'); |
312 | $evt['paiement_id'] = (Post::get('paiement_id')>0) ? Post::get('paiement_id') : null; |
313 | $evt['descriptif'] = Post::get('descriptif'); |
314 | $evt['debut'] = Post::get('deb_Year')."-".Post::get('deb_Month') |
315 | . "-".Post::get('deb_Day')." ".Post::get('deb_Hour') |
316 | . ":".Post::get('deb_Minute').":00"; |
317 | $evt['fin'] = Post::get('fin_Year')."-".Post::get('fin_Month') |
318 | . "-".Post::get('fin_Day')." ".Post::get('fin_Hour') |
319 | . ":".Post::get('fin_Minute').":00"; |
320 | $evt['membres_only'] = Post::get('membres_only'); |
321 | $evt['advertise'] = Post::get('advertise'); |
322 | $evt['show_participants'] = Post::get('show_participants'); |
323 | $evt['noinvite'] = Post::get('noinvite'); |
324 | if (!$short_name) { |
325 | $short_name = ''; |
326 | } |
327 | $evt['short_name'] = $short_name; |
328 | $evt['deadline_inscription'] = Post::get('deadline', 'off') == 'on' ? null |
329 | : (Post::get('inscr_Year')."-".Post::get('inscr_Month') |
330 | ."-".Post::get('inscr_Day')); |
331 | |
332 | // Store the modifications in the database |
333 | $globals->xdb->execute("REPLACE INTO groupex.evenements |
334 | SET eid={?}, asso_id={?}, organisateur_uid={?}, intitule={?}, |
335 | paiement_id = {?}, descriptif = {?}, |
336 | debut = {?}, fin = {?}, |
337 | membres_only = {?}, advertise = {?}, show_participants = {?}, |
338 | short_name = {?}, deadline_inscription = {?}, noinvite = {?}", |
339 | $evt['eid'], $evt['asso_id'], $evt['organisateur_uid'], $evt['intitule'] |
340 | , $evt['paiement_id'], $evt['descriptif'], |
341 | $evt['debut'], $evt['fin'], |
342 | $evt['membres_only'], $evt['advertise'], $evt['show_participants'], |
343 | $evt['short_name'], $evt['deadline_inscription'], $evt['noinvite']); |
344 | |
345 | // if new event, get its id |
346 | if (!$eid) { |
347 | $res = $globals->xdb->query("SELECT LAST_INSERT_ID()"); |
348 | $eid = $res->fetchOneCell(); |
349 | $evt['eid'] = $eid; |
350 | } |
351 | |
352 | $nb_moments = 0; |
353 | $money_defaut = 0; |
354 | |
355 | foreach ($moments as $i) { |
356 | if (Post::get('titre'.$i)) { |
357 | $nb_moments++; |
358 | if (!($money_defaut > 0)) |
359 | $money_defaut = strtr(Post::get('montant'.$i), ',', '.'); |
360 | $globals->xdb->execute(" |
361 | REPLACE INTO groupex.evenements_items |
362 | VALUES ({?}, {?}, {?}, {?}, {?})", |
363 | $eid, $i, Post::get('titre'.$i), |
364 | Post::get('details'.$i), |
365 | strtr(Post::get('montant'.$i), ',', '.')); |
366 | } else { |
367 | $globals->xdb->execute("DELETE FROM groupex.evenements_items |
368 | WHERE eid = {?} AND item_id = {?}", $eid, $i); |
369 | } |
370 | } |
371 | |
372 | // request for a new payment |
373 | if (Post::get('paiement_id') == -1 && $money_defaut >= 0) { |
374 | require_once 'validations.inc.php'; |
375 | $p = new PayReq(Session::get('uid'), |
376 | Post::get('intitule')." - ".$globals->asso('nom'), |
377 | Post::get('site'), $money_defaut, |
378 | Post::get('confirmation'), 0, 999, |
379 | $globals->asso('id'), $eid); |
380 | $p->submit(); |
381 | } |
382 | |
383 | // events with no sub-event: add a sub-event with no name |
384 | if ($nb_moments == 0) { |
385 | $globals->xdb->execute("INSERT INTO groupex.evenements_items |
386 | VALUES ({?}, {?}, '', '', 0)", $eid, 1); |
387 | } |
388 | } |
389 | |
390 | if (Env::has('sup') && $eid) { |
391 | // deletes the event |
392 | $globals->xdb->execute("DELETE FROM groupex.evenements |
393 | WHERE eid = {?} AND asso_id = {?}", |
394 | $eid, $globals->asso('id')); |
395 | |
396 | // deletes the event items |
397 | $globals->xdb->execute("DELETE FROM groupex.evenements_items WHERE eid = {?}", $eid); |
398 | |
399 | // deletes the event participants |
400 | $globals->xdb->execute("DELETE FROM groupex.evenements_participants |
401 | WHERE eid = {?}", $eid); |
402 | |
403 | // deletes the event mailing aliases |
404 | if ($infos['short_name']) { |
405 | $globals->xdb->execute("DELETE FROM virtual |
406 | WHERE type = 'evt' AND alias LIKE {?}", |
407 | $infos['short_name']."-%"); |
408 | } |
409 | |
410 | // delete the requests for payments |
411 | require_once 'validations.inc.php'; |
412 | $globals->xdb->execute("DELETE FROM requests |
413 | WHERE type = 'paiements' AND data LIKE {?}", |
414 | PayReq::same_event($eid, $globals->asso('id'))); |
415 | redirect("evenements.php"); |
416 | } |
417 | |
418 | if (!$get_form) { |
419 | redirect("evenements.php"); |
420 | } |
421 | |
422 | // get a list of all the payment for this asso |
423 | $res = $globals->xdb->iterator("SELECT id, text |
424 | FROM {$globals->money->mpay_tprefix}paiements |
425 | WHERE asso_id = {?}", $globals->asso('id')); |
426 | $paiements = array(); |
427 | while ($a = $res->next()) $paiements[$a['id']] = $a['text']; { |
428 | $page->assign('paiements', $paiements); |
429 | } |
430 | |
431 | // when modifying an old event retreive the old datas |
432 | if ($eid) { |
433 | $res = $globals->xdb->query( |
434 | "SELECT eid, intitule, descriptif, debut, fin, |
435 | membres_only, advertise, show_participants, |
436 | paiement_id, short_name, deadline_inscription, |
437 | noinvite |
438 | FROM groupex.evenements |
439 | WHERE eid = {?}", $eid); |
440 | $evt = $res->fetchOneAssoc(); |
441 | // find out if there is already a request for a payment for this event |
442 | require_once 'validations.inc.php'; |
443 | $res = $globals->xdb->query("SELECT stamp FROM requests |
444 | WHERE type = 'paiements' AND data LIKE {?}", |
445 | PayReq::same_event($eid, $globals->asso('id'))); |
446 | $stamp = $res->fetchOneCell(); |
447 | if ($stamp) { |
448 | $evt['paiement_id'] = -2; |
449 | $evt['paiement_req'] = $stamp; |
450 | } |
451 | $page->assign('evt', $evt); |
452 | // get all the different moments infos |
453 | $res = $globals->xdb->iterator( |
454 | "SELECT item_id, titre, details, montant |
455 | FROM groupex.evenements_items AS ei |
456 | INNER JOIN groupex.evenements AS e ON(e.eid = ei.eid) |
457 | WHERE e.eid = {?} |
458 | ORDER BY item_id", $eid); |
459 | $items = array(); |
460 | while ($item = $res->next()) { |
461 | $items[$item['item_id']] = $item; |
462 | } |
463 | $page->assign('items', $items); |
464 | } |
465 | } |
466 | |
467 | function handler_admin(&$page, $eid = null, $item_id = null) |
468 | { |
469 | global $globals; |
470 | |
471 | define('NB_PER_PAGE', 25); |
472 | |
473 | require_once('xnet/evenements.php'); |
474 | |
475 | $evt = get_event_detail($eid, $item_id); |
476 | |
477 | // the event doesn't exist or doesn't belong to this assoif (!$evt) |
478 | if (!$evt) { |
479 | return PL_NOT_FOUND; |
480 | } |
481 | |
482 | if ($evt['show_participants']) { |
483 | new_group_page('xnet/groupe/evt-admin.tpl'); |
484 | } else { |
485 | new_groupadmin_page('xnet/groupe/evt-admin.tpl'); |
486 | } |
487 | |
488 | $admin = may_update(); |
489 | |
490 | // select a member from his mail |
491 | if ($admin && Env::get('adm') && Env::get('mail')) { |
492 | if (strpos(Env::get('mail'), '@') === false) { |
493 | $res = $globals->xdb->query( |
494 | "SELECT m.uid |
495 | FROM groupex.membres AS m |
496 | INNER JOIN aliases AS a ON (a.id = m.uid) |
497 | WHERE a.alias = {?} AND m.asso_id = {?}", |
498 | Env::get('mail'), $globals->asso('id')); |
499 | } else { |
500 | $res = $globals->xdb->query( |
501 | "SELECT m.uid |
502 | FROM groupex.membres AS m |
503 | WHERE m.email = {?} AND m.asso_id = {?}", |
504 | Env::get('mail'), $globals->asso('id')); |
505 | } |
506 | $member = $res->fetchOneCell(); |
507 | if (!$member) $page->trig("Membre introuvable"); |
508 | } |
509 | |
510 | // change the price paid by a participant |
511 | if ($admin && Env::get('adm') == 'prix' && $member) { |
512 | $globals->xdb->execute("UPDATE groupex.evenements_participants SET paid = IF(paid + {?} > 0, paid + {?}, 0) WHERE uid = {?} AND eid = {?}", |
513 | strtr(Env::get('montant'), ',', '.'), |
514 | strtr(Env::get('montant'), ',', '.'), |
515 | $member, Env::get('eid')); |
516 | } |
517 | |
518 | // change the number of personns coming with a participant |
519 | if ($admin && Env::get('adm') == 'nbs' && $member) { |
520 | $res = $globals->xdb->query("SELECT paid FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?}", $member, Env::get('eid')); |
521 | $paid = $res->fetchOneCell(); |
522 | $participate = false; |
523 | foreach ($evt['moments'] as $m) if (Env::has('nb'.$m['item_id'])) { |
524 | $nb = Env::getInt('nb'.$m['item_id'], 0); |
525 | if ($nb < 0) $nb = 0; |
526 | if ($nb) { |
527 | $participate = true; |
528 | if (!$paid) $paid = 0; |
529 | $globals->xdb->execute("REPLACE INTO groupex.evenements_participants VALUES ({?}, {?}, {?}, {?}, {?})", |
530 | Env::get('eid'), $member, $m['item_id'], $nb, $paid); |
531 | } else { |
532 | $globals->xdb->execute("DELETE FROM groupex.evenements_participants WHERE uid = {?} AND eid = {?} AND item_id = {?}", $member, Env::get('eid'), $m['item_id']); |
533 | } |
534 | } |
535 | if ($participate) { |
536 | subscribe_lists_event(true, $member, $evt['participant_list'], $evt['absent_list']); |
537 | } else { |
538 | $res = $globals->xdb->query( |
539 | "SELECT uid FROM groupex.evenements_participants |
540 | WHERE uid = {?} AND eid = {?}", $member, $eid); |
541 | $u = $res->fetchOneCell(); |
542 | subscribe_lists_event($u, $member, $evt['participant_list'], $evt['absent_list']); |
543 | } |
544 | $evt = get_event_detail($eid, $item_id); |
545 | } |
546 | |
547 | $page->assign('admin', $admin); |
548 | $page->assign('evt', $evt); |
549 | $page->assign('url_page', Env::get('PHP_SELF')."?eid=".Env::get('eid').(Env::has('item_id')?("&item_id=".Env::getInt('item_id')):'')); |
550 | $page->assign('tout', !Env::has('item_id')); |
551 | |
552 | if (count($evt['moments'])) $page->assign('moments', $evt['moments']); |
553 | $page->assign('money', $evt['money']); |
554 | |
555 | $tri = (Env::get('order') == 'alpha' ? 'promo, nom, prenom' : 'nom, prenom, promo'); |
556 | $whereitemid = Env::has('item_id')?('AND ep.item_id = '.Env::getInt('item_id', 1)):''; |
557 | $res = $globals->xdb->iterRow( |
558 | 'SELECT UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>"", u.nom_usage, u.nom)), 1, 1)), COUNT(DISTINCT ep.uid) |
559 | FROM groupex.evenements_participants AS ep |
560 | INNER JOIN groupex.evenements AS e ON (ep.eid = e.eid) |
561 | LEFT JOIN groupex.membres AS m ON ( ep.uid = m.uid AND e.asso_id = m.asso_id) |
562 | LEFT JOIN auth_user_md5 AS u ON ( u.user_id = ep.uid ) |
563 | WHERE ep.eid = {?} '.$whereitemid.' |
564 | GROUP BY UPPER(SUBSTRING(IF(u.nom IS NULL,m.nom,u.nom), 1, 1))', Env::get('eid')); |
565 | |
566 | $alphabet = array(); |
567 | $nb_tot = 0; |
568 | while (list($char, $nb) = $res->next()) { |
569 | $alphabet[ord($char)] = $char; |
570 | $nb_tot += $nb; |
571 | if (Env::has('initiale') && $char == strtoupper(Env::get('initiale'))) { |
572 | $tot = $nb; |
573 | } |
574 | } |
575 | ksort($alphabet); |
576 | $page->assign('alphabet', $alphabet); |
577 | |
578 | $ofs = Env::getInt('offset'); |
579 | $tot = Env::get('initiale') ? $tot : $nb_tot; |
580 | $nbp = intval(($tot-1)/NB_PER_PAGE); |
581 | $links = array(); |
582 | if ($ofs) { |
583 | $links['précédent'] = $ofs-1; |
584 | } |
585 | for ($i = 0; $i <= $nbp; $i++) { |
586 | $links[(string)($i+1)] = $i; |
587 | } |
588 | if ($ofs < $nbp) { |
589 | $links['suivant'] = $ofs+1; |
590 | } |
591 | if (count($links)>1) { |
592 | $page->assign('links', $links); |
593 | } |
594 | |
595 | $ini = Env::has('initiale') ? 'AND IF(u.nom IS NULL,m.nom,IF(u.nom_usage<>"", u.nom_usage, u.nom)) LIKE "'.addslashes(Env::get('initiale')).'%"' : ''; |
596 | |
597 | $participants = get_event_participants(Env::get('eid'), Env::get('item_id'), $ini, $tri, "LIMIT ".($ofs*NB_PER_PAGE).", ".NB_PER_PAGE, $evt['money'] && $admin, $evt['paiement_id']); |
598 | |
599 | if ($evt['paiement_id']) { |
600 | $res = $globals->xdb->iterator( |
601 | "SELECT IF(u.nom_usage<>'', u.nom_usage, u.nom) AS nom, u.prenom, |
602 | u.promo, a.alias AS email, t.montant |
603 | FROM {$globals->money->mpay_tprefix}transactions AS t |
604 | INNER JOIN auth_user_md5 AS u ON(t.uid = u.user_id) |
605 | INNER JOIN aliases AS a ON (a.id = t.uid AND a.type='a_vie' ) |
606 | LEFT JOIN groupex.evenements_participants AS ep ON(ep.uid = t.uid AND ep.eid = {?}) |
607 | WHERE t.ref = {?} AND ep.uid IS NULL", |
608 | $evt['eid'], $evt['paiement_id']); |
609 | $page->assign('oublis', $res->total()); |
610 | $page->assign('oubliinscription', $res); |
611 | } |
612 | |
613 | $page->assign('participants', $participants); |
614 | } |
4f10a058 |
615 | } |
616 | |
617 | ?> |