From c5f62b9bf898c7e0dc55b9a72a84f63267aac282 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 6 Apr 2018 14:50:38 -0400 Subject: [PATCH] Bug 20467: (QA follow-up) Display error if no or invalid course id is passed Signed-off-by: Katrin Fischer Signed-off-by: Nick Clemens --- course_reserves/batch_add_items.pl | 80 ++++++++++--------- .../course_reserves/batch_add_items.tt | 3 + 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/course_reserves/batch_add_items.pl b/course_reserves/batch_add_items.pl index ba16e76904..76d0caa0b5 100755 --- a/course_reserves/batch_add_items.pl +++ b/course_reserves/batch_add_items.pl @@ -52,50 +52,56 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); -$template->param( course => GetCourse($course_id) ); +my $course = GetCourse($course_id); -if ( !$action ) { - $template->param( action => 'display_form' ); -} -elsif ( $action eq 'add' ) { - my @barcodes = uniq( split( /\s\n/, $barcodes ) ); - - my @items; - my @invalid_barcodes; - for my $b (@barcodes) { - my $item = Koha::Items->find( { barcode => $b } ); +if ( $course_id && $course ) { + $template->param( course => $course ); - if ($item) { - push( @items, $item ); - } - else { - push( @invalid_barcodes, $b ); - } + if ( !$action ) { + $template->param( action => 'display_form' ); } + elsif ( $action eq 'add' ) { + my @barcodes = uniq( split( /\s\n/, $barcodes ) ); + + my @items; + my @invalid_barcodes; + for my $b (@barcodes) { + my $item = Koha::Items->find( { barcode => $b } ); + + if ($item) { + push( @items, $item ); + } + else { + push( @invalid_barcodes, $b ); + } + } - foreach my $item (@items) { - my $ci_id = ModCourseItem( - itemnumber => $item->id, - itype => $itype, - ccode => $ccode, - holdingbranch => $holdingbranch, - location => $location, - ); + foreach my $item (@items) { + my $ci_id = ModCourseItem( + itemnumber => $item->id, + itype => $itype, + ccode => $ccode, + holdingbranch => $holdingbranch, + location => $location, + ); + + my $cr_id = ModCourseReserve( + course_id => $course_id, + ci_id => $ci_id, + staff_note => $staff_note, + public_note => $public_note, + ); + } - my $cr_id = ModCourseReserve( - course_id => $course_id, - ci_id => $ci_id, - staff_note => $staff_note, - public_note => $public_note, + $template->param( + action => 'display_results', + items_added => \@items, + invalid_barcodes => \@invalid_barcodes, + course_id => $course_id, ); } - - $template->param( - action => 'display_results', - items_added => \@items, - invalid_barcodes => \@invalid_barcodes, - course_id => $course_id, - ); +} else { + $template->param( action => 'invalid_course' ); } output_html_with_http_headers $cgi, $cookie, $template->output; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt index 9ebe71de53..7326485873 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt @@ -16,6 +16,9 @@
+ [% IF action == 'invalid_course' %] +
Invalid course!
+ [% END %] [% IF action == 'display_form' %]
-- 2.39.5