Bug 20539: Remove warnings in catalogue/search.pl
[koha.git] / catalogue / detail.pl
index 25a28c5..86a0698 100755 (executable)
@@ -29,9 +29,8 @@ use C4::Biblio;
 use C4::Items;
 use C4::Circulation;
 use C4::Reserves;
-use C4::Members; # to use GetMember
 use C4::Serials;
-use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
+use C4::XISBN qw(get_xisbns);
 use C4::External::Amazon;
 use C4::Search;                # enabled_staff_search_views
 use C4::Tags qw(get_tags);
@@ -44,6 +43,7 @@ use C4::Acquisition qw(GetOrdersByBiblionumber);
 use Koha::AuthorisedValues;
 use Koha::Biblios;
 use Koha::Items;
+use Koha::ItemTypes;
 use Koha::Patrons;
 use Koha::Virtualshelves;
 
@@ -63,7 +63,7 @@ my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
 
 my $biblionumber = $query->param('biblionumber');
 $biblionumber = HTML::Entities::encode($biblionumber);
-my $record       = GetMarcBiblio($biblionumber);
+my $record       = GetMarcBiblio({ biblionumber => $biblionumber });
 
 if ( not defined $record ) {
     # biblionumber invalid -> report and exit
@@ -74,12 +74,13 @@ if ( not defined $record ) {
 }
 
 if($query->cookie("holdfor")){ 
-    my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
+    my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
     $template->param(
+        # FIXME Should pass the patron object
         holdfor => $query->cookie("holdfor"),
-        holdfor_surname => $holdfor_patron->{'surname'},
-        holdfor_firstname => $holdfor_patron->{'firstname'},
-        holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
+        holdfor_surname => $holdfor_patron->surname,
+        holdfor_firstname => $holdfor_patron->firstname,
+        holdfor_cardnumber => $holdfor_patron->cardnumber,
     );
 }
 
@@ -129,8 +130,8 @@ my $marcurlsarray    = GetMarcUrls    ($record,$marcflavour);
 my $marchostsarray  = GetMarcHosts($record,$marcflavour);
 my $subtitle         = GetRecordValue('subtitle', $record, $fw);
 
-# Get Branches, Itemtypes and Locations
-my $itemtypes = GetItemTypes();
+my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search->unblessed } };
+
 my $dbh = C4::Context->dbh;
 
 my @all_items = GetItemsInfo( $biblionumber );
@@ -202,16 +203,20 @@ my $copynumbers =
 my (@itemloop, @otheritemloop, %itemfields);
 my $norequests = 1;
 
-my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => { not => undef } });
+my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 if ( $mss->count ) {
     $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
 }
-$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => { not => undef } });
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 if ( $mss->count ) {
     $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
 }
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => { not => undef } });
+if ( $mss->count ) {
+    $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
+}
 
-$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => { not => undef } });
+$mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
 my %materials_map;
 if ($mss->count) {
     my $materials_authvals = GetAuthorisedValues($mss->next->authorised_value);
@@ -252,27 +257,22 @@ foreach my $item (@items) {
         $itemfields{$_} = 1 if ( $item->{$_} );
     }
 
-    if (C4::Context->preference('HidePatronName')){
-        $item->{'hidepatronname'} = 1;
-    }
-
-
     # checking for holds
     my $item_object = Koha::Items->find( $item->{itemnumber} );
-    my $holds = $item_object->holds_placed_before_today;
+    my $holds = $item_object->current_holds;
     if ( my $first_hold = $holds->next ) {
-        my $ItemBorrowerReserveInfo = C4::Members::GetMember( borrowernumber => $first_hold->borrowernumber); # FIXME could be improved
+        my $patron = Koha::Patrons->find( $first_hold->borrowernumber );
         $item->{backgroundcolor} = 'reserved';
         $item->{reservedate}     = $first_hold->reservedate;
-        $item->{ReservedForBorrowernumber}     = $first_hold->borrowernumber;
-        $item->{ReservedForSurname}     = $ItemBorrowerReserveInfo->{'surname'};
-        $item->{ReservedForFirstname}   = $ItemBorrowerReserveInfo->{'firstname'};
+        $item->{ReservedFor}     = $patron,
         $item->{ExpectedAtLibrary}      = $first_hold->branchcode;
-        $item->{Reservedcardnumber}             = $ItemBorrowerReserveInfo->{'cardnumber'};
         # Check waiting status
         $item->{waitingdate} = $first_hold->waitingdate;
     }
 
+    if ( my $checkout = $item_object->checkout ) {
+        $item->{CheckedOutFor} = $checkout->patron;
+    }
 
        # Check the transit status
     my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($item->{itemnumber});
@@ -435,7 +435,7 @@ if (C4::Context->preference("virtualshelves") ) {
 if (C4::Context->preference("FRBRizeEditions")==1) {
     eval {
         $template->param(
-            XISBNS => get_xisbns($isbn)
+            XISBNS => scalar get_xisbns($isbn)
         );
     };
     if ($@) { warn "XISBN Failed $@"; }