X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=dade4704f95ae8ac9647b3096c9a36aa8e26ba02;hb=05613e9aa75a084c495c82f6af043d5246e003ab;hp=52c4ad23d3e5affc268611fbad84b69bdd95a300;hpb=a7c0d514f97ce39696d5660ef4faccdd8380fe00;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index 52c4ad2..dade470 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -1,6 +1,6 @@ asso('id'); } - $evt = XDB::fetchOneAssoc('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, + if (!$item_id) { + $where = ''; + $group_by = 'e.eid'; + } else { + $where = XDB::format(' AND ei.item_id = {?}', $item_id); + $group_by = 'ei.item_id'; + } + $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, IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, - LEFT(10, e.debut) AS start_day, LEFT(10, e.fin) AS last_day, + LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day, LEFT(NOW(), 10) AS now, ei.titre, e.subscription_notification FROM group_events AS e INNER JOIN group_event_items AS ei ON (e.eid = ei.eid) LEFT JOIN group_event_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) - WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?} - GROUP BY ei.item_id', - $eid, $eid, $item_id ? $item_id : 1, $asso_id); + WHERE (e.eid = {?} OR e.short_name = {?}) AND e.asso_id = {?}' . $where . ' + GROUP BY ' . $group_by, + $eid, $eid, $asso_id); if (!$evt) { return null; @@ -48,17 +163,18 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) return false; } - // smart calculation of the total number if (!$item_id) { - $res = XDB::query('SELECT MAX(nb) - FROM group_events AS e - INNER JOIN group_event_items AS ei ON (e.eid = ei.eid) - LEFT JOIN group_event_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id) - WHERE e.eid = {?} - GROUP BY ep.uid', $evt['eid']); - $evt['nb_tot'] = array_sum($res->fetchColumn()); + /* Don't try to be to smart here, in case we're getting the global summary, we cannot have + * a general formula to estimate the total number of comers since 'moments' may (or may not be) + * disjuncted. As a consequence, we can only provides the number of user having fullfiled the + * registration procedure. + */ + $evt['user_count'] = $evt['nb_tot'] = $evt['nb']; $evt['titre'] = ''; $evt['item_id'] = 0; + $evt['csv_name'] = urlencode($evt['intitule']); + } else { + $evt['csv_name'] = urlencode($evt['intitule'] . '.' . $evt['titre']); } $evt['moments'] = XDB::fetchAllAssoc('SELECT titre, details, montant, ei.item_id, nb, @@ -76,7 +192,7 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) if ($m['montant']) { $evt['money'] = true; } - $evt['paid'] = $m['paid']; + $evt['paid'] += $m['paid']; $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } @@ -88,9 +204,9 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['paid'] += $montant; $evt['organizer'] = User::getSilent($evt['uid']); - make_event_date($evt); + $evt['date'] = make_event_date($evt['debut'], $evt['fin']); - $evt['show_participants'] = ($evt['show_participants'] && (is_member() || may_update())); + $evt['show_participants'] = ($evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() || may_update())); return $evt; } @@ -98,7 +214,7 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) // }}} // {{{ function get_event_participants() -function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null) +function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null, $offset = 0) { global $globals; @@ -113,7 +229,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = WHERE ep.eid = {?} AND nb > 0 ' . $append . ' GROUP BY ep.uid', $eid); $uf = new UserFilter(new PFC_True(), $tri); - $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($count, $offset))); + $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($limit, $offset))); $tab = array(); foreach ($users as $user) { $uid = $user->id(); @@ -130,7 +246,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = $evt['topay'] = 0; $evt['paid'] = 0; foreach ($tab as $uid=>&$u) { - $u['adminpaid'] = $u['paid']; + $u['adminpaid'] = (float)$u['paid']; $u['montant'] = 0; if ($money && $pay_id) { $montant = XDB::fetchOneCell('SELECT SUM(amount) @@ -147,7 +263,7 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = $eid, $uid); while ($i = $res_->next()) { $u[$i['item_id']] = $i['nb']; - $u['montant'] += $i['montant']*$i['nb']; + $u['montant'] += $i['montant'] * $i['nb']; } $evt['telepaid'] += $u['telepayment']; $evt['adminpaid'] += $u['adminpaid']; @@ -158,6 +274,84 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = } // }}} +// {{{ function subscribe() +/** set or update the user's subscription + * + * @param $uid: user's id + * @param $eid: event's id + * @param $subs: user's new subscription + * + */ +function subscribe($uid, $eid, $subs = array()) +{ + global $globals; + // get items + $items = get_event_items($eid); + // get previous subscription + $old_subs = get_event_subscription($eid, $uid); + $participate = false; + $updated = false; + // TODO : change the way to deal with manual payment + $paid = 0; + foreach ($old_subs as $item_id => $s) { + $paid += $s['paid']; + } + $paid_updated = false; + // for each item of the event + foreach ($items as $item_id => $details) { + // check if there is an old subscription + if (array_key_exists($item_id, $old_subs)) { + // compares new and old subscription + if ($old_subs[$item_id]['nb'] != $subs[$item_id]) { + if ($subs[$item_id] != 0) { + echo "je m'inscris "; + XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) + VALUES ({?}, {?}, {?}, {?}, {?}, {?}) + ON DUPLICATE KEY UPDATE nb = VALUES(nb), flags = VALUES(flags), paid = VALUES(paid)', + $eid, $uid, $item_id, $subs[$item_id],(Env::has('notify_payment') ? 'notify_payment' : 0), (!$paid_updated ? $paid : 0)); + $participate = true; + $paid_updated = true; + } else { // we do not store non-subscription to event items + XDB::execute('DELETE FROM group_event_participants + WHERE eid = {?} AND uid = {?} AND item_id = {?}', + $eid, $uid, $item_id); + } + $updated = true; + } + } else { // if no old subscription + if ($subs[$item_id] != 0) { + XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) + VALUES ({?}, {?}, {?}, {?}, {?}, {?})', + $eid, $uid, $item_id, $subs[$item_id], '', 0); + $participate = true; + $updated = true; + } + } + } + // item 0 stores whether the user participates globally or not, if he has to be notified when payment is created and his manual payment + /* + if (array_key_exists(0, $old_subs)) { + XDB::execute('UPDATE group_event_participants + SET nb = {?} + WHERE eid = {?}, uid = {?}, item_id = 0', + ($participate ? 1 : 0), $eid, $uid); + } else { + XDB::execute('INSERT INTO group_event_participants (eid, uid, item_id, nb, flags, paid) + VALUES ({?}, {?}, {?}, {?}, {?}, {?})', + $eid, $uid, 0, ($participate ? 1 : 0), (Env::has('notify_payment') ? 'notify_payment' : ''), 0); + } + */ + // if subscription is updated, we have to update the event aliases + if ($updated) { + $short_name = get_event_detail($eid)['short_name']; + subscribe_lists_event($uid, $short_name, ($participate ? 1 : -1), 0); + } + return $updated; +} +// }}} + +// TODO : correct this function to be compatible with subscribe() (use $eid, remove useless argument) +// TODO : correct other calls // {{{ function subscribe_lists_event() /** Subscribes user to various event related mailing lists. * @@ -272,20 +466,23 @@ function event_change_shortname($page, $eid, $old, $new) // if we have a first new short_name create the lists $lastid = array(); $where = array( - $globals->xnet->participant_list => 'nb > 0', - $globals->xnet->payed_list => 'paid > 0', - $globals->xnet->unpayed_list => 'nb > 0 AND paid = 0' + $globals->xnet->participant_list => 'g.nb > 0', + $globals->xnet->payed_list => '(g.paid > 0 OR p.amount > 0)', + $globals->xnet->unpayed_list => 'g.nb > 0 AND g.paid = 0 AND p.amount IS NULL' ); foreach (array($globals->xnet->participant_list, $globals->xnet->payed_list, $globals->xnet->unpayed_list) as $suffix) { - $uids = XDB::fetchColumn('SELECT uid - FROM group_event_participants - WHERE eid = {?} AND ' . $where[$suffix], + $uids = XDB::fetchColumn('SELECT g.uid + FROM group_event_participants AS g + INNER JOIN group_events AS e ON (g.eid = e.eid) + LEFT JOIN payment_transactions AS p ON (e.paiement_id = p.ref AND g.uid = p.uid) + WHERE g.eid = {?} AND ' . $where[$suffix], $eid); foreach ($uids as $uid) { add_to_list_alias($uid, $new . $suffix, $globals->xnet->evts_domain, 'event'); } } + $uids = XDB::fetchColumn('SELECT m.uid FROM group_members AS m LEFT JOIN group_event_participants AS e ON (e.uid = m.uid AND e.eid = {?}) @@ -313,14 +510,14 @@ function event_change_shortname($page, $eid, $old, $new) // }}} // {{{ function make_event_date() -function make_event_date(&$e) +function make_event_date($debut, $fin) { - $start = strtotime($e['debut']); - $end = strtotime($e['fin']); - $first_day = @strtotime($e['first_day']); - $last_day = strtotime($e['last_day']); - unset($e['debut'], $e['fin'], $e['first_day'], $e['last_day']); - + $start = strtotime($debut); + $end = strtotime($fin); +// $first_day = $e['first_day']; +// $last_day = $e['last_day']; + $first_day = strftime("%d %B %Y", $start); + $last_day = strftime("%d %B %Y", $end); $date = ""; if ($start && $end != $start) { if ($first_day == $last_day) { @@ -333,9 +530,9 @@ function make_event_date(&$e) } else { $date .= "le " . strftime("%d %B %Y à %H:%M", $start); } - $e['date'] = $date; + return $date; } // }}} -// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: +// vim:set et sw=4 sts=4 sws=4 foldmethod=marker fenc=utf-8: ?>