Bug 17600: Standardize our EXPORT_OK
[srvgit] / opac / opac-ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # parts copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
22 =head1 NAME
23
24 opac-ISBDdetail.pl - script to show a biblio in ISBD format
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.tt.
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 =cut
41
42 use Modern::Perl;
43
44 use C4::Auth qw( get_template_and_user );
45 use C4::Context;
46 use C4::Output qw( parametrized_url output_html_with_http_headers );
47 use CGI qw ( -utf8 );
48 use C4::Biblio qw(
49     CountItemsIssued
50     GetISBDView
51     GetMarcControlnumber
52     GetMarcISSN
53     TransformMarcToKoha
54 );
55 use C4::Reserves;
56 use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
57 use C4::Koha qw(
58     GetNormalizedEAN
59     GetNormalizedISBN
60     GetNormalizedOCLCNumber
61     GetNormalizedUPC
62 );
63 use Koha::CirculationRules;
64 use Koha::ItemTypes;
65 use Koha::Patrons;
66 use Koha::RecordProcessor;
67 use Koha::Biblios;
68
69 my $query = CGI->new();
70 my $biblionumber = $query->param('biblionumber');
71 my $biblio;
72 $biblio = Koha::Biblios->find( $biblionumber, { prefetch => [ 'metadata', 'items' ] } ) if $biblionumber;
73 if( !$biblio ) {
74     print $query->redirect('/cgi-bin/koha/errors/404.pl');
75     exit;
76 }
77
78 #open template
79 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
80     {
81         template_name   => "opac-ISBDdetail.tt",
82         query           => $query,
83         type            => "opac",
84         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
85     }
86 );
87
88 my $patron = Koha::Patrons->find($loggedinuser);
89
90 my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
91
92 unless ( $patron and $patron->category->override_hidden_items ) {
93     # only skip this check if there's a logged in user
94     # and its category overrides OpacHiddenItems
95     if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) {
96         print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
97         exit;
98     }
99 }
100
101 my $record      = $biblio->metadata->record;
102 my $marcflavour = C4::Context->preference("marcflavour");
103
104 my $record_processor = Koha::RecordProcessor->new({
105     filters => 'ViewPolicy',
106     options => {
107         interface => 'opac',
108         frameworkcode => $biblio->frameworkcode
109     }
110 });
111 $record_processor->process($record);
112
113 # get biblionumbers stored in the cart
114 if(my $cart_list = $query->cookie("bib_list")){
115     my @cart_list = split(/\//, $cart_list);
116     if ( grep {$_ eq $biblionumber} @cart_list) {
117         $template->param( incart => 1 );
118     }
119 }
120
121 # some useful variables for enhanced content;
122 # in each case, we're grabbing the first value we find in
123 # the record and normalizing it
124 my $upc  = GetNormalizedUPC( $record, $marcflavour );
125 my $ean  = GetNormalizedEAN( $record, $marcflavour );
126 my $oclc = GetNormalizedOCLCNumber( $record, $marcflavour );
127 my $isbn = GetNormalizedISBN( undef, $record, $marcflavour );
128 my $content_identifier_exists;
129 if ( $isbn or $ean or $oclc or $upc ) {
130     $content_identifier_exists = 1;
131 }
132 $template->param(
133     normalized_upc            => $upc,
134     normalized_ean            => $ean,
135     normalized_oclc           => $oclc,
136     normalized_isbn           => $isbn,
137     content_identifier_exists => $content_identifier_exists,
138 );
139
140 #coping with subscriptions
141 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
142 my $dat                 = TransformMarcToKoha( $record );
143
144 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
145 my @subs;
146 foreach my $subscription (@subscriptions) {
147     my %cell;
148         my $serials_to_display;
149     $cell{subscriptionid}    = $subscription->{subscriptionid};
150     $cell{subscriptionnotes} = $subscription->{notes};
151     $cell{branchcode}        = $subscription->{branchcode};
152
153     #get the three latest serials.
154         $serials_to_display = $subscription->{opacdisplaycount};
155         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
156         $cell{opacdisplaycount} = $serials_to_display;
157     $cell{latestserials} =
158       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
159     push @subs, \%cell;
160 }
161
162 $template->param(
163     subscriptions       => \@subs,
164     subscriptionsnumber => $subscriptionsnumber,
165 );
166
167 my $norequests = 1;
168 my $allow_onshelf_holds;
169 my $res = GetISBDView({
170     'record'    => $record,
171     'template'  => 'opac',
172     'framework' => $biblio->frameworkcode
173 });
174
175 my $items = $biblio->items;
176 while ( my $item = $items->next ) {
177     $norequests = 0
178       if $norequests
179         && !$item->withdrawn
180         && !$item->itemlost
181         && ($item->notforloan < 0 || not $item->notforloan )
182         && !Koha::ItemTypes->find($item->effective_itemtype)->notforloan
183         && $item->itemnumber;
184
185     $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
186       unless $allow_onshelf_holds;
187 }
188
189 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
190     $template->param( ReservableItems => 1 );
191 }
192
193 $template->param(
194     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
195     norequests   => $norequests,
196     ISBD         => $res,
197     biblio       => $biblio,
198 );
199
200 #Search for title in links
201 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
202 my $marcissns = GetMarcISSN ( $record, $marcflavour );
203 my $issn = $marcissns->[0] || '';
204
205 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
206     $dat->{title} =~ s/\/+$//; # remove trailing slash
207     $dat->{title} =~ s/\s+$//; # remove trailing space
208     $search_for_title = parametrized_url(
209         $search_for_title,
210         {
211             TITLE         => $dat->{title},
212             AUTHOR        => $dat->{author},
213             ISBN          => $isbn,
214             ISSN          => $issn,
215             CONTROLNUMBER => $marccontrolnumber,
216             BIBLIONUMBER  => $biblionumber,
217         }
218     );
219     $template->param('OPACSearchForTitleIn' => $search_for_title);
220 }
221
222 if( C4::Context->preference('ArticleRequests') ) {
223     my $itemtype = Koha::ItemTypes->find($biblio->itemtype);
224     my $artreqpossible = $patron
225         ? $biblio->can_article_request( $patron )
226         : $itemtype
227         ? $itemtype->may_article_request
228         : q{};
229     $template->param( artreqpossible => $artreqpossible );
230 }
231
232 output_html_with_http_headers $query, $cookie, $template->output;