Updates for front end and pdf.
authorSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 21:30:40 +0000 (16:30 -0500)
committerSteve Sutton <steve@gaslightmedia.com>
Fri, 2 Dec 2016 21:30:40 +0000 (16:30 -0500)
Update the pdf so it won't print same coupon twice.
Update the list so it outputs the member name.

models/admin/ajax/pdfCoupons.php
views/front/coupons/list.html

index cc1e464..c4611f4 100644 (file)
@@ -128,7 +128,7 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
             foreach ($_REQUEST as $posted => $value) {
                 if (preg_match('%coupon-id-(\d+)%', $posted, $matches)) {
                     //echo '<pre>' . print_r($matches, true) . '</pre>';
-                    $printIds[] = $matches[1];
+                    $printIds[$matches[1]] = $matches[1];
                 }
             }
         } else {
@@ -141,9 +141,11 @@ class GlmMembersAdmin_ajax_pdfCoupons extends GlmDataCoupons
         $mycount = $count = 1;   //
 
         $options = $coupon_lft_opt;
-        foreach ($coupons as $coupon) {
-            if (!$printAll && !in_array($coupon['id'], $printIds)) {
+        foreach ( $coupons as $coupon ) {
+            if ( !$printAll && !in_array( $coupon['id'], $printIds ) ) {
                 continue;
+            } else if ( !$printAll && in_array( $coupon['id'], $printIds ) ) {
+                unset( $printIds[$coupon['id']] );
             }
             $reset              = $y;
             $val                = array();
index 24a4738..5168b36 100644 (file)
@@ -1,9 +1,9 @@
-{debug}
 <div>
     <h1>List Coupons</h1>
-    <form action="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=pdfCoupons&pdf=1" method="post">
-        <input type="submit" value="Print All" name="printAll" class="button success glm_coupon_print">
-        <input type="submit" value="Print Selected" name="printSel" class="button success glm_coupon_print">
+    <form id="glm-coupon-form" action="{$ajaxUrl}?action=glm_members_admin_ajax&glm_action=pdfCoupons&pdf=1" method="post">
+        <input type="hidden" id="form-option" name="option" value="">
+        <input type="submit"id="print-all-coupon" value="Print All" name="printAll" class="button success glm_coupon_print">
+        <input type="submit" id="print-selected-coupon" value="Print Selected" name="printSel" class="button success glm_coupon_print">
         {if $categories}
         {foreach $categories as $catName => $coupons}
             {if $catName != '1-category'}
@@ -17,7 +17,7 @@
                         <div class="{if $coupon.end}end {/if}coupon-item">
                             <div class="coupon-select"><label><input type="checkbox" name="coupon-id-{$coupon.id}"> Select this coupon</label></div>
                             <div class="coupon-item-wrap">
-                                {if $coupon.glm_coupons_member}<h3>{$coupon.glm_coupons_member}</h3>{/if}
+                                {if $coupon.ref_dest}<h3>{$coupon.ref_dest}</h3>{/if}
                                 <h3>{$coupon.name}</h3>
                                 {if $coupon.image}<img src="{$imgUrl}{$coupon.image}">{/if}
                                 <div class="coupon-descr">{$coupon.descr}</div>
         {/if}
     </form>
 </div>
+{literal}
+<script>
+jQuery(function($){
+    $("#print-all-coupon").click(function(){
+        $("#form-option").val('printAll');
+    });
+    $("#print-selected-coupon").click(function(){
+        $("#form-option").val('printSel');
+    });
+    $("#glm-coupon-form").submit(function(){
+        var option = $("#form-option").val();
+        console.log(option);
+        switch ( option ) {
+        case 'printSel':
+            // test how many are checked
+            var counter = 0;
+            $('input[name^="coupon-id"]').each(function(){
+                if ( $(this).is(":checked") ) {
+                    counter++;
+                }
+            });
+            if ( counter > 0 ) {
+                return true;
+            } else {
+                alert('Please select a coupon.');
+            }
+            return false;
+            break;
+        default:
+            return true;
+            break;
+        }
+        return false;
+
+    });
+});
+</script>
+{/literal}