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');
34 $where = XDB
::format(' AND ei.item_id = {?}', $item_id);
35 $group_by = 'ei.item_id';
37 $evt = XDB
::fetchOneAssoc('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, SUM(IF(nb > 0, 1, 0)) AS user_count,
38 IF(e.deadline_inscription,
39 e.deadline_inscription >= LEFT(NOW(), 10),
41 LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day,
42 LEFT(NOW(), 10) AS now,
43 ei.titre, e.subscription_notification
44 FROM group_events AS e
45 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
46 LEFT JOIN group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
47 WHERE (e.eid = {?} OR e.short_name = {?}) AND e.asso_id = {?}' . $where . '
48 GROUP BY ' . $group_by,
49 $eid, $eid, $asso_id);
54 if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) {
58 // smart calculation of the total number
60 $res = XDB
::query('SELECT MAX(nb)
61 FROM group_events AS e
62 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
63 LEFT JOIN group_event_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
65 GROUP BY ep.uid', $evt['eid']);
66 $evt['nb_tot'] = array_sum($res->fetchColumn());
69 $evt['csv_name'] = urlencode($evt['intitule']);
71 $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']);
74 $evt['moments'] = XDB
::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb,
75 ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
76 FROM group_event_items AS ei
77 LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id
80 S
::i('uid'), $evt['eid']);
83 $evt['notify_payment'] = false
;
84 foreach ($evt['moments'] as $m) {
85 $evt['topay'] +
= $m['nb'] * $m['montant'];
89 $evt['paid'] +
= $m['paid'];
90 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
93 $montant = XDB
::fetchOneCell('SELECT SUM(amount) AS sum_amount
94 FROM payment_transactions AS t
95 WHERE ref = {?} AND uid = {?}',
96 $evt['paiement_id'], S
::v('uid'));
97 $evt['telepaid'] = $montant;
98 $evt['paid'] +
= $montant;
99 $evt['organizer'] = User
::getSilent($evt['uid']);
101 make_event_date($evt);
103 $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() ||
may_update()));
110 // {{{ function get_event_participants()
111 function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null
, $offset = 0)
116 $money = $evt['money'] && (function_exists('may_update')) && may_update();
117 $pay_id = $evt['paiement_id'];
119 $append = $item_id ? XDB
::format(' AND ep.item_id = {?}', $item_id) : '';
120 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
121 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
122 FROM group_event_participants AS ep
123 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
124 GROUP BY ep.uid', $eid);
125 $uf = new UserFilter(new PFC_True(), $tri);
126 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset)));
128 foreach ($users as $user) {
130 $tab[$uid] = $query[$uid];
131 $tab[$uid]['user'] = $user;
138 $evt['adminpaid'] = 0;
139 $evt['telepaid'] = 0;
142 foreach ($tab as $uid=>&$u) {
143 $u['adminpaid'] = (float)$u['paid'];
145 if ($money && $pay_id) {
146 $montant = XDB
::fetchOneCell('SELECT SUM(amount)
147 FROM payment_transactions AS t
148 WHERE ref = {?} AND uid = {?}',
150 $u['paid'] +
= $montant;
152 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
153 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
154 FROM group_event_participants AS ep
155 INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
156 WHERE ep.eid = {?} AND ep.uid = {?}',
158 while ($i = $res_->next()) {
159 $u[$i['item_id']] = $i['nb'];
160 $u['montant'] +
= $i['montant']*$i['nb'];
162 $evt['telepaid'] +
= $u['telepayment'];
163 $evt['adminpaid'] +
= $u['adminpaid'];
164 $evt['paid'] +
= $u['paid'];
165 $evt['topay'] +
= $u['montant'];
171 // {{{ function subscribe_lists_event()
172 /** Subscribes user to various event related mailing lists.
174 * @param $uid: user's id.
175 * @param short_name: event's short_name, which corresponds to the beginning of the emails.
176 * @param participate: indicates if the user takes part at the event or not;
177 * -1 means he did not answer, 0 means no, and 1 means yes.
178 * @param paid: has the user already payed anything?
179 * 0 means no, a positive amount means yes.
180 * @param payment: is this function called from a payment page?
181 * If true, only payment related lists should be updated.
183 function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false
)
186 require_once 'emails.inc.php';
188 if (is_null($short_name)) {
192 /** If $payment is not null, we do not retrieve the value of $participate,
193 * thus we do not alter participant and absent lists.
195 if ($payment === true
) {
197 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
198 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
201 switch ($participate) {
203 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
204 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
205 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
206 add_to_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
209 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
210 delete_from_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
211 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
212 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
215 add_to_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
216 delete_from_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
218 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
219 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
221 add_to_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
222 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
230 // {{{ function event_change_shortname()
231 function event_change_shortname($page, $eid, $old, $new)
234 require_once 'emails.inc.php';
239 // Quelques vérifications sur l'alias (caractères spéciaux)
240 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
241 $page->trigError("Le raccourci demandé n'est pas valide.
242 Vérifie qu'il comporte entre 3 et 20 caractères
243 et qu'il ne contient que des lettres non accentuées,
244 des chiffres ou les caractères - et .");
246 } elseif ($new && (is_int($new) ||
ctype_digit($new))) {
247 $page->trigError("Le raccourci demandé ne peut être accepté car il
248 ne contient que des chiffres. Rajoute-lui par exemple
253 //vérifier que l'alias n'est pas déja pris
254 if ($new && $old != $new) {
255 $res = XDB
::query('SELECT COUNT(*)
257 WHERE short_name = {?}',
259 if ($res->fetchOneCell() > 0) {
260 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
270 // if had a previous shortname change the old lists
271 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
272 XDB
::execute('UPDATE email_virtual
274 WHERE type = \'event\' AND email = {?}',
275 $new . $suffix, $old . $suffix);
282 // if we have a first new short_name create the lists
285 $globals->xnet
->participant_list
=> 'g.nb > 0',
286 $globals->xnet
->payed_list
=> '(g.paid > 0 OR p.amount > 0)',
287 $globals->xnet
->unpayed_list
=> 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL'
290 foreach (array($globals->xnet
->participant_list
, $globals->xnet
->payed_list
, $globals->xnet
->unpayed_list
) as $suffix) {
291 $uids = XDB
::fetchColumn('SELECT g.uid
292 FROM group_event_participants AS g
293 INNER JOIN group_events AS e ON (g.eid = e.eid)
294 LEFT JOIN payment_transactions AS p ON (e.paiement_id = p.ref AND g.uid = p.uid)
295 WHERE g.eid = {?} AND ' . $where[$suffix],
297 foreach ($uids as $uid) {
298 add_to_list_alias($uid, $new . $suffix, $globals->xnet
->evts_domain
, 'event');
302 $uids = XDB
::fetchColumn('SELECT m.uid
303 FROM group_members AS m
304 LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?})
305 WHERE m.asso_id = {?} AND e.uid IS NULL',
306 $eid, $globals->asso('id'));
307 foreach ($uids as $uid) {
308 add_to_list_alias($uid, $new . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
315 // if we delete the old short name, delete the lists
316 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
317 delete_list_alias($old . $suffix, $globals->xnet
->evts_domain
);
328 // {{{ function make_event_date()
329 function make_event_date(&$e)
331 $start = strtotime($e['debut']);
332 $end = strtotime($e['fin']);
333 $first_day = $e['first_day'];
334 $last_day = $e['last_day'];
337 if ($start && $end != $start) {
338 if ($first_day == $last_day) {
339 $date .= "le " . strftime("%d %B %Y", $start) . " de "
340 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
342 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
343 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
346 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
352 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: