wr72054 fixing the z3950 search for acquisitions
[koha.git] / opac / opac-ISBDdetail.pl
blob4883e89321754c35dbb5d5d913107e33289c9488
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
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 =over 2
42 =cut
44 use strict;
45 use warnings;
47 use C4::Auth;
48 use C4::Context;
49 use C4::Output;
50 use CGI;
51 use MARC::Record;
52 use C4::Biblio;
53 use C4::Items;
54 use C4::Acquisition;
55 use C4::Review;
56 use C4::Serials; # uses getsubscriptionfrom biblionumber
57 use C4::Koha;
58 use C4::Members; # GetMember
59 use C4::External::Amazon;
61 my $query = CGI->new();
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
64 template_name => "opac-ISBDdetail.tmpl",
65 query => $query,
66 type => "opac",
67 authnotrequired => 1,
68 debug => 1,
72 my $biblionumber = $query->param('biblionumber');
74 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
75 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
77 my $marcflavour = C4::Context->preference("marcflavour");
78 my $record = GetMarcBiblio($biblionumber);
79 if ( ! $record ) {
80 print $query->redirect("/cgi-bin/koha/errors/404.pl");
81 exit;
83 # some useful variables for enhanced content;
84 # in each case, we're grabbing the first value we find in
85 # the record and normalizing it
86 my $upc = GetNormalizedUPC($record,$marcflavour);
87 my $ean = GetNormalizedEAN($record,$marcflavour);
88 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
89 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
90 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
91 $template->param(
92 normalized_upc => $upc,
93 normalized_ean => $ean,
94 normalized_oclc => $oclc,
95 normalized_isbn => $isbn,
96 content_identifier_exists => $content_identifier_exists,
99 #coping with subscriptions
100 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
101 my $dbh = C4::Context->dbh;
102 my $dat = TransformMarcToKoha( $dbh, $record );
103 my @subscriptions =
104 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
105 my @subs;
106 foreach my $subscription (@subscriptions) {
107 my %cell;
108 my $serials_to_display;
109 $cell{subscriptionid} = $subscription->{subscriptionid};
110 $cell{subscriptionnotes} = $subscription->{notes};
111 $cell{branchcode} = $subscription->{branchcode};
113 #get the three latest serials.
114 $serials_to_display = $subscription->{opacdisplaycount};
115 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
116 $cell{opacdisplaycount} = $serials_to_display;
117 $cell{latestserials} =
118 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
119 push @subs, \%cell;
122 $template->param(
123 subscriptions => \@subs,
124 subscriptionsnumber => $subscriptionsnumber,
127 my $norequests = 1;
128 my $res = GetISBDView($biblionumber, "opac");
129 my @items = &GetItemsInfo($biblionumber, 'opac');
131 my $itemtypes = GetItemTypes();
132 for my $itm (@items) {
133 $norequests = 0
134 if ( (not $itm->{'wthdrawn'} )
135 && (not $itm->{'itemlost'} )
136 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
137 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
138 && ($itm->{'itemnumber'} ) );
141 my $reviews = getreviews( $biblionumber, 1 );
142 foreach ( @$reviews ) {
143 my $borrower_number_review = $_->{borrowernumber};
144 my $borrowerData = GetMember('borrowernumber' =>$borrower_number_review);
145 # setting some borrower info into this hash
146 $_->{title} = $borrowerData->{'title'};
147 $_->{surname} = $borrowerData->{'surname'};
148 $_->{firstname} = $borrowerData->{'firstname'};
152 $template->param(
153 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
154 AllowOnShelfHolds => C4::Context->preference('AllowOnShelfHolds'),
155 norequests => $norequests,
156 ISBD => $res,
157 biblionumber => $biblionumber,
158 reviews => $reviews,
161 ## Amazon.com stuff
162 #not used unless preference set
163 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
165 my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
167 foreach my $result ( @{ $amazon_details->{Details} } ) {
168 $template->param( item_description => $result->{ProductDescription} );
169 $template->param( image => $result->{ImageUrlMedium} );
170 $template->param( list_price => $result->{ListPrice} );
171 $template->param( amazon_url => $result->{url} );
174 my @products;
175 my @reviews;
176 for my $details ( @{ $amazon_details->{Details} } ) {
177 next unless $details->{SimilarProducts};
178 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
179 push @products, +{ Product => $product };
181 next unless $details->{Reviews};
182 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
183 $template->param( rating => $product * 20 );
185 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
186 push @reviews,
188 Summary => $reviews->{Summary},
189 Comment => $reviews->{Comment},
193 $template->param( SIMILAR_PRODUCTS => \@products );
194 $template->param( AMAZONREVIEWS => \@reviews );
197 output_html_with_http_headers $query, $cookie, $template->output;