2 /***************************************************************************
3 * Copyright (C) 2003-2006 Polytechnique.org *
4 * http://opensource.polytechnique.org/ *
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. *
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. *
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 *
19 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
20 ***************************************************************************/
22 class XnetEventsModule
extends PLModule
27 'grp/events' => $this->make_hook('events', AUTH_MDP
),
28 'grp/events/csv' => $this->make_hook('csv', AUTH_MDP
),
32 function handler_events(&$page)
36 new_group_page('xnet/groupe/evenements.tpl');
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,
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'])
54 $page->trig("Les inscriptions sont closes");
58 if ($e['membres_only'] && !is_member())
60 $page->trig("Les inscriptions à cet événement ne sont pas publiques");
64 // impossible to unsubscribe if you already paid sthing
66 $inscriptions = array();
67 for ($j=1; Env
::has('moment'.$eid.'_'.$j); $j++
)
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];
83 $unsubscribing = ($total_inscr == 0);
85 // retreive the amount already paid for this event in cash
86 $res = $globals->xdb
->query("
88 FROM groupex.evenements_participants
89 WHERE eid = {?} AND uid = {?}
91 $eid, Session
::get("uid"));
92 $paid = $res->fetchOneCell();
93 if (!$paid) $paid = 0;
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 ".
104 // update actual inscriptions
105 foreach ($inscriptions as $j=>$nb) {
107 $globals->xdb
->execute(
108 "REPLACE INTO groupex.evenements_participants
109 VALUES ({?}, {?}, {?}, {?}, {?})",
110 $eid, Session
::get("uid"), $j, $nb, $paid);
112 $globals->xdb
->execute(
113 "DELETE FROM groupex.evenements_participants
114 WHERE eid = {?} AND uid = {?} AND item_id = {?}",
115 $eid, Session
::get("uid"), $j);
121 /**** retreive all infos about all events ****/
122 $page->assign('logged', logged());
123 $page->assign('admin', may_update());
125 $evenements = $globals->xdb
->iterator(
127 IF(e.intitule = '', ' ', e.intitule) AS intitule,
128 IF(e.descriptif = '', ' ', e.descriptif) AS descriptif,
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,
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 = {?})
144 ORDER BY debut",Session
::get('uid'),$globals->asso('id'));
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 = {?})
154 Session
::get('uid'), $e['eid']);
155 $query = $globals->xdb
->query(
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);
167 $page->assign('evenements', $evts);
168 $page->assign('is_member', is_member());
171 function handler_csv(&$page, $eid = null
, $item_id = null
)
173 require_once('xnet/evenements.php');
175 $evt = get_event_detail($eid, $item_id);
180 header('Content-type: text/x-csv');
182 header('Cache-Control: ');
184 new_nonhtml_page('xnet/groupe/evt-csv.tpl');
186 $admin = may_update();
188 $tri = (Env
::get('order') == 'alpha' ?
'promo, nom, prenom' : 'nom, prenom, promo');
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')).'%"';
198 $participants = get_event_participants($eid, $item_id, $ini, $tri, "",
199 $evt['money'] && $admin,
200 $evt['paiement_id']);
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
));