2 /***************************************************************************
3 * Copyright (C) 2003-2011 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 pyl.vid AS payed_list, bl.vid AS booked_unpayed_list,
38 e.subscription_notification
39 FROM group_events AS e
40 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
41 LEFT JOIN group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
42 LEFT JOIN virtual AS al ON(al.type = \'evt\' AND al.alias = CONCAT(short_name, {?}))
43 LEFT JOIN virtual AS pl ON(pl.type = \'evt\' AND pl.alias = CONCAT(short_name, {?}))
44 LEFT JOIN virtual AS pyl ON(pyl.type = \'evt\' AND pyl.alias = CONCAT(short_name, {?}))
45 LEFT JOIN virtual AS bl ON(bl.type = \'evt\' AND bl.alias = CONCAT(short_name, {?}))
46 WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?}
48 '-absents@'.$globals->xnet
->evts_domain
,
49 '-participants@'.$globals->xnet
->evts_domain
,
50 '-paye@' . $globals->xnet
->evts_domain
,
51 '-participants-non-paye@' . $globals->xnet
->evts_domain
,
52 $eid, $eid, $item_id ?
$item_id : 1, $asso_id);
53 $evt = $res->fetchOneAssoc();
58 if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) {
62 // smart calculation of the total number
64 $res = XDB
::query('SELECT MAX(nb)
65 FROM group_events AS e
66 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
67 LEFT JOIN group_event_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
69 GROUP BY ep.uid', $evt['eid']);
70 $evt['nb_tot'] = array_sum($res->fetchColumn());
75 $evt['moments'] = XDB
::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb,
76 ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
77 FROM group_event_items AS ei
78 LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id
81 S
::i('uid'), $evt['eid']);
84 $evt['notify_payment'] = false
;
85 foreach ($evt['moments'] as $m) {
86 $evt['topay'] +
= $m['nb'] * $m['montant'];
90 $evt['paid'] = $m['paid'];
91 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
94 $montants = XDB
::fetchColumn('SELECT amount
95 FROM payment_transactions AS t
96 WHERE ref = {?} AND uid = {?}',
97 $evt['paiement_id'], S
::v('uid'));
99 foreach ($montants as $m) {
100 $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
101 $evt['paid'] +
= trim($p);
102 $evt['telepaid'] +
= trim($p);
104 $evt['organizer'] = User
::getSilent($evt['uid']);
106 make_event_date($evt);
113 // {{{ function get_event_participants()
114 function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null
)
119 $money = $evt['money'] && (function_exists('may_update')) && may_update();
120 $pay_id = $evt['paiement_id'];
122 $append = $item_id ? XDB
::format(' AND ep.item_id = {?}', $item_id) : '';
123 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
124 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
125 FROM group_event_participants AS ep
126 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
127 GROUP BY ep.uid', $eid);
128 $uf = new UserFilter(new PFC_True(), $tri);
129 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($count, $offset)));
131 foreach ($users as $user) {
133 $tab[$uid] = $query[$uid];
134 $tab[$uid]['user'] = $user;
141 $evt['adminpaid'] = 0;
142 $evt['telepaid'] = 0;
145 foreach ($tab as $uid=>&$u) {
146 $u['adminpaid'] = $u['paid'];
148 if ($money && $pay_id) {
149 $montants = XDB
::fetchColumn('SELECT amount
150 FROM payment_transactions AS t
151 WHERE ref = {?} AND uid = {?}',
153 foreach ($montants as $m) {
154 $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
155 $u['paid'] +
= trim($p);
158 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
159 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
160 FROM group_event_participants AS ep
161 INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
162 WHERE ep.eid = {?} AND ep.uid = {?}',
164 while ($i = $res_->next()) {
165 $u[$i['item_id']] = $i['nb'];
166 $u['montant'] +
= $i['montant']*$i['nb'];
168 $evt['telepaid'] +
= $u['telepayment'];
169 $evt['adminpaid'] +
= $u['adminpaid'];
170 $evt['paid'] +
= $u['paid'];
171 $evt['topay'] +
= $u['montant'];
177 // {{{ function subscribe_lists_event()
178 /** Subscribes user to various event related mailing lists.
180 * @param $uid: user's id.
181 * @param evt: events data, in particular ids of the lists at stake.
182 * @param participate: indicates if the user takes part at the event or not;
183 * -1 means he did not answer, 0 means no, and 1 means yes.
184 * @param paid: has the user already payed anything?
185 * 0 means no, a positive amount means yes.
186 * @param payment: is this function called from a payment page?
187 * If true, only payment related lists should be updated.
189 function subscribe_lists_event($uid, $evt, $participate, $paid, $payment = false
)
191 $participant_list = $evt['participant_list'];
192 $absent_list = $evt['absent_list'];
193 $unpayed_list = $evt['booked_unpayed_list'];
194 $payed_list = $evt['payed_list'];
196 $user = User
::getSilent($uid);
197 $email = $user->forlifeEmail();
199 function subscribe($list, $email)
201 if ($list && $email) {
202 XDB
::execute('INSERT IGNORE INTO virtual_redirect
208 function unsubscribe($list, $email)
210 if ($list && $email) {
211 XDB
::execute('DELETE FROM virtual_redirect
212 WHERE vid = {?} AND redirect = {?}',
217 /** If $payment is not null, we do not retrieve the value of $participate,
218 * thus we do not alter participant and absent lists.
220 if ($payment === true
) {
222 unsubscribe($unpayed_list, $email);
223 subscribe($payed_list, $email);
226 switch ($participate) {
228 unsubscribe($participant_list, $email);
229 unsubscribe($unpayed_list, $email);
230 unsubscribe($payed_list, $email);
231 subscribe($absent_list, $email);
234 unsubscribe($participant_list, $email);
235 unsubscribe($absent_list, $email);
236 unsubscribe($unpayed_list, $email);
237 unsubscribe($payed_list, $email);
240 subscribe($participant_list, $email);
241 unsubscribe($absent_list, $email);
243 unsubscribe($unpayed_list, $email);
244 subscribe($payed_list, $email);
246 subscribe($unpayed_list, $email);
247 unsubscribe($payed_list, $email);
255 // {{{ function event_change_shortname()
256 function event_change_shortname(&$page, $eid, $old, $new)
263 // Quelques vérifications sur l'alias (caractères spéciaux)
264 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
265 $page->trigError("Le raccourci demandé n'est pas valide.
266 Vérifie qu'il comporte entre 3 et 20 caractères
267 et qu'il ne contient que des lettres non accentuées,
268 des chiffres ou les caractères - et .");
270 } elseif ($new && (is_int($new) ||
ctype_digit($new))) {
271 $page->trigError("Le raccourci demandé ne peut être accepté car il
272 ne contient que des chiffres. Rajoute-lui par exemple
277 //vérifier que l'alias n'est pas déja pris
278 if ($new && $old != $new) {
279 $res = XDB
::query('SELECT COUNT(*)
281 WHERE short_name = {?}',
283 if ($res->fetchOneCell() > 0) {
284 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
294 // if had a previous shortname change the old lists
295 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
296 $v .= $globals->xnet
->evts_domain
;
297 XDB
::execute("UPDATE virtual
299 WHERE type = 'evt' AND alias = {?}",
300 $new . $v, $old . $v);
306 // if we have a first new short_name create the lists
309 '-participants@' => 'ep.nb > 0',
310 '-paye@' => 'ep.paid > 0',
311 '-participants-non-paye@' => 'ep.nb > 0 AND ep.paid = 0'
314 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
315 XDB
::execute("INSERT INTO virtual
316 SET type = 'evt', alias = {?}",
317 $new . $v . $globals->xnet
->evts_domain
);
319 $lastid[$v] = XDB
::insertId();
322 foreach (array('-participants@', '-paye@', '-participants-non-paye@') as $v) {
323 XDB
::execute("INSERT IGNORE INTO virtual_redirect (
324 SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
325 FROM group_event_participants AS ep
326 LEFT JOIN accounts AS a ON (ep.uid = a.uid)
327 LEFT JOIN aliases AS al ON (al.uid = a.uid AND al.type = 'a_vie')
328 WHERE ep.eid = {?} AND " . $where[$v] . "
330 $lastid[$v], '@' . $globals->mail
->domain
, $eid);
332 XDB
::execute("INSERT IGNORE INTO virtual_redirect (
333 SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect
334 FROM group_members AS m
335 LEFT JOIN accounts AS a ON (a.uid = m.uid)
336 LEFT JOIN aliases AS al ON (al.uid = a.uid AND al.type = 'a_vie')
337 LEFT JOIN group_event_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?})
338 WHERE m.asso_id = {?} AND ep.uid IS NULL
340 $lastid['-absents@'], '@' . $globals->mail
->domain
, $eid, $globals->asso('id'));
346 // if we delete the old short name, delete the lists
347 foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) {
348 $v .= $globals->xnet
->evts_domain
;
349 XDB
::execute("DELETE virtual, virtual_redirect
351 LEFT JOIN virtual_redirect USING(vid)
352 WHERE virtual.alias = {?}",
353 $infos['short_name'] . $v);
363 // {{{ function make_event_date()
364 function make_event_date(&$e)
366 $start = strtotime($e['debut']);
367 $end = strtotime($e['fin']);
368 $first_day = @strtotime
($e['first_day']);
369 $last_day = strtotime($e['last_day']);
370 unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
373 if ($start && $end != $start) {
374 if ($first_day == $last_day) {
375 $date .= "le " . strftime("%d %B %Y", $start) . " de "
376 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
378 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
379 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
382 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
388 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: