]> git.mxchange.org Git - mailer.git/blobdiff - inc/filter/order_filter.php
Rewrites to use filters instead of mass if() blocks
[mailer.git] / inc / filter / order_filter.php
index 3fd044f61466cf061e60cec7d01bdbee8240a820..ef5dbb457ffe3b1501dd6c9a88068058c13b97fa 100644 (file)
@@ -82,17 +82,30 @@ function FILTER_GET_ALL_ORDER_POINTS_COLUMN_NAMES ($filterData) {
 // Filter for ZIP code inclusion (not exclusion but it must be run in exclusion filter chain)
 function FILTER_ORDER_ZIP_CODE_SQL ($sql) {
        // Check if category and number of receivers is okay
-       if ((isOrderMultiPageEnabled()) && (isPostRequestElementSet('zip')) && (postRequestElement('zip') != '')) {
-               // Choose recipients by ZIP code
-               if (empty($sql)) {
-                       $sql = sprintf(" WHERE `zip` LIKE '%s%%%%'",
-                               bigintval(postRequestElement('zip'))
-                       );
-               } else {
-                       $sql .= sprintf(" AND `zip` LIKE '%s%%%%'",
-                               bigintval(postRequestElement('zip'))
-                       );
+       if (isOrderMultiPageEnabled()) {
+               // Default is no zip code limitation
+               $zip = NULL;
+
+               // POST or GET elements?
+               if ((isPostRequestElementSet('zip')) && (postRequestElement('zip') != '')) {
+                       // Choose recipients by zip code from POST
+                       $zip = bigintval(postRequestElement('zip'));
+               } elseif ((isGetRequestElementSet('zip')) && (getRequestElement('zip') != '')) {
+                       // Choose recipients by zip code from GET
+                       $zip = bigintval(getRequestElement('zip'));
                }
+
+               // Is the zip code set?
+               if (!is_null($zip)) {
+                       // Is the previous SQL statement empty?
+                       if (empty($sql)) {
+                               // SQL statemet is empty, so use WHERE
+                               $sql = sprintf(" WHERE `zip` LIKE '%s%%%%'", $zip);
+                       } else {
+                               // ... otherwise use AND
+                               $sql .= sprintf(" AND `zip` LIKE '%s%%%%'", $zip);
+                       }
+               } // END - if
        } // END - if
 
        // Return expanded SQL