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