Bug 19198: Prevent the test to fail randomly
[koha.git] / opac / opac-ISBDdetail.pl
bloba3cb1a970553ce6dd100ac7e0b839f08fde672be
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 Modern::Perl;
44 use C4::Auth;
45 use C4::Context;
46 use C4::Output;
47 use CGI qw ( -utf8 );
48 use MARC::Record;
49 use C4::Biblio;
50 use C4::Items;
51 use C4::Reserves;
52 use C4::Acquisition;
53 use C4::Serials; # uses getsubscriptionfrom biblionumber
54 use C4::Koha;
55 use Koha::ItemTypes;
56 use Koha::Patrons;
57 use Koha::RecordProcessor;
60 my $query = CGI->new();
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63 template_name => "opac-ISBDdetail.tt",
64 query => $query,
65 type => "opac",
66 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
67 debug => 1,
71 my $biblionumber = $query->param('biblionumber');
72 $biblionumber = int($biblionumber);
74 # get biblionumbers stored in the cart
75 if(my $cart_list = $query->cookie("bib_list")){
76 my @cart_list = split(/\//, $cart_list);
77 if ( grep {$_ eq $biblionumber} @cart_list) {
78 $template->param( incart => 1 );
82 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
84 my $marcflavour = C4::Context->preference("marcflavour");
86 my @items = GetItemsInfo($biblionumber);
87 if (scalar @items >= 1) {
88 my @hiddenitems = GetHiddenItemnumbers(@items);
90 if (scalar @hiddenitems == scalar @items ) {
91 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
92 exit;
96 my $record = GetMarcBiblio({
97 biblionumber => $biblionumber,
98 embed_items => 1 });
99 if ( ! $record ) {
100 print $query->redirect("/cgi-bin/koha/errors/404.pl");
101 exit;
103 my $framework = GetFrameworkCode( $biblionumber );
104 my $record_processor = Koha::RecordProcessor->new({
105 filters => 'ViewPolicy',
106 options => {
107 interface => 'opac',
108 frameworkcode => $framework
111 $record_processor->process($record);
113 # some useful variables for enhanced content;
114 # in each case, we're grabbing the first value we find in
115 # the record and normalizing it
116 my $upc = GetNormalizedUPC($record,$marcflavour);
117 my $ean = GetNormalizedEAN($record,$marcflavour);
118 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
119 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
120 my $content_identifier_exists;
121 if ( $isbn or $ean or $oclc or $upc ) {
122 $content_identifier_exists = 1;
124 $template->param(
125 normalized_upc => $upc,
126 normalized_ean => $ean,
127 normalized_oclc => $oclc,
128 normalized_isbn => $isbn,
129 content_identifier_exists => $content_identifier_exists,
132 #coping with subscriptions
133 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
134 my $dbh = C4::Context->dbh;
135 my $dat = TransformMarcToKoha( $record );
137 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
138 my @subs;
139 foreach my $subscription (@subscriptions) {
140 my %cell;
141 my $serials_to_display;
142 $cell{subscriptionid} = $subscription->{subscriptionid};
143 $cell{subscriptionnotes} = $subscription->{notes};
144 $cell{branchcode} = $subscription->{branchcode};
146 #get the three latest serials.
147 $serials_to_display = $subscription->{opacdisplaycount};
148 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
149 $cell{opacdisplaycount} = $serials_to_display;
150 $cell{latestserials} =
151 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
152 push @subs, \%cell;
155 $template->param(
156 subscriptions => \@subs,
157 subscriptionsnumber => $subscriptionsnumber,
160 my $norequests = 1;
161 my $allow_onshelf_holds;
162 my $res = GetISBDView({
163 'record' => $record,
164 'template' => 'opac',
165 'framework' => $framework
168 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
169 my $patron = Koha::Patrons->find( $loggedinuser );
170 for my $itm (@items) {
171 $norequests = 0
172 if $norequests
173 && !$itm->{'withdrawn'}
174 && !$itm->{'itemlost'}
175 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
176 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
177 && $itm->{'itemnumber'};
179 $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, ( $patron ? $patron->unblessed : {} ) )
180 unless $allow_onshelf_holds;
183 $template->param(
184 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
185 AllowOnShelfHolds => $allow_onshelf_holds,
186 norequests => $norequests,
187 ISBD => $res,
188 biblionumber => $biblionumber,
191 #Search for title in links
192 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
193 my $marcissns = GetMarcISSN ( $record, $marcflavour );
194 my $issn = $marcissns->[0] || '';
196 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
197 $dat->{title} =~ s/\/+$//; # remove trailing slash
198 $dat->{title} =~ s/\s+$//; # remove trailing space
199 $search_for_title = parametrized_url(
200 $search_for_title,
202 TITLE => $dat->{title},
203 AUTHOR => $dat->{author},
204 ISBN => $isbn,
205 ISSN => $issn,
206 CONTROLNUMBER => $marccontrolnumber,
207 BIBLIONUMBER => $biblionumber,
210 $template->param('OPACSearchForTitleIn' => $search_for_title);
213 output_html_with_http_headers $query, $cookie, $template->output;