From a5f90c7d688a581e7f7cc29f38b70c7f92c8e7f0 Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Thu, 29 May 2008 13:15:23 -0500 Subject: [PATCH] Repair Labels code to accomodate patroncards. Purged EXPR. Major FIXME's still remain, like the use of GET instead of POST. The code is also a bit too INCLUDE-happy to net good performance. The entire mechanism of adding to a batch should probably be proper AJAX instead of the GET-centric opener.location approach. Signed-off-by: Joshua Ferraro --- C4/Labels.pm | 58 +++++++------------ .../prog/en/includes/label-status.inc | 2 +- .../includes/tools-labels-batches-toolbar.inc | 22 +++---- .../prog/en/modules/labels/label-manager.tmpl | 41 +++++-------- labels/label-manager.pl | 17 +++--- 5 files changed, 57 insertions(+), 83 deletions(-) diff --git a/C4/Labels.pm b/C4/Labels.pm index 8f7197b2de..e78df94817 100644 --- a/C4/Labels.pm +++ b/C4/Labels.pm @@ -296,25 +296,23 @@ sub get_text_fields { else, return the next available batch_id. =return =cut -sub add_batch { - my ( $batch_type,$batch_list ) = @_; - my $new_batch; +sub add_batch ($;$) { + my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels'; + my $batch_list = (@_) ? shift : undef; my $dbh = C4::Context->dbh; - my $q ="SELECT MAX(DISTINCT batch_id) FROM $batch_type"; + my $q ="SELECT MAX(DISTINCT batch_id) FROM $table"; my $sth = $dbh->prepare($q); $sth->execute(); - my ($batch_id) = $sth->fetchrow_array; - $sth->finish; - if($batch_id) { - $batch_id++; - } else { - $batch_id = 1; - } - # TODO: let this block use $batch_type - if(ref($batch_list) && ($batch_type eq 'labels') ) { - my $sth = $dbh->prepare("INSERT INTO labels (`batch_id`,`itemnumber`) VALUES (?,?)"); - for my $item (@$batch_list) { - $sth->execute($batch_id,$item); + my ($batch_id) = $sth->fetchrow_array || 0; + $batch_id++; + if ($batch_list) { + if ($table eq 'patroncards') { + $sth = $dbh->prepare("INSERT INTO $table (`batch_id`,`borrowernumber`) VALUES (?,?)"); + } else { + $sth = $dbh->prepare("INSERT INTO $table (`batch_id`,`itemnumber` ) VALUES (?,?)"); + } + for (@$batch_list) { + $sth->execute($batch_id,$_); } } return $batch_id; @@ -323,31 +321,19 @@ sub add_batch { #FIXME: Needs to be ported to receive $batch_type # ... this looks eerily like add_batch() ... sub get_highest_batch { - my $new_batch; - my $dbh = C4::Context->dbh; + my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels'; my $q = - "select distinct batch_id from labels order by batch_id desc limit 1"; - my $sth = $dbh->prepare($q); + "select distinct batch_id from $table order by batch_id desc limit 1"; + my $sth = C4::Context->dbh->prepare($q); $sth->execute(); - my $data = $sth->fetchrow_hashref; - $sth->finish; - - if ( !$data->{'batch_id'} ) { - $new_batch = 1; - } - else { - $new_batch = $data->{'batch_id'}; - } - - return $new_batch; + my $data = $sth->fetchrow_hashref or return 1; + return ($data->{'batch_id'} || 1); } -sub get_batches { - # my $q = "SELECT batch_id, COUNT(*) AS num FROM " . shift . " GROUP BY batch_id"; - # FIXEDME: There is only ONE table with batch_id, so why try to select a different one? - # get_batches() was frequently being called w/ no args, crashing DBD - my $q = "SELECT batch_id, COUNT(*) AS num FROM labels GROUP BY batch_id"; +sub get_batches (;$) { + my $table = (@_ and 'patroncards' eq shift) ? 'patroncards' : 'labels'; + my $q = "SELECT batch_id, COUNT(*) AS num FROM $table GROUP BY batch_id"; my $sth = C4::Context->dbh->prepare($q); $sth->execute(); my $batches = $sth->fetchall_arrayref({}); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/label-status.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/label-status.inc index b4b86ca287..3202ad4ed3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/label-status.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/label-status.inc @@ -3,6 +3,6 @@ - +
Layout:No Layout Specified: Select a Label Layout
Template: No Template Specified: Select a Label Template
Batch: ">Create a new batch
Batch: ">Create a new batch
diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc index 6b4fa3c64c..394d5a93e3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/tools-labels-batches-toolbar.inc @@ -1,4 +1,4 @@ - +
- +
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manager.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manager.tmpl index c52fdacf81..056a6393fc 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manager.tmpl +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/labels/label-manager.tmpl @@ -1,11 +1,11 @@ -Koha › Tools › Labels › <!-- TMPL_IF EXPR="(type eq 'labels')" -->Label Batch<!-- TMPL_ELSIF EXPR="(type eq 'patroncards')" -->Patron Card Batch<!-- /TMPL_IF --> +Koha › Tools › Labels › <!-- TMPL_IF NAME="batch_is_labels" -->Label<!-- TMPL_ELSIF NAME="batch_is_patroncards" -->Patron Card<!-- TMPL_ELSE -->Unknown Batchtype<!-- /TMPL_IF --> Batch - +
@@ -19,9 +19,9 @@ -
+

