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( |
27 | 'grp/events' => $this->make_hook('events', AUTH_MDP), |
28 | 'grp/events/csv' => $this->make_hook('csv', AUTH_MDP), |
29 | ); |
30 | } |
31 | |
32 | function handler_events(&$page) |
33 | { |
34 | global $globals; |
35 | |
36 | new_group_page('xnet/groupe/evenements.tpl'); |
37 | |
38 | /**** manage inscriptions ****/ |
39 | // inscription to events |
40 | if (Env::has('ins')) { |
41 | for ($i=1; Env::has('evt_'.$i); $i++) { |
42 | $eid = Env::get('evt_'.$i); |
43 | $res = $globals->xdb->query(" |
44 | SELECT deadline_inscription, |
45 | LEFT(NOW(), 10) AS now, |
46 | noinvite, |
47 | membres_only |
48 | FROM groupex.evenements |
49 | WHERE eid = {?}", $eid); |
50 | $e = $res->fetchOneAssoc(); |
51 | // impossible to change inscription: either inscription closed or members only |
52 | if ($e['deadline_inscription'] && $e['deadline_inscription'] < $e['now']) |
53 | { |
54 | $page->trig("Les inscriptions sont closes"); |
55 | continue; |
56 | } |
57 | |
58 | if ($e['membres_only'] && !is_member()) |
59 | { |
60 | $page->trig("Les inscriptions à cet événement ne sont pas publiques"); |
61 | continue; |
62 | } |
63 | |
64 | // impossible to unsubscribe if you already paid sthing |
65 | $total_inscr = 0; |
66 | $inscriptions = array(); |
67 | for ($j=1; Env::has('moment'.$eid.'_'.$j); $j++) |
68 | { |
69 | $inscriptions[$j] = Env::get('moment'.$eid.'_'.$j); |
70 | // retreive ohter field when more than one person |
71 | if ($inscriptions[$j] == 2) |
72 | $inscriptions[$j] = 1 + Env::get('personnes'.$eid.'_'.$j,0); |
73 | // avoid negative count if other field incorrect |
74 | if ($inscriptions[$j] < 0) |
75 | $inscriptions[$j] = 0; |
76 | // avoid floating count if other field incorrect |
77 | $inscriptions[$j] = floor($inscriptions[$j]); |
78 | // avoid invite if no invite allowed |
79 | if ($inscriptions[$j] > 1 && $e['noinvite']) |
80 | $inscriptions[$j] = 1; |
81 | $total_inscr += $inscriptions[$j]; |
82 | } |
83 | $unsubscribing = ($total_inscr == 0); |
84 | |
85 | // retreive the amount already paid for this event in cash |
86 | $res = $globals->xdb->query(" |
87 | SELECT paid |
88 | FROM groupex.evenements_participants |
89 | WHERE eid = {?} AND uid = {?} |
90 | LIMIT 1", |
91 | $eid, Session::get("uid")); |
92 | $paid = $res->fetchOneCell(); |
93 | if (!$paid) $paid = 0; |
94 | |
95 | if ($unsubscribing && $paid != 0) { |
96 | $page->trig("Impossible de te désinscrire complètement ". |
97 | "parce que tu as fait un paiement par ". |
98 | "chèque ou par liquide. Contacte un ". |
99 | "administrateur du groupe si tu es sûr de ". |
100 | "ne pas venir"); |
101 | continue; |
102 | } |
103 | |
104 | // update actual inscriptions |
105 | foreach ($inscriptions as $j=>$nb) { |
106 | if ($nb > 0) { |
107 | $globals->xdb->execute( |
108 | "REPLACE INTO groupex.evenements_participants |
109 | VALUES ({?}, {?}, {?}, {?}, {?})", |
110 | $eid, Session::get("uid"), $j, $nb, $paid); |
111 | } else { |
112 | $globals->xdb->execute( |
113 | "DELETE FROM groupex.evenements_participants |
114 | WHERE eid = {?} AND uid = {?} AND item_id = {?}", |
115 | $eid, Session::get("uid"), $j); |
116 | } |
117 | } |
118 | } |
119 | } |
120 | |
121 | /**** retreive all infos about all events ****/ |
122 | $page->assign('logged', logged()); |
123 | $page->assign('admin', may_update()); |
124 | |
125 | $evenements = $globals->xdb->iterator( |
126 | "SELECT e.eid, |
127 | IF(e.intitule = '', ' ', e.intitule) AS intitule, |
128 | IF(e.descriptif = '', ' ', e.descriptif) AS descriptif, |
129 | e.debut, e.fin, |
130 | LEFT(10,e.debut) AS debut_day, |
131 | LEFT(10,e.fin) AS fin_day, |
132 | e.paiement_id, e.membres_only, e.noinvite, |
133 | e.show_participants, u.nom, u.prenom, u.promo, a.alias, MAX(ep.nb) AS inscrit, |
134 | MAX(ep.paid) AS paid, |
135 | e.short_name, |
136 | IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), |
137 | 1) AS inscr_open, e.deadline_inscription |
138 | FROM groupex.evenements AS e |
139 | INNER JOIN x4dat.auth_user_md5 AS u ON u.user_id = e.organisateur_uid |
140 | LEFT JOIN x4dat.aliases AS a ON (a.type = 'a_vie' AND a.id = u.user_id) |
141 | LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = e.eid AND ep.uid = {?}) |
142 | WHERE asso_id = {?} |
143 | GROUP BY e.eid |
144 | ORDER BY debut",Session::get('uid'),$globals->asso('id')); |
145 | |
146 | $evts = array(); |
147 | while ($e = $evenements->next()) { |
148 | $e['moments'] = $globals->xdb->iterator( |
149 | "SELECT titre, details, montant, ei.item_id, nb |
150 | FROM groupex.evenements_items AS ei |
151 | LEFT JOIN groupex.evenements_participants AS ep |
152 | ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?}) |
153 | WHERE ei.eid = {?}", |
154 | Session::get('uid'), $e['eid']); |
155 | $query = $globals->xdb->query( |
156 | "SELECT montant |
157 | FROM {$globals->money->mpay_tprefix}transactions AS t |
158 | WHERE ref = {?} AND uid = {?}", $e['paiement_id'], Session::get('uid')); |
159 | $montants = $query->fetchColumn(); |
160 | foreach ($montants as $m) { |
161 | $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", "."); |
162 | $e['paid'] += trim($p); |
163 | } |
164 | $evts[] = $e; |
165 | } |
166 | |
167 | $page->assign('evenements', $evts); |
168 | $page->assign('is_member', is_member()); |
169 | } |
170 | |
171 | function handler_csv(&$page, $eid = null, $item_id = null) |
172 | { |
173 | require_once('xnet/evenements.php'); |
174 | |
175 | $evt = get_event_detail($eid, $item_id); |
176 | if (!$evt) { |
177 | return PL_NOT_FOUND; |
178 | } |
179 | |
180 | header('Content-type: text/x-csv'); |
181 | header('Pragma: '); |
182 | header('Cache-Control: '); |
183 | |
184 | new_nonhtml_page('xnet/groupe/evt-csv.tpl'); |
185 | |
186 | $admin = may_update(); |
187 | |
188 | $tri = (Env::get('order') == 'alpha' ? 'promo, nom, prenom' : 'nom, prenom, promo'); |
189 | |
190 | if (Env::has('initiale')) { |
191 | $ini = 'AND IF(u.nom IS NULL, m.nom, |
192 | IF(u.nom_usage<>"", u.nom_usage, u.nom)) |
193 | LIKE "'.addslashes(Env::get('initiale')).'%"'; |
194 | } else { |
195 | $ini = ''; |
196 | } |
197 | |
198 | $participants = get_event_participants($eid, $item_id, $ini, $tri, "", |
199 | $evt['money'] && $admin, |
200 | $evt['paiement_id']); |
201 | |
202 | $page->assign('participants', $participants); |
203 | $page->assign('admin', $admin); |
204 | $page->assign('moments', $evt['moments']); |
205 | $page->assign('money', $evt['money']); |
206 | $page->assign('tout', !Env::get('item_id', false)); |
207 | } |
208 | } |
209 | |
210 | ?> |