German intranet updates
[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 with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 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::External::Amazon;
55 use C4::Review;
56 use C4::Serials;    # uses getsubscriptionfrom biblionumber
57 use C4::Koha;       # use getitemtypeinfo
58 use C4::Members;    # GetMember
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 my $marcflavour      = C4::Context->preference("marcflavour");
74 my $record = GetMarcBiblio($biblionumber);
75
76 #coping with subscriptions
77 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
78 my $dbh = C4::Context->dbh;
79 my $dat                 = TransformMarcToKoha( $dbh, $record );
80 my @subscriptions       =
81   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
82 my @subs;
83 foreach my $subscription (@subscriptions) {
84     my %cell;
85     $cell{subscriptionid}    = $subscription->{subscriptionid};
86     $cell{subscriptionnotes} = $subscription->{notes};
87     $cell{branchcode}        = $subscription->{branchcode};
88
89     #get the three latest serials.
90     $cell{latestserials} =
91       GetLatestSerials( $subscription->{subscriptionid}, 3 );
92     push @subs, \%cell;
93 }
94
95 $template->param(
96     subscriptions       => \@subs,
97     subscriptionsnumber => $subscriptionsnumber,
98 );
99
100 # my @blocs = split /\@/,$ISBD;
101 # my @fields = $record->fields();
102 my $res = GetISBDView($biblionumber);
103
104 my $reviews = getreviews( $biblionumber, 1 );
105 foreach ( @$reviews ) {
106     my $borrower_number_review = $_->{borrowernumber};
107     my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
108     # setting some borrower info into this hash
109     $_->{title}     = $borrowerData->{'title'};
110     $_->{surname}   = $borrowerData->{'surname'};
111     $_->{firstname} = $borrowerData->{'firstname'};
112 }
113
114
115 $template->param(
116     ISBD         => $res,
117     biblionumber => $biblionumber,
118     reviews             => $reviews,
119 );
120     my @services;
121         my $amazon_reviews  = C4::Context->preference("AmazonReviews");
122         my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
123                 
124     if ( $amazon_reviews ) {
125         $template->param( AmazonReviews => 1 );
126         push( @services, 'EditorialReview' );
127     }
128     if ( $amazon_similars ) {
129         $template->param( AmazonSimilarItems => 1 );
130         push( @services, 'Similarities' );
131     }
132
133 ## Amazon.com stuff
134 #not used unless preference set
135 if ( C4::Context->preference("AmazonContent") == 1 ) {
136     use C4::External::Amazon;
137     $dat->{'amazonisbn'} = $dat->{'isbn'};
138     $dat->{'amazonisbn'} =~ s|-||g;
139
140     $template->param( amazonisbn => $dat->{amazonisbn} );
141
142     my $amazon_details = &get_amazon_details( $dat->{amazonisbn}, $record, $marcflavour );
143
144     foreach my $result ( @{ $amazon_details->{Details} } ) {
145         $template->param( item_description => $result->{ProductDescription} );
146         $template->param( image            => $result->{ImageUrlMedium} );
147         $template->param( list_price       => $result->{ListPrice} );
148         $template->param( amazon_url       => $result->{url} );
149     }
150
151     my @products;
152     my @reviews;
153     for my $details ( @{ $amazon_details->{Details} } ) {
154         next unless $details->{SimilarProducts};
155         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
156             push @products, +{ Product => $product };
157         }
158         next unless $details->{Reviews};
159         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
160             $template->param( rating => $product * 20 );
161         }
162         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
163             push @reviews,
164               +{
165                 Summary => $reviews->{Summary},
166                 Comment => $reviews->{Comment},
167               };
168         }
169     }
170     $template->param( SIMILAR_PRODUCTS => \@products );
171     $template->param( AMAZONREVIEWS    => \@reviews );
172 }
173
174 output_html_with_http_headers $query, $cookie, $template->output;