Bug 20467: (QA follow-up) Display error if no or invalid course id is passed
authorKyle M Hall <kyle@bywatetsolutions.com>
Fri, 6 Apr 2018 18:50:38 +0000 (14:50 -0400)
committerNick Clemens <nick@bywatersolutions.com>
Mon, 2 Jul 2018 12:55:38 +0000 (12:55 +0000)
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

course_reserves/batch_add_items.pl
koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/batch_add_items.tt

index ba16e76..76d0caa 100755 (executable)
@@ -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;
index 9ebe71d..7326485 100644 (file)
@@ -16,6 +16,9 @@
 <div class="main container-fluid">
     <div class="row">
         <div class="col-md-8 col-md-offset-2">
+        [% IF action == 'invalid_course' %]
+            <div id="invalid-course-error" class="dialog alert">Invalid course!</div>
+        [% END %]
 
         [% IF action == 'display_form' %]
             <form method="post" action="/cgi-bin/koha/course_reserves/batch_add_items.pl">