Third installment Patron card generation feature
authorChris Nighswonger <cnighswonger@foundations.edu>
Mon, 17 Mar 2008 14:43:53 +0000 (10:43 -0400)
committerJoshua Ferraro <jmf@liblime.com>
Tue, 18 Mar 2008 01:43:05 +0000 (20:43 -0500)
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
C4/Labels.pm
koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manager.tmpl
labels/label-manager.pl

index 1632eb2..c257c92 100644 (file)
@@ -33,7 +33,7 @@ BEGIN {
        require Exporter;
        @ISA    = qw(Exporter);
        @EXPORT = qw(
-               &get_label_options &get_label_items
+               &get_label_options &GetLabelItems
                &build_circ_barcode &draw_boundaries
                &drawbox &GetActiveLabelTemplate
                &GetAllLabelTemplates &DeleteTemplate
@@ -302,8 +302,9 @@ sub get_highest_batch {
 
 #FIXME: Needs to be ported to receive $batch_type
 sub get_batches {
+    my ($batch_type) = @_;
     my $dbh = C4::Context->dbh;
-    my $q   = "select batch_id, count(*) as num from labels group by batch_id";
+    my $q   = "select batch_id, count(*) as num from $batch_type group by batch_id";
     my $sth = $dbh->prepare($q);
     $sth->execute();
     my @resultsloop;
@@ -733,16 +734,16 @@ sub SetAssociatedProfile {
     $sth->finish;
 }
 
-=item get_label_items;
+=item GetLabelItems;
 
-        $options = get_label_items()
+        $options = GetLabelItems()
 
 Returns an array of references-to-hash, whos keys are the field from the biblio, biblioitems, items and labels tables in the Koha database.
 
 =cut
 
 #'
-sub get_label_items {
+sub GetLabelItems {
     my ($batch_id) = @_;
     my $dbh = C4::Context->dbh;
 
@@ -808,18 +809,19 @@ sub GetPatronCardItems {
     my ( $batch_id ) = @_;
     my @resultsloop;
     
-    warn "Received batch id: $batch_id";
     my $dbh = C4::Context->dbh;
     my $query = "SELECT * FROM patroncards WHERE batch_id = ? ORDER BY borrowernumber";
     my $sth = $dbh->prepare($query);
-    warn "Executing query...\n";
     $sth->execute($batch_id);
-    warn "Parsing results...\n";
+    my $cardno = 1;
     while ( my $data = $sth->fetchrow_hashref ) {
-        warn "for borrowernumber $data->{'borrowernumber'}\n";
         my $patron_data = GetMember( $data->{'borrowernumber'} );
         $patron_data->{'branchname'} = GetBranchName( $patron_data->{'branchcode'} );
+        $patron_data->{'cardno'} = $cardno;
+        $patron_data->{'cardid'} = $data->{'cardid'};
+        $patron_data->{'batch_id'} = $batch_id;
         push( @resultsloop, $patron_data );
+        $cardno++;
     }
     $sth->finish;
     return @resultsloop;
@@ -1131,7 +1133,7 @@ sub DrawBarcode {
   build_circ_barcode( $x_pos, $y_pos, $barcode,
                $barcodetype, \$item);
 
-$item is the result of a previous call to get_label_items();
+$item is the result of a previous call to GetLabelItems();
 
 =cut
 
index 8e76163..24b011f 100644 (file)
@@ -22,118 +22,131 @@ function Plugin(batch_id) {
        <!-- /TMPL_LOOP -->
 <!-- /TMPL_IF -->
 
-<!-- TMPL_UNLESS NAME="batch_id" -->
 <!-- TMPL_INCLUDE NAME="tools-labels-toolbar.inc" -->
+<!-- TMPL_UNLESS NAME="batch_id" -->
+<!-- TMPL_IF EXPR="(batch_type eq 'labels')" -->
 <!-- TMPL_IF NAME="batches" -->
-<div class="yui-g">
-
-<div class="yui-u first">
-<h2>Label Batches</h2>
-<table>
-<tr>
-        <th>ID</th>
-        <th>#</th>
-        <th>Edit</th>
-        <th>Delete</th>
-        <th>Print</th>
-</tr>
-<!-- TMPL_LOOP NAME="batches" -->
-<tr>
-        <td><!-- TMPL_VAR NAME="batch_id" --></td>
-        <td><!-- TMPL_VAR NAME="num" --> records</td>
-        <td>
-                <a href="/cgi-bin/koha/labels/label-manager.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Edit</a>
-        </td>
-        <td>
-                <a href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Delete</a>
-                               <!-- FIXME: should use POST to change server state, not GET -->
-        </td>
-        <td>
-                 <a style="float: left;"  href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Generate PDF for Batch  <!-- TMPL_VAR NAME="batch_id" --></a>
-        </td></tr>
-<!-- /TMPL_LOOP -->
-</table>
-</div>
-<div class="yui-u">
-<!-- TMPL_INCLUDE NAME="label-status.inc" -->
-</div>
-</div>
+    <div class="yui-g">
+        <div class="yui-u first">
+            <h2>Label Batches</h2>
+            <table>
+                <tr>
+                    <th>ID</th>
+                    <th>#</th>
+                    <th>Edit</th>
+                    <th>Delete</th>
+                    <th>Print</th>
+                </tr>
+                <!-- TMPL_LOOP NAME="batches" -->
+                <tr>
+                    <td><!-- TMPL_VAR NAME="batch_id" --></td>
+                    <td><!-- TMPL_VAR NAME="num" --> records</td>
+                    <td><a href="/cgi-bin/koha/labels/label-manager.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Edit</a></td>
+                    <td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Delete</a><!-- FIXME: should use POST to change server state, not GET --></td>
+                    <td><a style="float: left;"  href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Generate PDF for Batch  <!-- TMPL_VAR NAME="batch_id" --></a></td>
+                </tr>
+                <!-- /TMPL_LOOP -->
+            </table>
+        </div>
+        <div class="yui-u">
+        <!-- TMPL_INCLUDE NAME="label-status.inc" -->
+        </div>
+    </div>
 <!-- TMPL_ELSE -->
-<div class="yui-g">
-<div class="yui-u first">
-<h2>No Label Batches Currently Defined</h2>
-</div>
-<div class="yui-u">
-<!-- TMPL_INCLUDE NAME="label-status.inc" -->
-</div>
-</div>
+    <div class="yui-g">
+        <div class="yui-u first">
+            <h2>No Label Batches Currently Defined</h2>
+        </div>
+        <div class="yui-u">
+        <!-- TMPL_INCLUDE NAME="label-status.inc" -->
+        </div>
+    </div>
 <!-- /TMPL_IF --><!-- /batches -->
-
+<!-- TMPL_ELSIF EXPR="(batch_type eq 'patroncards')" -->
+<!-- TMPL_IF NAME="batches" -->
+    <div class="yui-g">
+        <div class="yui-u first">
+            <h2>Patron Card Batches</h2>
+            <table>
+                <tr>
+                    <th>ID</th>
+                    <th>#</th>
+                    <th>Edit</th>
+                    <th>Delete</th>
+                    <th>Print</th>
+                </tr>
+                <!-- TMPL_LOOP NAME="batches" -->
+                <tr>
+                    <td><!-- TMPL_VAR NAME="batch_id" --></td>
+                    <td><!-- TMPL_VAR NAME="num" --> records</td>
+                    <td><a href="/cgi-bin/koha/labels/label-manager.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Edit</a></td>
+                    <td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Delete</a><!-- FIXME: should use POST to change server state, not GET --></td>
+                    <td><a style="float: left;"  href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Generate PDF for Batch  <!-- TMPL_VAR NAME="batch_id" --></a></td>
+                </tr>
+                <!-- /TMPL_LOOP -->
+            </table>
+        </div>
+        <div class="yui-u">
+            <!-- TMPL_INCLUDE NAME="label-status.inc" -->
+        </div>
+    </div>
 <!-- TMPL_ELSE -->
-
-<div id="toolbar">
-       <script type="text/javascript">
-       //<![CDATA[
-
-       // prepare DOM for YUI Toolbar
-
-        $(document).ready(function() {
-               $("#additemsc").empty();
-           yuiToolbar();
-        });
-
-       // YUI Toolbar Functions
-
-       function yuiToolbar() {
-               new YAHOO.widget.Button({
-                                            id: "additems", 
-                                            type: "button", 
-                                            label: "Add item(s) to batch", 
-                                            container: "additemsc",
-                                                                                       onclick: {fn:function(){Plugin(<!-- TMPL_VAR NAME="batch_id" -->)}}
-                                        });
-               new YAHOO.widget.Button("deletebatch");
-               new YAHOO.widget.Button("dedup");
-               new YAHOO.widget.Button("generate");
-       }
-
-       //]]>
-       </script>
-       <ul class="toolbar">
-       <li id="additemsc"><a id="additems" href="#" onclick="Plugin(<!-- TMPL_VAR NAME="batch_id" -->); return false;">Add item(s) to batch</a></li>
-       <li><a id="deletebatch" href="/cgi-bin/koha/labels/label-manager.pl?op=delete_batch&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Delete current batch</a></li>
-                               <!-- FIXME: should use POST to change server state, not GET -->
-       <li><a id="dedup" href="/cgi-bin/koha/labels/label-manager.pl?op=deduplicate&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Remove duplicate barcodes</a></li>
-       <li><a id="generate" href="/cgi-bin/koha/labels/label-print-pdf.pl?batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Generate PDF for Batch</a></li>
-</ul></div>
-
-<h2>Items to be Printed for Batch <!-- TMPL_VAR NAME="batch_id" -->  (<!-- TMPL_VAR NAME="batch_count" -->  items)</h2>
-
-<table>
-<tr>
-        <th>Label<br />Num.</th>
-        <th>Summary</th>
-        <th>Item<br />Type</th>
-        <th>Barcode</th>
-        <th>Delete</th>
-</tr>
-<!-- TMPL_LOOP NAME="resultsloop" -->
-<tr>
-        <td><!-- TMPL_VAR NAME="labelno" --></td>
-        <td><b><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"> <!-- TMPL_VAR NAME="title" --></a></b>:
-                       <!-- TMPL_VAR NAME="author" -->:
-            <!-- TMPL_VAR NAME="isbn" --></td>
-        <td><!-- TMPL_VAR NAME="itemtype" --></td>
-        <td><!-- TMPL_VAR NAME="barcode" --></td>
-        <td>
-                <a href="/cgi-bin/koha/labels/label-manager.pl?op=delete&amp;labelid=<!-- TMPL_VAR NAME="labelid" -->&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->">Delete</a>
-                               <!-- FIXME: should use POST to change server state, not GET -->
-        </td>
-</tr>
-<!-- /TMPL_LOOP -->
-</table>
+    <div class="yui-g">
+        <div class="yui-u first">
+            <h2>No Patron Card Batches Currently Defined</h2>
+        </div>
+        <div class="yui-u">
+            <!-- TMPL_INCLUDE NAME="label-status.inc" -->
+        </div>
+    </div>
+<!-- /TMPL_IF --><!-- /batches -->
+<!-- /TMPL_IF --><!-- /batch_type -->
 <!-- /TMPL_UNLESS --><!-- batch_id -->
-
+<!-- if no batch_id do this -->
+<!-- TMPL_IF EXPR="(batch_type eq 'labels')" -->
+    <h2>Items to be Printed for Batch <!-- TMPL_VAR NAME="batch_id" -->  (<!-- TMPL_VAR NAME="batch_count" -->  items)</h2>
+    <table>
+        <tr>
+            <th>Label<br />Num.</th>
+            <th>Summary</th>
+            <th>Item<br />Type</th>
+            <th>Barcode</th>
+            <th>Delete</th>
+        </tr>
+        <!-- TMPL_LOOP NAME="resultsloop" -->
+        <tr>
+            <td><!-- TMPL_VAR NAME="labelno" --></td>
+            <td><b><a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=<!-- TMPL_VAR NAME="biblionumber" -->"> <!-- TMPL_VAR NAME="title" --></a></b> : <!-- TMPL_VAR NAME="author" --> : <!-- TMPL_VAR NAME="isbn" --></td>
+            <td><!-- TMPL_VAR NAME="itemtype" --></td>
+            <td><!-- TMPL_VAR NAME="barcode" --></td>
+            <td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete&amp;labelid=<!-- TMPL_VAR NAME="labelid" -->&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=labels">Delete</a></td>
+                           <!-- FIXME: should use POST to change server state, not GET -->
+        </tr>
+        <!-- /TMPL_LOOP -->
+    </table>
+<!-- TMPL_ELSIF EXPR="(batch_type eq 'patroncards')" -->
+    <h2>Patron Cards to be Printed for Batch <!-- TMPL_VAR NAME="batch_id" -->  (<!-- TMPL_VAR NAME="batch_count" -->  items)</h2>
+    <table>
+        <tr>
+            <th>Card<br />Num.</th>
+            <th>Patron Name</th>
+            <th>Borrower Number</th>
+            <th>Card Number</th>
+            <th>Delete</th>
+        </tr>
+        <!-- TMPL_LOOP NAME="resultsloop" -->
+        <tr>
+            <td><!-- TMPL_VAR NAME="cardno" --></td>
+            <td><b><a href="/cgi-bin/koha/members/moremember.pl?borrowernumber=<!-- TMPL_VAR NAME="borrowernumber" -->"> <!-- TMPL_VAR NAME="title" -->. <!-- TMPL_VAR NAME="firstname" --> <!-- TMPL_VAR NAME="surname" --></a></b></td>
+            <td><!-- TMPL_VAR NAME="borrowernumber" --></td>
+            <td><!-- TMPL_VAR NAME="cardnumber" --></td>
+            <td><a href="/cgi-bin/koha/labels/label-manager.pl?op=delete&amp;cardid=<!-- TMPL_VAR NAME="cardid" -->&amp;batch_id=<!-- TMPL_VAR NAME="batch_id" -->&amp;type=patroncards">Delete</a></td>
+                           <!-- FIXME: should use POST to change server state, not GET -->
+        </tr>
+        <!-- /TMPL_LOOP -->
+    </table>
+<!-- TMPL_ELSIF EXPR="(batch_type eq 'patroncards')" -->
+<!-- /TMPL_IF --><!-- /batch_type -->
 </div>
 </div>
 <div class="yui-b">
index 5947840..af8ce00 100755 (executable)
@@ -41,22 +41,22 @@ my $printingtype   = $query->param('printingtype');
 my $guidebox       = $query->param('guidebox');
 my $fontsize       = $query->param('fontsize');
 my @itemnumber     = $query->param('itemnumber');
-
+my $batch_type     = $query->param('type');
 
 # little block for displaying active layout/template/batch in templates
 # ----------
-my $batch_id     = $query->param('batch_id');
-my $active_layout = get_active_layout();
-my $active_template = GetActiveLabelTemplate();
-my $active_layout_name = $active_layout->{'layoutname'};
-my $active_template_name = $active_template->{'tmpl_code'};
+my $batch_id                    = $query->param('batch_id');
+my $active_layout               = get_active_layout();
+my $active_template             = GetActiveLabelTemplate();
+my $active_layout_name          = $active_layout->{'layoutname'};
+my $active_template_name        = $active_template->{'tmpl_code'};
 # ----------
 
 #if (!$batch_id ) {
 #    $batch_id  = get_highest_batch();
 #}
 
-my $batch_type = "labels";      #FIXME: Hardcoded for testing...
+#my $batch_type = "labels";      #FIXME: Hardcoded for testing/development...
 my @messages;
 my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1);
 
@@ -154,8 +154,8 @@ elsif ( $op eq 'deduplicate' ) {
 
 #  first lets do a read of the labels table , to get the a list of the
 # currently entered items to be prinited
-my @batches = get_batches();
-my @resultsloop = get_label_items($batch_id);
+my @batches = get_batches($batch_type);
+my @resultsloop = ($batch_type eq 'labels') ? GetLabelItems($batch_id) : GetPatronCardItems($batch_id);
 #warn "$batches[0] (id $batch_id)";
 #warn Dumper(@resultsloop);
 
@@ -176,14 +176,15 @@ if (scalar @messages) {
        $template->param(message_loop => \@complex);
 }
 $template->param(
-    batch_id => $batch_id,
-       batch_count => scalar @resultsloop,
-    active_layout_name => $active_layout_name,
-    active_template_name => $active_template_name,
-
-    resultsloop => \@resultsloop,
-    batches => \@batches,
-       tmpl_desc => $active_template->{'tmpl_desc'},
+    batch_type                  => $batch_type,
+    batch_id                    => $batch_id,
+    batch_count                 => scalar @resultsloop,
+    active_layout_name          => $active_layout_name,
+    active_template_name        => $active_template_name,
+
+    resultsloop                 => \@resultsloop,
+    batches                     => \@batches,
+    tmpl_desc                   => $active_template->{'tmpl_desc'},
 
     #  startrow         => $startrow,
     #  sheets           => $sheets_needed,