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(10, e.debut) AS start_day, LEFT(10, e.fin) 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());
64 $evt['moments'] = XDB
::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb,
65 ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
66 FROM group_event_items AS ei
67 LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id
70 S
::i('uid'), $evt['eid']);
73 $evt['notify_payment'] = false
;
74 foreach ($evt['moments'] as $m) {
75 $evt['topay'] +
= $m['nb'] * $m['montant'];
79 $evt['paid'] = $m['paid'];
80 $evt['notify_payment'] = $evt['notify_payment'] ||
$m['notify_payment'];
83 $montant = XDB
::fetchOneCell('SELECT SUM(amount) AS sum_amount
84 FROM payment_transactions AS t
85 WHERE ref = {?} AND uid = {?}',
86 $evt['paiement_id'], S
::v('uid'));
87 $evt['telepaid'] = $montant;
88 $evt['paid'] +
= $montant;
89 $evt['organizer'] = User
::getSilent($evt['uid']);
91 make_event_date($evt);
93 $evt['show_participants'] = ($evt['show_participants'] && (is_member() ||
may_update()));
100 // {{{ function get_event_participants()
101 function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null
, $offset = 0)
106 $money = $evt['money'] && (function_exists('may_update')) && may_update();
107 $pay_id = $evt['paiement_id'];
109 $append = $item_id ? XDB
::format(' AND ep.item_id = {?}', $item_id) : '';
110 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
111 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
112 FROM group_event_participants AS ep
113 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
114 GROUP BY ep.uid', $eid);
115 $uf = new UserFilter(new PFC_True(), $tri);
116 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset)));
118 foreach ($users as $user) {
120 $tab[$uid] = $query[$uid];
121 $tab[$uid]['user'] = $user;
128 $evt['adminpaid'] = 0;
129 $evt['telepaid'] = 0;
132 foreach ($tab as $uid=>&$u) {
133 $u['adminpaid'] = $u['paid'];
135 if ($money && $pay_id) {
136 $montant = XDB
::fetchOneCell('SELECT SUM(amount)
137 FROM payment_transactions AS t
138 WHERE ref = {?} AND uid = {?}',
140 $u['paid'] +
= $montant;
142 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
143 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
144 FROM group_event_participants AS ep
145 INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
146 WHERE ep.eid = {?} AND ep.uid = {?}',
148 while ($i = $res_->next()) {
149 $u[$i['item_id']] = $i['nb'];
150 $u['montant'] +
= $i['montant']*$i['nb'];
152 $evt['telepaid'] +
= $u['telepayment'];
153 $evt['adminpaid'] +
= $u['adminpaid'];
154 $evt['paid'] +
= $u['paid'];
155 $evt['topay'] +
= $u['montant'];
161 // {{{ function subscribe_lists_event()
162 /** Subscribes user to various event related mailing lists.
164 * @param $uid: user's id.
165 * @param short_name: event's short_name, which corresponds to the beginning of the emails.
166 * @param participate: indicates if the user takes part at the event or not;
167 * -1 means he did not answer, 0 means no, and 1 means yes.
168 * @param paid: has the user already payed anything?
169 * 0 means no, a positive amount means yes.
170 * @param payment: is this function called from a payment page?
171 * If true, only payment related lists should be updated.
173 function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false
)
176 require_once 'emails.inc.php';
178 if (is_null($short_name)) {
182 /** If $payment is not null, we do not retrieve the value of $participate,
183 * thus we do not alter participant and absent lists.
185 if ($payment === true
) {
187 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
188 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
191 switch ($participate) {
193 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
194 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
195 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
196 add_to_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
199 delete_from_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
200 delete_from_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
201 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
202 delete_from_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
205 add_to_list_alias($uid, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
206 delete_from_list_alias($uid, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
208 delete_from_list_alias($uid, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
209 add_to_list_alias($uid, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
211 add_to_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');
220 // {{{ function event_change_shortname()
221 function event_change_shortname($page, $eid, $old, $new)
224 require_once 'emails.inc.php';
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 && (is_int($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(*)
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 (explode(',', $globals->xnet
->event_lists
) as $suffix) {
262 XDB
::execute('UPDATE email_virtual
264 WHERE type = \'event\' AND email = {?}',
265 $new . $suffix, $old . $suffix);
272 // if we have a first new short_name create the lists
275 $globals->xnet
->participant_list
=> 'nb > 0',
276 $globals->xnet
->payed_list
=> 'paid > 0',
277 $globals->xnet
->unpayed_list
=> 'nb > 0 AND paid = 0'
280 foreach (array($globals->xnet
->participant_list
, $globals->xnet
->payed_list
, $globals->xnet
->unpayed_list
) as $suffix) {
281 $uids = XDB
::fetchColumn('SELECT uid
282 FROM group_event_participants
283 WHERE eid = {?} AND ' . $where[$suffix],
285 foreach ($uids as $uid) {
286 add_to_list_alias($uid, $new . $suffix, $globals->xnet
->evts_domain
, 'event');
289 $uids = XDB
::fetchColumn('SELECT m.uid
290 FROM group_members AS m
291 LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?})
292 WHERE m.asso_id = {?} AND e.uid IS NULL',
293 $eid, $globals->asso('id'));
294 foreach ($uids as $uid) {
295 add_to_list_alias($uid, $new . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
302 // if we delete the old short name, delete the lists
303 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
304 delete_list_alias($old . $suffix, $globals->xnet
->evts_domain
);
315 // {{{ function make_event_date()
316 function make_event_date(&$e)
318 $start = strtotime($e['debut']);
319 $end = strtotime($e['fin']);
320 $first_day = @strtotime
($e['first_day']);
321 $last_day = strtotime($e['last_day']);
322 unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
325 if ($start && $end != $start) {
326 if ($first_day == $last_day) {
327 $date .= "le " . strftime("%d %B %Y", $start) . " de "
328 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
330 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
331 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
334 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
340 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: