0337d704 |
1 | <?php |
2 | require 'xnet.inc.php'; |
258b9710 |
3 | // vim:set et sw=4 sts=4 sws=4 foldmethod=marker: |
4 | /*************************************************************************** |
5 | * Copyright (C) 2003-2004 Polytechnique.org * |
6 | * http://opensource.polytechnique.org/ * |
7 | * * |
8 | * This program is free software; you can redistribute it and/or modify * |
9 | * it under the terms of the GNU General Public License as published by * |
10 | * the Free Software Foundation; either version 2 of the License, or * |
11 | * (at your option) any later version. * |
12 | * * |
13 | * This program is distributed in the hope that it will be useful, * |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 | * GNU General Public License for more details. * |
17 | * * |
18 | * You should have received a copy of the GNU General Public License * |
19 | * along with this program; if not, write to the Free Software * |
20 | * Foundation, Inc., * |
21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
22 | ***************************************************************************/ |
0337d704 |
23 | |
24 | new_group_page('xnet/groupe/evenements.tpl'); |
25 | |
258b9710 |
26 | /**** manage inscriptions ****/ |
27 | // inscription to events |
28 | if (Env::has('ins')) { |
29 | for ($i=1; Env::has('evt_'.$i); $i++) |
30 | { |
31 | $eid = Env::get('evt_'.$i); |
32 | $res = $globals->xdb->query(" |
33 | SELECT deadline_inscription, |
34 | LEFT(NOW(), 10) AS now, |
35 | membres_only |
36 | FROM groupex.evenements |
37 | WHERE eid = {?}", $eid); |
38 | $e = $res->fetchOneAssoc(); |
39 | // impossible to change inscription: either inscription closed or members only |
40 | if ($e['deadline_inscription'] && $e['deadline_inscription']<$e['now']) |
41 | { |
42 | $page->trig("Les inscriptions sont closes"); |
43 | continue; |
44 | } |
45 | |
46 | if ($e['membres_only'] && !is_member()) |
47 | { |
48 | $page->trig("Les inscriptions à cet événement ne sont pas publiques"); |
49 | continue; |
50 | } |
51 | |
52 | // impossible to unsubscribe if you already paid sthing |
53 | $total_inscr = 0; |
54 | $inscriptions = array(); |
82ab5344 |
55 | for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++) |
258b9710 |
56 | { |
82ab5344 |
57 | $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j); |
258b9710 |
58 | // retreive ohter field when more than one person |
82ab5344 |
59 | if ($inscriptions[$j] == 2) |
60 | $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0); |
258b9710 |
61 | // avoid negative count if other field incorrect |
82ab5344 |
62 | if ($inscriptions[$j] < 0) |
63 | $inscriptions[$j] = 0; |
258b9710 |
64 | // avoid floating count if other field incorrect |
82ab5344 |
65 | $inscriptions[$j] = floor($inscriptions[$j]); |
66 | $total_inscr += $inscriptions[$j]; |
258b9710 |
67 | } |
68 | $unsubscribing = ($total_inscr == 0); |
69 | |
70 | // retreive the amount already paid for this event in cash |
71 | $res = $globals->xdb->query(" |
72 | SELECT paid |
73 | FROM groupex.evenements_participants |
74 | WHERE eid = {?} AND uid = {?} |
75 | LIMIT 1", |
76 | $eid, Session::get("uid")); |
77 | $paid = $res->fetchOneCell(); |
78 | if (!$paid) $paid = 0; |
79 | |
80 | if ($unsubscribing && $paid != 0) |
81 | { |
82 | $page->trig("Impossible de te désinscrire complètement parce que tu as fait un paiement par chèque ou par liquide. Contacte un administrateur du groupe si tu es sûr de ne pas venir"); |
83 | continue; |
84 | } |
85 | |
86 | // update actual inscriptions |
82ab5344 |
87 | foreach ($inscriptions as $j=>$nb) |
258b9710 |
88 | { |
89 | if ($nb > 0) |
90 | { |
91 | $globals->xdb->execute( |
92 | "REPLACE INTO groupex.evenements_participants |
93 | VALUES ({?}, {?}, {?}, {?}, {?})", |
82ab5344 |
94 | $eid, Session::get("uid"), $j, $nb, $paid); |
258b9710 |
95 | } |
96 | else |
97 | { |
98 | $globals->xdb->execute( |
99 | "DELETE FROM groupex.evenements_participants |
100 | WHERE eid = {?} AND uid = {?} AND item_id = {?}", |
82ab5344 |
101 | $eid, Session::get("uid"), $j); |
258b9710 |
102 | } |
103 | } |
104 | } |
0337d704 |
105 | } |
106 | |
258b9710 |
107 | /**** retreive all infos about all events ****/ |
108 | $page->assign('logged', logged()); |
109 | $page->assign('admin', may_update()); |
0337d704 |
110 | |
258b9710 |
111 | $evenements = $globals->xdb->iterator( |
be007d27 |
112 | "SELECT e.eid, |
113 | IF(e.intitule = '', ' ', e.intitule) AS intitule, |
114 | IF(e.descriptif = '', ' ', e.descriptif) AS descriptif, |
258b9710 |
115 | e.debut, e.fin, |
116 | LEFT(10,e.debut) AS debut_day, |
117 | LEFT(10,e.fin) AS fin_day, |
118 | e.paiement_id, e.membres_only, |
119 | e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit, |
05370ed3 |
120 | MAX(ep.paid) AS paid, |
258b9710 |
121 | e.short_name, |
122 | IF(e.deadline_inscription,e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, e.deadline_inscription |
123 | FROM groupex.evenements AS e |
124 | INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid |
125 | LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) |
126 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) |
127 | WHERE asso_id = {?} |
128 | GROUP BY e.eid |
129 | ORDER BY debut",Session::get('uid'),$globals->asso('id')); |
130 | |
131 | $evts = array(); |
132 | while ($e = $evenements->next()) |
133 | { |
134 | $e['moments'] = $globals->xdb->iterator( |
135 | "SELECT titre, details, montant, ei.item_id, nb |
136 | FROM groupex.evenements_items AS ei |
137 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?}) |
138 | WHERE ei.eid = {?}", |
139 | Session::get('uid'), $e['eid']); |
05370ed3 |
140 | $query = $globals->xdb->query( |
141 | "SELECT montant |
142 | FROM {$globals->money->mpay_tprefix}transactions AS t |
143 | WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid')); |
144 | $montants = $query->fetchColumn(); |
145 | foreach ($montants as $m) { |
146 | $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); |
147 | $e['paid'] += trim($p); |
148 | } |
258b9710 |
149 | $evts[] = $e; |
0337d704 |
150 | } |
151 | |
258b9710 |
152 | $page->assign('evenements', $evts); |
153 | $page->assign('is_member', is_member()); |
0337d704 |
154 | |
258b9710 |
155 | $page->assign('nb_evt', $evenements->total()); |
0337d704 |
156 | |
157 | $page->run(); |
158 | |
159 | ?> |