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