Merge commit 'kc/master'
[koha.git] / opac / opac-ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20
21 =head1 NAME
22
23 opac-ISBDdetail.pl : script to show a biblio in ISBD format
24
25
26 =head1 DESCRIPTION
27
28 This script needs a biblionumber as parameter 
29
30 It shows the biblio
31
32 The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
33 this template must be divided into 11 "tabs".
34
35 The first 10 tabs present the biblio, the 11th one presents
36 the items attached to the biblio
37
38 =head1 FUNCTIONS
39
40 =over 2
41
42 =cut
43
44 use strict;
45 use warnings;
46
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::Acquisition;
54 use C4::Review;
55 use C4::Serials;    # uses getsubscriptionfrom biblionumber
56 use C4::Koha;
57 use C4::Members;    # GetMember
58 use C4::External::Amazon;
59
60 my $query = CGI->new();
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62     {
63         template_name   => "opac-ISBDdetail.tmpl",
64         query           => $query,
65         type            => "opac",
66         authnotrequired => 1,
67         debug           => 1,
68     }
69 );
70
71 my $biblionumber = $query->param('biblionumber');
72
73 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
74 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
75
76 my $marcflavour      = C4::Context->preference("marcflavour");
77 my $record = GetMarcBiblio($biblionumber);
78 if ( ! $record ) {
79     print $query->redirect("/cgi-bin/koha/errors/404.pl");
80     exit;
81 }
82 # some useful variables for enhanced content;
83 # in each case, we're grabbing the first value we find in
84 # the record and normalizing it
85 my $upc = GetNormalizedUPC($record,$marcflavour);
86 my $ean = GetNormalizedEAN($record,$marcflavour);
87 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
88 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
89 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
90 $template->param(
91     normalized_upc => $upc,
92     normalized_ean => $ean,
93     normalized_oclc => $oclc,
94     normalized_isbn => $isbn,
95         content_identifier_exists => $content_identifier_exists,
96 );
97
98 #coping with subscriptions
99 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
100 my $dbh = C4::Context->dbh;
101 my $dat                 = TransformMarcToKoha( $dbh, $record );
102 my @subscriptions       =
103   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
104 my @subs;
105 foreach my $subscription (@subscriptions) {
106     my %cell;
107         my $serials_to_display;
108     $cell{subscriptionid}    = $subscription->{subscriptionid};
109     $cell{subscriptionnotes} = $subscription->{notes};
110     $cell{branchcode}        = $subscription->{branchcode};
111
112     #get the three latest serials.
113         $serials_to_display = $subscription->{opacdisplaycount};
114         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
115         $cell{opacdisplaycount} = $serials_to_display;
116     $cell{latestserials} =
117       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
118     push @subs, \%cell;
119 }
120
121 $template->param(
122     subscriptions       => \@subs,
123     subscriptionsnumber => $subscriptionsnumber,
124 );
125
126 # my @blocs = split /\@/,$ISBD;
127 # my @fields = $record->fields();
128 my $res = GetISBDView($biblionumber, "opac");
129
130 my $reviews = getreviews( $biblionumber, 1 );
131 foreach ( @$reviews ) {
132     my $borrower_number_review = $_->{borrowernumber};
133     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
134     # setting some borrower info into this hash
135     $_->{title}     = $borrowerData->{'title'};
136     $_->{surname}   = $borrowerData->{'surname'};
137     $_->{firstname} = $borrowerData->{'firstname'};
138 }
139
140
141 $template->param(
142     ISBD         => $res,
143     biblionumber => $biblionumber,
144     reviews             => $reviews,
145 );
146
147 ## Amazon.com stuff
148 #not used unless preference set
149 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
150
151     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
152
153     foreach my $result ( @{ $amazon_details->{Details} } ) {
154         $template->param( item_description => $result->{ProductDescription} );
155         $template->param( image            => $result->{ImageUrlMedium} );
156         $template->param( list_price       => $result->{ListPrice} );
157         $template->param( amazon_url       => $result->{url} );
158     }
159
160     my @products;
161     my @reviews;
162     for my $details ( @{ $amazon_details->{Details} } ) {
163         next unless $details->{SimilarProducts};
164         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
165             push @products, +{ Product => $product };
166         }
167         next unless $details->{Reviews};
168         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
169             $template->param( rating => $product * 20 );
170         }
171         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
172             push @reviews,
173               +{
174                 Summary => $reviews->{Summary},
175                 Comment => $reviews->{Comment},
176               };
177         }
178     }
179     $template->param( SIMILAR_PRODUCTS => \@products );
180     $template->param( AMAZONREVIEWS    => \@reviews );
181 }
182
183 output_html_with_http_headers $query, $cookie, $template->output;