X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-cash_coupon.php;h=7718abc36c28129a9caedd600ecc945f5b372ca2;hb=f6014bce7255a915872f2f463247440c0d58f9a9;hp=90280846df88b3def065737e16b1e4f0a7a11d33;hpb=5c4d360166de238420eec3e5f4e694befb09ab5d;p=mailer.git diff --git a/inc/modules/member/what-cash_coupon.php b/inc/modules/member/what-cash_coupon.php index 90280846df..7718abc36c 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( - postRequestParameter('coupon_code'), + postRequestElement('coupon_code'), getMemberId() ), __FILE__, __LINE__); @@ -87,6 +89,9 @@ LIMIT 1", // Load data $content = SQL_FETCHARRAY($result); + // Run pre-filter + $content = runFilterChain('pre_cash_coupon', $content); + // Mark it as "cashed" SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_coupons` @@ -98,7 +103,7 @@ WHERE `userid`=%s LIMIT 1", array( - postRequestParameter('coupon_code'), + postRequestElement('coupon_code'), getMemberId() ), __FILE__, __LINE__); @@ -109,7 +114,7 @@ LIMIT 1", } // END - if // Update count as well - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_coupon_data` SET `total_used`=`total_used`+1 WHERE `id`=%s AND `total_used` < `total_created` LIMIT 1", + SQL_QUERY_ESC("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? @@ -118,27 +123,14 @@ LIMIT 1", debug_report_bug(__FILE__, __LINE__, 'Coupon data cannot be updated! coupon_id=' . $content['coupon_id']); } // 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')); - - // Subtract points from member account if the admin has selected one - if (isValidUserId(getConfig('coupon_userid'))) { - // Subtract from this account - subtractPoints('cashed_coupon', getConfig('coupon_userid'), $content['points']); - } // END - if - - // Translate some data - $content['coupon_expired'] = generateDateTime($content['coupon_expired'], '0'); - $content['coupon_created'] = generateDateTime($content['coupon_created'], '0'); - - // Send admin notification - sendAdminNotification('{--ADMIN_COUPON_CASHED_SUBJECT--}', 'admin_coupon_cashed', $content, getMemberId()); + // Run post filter chain + $content = runFilterChain('post_cash_coupon', $content); // 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_USED--}'); + displayMessage('{--MEMBER_COUPON_CODE_ALREADY_CASHED--}'); } // Free the result @@ -147,6 +139,30 @@ LIMIT 1", // 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);