Bug 10584 - Hide OPAC biblio details if all items are hidden
[koha.git] / opac / opac-ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # parts copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
21
22 =head1 NAME
23
24 opac-ISBDdetail.pl - script to show a biblio in ISBD format
25
26 =head1 DESCRIPTION
27
28 This script needs a biblionumber as parameter 
29
30 It shows the biblio
31
32 The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
33 this template must be divided into 11 "tabs".
34
35 The first 10 tabs present the biblio, the 11th one presents
36 the items attached to the biblio
37
38 =head1 FUNCTIONS
39
40 =cut
41
42 use strict;
43 use warnings;
44
45 use C4::Auth;
46 use C4::Context;
47 use C4::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Biblio;
51 use C4::Items;
52 use C4::Acquisition;
53 use C4::Review;
54 use C4::Serials;    # uses getsubscriptionfrom biblionumber
55 use C4::Koha;
56 use C4::Members;    # GetMember
57
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60     {
61         template_name   => "opac-ISBDdetail.tmpl",
62         query           => $query,
63         type            => "opac",
64         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
65         debug           => 1,
66     }
67 );
68
69 my $biblionumber = $query->param('biblionumber');
70 $biblionumber = int($biblionumber);
71
72 # get biblionumbers stored in the cart
73 my @cart_list;
74
75 if($query->cookie("bib_list")){
76     my $cart_list = $query->cookie("bib_list");
77     @cart_list = split(/\//, $cart_list);
78     if ( grep {$_ eq $biblionumber} @cart_list) {
79         $template->param( incart => 1 );
80     }
81 }
82
83 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
84 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
85
86 my $marcflavour      = C4::Context->preference("marcflavour");
87
88 my @items = GetItemsInfo($biblionumber);
89 if (scalar @items >= 1) {
90     my @hiddenitems = GetHiddenItemnumbers(@items);
91
92     if (scalar @hiddenitems == scalar @items ) {
93         print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
94         exit;
95     }
96 }
97
98 my $record = GetMarcBiblio($biblionumber);
99 if ( ! $record ) {
100     print $query->redirect("/cgi-bin/koha/errors/404.pl");
101     exit;
102 }
103 # some useful variables for enhanced content;
104 # in each case, we're grabbing the first value we find in
105 # the record and normalizing it
106 my $upc = GetNormalizedUPC($record,$marcflavour);
107 my $ean = GetNormalizedEAN($record,$marcflavour);
108 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
109 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
110 my $content_identifier_exists;
111 if ( $isbn or $ean or $oclc or $upc ) {
112     $content_identifier_exists = 1;
113 }
114 $template->param(
115     normalized_upc => $upc,
116     normalized_ean => $ean,
117     normalized_oclc => $oclc,
118     normalized_isbn => $isbn,
119         content_identifier_exists => $content_identifier_exists,
120 );
121
122 #coping with subscriptions
123 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
124 my $dbh = C4::Context->dbh;
125 my $dat                 = TransformMarcToKoha( $dbh, $record );
126
127 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
128 my @subs;
129 foreach my $subscription (@subscriptions) {
130     my %cell;
131         my $serials_to_display;
132     $cell{subscriptionid}    = $subscription->{subscriptionid};
133     $cell{subscriptionnotes} = $subscription->{notes};
134     $cell{branchcode}        = $subscription->{branchcode};
135
136     #get the three latest serials.
137         $serials_to_display = $subscription->{opacdisplaycount};
138         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
139         $cell{opacdisplaycount} = $serials_to_display;
140     $cell{latestserials} =
141       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
142     push @subs, \%cell;
143 }
144
145 $template->param(
146     subscriptions       => \@subs,
147     subscriptionsnumber => $subscriptionsnumber,
148 );
149
150 my $norequests = 1;
151 my $res = GetISBDView($biblionumber, "opac");
152
153 my $itemtypes = GetItemTypes();
154 for my $itm (@items) {
155     $norequests = 0
156        if ( (not $itm->{'withdrawn'} )
157          && (not $itm->{'itemlost'} )
158          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
159                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
160          && ($itm->{'itemnumber'} ) );
161 }
162
163 my $reviews = getreviews( $biblionumber, 1 );
164 foreach ( @$reviews ) {
165     my $borrower_number_review = $_->{borrowernumber};
166     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
167     # setting some borrower info into this hash
168     $_->{title}     = $borrowerData->{'title'};
169     $_->{surname}   = $borrowerData->{'surname'};
170     $_->{firstname} = $borrowerData->{'firstname'};
171 }
172
173
174 $template->param(
175     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
176     AllowOnShelfHolds   => C4::Context->preference('AllowOnShelfHolds'),
177     norequests   => $norequests,
178     ISBD         => $res,
179     biblionumber => $biblionumber,
180     reviews             => $reviews,
181 );
182
183 #Export options
184 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
185 my @export_options = split(/\|/,$OpacExportOptions);
186 $template->{VARS}->{'export_options'} = \@export_options;
187
188 #Search for title in links
189 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
190 my $marcissns = GetMarcISSN ( $record, $marcflavour );
191 my $issn = $marcissns->[0] || '';
192
193 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
194     $dat->{title} =~ s/\/+$//; # remove trailing slash
195     $dat->{title} =~ s/\s+$//; # remove trailing space
196     $search_for_title = parametrized_url(
197         $search_for_title,
198         {
199             TITLE         => $dat->{title},
200             AUTHOR        => $dat->{author},
201             ISBN          => $isbn,
202             ISSN          => $issn,
203             CONTROLNUMBER => $marccontrolnumber,
204             BIBLIONUMBER  => $biblionumber,
205         }
206     );
207     $template->param('OPACSearchForTitleIn' => $search_for_title);
208 }
209
210 output_html_with_http_headers $query, $cookie, $template->output;