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