(bug #3772) show place hold button in isbd view
[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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 warnings;
46
47 use C4::Auth;
48 use C4::Context;
49 use C4::Output;
50 use CGI;
51 use MARC::Record;
52 use C4::Biblio;
53 use C4::Items;
54 use C4::Acquisition;
55 use C4::Review;
56 use C4::Serials;    # uses getsubscriptionfrom biblionumber
57 use C4::Koha;
58 use C4::Members;    # GetMember
59 use C4::External::Amazon;
60
61 my $query = CGI->new();
62 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
63     {
64         template_name   => "opac-ISBDdetail.tmpl",
65         query           => $query,
66         type            => "opac",
67         authnotrequired => 1,
68         debug           => 1,
69     }
70 );
71
72 my $biblionumber = $query->param('biblionumber');
73
74 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
75 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
76
77 my $marcflavour      = C4::Context->preference("marcflavour");
78 my $record = GetMarcBiblio($biblionumber);
79 if ( ! $record ) {
80     print $query->redirect("/cgi-bin/koha/errors/404.pl");
81     exit;
82 }
83 # some useful variables for enhanced content;
84 # in each case, we're grabbing the first value we find in
85 # the record and normalizing it
86 my $upc = GetNormalizedUPC($record,$marcflavour);
87 my $ean = GetNormalizedEAN($record,$marcflavour);
88 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
89 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
90 my $content_identifier_exists = 1 if ($isbn or $ean or $oclc or $upc);
91 $template->param(
92     normalized_upc => $upc,
93     normalized_ean => $ean,
94     normalized_oclc => $oclc,
95     normalized_isbn => $isbn,
96         content_identifier_exists => $content_identifier_exists,
97 );
98
99 #coping with subscriptions
100 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
101 my $dbh = C4::Context->dbh;
102 my $dat                 = TransformMarcToKoha( $dbh, $record );
103 my @subscriptions       =
104   GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
105 my @subs;
106 foreach my $subscription (@subscriptions) {
107     my %cell;
108         my $serials_to_display;
109     $cell{subscriptionid}    = $subscription->{subscriptionid};
110     $cell{subscriptionnotes} = $subscription->{notes};
111     $cell{branchcode}        = $subscription->{branchcode};
112
113     #get the three latest serials.
114         $serials_to_display = $subscription->{opacdisplaycount};
115         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
116         $cell{opacdisplaycount} = $serials_to_display;
117     $cell{latestserials} =
118       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
119     push @subs, \%cell;
120 }
121
122 $template->param(
123     subscriptions       => \@subs,
124     subscriptionsnumber => $subscriptionsnumber,
125 );
126
127 my $norequests = 1;
128 my $res = GetISBDView($biblionumber, "opac");
129 my @items = &GetItemsInfo($biblionumber, 'opac');
130
131 my $itemtypes = GetItemTypes();
132 for my $itm (@items) {
133     $norequests = 0
134        if ( (not $itm->{'wthdrawn'} )
135          && (not $itm->{'itemlost'} )
136          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
137                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
138          && ($itm->{'itemnumber'} ) );
139 }
140
141 my $reviews = getreviews( $biblionumber, 1 );
142 foreach ( @$reviews ) {
143     my $borrower_number_review = $_->{borrowernumber};
144     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
145     # setting some borrower info into this hash
146     $_->{title}     = $borrowerData->{'title'};
147     $_->{surname}   = $borrowerData->{'surname'};
148     $_->{firstname} = $borrowerData->{'firstname'};
149 }
150
151
152 $template->param(
153     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
154     AllowOnShelfHolds   => C4::Context->preference('AllowOnShelfHolds'),
155     norequests   => $norequests,
156     ISBD         => $res,
157     biblionumber => $biblionumber,
158     reviews             => $reviews,
159 );
160
161 ## Amazon.com stuff
162 #not used unless preference set
163 if ( C4::Context->preference("OPACAmazonEnabled") == 1 ) {
164
165     my $amazon_details = &get_amazon_details( $isbn, $record, $marcflavour );
166
167     foreach my $result ( @{ $amazon_details->{Details} } ) {
168         $template->param( item_description => $result->{ProductDescription} );
169         $template->param( image            => $result->{ImageUrlMedium} );
170         $template->param( list_price       => $result->{ListPrice} );
171         $template->param( amazon_url       => $result->{url} );
172     }
173
174     my @products;
175     my @reviews;
176     for my $details ( @{ $amazon_details->{Details} } ) {
177         next unless $details->{SimilarProducts};
178         for my $product ( @{ $details->{SimilarProducts}->{Product} } ) {
179             push @products, +{ Product => $product };
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;