bug 2893: extend conditions handled by AllowNotForLoanOverride
[koha.git] / opac / opac-ISBDdetail.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 =head1 NAME
22
23 opac-ISBDdetail.pl : script to show a biblio in ISBD format
24
25
26 =head1 DESCRIPTION
27
28 This script needs a biblionumber as parameter 
29
30 It shows the biblio
31
32 The template is in <templates_dir>/catalogue/ISBDdetail.tmpl.
33 this template must be divided into 11 "tabs".
34
35 The first 10 tabs present the biblio, the 11th one presents
36 the items attached to the biblio
37
38 =head1 FUNCTIONS
39
40 =over 2
41
42 =cut
43
44 use strict;
45 use C4::Auth;
46 use C4::Context;
47 use C4::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Biblio;
51 use C4::Acquisition;
52 use C4::Review;
53 use C4::Serials;    # uses getsubscriptionfrom biblionumber
54 use C4::Koha;
55 use C4::Members;    # GetMember
56 use C4::External::Amazon;
57
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60     {
61         template_name   => "opac-ISBDdetail.tmpl",
62         query           => $query,
63         type            => "opac",
64         authnotrequired => 1,
65         debug           => 1,
66     }
67 );
68
69 my $biblionumber = $query->param('biblionumber');
70
71 my $marcflavour      = C4::Context->preference("marcflavour");
72 my $record = GetMarcBiblio($biblionumber);
73
74 # some useful variables for enhanced content;
75 # in each case, we're grabbing the first value we find in
76 # the record and normalizing it
77 my $upc = GetNormalizedUPC($record,$marcflavour);
78 my $ean = GetNormalizedEAN($record,$marcflavour);
79 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
80 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
81 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
82 $template->param(
83     normalized_upc => $upc,
84     normalized_ean => $ean,
85     normalized_oclc => $oclc,
86     normalized_isbn => $isbn,
87         content_identifier_exists => $content_identifier_exists,
88 );
89
90 #coping with subscriptions
91 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
92 my $dbh = C4::Context->dbh;
93 my $dat                 = TransformMarcToKoha( $dbh, $record );
94 my @subscriptions       =
95   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
96 my @subs;
97 foreach my $subscription (@subscriptions) {
98     my %cell;
99         my $serials_to_display;
100     $cell{subscriptionid}    = $subscription->{subscriptionid};
101     $cell{subscriptionnotes} = $subscription->{notes};
102     $cell{branchcode}        = $subscription->{branchcode};
103
104     #get the three latest serials.
105         $serials_to_display = $subscription->{opacdisplaycount};
106         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
107         $cell{opacdisplaycount} = $serials_to_display;
108     $cell{latestserials} =
109       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
110     push @subs, \%cell;
111 }
112
113 $template->param(
114     subscriptions       => \@subs,
115     subscriptionsnumber => $subscriptionsnumber,
116 );
117
118 # my @blocs = split /\@/,$ISBD;
119 # my @fields = $record->fields();
120 my $res = GetISBDView($biblionumber);
121
122 my $reviews = getreviews( $biblionumber, 1 );
123 foreach ( @$reviews ) {
124     my $borrower_number_review = $_->{borrowernumber};
125     my $borrowerData           = GetMember($borrower_number_review,'borrowernumber');
126     # setting some borrower info into this hash
127     $_->{title}     = $borrowerData->{'title'};
128     $_->{surname}   = $borrowerData->{'surname'};
129     $_->{firstname} = $borrowerData->{'firstname'};
130 }
131
132
133 $template->param(
134     ISBD         => $res,
135     biblionumber => $biblionumber,
136     reviews             => $reviews,
137 );
138
139 ## Amazon.com stuff
140 #not used unless preference set
141 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
142
143     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
144
145     foreach my $result ( @{ $amazon_details->{Details} } ) {
146         $template->param( item_description => $result->{ProductDescription} );
147         $template->param( image            => $result->{ImageUrlMedium} );
148         $template->param( list_price       => $result->{ListPrice} );
149         $template->param( amazon_url       => $result->{url} );
150     }
151
152     my @products;
153     my @reviews;
154     for my $details ( @{ $amazon_details->{Details} } ) {
155         next unless $details->{SimilarProducts};
156         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
157             push @products, +{ Product => $product };
158         }
159         next unless $details->{Reviews};
160         for my $product ( @{ $details->{Reviews}->{AvgCustomerRating} } ) {
161             $template->param( rating => $product * 20 );
162         }
163         for my $reviews ( @{ $details->{Reviews}->{CustomerReview} } ) {
164             push @reviews,
165               +{
166                 Summary => $reviews->{Summary},
167                 Comment => $reviews->{Comment},
168               };
169         }
170     }
171     $template->param( SIMILAR_PRODUCTS => \@products );
172     $template->param( AMAZONREVIEWS    => \@reviews );
173 }
174
175 output_html_with_http_headers $query, $cookie, $template->output;