Koha 3.8.0 Translation Update
[koha.git] / opac / opac-ISBDdetail.pl
blob634dd859c446fd5cb4974282bb273aced1eb4b84
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 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.
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.
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.
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.tmpl.
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;
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 use C4::External::Amazon;
59 my $query = CGI->new();
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62 template_name => "opac-ISBDdetail.tmpl",
63 query => $query,
64 type => "opac",
65 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
66 debug => 1,
70 my $biblionumber = $query->param('biblionumber');
72 # get biblionumbers stored in the cart
73 my @cart_list;
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 );
83 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
84 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
86 my $marcflavour = C4::Context->preference("marcflavour");
87 my $record = GetMarcBiblio($biblionumber);
88 if ( ! $record ) {
89 print $query->redirect("/cgi-bin/koha/errors/404.pl");
90 exit;
92 # some useful variables for enhanced content;
93 # in each case, we're grabbing the first value we find in
94 # the record and normalizing it
95 my $upc = GetNormalizedUPC($record,$marcflavour);
96 my $ean = GetNormalizedEAN($record,$marcflavour);
97 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
98 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
99 my $content_identifier_exists;
100 if ( $isbn or $ean or $oclc or $upc ) {
101 $content_identifier_exists = 1;
103 $template->param(
104 normalized_upc => $upc,
105 normalized_ean => $ean,
106 normalized_oclc => $oclc,
107 normalized_isbn => $isbn,
108 content_identifier_exists => $content_identifier_exists,
111 #coping with subscriptions
112 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
113 my $dbh = C4::Context->dbh;
114 my $dat = TransformMarcToKoha( $dbh, $record );
115 my @subscriptions = GetSubscriptions( undef, undef, $biblionumber );
117 my @subs;
118 foreach my $subscription (@subscriptions) {
119 my %cell;
120 my $serials_to_display;
121 $cell{subscriptionid} = $subscription->{subscriptionid};
122 $cell{subscriptionnotes} = $subscription->{notes};
123 $cell{branchcode} = $subscription->{branchcode};
125 #get the three latest serials.
126 $serials_to_display = $subscription->{opacdisplaycount};
127 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
128 $cell{opacdisplaycount} = $serials_to_display;
129 $cell{latestserials} =
130 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
131 push @subs, \%cell;
134 $template->param(
135 subscriptions => \@subs,
136 subscriptionsnumber => $subscriptionsnumber,
139 my $norequests = 1;
140 my $res = GetISBDView($biblionumber, "opac");
141 my @items = GetItemsInfo( $biblionumber );
143 my $itemtypes = GetItemTypes();
144 for my $itm (@items) {
145 $norequests = 0
146 if ( (not $itm->{'wthdrawn'} )
147 && (not $itm->{'itemlost'} )
148 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
149 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
150 && ($itm->{'itemnumber'} ) );
153 my $reviews = getreviews( $biblionumber, 1 );
154 foreach ( @$reviews ) {
155 my $borrower_number_review = $_->{borrowernumber};
156 my $borrowerData = GetMember('borrowernumber' =>$borrower_number_review);
157 # setting some borrower info into this hash
158 $_->{title} = $borrowerData->{'title'};
159 $_->{surname} = $borrowerData->{'surname'};
160 $_->{firstname} = $borrowerData->{'firstname'};
164 $template->param(
165 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
166 AllowOnShelfHolds => C4::Context->preference('AllowOnShelfHolds'),
167 norequests => $norequests,
168 ISBD => $res,
169 biblionumber => $biblionumber,
170 reviews => $reviews,
173 #Export options
174 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
175 my @export_options = split(/\|/,$OpacExportOptions);
176 $template->{VARS}->{'export_options'} = \@export_options;
178 #Search for title in links
179 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
180 my $marcissns = GetMarcISSN ( $record, $marcflavour );
181 my $issn = $marcissns->[0] || '';
183 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
184 $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
185 $dat->{title} =~ s/\/+$//; # remove trailing slash
186 $dat->{title} =~ s/\s+$//; # remove trailing space
187 $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
188 $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
189 $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g;
190 $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
191 $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
192 $template->param('OPACSearchForTitleIn' => $search_for_title);
195 ## Amazon.com stuff
196 #not used unless preference set
197 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
199 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
201 foreach my $result ( @{ $amazon_details->{Details} } ) {
202 $template->param( item_description => $result->{ProductDescription} );
203 $template->param( image => $result->{ImageUrlMedium} );
204 $template->param( list_price => $result->{ListPrice} );
205 $template->param( amazon_url => $result->{url} );
208 my @products;
209 my @reviews;
210 for my $details ( @{ $amazon_details->{Details} } ) {
211 next unless $details->{SimilarProducts};
212 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
213 push @products, +{ Product => $product };
215 next unless $details->{Reviews};
216 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
217 $template->param( rating => $product * 20 );
219 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
220 push @reviews,
222 Summary => $reviews->{Summary},
223 Comment => $reviews->{Comment},
227 $template->param( SIMILAR_PRODUCTS => \@products );
228 $template->param( AMAZONREVIEWS => \@reviews );
231 output_html_with_http_headers $query, $cookie, $template->output;