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