2 /***************************************************************************
3 * Copyright (C) 2003-2009 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 // {{{ function get_event_detail()
24 function get_event_detail($eid, $item_id = false
, $asso_id = null
)
27 if (is_null($asso_id)) {
28 $asso_id = $globals->asso('id');
30 $res = XDB
::query('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*,
31 IF(e.deadline_inscription,
32 e.deadline_inscription >= LEFT(NOW(), 10),
34 LEFT(10, e.debut) AS start_day, LEFT(10, e.fin) AS last_day,
35 LEFT(NOW(), 10) AS now,
36 ei.titre, al.vid AS absent_list, pl.vid AS participant_list
37 FROM groupex.evenements AS e
38 INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid)
39 LEFT JOIN groupex.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
40 LEFT JOIN virtual AS al ON(al.type = \'evt\' AND al.alias = CONCAT(short_name, {?}))
41 LEFT JOIN virtual AS pl ON(pl.type = \'evt\' AND pl.alias = CONCAT(short_name, {?}))
42 WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?}
44 '-absents@'.$globals->xnet
->evts_domain
,
45 '-participants@'.$globals->xnet
->evts_domain
,
46 $eid, $eid, $item_id ?
$item_id : 1, $asso_id);
47 $evt = $res->fetchOneAssoc();
52 if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) {
56 // smart calculation of the total number
58 $res = XDB
::query('SELECT MAX(nb)
59 FROM groupex.evenements AS e
60 INNER JOIN groupex.evenements_items AS ei ON (e.eid = ei.eid)
61 LEFT JOIN groupex.evenements_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
63 GROUP BY ep.uid', $evt['eid']);
64 $evt['nb_tot'] = array_sum($res->fetchColumn());
69 $evt['moments'] = XDB
::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb,
70 ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
71 FROM groupex.evenements_items AS ei
72 LEFT JOIN groupex.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id
75 S
::i('uid'), $evt['eid']);
78 $evt['notify_payment'] = false
;
79 foreach ($evt['moments'] as $m) {
80 $evt['topay'] +
= $m['nb'] * $m['montant'];
84 $evt['paid'] = $m['paid'];
85 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
88 $montants = XDB
::fetchColumn('SELECT montant
89 FROM ' . $globals->money
->mpay_tprefix
. 'transactions AS t
90 WHERE ref = {?} AND uid = {?}',
91 $evt['paiement_id'], S
::v('uid'));
93 foreach ($montants as $m) {
94 $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
95 $evt['paid'] +
= trim($p);
96 $evt['telepaid'] +
= trim($p);
99 make_event_date($evt);
106 // {{{ function get_event_participants()
107 function get_event_participants(&$evt, $item_id, array $tri = array(), $count = null
, $offset = null
)
112 $money = $evt['money'] && (function_exists('may_update')) && may_update();
113 $pay_id = $evt['paiement_id'];
115 $append = $item_id ? XDB
::foramt(' AND ep.item_id = {?}', $item_id) : '';
116 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
117 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
118 FROM groupex.evenements_participants AS ep
119 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
120 GROUP BY ep.uid', $eid);
121 $uf = new UserFilter(new UFC_True(), $tri);
122 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), $count, $offset));
124 foreach ($users as $user) {
126 $tab[$uid] = $query[$uid];
127 $tab[$uid]['user'] = $user;
134 $evt['adminpaid'] = 0;
135 $evt['telepaid'] = 0;
138 foreach ($tab as $uid=>&$u) {
139 $u['adminpaid'] = $u['paid'];
141 if ($money && $pay_id) {
142 $montants = XDB
::fetchColumn('SELECT montant
143 FROM ' . $globals->money
->mpay_tprefix
. 'transactions AS t
144 WHERE ref = {?} AND uid = {?}',
146 foreach ($montants as $m) {
147 $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
148 $u['paid'] +
= trim($p);
151 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
152 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
153 FROM groupex.evenements_participants AS ep
154 INNER JOIN groupex.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
155 WHERE ep.eid = {?} AND ep.uid = {?}',
157 while ($i = $res_->next()) {
158 $u[$i['item_id']] = $i['nb'];
159 $u['montant'] +
= $i['montant']*$i['nb'];
161 $evt['telepaid'] +
= $u['telepayment'];
162 $evt['adminpaid'] +
= $u['adminpaid'];
163 $evt['paid'] +
= $u['paid'];
164 $evt['topay'] +
= $u['montant'];
170 // {{{ function subscribe_lists_event()
171 function subscribe_lists_event($participate, $uid, $evt)
174 $page =& Platal
::page();
176 $participant_list = $evt['participant_list'];
177 $absent_list = $evt['absent_list'];
179 $user = User
::getSilent($uid);
181 $email = $user->forlifeEmail();
183 $res = XDB
::query("SELECT email
185 WHERE uid = {?} AND asso_id = {?}",
186 $uid, $globals->asso('id'));
187 $email = $res->fetchOneCell();
190 function subscribe($list, $email)
192 if ($list && $email) {
193 XDB
::execute("REPLACE INTO virtual_redirect
199 function unsubscribe($list, $email)
201 if ($list && $email) {
202 XDB
::execute("DELETE FROM virtual_redirect
203 WHERE vid = {?} AND redirect = {?}",
208 if (is_null($participate)) {
209 unsubscribe($participant_list, $email);
210 subscribe($absent_list, $email);
211 } elseif ($participate) {
212 subscribe($participant_list, $email);
213 unsubscribe($absent_list, $email);
215 unsubscribe($participant_list, $email);
216 unsubscribe($absent_list, $email);
221 // {{{ function event_change_shortname()
222 function event_change_shortname(&$page, $eid, $old, $new)
229 // Quelques vérifications sur l'alias (caractères spéciaux)
230 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
231 $page->trigError("Le raccourci demandé n'est pas valide.
232 Vérifie qu'il comporte entre 3 et 20 caractères
233 et qu'il ne contient que des lettres non accentuées,
234 des chiffres ou les caractères - et .");
236 } elseif ($new && ctype_digit($new)) {
237 $page->trigError("Le raccourci demandé ne peut être accepté car il
238 ne contient que des chiffres. Rajoute-lui par exemple
243 //vérifier que l'alias n'est pas déja pris
244 if ($new && $old != $new) {
245 $res = XDB
::query('SELECT COUNT(*)
246 FROM groupex.evenements
247 WHERE short_name = {?}',
249 if ($res->fetchOneCell() > 0) {
250 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
260 // if had a previous shortname change the old lists
261 foreach (array('-absents@', '-participants@') as $v) {
262 $v .= $globals->xnet
->evts_domain
;
263 XDB
::execute("UPDATE virtual SET alias = {?}
264 WHERE type = 'evt' AND alias = {?}",
271 // if we have a first new short_name create the lists
273 XDB
::execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
274 $new.'-participants@'.$globals->xnet
->evts_domain
);
276 $lastid = XDB
::insertId();
277 XDB
::execute('INSERT IGNORE INTO virtual_redirect (
278 SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
279 FROM groupex.evenements_participants AS ep
280 LEFT JOIN accounts AS a ON (ep.uid = a.uid)
281 LEFT JOIN aliases AS al ON (al.id = a.uid AND al.type = \'a_vie\')
282 WHERE ep.eid = {?} AND ep.nb > 0
284 $lastid, '@'.$globals->mail
->domain
, $eid);
286 XDB
::execute("INSERT INTO virtual SET type = 'evt', alias = {?}",
287 $new.'-absents@'.$globals->xnet
->evts_domain
);
289 $lastid = XDB
::insertId();
290 XDB
::execute("INSERT IGNORE INTO virtual_redirect (
291 SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
292 FROM groupex.membres AS m
293 LEFT JOIN groupex.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
294 LEFT JOIN accounts AS a ON (a.uid = m.uid)
295 LEFT JOIN aliases AS al ON (al.id = a.uid AND al.type = 'a_vie')
296 WHERE m.asso_id = {?} AND ep.uid IS NULL
298 $lastid, "@".$globals->mail
->domain
, $eid, $globals->asso('id'));
304 // if we delete the old short name, delete the lists
305 foreach (array('-absents@', '-participants@') as $v) {
306 $v .= $globals->xnet
->evts_domain
;
307 XDB
::execute("DELETE virtual, virtual_redirect FROM virtual
308 LEFT JOIN virtual_redirect USING(vid)
309 WHERE virtual.alias = {?}",
310 $infos['short_name'].$v);
320 // {{{ function make_event_date()
321 function make_event_date(&$e)
323 $start = strtotime($e['debut']);
324 $end = strtotime($e['fin']);
325 $first_day = @strtotime
($e['first_day']);
326 $last_day = strtotime($e['last_day']);
327 unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
330 if ($start && $end != $start) {
331 if ($first_day == $last_day) {
332 $date .= "le " . strftime("%d %B %Y", $start) . " de "
333 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
335 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
336 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
339 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
345 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: