X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Fmodules%2Fmember%2Fwhat-cash_coupon.php;h=dc1edff917513fbf0c30167bdabd73353eb4e613;hb=bb70f91b5535a0e21dba8098ba8f9af83ada9073;hp=3e538b9aa21049411afda73987580e8fcad47e58;hpb=43918668518996fcf51f360bcd0d2690427d53a9;p=mailer.git diff --git a/inc/modules/member/what-cash_coupon.php b/inc/modules/member/what-cash_coupon.php index 3e538b9aa2..dc1edff917 100644 --- a/inc/modules/member/what-cash_coupon.php +++ b/inc/modules/member/what-cash_coupon.php @@ -16,8 +16,8 @@ * $Author:: $ * * -------------------------------------------------------------------- * * Copyright (c) 2003 - 2009 by Roland Haeder * - * Copyright (c) 2009 - 2011 by Mailer Developer Team * - * For more information visit: http://www.mxchange.org * + * Copyright (c) 2009 - 2013 by Mailer Developer Team * + * For more information visit: http://mxchange.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -37,7 +37,7 @@ // Some security stuff... if (!defined('__SECURITY')) { - die(); + exit(); } elseif (!isMember()) { redirectToIndexMemberOnlyModule(); } @@ -54,41 +54,46 @@ if ((!isExtensionActive('coupon')) && (!isAdmin())) { // Is the form sent? if (isFormSent()) { // Is the coupon code entered? - if (isPostRequestParameterSet('coupon_code')) { + if (isPostRequestElementSet('coupon_code')) { // Search for the coupon - $result = SQL_QUERY_ESC("SELECT - c.`coupon_id`, - UNIX_TIMESTAMP(d.`coupon_created`) AS `coupon_created`, - UNIX_TIMESTAMP(d.`coupon_expired`) AS `coupon_expired`, - d.`coupon_type`, - d.`total_created`, - d.`total_cashed`, - d.`points`, - d.`coupon_description` + $result = sqlQueryEscaped("SELECT + `c`.`coupon_id`, + `c`.`userid`, + `c`.`coupon_code`, + UNIX_TIMESTAMP(`d`.`coupon_created`) AS `coupon_created`, + UNIX_TIMESTAMP(`d`.`coupon_expired`) AS `coupon_expired`, + `d`.`coupon_type`, + `d`.`total_created`, + `d`.`total_cashed`, + `d`.`points`, + `d`.`coupon_description` FROM - `{?_MYSQL_PREFIX?}_user_coupons` AS c + `{?_MYSQL_PREFIX?}_user_coupons` AS `c` INNER JOIN - `{?_MYSQL_PREFIX?}_coupon_data` AS d + `{?_MYSQL_PREFIX?}_coupon_data` AS `d` ON - c.`coupon_id`=d.`id` + `c`.`coupon_id`=`d`.`id` WHERE - c.`coupon_code`='%s' AND - c.`userid`=%s AND - c.`cashed_on` IS NULL AND - UNIX_TIMESTAMP(d.`coupon_expired`) > UNIX_TIMESTAMP() + `c`.`coupon_code`='%s' AND + `c`.`userid`=%s AND + `c`.`cashed_on` IS NULL AND + UNIX_TIMESTAMP(`d`.`coupon_expired`) > UNIX_TIMESTAMP() LIMIT 1", array( - postRequestParameter('coupon_code'), + postRequestElement('coupon_code'), getMemberId() ), __FILE__, __LINE__); - // Do we have an entry? - if (SQL_NUMROWS($result) == 1) { + // Is there an entry? + if (sqlNumRows($result) == 1) { // Load data - $content = SQL_FETCHARRAY($result); + $content = sqlFetchArray($result); + + // Run pre-filter + $content = runFilterChain('pre_cash_coupon', $content); // Mark it as "cashed" - SQL_QUERY_ESC("UPDATE + sqlQueryEscaped("UPDATE `{?_MYSQL_PREFIX?}_user_coupons` SET `cashed_on`=NOW(), @@ -98,41 +103,28 @@ WHERE `userid`=%s LIMIT 1", array( - postRequestParameter('coupon_code'), + postRequestElement('coupon_code'), getMemberId() ), __FILE__, __LINE__); // Does it work? - if (SQL_HASZEROAFFECTED()) { + if (ifSqlHasZeroAffectedRows()) { // Abort it here, it always must work - debug_report_bug(__FILE__, __LINE__, 'User coupon cannot be updated! coupon_id=' . $content['coupon_id']); + reportBug(__FILE__, __LINE__, 'User coupon cannot be updated! coupon_id=' . $content['coupon_id']); } // END - if // Update count as well - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_coupon_data` SET `total_cashed`=`total_cashed`+1 WHERE `id`=%s AND `total_cashed` < `total_created` LIMIT 1", + 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 (SQL_HASZEROAFFECTED()) { + if (ifSqlHasZeroAffectedRows()) { // Abort it here, it always must work - debug_report_bug(__FILE__, __LINE__, 'Coupon data cannot be updated! coupon_id=' . $content['coupon_id']); + reportBug(__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, getPaymentMethodFromExtensionName('coupon')); - - // 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('{%message,MEMBER_COUPON_CODE_CASHED=' . $content['points'] . '%}'); @@ -142,7 +134,7 @@ LIMIT 1", } // Free the result - SQL_FREERESULT($result); + sqlFreeResult($result); } else { // No code entered! displayMessage('{--MEMBER_COUPON_CODE_EMPTY--}'); @@ -160,11 +152,11 @@ LIMIT 1", } // And change it in the database - SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `receiving_coupons`='%s' WHERE `userid`=%s LIMIT 1", + sqlQueryEscaped("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()) { + if (!ifSqlHasZeroAffectedRows()) { // Records have been updated displayMessage($message); } else { @@ -173,7 +165,7 @@ LIMIT 1", } } else { // Load form template - loadTemplate('member_cash_coupon', false); + loadTemplate('member_cash_coupon', FALSE); } // [EOF]