d60f8fcb267484d119c3cb43018bdbd5283a8eb2
[koha_gimpoz] / 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 C4::Auth;
46 use C4::Context;
47 use C4::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Biblio;
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;
57
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60     {
61         template_name   => "opac-ISBDdetail.tmpl",
62         query           => $query,
63         type            => "opac",
64         authnotrequired => 1,
65         debug           => 1,
66     }
67 );
68
69 my $biblionumber = $query->param('biblionumber');
70
71 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
72 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
73
74 my $marcflavour      = C4::Context->preference("marcflavour");
75 my $record = GetMarcBiblio($biblionumber);
76
77 # some useful variables for enhanced content;
78 # in each case, we're grabbing the first value we find in
79 # the record and normalizing it
80 my $upc = GetNormalizedUPC($record,$marcflavour);
81 my $ean = GetNormalizedEAN($record,$marcflavour);
82 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
83 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
84 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
85 $template->param(
86     normalized_upc => $upc,
87     normalized_ean => $ean,
88     normalized_oclc => $oclc,
89     normalized_isbn => $isbn,
90         content_identifier_exists => $content_identifier_exists,
91 );
92
93 #coping with subscriptions
94 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
95 my $dbh = C4::Context->dbh;
96 my $dat                 = TransformMarcToKoha( $dbh, $record );
97 my @subscriptions       =
98   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
99 my @subs;
100 foreach my $subscription (@subscriptions) {
101     my %cell;
102         my $serials_to_display;
103     $cell{subscriptionid}    = $subscription->{subscriptionid};
104     $cell{subscriptionnotes} = $subscription->{notes};
105     $cell{branchcode}        = $subscription->{branchcode};
106
107     #get the three latest serials.
108         $serials_to_display = $subscription->{opacdisplaycount};
109         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
110         $cell{opacdisplaycount} = $serials_to_display;
111     $cell{latestserials} =
112       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
113     push @subs, \%cell;
114 }
115
116 $template->param(
117     subscriptions       => \@subs,
118     subscriptionsnumber => $subscriptionsnumber,
119 );
120
121 # my @blocs = split /\@/,$ISBD;
122 # my @fields = $record->fields();
123 my $res = GetISBDView($biblionumber);
124
125 my $reviews = getreviews( $biblionumber, 1 );
126 foreach ( @$reviews ) {
127     my $borrower_number_review = $_->{borrowernumber};
128     my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
129     # setting some borrower info into this hash
130     $_->{title}     = $borrowerData->{'title'};
131     $_->{surname}   = $borrowerData->{'surname'};
132     $_->{firstname} = $borrowerData->{'firstname'};
133 }
134
135
136 $template->param(
137     ISBD         => $res,
138     biblionumber => $biblionumber,
139     reviews             => $reviews,
140 );
141
142 ## Amazon.com stuff
143 #not used unless preference set
144 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
145
146     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
147
148     foreach my $result ( @{ $amazon_details->{Details} } ) {
149         $template->param( item_description => $result->{ProductDescription} );
150         $template->param( image            => $result->{ImageUrlMedium} );
151         $template->param( list_price       => $result->{ListPrice} );
152         $template->param( amazon_url       => $result->{url} );
153     }
154
155     my @products;
156     my @reviews;
157     for my $details ( @{ $amazon_details->{Details} } ) {
158         next unless $details->{SimilarProducts};
159         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
160             push @products, +{ Product => $product };
161         }
162         next unless $details->{Reviews};
163         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
164             $template->param( rating => $product * 20 );
165         }
166         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
167             push @reviews,
168               +{
169                 Summary => $reviews->{Summary},
170                 Comment => $reviews->{Comment},
171               };
172         }
173     }
174     $template->param( SIMILAR_PRODUCTS => \@products );
175     $template->param( AMAZONREVIEWS    => \@reviews );
176 }
177
178 output_html_with_http_headers $query, $cookie, $template->output;