X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=modules%2Fxnetevents%2Fxnetevents.inc.php;h=f329ad1a17362ba053d98d70f72117fc75a42899;hb=9f3f87bc8e2fc21c6b160f0db67bfd1b52d40007;hp=fe8fc4a132c7ee4251b5cf05b05d4cb659f20352;hpb=353f2d2b11c4e3c6c0bc3553813368b6f42fa9c6;p=platal.git diff --git a/modules/xnetevents/xnetevents.inc.php b/modules/xnetevents/xnetevents.inc.php index fe8fc4a..f329ad1 100644 --- a/modules/xnetevents/xnetevents.inc.php +++ b/modules/xnetevents/xnetevents.inc.php @@ -1,6 +1,6 @@ asso('id'); } - $res = XDB::query('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, - 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(NOW(), 10) AS now, - ei.titre, al.vid AS absent_list, pl.vid AS participant_list - FROM #groupex#.evenements AS e - INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid) - LEFT JOIN #groupex#.evenements_participants AS ep ON(e.eid = ep.eid AND ei.item_id = ep.item_id) - LEFT JOIN #x4dat#.virtual AS al ON(al.type = \'evt\' AND al.alias = CONCAT(short_name, {?})) - LEFT JOIN #x4dat#.virtual AS pl ON(pl.type = \'evt\' AND pl.alias = CONCAT(short_name, {?})) - WHERE (e.eid = {?} OR e.short_name = {?}) AND ei.item_id = {?} AND e.asso_id = {?} - GROUP BY ei.item_id', - '-absents@'.$globals->xnet->evts_domain, - '-participants@'.$globals->xnet->evts_domain, - '-paye@' . $globals->xnet->evts_domain, - '-participants-non-paye@' . $globals->xnet->evts_domain, - $eid, $eid, $item_id ? $item_id : 1, $asso_id); - $evt = $res->fetchOneAssoc(); + $evt = XDB::fetchOneAssoc('SELECT SUM(nb) AS nb_tot, COUNT(DISTINCT ep.uid) AS nb, e.*, + 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(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); if (!$evt) { return null; @@ -58,9 +51,9 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) // smart calculation of the total number if (!$item_id) { $res = XDB::query('SELECT MAX(nb) - FROM #groupex#.evenements AS e - INNER JOIN #groupex#.evenements_items AS ei ON (e.eid = ei.eid) - LEFT JOIN #groupex#.evenements_participants AS ep ON (e.eid = ep.eid AND ei.item_id = ep.item_id) + 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()); @@ -70,8 +63,8 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $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 #groupex#.evenements_items AS ei - LEFT JOIN #groupex#.evenements_participants AS ep ON (ep.eid = ei.eid AND ep.item_id = ei.item_id + 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']); @@ -87,8 +80,8 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['notify_payment'] = $evt['notify_payment'] || $m['notify_payment']; } - $montants = XDB::fetchColumn('SELECT montant - FROM ' . $globals->money->mpay_tprefix . 'transactions AS t + $montants = XDB::fetchColumn('SELECT amount + FROM payment_transactions AS t WHERE ref = {?} AND uid = {?}', $evt['paiement_id'], S::v('uid')); $evt['telepaid'] = 0; @@ -97,6 +90,7 @@ function get_event_detail($eid, $item_id = false, $asso_id = null) $evt['paid'] += trim($p); $evt['telepaid'] += trim($p); } + $evt['organizer'] = User::getSilent($evt['uid']); make_event_date($evt); @@ -106,7 +100,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(), $count = null, $offset = null) +function get_event_participants(&$evt, $item_id, array $tri = array(), $limit = null) { global $globals; @@ -114,14 +108,14 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = $money = $evt['money'] && (function_exists('may_update')) && may_update(); $pay_id = $evt['paiement_id']; - $append = $item_id ? XDB::foramt(' AND ep.item_id = {?}', $item_id) : ''; + $append = $item_id ? XDB::format(' AND ep.item_id = {?}', $item_id) : ''; $query = XDB::fetchAllAssoc('uid', 'SELECT ep.uid, SUM(ep.paid) AS paid, SUM(ep.nb) AS nb, FIND_IN_SET(\'notify_payment\', ep.flags) AS notify_payment - FROM #groupex#.evenements_participants AS ep + FROM group_event_participants AS ep WHERE ep.eid = {?} AND nb > 0 ' . $append . ' GROUP BY ep.uid', $eid); - $uf = new UserFilter(new UFC_True(), $tri); - $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), $count, $offset)); + $uf = new UserFilter(new PFC_True(), $tri); + $users = User::getBulkUsersWithUIDs($uf->filter(array_keys($query), new PlLimit($count, $offset))); $tab = array(); foreach ($users as $user) { $uid = $user->id(); @@ -141,8 +135,8 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = $u['adminpaid'] = $u['paid']; $u['montant'] = 0; if ($money && $pay_id) { - $montants = XDB::fetchColumn('SELECT montant - FROM ' . $globals->money->mpay_tprefix . 'transactions AS t + $montants = XDB::fetchColumn('SELECT amount + FROM payment_transactions AS t WHERE ref = {?} AND uid = {?}', $pay_id, $uid); foreach ($montants as $m) { @@ -152,8 +146,8 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = } $u['telepayment'] = $u['paid'] - $u['adminpaid']; $res_ = XDB::iterator('SELECT ep.nb, ep.item_id, ei.montant - FROM #groupex#.evenements_participants AS ep - INNER JOIN #groupex#.evenements_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) + FROM group_event_participants AS ep + INNER JOIN group_event_items AS ei ON (ei.eid = ep.eid AND ei.item_id = ep.item_id) WHERE ep.eid = {?} AND ep.uid = {?}', $eid, $uid); while ($i = $res_->next()) { @@ -170,71 +164,71 @@ function get_event_participants(&$evt, $item_id, array $tri = array(), $count = // }}} // {{{ function subscribe_lists_event() -function subscribe_lists_event($participate, $uid, $evt, $paid, $payment = null) +/** Subscribes user to various event related mailing lists. + * + * @param $uid: user's id. + * @param short_name: event's short_name, which corresponds to the beginning of the emails. + * @param participate: indicates if the user takes part at the event or not; + * -1 means he did not answer, 0 means no, and 1 means yes. + * @param paid: has the user already payed anything? + * 0 means no, a positive amount means yes. + * @param payment: is this function called from a payment page? + * If true, only payment related lists should be updated. + */ +function subscribe_lists_event($uid, $short_name, $participate, $paid, $payment = false) { global $globals; - $page =& Platal::page(); + require_once 'emails.inc.php'; - $participant_list = $evt['participant_list']; - $absent_list = $evt['absent_list']; - $unpayed_list = $evt['booked_unpayed_list']; - $payed_list = $evt['payed_list']; - - $user = User::getSilent($uid); - if ($user) { - $email = $user->forlifeEmail(); - } else { - $res = XDB::query("SELECT email - FROM #groupex#.membres - WHERE uid = {?} AND asso_id = {?}", - $uid, $globals->asso('id')); - $email = $res->fetchOneCell(); - } - - function subscribe($list, $email) - { - if ($list && $email) { - XDB::execute("REPLACE INTO virtual_redirect - VALUES ({?},{?})", - $list, $email); - } + if (is_null($short_name)) { + return; } - function unsubscribe($list, $email) - { - if ($list && $email) { - XDB::execute("DELETE FROM virtual_redirect - WHERE vid = {?} AND redirect = {?}", - $list, $email); - } - } + $user = User::getSilentWithUID($uid); - if (is_null($payment)) { - if (is_null($participate)) { - unsubscribe($participant_list, $email); - subscribe($absent_list, $email); - } elseif ($participate) { - subscribe($participant_list, $email); - unsubscribe($absent_list, $email); - } else { - unsubscribe($participant_list, $email); - unsubscribe($absent_list, $email); + /** If $payment is not null, we do not retrieve the value of $participate, + * thus we do not alter participant and absent lists. + */ + if ($payment === true) { + if ($paid > 0) { + delete_from_list_alias($user, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); + add_to_list_alias($user, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); } - } - if ($paid > 0) { - unsubscribe($unpayed_list, $email); - subscribe($payed_list, $email); } else { - unsubscribe($payed_list, $email); - subscribe($unpayed_list, $email); + switch ($participate) { + case -1: + delete_from_list_alias($user, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); + add_to_list_alias($user, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); + break; + case 0: + delete_from_list_alias($user, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); + break; + case 1: + add_to_list_alias($user, $short_name . $globals->xnet->participant_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); + if ($paid > 0) { + delete_from_list_alias($user, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); + add_to_list_alias($user, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); + } else { + add_to_list_alias($user, $short_name . $globals->xnet->unpayed_list, $globals->xnet->evts_domain, 'event'); + delete_from_list_alias($user, $short_name . $globals->xnet->payed_list, $globals->xnet->evts_domain, 'event'); + } + break; + } } } // }}} // {{{ function event_change_shortname() -function event_change_shortname(&$page, $eid, $old, $new) +function event_change_shortname($page, $eid, $old, $new) { global $globals; + require_once 'emails.inc.php'; if (is_null($old)) { $old = ''; @@ -246,7 +240,7 @@ function event_change_shortname(&$page, $eid, $old, $new) et qu'il ne contient que des lettres non accentuées, des chiffres ou les caractères - et ."); return $old; - } elseif ($new && ctype_digit($new)) { + } elseif ($new && (is_int($new) || ctype_digit($new))) { $page->trigError("Le raccourci demandé ne peut être accepté car il ne contient que des chiffres. Rajoute-lui par exemple une lettre."); @@ -256,7 +250,7 @@ function event_change_shortname(&$page, $eid, $old, $new) //vérifier que l'alias n'est pas déja pris if ($new && $old != $new) { $res = XDB::query('SELECT COUNT(*) - FROM #groupex#.evenements + FROM group_events WHERE short_name = {?}', $new); if ($res->fetchOneCell() > 0) { @@ -271,13 +265,13 @@ function event_change_shortname(&$page, $eid, $old, $new) if ($old && $new) { // if had a previous shortname change the old lists - foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) { - $v .= $globals->xnet->evts_domain; - XDB::execute("UPDATE virtual - SET alias = {?} - WHERE type = 'evt' AND alias = {?}", - $new . $v, $old . $v); + foreach (explode(',', $globals->xnet->event_lists) as $suffix) { + XDB::execute('UPDATE email_virtual + SET email = {?} + WHERE type = \'event\' AND email = {?}', + $new . $suffix, $old . $suffix); } + return $new; } @@ -285,52 +279,40 @@ function event_change_shortname(&$page, $eid, $old, $new) // if we have a first new short_name create the lists $lastid = array(); $where = array( - '-participants@' => 'ep.nb > 0', - '-paye@' => 'ep.paid > 0', - '-participants-non-paye@' => 'ep.nb > 0 AND ep.paid = 0' + $globals->xnet->participant_list => 'nb > 0', + $globals->xnet->payed_list => 'paid > 0', + $globals->xnet->unpayed_list => 'nb > 0 AND paid = 0' ); - foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) { - XDB::execute("INSERT INTO virtual - SET type = 'evt', alias = {?}", - $new . $v . $globals->xnet->evts_domain); - - $lastid[$v] = XDB::insertId(); + 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, + $eid); + $users = User::getBulkUsersWithUIDs($uids, null, null, false); + foreach ($users as $user) { + add_to_list_alias($user, $new . $suffix, $globals->xnet->evts_domain, 'event'); + } } - - foreach (array('-participants@', '-paye@', '-participants-non-paye@') as $v) { - XDB::execute("INSERT IGNORE INTO virtual_redirect ( - SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect - FROM #groupex#.evenements_participants AS ep - LEFT JOIN #x4dat#.accounts AS a ON (ep.uid = a.uid) - LEFT JOIN #x4dat#.aliases AS al ON (al.id = a.uid AND al.type = 'a_vie') - WHERE ep.eid = {?} AND " . $where[$v] . " - GROUP BY ep.uid)", - $lastid[$v], '@' . $globals->mail->domain, $eid); + $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 = {?}) + WHERE m.asso_id = {?} AND e.uid IS NULL', + $eid, $globals->asso('id')); + $users = User::getBulkUsersWithUIDs($uids, null, null, false); + foreach ($users as $user) { + add_to_list_alias($user, $new . $globals->xnet->absent_list, $globals->xnet->evts_domain, 'event'); } - XDB::execute("INSERT IGNORE INTO virtual_redirect ( - SELECT {?} AS vid, IF(al.alias IS NULL, a.email, CONCAT(al.alias, {?})) AS redirect - FROM #groupex#.membres AS m - LEFT JOIN #x4dat#.accounts AS a ON (a.uid = m.uid) - LEFT JOIN #x4dat#.aliases AS al ON (al.id = a.uid AND al.type = 'a_vie') - LEFT JOIN #groupex#.evenements_participants AS ep ON (ep.uid = m.uid AND ep.eid = {?}) - WHERE m.asso_id = {?} AND ep.uid IS NULL - GROUP BY m.uid)", - $lastid['-absents@'], '@' . $globals->mail->domain, $eid, $globals->asso('id')); return $new; } if ($old && !$new) { // if we delete the old short name, delete the lists - foreach (array('-absents@', '-participants@', '-paye@', '-participants-non-paye@') as $v) { - $v .= $globals->xnet->evts_domain; - XDB::execute("DELETE virtual, virtual_redirect - FROM virtual - LEFT JOIN virtual_redirect USING(vid) - WHERE virtual.alias = {?}", - $infos['short_name'] . $v); + foreach (explode(',', $globals->xnet->event_lists) as $suffix) { + delete_list_alias($old . $suffix, $globals->xnet->evts_domain); } + return $new; }