(bug #4334) create needed sample datas
[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::Items;
54 use C4::Acquisition;
55 use C4::External::Amazon;
56 use C4::Review;
57 use C4::Serials;    # uses getsubscriptionfrom biblionumber
58 use C4::Koha;       # use getitemtypeinfo
59 use C4::Members;    # GetMember
60
61 my $query = CGI->new();
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name   => "opac-ISBDdetail.tmpl",
65         query           => $query,
66         type            => "opac",
67         authnotrequired => 1,
68         debug           => 1,
69     }
70 );
71
72 my $biblionumber = $query->param('biblionumber');
73
74 my $marcflavour      = C4::Context->preference("marcflavour");
75 my $record = GetMarcBiblio($biblionumber);
76
77 #coping with subscriptions
78 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
79 my $dbh = C4::Context->dbh;
80 my $dat                 = TransformMarcToKoha( $dbh, $record );
81 my @subscriptions       =
82   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
83 my @subs;
84 foreach my $subscription (@subscriptions) {
85     my %cell;
86     $cell{subscriptionid}    = $subscription->{subscriptionid};
87     $cell{subscriptionnotes} = $subscription->{notes};
88     $cell{branchcode}        = $subscription->{branchcode};
89
90     #get the three latest serials.
91     $cell{latestserials} =
92       GetLatestSerials( $subscription->{subscriptionid}, 3 );
93     push @subs, \%cell;
94 }
95
96 $template->param(
97     subscriptions       => \@subs,
98     subscriptionsnumber => $subscriptionsnumber,
99 );
100
101 $template->param(C4::Search::enabled_opac_search_views);
102
103 my $norequests = 1;
104 my $res = GetISBDView($biblionumber, "opac");
105 my @items = &GetItemsInfo($biblionumber, 'opac');
106
107 my $itemtypes = GetItemTypes();
108 for my $itm (@items) {
109     $norequests = 0
110        if ( (not $itm->{'wthdrawn'} )
111          && (not $itm->{'itemlost'} )
112          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
113                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
114          && ($itm->{'itemnumber'} ) );
115 }
116
117 my $reviews = getreviews( $biblionumber, 1 );
118 foreach ( @$reviews ) {
119     my $borrower_number_review = $_->{borrowernumber};
120     my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
121     # setting some borrower info into this hash
122     $_->{title}     = $borrowerData->{'title'};
123     $_->{surname}   = $borrowerData->{'surname'};
124     $_->{firstname} = $borrowerData->{'firstname'};
125 }
126
127
128 $template->param(
129     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
130     AllowOnShelfHolds   => C4::Context->preference('AllowOnShelfHolds'),
131     norequests   => $norequests,
132     ISBD         => $res,
133     biblionumber => $biblionumber,
134     reviews             => $reviews,
135 );
136     my @services;
137         my $amazon_reviews  = C4::Context->preference("AmazonReviews");
138         my $amazon_similars = C4::Context->preference("AmazonSimilarItems");
139                 
140     if ( $amazon_reviews ) {
141         $template->param( AmazonReviews => 1 );
142         push( @services, 'EditorialReview' );
143     }
144     if ( $amazon_similars ) {
145         $template->param( AmazonSimilarItems => 1 );
146         push( @services, 'Similarities' );
147     }
148
149 ## Amazon.com stuff
150 #not used unless preference set
151 if ( C4::Context->preference("AmazonContent") == 1 ) {
152     use C4::External::Amazon;
153     $dat->{'amazonisbn'} = $dat->{'isbn'};
154     $dat->{'amazonisbn'} =~ s|-||g;
155
156     $template->param( amazonisbn => $dat->{amazonisbn} );
157
158     my $amazon_details = &get_amazon_details( $dat->{amazonisbn}, $record, $marcflavour );
159
160     foreach my $result ( @{ $amazon_details->{Details} } ) {
161         $template->param( item_description => $result->{ProductDescription} );
162         $template->param( image            => $result->{ImageUrlMedium} );
163         $template->param( list_price       => $result->{ListPrice} );
164         $template->param( amazon_url       => $result->{url} );
165     }
166
167     my @products;
168     my @reviews;
169     for my $details ( @{ $amazon_details->{Details} } ) {
170         next unless $details->{SimilarProducts};
171         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
172             push @products, +{ Product => $product };
173         }
174         next unless $details->{Reviews};
175         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
176             $template->param( rating => $product * 20 );
177         }
178         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
179             push @reviews,
180               +{
181                 Summary => $reviews->{Summary},
182                 Comment => $reviews->{Comment},
183               };
184         }
185     }
186     $template->param( SIMILAR_PRODUCTS => \@products );
187     $template->param( AMAZONREVIEWS    => \@reviews );
188 }
189
190 output_html_with_http_headers $query, $cookie, $template->output;