Items to be Printed for Batch ( items)

@@ -42,10 +42,7 @@
-
- -
-
+

Patron Cards to be Printed for Batch ( items)

@@ -66,18 +63,20 @@
+ + Error: Unknown Batch Type "" +
-
- - +
+

Label Batches

@@ -97,30 +96,23 @@
-
-
- -
-
-
-
No Label Batches Currently Defined
Select "New Label Batch" to create a Label batch.
+
- - - +
+

Patron Card Batches

@@ -140,26 +132,19 @@
-
-
- -
-
-
-
No Patron Card Batches Currently Defined
Select "New Patron Card Batch" to create a Label batch.
+
-
diff --git a/labels/label-manager.pl b/labels/label-manager.pl index eab45b0749..64f48db0e7 100755 --- a/labels/label-manager.pl +++ b/labels/label-manager.pl @@ -41,7 +41,8 @@ my $printingtype = $query->param('printingtype'); my $guidebox = $query->param('guidebox'); my $fontsize = $query->param('fontsize'); my $formatstring = $query->param('formatstring'); -my $batch_type = $query->param('type') || 'labels'; +my $batch_type = $query->param('type'); +($batch_type and $batch_type eq 'patroncards') or $batch_type = 'labels'; my @itemnumber; ($batch_type eq 'labels') ? (@itemnumber = $query->param('itemnumber')) : (@itemnumber = $query->param('borrowernumber')); @@ -112,19 +113,19 @@ elsif ( $op eq 'add_layout' ) { # FIXME: The trinary conditionals here really need to be replaced with a more robust form of db abstraction -fbcit elsif ( $op eq 'add' ) { # add item - my $query2 = "INSERT INTO labels (itemnumber, batch_id) values ( ?,? )"; + my $query2 = ($batch_type eq 'patroncards') ? + "INSERT INTO patroncards (borrowernumber, batch_id) values (?,?)" : + "INSERT INTO labels (itemnumber, batch_id) values (?,?)" ; my $sth2 = $dbh->prepare($query2); for my $inum (@itemnumber) { - # warn "INSERTing " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ":$inum for batch $batch_id"; + # warn "INSERTing " . (($batch_type eq 'labels') ? 'itemnumber' : 'borrowernumber') . ":$inum for batch $batch_id"; $sth2->execute($inum, $batch_id); } - $sth2->finish; } elsif ( $op eq 'deleteall' ) { my $query2 = "DELETE FROM $batch_type"; my $sth2 = $dbh->prepare($query2); $sth2->execute(); - $sth2->finish; } elsif ( $op eq 'delete' ) { my @labelids = $query->param((($batch_type eq 'labels') ? 'labelid' : 'cardid')); @@ -135,7 +136,6 @@ elsif ( $op eq 'delete' ) { $debug and push @messages, "query2: $query2 -- (@labelids)"; my $sth2 = $dbh->prepare($query2); $sth2->execute(@labelids); - $sth2->finish; } elsif ( $op eq 'delete_batch' ) { delete_batch($batch_id, $batch_type); @@ -180,8 +180,11 @@ if (scalar @messages) { } $template->param(message_loop => \@complex); } +if ($batch_type eq 'labels' or $batch_type eq 'patroncards') { + $template->param("batch_is_$batch_type" => 1); +} $template->param( - type => $batch_type, # FIXME: type is an otherwise RESERVED template variable with 2 valid values: 'opac' and 'intranet' + batch_type => $batch_type, batch_id => $batch_id, batch_count => scalar @resultsloop, active_layout_name => $active_layout_name, -- 2.39.5