fixing syntax error in sysprefs.sql
[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::XISBN qw(get_xisbns get_biblio_from_xisbn);
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 # XISBN Stuff
137 my $xisbn=$dat->{'isbn'};
138 $xisbn =~ s/(p|-| |:)//g;
139 $template->param(amazonisbn => $xisbn);
140 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
141     eval {
142         $template->param(
143             xisbn => $xisbn,
144             XISBNS => get_xisbns($xisbn)
145         );
146     };
147     if ($@) { warn "XISBN Failed $@"; }
148 }
149 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
150     my $amazon_details = &get_amazon_details( $xisbn );
151     foreach my $result ( @{ $amazon_details->{Details} } ) {
152         $template->param( item_description => $result->{ProductDescription} );
153         $template->param( image            => $result->{ImageUrlMedium} );
154         $template->param( list_price       => $result->{ListPrice} );
155         $template->param( amazon_url       => $result->{url} );
156     }
157
158     my @products;
159     my @reviews;
160     for my $details ( @{ $amazon_details->{Details} } ) {
161         next unless $details->{SimilarProducts};
162         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
163             if (C4::Context->preference("OPACAmazonSimilarItems") ) {
164                 my $xbiblios;
165                 my @xisbns;
166
167                 if (C4::Context->preference("OPACXISBNAmazonSimilarItems") ) {
168                     my $xbiblio = get_biblio_from_xisbn($product);
169                     push @xisbns, $xbiblio;
170                     $xbiblios = \@xisbns;
171                 }
172                 else {
173                     $xbiblios = get_xisbns($product);
174                 }
175                 push @products, +{ product => $xbiblios };
176             }
177         }
178         next unless $details->{Reviews};
179         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
180             $template->param( rating => $product * 20 );
181         }
182         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
183             push @reviews,
184               +{
185                 summary => $reviews->{Summary},
186                 comment => $reviews->{Comment},
187               };
188         }
189     }
190     $template->param( SIMILAR_PRODUCTS => \@products );
191     $template->param( AMAZONREVIEWS    => \@reviews );
192 }
193
194 output_html_with_http_headers $query, $cookie, $template->output;