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.*,
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 $montants = XDB
::fetchColumn('SELECT amount
84 FROM payment_transactions AS t
85 WHERE ref = {?} AND uid = {?}',
86 $evt['paiement_id'], S
::v('uid'));
88 foreach ($montants as $m) {
89 $p = strtr(substr($m, 0, strpos($m, 'EUR')), ',', '.');
90 $evt['paid'] +
= trim($p);
91 $evt['telepaid'] +
= trim($p);
93 $evt['organizer'] = User
::getSilent($evt['uid']);
95 make_event_date($evt);
102 // {{{ function get_event_participants()
103 function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null
)
108 $money = $evt['money'] && (function_exists('may_update')) && may_update();
109 $pay_id = $evt['paiement_id'];
111 $append = $item_id ? XDB
::format(' AND ep.item_id = {?}', $item_id) : '';
112 $query = XDB
::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb,
113 FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment
114 FROM group_event_participants AS ep
115 WHERE ep.eid = {?} AND nb > 0 ' . $append . '
116 GROUP BY ep.uid', $eid);
117 $uf = new UserFilter(new PFC_True(), $tri);
118 $users = User
::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($count, $offset)));
120 foreach ($users as $user) {
122 $tab[$uid] = $query[$uid];
123 $tab[$uid]['user'] = $user;
130 $evt['adminpaid'] = 0;
131 $evt['telepaid'] = 0;
134 foreach ($tab as $uid=>&$u) {
135 $u['adminpaid'] = $u['paid'];
137 if ($money && $pay_id) {
138 $montants = XDB
::fetchColumn('SELECT amount
139 FROM payment_transactions AS t
140 WHERE ref = {?} AND uid = {?}',
142 foreach ($montants as $m) {
143 $p = strtr(substr($m, 0, strpos($m, "EUR")), ",", ".");
144 $u['paid'] +
= trim($p);
147 $u['telepayment'] = $u['paid'] - $u['adminpaid'];
148 $res_ = XDB
::iterator('SELECT ep.nb, ep.item_id, ei.montant
149 FROM group_event_participants AS ep
150 INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id)
151 WHERE ep.eid = {?} AND ep.uid = {?}',
153 while ($i = $res_->next()) {
154 $u[$i['item_id']] = $i['nb'];
155 $u['montant'] +
= $i['montant']*$i['nb'];
157 $evt['telepaid'] +
= $u['telepayment'];
158 $evt['adminpaid'] +
= $u['adminpaid'];
159 $evt['paid'] +
= $u['paid'];
160 $evt['topay'] +
= $u['montant'];
166 // {{{ function subscribe_lists_event()
167 /** Subscribes user to various event related mailing lists.
169 * @param $uid: user's id.
170 * @param short_name: event's short_name, which corresponds to the beginning of the emails.
171 * @param participate: indicates if the user takes part at the event or not;
172 * -1 means he did not answer, 0 means no, and 1 means yes.
173 * @param paid: has the user already payed anything?
174 * 0 means no, a positive amount means yes.
175 * @param payment: is this function called from a payment page?
176 * If true, only payment related lists should be updated.
178 function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false
)
181 require_once 'emails.inc.php';
183 if (is_null($short_name)) {
187 $user = User
::getSilentWithUID($uid);
189 /** If $payment is not null, we do not retrieve the value of $participate,
190 * thus we do not alter participant and absent lists.
192 if ($payment === true
) {
194 delete_from_list_alias($user, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
195 add_to_list_alias($user, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
198 switch ($participate) {
200 delete_from_list_alias($user, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
201 delete_from_list_alias($user, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
202 delete_from_list_alias($user, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
203 add_to_list_alias($user, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
206 delete_from_list_alias($user, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
207 delete_from_list_alias($user, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
208 delete_from_list_alias($user, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
209 delete_from_list_alias($user, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
212 add_to_list_alias($user, $short_name . $globals->xnet
->participant_list
, $globals->xnet
->evts_domain
, 'event');
213 delete_from_list_alias($user, $short_name . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
215 delete_from_list_alias($user, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
216 add_to_list_alias($user, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
218 add_to_list_alias($user, $short_name . $globals->xnet
->unpayed_list
, $globals->xnet
->evts_domain
, 'event');
219 delete_from_list_alias($user, $short_name . $globals->xnet
->payed_list
, $globals->xnet
->evts_domain
, 'event');
227 // {{{ function event_change_shortname()
228 function event_change_shortname($page, $eid, $old, $new)
231 require_once 'emails.inc.php';
236 // Quelques vérifications sur l'alias (caractères spéciaux)
237 if ($new && !preg_match( "/^[a-zA-Z0-9\-.]{3,20}$/", $new)) {
238 $page->trigError("Le raccourci demandé n'est pas valide.
239 Vérifie qu'il comporte entre 3 et 20 caractères
240 et qu'il ne contient que des lettres non accentuées,
241 des chiffres ou les caractères - et .");
243 } elseif ($new && (is_int($new) ||
ctype_digit($new))) {
244 $page->trigError("Le raccourci demandé ne peut être accepté car il
245 ne contient que des chiffres. Rajoute-lui par exemple
250 //vérifier que l'alias n'est pas déja pris
251 if ($new && $old != $new) {
252 $res = XDB
::query('SELECT COUNT(*)
254 WHERE short_name = {?}',
256 if ($res->fetchOneCell() > 0) {
257 $page->trigError("Le raccourci demandé est déjà utilisé. Choisis en un autre.");
267 // if had a previous shortname change the old lists
268 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
269 XDB
::execute('UPDATE email_virtual
271 WHERE type = \'event\' AND email = {?}',
272 $new . $suffix, $old . $suffix);
279 // if we have a first new short_name create the lists
282 $globals->xnet
->participant_list
=> 'nb > 0',
283 $globals->xnet
->payed_list
=> 'paid > 0',
284 $globals->xnet
->unpayed_list
=> 'nb > 0 AND paid = 0'
287 foreach (array($globals->xnet
->participant_list
, $globals->xnet
->payed_list
, $globals->xnet
->unpayed_list
) as $suffix) {
288 $uids = XDB
::fetchColumn('SELECT uid
289 FROM group_event_participants
290 WHERE eid = {?} AND ' . $where,
292 $users = User
::getBulkUsersWithUIDs($uids, null
, null
, false
);
293 foreach ($users as $user) {
294 add_to_list_alias($user, $new . $suffix, $globals->xnet
->evts_domain
, 'event');
297 $uids = XDB
::fetchColumn('SELECT m.uid
298 FROM group_members AS m
299 LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?})
300 WHERE m.asso_id = {?} AND e.uid IS NULL',
301 $eid, $globals->asso('id'));
302 $users = User
::getBulkUsersWithUIDs($uids, null
, null
, false
);
303 foreach ($users as $user) {
304 add_to_list_alias($user, $new . $globals->xnet
->absent_list
, $globals->xnet
->evts_domain
, 'event');
311 // if we delete the old short name, delete the lists
312 foreach (explode(',', $globals->xnet
->event_lists
) as $suffix) {
313 delete_list_alias($old . $suffix, $globals->xnet
->evts_domain
);
324 // {{{ function make_event_date()
325 function make_event_date(&$e)
327 $start = strtotime($e['debut']);
328 $end = strtotime($e['fin']);
329 $first_day = @strtotime
($e['first_day']);
330 $last_day = strtotime($e['last_day']);
331 unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']);
334 if ($start && $end != $start) {
335 if ($first_day == $last_day) {
336 $date .= "le " . strftime("%d %B %Y", $start) . " de "
337 . strftime("%H:%M", $start) . " à " . strftime("%H:%M", $end);
339 $date .= "du " . strftime("%d %B %Y à %H:%M", $start)
340 . "\nau " . strftime("%d %B %Y à %H:%M", $end);
343 $date .= "le " . strftime("%d %B %Y à %H:%M", $start);
349 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: