Fix for printing of searched coupons.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jul 2016 17:36:05 +0000 (13:36 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 29 Jul 2016 17:36:05 +0000 (13:36 -0400)
If you searched for one category of coupons and did print all it would
give all the coupons.
Now it is restricting them by the category.

index.php
views/front/couponPrint.php

index e8f3c3a..de14919 100644 (file)
--- a/index.php
+++ b/index.php
@@ -2,7 +2,7 @@
 /**
  * Plugin Name: Gaslight Media Coupons
  * Description: Coupon Application for Gaslight Media Clients.
- * Version: 1.1.6
+ * Version: 1.1.7
  * Author: Steve Sutton
  * Author URI: http://www.gaslightmedia.com
  * License: All right reserved
index f780e1d..0e7b7ff 100644 (file)
@@ -1,4 +1,5 @@
 <?php
+
 include_once  GLM_COUPON_PLUGIN_PATH_DIR . '/lib/class.pdf.php';
 include_once  GLM_COUPON_PLUGIN_PATH_DIR . '/lib/class.ezpdf.php';
 class Creport extends Cezpdf
@@ -56,83 +57,83 @@ $coupon_width     = 265; //
 $mycount = $count = 1;   //
 
 $options = $coupon_lft_opt;
-//echo '<pre>' . print_r($coupons, true)  . '</pre>';
-//exit;
-foreach ($coupons as $coupon) {
-    if (!$printAll && !in_array($coupon->ID, $printIds)) {
-        continue;
-    }
-    $reset = $y;
-    $val = array();
-    $val['header'] = iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->post_title);
-    $val['description'] = iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->post_content);
-    $header = ($coupon->glm_coupons_member) ? "<b>" . iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->glm_coupons_member) . "</b>\n" : '';
-    $header .= "<b>".$val['header']."</b>\n";
-    $descr = preg_replace(
-        "/<br>|<br \/>/i",
-        "\n",
-        strip_tags(substr($val['description'], 0, 600))
-    )."\n";
-    $url    = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url);
-    $expire = '<b>Expires: '.date("n/j/Y", $coupon->glm_coupons_expdate).'</b>';
-    if ($count == 2) {
-        $reset                           = $y;
-        $options                         = $coupon_rgt_opt;
-        $header_options                  = $options;
-        $header_options['justification'] = 'center';
-        $img_align                       = 'right';
-    } elseif ($count == 1) {
-        $options                         = $coupon_lft_opt;
-        $header_options                  = $options;
-        $header_options['justification'] = 'center';
-        $img_align                       = 'left';
-    }
-    $pdf->setLineStyle(1, '', '', array(5, 5, 5, 5));
-    $pdf->setColor(0, 0, 0, 1);
-    $pdf->setStrokeColor(0, 0, 0, 1);
-    $pdf->line($x, $y, $x + $coupon_width , $y); // make line for the top of coupon
-    $pdf->ezSetY($y);
-    $y = $pdf->ezText("\n".$header, 12, $header_options);
-    $y = $pdf->ezText($descr, 10, $options);
-    if (isset($coupon->glm_coupons_address) && $coupon->glm_coupons_address) {
-        $y = $pdf->ezText($coupon->glm_coupons_address, 9, $header_options);
-    }
-    if (isset($phone) && $phone) {
-        $y = $pdf->ezText($phone, 9, $header_options);
-    }
-    if (isset($url) && $url) {
-        $y = $pdf->ezText($url, 9, $header_options);
-    }
-    $y = $pdf->ezText("\n".$expire."\n", 9, $options);
-    // bottom footer
-    $pdf->saveState();
-    $pdf->setLineStyle(1, null, null, array());
-    $pdf->line($x, $y, $x + $coupon_width, $y); // make line for bottom
-    $y = $pdf->ezText( "<b>" . get_bloginfo('name') . "</b> - <b>" . home_url() . "</b>\n", 8, $options );
-    $pdf->restoreState();
-    $pdf->line($x, $y, $x + $coupon_width, $y);                         // make line for bottom
-    $pdf->line($x + $coupon_width, $reset, $x + $coupon_width, $y);     // make right
-    $pdf->line($x, $reset, $x, $y);                                     // make left
-    if ($count == 2 && $mycount != count($coupons)) {
-        $x = 20;
-        $count = 0;
-        if ($minY <= $y) {
-            $y = $minY - 5;
-        } else {
-            $y = $y - 5;
+foreach ( $categories as $catName => $coupons ) {
+    foreach ($coupons as $coupon) {
+        if (!$printAll && !in_array($coupon->ID, $printIds)) {
+            continue;
+        }
+        $reset = $y;
+        $val = array();
+        $val['header'] = iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->post_title);
+        $val['description'] = iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->post_content);
+        $header = ($coupon->glm_coupons_member) ? "<b>" . iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->glm_coupons_member) . "</b>\n" : '';
+        $header .= "<b>".$val['header']."</b>\n";
+        $descr = preg_replace(
+            "/<br>|<br \/>/i",
+            "\n",
+            strip_tags(substr($val['description'], 0, 600))
+        )."\n";
+        $url    = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url);
+        $expire = '<b>Expires: '.date("n/j/Y", $coupon->glm_coupons_expdate).'</b>';
+        if ($count == 2) {
+            $reset                           = $y;
+            $options                         = $coupon_rgt_opt;
+            $header_options                  = $options;
+            $header_options['justification'] = 'center';
+            $img_align                       = 'right';
+        } elseif ($count == 1) {
+            $options                         = $coupon_lft_opt;
+            $header_options                  = $options;
+            $header_options['justification'] = 'center';
+            $img_align                       = 'left';
+        }
+        $pdf->setLineStyle(1, '', '', array(5, 5, 5, 5));
+        $pdf->setColor(0, 0, 0, 1);
+        $pdf->setStrokeColor(0, 0, 0, 1);
+        $pdf->line($x, $y, $x + $coupon_width , $y); // make line for the top of coupon
+        $pdf->ezSetY($y);
+        $y = $pdf->ezText("\n".$header, 12, $header_options);
+        $y = $pdf->ezText($descr, 10, $options);
+        if (isset($coupon->glm_coupons_address) && $coupon->glm_coupons_address) {
+            $y = $pdf->ezText($coupon->glm_coupons_address, 9, $header_options);
         }
-        if ($y < 180 || ($mycount % 8 == 0)) {
-            $pdf->ezNewPage();
-            $y = 800;
+        if (isset($phone) && $phone) {
+            $y = $pdf->ezText($phone, 9, $header_options);
+        }
+        if (isset($url) && $url) {
+            $y = $pdf->ezText($url, 9, $header_options);
+        }
+        $y = $pdf->ezText("\n".$expire."\n", 9, $options);
+        // bottom footer
+        $pdf->saveState();
+        $pdf->setLineStyle(1, null, null, array());
+        $pdf->line($x, $y, $x + $coupon_width, $y); // make line for bottom
+        $y = $pdf->ezText( "<b>" . get_bloginfo('name') . "</b> - <b>" . home_url() . "</b>\n", 8, $options );
+        $pdf->restoreState();
+        $pdf->line($x, $y, $x + $coupon_width, $y);                         // make line for bottom
+        $pdf->line($x + $coupon_width, $reset, $x + $coupon_width, $y);     // make right
+        $pdf->line($x, $reset, $x, $y);                                     // make left
+        if ($count == 2 && $mycount != count($coupons)) {
+            $x = 20;
+            $count = 0;
+            if ($minY <= $y) {
+                $y = $minY - 5;
+            } else {
+                $y = $y - 5;
+            }
+            if ($y < 180 || ($mycount % 8 == 0)) {
+                $pdf->ezNewPage();
+                $y = 800;
+                $minY = $y;
+            }
+        } else {
             $minY = $y;
+            $y = $reset;
+            $x = 300;
         }
-    } else {
-        $minY = $y;
-        $y = $reset;
-        $x = 300;
+        $count++;
+        $mycount++;
     }
-    $count++;
-    $mycount++;
 }
 $pdf->stream();
 exit;