X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=labels%2Flabel-edit-batch.pl;h=687535974c18882f659ad94c63fa513b47a1fb73;hb=bfdd5150c1e01f7167bb1702cebba218dfeec38e;hp=1eae99b826cef6c43636f82cd5ebb740dc56ec2f;hpb=4b4b161d50e039833610e5d8c4e6521199c6bd76;p=koha.git diff --git a/labels/label-edit-batch.pl b/labels/label-edit-batch.pl index 1eae99b826..687535974c 100755 --- a/labels/label-edit-batch.pl +++ b/labels/label-edit-batch.pl @@ -4,43 +4,35 @@ # 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. +# 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 3 of the License, or +# (at your option) any later version. # -# 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 +# 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, see . -use strict; -use warnings; +use Modern::Perl; 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 CGI qw ( -utf8 ); -use C4::Auth; -use C4::Output; -use C4::Context; -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; +use C4::Auth qw(get_template_and_user); +use C4::Output qw(output_html_with_http_headers); +use C4::Items qw(GetItem GetItemnumberFromBarcode); +use C4::Creators; +use C4::Labels; my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "labels/label-edit-batch.tmpl", + template_name => "labels/label-edit-batch.tt", query => $cgi, type => "intranet", authnotrequired => 0, @@ -48,45 +40,75 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( debug => 1, } ); + my $err = 0; -my $errstr = undef; +my $errtype = undef; my $duplicate_count = undef; my $duplicate_message = undef; my $db_rows = {}; my $batch = undef; -my $display_columns = [ {_label_number => {label => 'Label Number', link_field => 0}}, +my $display_columns = [ {_label_number => {label => 'Label number', link_field => 0}}, {_summary => {label => 'Summary', link_field => 0}}, - {_item_type => {label => 'Item Type', link_field => 0}}, + {_item_type => {label => 'Item type', link_field => 0}}, + {_item_cn => {label => 'Call number', link_field => 0}}, {_barcode => {label => 'Barcode', link_field => 0}}, + {_delete => {label => 'Actions', link_field => 0}}, {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 @item_numbers = $cgi->param('item_number') if $cgi->param('item_number'); -my $branch_code = get_branch_code_from_name($template->param('LoginBranchname')); +my $op = $cgi->param('op') || 'edit'; +my @label_ids; +my @item_numbers; +my $number_list; +my $number_type = $cgi->param('number_type') || "barcode"; +my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0; +@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id'); +@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number'); +$number_list = $cgi->param('number_list') if $cgi->param('number_list'); + +my $branch_code = C4::Context->userenv->{'branch'}; if ($op eq 'remove') { $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); foreach my $label_id (@label_ids) { $err = $batch->remove_item($label_id); } - $errstr = "item(s) not removed from batch $batch_id." if $err; + $errtype = 'ITEM_NOT_REMOVED' if $err; # Something like this would be nice to avoid problems with the browser's 'refresh' button, but it needs an error handling mechanism... # print $cgi->redirect("label-edit-batch.pl?op=edit&batch_id=$batch_id"); # exit; } elsif ($op eq 'delete') { $err = C4::Labels::Batch::delete(batch_id => $batch_id, branch_code => $branch_code); - $errstr = "batch $batch_id was not deleted." if $err; + $errtype = 'BATCH_NOT_DELETED' if $err; } elsif ($op eq 'add') { - $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); - $batch = C4::Labels::Batch->new(branch_code => $branch_code) if $batch == -2; - foreach my $item_number (@item_numbers) { - $err = $batch->add_item($item_number); + if ($number_list) { + my @numbers_list = split /\n/, $number_list; # Entries are effectively passed in as a separated list + foreach my $number (@numbers_list) { + $number =~ s/\r$//; # strip any naughty return chars + if( $number_type eq "itemnumber" && GetItem($number) ) { + push @item_numbers, $number; + } + elsif ($number_type eq "barcode" ) { # we must test in case an invalid barcode is passed in; we effectively disgard them atm + if( my $item_number = GetItemnumberFromBarcode($number) ){ + push @item_numbers, $item_number; + } + } + } + } + if ($batch_id != 0) {$batch = C4::Labels::Batch->retrieve(batch_id => $batch_id);} + if ($batch_id == 0 || $batch == -2) {$batch = C4::Labels::Batch->new(branch_code => $branch_code);} + if ($branch_code){ + foreach my $item_number (@item_numbers) { + $err = $batch->add_item($item_number); + } + $batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch + $errtype = 'ITEM_NOT_ADDED' if $err; + } + else { + $err = 1; + $errtype = 'BRANCH_NOT_SET'; } - $errstr = "item(s) not added to batch $batch_id." if $err; } elsif ($op eq 'new') { $batch = C4::Labels::Batch->new(branch_code => $branch_code); @@ -96,7 +118,7 @@ elsif ($op eq 'de_duplicate') { $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); $duplicate_count = $batch->remove_duplicates(); $duplicate_message = 1 if $duplicate_count != -1; - $errstr = "batch $batch_id not fully de-duplicated." if $duplicate_count == -1; + $errtype = 'BATCH_NOT_DEDUP' if $duplicate_count == -1; } else { # edit $batch = C4::Labels::Batch->retrieve(batch_id => $batch_id); @@ -108,19 +130,16 @@ $db_rows = get_label_summary(items => $items, batch_id => $batch_id); my $table = html_table($display_columns, $db_rows); $template->param( - duplicate_message => $duplicate_message, - duplicate_count => $duplicate_count, - ); - -$template->param( err => $err, - errstr => $errstr, + errtype => $errtype, ) if ($err ne 0); $template->param( - op => $op, - batch_id => $batch_id, - table_loop => $table, + op => $op, + batch_id => $batch_id, + table_loop => $table, + duplicate_message => $duplicate_message, + duplicate_count => $duplicate_count, ); output_html_with_http_headers $cgi, $cookie, $template->output;