From c468a724b444a0b632ee68383e6c9515fa146f64 Mon Sep 17 00:00:00 2001 From: Chris Nighswonger Date: Mon, 10 Aug 2009 12:45:43 -0400 Subject: [PATCH] [22/40] General code cleanup of new labels module code. --- C4/Labels/Batch.pm | 16 ++- labels/label-edit-batch.pl | 13 +-- labels/label-edit-layout.pl | 9 +- labels/label-edit-profile.pl | 18 ++-- labels/label-edit-template.pl | 17 ++- labels/label-home.pl | 26 ++++- labels/label-item-search.pl | 35 ++----- labels/label-manage.pl | 41 +++----- labels/label-manager.pl | 192 ---------------------------------- 9 files changed, 85 insertions(+), 282 deletions(-) delete mode 100755 labels/label-manager.pl diff --git a/C4/Labels/Batch.pm b/C4/Labels/Batch.pm index 05a6a2a67f..b9071b4279 100644 --- a/C4/Labels/Batch.pm +++ b/C4/Labels/Batch.pm @@ -65,15 +65,21 @@ C4::Labels::Batch - A class for creating and manipulating batch objects in Koha =head1 METHODS -=head2 C4::Labels::Batch->new(layout_id => layout_id, template_id => template_id, profile_id => profile_id) +=head2 C4::Labels::Batch->new() - Invoking the I method constructs a new batch object with no items. + Invoking the I method constructs a new batch object with no items. It is possible to pre-populate the batch with items and a branch code by passing them + as in the second example below. + + B The items list must be an arrayref pointing to an array of hashes containing a key/data pair after this fashion: {item_number => item_number}. The order of + the array elements determines the order of the items in the batch. example: - my $batch = C4::Labels::Batch->new(layout_id => layout_id, template_id => template_id, profile_id => profile_id); - # Creates and returns a new batch object + Cnew(); # Creates and returns a new batch object> + + Cnew(items => $arrayref, branch_code => branch_code) # Creates and returns a new batch object containing the items passed in + with the branch code passed in.> - B This batch is I written to the database untill $batch->save() is invoked. You have been warned! + B This batch is I written to the database until C<$batch->save()> is invoked. You have been warned! =cut diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index 1eae99b826..1278df90c0 100755 --- a/labels/label-edit-batch.pl +++ b/labels/label-edit-batch.pl @@ -23,17 +23,12 @@ use warnings; use vars qw($debug); use Sys::Syslog qw(syslog); -use Switch qw(Perl6); use CGI; use HTML::Template::Pro; -use Data::Dumper; -use JSON; -use C4::Auth; -use C4::Output; -use C4::Context; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use C4::Branch qw(get_branch_code_from_name); -use C4::Debug; use C4::Labels::Lib 1.000000 qw(get_label_summary html_table); use C4::Labels::Batch 1.000000; @@ -48,6 +43,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); + my $err = 0; my $errstr = undef; my $duplicate_count = undef; @@ -61,9 +57,10 @@ my $display_columns = [ {_label_number => {label => 'Label Number', link_field {select => {label => 'Select', value => '_label_id'}}, ]; my $op = $cgi->param('op') || undef; -my @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || undef; +my @label_ids = $cgi->param('label_id') if $cgi->param('label_id'); my @item_numbers = $cgi->param('item_number') if $cgi->param('item_number'); + my $branch_code = get_branch_code_from_name($template->param('LoginBranchname')); if ($op eq 'remove') { diff --git a/labels/label-edit-layout.pl b/labels/label-edit-layout.pl index 7aaf4487dd..d08f065acb 100755 --- a/labels/label-edit-layout.pl +++ b/labels/label-edit-layout.pl @@ -20,17 +20,15 @@ use strict; use warnings; + use Sys::Syslog qw(syslog); use CGI; use HTML::Template::Pro; -use Data::Dumper; use POSIX; use Text::CSV_XS; -use C4::Auth; -use C4::Output; -use C4::Context; -use C4::Debug; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use C4::Labels::Lib 1.000000 qw(get_barcode_types get_label_types get_font_types get_text_justification_types); use C4::Labels::Layout 1.000000; @@ -46,7 +44,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); - my $op = $cgi->param('op') || $ARGV[0] || ''; my $layout_id = $cgi->param('layout_id') || $cgi->param('element_id') || $ARGV[1] || ''; my $layout = ''; diff --git a/labels/label-edit-profile.pl b/labels/label-edit-profile.pl index e5d8bddb93..93852ef257 100755 --- a/labels/label-edit-profile.pl +++ b/labels/label-edit-profile.pl @@ -20,15 +20,13 @@ use strict; use warnings; + use Sys::Syslog qw(syslog); use CGI; use HTML::Template::Pro; -use Data::Dumper; -use C4::Auth; -use C4::Output; -use C4::Context; -use C4::Debug; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use C4::Labels::Lib 1.000000 qw(get_all_templates get_unit_values); use C4::Labels::Profile 1.000000; @@ -43,11 +41,13 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); -my $op = $cgi->param('op') || $ARGV[0] || ''; -my $profile_id = $cgi->param('profile_id') || $cgi->param('element_id') || $ARGV[1] || ''; -my $profile = ''; -my $template_list = ''; + +my $op = $cgi->param('op'); +my $profile_id = $cgi->param('profile_id') || $cgi->param('element_id'); +my $profile = undef; +my $template_list = undef; my @label_template = (); + my $units = get_unit_values(); if ($op eq 'edit') { diff --git a/labels/label-edit-template.pl b/labels/label-edit-template.pl index 44a554f1fa..1860a60a6b 100755 --- a/labels/label-edit-template.pl +++ b/labels/label-edit-template.pl @@ -20,15 +20,13 @@ use strict; use warnings; + use Sys::Syslog qw(syslog); use CGI; use HTML::Template::Pro; -use Data::Dumper; -use C4::Auth; -use C4::Output; -use C4::Context; -use C4::Debug; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use C4::Labels::Lib 1.000000 qw(get_all_profiles get_unit_values); use C4::Labels::Template 1.000000; @@ -44,10 +42,11 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -my $op = $cgi->param('op') || $ARGV[0] || ''; -my $template_id = $cgi->param('template_id') || $cgi->param('element_id') || $ARGV[1] || ''; -my $label_template = ''; -my $profile_list = ''; +my $op = $cgi->param('op'); +my $template_id = $cgi->param('template_id') || $cgi->param('element_id'); +my $label_template = undef; +my $profile_list = undef; + my $units = get_unit_values(); if ($op eq 'edit') { diff --git a/labels/label-home.pl b/labels/label-home.pl index f60ab723fc..40a36211ba 100755 --- a/labels/label-home.pl +++ b/labels/label-home.pl @@ -1,12 +1,32 @@ #!/usr/bin/perl +# +# Copyright 2006 Katipo Communications. +# Parts Copyright 2009 Foundations Bible College. +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA use strict; +use warnings; + use CGI; -use C4::Auth; -use C4::Output; -use C4::Context; use HTML::Template::Pro; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); + my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { diff --git a/labels/label-item-search.pl b/labels/label-item-search.pl index 52851dc378..433ed14699 100755 --- a/labels/label-item-search.pl +++ b/labels/label-item-search.pl @@ -1,5 +1,5 @@ #!/usr/bin/perl - +# # Copyright 2000-2002 Katipo Communications # # This file is part of Koha. @@ -19,24 +19,21 @@ use strict; use warnings; +use vars qw($debug $cgi_debug); use CGI; use HTML::Template::Pro; use List::Util qw( max min ); use POSIX; -use Data::Dumper; -use C4::Auth; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use C4::Context; -use C4::Search; -use C4::Auth; -use C4::Output; -use C4::Biblio; -use C4::Items; -use C4::Acquisition; -use C4::Search; use C4::Dates; -use C4::Koha; # XXX subfield_is_koha_internal_p +use C4::Search qw(SimpleSearch); +use C4::Biblio qw(TransformMarcToKoha); +use C4::Items qw(GetItemInfosOf get_itemnumbers_of); +use C4::Koha qw(GetItemTypes); # XXX subfield_is_koha_internal_p use C4::Labels::Lib qw(html_table); use C4::Debug; @@ -48,29 +45,20 @@ BEGIN { } } -# Creates a scrolling list with the associated default value. -# Using more than one scrolling list in a CGI assigns the same default value to all the -# scrolling lists on the page !?!? That's why this function was written. - my $query = new CGI; my $type = $query->param('type'); -my $op = $query->param('op') || ''; +my $op = $query->param('op'); my $batch_id = $query->param('batch_id'); -my $ccl_query = $query->param('ccl_query') || ''; - -my $dbh = C4::Context->dbh; - +my $ccl_query = $query->param('ccl_query'); my $startfrom = $query->param('startfrom') || 1; -my ( $template, $loggedinuser, $cookie ); +my ($template, $loggedinuser, $cookie) = (undef, undef, undef); my ( $total_hits, $orderby, $results, $total, $error, $marcresults, $idx, $datefrom, $dateto, $ccl_textbox ); - my $resultsperpage = C4::Context->preference('numSearchResults') || '20'; my $show_results = 0; - my $display_columns = [ {_add => {label => "Add Item", link_field => 1}}, {_item_call_number => {label => "Call Number", link_field => 0}}, {_date_accessioned => {label => "Accession Date", link_field => 0}}, @@ -79,7 +67,6 @@ my $display_columns = [ {_add => {label => "Add Item", link_fi ]; if ( $op eq "do_search" ) { - my @params = $query->param(); $idx = $query->param('idx'); $ccl_textbox = $query->param('ccl_textbox'); if ( $ccl_textbox && $idx ) { diff --git a/labels/label-manage.pl b/labels/label-manage.pl index bb7902b1e1..8c90f4493e 100755 --- a/labels/label-manage.pl +++ b/labels/label-manage.pl @@ -23,16 +23,12 @@ use warnings; use vars qw($debug); use Sys::Syslog qw(syslog); -use Switch qw(Perl6); use CGI; use HTML::Template::Pro; -use Data::Dumper; -use C4::Auth; -use C4::Output; -use C4::Context; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); use autouse 'C4::Branch' => qw(get_branch_code_from_name); -use C4::Debug; use C4::Labels::Lib 1.000000 qw(get_all_templates get_all_layouts get_all_profiles get_batch_summary html_table); use C4::Labels::Layout 1.000000; use C4::Labels::Template 1.000000; @@ -78,31 +74,24 @@ my $display_columns = { layout => [ #db column => display column ], }; -my $label_element = $cgi->param('label_element') || $ARGV[0]; -my $op = $cgi->param('op') || $ARGV[1] || ''; -my $element_id = $cgi->param('element_id') || $ARGV[2] || ''; +my $label_element = $cgi->param('label_element'); +my $op = $cgi->param('op'); +my $element_id = $cgi->param('element_id'); my $branch_code = ($label_element eq 'batch' ? get_branch_code_from_name($template->param('LoginBranchname')) : ''); if ($op eq 'delete') { - given ($label_element) { - when 'layout' {$error = C4::Labels::Layout::delete(layout_id => $element_id); last;} - when 'template' {$error = C4::Labels::Template::delete(template_id => $element_id); last;} - when 'profile' {$error = C4::Labels::Profile::delete(profile_id => $element_id); last;} - when 'batch' {$error = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code); last;} - default {} # FIXME: Some error trapping code - } -# FIXME: this does not allow us to process any errors -# print $cgi->redirect("label-manage.pl?label_element=$label_element"); -# exit; + if ($label_element eq 'layout') {$error = C4::Labels::Layout::delete(layout_id => $element_id);} + elsif ($label_element eq 'template') {$error = C4::Labels::Template::delete(template_id => $element_id);} + elsif ($label_element eq 'profile') {$error = C4::Labels::Profile::delete(profile_id => $element_id);} + elsif ($label_element eq 'batch') {$error = C4::Labels::Batch::delete(batch_id => $element_id, branch_code => $branch_code);} + else {} # FIXME: Some error trapping code } -given ($label_element) { - when 'layout' {$db_rows = get_all_layouts();} - when 'template' {$db_rows = get_all_templates();} - when 'profile' {$db_rows = get_all_profiles();} - when 'batch' {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\'");} - default {} # FIXME: Some error trapping code -} +if ($label_element eq 'layout') {$db_rows = get_all_layouts();} +elsif ($label_element eq 'template') {$db_rows = get_all_templates();} +elsif ($label_element eq 'profile') {$db_rows = get_all_profiles();} +elsif ($label_element eq 'batch') {$db_rows = get_batch_summary(filter => "branch_code=\'$branch_code\'");} +else {} # FIXME: Some error trapping code my $table = html_table($display_columns->{$label_element}, $db_rows); diff --git a/labels/label-manager.pl b/labels/label-manager.pl deleted file mode 100755 index 08432caa8c..0000000000 --- a/labels/label-manager.pl +++ /dev/null @@ -1,192 +0,0 @@ -#!/usr/bin/perl - -use strict; -use CGI; -use C4::Auth; -use C4::Labels; -use C4::Output; -use HTML::Template::Pro; -#use POSIX qw(ceil); -#use Data::Dumper; -#use Smart::Comments; - -use vars qw($debug); - -BEGIN { - $debug = $ENV{DEBUG} || 0; -} - -my $dbh = C4::Context->dbh; -my $query = new CGI; -$query->param('debug') and $debug = $query->param('debug'); -my $op = $query->param('op'); -my $layout_id = $query->param('layout_id'); -my $layoutname = $query->param('layoutname'); -my $barcodetype = $query->param('barcodetype'); -my $bcn = $query->param('tx_barcode'); -my $title = $query->param('tx_title'); -my $subtitle = $query->param('tx_subtitle'); -my $isbn = $query->param('tx_isbn'); -my $issn = $query->param('tx_issn'); -my $itemtype = $query->param('tx_itemtype'); -my $itemcallnumber = $query->param('tx_itemcallnumber'); -my $author = $query->param('tx_author'); -my $tmpl_id = $query->param('tmpl_id'); -my $summary = $query->param('summary'); -my $startlabel = $query->param('startlabel'); -my $printingtype = $query->param('printingtype'); -my $guidebox = $query->param('guidebox'); -my $fontsize = $query->param('fontsize'); -my $callnum_split = $query->param('callnum_split'); -my $text_justify = $query->param('text_justify'); -my $formatstring = $query->param('formatstring'); -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')); - -# 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'}; -# ---------- - -#if (!$batch_id ) { -# $batch_id = get_highest_batch(); -#} - -#my $batch_type = "labels"; #FIXME: Hardcoded for testing/development... -my @messages; -my ($itemnumber) = @itemnumber if (scalar(@itemnumber) == 1); - -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "labels/label-manager.tmpl", - query => $query, - type => "intranet", - authnotrequired => 0, - flagsrequired => { catalogue => 1 }, - debug => 1, - } -); - -if ( $op eq 'save_layout' ) { - save_layout( - $barcodetype, $title, $subtitle, $isbn, - $issn, $itemtype, $bcn, $text_justify, - $callnum_split, $itemcallnumber, $author, - $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname, - , $formatstring , $layout_id - ); - ### $layoutname - print $query->redirect("label-home.pl"); - exit; -} -elsif ( $op eq 'add_layout' ) { - add_layout( - $barcodetype, $title, $subtitle, $isbn, - $issn, $itemtype, $bcn, $text_justify, - $callnum_split, $itemcallnumber, $author, - $tmpl_id, $printingtype, $guidebox, $startlabel, $layoutname, - $formatstring , $layout_id - ); - ### $layoutname - print $query->redirect("label-home.pl"); - exit; -} - -# 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 = ($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"; - $sth2->execute($inum, $batch_id); - } -} -elsif ( $op eq 'deleteall' ) { - my $query2 = "DELETE FROM $batch_type"; - my $sth2 = $dbh->prepare($query2); - $sth2->execute(); -} -elsif ( $op eq 'delete' ) { - my @labelids = $query->param((($batch_type eq 'labels') ? 'labelid' : 'cardid')); - scalar @labelids or push @messages, (($batch_type eq 'labels') ? "ERROR: No labelid(s) supplied for deletion." : "ERROR: No cardid(s) supplied for deletion."); - my $ins = "?," x (scalar @labelids); - $ins =~ s/\,$//; - my $query2 = "DELETE FROM $batch_type WHERE " . (($batch_type eq 'labels') ? 'labelid' : 'cardid') ." IN ($ins) "; - $debug and push @messages, "query2: $query2 -- (@labelids)"; - my $sth2 = $dbh->prepare($query2); - $sth2->execute(@labelids); -} -elsif ( $op eq 'delete_batch' ) { - delete_batch($batch_id, $batch_type); - print $query->redirect("label-manager.pl?type=$batch_type"); - exit; -} -elsif ( $op eq 'add_batch' ) { - $batch_id= add_batch($batch_type); -} -elsif ( $op eq 'set_active_layout' ) { - set_active_layout($layout_id); - print $query->redirect("label-home.pl"); - exit; -} -elsif ( $op eq 'deduplicate' ) { - warn "\$batch_id=$batch_id and \$batch_type=$batch_type"; - my ($return, $dberror) = deduplicate_batch($batch_id, $batch_type); - my $msg = (($return) ? "Removed $return" : "Error removing") . " duplicate items from Batch $batch_id." . (($dberror) ? " Database returned: $dberror" : ""); - push @messages, $msg; -} - -# 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($batch_type); -my @resultsloop = ($batch_type eq 'labels') ? GetLabelItems($batch_id) : GetPatronCardItems($batch_id); -#warn "$batches[0] (id $batch_id)"; -#warn Dumper(@resultsloop); - -#calc-ing number of sheets -#my $number_of_results = scalar @resultsloop; -#my $sheets_needed = ceil( ( --$number_of_results + $startrow ) / 8 ); # rounding up -#my $tot_labels = ( $sheets_needed * 8 ); -#my $start_results = ( $number_of_results + $startrow ); -#my $labels_remaining = ( $tot_labels - $start_results ); - -if (scalar @messages) { - $template->param(message => 1); - my @complex = (); - foreach (@messages) { - my %hash = (message_text => $_); - push @complex, \%hash; - } - $template->param(message_loop => \@complex); -} -if ($batch_type eq 'labels' or $batch_type eq 'patroncards') { - $template->param("batch_is_$batch_type" => 1); -} -$template->param( - batch_type => $batch_type, - batch_id => $batch_id, - batch_count => scalar @resultsloop, - active_layout_name => $active_layout_name, - active_template_name => $active_template_name, - outputformat => ( $active_layout->{'printingtype'} eq 'CSV' ) ? 'csv' : 'pdf' , - layout_tx => ( $active_layout->{'formatstring'}) ? 0 : 1 , - layout_string => ( $active_layout->{'formatstring'}) ? 1 : 0 , - - resultsloop => \@resultsloop, - batches => \@batches, - tmpl_desc => $active_template->{'tmpl_desc'}, - - # startrow => $startrow, - # sheets => $sheets_needed, - # labels_remaining => $labels_remaining, -); -output_html_with_http_headers $query, $cookie, $template->output; -- 2.39.5