ffzg/recall_notices.pl: added --interval and --dedup
[koha.git] / opac / opac-ISBDdetail.pl
index 6cb502c..ed39f72 100755 (executable)
@@ -52,12 +52,22 @@ use C4::Reserves;
 use C4::Acquisition;
 use C4::Serials;    # uses getsubscriptionfrom biblionumber
 use C4::Koha;
-use C4::Members;    # GetMember
+use Koha::IssuingRules;
+use Koha::Items;
 use Koha::ItemTypes;
+use Koha::Patrons;
 use Koha::RecordProcessor;
-
+use Koha::Biblios;
 
 my $query = CGI->new();
+my $biblionumber = $query->param('biblionumber');
+if ( !$biblionumber ) {
+    print $query->redirect('/cgi-bin/koha/errors/404.pl');
+    exit;
+}
+$biblionumber = int($biblionumber);
+
+#open template
 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     {
         template_name   => "opac-ISBDdetail.tt",
@@ -68,37 +78,32 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
     }
 );
 
-my $biblionumber = $query->param('biblionumber');
-$biblionumber = int($biblionumber);
-
-# get biblionumbers stored in the cart
-if(my $cart_list = $query->cookie("bib_list")){
-    my @cart_list = split(/\//, $cart_list);
-    if ( grep {$_ eq $biblionumber} @cart_list) {
-        $template->param( incart => 1 );
-    }
-}
-
-$template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
-
-my $marcflavour      = C4::Context->preference("marcflavour");
-
-my @items = GetItemsInfo($biblionumber);
-if (scalar @items >= 1) {
-    my @hiddenitems = GetHiddenItemnumbers(@items);
-
-    if (scalar @hiddenitems == scalar @items ) {
-        print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
-        exit;
-    }
+my $patron = Koha::Patrons->find( $loggedinuser );
+my $borcat = q{};
+if ( $patron && C4::Context->preference('OpacHiddenItemsExceptions') ) {
+    $borcat = $patron->categorycode;
 }
 
-my $record = GetMarcBiblio($biblionumber,1);
+my $record = GetMarcBiblio({
+    biblionumber => $biblionumber,
+    embed_items  => 1,
+    opac         => 1,
+    borcat       => $borcat });
 if ( ! $record ) {
     print $query->redirect("/cgi-bin/koha/errors/404.pl");
     exit;
 }
-my $framework = GetFrameworkCode( $biblionumber );
+
+my @all_items = GetItemsInfo($biblionumber);
+my $biblio = Koha::Biblios->find( $biblionumber );
+my $framework = $biblio ? $biblio->frameworkcode : q{};
+my ($tag_itemnumber, $subtag_itemnumber) = &GetMarcFromKohaField('items.itemnumber',$framework);
+my @nonhiddenitems = $record->field($tag_itemnumber);
+if (scalar @all_items >= 1 && scalar @nonhiddenitems == 0) {
+    print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
+    exit;
+}
+
 my $record_processor = Koha::RecordProcessor->new({
     filters => 'ViewPolicy',
     options => {
@@ -108,6 +113,16 @@ my $record_processor = Koha::RecordProcessor->new({
 });
 $record_processor->process($record);
 
+# get biblionumbers stored in the cart
+if(my $cart_list = $query->cookie("bib_list")){
+    my @cart_list = split(/\//, $cart_list);
+    if ( grep {$_ eq $biblionumber} @cart_list) {
+        $template->param( incart => 1 );
+    }
+}
+
+my $marcflavour      = C4::Context->preference("marcflavour");
+
 # some useful variables for enhanced content;
 # in each case, we're grabbing the first value we find in
 # the record and normalizing it
@@ -129,7 +144,6 @@ $template->param(
 
 #coping with subscriptions
 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
-my $dbh = C4::Context->dbh;
 my $dat                 = TransformMarcToKoha( $record );
 
 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
@@ -164,8 +178,8 @@ my $res = GetISBDView({
 });
 
 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
-my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
-for my $itm (@items) {
+for my $itm (@all_items) {
+    my $item = Koha::Items->find( $itm->{itemnumber} );
     $norequests = 0
       if $norequests
         && !$itm->{'withdrawn'}
@@ -174,16 +188,19 @@ for my $itm (@items) {
         && !$itemtypes->{$itm->{'itype'}}->{notforloan}
         && $itm->{'itemnumber'};
 
-    $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $borrower)
+    $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
@@ -208,4 +225,11 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
     $template->param('OPACSearchForTitleIn' => $search_for_title);
 }
 
+if( C4::Context->preference('ArticleRequests') ) {
+    my $artreqpossible = $patron
+        ? $biblio->can_article_request( $patron )
+        : Koha::ItemTypes->find($biblio->itemtype)->may_article_request;
+    $template->param( artreqpossible => $artreqpossible );
+}
+
 output_html_with_http_headers $query, $cookie, $template->output;