Bug 17600: Standardize our EXPORT_OK
[srvgit] / opac / opac-MARCdetail.pl
index 39cb10e..69578be 100755 (executable)
@@ -45,25 +45,31 @@ the items attached to the biblio
 
 use Modern::Perl;
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Output;
+use C4::Output qw( parametrized_url output_html_with_http_headers );
 use CGI qw ( -utf8 );
-use MARC::Record;
-use C4::Biblio;
-use C4::Items;
+use C4::Biblio qw(
+    CountItemsIssued
+    GetAuthorisedValueDesc
+    GetMarcBiblio
+    GetMarcControlnumber
+    GetMarcFromKohaField
+    GetMarcISSN
+    GetMarcStructure
+    TransformMarcToKoha
+);
 use C4::Reserves;
 use C4::Members;
-use C4::Acquisition;
-use C4::Koha;
-use List::MoreUtils qw( any uniq );
+use C4::Koha qw( GetNormalizedISBN );
+use List::MoreUtils qw( uniq );
 use Koha::Biblios;
 use Koha::CirculationRules;
 use Koha::Items;
 use Koha::ItemTypes;
 use Koha::Patrons;
 use Koha::RecordProcessor;
-use Koha::DateUtils;
+use Koha::DateUtils qw( output_pref );
 
 my $query = CGI->new();
 
@@ -81,7 +87,6 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
         query           => $query,
         type            => "opac",
         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
-        debug           => 1,
     }
 );
 
@@ -102,17 +107,19 @@ if ( ! $record ) {
     exit;
 }
 
-my @all_items = GetItemsInfo($biblionumber);
 my $biblio = Koha::Biblios->find( $biblionumber );
-my $framework = $biblio ? $biblio->frameworkcode : q{};
-my $tagslib = &GetMarcStructure( 0, $framework );
-my ($tag_itemnumber,$subtag_itemnumber) = &GetMarcFromKohaField( 'items.itemnumber' );
-my @nonhiddenitems = $record->field($tag_itemnumber);
-if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) {
-    print $query->redirect("/cgi-bin/koha/errors/404.pl");
-    exit;
+unless ( $patron and $patron->category->override_hidden_items ) {
+    # only skip this check if there's a logged in user
+    # and its category overrides OpacHiddenItems
+    if ( $biblio->hidden_in_opac({ rules => C4::Context->yaml_preference('OpacHiddenItems') }) ) {
+        print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
+        exit;
+    }
 }
 
+my $framework = $biblio ? $biblio->frameworkcode : q{};
+my $tagslib   = &GetMarcStructure( 0, $framework );
+
 my $record_processor = Koha::RecordProcessor->new({
     filters => 'ViewPolicy',
     options => {
@@ -136,11 +143,21 @@ $template->param(
 ) if $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} <= 0 && # <=0 OPAC visible.
      $tagslib->{$bt_tag}->{$bt_subtag}->{hidden} > -8;   # except -8;
 
+my $norequests = 1;
 my $allow_onshelf_holds;
-for my $itm (@all_items) {
-    my $item = Koha::Items->find( $itm->{itemnumber} );
-    $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } );
-    last if $allow_onshelf_holds;
+my $items = $biblio->items;
+
+while ( my $item = $items->next ) {
+    $norequests = 0
+      if $norequests
+        && !$item->withdrawn
+        && !$item->itemlost
+        && ($item->notforloan < 0 || not $item->notforloan )
+        && !Koha::ItemTypes->find($item->effective_itemtype)->notforloan
+        && $item->itemnumber;
+
+    $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
+      unless $allow_onshelf_holds;
 }
 
 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
@@ -309,7 +326,7 @@ foreach my $field (@fields) {
         }
         else {
             $item->{ $subf[$i][0] } .= GetAuthorisedValueDesc( $field->tag(), $subf[$i][0],
-                $subf[$i][1], '', $tagslib, '', 'opac' );
+                $subf[$i][1], '', $tagslib, '', 'opac' ) // q{};
         }
 
         my $kohafield = $tagslib->{ $field->tag() }->{ $subf[$i][0] }->{kohafield};
@@ -379,6 +396,7 @@ $template->param(
     item_header_loop    => \@item_header_loop,
     item_subfield_codes => \@item_subfield_codes,
     biblio              => $biblio,
+    norequests          => $norequests,
 );
 
 output_html_with_http_headers $query, $cookie, $template->output;