mailer project continued:
[mailer.git] / inc / modules / admin / what-send_coupon.php
index 469329ba74ed1f08ef0e9c234312b8d6285d8979..9cfb2f5607b754d7bd33a9d1abf5e9c6acaa2e20 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
+ * Copyright (c) 2009 - 2012 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -54,11 +54,20 @@ if (isFormSent()) {
                displayMessage('{--ADMIN_SEND_COUPON_DESCRIPTION_NOT_ENTERED--}');
        } else {
                // All fields are set, so we can start looking for users who wants to receive coupons
-               $result = SQL_QUERY("SELECT `userid` FROM `{?_MYSQL_PREFIX?}_user_data` WHERE `status`='CONFIRMED' AND `receiving_coupons`='Y' ORDER BY `userid` ASC",
+               $result = SQL_QUERY("SELECT
+       `userid`
+FROM
+       `{?_MYSQL_PREFIX?}_user_data`
+WHERE
+       `status`='CONFIRMED' AND
+       `receiving_coupons`='Y'
+       " . runFilterChain('user_exclusion_sql', ' ') . "
+ORDER BY
+       `userid` ASC",
                        __FILE__, __LINE__);
 
                // Do we have entries left?
-               if (SQL_NUMROWS($result) > 0) {
+               if (!SQL_HASZERONUMS($result)) {
                        // Convert timestamp selections
                        $expirationTime = time() + createEpocheTimeFromSelections('coupon_default_time', postRequestArray());
 
@@ -88,7 +97,7 @@ if (isFormSent()) {
                                         * table-unique "id". The function generatePassword() can do
                                         * this job for us but we want to exclude some characters.
                                         */
-                                       $couponCode = generatePassword(30, array('-','+','_','/','.'));
+                                       $couponCode = generatePassword(30, array('-', '+', '_', '/', '.'));
 
                                        // Is it really unique?
                                        $isUnique = (countSumTotalData($couponCode, 'user_coupons', 'id', 'coupon_code', true) == 0);
@@ -96,7 +105,11 @@ if (isFormSent()) {
 
                                // The above loop should always set $couponCode, so we can now insert it
                                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_user_coupons` (`coupon_id`,`userid`,`coupon_code`) VALUES (%s,%s,'%s')",
-                                       array($couponId, $userid, $couponCode), __FILE__, __LINE__);
+                                       array(
+                                               $couponId,
+                                               $userid,
+                                               $couponCode
+                                       ), __FILE__, __LINE__);
 
                                // Fill array with all required data
                                $content = array(
@@ -114,7 +127,7 @@ if (isFormSent()) {
                                sendEmail($userid, '{--MEMBER_COUPON_SUBJECT--}', $mailText);
 
                                // Rember this user for the admin email
-                               $adminUserids[] = $userid;
+                               array_push($adminUserids, $userid);
                        } // END - while
 
                        // Prepare content for template