if ($eid = $res->fetchOneCell()) {
require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php';
$evt = get_event_detail($eid);
- subscribe_lists_event(0, $uid, $evt, $montant, true);
+ subscribe_lists_event($uid, $evt, 1, $montant, true);
}
/* on genere le mail de confirmation */
if ($eid = $res->fetchOneCell()) {
require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php';
$evt = get_event_detail($eid);
- subscribe_lists_event(0, $user->id(), $evt, $montant, true);
+ subscribe_lists_event($user->id(), $evt, 1, $montant, true);
}
/* on genere le mail de confirmation */
if ($eid = $res->fetchOneCell()) {
require_once dirname(__FILE__) . '/xnetevents/xnetevents.inc.php';
$evt = get_event_detail($eid);
- subscribe_lists_event(0, $uid, $evt, $montant, true);
+ subscribe_lists_event($user->id(), $evt, 1, $montant, true);
}
/* on genere le mail de confirmation */
}
if ($updated !== false) {
$page->trigSuccess('Ton inscription à l\'événement a été mise à jour avec succès.');
- subscribe_lists_event($total, S::i('uid'), $evt, $paid);
+ subscribe_lists_event(S::i('uid'), $evt, ($total > 0 ? 1 : 0), 0);
}
$page->assign('event', get_event_detail($eid));
}
// change the price paid by a participant
if (Env::v('adm') == 'prix' && $member) {
+ $amount = strtr(Env::v('montant'), ',', '.');
XDB::execute("UPDATE group_event_participants
SET paid = paid + {?}
WHERE uid = {?} AND eid = {?} AND item_id = 1",
- strtr(Env::v('montant'), ',', '.'),
- $member->uid, $evt['eid']);
+ $amount, $member->uid, $evt['eid']);
+ subscribe_lists_event($member->uid, $evt, 1, $amount);
}
// change the number of personns coming with a participant
foreach ($nbs as $id => $nb) {
$nb = max(intval($nb), 0);
- XDB::execute("REPLACE INTO group_event_participants
- VALUES ({?}, {?}, {?}, {?}, {?}, {?})",
- $evt['eid'], $member->uid, $id, $nb, '', $id == 1 ? $paid : 0);
+ XDB::execute('REPLACE INTO group_event_participants
+ VALUES ({?}, {?}, {?}, {?}, {?}, {?})',
+ $evt['eid'], $member->uid, $id, $nb, '', $id == 1 ? $paid : 0);
}
- $res = XDB::query("SELECT COUNT(uid) AS cnt, SUM(nb) AS nb
- FROM group_event_participants
- WHERE uid = {?} AND eid = {?}
- GROUP BY uid",
- $member->uid, $evt['eid']);
+ $res = XDB::query('SELECT COUNT(uid) AS cnt, SUM(nb) AS nb
+ FROM group_event_participants
+ WHERE uid = {?} AND eid = {?}
+ GROUP BY uid',
+ $member->uid, $evt['eid']);
$u = $res->fetchOneAssoc();
if ($u['cnt'] == 1 && $paid == 0 && Post::v('cancel')) {
XDB::execute("DELETE FROM group_event_participants
WHERE uid = {?} AND eid = {?}",
$member->uid, $evt['eid']);
$u = 0;
+ subscribe_lists_event($member->uid, $evt, -1, $paid);
} else {
+ var_dump($u);
$u = $u['cnt'] ? $u['nb'] : null;
+ subscribe_lists_event($member->uid, $evt, ($u > 0 ? 1 : 0), $paid);
}
- subscribe_lists_event($u, $member->uid, $evt, $paid);
}
$evt = get_event_detail($eid, $item_id);
// }}}
// {{{ 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 evt: events data, in particular ids of the lists at stake.
+ * @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, $evt, $participate, $paid, $payment = false)
{
- global $globals;
- $page =& Platal::page();
-
$participant_list = $evt['participant_list'];
$absent_list = $evt['absent_list'];
$unpayed_list = $evt['booked_unpayed_list'];
function subscribe($list, $email)
{
if ($list && $email) {
- XDB::execute("REPLACE INTO virtual_redirect
- VALUES ({?},{?})",
+ XDB::execute('REPLACE INTO virtual_redirect
+ VALUES ({?}, {?})',
$list, $email);
}
}
function unsubscribe($list, $email)
{
if ($list && $email) {
- XDB::execute("DELETE FROM virtual_redirect
- WHERE vid = {?} AND redirect = {?}",
+ XDB::execute('DELETE FROM virtual_redirect
+ WHERE vid = {?} AND redirect = {?}',
$list, $email);
}
}
- if (is_null($payment)) {
- if (is_null($participate)) {
+ /** 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) {
+ unsubscribe($unpayed_list, $email);
+ subscribe($payed_list, $email);
+ }
+ } else {
+ switch ($participate) {
+ case -1:
unsubscribe($participant_list, $email);
+ unsubscribe($unpayed_list, $email);
+ unsubscribe($payed_list, $email);
subscribe($absent_list, $email);
- } elseif ($participate) {
- subscribe($participant_list, $email);
- unsubscribe($absent_list, $email);
- } else {
+ break;
+ case 0:
unsubscribe($participant_list, $email);
unsubscribe($absent_list, $email);
- }
- }
- if ($paid > 0) {
- unsubscribe($unpayed_list, $email);
- subscribe($payed_list, $email);
- } else {
- unsubscribe($payed_list, $email);
- if (!is_null($participate)) {
- subscribe($unpayed_list, $email);
+ unsubscribe($unpayed_list, $email);
+ unsubscribe($payed_list, $email);
+ break;
+ case 1:
+ subscribe($participant_list, $email);
+ unsubscribe($absent_list, $email);
+ if ($paid > 0) {
+ unsubscribe($unpayed_list, $email);
+ subscribe($payed_list, $email);
+ } else {
+ subscribe($unpayed_list, $email);
+ unsubscribe($payed_list, $email);
+ }
+ break;
}
}
}