Bug 7143: Fix typo in adding new dev
[koha_ffzg] / course_reserves / add_items.pl
index ef8605f..ff398b9 100755 (executable)
@@ -26,9 +26,13 @@ use C4::Auth;
 use C4::Output;
 use C4::Koha;
 use C4::Biblio;
+use Koha::Items;
 
 use C4::CourseReserves qw(GetCourse GetCourseItem GetCourseReserve ModCourseItem ModCourseReserve);
 
+use Koha::Items;
+use Koha::ItemTypes;
+
 my $cgi = new CGI;
 
 my $action       = $cgi->param('action')       || '';
@@ -37,7 +41,8 @@ my $barcode      = $cgi->param('barcode')      || '';
 my $return       = $cgi->param('return')       || '';
 my $itemnumber   = ($cgi->param('itemnumber') && $action eq 'lookup') ? $cgi->param('itemnumber') : '';
 
-my $item = GetBiblioFromItemNumber( $itemnumber, $barcode );
+my $item = Koha::Items->find( { ( $itemnumber ? ( itemnumber => $itemnumber ) : ( barcode => $barcode ) ) } );
+my $title = ($item) ? $item->biblio->title : undef;
 
 my $step = ( $action eq 'lookup' && $item ) ? '2' : '1';
 
@@ -50,14 +55,16 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         flagsrequired   => { coursereserves => 'add_reserves' },
     }
 );
-my $inumber = $itemnumber ? "<blank> (itemnumber:$itemnumber)" : "";
-$template->param( ERROR_BARCODE_NOT_FOUND => $barcode . $inumber )
-  unless ( $barcode && !$itemnumber && $item && $action eq 'lookup' );
+
+if ( !$item && $action eq 'lookup' ){
+    $template->param( ERROR_ITEM_NOT_FOUND => 1 );
+    $template->param( UNKNOWN_BARCODE => $barcode ) if $barcode;
+}
 
 $template->param( course => GetCourse($course_id) );
 
-if ( $action eq 'lookup' ) {
-    my $course_item = GetCourseItem( itemnumber => $item->{'itemnumber'} );
+if ( $action eq 'lookup' and $item ) {
+    my $course_item = GetCourseItem( itemnumber => $item->itemnumber );
     my $course_reserve =
       ($course_item)
       ? GetCourseReserve(
@@ -66,14 +73,16 @@ if ( $action eq 'lookup' ) {
       )
       : undef;
 
+    my $itemtypes = Koha::ItemTypes->search;
     $template->param(
         item           => $item,
+        biblio         => $item->biblio,
         course_item    => $course_item,
         course_reserve => $course_reserve,
 
         ccodes    => GetAuthorisedValues('CCODE'),
         locations => GetAuthorisedValues('LOC'),
-        itypes    => GetItemTypes( style => 'array' ),
+        itypes    => $itemtypes, # FIXME We certainly want to display the translated_description in the template
         return    => $return,
     );