function get_event_detail($eid, $item_id = false, $asso_id = null) { global $globals; if (is_null($asso_id)) { $asso_id = $globals->asso('id'); } 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(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 e.asso_id = {?}' . $where . ' GROUP BY ' . $group_by, $eid, $eid, $asso_id); if (!$evt) { return null; } if ($GLOBALS['IS_XNET_SITE'] && $evt['accept_nonmembre'] == 0 && !is_member() && !may_update()) { return false; } if (!$item_id) { /* 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, ep.paid, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment FROM group_event_items AS ei LEFT JOIN group_event_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id AND uid = {?}) WHERE ei.eid = {?}', S::i('uid'), $evt['eid']); $evt['topay'] = 0; $evt['paid'] = 0; $evt['notify_payment'] = false; foreach ($evt['moments'] as $m) { $evt['topay'] += $m['nb'] * $m['montant']; if ($m['montant']) { $evt['money'] = true; } $evt['paid'] += $m['paid']; $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } $montant = XDB::fetchOneCell('SELECT SUM(amount) AS sum_amount FROM payment_transactions AS t WHERE status = "confirmed" AND ref = {?} AND uid = {?}', $evt['paiement_id'], S::v('uid')); $evt['telepaid'] = $montant; $evt['paid'] += $montant; $evt['organizer'] = User::getSilent($evt['uid']); $evt['date'] = make_event_date($evt['debut'], $evt['fin']); $evt['show_participants'] = $evt['show_participants'] && $GLOBALS['IS_XNET_SITE'] && (is_member() || may_update()); return $evt; }
function handler_events($page, $archive = null) { global $globals; $page->changeTpl('xnetevents/index.tpl'); $this->load('xnetevents.inc.php'); $action = null; $archive = $archive == 'archive' && may_update(); if (Post::has('del')) { $action = 'del'; $eid = Post::v('del'); } elseif (Post::has('archive')) { $action = 'archive'; $eid = Post::v('archive'); } elseif (Post::has('unarchive')) { $action = 'unarchive'; $eid = Post::v('unarchive'); } if (!is_null($action)) { if (!may_update()) { return PL_FORBIDDEN; } S::assert_xsrf_token(); $res = XDB::query("SELECT asso_id, short_name FROM group_events\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); $tmp = $res->fetchOneRow(); if (!$tmp) { return PL_FORBIDDEN; } } if ($action == 'del') { // deletes the event mailing aliases if ($tmp[1]) { require_once 'emails.inc.php'; foreach (explode(',', $globals->xnet->event_lists) as $suffix) { delete_list_alias($tmp[1] . $suffix, $globals->xnet->evts_domain, 'event'); } } // archive le paiement associƩ si il existe $pay_id = XDB::fetchOneCell("SELECT paiement_id\n FROM group_events\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); if (!$pay_id == '') { XDB::execute("UPDATE payments\n SET flags = 'old'\n WHERE id = {?}", $pay_id); } // deletes the event items XDB::execute('DELETE FROM group_event_items WHERE eid = {?}', $eid); // deletes the event participants XDB::execute('DELETE FROM group_event_participants WHERE eid = {?}', $eid); // deletes the event XDB::execute('DELETE FROM group_events WHERE eid = {?} AND asso_id = {?}', $eid, $globals->asso('id')); // delete the requests for payments XDB::execute("DELETE FROM requests\n WHERE type = 'paiements' AND data LIKE {?}", PayReq::same_event($eid, $globals->asso('id'))); $globals->updateNbValid(); } if ($action == 'archive') { $pay_id = XDB::fetchOneCell("SELECT paiement_id \n FROM group_events\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); if (!$pay_id == '') { XDB::execute("UPDATE payments\n SET flags = 'old'\n WHERE id = {?}", $pay_id); } XDB::execute("UPDATE group_events\n SET archive = 1\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); } if ($action == 'unarchive') { $pay_id = XDB::fetchOneCell("SELECT paiement_id FROM group_events\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); if (!$pay_id == '') { XDB::execute("UPDATE payments\n SET flags = ''\n WHERE id = {?}", $pay_id); } XDB::execute("UPDATE group_events\n SET archive = 0\n WHERE eid = {?} AND asso_id = {?}", $eid, $globals->asso('id')); } $page->assign('archive', $archive); if (Post::has('order')) { $order = Post::v('order'); XDB::execute("UPDATE groups\n SET event_order = {?}\n WHERE id = {?}", $order, $globals->asso('id')); } $order = get_event_order($globals->asso('id')); $evts = get_events($globals->asso('id'), $order, $archive); $page->assign('order', $order); $undisplayed_events = 0; foreach ($evts as $eid => &$e) { if (!is_member() && !may_update() && !$e['accept_nonmembre']) { $undisplayed_events++; continue; } $e['show_participants'] = $e['show_participants'] && (is_member() || may_update()); $e['items'] = get_event_items($eid); $e['topay'] = 0; $e['paid'] = 0; $sub = get_event_subscription($eid, S::i('uid')); if (empty($sub)) { $e['inscrit'] = false; } else { $e['inscrit'] = true; foreach ($e['items'] as $item_id => $m) { if (isset($sub[$item_id])) { $e['topay'] += $sub[$item_id]['nb'] * $m['montant']; $e['paid'] += $sub[$item_id]['paid']; } } } $e['sub'] = $sub; $telepaid = get_event_telepaid($eid, S::i('uid')); $e['paid'] += $telepaid; $e['date'] = make_event_date($e['debut'], $e['fin']); if ($e['deadline_inscription'] == null || strtotime($e['deadline_inscription']) >= time()) { $e['inscr_open'] = true; } else { $e['inscr_open'] = false; } if (Env::has('updated') && $e['eid'] == Env::i('updated')) { $page->assign('updated', $e); } } $page->assign('evenements', $evts); $page->assign('undisplayed_events', $undisplayed_events); }