Bug 19991: Remove warning from opac-user
[koha.git] / opac / opac-ISBDdetail.pl
index 175d346..40e9b71 100755 (executable)
@@ -52,10 +52,12 @@ use C4::Reserves;
 use C4::Acquisition;
 use C4::Serials;    # uses getsubscriptionfrom biblionumber
 use C4::Koha;
+use Koha::IssuingRules;
+use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
 use Koha::RecordProcessor;
-
+use Koha::Biblios;
 
 my $query = CGI->new();
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
@@ -79,8 +81,6 @@ if(my $cart_list = $query->cookie("bib_list")){
     }
 }
 
-$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
-
 my $marcflavour      = C4::Context->preference("marcflavour");
 
 my @items = GetItemsInfo($biblionumber);
@@ -93,11 +93,16 @@ if (scalar @items >= 1) {
     }
 }
 
-my $record = GetMarcBiblio($biblionumber,1);
+my $record = GetMarcBiblio({
+    biblionumber => $biblionumber,
+    embed_items  => 1 });
 if ( ! $record ) {
     print $query->redirect("/cgi-bin/koha/errors/404.pl");
     exit;
 }
+
+my $biblio = Koha::Biblios->find( $biblionumber );
+
 my $framework = GetFrameworkCode( $biblionumber );
 my $record_processor = Koha::RecordProcessor->new({
     filters => 'ViewPolicy',
@@ -166,6 +171,7 @@ my $res = GetISBDView({
 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
 my $patron = Koha::Patrons->find( $loggedinuser );
 for my $itm (@items) {
+    my $item = Koha::Items->find( $itm->{itemnumber} );
     $norequests = 0
       if $norequests
         && !$itm->{'withdrawn'}
@@ -174,16 +180,19 @@ for my $itm (@items) {
         && !$itemtypes->{$itm->{'itype'}}->{notforloan}
         && $itm->{'itemnumber'};
 
-    $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $patron->unblessed)
+    $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
       unless $allow_onshelf_holds;
 }
 
+if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
+    $template->param( ReservableItems => 1 );
+}
+
 $template->param(
     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
-    AllowOnShelfHolds   => $allow_onshelf_holds,
     norequests   => $norequests,
     ISBD         => $res,
-    biblionumber => $biblionumber,
+    biblio       => $biblio,
 );
 
 #Search for title in links