Bug 11856: Add confirm option to POD in advance_notices.pl
[koha.git] / opac / opac-detail.pl
blob01c801f371bca1c6f35129cccaeca7ac3b107005
1 #!/usr/bin/perl
3 # Copyright 2000-2002 Katipo Communications
4 # Copyright 2010 BibLibre
5 # Copyright 2011 KohaAloha, NZ
7 # This file is part of Koha.
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 use strict;
24 use warnings;
26 use CGI;
27 use C4::Auth qw(:DEFAULT get_session);
28 use C4::Branch;
29 use C4::Koha;
30 use C4::Serials; #uses getsubscriptionfrom biblionumber
31 use C4::Output;
32 use C4::Biblio;
33 use C4::Items;
34 use C4::Circulation;
35 use C4::Tags qw(get_tags);
36 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
37 use C4::External::Amazon;
38 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39 use C4::Review;
40 use C4::Ratings;
41 use C4::Members;
42 use C4::VirtualShelves;
43 use C4::XSLT;
44 use C4::ShelfBrowser;
45 use C4::Reserves;
46 use C4::Charset;
47 use MARC::Record;
48 use MARC::Field;
49 use List::MoreUtils qw/any none/;
50 use C4::Images;
51 use Koha::DateUtils;
52 use C4::HTML5Media;
53 use C4::CourseReserves qw(GetItemCourseReservesInfo);
55 BEGIN {
56 if (C4::Context->preference('BakerTaylorEnabled')) {
57 require C4::External::BakerTaylor;
58 import C4::External::BakerTaylor qw(&image_url &link_url);
62 my $query = new CGI;
63 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
65 template_name => "opac-detail.tmpl",
66 query => $query,
67 type => "opac",
68 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69 flagsrequired => { borrow => 1 },
73 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
74 $biblionumber = int($biblionumber);
76 my @all_items = GetItemsInfo($biblionumber);
77 my @hiddenitems;
78 if (scalar @all_items >= 1) {
79 push @hiddenitems, GetHiddenItemnumbers(@all_items);
81 if (scalar @hiddenitems == scalar @all_items ) {
82 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
83 exit;
87 my $record = GetMarcBiblio($biblionumber);
88 if ( ! $record ) {
89 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90 exit;
93 # redirect if opacsuppression is enabled and biblio is suppressed
94 if (C4::Context->preference('OpacSuppression')) {
95 # FIXME hardcoded; the suppression flag ought to be materialized
96 # as a column on biblio or the like
97 my $opacsuppressionfield = '942';
98 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
99 # redirect to opac-blocked info page or 404?
100 my $opacsuppressionredirect;
101 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
102 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
103 } else {
104 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
106 if ( $opacsuppressionfieldvalue &&
107 $opacsuppressionfieldvalue->subfield("n") &&
108 $opacsuppressionfieldvalue->subfield("n") == 1) {
109 # if OPAC suppression by IP address
110 if (C4::Context->preference('OpacSuppressionByIPRange')) {
111 my $IPAddress = $ENV{'REMOTE_ADDR'};
112 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
113 if ($IPAddress !~ /^$IPRange/) {
114 print $query->redirect($opacsuppressionredirect);
115 exit;
117 } else {
118 print $query->redirect($opacsuppressionredirect);
119 exit;
124 $template->param( biblionumber => $biblionumber );
126 # get biblionumbers stored in the cart
127 my @cart_list;
129 if($query->cookie("bib_list")){
130 my $cart_list = $query->cookie("bib_list");
131 @cart_list = split(/\//, $cart_list);
132 if ( grep {$_ eq $biblionumber} @cart_list) {
133 $template->param( incart => 1 );
138 SetUTF8Flag($record);
139 my $marcflavour = C4::Context->preference("marcflavour");
140 my $ean = GetNormalizedEAN( $record, $marcflavour );
142 # XSLT processing of some stuff
143 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
144 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
147 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
148 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
150 # We look for the busc param to build the simple paging from the search
151 if ($OpacBrowseResults) {
152 my $session = get_session($query->cookie("CGISESSID"));
153 my %paging = (previous => {}, next => {});
154 if ($session->param('busc')) {
155 use C4::Search;
157 # Rebuild the string to store on session
158 sub rebuildBuscParam
160 my $arrParamsBusc = shift;
162 my $pasarParams = '';
163 my $j = 0;
164 for (keys %$arrParamsBusc) {
165 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
166 if (defined($arrParamsBusc->{$_})) {
167 $pasarParams .= '&' if ($j);
168 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
169 $j++;
171 } else {
172 for my $value (@{$arrParamsBusc->{$_}}) {
173 $pasarParams .= '&' if ($j);
174 $pasarParams .= $_ . '=' . $value;
175 $j++;
179 return $pasarParams;
180 }#rebuildBuscParam
182 # Search given the current values from the busc param
183 sub searchAgain
185 my ($arrParamsBusc, $offset, $results_per_page) = @_;
187 my $expanded_facet = $arrParamsBusc->{'expand'};
188 my $branches = GetBranches();
189 my $itemtypes = GetItemTypes;
190 my @servers;
191 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
192 @servers = ("biblioserver") unless (@servers);
194 my ($default_sort_by, @sort_by);
195 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
196 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
197 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
198 my ($error, $results_hashref, $facets);
199 eval {
200 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
202 my $hits;
203 my @newresults;
204 for (my $i=0;$i<@servers;$i++) {
205 my $server = $servers[$i];
206 $hits = $results_hashref->{$server}->{"hits"};
207 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
209 return \@newresults;
210 }#searchAgain
212 # Build the current list of biblionumbers in this search
213 sub buildListBiblios
215 my ($newresultsRef, $results_per_page) = @_;
217 my $listBiblios = '';
218 my $j = 0;
219 foreach (@$newresultsRef) {
220 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
221 $listBiblios .= $bibnum . ',';
222 $j++;
223 last if ($j == $results_per_page);
225 chop $listBiblios if ($listBiblios =~ /,$/);
226 return $listBiblios;
227 }#buildListBiblios
229 my $busc = $session->param("busc");
230 my @arrBusc = split(/\&(?:amp;)?/, $busc);
231 my ($key, $value);
232 my %arrParamsBusc = ();
233 for (@arrBusc) {
234 ($key, $value) = split(/=/, $_, 2);
235 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
236 $arrParamsBusc{$key} = $value;
237 } else {
238 unless (exists($arrParamsBusc{$key})) {
239 $arrParamsBusc{$key} = [];
241 push @{$arrParamsBusc{$key}}, $value;
244 my $searchAgain = 0;
245 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
246 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
247 $arrParamsBusc{'count'} = $results_per_page;
248 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
249 # The value OPACnumSearchResults has changed and the search has to be rebuild
250 if ($count != $results_per_page) {
251 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
252 my $indexBiblio = 0;
253 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
254 for (@arrBibliosAux) {
255 last if ($_ == $biblionumber);
256 $indexBiblio++;
258 $indexBiblio += $offset;
259 $offset = int($indexBiblio / $count) * $count;
260 $arrParamsBusc{'offset'} = $offset;
262 $arrParamsBusc{'count'} = $count;
263 $results_per_page = $count;
264 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
265 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
266 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
267 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
268 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
269 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
270 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
271 $session->param("busc" => $newbusc);
272 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
273 } else {
274 my $modifyListBiblios = 0;
275 # We come from a previous click
276 if (exists($arrParamsBusc{'previous'})) {
277 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
278 delete $arrParamsBusc{'previous'};
279 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
280 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
281 delete $arrParamsBusc{'next'};
283 if ($modifyListBiblios) {
284 if (exists($arrParamsBusc{'newlistBiblios'})) {
285 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
286 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
287 my @arrAux = split(',', $listBibliosAux);
288 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
289 if ($modifyListBiblios == 1) {
290 $arrParamsBusc{'next'} = $arrAux[0];
291 $paging{'next'}->{biblionumber} = $arrAux[0];
292 }else {
293 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
294 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
296 } else {
297 delete $arrParamsBusc{'listBiblios'};
299 my $offsetAux = $arrParamsBusc{'offset'};
300 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
301 $arrParamsBusc{'offsetSearch'} = $offsetAux;
302 $offset = $arrParamsBusc{'offset'};
303 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
304 $session->param("busc" => $newbusc);
305 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
308 my $buscParam = '';
309 my $j = 0;
310 # Rebuild the query for the button "back to results"
311 for (@arrBusc) {
312 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
313 $buscParam .= '&amp;' unless ($j == 0);
314 $buscParam .= $_;
315 $j++;
318 $template->param('busc' => $buscParam);
319 my $offsetSearch;
320 my @arrBiblios;
321 # We are inside the list of biblios and we don't have to search
322 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
323 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
324 if (@arrBiblios) {
325 # We are at the first item of the list
326 if ($arrBiblios[0] == $biblionumber) {
327 if (@arrBiblios > 1) {
328 for (my $j = 1; $j < @arrBiblios; $j++) {
329 next unless ($arrBiblios[$j]);
330 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
331 last;
334 # search again if we are not at the first searching list
335 if ($offset && !$arrParamsBusc{'previous'}) {
336 $searchAgain = 1;
337 $offsetSearch = $offset - $results_per_page;
339 # we are at the last item of the list
340 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
341 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
342 next unless ($arrBiblios[$j]);
343 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
344 last;
346 if (!$offset) {
347 # search again if we are at the first list and there is more results
348 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
349 } else {
350 # search again if we aren't at the first list and there is more results
351 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
353 $offsetSearch = $offset + $results_per_page if ($searchAgain);
354 } else {
355 for (my $j = 1; $j < $#arrBiblios; $j++) {
356 if ($arrBiblios[$j] == $biblionumber) {
357 for (my $z = $j - 1; $z >= 0; $z--) {
358 next unless ($arrBiblios[$z]);
359 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
360 last;
362 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
363 next unless ($arrBiblios[$z]);
364 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
365 last;
367 last;
372 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
374 if ($searchAgain) {
375 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
376 my @newresults = @$newresultsRef;
377 # build the new listBiblios
378 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
379 unless (exists($arrParamsBusc{'listBiblios'})) {
380 $arrParamsBusc{'listBiblios'} = $listBiblios;
381 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
382 } else {
383 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
385 # From the new list we build again the next and previous result
386 if (@arrBiblios) {
387 if ($arrBiblios[0] == $biblionumber) {
388 for (my $j = $#newresults; $j >= 0; $j--) {
389 next unless ($newresults[$j]);
390 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
391 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
392 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
393 last;
395 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
396 for (my $j = 0; $j < @newresults; $j++) {
397 next unless ($newresults[$j]);
398 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
399 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
400 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
401 last;
405 # build new busc param
406 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
407 $session->param("busc" => $newbusc);
409 my ($numberBiblioPaging, $dataBiblioPaging);
410 # Previous biblio
411 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
412 if ($numberBiblioPaging) {
413 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
414 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
415 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
417 # Next biblio
418 $numberBiblioPaging = $paging{'next'}->{biblionumber};
419 if ($numberBiblioPaging) {
420 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
421 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
422 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
424 # Partial list of biblio results
425 my @listResults;
426 for (my $j = 0; $j < @arrBiblios; $j++) {
427 next unless ($arrBiblios[$j]);
428 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
429 push @listResults, {index => $j + 1 + $offset, biblionumber => $arrBiblios[$j], title => ($arrBiblios[$j] == $biblionumber)?'':$dataBiblioPaging->{title}, author => ($arrBiblios[$j] != $biblionumber && $dataBiblioPaging->{author})?$dataBiblioPaging->{author}:'', url => ($arrBiblios[$j] == $biblionumber)?'':'opac-detail.pl?biblionumber=' . $arrBiblios[$j]};
431 $template->param('listResults' => \@listResults) if (@listResults);
432 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
438 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
439 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
443 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
444 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
446 # adding items linked via host biblios
448 my $analyticfield = '773';
449 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
450 $analyticfield = '773';
451 } elsif ($marcflavour eq 'UNIMARC') {
452 $analyticfield = '461';
454 foreach my $hostfield ( $record->field($analyticfield)) {
455 my $hostbiblionumber = $hostfield->subfield("0");
456 my $linkeditemnumber = $hostfield->subfield("9");
457 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
458 foreach my $hostitemInfo (@hostitemInfos){
459 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
460 push(@all_items, $hostitemInfo);
465 my @items;
467 # Are there items to hide?
468 my $hideitems;
469 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
471 # Hide items
472 if ($hideitems) {
473 for my $itm (@all_items) {
474 if ( C4::Context->preference('hidelostitems') ) {
475 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
476 } else {
477 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
480 } else {
481 # Or not
482 @items = @all_items;
485 my $branches = GetBranches();
486 my $branch = '';
487 if (C4::Context->userenv){
488 $branch = C4::Context->userenv->{branch};
490 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
491 if (
492 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
494 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
496 my $branchname;
497 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
498 $branchname = $branches->{$branch}->{'branchname'};
500 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
501 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
504 my @our_items;
505 my @other_items;
507 foreach my $item ( @items ) {
508 if ( $item->{'branchname'} eq $branchname ) {
509 $item->{'this_branch'} = 1;
510 push( @our_items, $item );
511 } else {
512 push( @other_items, $item );
516 @items = ( @our_items, @other_items );
520 my $dat = &GetBiblioData($biblionumber);
522 my $itemtypes = GetItemTypes();
523 # imageurl:
524 my $itemtype = $dat->{'itemtype'};
525 if ( $itemtype ) {
526 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
527 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
529 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
530 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
531 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
533 #coping with subscriptions
534 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
535 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
537 my @subs;
538 $dat->{'serial'}=1 if $subscriptionsnumber;
539 foreach my $subscription (@subscriptions) {
540 my $serials_to_display;
541 my %cell;
542 $cell{subscriptionid} = $subscription->{subscriptionid};
543 $cell{subscriptionnotes} = $subscription->{notes};
544 $cell{missinglist} = $subscription->{missinglist};
545 $cell{opacnote} = $subscription->{opacnote};
546 $cell{histstartdate} = $subscription->{histstartdate};
547 $cell{histenddate} = $subscription->{histenddate};
548 $cell{branchcode} = $subscription->{branchcode};
549 $cell{branchname} = GetBranchName($subscription->{branchcode});
550 $cell{hasalert} = $subscription->{hasalert};
551 $cell{callnumber} = $subscription->{callnumber};
552 $cell{closed} = $subscription->{closed};
553 #get the three latest serials.
554 $serials_to_display = $subscription->{opacdisplaycount};
555 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
556 $cell{opacdisplaycount} = $serials_to_display;
557 $cell{latestserials} =
558 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
559 push @subs, \%cell;
562 $dat->{'count'} = scalar(@items);
565 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
567 my (%item_reserves, %priority);
568 my ($show_holds_count, $show_priority);
569 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
570 m/holds/o and $show_holds_count = 1;
571 m/priority/ and $show_priority = 1;
573 my $has_hold;
574 if ( $show_holds_count || $show_priority) {
575 my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
576 $template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
577 foreach (@$reserves) {
578 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
579 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
580 $has_hold = 1;
581 $_->{itemnumber}
582 ? ($priority{ $_->{itemnumber} } = $_->{priority})
583 : ($template->param( priority => $_->{priority} ));
587 $template->param( show_priority => $has_hold ) ;
589 my $norequests = 1;
590 my %itemfields;
591 my (@itemloop, @otheritemloop);
592 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
593 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
594 $template->param(SeparateHoldings => 1);
596 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
597 my $viewallitems = $query->param('viewallitems');
598 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
599 if ( not $viewallitems and @items > $max_items_to_display ) {
600 $template->param(
601 too_many_items => 1,
602 items_count => scalar( @items ),
604 } else {
605 for my $itm (@items) {
606 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
607 $itm->{priority} = $priority{ $itm->{itemnumber} };
608 $norequests = 0
609 if ( (not $itm->{'withdrawn'} )
610 && (not $itm->{'itemlost'} )
611 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
612 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
613 && ($itm->{'itemnumber'} ) );
615 # get collection code description, too
616 my $ccode = $itm->{'ccode'};
617 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
618 my $copynumber = $itm->{'copynumber'};
619 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
620 if ( defined $itm->{'location'} ) {
621 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
623 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
624 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
625 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
627 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
628 $itemfields{$_} = 1 if ($itm->{$_});
631 # walk through the item-level authorised values and populate some images
632 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
633 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
635 if ( $itm->{'itemlost'} ) {
636 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
637 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
638 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
640 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
641 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
642 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
644 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
645 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
646 $itm->{transfertwhen} = $transfertwhen;
647 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
648 $itm->{transfertto} = $branches->{$transfertto}{branchname};
650 my $itembranch = $itm->{$separatebranch};
651 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
652 if ($itembranch and $itembranch eq $currentbranch) {
653 push @itemloop, $itm;
654 } else {
655 push @otheritemloop, $itm;
657 } else {
658 push @itemloop, $itm;
663 # Display only one tab if one items list is empty
664 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
665 $template->param(SeparateHoldings => 0);
666 if (scalar(@itemloop) == 0) {
667 @itemloop = @otheritemloop;
671 ## get notes and subjects from MARC record
672 my $dbh = C4::Context->dbh;
673 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
674 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
675 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
676 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
677 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
678 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
679 my $marchostsarray = GetMarcHosts($record,$marcflavour);
680 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
682 $template->param(
683 MARCNOTES => $marcnotesarray,
684 MARCSUBJCTS => $marcsubjctsarray,
685 MARCAUTHORS => $marcauthorsarray,
686 MARCSERIES => $marcseriesarray,
687 MARCURLS => $marcurlsarray,
688 MARCISBNS => $marcisbnsarray,
689 MARCHOSTS => $marchostsarray,
690 norequests => $norequests,
691 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
692 itemdata_ccode => $itemfields{ccode},
693 itemdata_enumchron => $itemfields{enumchron},
694 itemdata_uri => $itemfields{uri},
695 itemdata_copynumber => $itemfields{copynumber},
696 itemdata_itemnotes => $itemfields{itemnotes},
697 authorised_value_images => $biblio_authorised_value_images,
698 subtitle => $subtitle,
699 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
702 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
703 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
704 my $subfields = substr $fieldspec, 3;
705 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
706 my @alternateholdingsinfo = ();
707 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
709 for my $field (@holdingsfields) {
710 my %holding = ( holding => '' );
711 my $havesubfield = 0;
712 for my $subfield ($field->subfields()) {
713 if ((index $subfields, $$subfield[0]) >= 0) {
714 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
715 $holding{'holding'} .= $$subfield[1];
716 $havesubfield++;
719 if ($havesubfield) {
720 push(@alternateholdingsinfo, \%holding);
724 $template->param(
725 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
729 foreach ( keys %{$dat} ) {
730 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
733 # some useful variables for enhanced content;
734 # in each case, we're grabbing the first value we find in
735 # the record and normalizing it
736 my $upc = GetNormalizedUPC($record,$marcflavour);
737 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
738 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
739 my $content_identifier_exists;
740 if ( $isbn or $ean or $oclc or $upc ) {
741 $content_identifier_exists = 1;
743 $template->param(
744 normalized_upc => $upc,
745 normalized_ean => $ean,
746 normalized_oclc => $oclc,
747 normalized_isbn => $isbn,
748 content_identifier_exists => $content_identifier_exists,
751 # COinS format FIXME: for books Only
752 $template->param(
753 ocoins => GetCOinSBiblio($record),
756 my $libravatar_enabled = 0;
757 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
758 eval {
759 require Libravatar::URL;
760 Libravatar::URL->import();
762 if (!$@ ) {
763 $libravatar_enabled = 1;
767 my $reviews = getreviews( $biblionumber, 1 );
768 my $loggedincommenter;
773 foreach ( @$reviews ) {
774 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
775 # setting some borrower info into this hash
776 $_->{title} = $borrowerData->{'title'};
777 $_->{surname} = $borrowerData->{'surname'};
778 $_->{firstname} = $borrowerData->{'firstname'};
779 if ($libravatar_enabled and $borrowerData->{'email'}) {
780 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
782 $_->{userid} = $borrowerData->{'userid'};
783 $_->{cardnumber} = $borrowerData->{'cardnumber'};
785 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
786 $_->{your_comment} = 1;
787 $loggedincommenter = 1;
792 if(C4::Context->preference("ISBD")) {
793 $template->param(ISBD => 1);
796 $template->param(
797 itemloop => \@itemloop,
798 otheritemloop => \@otheritemloop,
799 subscriptionsnumber => $subscriptionsnumber,
800 biblionumber => $biblionumber,
801 subscriptions => \@subs,
802 subscriptionsnumber => $subscriptionsnumber,
803 reviews => $reviews,
804 loggedincommenter => $loggedincommenter
807 # Lists
809 if (C4::Context->preference("virtualshelves") ) {
810 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
814 # XISBN Stuff
815 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
816 eval {
817 $template->param(
818 XISBNS => get_xisbns($isbn)
821 if ($@) { warn "XISBN Failed $@"; }
824 # Serial Collection
825 my @sc_fields = $record->field(955);
826 my @lc_fields = $marcflavour eq 'UNIMARC'
827 ? $record->field(930)
828 : $record->field(852);
829 my @serialcollections = ();
831 foreach my $sc_field (@sc_fields) {
832 my %row_data;
834 $row_data{text} = $sc_field->subfield('r');
835 $row_data{branch} = $sc_field->subfield('9');
836 foreach my $lc_field (@lc_fields) {
837 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
838 ? $lc_field->subfield('a') # 930$a
839 : $lc_field->subfield('h') # 852$h
840 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
843 if ($row_data{text} && $row_data{branch}) {
844 push (@serialcollections, \%row_data);
848 if (scalar(@serialcollections) > 0) {
849 $template->param(
850 serialcollection => 1,
851 serialcollections => \@serialcollections);
854 # Local cover Images stuff
855 if (C4::Context->preference("OPACLocalCoverImages")){
856 $template->param(OPACLocalCoverImages => 1);
859 # HTML5 Media
860 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
861 $template->param( C4::HTML5Media->gethtml5media($record));
864 my $syndetics_elements;
866 if ( C4::Context->preference("SyndeticsEnabled") ) {
867 $template->param("SyndeticsEnabled" => 1);
868 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
869 eval {
870 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
871 for my $element (values %$syndetics_elements) {
872 $template->param("Syndetics$element"."Exists" => 1 );
873 #warn "Exists: "."Syndetics$element"."Exists";
876 warn $@ if $@;
879 if ( C4::Context->preference("SyndeticsEnabled")
880 && C4::Context->preference("SyndeticsSummary")
881 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
882 eval {
883 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
884 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
886 warn $@ if $@;
890 if ( C4::Context->preference("SyndeticsEnabled")
891 && C4::Context->preference("SyndeticsTOC")
892 && exists($syndetics_elements->{'TOC'}) ) {
893 eval {
894 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
895 $template->param( SYNDETICS_TOC => $syndetics_toc );
897 warn $@ if $@;
900 if ( C4::Context->preference("SyndeticsEnabled")
901 && C4::Context->preference("SyndeticsExcerpt")
902 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
903 eval {
904 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
905 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
907 warn $@ if $@;
910 if ( C4::Context->preference("SyndeticsEnabled")
911 && C4::Context->preference("SyndeticsReviews")) {
912 eval {
913 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
914 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
916 warn $@ if $@;
919 if ( C4::Context->preference("SyndeticsEnabled")
920 && C4::Context->preference("SyndeticsAuthorNotes")
921 && exists($syndetics_elements->{'ANOTES'}) ) {
922 eval {
923 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
924 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
926 warn $@ if $@;
929 # LibraryThingForLibraries ID Code and Tabbed View Option
930 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
932 $template->param(LibraryThingForLibrariesID =>
933 C4::Context->preference('LibraryThingForLibrariesID') );
934 $template->param(LibraryThingForLibrariesTabbedView =>
935 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
938 # Novelist Select
939 if( C4::Context->preference('NovelistSelectEnabled') )
941 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
942 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
943 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
947 # Babelthèque
948 if ( C4::Context->preference("Babeltheque") ) {
949 $template->param(
950 Babeltheque => 1,
951 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
955 # Social Networks
956 if ( C4::Context->preference( "SocialNetworks" ) ) {
957 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
958 $template->param( SocialNetworks => 1 );
961 # Shelf Browser Stuff
962 if (C4::Context->preference("OPACShelfBrowser")) {
963 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
964 if (defined($starting_itemnumber)) {
965 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
966 my $nearby = GetNearbyItems($starting_itemnumber);
968 $template->param(
969 starting_itemnumber => $starting_itemnumber,
970 starting_homebranch => $nearby->{starting_homebranch}->{description},
971 starting_location => $nearby->{starting_location}->{description},
972 starting_ccode => $nearby->{starting_ccode}->{description},
973 shelfbrowser_prev_item => $nearby->{prev_item},
974 shelfbrowser_next_item => $nearby->{next_item},
975 shelfbrowser_items => $nearby->{items},
978 # in which tab shelf browser should open ?
979 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
980 $template->param(shelfbrowser_tab => 'holdings');
981 } else {
982 $template->param(shelfbrowser_tab => 'otherholdings');
987 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
989 if (C4::Context->preference("BakerTaylorEnabled")) {
990 $template->param(
991 BakerTaylorEnabled => 1,
992 BakerTaylorImageURL => &image_url(),
993 BakerTaylorLinkURL => &link_url(),
994 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
996 my ($bt_user, $bt_pass);
997 if ($isbn and
998 $bt_user = C4::Context->preference('BakerTaylorUsername') and
999 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1001 $template->param(
1002 BakerTaylorContentURL =>
1003 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1004 $bt_user,$bt_pass,$isbn)
1009 my $tag_quantity;
1010 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1011 $template->param(
1012 TagsEnabled => 1,
1013 TagsShowOnDetail => $tag_quantity,
1014 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1016 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1017 'sort'=>'-weight', limit=>$tag_quantity}));
1020 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1021 # These values are going to be read by Javascript, at least in the case
1022 # of the google covers
1023 $template->param(covernewwindow => 'true');
1024 } else {
1025 $template->param(covernewwindow => 'false');
1028 #Export options
1029 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
1030 my @export_options = split(/\|/,$OpacExportOptions);
1031 $template->{VARS}->{'export_options'} = \@export_options;
1033 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1034 my $rating = GetRating( $biblionumber, $borrowernumber );
1035 $template->param(
1036 rating_value => $rating->{'rating_value'},
1037 rating_total => $rating->{'rating_total'},
1038 rating_avg => $rating->{'rating_avg'},
1039 rating_avg_int => $rating->{'rating_avg_int'},
1040 borrowernumber => $borrowernumber
1044 #Search for title in links
1045 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1046 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1047 my $issn = $marcissns->[0] || '';
1049 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1050 $dat->{title} =~ s/\/+$//; # remove trailing slash
1051 $dat->{title} =~ s/\s+$//; # remove trailing space
1052 $search_for_title = parametrized_url(
1053 $search_for_title,
1055 TITLE => $dat->{title},
1056 AUTHOR => $dat->{author},
1057 ISBN => $isbn,
1058 ISSN => $issn,
1059 CONTROLNUMBER => $marccontrolnumber,
1060 BIBLIONUMBER => $biblionumber,
1063 $template->param('OPACSearchForTitleIn' => $search_for_title);
1066 # We try to select the best default tab to show, according to what
1067 # the user wants, and what's available for display
1068 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1069 my $defaulttab =
1070 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1071 ? 'subscriptions' :
1072 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1073 ? 'serialcollection' :
1074 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1075 ? 'holdings' :
1076 $subscriptionsnumber
1077 ? 'subscriptions' :
1078 @serialcollections > 0
1079 ? 'serialcollection' : 'subscriptions';
1080 $template->param('defaulttab' => $defaulttab);
1082 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1083 my @images = ListImagesForBiblio($biblionumber);
1084 $template->{VARS}->{localimages} = \@images;
1087 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1088 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1089 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1090 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1092 if (C4::Context->preference('OpacHighlightedWords')) {
1093 $template->{VARS}->{query_desc} = $query->param('query_desc');
1095 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1097 if ( C4::Context->preference('UseCourseReserves') ) {
1098 foreach my $i ( @items ) {
1099 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1103 output_html_with_http_headers $query, $cookie, $template->output;