Bug 9302: Use patron-title.inc
[koha.git] / opac / opac-ISBDdetail.pl
blob40e9b71f4cb1c9f94a180f6842a054684e80df3c
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::IssuingRules;
56 use Koha::Items;
57 use Koha::ItemTypes;
58 use Koha::Patrons;
59 use Koha::RecordProcessor;
60 use Koha::Biblios;
62 my $query = CGI->new();
63 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65 template_name => "opac-ISBDdetail.tt",
66 query => $query,
67 type => "opac",
68 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69 debug => 1,
73 my $biblionumber = $query->param('biblionumber');
74 $biblionumber = int($biblionumber);
76 # get biblionumbers stored in the cart
77 if(my $cart_list = $query->cookie("bib_list")){
78 my @cart_list = split(/\//, $cart_list);
79 if ( grep {$_ eq $biblionumber} @cart_list) {
80 $template->param( incart => 1 );
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;
104 my $biblio = Koha::Biblios->find( $biblionumber );
106 my $framework = GetFrameworkCode( $biblionumber );
107 my $record_processor = Koha::RecordProcessor->new({
108 filters => 'ViewPolicy',
109 options => {
110 interface => 'opac',
111 frameworkcode => $framework
114 $record_processor->process($record);
116 # some useful variables for enhanced content;
117 # in each case, we're grabbing the first value we find in
118 # the record and normalizing it
119 my $upc = GetNormalizedUPC($record,$marcflavour);
120 my $ean = GetNormalizedEAN($record,$marcflavour);
121 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
122 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
123 my $content_identifier_exists;
124 if ( $isbn or $ean or $oclc or $upc ) {
125 $content_identifier_exists = 1;
127 $template->param(
128 normalized_upc => $upc,
129 normalized_ean => $ean,
130 normalized_oclc => $oclc,
131 normalized_isbn => $isbn,
132 content_identifier_exists => $content_identifier_exists,
135 #coping with subscriptions
136 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
137 my $dbh = C4::Context->dbh;
138 my $dat = TransformMarcToKoha( $record );
140 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
141 my @subs;
142 foreach my $subscription (@subscriptions) {
143 my %cell;
144 my $serials_to_display;
145 $cell{subscriptionid} = $subscription->{subscriptionid};
146 $cell{subscriptionnotes} = $subscription->{notes};
147 $cell{branchcode} = $subscription->{branchcode};
149 #get the three latest serials.
150 $serials_to_display = $subscription->{opacdisplaycount};
151 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
152 $cell{opacdisplaycount} = $serials_to_display;
153 $cell{latestserials} =
154 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
155 push @subs, \%cell;
158 $template->param(
159 subscriptions => \@subs,
160 subscriptionsnumber => $subscriptionsnumber,
163 my $norequests = 1;
164 my $allow_onshelf_holds;
165 my $res = GetISBDView({
166 'record' => $record,
167 'template' => 'opac',
168 'framework' => $framework
171 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
172 my $patron = Koha::Patrons->find( $loggedinuser );
173 for my $itm (@items) {
174 my $item = Koha::Items->find( $itm->{itemnumber} );
175 $norequests = 0
176 if $norequests
177 && !$itm->{'withdrawn'}
178 && !$itm->{'itemlost'}
179 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
180 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
181 && $itm->{'itemnumber'};
183 $allow_onshelf_holds = Koha::IssuingRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
184 unless $allow_onshelf_holds;
187 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
188 $template->param( ReservableItems => 1 );
191 $template->param(
192 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
193 norequests => $norequests,
194 ISBD => $res,
195 biblio => $biblio,
198 #Search for title in links
199 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
200 my $marcissns = GetMarcISSN ( $record, $marcflavour );
201 my $issn = $marcissns->[0] || '';
203 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
204 $dat->{title} =~ s/\/+$//; # remove trailing slash
205 $dat->{title} =~ s/\s+$//; # remove trailing space
206 $search_for_title = parametrized_url(
207 $search_for_title,
209 TITLE => $dat->{title},
210 AUTHOR => $dat->{author},
211 ISBN => $isbn,
212 ISSN => $issn,
213 CONTROLNUMBER => $marccontrolnumber,
214 BIBLIONUMBER => $biblionumber,
217 $template->param('OPACSearchForTitleIn' => $search_for_title);
220 output_html_with_http_headers $query, $cookie, $template->output;