removed superfluous and unclosed TMPL_IF
[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::Koha;
26 use C4::Serials;    #uses getsubscriptionfrom biblionumber
27 use C4::Output;
28 use C4::Biblio;
29 use C4::XISBN qw(get_xisbns get_biblio_from_xisbn);
30 use C4::Amazon;
31 use C4::Review;
32 use C4::Serials;
33 use C4::Members;
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         #get collection code description, too
92         $itm->{'ccode'}  = GetAuthorisedValueDesc('','',   $itm->{'ccode'} ,'','','CCODE');
93 }
94
95 $template->param( norequests => $norequests, RequestOnOpac=>$RequestOnOpac );
96
97 ## get notes and subjects from MARC record
98     my $dbh              = C4::Context->dbh;
99     my $marcflavour      = C4::Context->preference("marcflavour");
100     my $record           = GetMarcBiblio($biblionumber);
101     my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
102     my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
103     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
104         my $marcseriesarray  = GetMarcSeries($record,$marcflavour);
105         my $marcurlsarray       = GetMarcUrls($record,$marcflavour);
106
107     $template->param(
108         MARCNOTES   => $marcnotesarray,
109         MARCSUBJCTS => $marcsubjctsarray,
110         MARCAUTHORS => $marcauthorsarray,
111                 MARCSERIES  => $marcseriesarray,
112                 MARCURLS        => $marcurlsarray,
113     );
114
115 my @results = ( $dat, );
116 foreach ( keys %{$dat} ) {
117     $template->param( "$_" => $dat->{$_} . "" );
118 }
119
120 my $reviews = getreviews( $biblionumber, 1 );
121 foreach ( @$reviews ) {
122     my $borrower_number_review = $_->{borrowernumber};
123     my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
124     # setting some borrower info into this hash
125     $_->{title}     = $borrowerData->{'title'};
126     $_->{surname}   = $borrowerData->{'surname'};
127     $_->{firstname} = $borrowerData->{'firstname'};
128 }
129
130 $template->param(
131     ITEM_RESULTS        => \@items,
132     subscriptionsnumber => $subscriptionsnumber,
133     biblionumber        => $biblionumber,
134     subscriptions       => \@subs,
135     subscriptionsnumber => $subscriptionsnumber,
136     reviews             => $reviews
137 );
138
139 # XISBN Stuff
140 my $xisbn=$dat->{'isbn'};
141 $xisbn =~ s/(p|-| |:)//g;
142 $template->param(amazonisbn => $xisbn);
143 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
144     eval {
145         $template->param(
146             xisbn => $xisbn,
147             XISBNS => get_xisbns($xisbn)
148         );
149     };
150     if ($@) { warn "XISBN Failed $@"; }
151 }
152 if ( C4::Context->preference("OPACAmazonContent") == 1 ) {
153     my $amazon_details = &get_amazon_details( $xisbn );
154     foreach my $result ( @{ $amazon_details->{Details} } ) {
155         $template->param( item_description => $result->{ProductDescription} );
156         $template->param( image            => $result->{ImageUrlMedium} );
157         $template->param( list_price       => $result->{ListPrice} );
158         $template->param( amazon_url       => $result->{url} );
159     }
160
161     my @products;
162     my @reviews;
163     for my $details ( @{ $amazon_details->{Details} } ) {
164         next unless $details->{SimilarProducts};
165         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
166             if (C4::Context->preference("OPACAmazonSimilarItems") ) {
167                 my $xbiblios;
168                 my @xisbns;
169
170                 if (C4::Context->preference("OPACXISBNAmazonSimilarItems") ) {
171                     my $xbiblio = get_biblio_from_xisbn($product);
172                     push @xisbns, $xbiblio;
173                     $xbiblios = \@xisbns;
174                 }
175                 else {
176                     $xbiblios = get_xisbns($product);
177                 }
178                 push @products, +{ product => $xbiblios };
179             }
180         }
181         next unless $details->{Reviews};
182         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
183             $template->param( rating => $product * 20 );
184         }
185         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
186             push @reviews,
187               +{
188                 summary => $reviews->{Summary},
189                 comment => $reviews->{Comment},
190               };
191         }
192     }
193     $template->param( SIMILAR_PRODUCTS => \@products );
194     $template->param( AMAZONREVIEWS    => \@reviews );
195 }
196
197 output_html_with_http_headers $query, $cookie, $template->output;