BUG-1533, adding sys-pref search back in, too handy for deving/testing.
[koha.git] / catalogue / detail.pl
blob82ee42905eac8373930e81684d732bd962fd02a7
1 #!/usr/bin/perl
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
19 use strict;
20 require Exporter;
21 use CGI;
22 use C4::Auth;
23 use C4::Serials; #uses getsubscriptionfrom biblionumber
24 use C4::Output;
25 use C4::Biblio;
26 use C4::Serials;
27 use C4::XISBN qw(get_xisbns get_biblio_from_xisbn);
28 use C4::Amazon;
30 my $query = new CGI;
31 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
33 template_name => "catalogue/detail.tmpl",
34 query => $query,
35 type => "intranet",
36 authnotrequired => 0,
37 flagsrequired => { catalogue => 1 },
41 my $biblionumber = $query->param('biblionumber');
43 # change back when ive fixed request.pl
44 my @items = &GetItemsInfo( $biblionumber, 'intra' );
45 my $dat = &GetBiblioData($biblionumber);
47 if (!$dat) {
48 print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
51 #coping with subscriptions
52 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
53 my @subscriptions = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
55 my @subs;
56 foreach my $subscription (@subscriptions) {
57 my %cell;
58 $cell{subscriptionid} = $subscription->{subscriptionid};
59 $cell{subscriptionnotes} = $subscription->{notes};
61 #get the three latest serials.
62 $cell{latestserials} =
63 GetLatestSerials( $subscription->{subscriptionid}, 3 );
64 push @subs, \%cell;
67 $dat->{'count'} = @items;
69 my $norequests = 1;
70 foreach my $itm (@items) {
71 $norequests = 0
72 unless ( ( $itm->{'notforloan'} > 0 )
73 || ( $itm->{'itemnotforloan'} > 0 ) );
74 $itm->{ $itm->{'publictype'} } = 1;
77 $template->param( norequests => $norequests );
79 ## get notes and subjects from MARC record
80 my $dbh = C4::Context->dbh;
81 my $marcflavour = C4::Context->preference("marcflavour");
82 my $record = GetMarcBiblio($biblionumber);
83 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
84 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
85 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
87 $template->param(
88 MARCNOTES => $marcnotesarray,
89 MARCSUBJCTS => $marcsubjctsarray,
90 MARCAUTHORS => $marcauthorsarray
93 my @results = ( $dat, );
94 foreach ( keys %{$dat} ) {
95 $template->param( "$_" => $dat->{$_} . "" );
98 $template->param(
99 ITEM_RESULTS => \@items,
100 biblionumber => $biblionumber,
101 detailview => 1,
102 subscriptions => \@subs,
103 subscriptionsnumber => $subscriptionsnumber,
104 subscriptiontitle => $dat->{title},
107 # XISBN Stuff
108 my $xisbn=$dat->{'isbn'};
109 $xisbn =~ s/(p|-| |:)//g;
110 $template->param(amazonisbn => $xisbn);
111 if (C4::Context->preference("FRBRizeEditions")==1) {
112 eval {
113 $template->param(
114 xisbn => $xisbn,
115 XISBNS => get_xisbns($xisbn)
118 if ($@) { warn "XISBN Failed $@"; }
120 if ( C4::Context->preference("AmazonContent") == 1 ) {
121 my $amazon_details = &get_amazon_details( $xisbn );
122 foreach my $result ( @{ $amazon_details->{Details} } ) {
123 $template->param( item_description => $result->{ProductDescription} );
124 $template->param( image => $result->{ImageUrlMedium} );
125 $template->param( list_price => $result->{ListPrice} );
126 $template->param( amazon_url => $result->{url} );
129 my @products;
130 my @reviews;
131 for my $details ( @{ $amazon_details->{Details} } ) {
132 next unless $details->{SimilarProducts};
133 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
134 if (C4::Context->preference("AmazonSimilarItems") ) {
135 my $xbiblios;
136 my @xisbns;
138 if (C4::Context->preference("XISBNAmazonSimilarItems") ) {
139 my $xbiblio = get_biblio_from_xisbn($product);
140 push @xisbns, $xbiblio;
141 $xbiblios = \@xisbns;
143 else {
144 $xbiblios = get_xisbns($product);
146 push @products, +{ product => $xbiblios };
149 next unless $details->{Reviews};
150 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
151 $template->param( rating => $product * 20 );
153 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
154 push @reviews,
156 summary => $reviews->{Summary},
157 comment => $reviews->{Comment},
161 $template->param( SIMILAR_PRODUCTS => \@products );
162 $template->param( AMAZONREVIEWS => \@reviews );
165 output_html_with_http_headers $query, $cookie, $template->output;