Wrap up of working plugin
authorSteve Sutton <steve@gaslightmedia.com>
Wed, 16 Sep 2015 18:05:36 +0000 (14:05 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Wed, 16 Sep 2015 18:05:36 +0000 (14:05 -0400)
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
views/front/couponList.php
views/front/couponPrint.php

index a6c7db5..8b04abb 100644 (file)
@@ -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) {
index 9966089..63fbdac 100644 (file)
@@ -35,7 +35,4 @@
         </div>
     <?php endforeach; endif;?>
     </form>
-    <pre>
-        <?php echo print_r($_REQUEST, true);?>
-    </pre>
 </div>
index 15a50ba..08cbc84 100644 (file)
@@ -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( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
-$y = $pdf->ezText( "<b>Site name here</b> - <b>coupon url here</b>\n", 8, $options );
+$coupon_lft_opt = array(
+    'left' => 5,
+    'right' => 280,
+    'justification'=>'left'
+);
+$coupon_rgt_opt = array(
+    'left' => 290,
+    'justification'=>'left'
+);
+
+//echo '<pre>' . print_r($_REQUEST, true) . '</pre>';
+// 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 '<pre>' . print_r($matches, true) . '</pre>';
+            $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 '<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 .= "<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 ($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( "<b>".get_bloginfo('sitename')."</b> - <b>".get_bloginfo('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;
+    }
+    $count++;
+    $mycount++;
+}
 $pdf->stream();
 exit;
 return;