From 28db81b467f3aa8a35bda0ef893a04462f533809 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Fri, 29 Jul 2016 13:36:05 -0400 Subject: [PATCH] Fix for printing of searched coupons. 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 | 2 +- views/front/couponPrint.php | 147 ++++++++++++++++++------------------ 2 files changed, 75 insertions(+), 74 deletions(-) diff --git a/index.php b/index.php index e8f3c3a..de14919 100644 --- 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 diff --git a/views/front/couponPrint.php b/views/front/couponPrint.php index f780e1d..0e7b7ff 100644 --- a/views/front/couponPrint.php +++ b/views/front/couponPrint.php @@ -1,4 +1,5 @@ ' . print_r($coupons, true) . ''; -//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) ? "" . iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->glm_coupons_member) . "\n" : ''; - $header .= "".$val['header']."\n"; - $descr = preg_replace( - "/
|
/i", - "\n", - strip_tags(substr($val['description'], 0, 600)) - )."\n"; - $url = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url); - $expire = 'Expires: '.date("n/j/Y", $coupon->glm_coupons_expdate).''; - 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( "" . get_bloginfo('name') . " - " . home_url() . "\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) ? "" . iconv('UTF-8', 'ISO-8859-1//IGNORE', $coupon->glm_coupons_member) . "\n" : ''; + $header .= "".$val['header']."\n"; + $descr = preg_replace( + "/
|
/i", + "\n", + strip_tags(substr($val['description'], 0, 600)) + )."\n"; + $url = preg_replace('/http:\/\//i', '', $coupon->glm_coupons_url); + $expire = 'Expires: '.date("n/j/Y", $coupon->glm_coupons_expdate).''; + 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( "" . get_bloginfo('name') . " - " . home_url() . "\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; -- 2.17.1