Bug 16400: Use the fa-times icon for Cancel
[koha.git] / opac / opac-detail.pl
blob98afe3e9f0f75784f5058f53720978f06f9ad782
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
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Modern::Perl;
25 use CGI qw ( -utf8 );
26 use C4::Acquisition qw( SearchOrders );
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::XSLT;
43 use C4::ShelfBrowser;
44 use C4::Reserves;
45 use C4::Charset;
46 use MARC::Record;
47 use MARC::Field;
48 use List::MoreUtils qw/any none/;
49 use C4::Images;
50 use Koha::DateUtils;
51 use C4::HTML5Media;
52 use C4::CourseReserves qw(GetItemCourseReservesInfo);
54 use Koha::Virtualshelves;
56 BEGIN {
57 if (C4::Context->preference('BakerTaylorEnabled')) {
58 require C4::External::BakerTaylor;
59 import C4::External::BakerTaylor qw(&image_url &link_url);
63 my $query = new CGI;
64 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
66 template_name => "opac-detail.tt",
67 query => $query,
68 type => "opac",
69 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
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 my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
144 my $lang = $xslfile ? C4::Languages::getlanguage() : undef;
145 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
147 if ( $xslfile ) {
148 $template->param(
149 XSLTBloc => XSLTParse4Display(
150 $biblionumber, $record, "OPACXSLTDetailsDisplay",
151 1, undef, $sysxml, $xslfile, $lang
156 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
157 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
159 # We look for the busc param to build the simple paging from the search
160 if ($OpacBrowseResults) {
161 my $session = get_session($query->cookie("CGISESSID"));
162 my %paging = (previous => {}, next => {});
163 if ($session->param('busc')) {
164 use C4::Search;
165 use URI::Escape;
167 # Rebuild the string to store on session
168 # param value is URI encoded and params separator is HTML encode (&amp;)
169 sub rebuildBuscParam
171 my $arrParamsBusc = shift;
173 my $pasarParams = '';
174 my $j = 0;
175 for (keys %$arrParamsBusc) {
176 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
177 if (defined($arrParamsBusc->{$_})) {
178 $pasarParams .= '&amp;' if ($j);
179 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
180 $j++;
182 } else {
183 for my $value (@{$arrParamsBusc->{$_}}) {
184 $pasarParams .= '&amp;' if ($j);
185 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
186 $j++;
190 return $pasarParams;
191 }#rebuildBuscParam
193 # Search given the current values from the busc param
194 sub searchAgain
196 my ($arrParamsBusc, $offset, $results_per_page) = @_;
198 my $expanded_facet = $arrParamsBusc->{'expand'};
199 my $branches = GetBranches();
200 my $itemtypes = GetItemTypes;
201 my @servers;
202 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
203 @servers = ("biblioserver") unless (@servers);
205 my ($default_sort_by, @sort_by);
206 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
207 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
208 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
209 my ($error, $results_hashref, $facets);
210 eval {
211 ($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'});
213 my $hits;
214 my @newresults;
215 for (my $i=0;$i<@servers;$i++) {
216 my $server = $servers[$i];
217 $hits = $results_hashref->{$server}->{"hits"};
218 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
220 return \@newresults;
221 }#searchAgain
223 # Build the current list of biblionumbers in this search
224 sub buildListBiblios
226 my ($newresultsRef, $results_per_page) = @_;
228 my $listBiblios = '';
229 my $j = 0;
230 foreach (@$newresultsRef) {
231 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
232 $listBiblios .= $bibnum . ',';
233 $j++;
234 last if ($j == $results_per_page);
236 chop $listBiblios if ($listBiblios =~ /,$/);
237 return $listBiblios;
238 }#buildListBiblios
240 my $busc = $session->param("busc");
241 my @arrBusc = split(/\&(?:amp;)?/, $busc);
242 my ($key, $value);
243 my %arrParamsBusc = ();
244 for (@arrBusc) {
245 ($key, $value) = split(/=/, $_, 2);
246 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
247 $arrParamsBusc{$key} = uri_unescape($value);
248 } else {
249 unless (exists($arrParamsBusc{$key})) {
250 $arrParamsBusc{$key} = [];
252 push @{$arrParamsBusc{$key}}, uri_unescape($value);
255 my $searchAgain = 0;
256 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
257 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
258 $arrParamsBusc{'count'} = $results_per_page;
259 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
260 # The value OPACnumSearchResults has changed and the search has to be rebuild
261 if ($count != $results_per_page) {
262 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
263 my $indexBiblio = 0;
264 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
265 for (@arrBibliosAux) {
266 last if ($_ == $biblionumber);
267 $indexBiblio++;
269 $indexBiblio += $offset;
270 $offset = int($indexBiblio / $count) * $count;
271 $arrParamsBusc{'offset'} = $offset;
273 $arrParamsBusc{'count'} = $count;
274 $results_per_page = $count;
275 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
276 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
277 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
278 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
279 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
280 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
281 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
282 $session->param("busc" => $newbusc);
283 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
284 } else {
285 my $modifyListBiblios = 0;
286 # We come from a previous click
287 if (exists($arrParamsBusc{'previous'})) {
288 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
289 delete $arrParamsBusc{'previous'};
290 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
291 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
292 delete $arrParamsBusc{'next'};
294 if ($modifyListBiblios) {
295 if (exists($arrParamsBusc{'newlistBiblios'})) {
296 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
297 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
298 my @arrAux = split(',', $listBibliosAux);
299 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
300 if ($modifyListBiblios == 1) {
301 $arrParamsBusc{'next'} = $arrAux[0];
302 $paging{'next'}->{biblionumber} = $arrAux[0];
303 }else {
304 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
305 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
307 } else {
308 delete $arrParamsBusc{'listBiblios'};
310 my $offsetAux = $arrParamsBusc{'offset'};
311 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
312 $arrParamsBusc{'offsetSearch'} = $offsetAux;
313 $offset = $arrParamsBusc{'offset'};
314 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
315 $session->param("busc" => $newbusc);
316 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
319 my $buscParam = '';
320 my $j = 0;
321 # Rebuild the query for the button "back to results"
322 for (@arrBusc) {
323 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
324 $buscParam .= '&amp;' unless ($j == 0);
325 $buscParam .= $_; # string already URI encoded
326 $j++;
329 $template->param('busc' => $buscParam);
330 my $offsetSearch;
331 my @arrBiblios;
332 # We are inside the list of biblios and we don't have to search
333 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
334 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
335 if (@arrBiblios) {
336 # We are at the first item of the list
337 if ($arrBiblios[0] == $biblionumber) {
338 if (@arrBiblios > 1) {
339 for (my $j = 1; $j < @arrBiblios; $j++) {
340 next unless ($arrBiblios[$j]);
341 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
342 last;
345 # search again if we are not at the first searching list
346 if ($offset && !$arrParamsBusc{'previous'}) {
347 $searchAgain = 1;
348 $offsetSearch = $offset - $results_per_page;
350 # we are at the last item of the list
351 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
352 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
353 next unless ($arrBiblios[$j]);
354 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
355 last;
357 if (!$offset) {
358 # search again if we are at the first list and there is more results
359 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
360 } else {
361 # search again if we aren't at the first list and there is more results
362 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
364 $offsetSearch = $offset + $results_per_page if ($searchAgain);
365 } else {
366 for (my $j = 1; $j < $#arrBiblios; $j++) {
367 if ($arrBiblios[$j] == $biblionumber) {
368 for (my $z = $j - 1; $z >= 0; $z--) {
369 next unless ($arrBiblios[$z]);
370 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
371 last;
373 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
374 next unless ($arrBiblios[$z]);
375 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
376 last;
378 last;
383 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
385 if ($searchAgain) {
386 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
387 my @newresults = @$newresultsRef;
388 # build the new listBiblios
389 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
390 unless (exists($arrParamsBusc{'listBiblios'})) {
391 $arrParamsBusc{'listBiblios'} = $listBiblios;
392 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
393 } else {
394 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
396 # From the new list we build again the next and previous result
397 if (@arrBiblios) {
398 if ($arrBiblios[0] == $biblionumber) {
399 for (my $j = $#newresults; $j >= 0; $j--) {
400 next unless ($newresults[$j]);
401 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
402 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
403 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
404 last;
406 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
407 for (my $j = 0; $j < @newresults; $j++) {
408 next unless ($newresults[$j]);
409 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
410 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
411 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
412 last;
416 # build new busc param
417 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
418 $session->param("busc" => $newbusc);
420 my ($numberBiblioPaging, $dataBiblioPaging);
421 # Previous biblio
422 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
423 if ($numberBiblioPaging) {
424 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
425 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
426 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
428 # Next biblio
429 $numberBiblioPaging = $paging{'next'}->{biblionumber};
430 if ($numberBiblioPaging) {
431 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
432 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
433 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
435 # Partial list of biblio results
436 my @listResults;
437 for (my $j = 0; $j < @arrBiblios; $j++) {
438 next unless ($arrBiblios[$j]);
439 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
440 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]};
442 $template->param('listResults' => \@listResults) if (@listResults);
443 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
448 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
449 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
450 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
452 # adding items linked via host biblios
454 my $analyticfield = '773';
455 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
456 $analyticfield = '773';
457 } elsif ($marcflavour eq 'UNIMARC') {
458 $analyticfield = '461';
460 foreach my $hostfield ( $record->field($analyticfield)) {
461 my $hostbiblionumber = $hostfield->subfield("0");
462 my $linkeditemnumber = $hostfield->subfield("9");
463 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
464 foreach my $hostitemInfo (@hostitemInfos){
465 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
466 push(@all_items, $hostitemInfo);
471 my @items;
473 # Are there items to hide?
474 my $hideitems;
475 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
477 # Hide items
478 if ($hideitems) {
479 for my $itm (@all_items) {
480 if ( C4::Context->preference('hidelostitems') ) {
481 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
482 } else {
483 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
486 } else {
487 # Or not
488 @items = @all_items;
491 my $branches = GetBranches();
492 my $branch = '';
493 if (C4::Context->userenv){
494 $branch = C4::Context->userenv->{branch};
496 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
497 if (
498 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
500 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
502 my $branchname;
503 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
504 $branchname = $branches->{$branch}->{'branchname'};
506 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
507 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
510 my @our_items;
511 my @other_items;
513 foreach my $item ( @items ) {
514 if ( $item->{'branchname'} eq $branchname ) {
515 $item->{'this_branch'} = 1;
516 push( @our_items, $item );
517 } else {
518 push( @other_items, $item );
522 @items = ( @our_items, @other_items );
526 my $dat = &GetBiblioData($biblionumber);
528 my $itemtypes = GetItemTypes();
529 # imageurl:
530 my $itemtype = $dat->{'itemtype'};
531 if ( $itemtype ) {
532 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
533 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
535 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
536 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
537 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
539 #coping with subscriptions
540 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
541 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
543 my @subs;
544 $dat->{'serial'}=1 if $subscriptionsnumber;
545 foreach my $subscription (@subscriptions) {
546 my $serials_to_display;
547 my %cell;
548 $cell{subscriptionid} = $subscription->{subscriptionid};
549 $cell{subscriptionnotes} = $subscription->{notes};
550 $cell{missinglist} = $subscription->{missinglist};
551 $cell{opacnote} = $subscription->{opacnote};
552 $cell{histstartdate} = $subscription->{histstartdate};
553 $cell{histenddate} = $subscription->{histenddate};
554 $cell{branchcode} = $subscription->{branchcode};
555 $cell{branchname} = GetBranchName($subscription->{branchcode});
556 $cell{hasalert} = $subscription->{hasalert};
557 $cell{callnumber} = $subscription->{callnumber};
558 $cell{closed} = $subscription->{closed};
559 #get the three latest serials.
560 $serials_to_display = $subscription->{opacdisplaycount};
561 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
562 $cell{opacdisplaycount} = $serials_to_display;
563 $cell{latestserials} =
564 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
565 push @subs, \%cell;
568 $dat->{'count'} = scalar(@items);
571 my (%item_reserves, %priority);
572 my ($show_holds_count, $show_priority);
573 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
574 m/holds/o and $show_holds_count = 1;
575 m/priority/ and $show_priority = 1;
577 my $has_hold;
578 if ( $show_holds_count || $show_priority) {
579 my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
580 $template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
581 foreach (@$reserves) {
582 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
583 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
584 $has_hold = 1;
585 $_->{itemnumber}
586 ? ($priority{ $_->{itemnumber} } = $_->{priority})
587 : ($template->param( priority => $_->{priority} ));
591 $template->param( show_priority => $has_hold ) ;
593 my $norequests = 1;
594 my %itemfields;
595 my (@itemloop, @otheritemloop);
596 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
597 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
598 $template->param(SeparateHoldings => 1);
600 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
601 my $viewallitems = $query->param('viewallitems');
602 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
604 # Get items on order
605 my ( @itemnumbers_on_order );
606 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
607 my $orders = C4::Acquisition::SearchOrders({
608 biblionumber => $biblionumber,
609 ordered => 1,
611 my $total_quantity = 0;
612 for my $order ( @$orders ) {
613 if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
614 for my $itemnumber ( C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ) {
615 push @itemnumbers_on_order, $itemnumber;
618 $total_quantity += $order->{quantity};
620 $template->{VARS}->{acquisition_details} = {
621 total_quantity => $total_quantity,
625 if ( not $viewallitems and @items > $max_items_to_display ) {
626 $template->param(
627 too_many_items => 1,
628 items_count => scalar( @items ),
630 } else {
631 my $allow_onshelf_holds;
632 my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
633 for my $itm (@items) {
634 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
635 $itm->{priority} = $priority{ $itm->{itemnumber} };
636 $norequests = 0
637 if $norequests
638 && !$itm->{'withdrawn'}
639 && !$itm->{'itemlost'}
640 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
641 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
642 && $itm->{'itemnumber'};
644 $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $borrower )
645 unless $allow_onshelf_holds;
647 # get collection code description, too
648 my $ccode = $itm->{'ccode'};
649 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
650 my $copynumber = $itm->{'copynumber'};
651 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
652 if ( defined $itm->{'location'} ) {
653 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
655 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
656 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
657 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description};
659 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
660 $itemfields{$_} = 1 if ($itm->{$_});
663 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
664 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
665 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
667 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
668 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
669 $itm->{transfertwhen} = $transfertwhen;
670 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
671 $itm->{transfertto} = $branches->{$transfertto}{branchname};
674 if ( C4::Context->preference('OPACAcquisitionDetails')
675 and C4::Context->preference('AcqCreateItem') eq 'ordering' )
677 $itm->{on_order} = 1
678 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
681 my $itembranch = $itm->{$separatebranch};
682 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
683 if ($itembranch and $itembranch eq $currentbranch) {
684 push @itemloop, $itm;
685 } else {
686 push @otheritemloop, $itm;
688 } else {
689 push @itemloop, $itm;
692 $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
695 # Display only one tab if one items list is empty
696 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
697 $template->param(SeparateHoldings => 0);
698 if (scalar(@itemloop) == 0) {
699 @itemloop = @otheritemloop;
703 ## get notes and subjects from MARC record
704 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
705 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
706 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
707 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
708 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
709 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
710 my $marchostsarray = GetMarcHosts($record,$marcflavour);
712 $template->param(
713 MARCSUBJCTS => $marcsubjctsarray,
714 MARCAUTHORS => $marcauthorsarray,
715 MARCSERIES => $marcseriesarray,
716 MARCURLS => $marcurlsarray,
717 MARCISBNS => $marcisbnsarray,
718 MARCHOSTS => $marchostsarray,
722 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
723 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
725 $template->param(
726 MARCNOTES => $marcnotesarray,
727 norequests => $norequests,
728 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
729 itemdata_ccode => $itemfields{ccode},
730 itemdata_enumchron => $itemfields{enumchron},
731 itemdata_uri => $itemfields{uri},
732 itemdata_copynumber => $itemfields{copynumber},
733 itemdata_itemnotes => $itemfields{itemnotes},
734 subtitle => $subtitle,
735 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
738 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
739 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
740 my $subfields = substr $fieldspec, 3;
741 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
742 my @alternateholdingsinfo = ();
743 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
745 for my $field (@holdingsfields) {
746 my %holding = ( holding => '' );
747 my $havesubfield = 0;
748 for my $subfield ($field->subfields()) {
749 if ((index $subfields, $$subfield[0]) >= 0) {
750 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
751 $holding{'holding'} .= $$subfield[1];
752 $havesubfield++;
755 if ($havesubfield) {
756 push(@alternateholdingsinfo, \%holding);
760 $template->param(
761 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
765 foreach ( keys %{$dat} ) {
766 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
769 # some useful variables for enhanced content;
770 # in each case, we're grabbing the first value we find in
771 # the record and normalizing it
772 my $upc = GetNormalizedUPC($record,$marcflavour);
773 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
774 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
775 my $content_identifier_exists;
776 if ( $isbn or $ean or $oclc or $upc ) {
777 $content_identifier_exists = 1;
779 $template->param(
780 normalized_upc => $upc,
781 normalized_ean => $ean,
782 normalized_oclc => $oclc,
783 normalized_isbn => $isbn,
784 content_identifier_exists => $content_identifier_exists,
787 # COinS format FIXME: for books Only
788 $template->param(
789 ocoins => GetCOinSBiblio($record),
792 my $libravatar_enabled = 0;
793 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
794 eval {
795 require Libravatar::URL;
796 Libravatar::URL->import();
798 if (!$@ ) {
799 $libravatar_enabled = 1;
803 my $reviews = getreviews( $biblionumber, 1 );
804 my $loggedincommenter;
809 foreach ( @$reviews ) {
810 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
811 # setting some borrower info into this hash
812 $_->{title} = $borrowerData->{'title'};
813 $_->{surname} = $borrowerData->{'surname'};
814 $_->{firstname} = $borrowerData->{'firstname'};
815 if ($libravatar_enabled and $borrowerData->{'email'}) {
816 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
818 $_->{userid} = $borrowerData->{'userid'};
819 $_->{cardnumber} = $borrowerData->{'cardnumber'};
821 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
822 $_->{your_comment} = 1;
823 $loggedincommenter = 1;
827 if ( C4::Context->preference("OPACISBD") ) {
828 $template->param( ISBD => 1 );
831 $template->param(
832 itemloop => \@itemloop,
833 otheritemloop => \@otheritemloop,
834 subscriptionsnumber => $subscriptionsnumber,
835 biblionumber => $biblionumber,
836 subscriptions => \@subs,
837 subscriptionsnumber => $subscriptionsnumber,
838 reviews => $reviews,
839 loggedincommenter => $loggedincommenter
842 # Lists
843 if (C4::Context->preference("virtualshelves") ) {
844 my $shelves = Koha::Virtualshelves->search(
846 biblionumber => $biblionumber,
847 category => 2,
850 join => 'virtualshelfcontents',
853 $template->param( shelves => $shelves );
856 # XISBN Stuff
857 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
858 eval {
859 $template->param(
860 XISBNS => get_xisbns($isbn)
863 if ($@) { warn "XISBN Failed $@"; }
866 # Serial Collection
867 my @sc_fields = $record->field(955);
868 my @lc_fields = $marcflavour eq 'UNIMARC'
869 ? $record->field(930)
870 : $record->field(852);
871 my @serialcollections = ();
873 foreach my $sc_field (@sc_fields) {
874 my %row_data;
876 $row_data{text} = $sc_field->subfield('r');
877 $row_data{branch} = $sc_field->subfield('9');
878 foreach my $lc_field (@lc_fields) {
879 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
880 ? $lc_field->subfield('a') # 930$a
881 : $lc_field->subfield('h') # 852$h
882 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
885 if ($row_data{text} && $row_data{branch}) {
886 push (@serialcollections, \%row_data);
890 if (scalar(@serialcollections) > 0) {
891 $template->param(
892 serialcollection => 1,
893 serialcollections => \@serialcollections);
896 # Local cover Images stuff
897 if (C4::Context->preference("OPACLocalCoverImages")){
898 $template->param(OPACLocalCoverImages => 1);
901 # HTML5 Media
902 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
903 $template->param( C4::HTML5Media->gethtml5media($record));
906 my $syndetics_elements;
908 if ( C4::Context->preference("SyndeticsEnabled") ) {
909 $template->param("SyndeticsEnabled" => 1);
910 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
911 eval {
912 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
913 for my $element (values %$syndetics_elements) {
914 $template->param("Syndetics$element"."Exists" => 1 );
915 #warn "Exists: "."Syndetics$element"."Exists";
918 warn $@ if $@;
921 if ( C4::Context->preference("SyndeticsEnabled")
922 && C4::Context->preference("SyndeticsSummary")
923 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
924 eval {
925 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
926 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
928 warn $@ if $@;
932 if ( C4::Context->preference("SyndeticsEnabled")
933 && C4::Context->preference("SyndeticsTOC")
934 && exists($syndetics_elements->{'TOC'}) ) {
935 eval {
936 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
937 $template->param( SYNDETICS_TOC => $syndetics_toc );
939 warn $@ if $@;
942 if ( C4::Context->preference("SyndeticsEnabled")
943 && C4::Context->preference("SyndeticsExcerpt")
944 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
945 eval {
946 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
947 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
949 warn $@ if $@;
952 if ( C4::Context->preference("SyndeticsEnabled")
953 && C4::Context->preference("SyndeticsReviews")) {
954 eval {
955 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
956 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
958 warn $@ if $@;
961 if ( C4::Context->preference("SyndeticsEnabled")
962 && C4::Context->preference("SyndeticsAuthorNotes")
963 && exists($syndetics_elements->{'ANOTES'}) ) {
964 eval {
965 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
966 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
968 warn $@ if $@;
971 # LibraryThingForLibraries ID Code and Tabbed View Option
972 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
974 $template->param(LibraryThingForLibrariesID =>
975 C4::Context->preference('LibraryThingForLibrariesID') );
976 $template->param(LibraryThingForLibrariesTabbedView =>
977 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
980 # Novelist Select
981 if( C4::Context->preference('NovelistSelectEnabled') )
983 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
984 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
985 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
989 # Babelthèque
990 if ( C4::Context->preference("Babeltheque") ) {
991 $template->param(
992 Babeltheque => 1,
993 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
997 # Social Networks
998 if ( C4::Context->preference( "SocialNetworks" ) ) {
999 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1000 $template->param( SocialNetworks => 1 );
1003 # Shelf Browser Stuff
1004 if (C4::Context->preference("OPACShelfBrowser")) {
1005 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1006 if (defined($starting_itemnumber)) {
1007 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
1008 my $nearby = GetNearbyItems($starting_itemnumber);
1010 $template->param(
1011 starting_itemnumber => $starting_itemnumber,
1012 starting_homebranch => $nearby->{starting_homebranch}->{description},
1013 starting_location => $nearby->{starting_location}->{description},
1014 starting_ccode => $nearby->{starting_ccode}->{description},
1015 shelfbrowser_prev_item => $nearby->{prev_item},
1016 shelfbrowser_next_item => $nearby->{next_item},
1017 shelfbrowser_items => $nearby->{items},
1020 # in which tab shelf browser should open ?
1021 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
1022 $template->param(shelfbrowser_tab => 'holdings');
1023 } else {
1024 $template->param(shelfbrowser_tab => 'otherholdings');
1029 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
1031 if (C4::Context->preference("BakerTaylorEnabled")) {
1032 $template->param(
1033 BakerTaylorEnabled => 1,
1034 BakerTaylorImageURL => &image_url(),
1035 BakerTaylorLinkURL => &link_url(),
1036 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1038 my ($bt_user, $bt_pass);
1039 if ($isbn and
1040 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1041 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1043 $template->param(
1044 BakerTaylorContentURL =>
1045 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1046 $bt_user,$bt_pass,$isbn)
1051 my $tag_quantity;
1052 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1053 $template->param(
1054 TagsEnabled => 1,
1055 TagsShowOnDetail => $tag_quantity,
1056 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1058 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1059 'sort'=>'-weight', limit=>$tag_quantity}));
1062 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1063 # These values are going to be read by Javascript, at least in the case
1064 # of the google covers
1065 $template->param(covernewwindow => 'true');
1066 } else {
1067 $template->param(covernewwindow => 'false');
1070 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1071 my $rating = GetRating( $biblionumber, $borrowernumber );
1072 $template->param(
1073 rating_value => $rating->{'rating_value'},
1074 rating_total => $rating->{'rating_total'},
1075 rating_avg => $rating->{'rating_avg'},
1076 rating_avg_int => $rating->{'rating_avg_int'},
1077 borrowernumber => $borrowernumber
1081 #Search for title in links
1082 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1083 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1084 my $issn = $marcissns->[0] || '';
1086 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1087 $dat->{title} =~ s/\/+$//; # remove trailing slash
1088 $dat->{title} =~ s/\s+$//; # remove trailing space
1089 $search_for_title = parametrized_url(
1090 $search_for_title,
1092 TITLE => $dat->{title},
1093 AUTHOR => $dat->{author},
1094 ISBN => $isbn,
1095 ISSN => $issn,
1096 CONTROLNUMBER => $marccontrolnumber,
1097 BIBLIONUMBER => $biblionumber,
1100 $template->param('OPACSearchForTitleIn' => $search_for_title);
1103 #IDREF
1104 if ( C4::Context->preference("IDREF") ) {
1105 # If the record comes from the SUDOC
1106 if ( $record->field('009') ) {
1107 my $unimarc3 = $record->field("009")->data;
1108 if ( $unimarc3 =~ /^\d+$/ ) {
1109 $template->param(
1110 IDREF => 1,
1116 # We try to select the best default tab to show, according to what
1117 # the user wants, and what's available for display
1118 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1119 my $defaulttab =
1120 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1121 ? 'subscriptions' :
1122 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1123 ? 'serialcollection' :
1124 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1125 ? 'holdings' :
1126 $subscriptionsnumber
1127 ? 'subscriptions' :
1128 @serialcollections > 0
1129 ? 'serialcollection' : 'subscriptions';
1130 $template->param('defaulttab' => $defaulttab);
1132 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1133 my @images = ListImagesForBiblio($biblionumber);
1134 $template->{VARS}->{localimages} = \@images;
1137 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1138 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1139 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1140 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1142 if (C4::Context->preference('OpacHighlightedWords')) {
1143 $template->{VARS}->{query_desc} = $query->param('query_desc');
1145 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1147 if ( C4::Context->preference('UseCourseReserves') ) {
1148 foreach my $i ( @items ) {
1149 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1153 $template->param(
1154 'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay') ,
1155 'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'),
1158 output_html_with_http_headers $query, $cookie, $template->output;