From eb0d35304bbabbf0074df49cc7b5e3a3f43f07c3 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Thu, 11 Jul 2013 23:13:42 -0400 Subject: [PATCH] Bug 10584 - Hide OPAC biblio details if all items are hidden If there are items for a given biblio number, and they are all hidden, then biblio needs to be hidden. If the biblio needs to be hidden, it immediately redirects to a 404.pl page, just as if the biblionumber does not exist. Arrays used to represent all the items were relocated and used, added if they didn't exist. Arrays representing the hidden items were relocated and used if they existed, added if they didn't exist. Upon debugging the opac-MARCdetail.pl modification, it was discovered the reason getHiddenItems was failing was because 'use YAML qw/Load/;' was not mentioned in C4::Items, and other libraries were triggering the loading of YAML to compensate for opac-detail.pl and opac-ISBDdetail.pl files. Signed-off-by: Mason James Signed-off-by: Jonathan Druart --- opac/opac-ISBDdetail.pl | 12 +++++++++++- opac/opac-MARCdetail.pl | 17 +++++++++++++++++ opac/opac-detail.pl | 21 ++++++++------------- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/opac/opac-ISBDdetail.pl b/opac/opac-ISBDdetail.pl index 6bfc500..2579a8b 100755 --- a/opac/opac-ISBDdetail.pl +++ b/opac/opac-ISBDdetail.pl @@ -84,6 +84,17 @@ $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHo $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 $record = GetMarcBiblio($biblionumber); if ( ! $record ) { print $query->redirect("/cgi-bin/koha/errors/404.pl"); @@ -138,7 +149,6 @@ $template->param( my $norequests = 1; my $res = GetISBDView($biblionumber, "opac"); -my @items = GetItemsInfo( $biblionumber ); my $itemtypes = GetItemTypes(); for my $itm (@items) { diff --git a/opac/opac-MARCdetail.pl b/opac/opac-MARCdetail.pl index 2a69244..705a182 100755 --- a/opac/opac-MARCdetail.pl +++ b/opac/opac-MARCdetail.pl @@ -50,6 +50,7 @@ use C4::Output; use CGI; use MARC::Record; use C4::Biblio; +use C4::Items; use C4::Acquisition; use C4::Koha; @@ -58,6 +59,22 @@ my $query = new CGI; my $dbh = C4::Context->dbh; my $biblionumber = $query->param('biblionumber'); +if ( ! $biblionumber ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); + exit; +} + +my @all_items = GetItemsInfo($biblionumber); +my @items2hide; +if (scalar @all_items >= 1) { + push @items2hide, GetHiddenItemnumbers(@all_items); + + if (scalar @items2hide == scalar @all_items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); + exit; + } +} + my $itemtype = &GetFrameworkCode($biblionumber); my $tagslib = &GetMarcStructure( 0, $itemtype ); my $biblio = GetBiblioData($biblionumber); diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index 7873f78..eb6b77f 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -73,14 +73,14 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0; $biblionumber = int($biblionumber); -my @itemsmatchingbiblionumber = GetItemsInfo($biblionumber); -if (scalar @itemsmatchingbiblionumber >= 1) { - my @items2hide = GetHiddenItemnumbers(@itemsmatchingbiblionumber); - - if (scalar @items2hide == scalar @itemsmatchingbiblionumber ) { - # biblionumber=0 effectively hides the biblio record - # since there is no such biblionumber. - $biblionumber = 0; +my @all_items = GetItemsInfo($biblionumber); +my @hiddenitems; +if (scalar @all_items >= 1) { + push @hiddenitems, GetHiddenItemnumbers(@all_items); + + if (scalar @hiddenitems == scalar @all_items ) { + print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early + exit; } } @@ -408,8 +408,6 @@ $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) ); $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") ); $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") ); -# change back when ive fixed request.pl -my @all_items = GetItemsInfo( $biblionumber ); # adding items linked via host biblios @@ -432,9 +430,6 @@ foreach my $hostfield ( $record->field($analyticfield)) { my @items; -# Getting items to be hidden -my @hiddenitems = GetHiddenItemnumbers(@all_items); - # Are there items to hide? my $hideitems; $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0; -- 1.7.10.4