// Continue only if the proper extension is active (admins can always continue)
if ((!isExtensionActive('coupon')) && (!isAdmin())) {
- displayMessage(generateExtensionInactiveNotInstalledMessage('coupon'));
+ displayMessage('{%pipe,generateExtensionInactiveNotInstalledMessage=coupon%}');
return;
} // END - if
} // END - if
// Now we just need to book that points on the user's account
- addPointsThroughReferalSystem('coupon_cashed', getMemberId(), $content['points'], false, 0, getConfig('coupon_payment_method'));
+ initReferalSystem();
+ addPointsThroughReferalSystem('coupon_cashed', getMemberId(), $content['points']);
// Subtract points from member account if the admin has selected one
if (isValidUserId(getConfig('coupon_userid'))) {
- // Subtract from this account
+ // Subtract from this account and ignore return status
subtractPoints('cashed_coupon', getConfig('coupon_userid'), $content['points']);
} // END - if
sendAdminNotification('{--ADMIN_COUPON_CASHED_SUBJECT--}', 'admin_coupon_cashed', $content, getMemberId());
// Display message
- displayMessage(getMaskedMessage('MEMBER_COUPON_CODE_CASHED', $content['points']));
+ displayMessage('{%message,MEMBER_COUPON_CODE_CASHED=' . $content['points'] . '%}');
} else {
// No coupon found
displayMessage('{--MEMBER_COUPON_CODE_ALREADY_CASHED--}');
// No code entered!
displayMessage('{--MEMBER_COUPON_CODE_EMPTY--}');
}
+} elseif (isFormSent('change')) {
+ // Change receive status, depending on its current state
+ if (isUserDataEnabled('receiving_coupons')) {
+ // Unsubscribe from coupons
+ $message = '{--MEMBER_COUPON_RECEIVE_STATUS_UNSUBSCRIBED--}';
+ $newStatus = 'N';
+ } else {
+ // Subscribe to coupons
+ $message = '{--MEMBER_COUPON_RECEIVE_STATUS_SUBSCRIBED--}';
+ $newStatus = 'Y';
+ }
+
+ // And change it in the database
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receiving_coupons`='%s' WHERE `userid`=%s LIMIT 1",
+ array($newStatus, getMemberId()), __FILE__, __LINE__);
+
+ // Did something change?
+ if (!SQL_HASZEROAFFECTED()) {
+ // Records have been updated
+ displayMessage($message);
+ } else {
+ // Nothing changed!
+ displayMessage('{--MEMBER_COUPON_RECEIVE_STATUS_UNCHANGED--}');
+ }
} else {
// Load form template
loadTemplate('member_cash_coupon', false);