fd92d2262a0cade023a10e428da63e57272e4fec
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 $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,
31 IF(e.deadline_inscription,
32 e.deadline_inscription >= LEFT(NOW(), 10),
34 LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day,
35 LEFT(NOW(), 10) AS now,
36 ei.titre, e.subscription_notification
37 FROM group_events AS e
38 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
39 LEFT JOIN group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id)
40 WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?}
42 $eid, $eid, $item_id ?
$item_id : 1, $asso_id);
47 if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) {
51 // smart calculation of the total number
53 $res = XDB
::query('SELECT MAX(nb)
54 FROM group_events AS e
55 INNER JOIN group_event_items AS ei ON (e.eid = ei.eid)
56 LEFT JOIN group_event_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id)
58 GROUP BY ep.uid', $evt['eid']);
59 $evt['nb_tot'] = array_sum($res->fetchColumn());
62 $evt['csv_name'] = urlencode($evt['intitule']);
64 $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']);
67 $evt['moments'] = XDB
::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb,
68 ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
69 FROM group_event_items AS ei
70 LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id
73 S
::i('uid'), $evt['eid']);
76 $evt['notify_payment'] = false
;
77 foreach ($evt['moments'] as $m) {
78 $evt['topay'] +
= $m['nb'] * $m['montant'];
82 $evt['paid'] +
= $m['paid'];
83 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
86 $montant = XDB
::fetchOneCell('SELECT SUM(amount) AS sum_amount
87 FROM payment_transactions AS t
88 WHERE ref = {?} AND uid = {?}',
89 $evt['paiement_id'], S
::v('uid'));
90 $evt['telepaid'] = $montant;
91 $evt['paid'] +
= $montant;
92 $evt['organizer'] = User
::getSilent($evt['uid']);
94 make_event_date($evt);
96 $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() ||
may_update()));
103 // {{{ function get_event_participants()
104 function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null
, $offset = 0)
109 $money = $evt['money'] && (function_exists('may_update')) && may_update();
110 $pay_id = $evt['paiement_id'];
112 $append = $item_id ? XDB
::format(' AND ep.item_id = {?}', $item_id) : '';
113 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
114 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
115 FROM group_event_participants AS ep
116 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
117 GROUP BY ep.uid', $eid);
118 $uf = new UserFilter(new PFC_True(), $tri);
119 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset)));
121 foreach ($users as $user) {
123 $tab[$uid] = $query[$uid];
124 $tab[$uid]['user'] = $user;
131 $evt['adminpaid'] = 0;
132 $evt['telepaid'] = 0;
135 foreach ($tab as $uid=>&$u) {
136 $u['adminpaid'] = $u['paid'];
138 if ($money && $pay_id) {
139 $montant = XDB
::fetchOneCell('SELECT SUM(amount)
140 FROM payment_transactions AS t
141 WHERE ref = {?} AND uid = {?}',
143 $u['paid'] +
= $montant;
145 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
146 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
147 FROM group_event_participants AS ep
148 INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
149 WHERE ep.eid = {?} AND ep.uid = {?}',
151 while ($i = $res_->next()) {
152 $u[$i['item_id']] = $i['nb'];
153 $u['montant'] +
= $i['montant']*$i['nb'];
155 $evt['telepaid'] +
= $u['telepayment'];
156 $evt['adminpaid'] +
= $u['adminpaid'];
157 $evt['paid'] +
= $u['paid'];
158 $evt['topay'] +
= $u['montant'];
164 // {{{ function subscribe_lists_event()
165 /** Subscribes user to various event related mailing lists.
167 * @param $uid: user's id.
168 * @param short_name: event's short_name, which corresponds to the beginning of the emails.
169 * @param participate: indicates if the user takes part at the event or not;
170 * -1 means he did not answer, 0 means no, and 1 means yes.
171 * @param paid: has the user already payed anything?
172 * 0 means no, a positive amount means yes.
173 * @param payment: is this function called from a payment page?
174 * If true, only payment related lists should be updated.
176 function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false
)
179 require_once 'emails.inc.php';
181 if (is_null($short_name)) {
185 /** If $payment is not null, we do not retrieve the value of $participate,
186 * thus we do not alter participant and absent lists.
188 if ($payment === true
) {
190 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
191 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
194 switch ($participate) {
196 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
197 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
198 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
199 add_to_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
202 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
203 delete_from_list_alias($uid, $short_name . $globals->xnet
->absent_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');
208 add_to_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
209 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 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
214 add_to_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
215 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
223 // {{{ function event_change_shortname()
224 function event_change_shortname($page, $eid, $old, $new)
227 require_once 'emails.inc.php';
232 // Quelques vérifications sur l'alias (caractères spéciaux)
233 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
234 $page->trigError("Le raccourci demandé n'est pas valide.
235 Vérifie qu'il comporte entre 3 et 20 caractères
236 et qu'il ne contient que des lettres non accentuées,
237 des chiffres ou les caractères - et .");
239 } elseif ($new && (is_int($new) ||
ctype_digit($new))) {
240 $page->trigError("Le raccourci demandé ne peut être accepté car il
241 ne contient que des chiffres. Rajoute-lui par exemple
246 //vérifier que l'alias n'est pas déja pris
247 if ($new && $old != $new) {
248 $res = XDB
::query('SELECT COUNT(*)
250 WHERE short_name = {?}',
252 if ($res->fetchOneCell() > 0) {
253 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
263 // if had a previous shortname change the old lists
264 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
265 XDB
::execute('UPDATE email_virtual
267 WHERE type = \'event\' AND email = {?}',
268 $new . $suffix, $old . $suffix);
275 // if we have a first new short_name create the lists
278 $globals->xnet
->participant_list
=> 'g.nb > 0',
279 $globals->xnet
->payed_list
=> '(g.paid > 0 OR p.amount > 0)',
280 $globals->xnet
->unpayed_list
=> 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL'
283 foreach (array($globals->xnet
->participant_list
, $globals->xnet
->payed_list
, $globals->xnet
->unpayed_list
) as $suffix) {
284 $uids = XDB
::fetchColumn('SELECT g.uid
285 FROM group_event_participants AS g
286 INNER JOIN group_events AS e ON (g.eid = e.eid)
287 LEFT JOIN payment_transactions AS p ON (e.paiement_id = p.ref AND g.uid = p.uid)
288 WHERE g.eid = {?} AND ' . $where[$suffix],
290 foreach ($uids as $uid) {
291 add_to_list_alias($uid, $new . $suffix, $globals->xnet
->evts_domain
, 'event');
295 $uids = XDB
::fetchColumn('SELECT m.uid
296 FROM group_members AS m
297 LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?})
298 WHERE m.asso_id = {?} AND e.uid IS NULL',
299 $eid, $globals->asso('id'));
300 foreach ($uids as $uid) {
301 add_to_list_alias($uid, $new . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
308 // if we delete the old short name, delete the lists
309 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
310 delete_list_alias($old . $suffix, $globals->xnet
->evts_domain
);
321 // {{{ function make_event_date()
322 function make_event_date(&$e)
324 $start = strtotime($e['debut']);
325 $end = strtotime($e['fin']);
326 $first_day = $e['first_day'];
327 $last_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: