adding GetMarcUrls() fcn to display 856's - adding also output to opac-detail.
[koha.git] / opac / opac-detail.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 # $Id$
21
22 use strict;
23 require Exporter;
24 use CGI;
25 use C4::Auth;
26 use C4::Serials;    #uses getsubscriptionfrom biblionumber
27 use C4::Output;
28 use C4::Biblio;
29 use C4::Amazon;
30 use C4::Review;
31 use C4::Serials;
32 use C4::Members;
33
34
35 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37     {
38         template_name   => "opac-detail.tmpl",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 1,
42         flagsrequired   => { borrow => 1 },
43     }
44 );
45
46 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
47 $template->param( biblionumber => $biblionumber );
48
49 # change back when ive fixed request.pl
50 my @items = &GetItemsInfo( $biblionumber, 'opac' );
51 my $dat = &GetBiblioData($biblionumber);
52
53 if (!$dat) {
54     print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
55 }
56
57 #coping with subscriptions
58 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
59 my @subscriptions       =
60   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
61 my @subs;
62 foreach my $subscription (@subscriptions) {
63     my %cell;
64     $cell{subscriptionid}    = $subscription->{subscriptionid};
65     $cell{subscriptionnotes} = $subscription->{notes};
66
67     #get the three latest serials.
68     $cell{latestserials} =
69       GetLatestSerials( $subscription->{subscriptionid}, 3 );
70     push @subs, \%cell;
71 }
72
73 $dat->{'count'} = @items;
74
75 #adding RequestOnOpac filter to allow or not the display of plce reserve button
76 # FIXME - use me or delete me.
77 my $RequestOnOpac;
78 if (C4::Context->preference("RequestOnOpac")) {
79         $RequestOnOpac = 1;
80 }
81
82 my $norequests = 1;
83 foreach my $itm (@items) {
84      $norequests = 0 && $norequests
85        if ( (not $itm->{'wthdrawn'} )
86           || (not $itm->{'itemlost'} )
87          || (not $itm->{'itemnotforloan'} )
88          || ($itm->{'itemnumber'} ) );
89      $itm->{ $itm->{'publictype'} } = 1;
90 }
91
92 $template->param( norequests => $norequests, RequestOnOpac=>$RequestOnOpac );
93
94 ## get notes and subjects from MARC record
95     my $dbh              = C4::Context->dbh;
96     my $marcflavour      = C4::Context->preference("marcflavour");
97     my $record           = GetMarcBiblio($biblionumber);
98     my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
99     my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
100     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
101         my $marcseriesarray  = GetMarcSeries($record,$marcflavour);
102         my $marcurlsarray       = GetMarcUrls($record,$marcflavour);
103
104     $template->param(
105         MARCNOTES   => $marcnotesarray,
106         MARCSUBJCTS => $marcsubjctsarray,
107         MARCAUTHORS => $marcauthorsarray,
108                 MARCSERIES  => $marcseriesarray,
109                 MARCURLS        => $marcurlsarray,
110     );
111
112 my @results = ( $dat, );
113 foreach ( keys %{$dat} ) {
114     $template->param( "$_" => $dat->{$_} . "" );
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 $template->param(
128     ITEM_RESULTS        => \@items,
129     subscriptionsnumber => $subscriptionsnumber,
130     biblionumber        => $biblionumber,
131     subscriptions       => \@subs,
132     subscriptionsnumber => $subscriptionsnumber,
133     reviews             => $reviews
134 );
135
136 ## Amazon.com stuff
137 #not used unless preference set
138 if ( C4::Context->preference("AmazonContent") == 1 ) {
139     use C4::Amazon;
140     $dat->{'amazonisbn'} = $dat->{'isbn'};
141     $dat->{'amazonisbn'} =~ s|-||g;
142
143     $template->param( amazonisbn => $dat->{amazonisbn} );
144
145     my $amazon_details = &get_amazon_details( $dat->{amazonisbn} );
146
147     foreach my $result ( @{ $amazon_details->{Details} } ) {
148         $template->param( item_description => $result->{ProductDescription} );
149         $template->param( image            => $result->{ImageUrlMedium} );
150         $template->param( list_price       => $result->{ListPrice} );
151         $template->param( amazon_url       => $result->{url} );
152     }
153
154     my @products;
155     my @reviews;
156     for my $details ( @{ $amazon_details->{Details} } ) {
157         next unless $details->{SimilarProducts};
158         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
159             push @products, +{ Product => $product };
160         }
161         next unless $details->{Reviews};
162         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
163             $template->param( rating => $product * 20 );
164         }
165         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
166             push @reviews,
167               +{
168                 Summary => $reviews->{Summary},
169                 Comment => $reviews->{Comment},
170               };
171         }
172     }
173     $template->param( SIMILAR_PRODUCTS => \@products );
174     $template->param( AMAZONREVIEWS    => \@reviews );
175 }
176 output_html_with_http_headers $query, $cookie, $template->output;