]> git.mxchange.org Git - mailer.git/blobdiff - inc/modules/admin/what-send_coupon.php
Renamed all SQL-related functions to camel-case notation
[mailer.git] / inc / modules / admin / what-send_coupon.php
index 262a4c8c73eaa4021217515f8f3929032fef0435..6b60506570c435def1d34685c92e99eb42f71139 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 - 2013 by Mailer Developer Team                   *
  * For more information visit: http://mxchange.org                      *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -54,49 +54,68 @@ 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 = sqlQuery("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) {
+               // Are there entries left?
+               if (!ifSqlHasZeroNums($result)) {
                        // Convert timestamp selections
                        $expirationTime = time() + createEpocheTimeFromSelections('coupon_default_time', postRequestArray());
 
                        // Insert coupon data
-                       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_coupon_data` (`coupon_expired`,`total_created`,`points`,`coupon_description`) VALUES ('{%%pipe,SQL_EPOCHE_TO_TIMESTAMP=%s%%}', %s,%s,'%s')",
+                       sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_coupon_data` (`coupon_expired`, `total_created`, `points`, `coupon_description`) VALUES ('{%%pipe,SQL_EPOCHE_TO_TIMESTAMP=%s%%}', %s,%s,'%s')",
                                array(
                                        $expirationTime,
-                                       SQL_NUMROWS($result),
+                                       sqlNumRows($result),
                                        bigintval(postRequestElement('points')),
                                        postRequestElement('coupon_description')
                                ), __FILE__, __LINE__
                        );
 
                        // Get the insert id from the table
-                       $couponId = SQL_INSERTID();
+                       $couponId = getSqlInsertId();
+
+                       // Init userid array
+                       $adminUserids = array();
 
                        // Load entry
-                       while (list($userid) = SQL_FETCHROW($result)) {
+                       while (list($userid) = sqlFetchRow($result)) {
+                               // Debug message
+                               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'NUMS=' . SQL_NUMROWS($result) . ',userid=' . $userid);
+
                                // By default no code is unique
-                               $isUnique = false;
+                               $isUnique = FALSE;
                                $couponCode = '';
 
                                // Look for a unique id
                                while (!$isUnique) {
-                                       /**
-                                        * Add a coupon for this user, first we need to create a
-                                        * table-unique "id". The function generatePassword() can do
-                                        * this job for us but we want to exclude some characters.
+                                       /*
+                                        * Add a coupon for this user, first generate a
+                                        * "table-unique" id number. generatePassword() can do this
+                                        * but with some characters excluded.
                                         */
-                                       $couponCode = generatePassword(30, array('-','+','_','/','.'));
+                                       $couponCode = generatePassword(30, array('-', '+', '_', '/', '.'));
 
                                        // Is it really unique?
-                                       $isUnique = (countSumTotalData($couponCode, 'user_coupons', 'id', 'coupon_code', true) == 0);
+                                       $isUnique = (countSumTotalData($couponCode, 'user_coupons', 'id', 'coupon_code', TRUE) == 0);
                                } // END - while
 
                                // 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__);
+                               sqlQueryEscaped("INSERT INTO `{?_MYSQL_PREFIX?}_user_coupons` (`coupon_id`, `userid`, `coupon_code`) VALUES (%s,%s,'%s')",
+                                       array(
+                                               $couponId,
+                                               $userid,
+                                               $couponCode
+                                       ), __FILE__, __LINE__);
 
                                // Fill array with all required data
                                $content = array(
@@ -114,7 +133,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
@@ -138,14 +157,14 @@ if (isFormSent()) {
                }
 
                // Free result
-               SQL_FREERESULT($result);
+               sqlFreeResult($result);
        }
 } else {
        // Prepare some template data
        $content['coupon_default_time_selection'] = createConfigurationTimeSelections('coupon_default_time', 'WDh');
 
        // Load template
-       loadTemplate('admin_send_coupon', false, $content);
+       loadTemplate('admin_send_coupon', FALSE, $content);
 }
 
 // [EOF]