Bug 36792: Limit POSIX imports
[koha.git] / 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 qw( IsAvailableForItemLevelRequest );
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 use Koha::Util::MARC;
69
70 my $query = CGI->new();
71 my $biblionumber = $query->param('biblionumber');
72 my $biblio;
73 $biblio = Koha::Biblios->find( $biblionumber, { prefetch => [ 'metadata', 'items' ] } ) if $biblionumber;
74 if( !$biblio ) {
75     print $query->redirect('/cgi-bin/koha/errors/404.pl');
76     exit;
77 }
78
79 #open template
80 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
81     {
82         template_name   => "opac-ISBDdetail.tt",
83         query           => $query,
84         type            => "opac",
85         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
86     }
87 );
88
89 my $patron = Koha::Patrons->find($loggedinuser);
90
91 my $opachiddenitems_rules = C4::Context->yaml_preference('OpacHiddenItems');
92
93 unless ( $patron and $patron->category->override_hidden_items ) {
94     # only skip this check if there's a logged in user
95     # and its category overrides OpacHiddenItems
96     if ( $biblio->hidden_in_opac({ rules => $opachiddenitems_rules }) ) {
97         print $query->redirect('/cgi-bin/koha/errors/404.pl'); # escape early
98         exit;
99     }
100 }
101
102 my $record = $biblio->metadata->record;
103 my @items  = $biblio->items->filter_by_visible_in_opac({ patron => $patron })->as_list;
104
105 my $record_processor = Koha::RecordProcessor->new(
106     {   filters => [ 'EmbedItems', 'ViewPolicy' ],
107         options => {
108             interface     => 'opac',
109             frameworkcode => $biblio->frameworkcode,
110             items         => \@items
111         }
112     }
113 );
114 $record_processor->process($record);
115
116 # get biblionumbers stored in the cart
117 if(my $cart_list = $query->cookie("bib_list")){
118     my @cart_list = split(/\//, $cart_list);
119     if ( grep {$_ eq $biblionumber} @cart_list) {
120         $template->param( incart => 1 );
121     }
122 }
123
124 my $marcflavour = C4::Context->preference("marcflavour");
125 # some useful variables for enhanced content;
126 # in each case, we're grabbing the first value we find in
127 # the record and normalizing it
128 my $upc  = GetNormalizedUPC( $record, $marcflavour );
129 my $ean  = GetNormalizedEAN( $record, $marcflavour );
130 my $oclc = GetNormalizedOCLCNumber( $record, $marcflavour );
131 my $isbn = GetNormalizedISBN( undef, $record, $marcflavour );
132 my $content_identifier_exists;
133 if ( $isbn or $ean or $oclc or $upc ) {
134     $content_identifier_exists = 1;
135 }
136 $template->param(
137     normalized_upc            => $upc,
138     normalized_ean            => $ean,
139     normalized_oclc           => $oclc,
140     normalized_isbn           => $isbn,
141     content_identifier_exists => $content_identifier_exists,
142 );
143
144 #coping with subscriptions
145 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
146 my $dat                 = TransformMarcToKoha({ record => $record });
147
148 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
149 my @subs;
150 foreach my $subscription (@subscriptions) {
151     my %cell;
152         my $serials_to_display;
153     $cell{subscriptionid}    = $subscription->{subscriptionid};
154     $cell{subscriptionnotes} = $subscription->{notes};
155     $cell{branchcode}        = $subscription->{branchcode};
156
157     #get the three latest serials.
158         $serials_to_display = $subscription->{opacdisplaycount};
159         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
160         $cell{opacdisplaycount} = $serials_to_display;
161     $cell{latestserials} =
162       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
163     push @subs, \%cell;
164 }
165
166 $template->param(
167     subscriptions       => \@subs,
168     subscriptionsnumber => $subscriptionsnumber,
169 );
170
171 my $can_item_be_reserved = 0;
172 my $res = GetISBDView({
173     'record'    => $record,
174     'template'  => 'opac',
175     'framework' => $biblio->frameworkcode
176 });
177
178 my $items = $biblio->items;
179 while ( my $item = $items->next ) {
180
181     $can_item_be_reserved = $can_item_be_reserved || $patron && IsAvailableForItemLevelRequest( $item, $patron, undef );
182 }
183
184 if( $can_item_be_reserved || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
185     $template->param( ReservableItems => 1 );
186 }
187
188 my $norequests = ! $items->filter_by_for_hold->count;
189
190 $template->param(
191     norequests   => $norequests,
192     ISBD         => $res,
193     biblio       => $biblio,
194 );
195
196 #Search for title in links
197 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
198 my $marcissns = GetMarcISSN ( $record, $marcflavour );
199 my $issn = $marcissns->[0] || '';
200
201 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
202     $dat->{title} =~ s/\/+$//; # remove trailing slash
203     $dat->{title} =~ s/\s+$//; # remove trailing space
204     my $oclc_no =  Koha::Util::MARC::oclc_number( $record );
205     $search_for_title = parametrized_url(
206         $search_for_title,
207         {
208             TITLE         => $dat->{title},
209             AUTHOR        => $dat->{author},
210             ISBN          => $isbn,
211             ISSN          => $issn,
212             CONTROLNUMBER => $marccontrolnumber,
213             BIBLIONUMBER  => $biblionumber,
214             OCLC_NO       => $oclc_no,
215         }
216     );
217     $template->param('OPACSearchForTitleIn' => $search_for_title);
218 }
219
220 if( C4::Context->preference('ArticleRequests') ) {
221     my $itemtype = Koha::ItemTypes->find($biblio->itemtype);
222     my $artreqpossible = $patron
223         ? $biblio->can_article_request( $patron )
224         : $itemtype
225         ? $itemtype->may_article_request
226         : q{};
227     $template->param( artreqpossible => $artreqpossible );
228 }
229
230 output_html_with_http_headers $query, $cookie, $template->output;