]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/member/what-cash_coupon.php
A lot has been rewritten, ext-teams added, ext-forced continued:
[mailer.git] / inc / modules / member / what-cash_coupon.php
index 90280846df88b3def065737e16b1e4f0a7a11d33..bbc77f1aabeb68e5254e682fca838b748b5d9e72 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * Mailer v0.2.1-FINAL                                Start: 28/06/2011 *
- * ===================                          Last change: 28/06/2011 *
+ * Mailer v0.2.1-FINAL                                Start: 06/28/2011 *
+ * ===================                          Last change: 06/28/2011 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : what-cash_coupon.php                             *
@@ -47,7 +47,7 @@ addYouAreHereLink('member', __FILE__);
 
 // 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
 
@@ -62,7 +62,7 @@ if (isFormSent()) {
        UNIX_TIMESTAMP(d.`coupon_expired`) AS `coupon_expired`,
        d.`coupon_type`,
        d.`total_created`,
-       d.`total_used`,
+       d.`total_cashed`,
        d.`points`,
        d.`coupon_description`
 FROM
@@ -109,7 +109,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?
@@ -119,11 +119,12 @@ LIMIT 1",
                        } // 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
 
@@ -135,10 +136,10 @@ LIMIT 1",
                        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_USED--}');
+                       displayMessage('{--MEMBER_COUPON_CODE_ALREADY_CASHED--}');
                }
 
                // Free the result
@@ -147,6 +148,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);