From 1b318ce282261b6bd0f5201ff14aae3ab9a75c1b Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Wed, 16 Sep 2015 14:05:36 -0400 Subject: [PATCH] Wrap up of working plugin I have the pdf generator creating coupons based on print all or print selected. todo: make the check boxs at least one required if they pick print selected coupons. --- controllers/front.php | 3 + views/front/couponList.php | 3 - views/front/couponPrint.php | 123 ++++++++++++++++++++++++++++++++---- 3 files changed, 114 insertions(+), 15 deletions(-) diff --git a/controllers/front.php b/controllers/front.php index a6c7db5..8b04abb 100644 --- a/controllers/front.php +++ b/controllers/front.php @@ -113,6 +113,9 @@ class glm_coupon_front GLM_COUPON_TAX_CATEGORIES, array('fields' => 'names') ); + if (count($post_categories) == 0 && !$glm_couponscategory) { + $categories[''][] = $coupon; + } foreach ($post_categories as $category) { $catSelect[$category] = $category; if (!$glm_couponscategory || $category == $catSelected) { diff --git a/views/front/couponList.php b/views/front/couponList.php index 9966089..63fbdac 100644 --- a/views/front/couponList.php +++ b/views/front/couponList.php @@ -35,7 +35,4 @@ -
-        
-    
diff --git a/views/front/couponPrint.php b/views/front/couponPrint.php index 15a50ba..08cbc84 100644 --- a/views/front/couponPrint.php +++ b/views/front/couponPrint.php @@ -11,7 +11,8 @@ class Creport extends Cezpdf } } $pdf = new Creport('a4', 'portrait'); -$pdf->selectFont(GLM_COUPON_PLUGIN_PATH_DIR . "glm-coupons/fonts/Helvetica.afm"); +$pdf->selectFont(GLM_COUPON_PLUGIN_PATH_DIR . "/fonts/Helvetica.afm"); +//var_dump(GLM_COUPON_PLUGIN_PATH_DIR . "/fonts/Helvetica.afm"); $pdf->ezSetMargins(90, 30, 30, 35); // put a line top and bottom on all the pages $all = $pdf->openObject(); @@ -23,17 +24,115 @@ $pdf->restoreState(); $pdf->closeObject(); $pdf->addObject($all, 'all'); //$pdfcode = $pdf->output(); -$options = array(); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); -$y = $pdf->ezText( "Site name here - coupon url here\n", 8, $options ); +$coupon_lft_opt = array( + 'left' => 5, + 'right' => 280, + 'justification'=>'left' +); +$coupon_rgt_opt = array( + 'left' => 290, + 'justification'=>'left' +); + +//echo '
' . print_r($_REQUEST, true) . '
'; +// check to see if Print selected is on +$printIds = array(); +if ($_REQUEST['printSel']) { + $printAll = false; + foreach ($_REQUEST as $posted => $value) { + if (preg_match('%coupon-id-(\d+)%', $posted, $matches)) { + //echo '
' . print_r($matches, true) . '
'; + $printIds[] = $matches[1]; + } + } +} else { + $printAll = true; +} +//exit; +$minY = $y // y is verticle position starting at lower left hand corner + = 800; +$x = 20; // x is horizontal position starting at lover left hand corner +$coupon_width = 265; // +$mycount = $count = 1; // + +$options = $coupon_lft_opt; +//echo '
' . 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 .= "".$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 ($memberAddress) { + $y = $pdf->ezText($memberAddress, 9, $header_options); + } + if ($phone) { + $y = $pdf->ezText($phone, 9, $header_options); + } + if ($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('sitename')." - ".get_bloginfo('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; + } + $count++; + $mycount++; +} $pdf->stream(); exit; return; -- 2.17.1