X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=patroncards%2Fedit-batch.pl;h=bd06aabb65b53ca6c1d4bf46a5b8b756e1d21a2b;hb=0a204a15c4b771bd43460913ee98d6632c17d3b8;hp=4897e5f4e626be297bfa540e70ed1b397c12edfe;hpb=b7b92a4c812570894286bbd2094ff0377c35221f;p=koha.git diff --git a/patroncards/edit-batch.pl b/patroncards/edit-batch.pl index 4897e5f4e6..bd06aabb65 100755 --- a/patroncards/edit-batch.pl +++ b/patroncards/edit-batch.pl @@ -5,36 +5,36 @@ # # 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 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. # -# 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 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# 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 CGI; +use CGI qw ( -utf8 ); use autouse 'Data::Dumper' => qw(Dumper); 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::Creators; use C4::Patroncards; +use Koha::Patrons; my $cgi = new CGI; my ( $template, $loggedinuser, $cookie ) = get_template_and_user( { - template_name => "patroncards/edit-batch.tmpl", + template_name => "patroncards/edit-batch.tt", query => $cgi, type => "intranet", authnotrequired => 0, @@ -48,18 +48,19 @@ my $duplicate_count = undef; my $duplicate_message = undef; my $db_rows = {}; my $batch = undef; -my $display_columns = [ {_card_number => {label => 'Card Number', link_field => 0}}, - {_summary => {label => 'Summary', link_field => 0}}, +my $display_columns = [ {_summary => {label => 'Summary', link_field => 0}}, {borrowernumber => {label => 'Borrower Number', link_field => 0}}, + {_action => {label => 'Actions ', link_field => 0}}, {select => {label => 'Select', value => '_label_id'}}, ]; my $op = $cgi->param('op') || 'new'; -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 @borrower_numbers = $cgi->param('borrower_number') if $cgi->param('borrower_number'); +my $batch_id = $cgi->param('element_id') || $cgi->param('batch_id') || 0; +my ( @label_ids, @item_numbers, @borrower_numbers ); +@label_ids = $cgi->multi_param('label_id') if $cgi->param('label_id'); +@item_numbers = $cgi->multi_param('item_number') if $cgi->param('item_number'); +@borrower_numbers = $cgi->multi_param('borrower_number') if $cgi->param('borrower_number'); my $errstr = $cgi->param('error') || ''; - +my $bor_num_list = $cgi->param('bor_num_list') || undef; my $branch_code = C4::Context->userenv->{'branch'}; if ($op eq 'remove') { @@ -80,12 +81,23 @@ elsif ($op eq 'delete') { } } elsif ($op eq 'add') { - $batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id); - $batch = C4::Patroncards::Batch->new(branch_code => $branch_code) if $batch == -2; +if ($bor_num_list) { + my @bor_nums_unchecked = split /\n/, $bor_num_list; # $bor_num_list is effectively passed in as a separated list + foreach my $number (@bor_nums_unchecked) { + $number =~ s/\r$//; # strip any naughty return chars + if ( Koha::Patrons->find( $number )) { # we must test in case an invalid borrowernumber is passed in; we effectively disgard them atm + my $borrower_number = $number; + push @borrower_numbers, $borrower_number; + } + } + } + if ($batch_id != 0) {$batch = C4::Patroncards::Batch->retrieve(batch_id => $batch_id);} + if ($batch_id == 0 || $batch == -2) {$batch = C4::Patroncards::Batch->new(branch_code => $branch_code);} if ($branch_code){ foreach my $borrower_number (@borrower_numbers) { $err = $batch->add_item($borrower_number); } + $batch_id = $batch->get_attr('batch_id') if $batch_id == 0; #update batch_id if we added to a new batch if ($err) { print $cgi->redirect("edit-batch.pl?op=edit&batch_id=$batch_id&error=401"); exit; @@ -134,8 +146,7 @@ $template->param( table_loop => $table, duplicate_message => $duplicate_message, duplicate_count => $duplicate_count, - error => ($errstr ? 1 : 0), - $errstr => 1, + error => $errstr, ); output_html_with_http_headers $cgi, $cookie, $template->output;