Remove NOT NULL for new columns in biblioitems as they
[koha.git] / opac / opac-detail.pl
blob5266afb683f82bc00aba3c12eb453599306d0e31
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
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.
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.
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
20 # $Id$
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;
35 my $query = new CGI;
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38 template_name => "opac-detail.tmpl",
39 query => $query,
40 type => "opac",
41 authnotrequired => 1,
42 flagsrequired => { borrow => 1 },
46 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
47 $template->param( biblionumber => $biblionumber );
49 # change back when ive fixed request.pl
50 my @items = &GetItemsInfo( $biblionumber, 'opac' );
51 my $dat = &GetBiblioData($biblionumber);
52 #coping with subscriptions
53 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
54 my @subscriptions =
55 GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
56 my @subs;
57 foreach my $subscription (@subscriptions) {
58 my %cell;
59 $cell{subscriptionid} = $subscription->{subscriptionid};
60 $cell{subscriptionnotes} = $subscription->{notes};
62 #get the three latest serials.
63 $cell{latestserials} =
64 GetLatestSerials( $subscription->{subscriptionid}, 3 );
65 push @subs, \%cell;
68 $dat->{'count'} = @items;
70 #adding RequestOnOpac filter to allow or not the display of plce reserve button
71 # FIXME - use me or delete me.
72 my $RequestOnOpac;
73 if (C4::Context->preference("RequestOnOpac")) {
74 $RequestOnOpac = 1;
77 my $norequests = 1;
78 foreach my $itm (@items) {
79 $norequests = 0 && $norequests
80 if ( (not $itm->{'wthdrawn'} )
81 || (not $itm->{'itemlost'} )
82 || (not $itm->{'itemnotforloan'} )
83 || ($itm->{'itemnumber'} ) );
84 $itm->{ $itm->{'publictype'} } = 1;
87 $template->param( norequests => $norequests, RequestOnOpac=>$RequestOnOpac );
89 ## get notes and subjects from MARC record
90 my $dbh = C4::Context->dbh;
91 my $marcflavour = C4::Context->preference("marcflavour");
92 my $record = GetMarcBiblio($biblionumber);
93 my $marcnotesarray = GetMarcNotes( $record, $marcflavour );
94 my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
95 my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
96 my $marcseriesarray = GetMarcSeries($record,$marcflavour);
98 $template->param(
99 MARCNOTES => $marcnotesarray,
100 MARCSUBJCTS => $marcsubjctsarray,
101 MARCAUTHORS => $marcauthorsarray,
102 MARCSERIES => $marcseriesarray
105 my @results = ( $dat, );
106 foreach ( keys %{$dat} ) {
107 $template->param( "$_" => $dat->{$_} . "" );
110 my $reviews = getreviews( $biblionumber, 1 );
111 foreach ( @$reviews ) {
112 my $borrower_number_review = $_->{borrowernumber};
113 my $borrowerData = GetMember($borrower_number_review,'borrowernumber');
114 # setting some borrower info into this hash
115 $_->{title} = $borrowerData->{'title'};
116 $_->{surname} = $borrowerData->{'surname'};
117 $_->{firstname} = $borrowerData->{'firstname'};
120 $template->param(
121 ITEM_RESULTS => \@items,
122 subscriptionsnumber => $subscriptionsnumber,
123 biblionumber => $biblionumber,
124 subscriptions => \@subs,
125 subscriptionsnumber => $subscriptionsnumber,
126 reviews => $reviews
129 ## Amazon.com stuff
130 #not used unless preference set
131 if ( C4::Context->preference("AmazonContent") == 1 ) {
132 use C4::Amazon;
133 $dat->{'amazonisbn'} = $dat->{'isbn'};
134 $dat->{'amazonisbn'} =~ s|-||g;
136 $template->param( amazonisbn => $dat->{amazonisbn} );
138 my $amazon_details = &get_amazon_details( $dat->{amazonisbn} );
140 foreach my $result ( @{ $amazon_details->{Details} } ) {
141 $template->param( item_description => $result->{ProductDescription} );
142 $template->param( image => $result->{ImageUrlMedium} );
143 $template->param( list_price => $result->{ListPrice} );
144 $template->param( amazon_url => $result->{url} );
147 my @products;
148 my @reviews;
149 for my $details ( @{ $amazon_details->{Details} } ) {
150 next unless $details->{SimilarProducts};
151 for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
152 push @products, +{ Product => $product };
154 next unless $details->{Reviews};
155 for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
156 $template->param( rating => $product * 20 );
158 for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
159 push @reviews,
161 Summary => $reviews->{Summary},
162 Comment => $reviews->{Comment},
166 $template->param( SIMILAR_PRODUCTS => \@products );
167 $template->param( AMAZONREVIEWS => \@reviews );
169 output_html_with_http_headers $query, $cookie, $template->output;