Bug 5385: POD Cleanups (part 2)
[koha.git] / opac / opac-ISBDdetail.pl
blob88904da4513e864ae5d91e3a5b85f69cffb54d9d
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 =head1 NAME
23 opac-ISBDdetail.pl - script to show a biblio in ISBD format
25 =head1 DESCRIPTION
27 This script needs a biblionumber as parameter
29 It shows the biblio
31 The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
32 this template must be divided into 11 "tabs".
34 The first 10 tabs present the biblio, the 11th one presents
35 the items attached to the biblio
37 =head1 FUNCTIONS
39 =cut
41 use strict;
42 use warnings;
44 use C4::Auth;
45 use C4::Context;
46 use C4::Output;
47 use CGI;
48 use MARC::Record;
49 use C4::Biblio;
50 use C4::Items;
51 use C4::Acquisition;
52 use C4::Review;
53 use C4::Serials; # uses getsubscriptionfrom biblionumber
54 use C4::Koha;
55 use C4::Members; # GetMember
56 use C4::External::Amazon;
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61 template_name => "opac-ISBDdetail.tmpl",
62 query => $query,
63 type => "opac",
64 authnotrequired => 1,
65 debug => 1,
69 my $biblionumber = $query->param('biblionumber');
71 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
72 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
74 my $marcflavour = C4::Context->preference("marcflavour");
75 my $record = GetMarcBiblio($biblionumber);
76 if ( ! $record ) {
77 print $query->redirect("/cgi-bin/koha/errors/404.pl");
78 exit;
80 # some useful variables for enhanced content;
81 # in each case, we're grabbing the first value we find in
82 # the record and normalizing it
83 my $upc = GetNormalizedUPC($record,$marcflavour);
84 my $ean = GetNormalizedEAN($record,$marcflavour);
85 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
86 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
87 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
88 $template->param(
89 normalized_upc => $upc,
90 normalized_ean => $ean,
91 normalized_oclc => $oclc,
92 normalized_isbn => $isbn,
93 content_identifier_exists => $content_identifier_exists,
96 #coping with subscriptions
97 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
98 my $dbh = C4::Context->dbh;
99 my $dat = TransformMarcToKoha( $dbh, $record );
100 my @subscriptions =
101 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
102 my @subs;
103 foreach my $subscription (@subscriptions) {
104 my %cell;
105 my $serials_to_display;
106 $cell{subscriptionid} = $subscription->{subscriptionid};
107 $cell{subscriptionnotes} = $subscription->{notes};
108 $cell{branchcode} = $subscription->{branchcode};
110 #get the three latest serials.
111 $serials_to_display = $subscription->{opacdisplaycount};
112 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
113 $cell{opacdisplaycount} = $serials_to_display;
114 $cell{latestserials} =
115 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
116 push @subs, \%cell;
119 $template->param(
120 subscriptions => \@subs,
121 subscriptionsnumber => $subscriptionsnumber,
124 my $norequests = 1;
125 my $res = GetISBDView($biblionumber, "opac");
126 my @items = &GetItemsInfo($biblionumber, 'opac');
128 my $itemtypes = GetItemTypes();
129 for my $itm (@items) {
130 $norequests = 0
131 if ( (not $itm->{'wthdrawn'} )
132 && (not $itm->{'itemlost'} )
133 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
134 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
135 && ($itm->{'itemnumber'} ) );
138 my $reviews = getreviews( $biblionumber, 1 );
139 foreach ( @$reviews ) {
140 my $borrower_number_review = $_->{borrowernumber};
141 my $borrowerData = GetMember('borrowernumber' =>$borrower_number_review);
142 # setting some borrower info into this hash
143 $_->{title} = $borrowerData->{'title'};
144 $_->{surname} = $borrowerData->{'surname'};
145 $_->{firstname} = $borrowerData->{'firstname'};
149 $template->param(
150 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
151 AllowOnShelfHolds => C4::Context->preference('AllowOnShelfHolds'),
152 norequests => $norequests,
153 ISBD => $res,
154 biblionumber => $biblionumber,
155 reviews => $reviews,
158 ## Amazon.com stuff
159 #not used unless preference set
160 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
162 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
164 foreach my $result ( @{ $amazon_details->{Details} } ) {
165 $template->param( item_description => $result->{ProductDescription} );
166 $template->param( image => $result->{ImageUrlMedium} );
167 $template->param( list_price => $result->{ListPrice} );
168 $template->param( amazon_url => $result->{url} );
171 my @products;
172 my @reviews;
173 for my $details ( @{ $amazon_details->{Details} } ) {
174 next unless $details->{SimilarProducts};
175 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
176 push @products, +{ Product => $product };
178 next unless $details->{Reviews};
179 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
180 $template->param( rating => $product * 20 );
182 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
183 push @reviews,
185 Summary => $reviews->{Summary},
186 Comment => $reviews->{Comment},
190 $template->param( SIMILAR_PRODUCTS => \@products );
191 $template->param( AMAZONREVIEWS => \@reviews );
194 output_html_with_http_headers $query, $cookie, $template->output;