X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-cash_coupon.php;h=dc1edff917513fbf0c30167bdabd73353eb4e613;hb=5f70ac9d208ca39e3381705afcad2654a700a850;hp=2984ec788dcf755dd9cdcc11c4fc297514455573;hpb=2e394cb5b8a6225a39a6942b1fcc17c37a17a175;p=mailer.git diff --git a/inc/modules/member/what-cash_coupon.php b/inc/modules/member/what-cash_coupon.php index 2984ec788d..dc1edff917 100644 --- a/inc/modules/member/what-cash_coupon.php +++ b/inc/modules/member/what-cash_coupon.php @@ -1,7 +1,7 @@ UNIX_TIMESTAMP() +LIMIT 1", + array( + postRequestElement('coupon_code'), + getMemberId() + ), __FILE__, __LINE__); + + // Is there an entry? + if (sqlNumRows($result) == 1) { + // Load data + $content = sqlFetchArray($result); + + // Run pre-filter + $content = runFilterChain('pre_cash_coupon', $content); + + // Mark it as "cashed" + sqlQueryEscaped("UPDATE + `{?_MYSQL_PREFIX?}_user_coupons` +SET + `cashed_on`=NOW(), + `coupon_code`=NULL +WHERE + `coupon_code`='%s' AND + `userid`=%s +LIMIT 1", + array( + postRequestElement('coupon_code'), + getMemberId() + ), __FILE__, __LINE__); + + // Does it work? + if (ifSqlHasZeroAffectedRows()) { + // Abort it here, it always must work + reportBug(__FILE__, __LINE__, 'User coupon cannot be updated! coupon_id=' . $content['coupon_id']); + } // END - if + + // Update count as well + sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_coupon_data` SET `total_cashed`=`total_cashed`+1 WHERE `id`=%s AND `total_cashed` < `total_created` LIMIT 1", + array(bigintval($content['coupon_id'])), __FILE__, __LINE__); + + // Does it work? + if (ifSqlHasZeroAffectedRows()) { + // Abort it here, it always must work + reportBug(__FILE__, __LINE__, 'Coupon data cannot be updated! coupon_id=' . $content['coupon_id']); + } // END - if + + // Run post filter chain + $content = runFilterChain('post_cash_coupon', $content); + + // Display message + displayMessage('{%message,MEMBER_COUPON_CODE_CASHED=' . $content['points'] . '%}'); + } else { + // No coupon found + displayMessage('{--MEMBER_COUPON_CODE_ALREADY_CASHED--}'); + } + + // Free the result + sqlFreeResult($result); + } else { + // 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 + sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receiving_coupons`='%s' WHERE `userid`=%s LIMIT 1", + array($newStatus, getMemberId()), __FILE__, __LINE__); + + // Did something change? + if (!ifSqlHasZeroAffectedRows()) { + // Records have been updated + displayMessage($message); + } else { + // Nothing changed! + displayMessage('{--MEMBER_COUPON_RECEIVE_STATUS_UNCHANGED--}'); + } } else { // Load form template - loadTemplate('member_cash_coupon', false); + loadTemplate('member_cash_coupon', FALSE); } // [EOF]