X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents.php;h=f99a4b6c3ac0baa80c65e58aa4261199c758067b;hb=fe5ccad978199cfbe71c583280b999769a27c9b2;hp=0dc18e3fe0d62ae435698915e20539733cca0bb7;hpb=ee923b43a6a0dd1e1418c7c262065d7519933f73;p=platal.git diff --git a/modules/xnetevents.php b/modules/xnetevents.php index 0dc18e3..f99a4b6 100644 --- a/modules/xnetevents.php +++ b/modules/xnetevents.php @@ -114,7 +114,7 @@ class XnetEventsModule extends PLModule } $page->assign('archive', $archive); - $evenements = XDB::iterator('SELECT e.*, LEFT(10, e.debut) AS first_day, LEFT(10, e.fin) AS last_day, + $evenements = XDB::iterator('SELECT e.*, LEFT(e.debut, 10) AS first_day, LEFT(e.fin, 10) AS last_day, IF(e.deadline_inscription, e.deadline_inscription >= LEFT(NOW(), 10), 1) AS inscr_open, @@ -237,18 +237,20 @@ class XnetEventsModule extends PLModule } // update actual inscriptions - $updated = false; - $total = 0; - $paid = $evt['paid'] ? $evt['paid'] : 0; - $telepaid= $evt['telepaid'] ? $evt['telepaid'] : 0; + $updated = false; + $total = 0; + $paid = $evt['paid'] ? $evt['paid'] : 0; + $telepaid = $evt['telepaid'] ? $evt['telepaid'] : 0; + $paid_inserted = false; foreach ($subs as $j => $nb) { if ($nb >= 0) { 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, S::v('uid'), $j, $nb, (Env::has('notify_payment') ? 'notify_payment' : ''), - ($j == 1 ? $paid - $telepaid : 0)); + ((!$paid_inserted) ? $paid - $telepaid : 0)); $updated = $eid; + $paid_inserted = true; } else { XDB::execute( "DELETE FROM group_event_participants @@ -594,27 +596,42 @@ class XnetEventsModule extends PLModule $amount = strtr(Env::v('montant'), ',', '.'); XDB::execute("UPDATE group_event_participants SET paid = paid + {?} - WHERE uid = {?} AND eid = {?} AND item_id = 1", + WHERE uid = {?} AND eid = {?} AND nb > 0 + ORDER BY item_id ASC + LIMIT 1", $amount, $member->uid, $evt['eid']); subscribe_lists_event($member->uid, $evt['short_name'], 1, $amount); } // change the number of personns coming with a participant if (Env::v('adm') == 'nbs' && $member) { - $res = XDB::query("SELECT paid + $res = XDB::query("SELECT SUM(paid) FROM group_event_participants WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']); - $paid = intval($res->fetchOneCell()); + $paid = $res->fetchOneCell(); + + // Ensure we have an integer + if ($paid == null) { + $paid = 0; + } + $nbs = Post::v('nb', array()); + $paid_inserted = false; foreach ($nbs as $id => $nb) { $nb = max(intval($nb), 0); + if (!$paid_inserted && $nb > 0) { + $item_paid = $paid; + $paid_inserted = true; + } else { + $item_paid = 0; + } 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)', - $evt['eid'], $member->uid, $id, $nb, '', ($id == 1 ? $paid : 0)); + $evt['eid'], $member->uid, $id, $nb, '', $item_paid); } $res = XDB::query('SELECT COUNT(uid) AS cnt, SUM(nb) AS nb @@ -623,7 +640,7 @@ class XnetEventsModule extends PLModule GROUP BY uid', $member->uid, $evt['eid']); $u = $res->fetchOneAssoc(); - if ($u['cnt'] == 1 && $paid == 0 && Post::v('cancel')) { + if ($paid == 0 && Post::v('cancel')) { XDB::execute("DELETE FROM group_event_participants WHERE uid = {?} AND eid = {?}", $member->uid, $evt['eid']);