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>.
27 use C4::Acquisition qw( SearchOrders );
28 use C4::Auth qw(:DEFAULT get_session);
31 use C4::Serials; #uses getsubscriptionfrom biblionumber
36 use C4::Tags qw(get_tags);
37 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
38 use C4::External::Amazon;
39 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
43 use C4::VirtualShelves;
50 use List::MoreUtils qw/any none/;
54 use C4::CourseReserves qw(GetItemCourseReservesInfo);
56 use Koha::Virtualshelves;
59 if (C4::Context->preference('BakerTaylorEnabled')) {
60 require C4::External::BakerTaylor;
61 import C4::External::BakerTaylor qw(&image_url &link_url);
66 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
68 template_name => "opac-detail.tt",
71 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
75 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
76 $biblionumber = int($biblionumber);
78 my @all_items = GetItemsInfo($biblionumber);
80 if (scalar @all_items >= 1) {
81 push @hiddenitems, GetHiddenItemnumbers(@all_items);
83 if (scalar @hiddenitems == scalar @all_items ) {
84 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
89 my $record = GetMarcBiblio($biblionumber);
91 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
95 # redirect if opacsuppression is enabled and biblio is suppressed
96 if (C4::Context->preference('OpacSuppression')) {
97 # FIXME hardcoded; the suppression flag ought to be materialized
98 # as a column on biblio or the like
99 my $opacsuppressionfield = '942';
100 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
101 # redirect to opac-blocked info page or 404?
102 my $opacsuppressionredirect;
103 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
104 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
106 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
108 if ( $opacsuppressionfieldvalue &&
109 $opacsuppressionfieldvalue->subfield("n") &&
110 $opacsuppressionfieldvalue->subfield("n") == 1) {
111 # if OPAC suppression by IP address
112 if (C4::Context->preference('OpacSuppressionByIPRange')) {
113 my $IPAddress = $ENV{'REMOTE_ADDR'};
114 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
115 if ($IPAddress !~ /^$IPRange/) {
116 print $query->redirect($opacsuppressionredirect);
120 print $query->redirect($opacsuppressionredirect);
126 $template->param( biblionumber => $biblionumber );
128 # get biblionumbers stored in the cart
131 if($query->cookie("bib_list")){
132 my $cart_list = $query->cookie("bib_list");
133 @cart_list = split(/\//, $cart_list);
134 if ( grep {$_ eq $biblionumber} @cart_list) {
135 $template->param( incart => 1 );
140 SetUTF8Flag($record);
141 my $marcflavour = C4::Context->preference("marcflavour");
142 my $ean = GetNormalizedEAN( $record, $marcflavour );
144 # XSLT processing of some stuff
145 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
146 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
149 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
150 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
152 # We look for the busc param to build the simple paging from the search
153 if ($OpacBrowseResults) {
154 my $session = get_session($query->cookie("CGISESSID"));
155 my %paging = (previous => {}, next => {});
156 if ($session->param('busc')) {
160 # Rebuild the string to store on session
161 # param value is URI encoded and params separator is HTML encode (&)
164 my $arrParamsBusc = shift;
166 my $pasarParams = '';
168 for (keys %$arrParamsBusc) {
169 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
170 if (defined($arrParamsBusc->{$_})) {
171 $pasarParams .= '&' if ($j);
172 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
176 for my $value (@{$arrParamsBusc->{$_}}) {
177 $pasarParams .= '&' if ($j);
178 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
186 # Search given the current values from the busc param
189 my ($arrParamsBusc, $offset, $results_per_page) = @_;
191 my $expanded_facet = $arrParamsBusc->{'expand'};
192 my $branches = GetBranches();
193 my $itemtypes = GetItemTypes;
195 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
196 @servers = ("biblioserver") unless (@servers);
198 my ($default_sort_by, @sort_by);
199 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
200 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
201 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
202 my ($error, $results_hashref, $facets);
204 ($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'});
208 for (my $i=0;$i<@servers;$i++) {
209 my $server = $servers[$i];
210 $hits = $results_hashref->{$server}->{"hits"};
211 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
216 # Build the current list of biblionumbers in this search
219 my ($newresultsRef, $results_per_page) = @_;
221 my $listBiblios = '';
223 foreach (@$newresultsRef) {
224 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
225 $listBiblios .= $bibnum . ',';
227 last if ($j == $results_per_page);
229 chop $listBiblios if ($listBiblios =~ /,$/);
233 my $busc = $session->param("busc");
234 my @arrBusc = split(/\&(?:amp;)?/, $busc);
236 my %arrParamsBusc = ();
238 ($key, $value) = split(/=/, $_, 2);
239 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
240 $arrParamsBusc{$key} = uri_unescape($value);
242 unless (exists($arrParamsBusc{$key})) {
243 $arrParamsBusc{$key} = [];
245 push @{$arrParamsBusc{$key}}, uri_unescape($value);
249 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
250 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
251 $arrParamsBusc{'count'} = $results_per_page;
252 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
253 # The value OPACnumSearchResults has changed and the search has to be rebuild
254 if ($count != $results_per_page) {
255 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
257 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
258 for (@arrBibliosAux) {
259 last if ($_ == $biblionumber);
262 $indexBiblio += $offset;
263 $offset = int($indexBiblio / $count) * $count;
264 $arrParamsBusc{'offset'} = $offset;
266 $arrParamsBusc{'count'} = $count;
267 $results_per_page = $count;
268 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
269 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
270 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
271 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
272 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
273 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
274 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
275 $session->param("busc" => $newbusc);
276 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
278 my $modifyListBiblios = 0;
279 # We come from a previous click
280 if (exists($arrParamsBusc{'previous'})) {
281 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
282 delete $arrParamsBusc{'previous'};
283 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
284 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
285 delete $arrParamsBusc{'next'};
287 if ($modifyListBiblios) {
288 if (exists($arrParamsBusc{'newlistBiblios'})) {
289 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
290 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
291 my @arrAux = split(',', $listBibliosAux);
292 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
293 if ($modifyListBiblios == 1) {
294 $arrParamsBusc{'next'} = $arrAux[0];
295 $paging{'next'}->{biblionumber} = $arrAux[0];
297 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
298 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
301 delete $arrParamsBusc{'listBiblios'};
303 my $offsetAux = $arrParamsBusc{'offset'};
304 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
305 $arrParamsBusc{'offsetSearch'} = $offsetAux;
306 $offset = $arrParamsBusc{'offset'};
307 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
308 $session->param("busc" => $newbusc);
309 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
314 # Rebuild the query for the button "back to results"
316 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
317 $buscParam .= '&' unless ($j == 0);
318 $buscParam .= $_; # string already URI encoded
322 $template->param('busc' => $buscParam);
325 # We are inside the list of biblios and we don't have to search
326 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
327 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
329 # We are at the first item of the list
330 if ($arrBiblios[0] == $biblionumber) {
331 if (@arrBiblios > 1) {
332 for (my $j = 1; $j < @arrBiblios; $j++) {
333 next unless ($arrBiblios[$j]);
334 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
338 # search again if we are not at the first searching list
339 if ($offset && !$arrParamsBusc{'previous'}) {
341 $offsetSearch = $offset - $results_per_page;
343 # we are at the last item of the list
344 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
345 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
346 next unless ($arrBiblios[$j]);
347 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
351 # search again if we are at the first list and there is more results
352 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
354 # search again if we aren't at the first list and there is more results
355 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
357 $offsetSearch = $offset + $results_per_page if ($searchAgain);
359 for (my $j = 1; $j < $#arrBiblios; $j++) {
360 if ($arrBiblios[$j] == $biblionumber) {
361 for (my $z = $j - 1; $z >= 0; $z--) {
362 next unless ($arrBiblios[$z]);
363 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
366 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
367 next unless ($arrBiblios[$z]);
368 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
376 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
379 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
380 my @newresults = @$newresultsRef;
381 # build the new listBiblios
382 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
383 unless (exists($arrParamsBusc{'listBiblios'})) {
384 $arrParamsBusc{'listBiblios'} = $listBiblios;
385 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
387 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
389 # From the new list we build again the next and previous result
391 if ($arrBiblios[0] == $biblionumber) {
392 for (my $j = $#newresults; $j >= 0; $j--) {
393 next unless ($newresults[$j]);
394 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
395 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
396 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
399 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
400 for (my $j = 0; $j < @newresults; $j++) {
401 next unless ($newresults[$j]);
402 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
403 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
404 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
409 # build new busc param
410 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
411 $session->param("busc" => $newbusc);
413 my ($numberBiblioPaging, $dataBiblioPaging);
415 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
416 if ($numberBiblioPaging) {
417 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
418 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
419 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
422 $numberBiblioPaging = $paging{'next'}->{biblionumber};
423 if ($numberBiblioPaging) {
424 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
425 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
426 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
428 # Partial list of biblio results
430 for (my $j = 0; $j < @arrBiblios; $j++) {
431 next unless ($arrBiblios[$j]);
432 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
433 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]};
435 $template->param('listResults' => \@listResults) if (@listResults);
436 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
441 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
442 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
443 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
445 # adding items linked via host biblios
447 my $analyticfield = '773';
448 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
449 $analyticfield = '773';
450 } elsif ($marcflavour eq 'UNIMARC') {
451 $analyticfield = '461';
453 foreach my $hostfield ( $record->field($analyticfield)) {
454 my $hostbiblionumber = $hostfield->subfield("0");
455 my $linkeditemnumber = $hostfield->subfield("9");
456 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
457 foreach my $hostitemInfo (@hostitemInfos){
458 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
459 push(@all_items, $hostitemInfo);
466 # Are there items to hide?
468 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
472 for my $itm (@all_items) {
473 if ( C4::Context->preference('hidelostitems') ) {
474 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
476 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
484 my $branches = GetBranches();
486 if (C4::Context->userenv){
487 $branch = C4::Context->userenv->{branch};
489 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
491 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
493 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
496 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
497 $branchname = $branches->{$branch}->{'branchname'};
499 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
500 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
506 foreach my $item ( @items ) {
507 if ( $item->{'branchname'} eq $branchname ) {
508 $item->{'this_branch'} = 1;
509 push( @our_items, $item );
511 push( @other_items, $item );
515 @items = ( @our_items, @other_items );
519 my $dat = &GetBiblioData($biblionumber);
521 my $itemtypes = GetItemTypes();
523 my $itemtype = $dat->{'itemtype'};
525 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
526 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
528 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
529 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
530 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
532 #coping with subscriptions
533 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
534 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
537 $dat->{'serial'}=1 if $subscriptionsnumber;
538 foreach my $subscription (@subscriptions) {
539 my $serials_to_display;
541 $cell{subscriptionid} = $subscription->{subscriptionid};
542 $cell{subscriptionnotes} = $subscription->{notes};
543 $cell{missinglist} = $subscription->{missinglist};
544 $cell{opacnote} = $subscription->{opacnote};
545 $cell{histstartdate} = $subscription->{histstartdate};
546 $cell{histenddate} = $subscription->{histenddate};
547 $cell{branchcode} = $subscription->{branchcode};
548 $cell{branchname} = GetBranchName($subscription->{branchcode});
549 $cell{hasalert} = $subscription->{hasalert};
550 $cell{callnumber} = $subscription->{callnumber};
551 $cell{closed} = $subscription->{closed};
552 #get the three latest serials.
553 $serials_to_display = $subscription->{opacdisplaycount};
554 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
555 $cell{opacdisplaycount} = $serials_to_display;
556 $cell{latestserials} =
557 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
561 $dat->{'count'} = scalar(@items);
564 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
566 my (%item_reserves, %priority);
567 my ($show_holds_count, $show_priority);
568 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
569 m/holds/o and $show_holds_count = 1;
570 m/priority/ and $show_priority = 1;
573 if ( $show_holds_count || $show_priority) {
574 my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
575 $template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
576 foreach (@$reserves) {
577 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
578 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
581 ? ($priority{ $_->{itemnumber} } = $_->{priority})
582 : ($template->param( priority => $_->{priority} ));
586 $template->param( show_priority => $has_hold ) ;
590 my (@itemloop, @otheritemloop);
591 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
592 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
593 $template->param(SeparateHoldings => 1);
595 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
596 my $viewallitems = $query->param('viewallitems');
597 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
600 my ( @itemnumbers_on_order );
601 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
602 my $orders = C4::Acquisition::SearchOrders({
603 biblionumber => $biblionumber,
606 my $total_quantity = 0;
607 for my $order ( @$orders ) {
608 if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
609 for my $itemnumber ( C4::Acquisition::GetItemnumbersFromOrder( $order->{ordernumber} ) ) {
610 push @itemnumbers_on_order, $itemnumber;
613 $total_quantity += $order->{quantity};
615 $template->{VARS}->{acquisition_details} = {
616 total_quantity => $total_quantity,
620 if ( not $viewallitems and @items > $max_items_to_display ) {
623 items_count => scalar( @items ),
626 my $allow_onshelf_holds;
627 my $borrower = GetMember( 'borrowernumber' => $borrowernumber );
628 for my $itm (@items) {
629 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
630 $itm->{priority} = $priority{ $itm->{itemnumber} };
633 && !$itm->{'withdrawn'}
634 && !$itm->{'itemlost'}
635 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
636 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
637 && $itm->{'itemnumber'};
639 $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed( $itm, $borrower )
640 unless $allow_onshelf_holds;
642 # get collection code description, too
643 my $ccode = $itm->{'ccode'};
644 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
645 my $copynumber = $itm->{'copynumber'};
646 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
647 if ( defined $itm->{'location'} ) {
648 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
650 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
651 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
652 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description};
654 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
655 $itemfields{$_} = 1 if ($itm->{$_});
658 # walk through the item-level authorised values and populate some images
659 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
660 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
662 if ( $itm->{'itemlost'} ) {
663 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
664 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
665 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
667 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
668 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
669 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
671 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
672 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
673 $itm->{transfertwhen} = $transfertwhen;
674 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
675 $itm->{transfertto} = $branches->{$transfertto}{branchname};
678 if ( C4::Context->preference('OPACAcquisitionDetails')
679 and C4::Context->preference('AcqCreateItem') eq 'ordering' )
682 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
685 my $itembranch = $itm->{$separatebranch};
686 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
687 if ($itembranch and $itembranch eq $currentbranch) {
688 push @itemloop, $itm;
690 push @otheritemloop, $itm;
693 push @itemloop, $itm;
696 $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
699 # Display only one tab if one items list is empty
700 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
701 $template->param(SeparateHoldings => 0);
702 if (scalar(@itemloop) == 0) {
703 @itemloop = @otheritemloop;
707 ## get notes and subjects from MARC record
708 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
709 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
710 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
711 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
712 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
713 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
714 my $marchostsarray = GetMarcHosts($record,$marcflavour);
717 MARCSUBJCTS => $marcsubjctsarray,
718 MARCAUTHORS => $marcauthorsarray,
719 MARCSERIES => $marcseriesarray,
720 MARCURLS => $marcurlsarray,
721 MARCISBNS => $marcisbnsarray,
722 MARCHOSTS => $marchostsarray,
726 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
727 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
730 MARCNOTES => $marcnotesarray,
731 norequests => $norequests,
732 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
733 itemdata_ccode => $itemfields{ccode},
734 itemdata_enumchron => $itemfields{enumchron},
735 itemdata_uri => $itemfields{uri},
736 itemdata_copynumber => $itemfields{copynumber},
737 itemdata_itemnotes => $itemfields{itemnotes},
738 authorised_value_images => $biblio_authorised_value_images,
739 subtitle => $subtitle,
740 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
743 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
744 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
745 my $subfields = substr $fieldspec, 3;
746 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
747 my @alternateholdingsinfo = ();
748 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
750 for my $field (@holdingsfields) {
751 my %holding = ( holding => '' );
752 my $havesubfield = 0;
753 for my $subfield ($field->subfields()) {
754 if ((index $subfields, $$subfield[0]) >= 0) {
755 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
756 $holding{'holding'} .= $$subfield[1];
761 push(@alternateholdingsinfo, \%holding);
766 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
770 foreach ( keys %{$dat} ) {
771 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
774 # some useful variables for enhanced content;
775 # in each case, we're grabbing the first value we find in
776 # the record and normalizing it
777 my $upc = GetNormalizedUPC($record,$marcflavour);
778 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
779 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
780 my $content_identifier_exists;
781 if ( $isbn or $ean or $oclc or $upc ) {
782 $content_identifier_exists = 1;
785 normalized_upc => $upc,
786 normalized_ean => $ean,
787 normalized_oclc => $oclc,
788 normalized_isbn => $isbn,
789 content_identifier_exists => $content_identifier_exists,
792 # COinS format FIXME: for books Only
794 ocoins => GetCOinSBiblio($record),
797 my $libravatar_enabled = 0;
798 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
800 require Libravatar::URL;
801 Libravatar::URL->import();
804 $libravatar_enabled = 1;
808 my $reviews = getreviews( $biblionumber, 1 );
809 my $loggedincommenter;
814 foreach ( @$reviews ) {
815 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
816 # setting some borrower info into this hash
817 $_->{title} = $borrowerData->{'title'};
818 $_->{surname} = $borrowerData->{'surname'};
819 $_->{firstname} = $borrowerData->{'firstname'};
820 if ($libravatar_enabled and $borrowerData->{'email'}) {
821 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
823 $_->{userid} = $borrowerData->{'userid'};
824 $_->{cardnumber} = $borrowerData->{'cardnumber'};
826 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
827 $_->{your_comment} = 1;
828 $loggedincommenter = 1;
833 if(C4::Context->preference("ISBD")) {
834 $template->param(ISBD => 1);
838 itemloop => \@itemloop,
839 otheritemloop => \@otheritemloop,
840 subscriptionsnumber => $subscriptionsnumber,
841 biblionumber => $biblionumber,
842 subscriptions => \@subs,
843 subscriptionsnumber => $subscriptionsnumber,
845 loggedincommenter => $loggedincommenter
849 if (C4::Context->preference("virtualshelves") ) {
850 my $shelves = Koha::Virtualshelves->search(
852 biblionumber => $biblionumber,
856 join => 'virtualshelfcontents',
859 $template->param( shelves => $shelves );
863 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
866 XISBNS => get_xisbns($isbn)
869 if ($@) { warn "XISBN Failed $@"; }
873 my @sc_fields = $record->field(955);
874 my @lc_fields = $marcflavour eq 'UNIMARC'
875 ? $record->field(930)
876 : $record->field(852);
877 my @serialcollections = ();
879 foreach my $sc_field (@sc_fields) {
882 $row_data{text} = $sc_field->subfield('r');
883 $row_data{branch} = $sc_field->subfield('9');
884 foreach my $lc_field (@lc_fields) {
885 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
886 ? $lc_field->subfield('a') # 930$a
887 : $lc_field->subfield('h') # 852$h
888 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
891 if ($row_data{text} && $row_data{branch}) {
892 push (@serialcollections, \%row_data);
896 if (scalar(@serialcollections) > 0) {
898 serialcollection => 1,
899 serialcollections => \@serialcollections);
902 # Local cover Images stuff
903 if (C4::Context->preference("OPACLocalCoverImages")){
904 $template->param(OPACLocalCoverImages => 1);
908 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
909 $template->param( C4::HTML5Media->gethtml5media($record));
912 my $syndetics_elements;
914 if ( C4::Context->preference("SyndeticsEnabled") ) {
915 $template->param("SyndeticsEnabled" => 1);
916 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
918 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
919 for my $element (values %$syndetics_elements) {
920 $template->param("Syndetics$element"."Exists" => 1 );
921 #warn "Exists: "."Syndetics$element"."Exists";
927 if ( C4::Context->preference("SyndeticsEnabled")
928 && C4::Context->preference("SyndeticsSummary")
929 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
931 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
932 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
938 if ( C4::Context->preference("SyndeticsEnabled")
939 && C4::Context->preference("SyndeticsTOC")
940 && exists($syndetics_elements->{'TOC'}) ) {
942 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
943 $template->param( SYNDETICS_TOC => $syndetics_toc );
948 if ( C4::Context->preference("SyndeticsEnabled")
949 && C4::Context->preference("SyndeticsExcerpt")
950 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
952 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
953 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
958 if ( C4::Context->preference("SyndeticsEnabled")
959 && C4::Context->preference("SyndeticsReviews")) {
961 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
962 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
967 if ( C4::Context->preference("SyndeticsEnabled")
968 && C4::Context->preference("SyndeticsAuthorNotes")
969 && exists($syndetics_elements->{'ANOTES'}) ) {
971 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
972 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
977 # LibraryThingForLibraries ID Code and Tabbed View Option
978 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
980 $template->param(LibraryThingForLibrariesID =>
981 C4::Context->preference('LibraryThingForLibrariesID') );
982 $template->param(LibraryThingForLibrariesTabbedView =>
983 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
987 if( C4::Context->preference('NovelistSelectEnabled') )
989 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
990 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
991 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
996 if ( C4::Context->preference("Babeltheque") ) {
999 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
1004 if ( C4::Context->preference( "SocialNetworks" ) ) {
1005 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1006 $template->param( SocialNetworks => 1 );
1009 # Shelf Browser Stuff
1010 if (C4::Context->preference("OPACShelfBrowser")) {
1011 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1012 if (defined($starting_itemnumber)) {
1013 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
1014 my $nearby = GetNearbyItems($starting_itemnumber);
1017 starting_itemnumber => $starting_itemnumber,
1018 starting_homebranch => $nearby->{starting_homebranch}->{description},
1019 starting_location => $nearby->{starting_location}->{description},
1020 starting_ccode => $nearby->{starting_ccode}->{description},
1021 shelfbrowser_prev_item => $nearby->{prev_item},
1022 shelfbrowser_next_item => $nearby->{next_item},
1023 shelfbrowser_items => $nearby->{items},
1026 # in which tab shelf browser should open ?
1027 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
1028 $template->param(shelfbrowser_tab => 'holdings');
1030 $template->param(shelfbrowser_tab => 'otherholdings');
1035 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
1037 if (C4::Context->preference("BakerTaylorEnabled")) {
1039 BakerTaylorEnabled => 1,
1040 BakerTaylorImageURL => &image_url(),
1041 BakerTaylorLinkURL => &link_url(),
1042 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1044 my ($bt_user, $bt_pass);
1046 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1047 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1050 BakerTaylorContentURL =>
1051 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1052 $bt_user,$bt_pass,$isbn)
1058 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1061 TagsShowOnDetail => $tag_quantity,
1062 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1064 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1065 'sort'=>'-weight', limit=>$tag_quantity}));
1068 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1069 # These values are going to be read by Javascript, at least in the case
1070 # of the google covers
1071 $template->param(covernewwindow => 'true');
1073 $template->param(covernewwindow => 'false');
1076 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1077 my $rating = GetRating( $biblionumber, $borrowernumber );
1079 rating_value => $rating->{'rating_value'},
1080 rating_total => $rating->{'rating_total'},
1081 rating_avg => $rating->{'rating_avg'},
1082 rating_avg_int => $rating->{'rating_avg_int'},
1083 borrowernumber => $borrowernumber
1087 #Search for title in links
1088 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1089 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1090 my $issn = $marcissns->[0] || '';
1092 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1093 $dat->{title} =~ s/\/+$//; # remove trailing slash
1094 $dat->{title} =~ s/\s+$//; # remove trailing space
1095 $search_for_title = parametrized_url(
1098 TITLE => $dat->{title},
1099 AUTHOR => $dat->{author},
1102 CONTROLNUMBER => $marccontrolnumber,
1103 BIBLIONUMBER => $biblionumber,
1106 $template->param('OPACSearchForTitleIn' => $search_for_title);
1110 if ( C4::Context->preference("IDREF") ) {
1111 # If the record comes from the SUDOC
1112 if ( $record->field('009') ) {
1113 my $unimarc3 = $record->field("009")->data;
1114 if ( $unimarc3 =~ /^\d+$/ ) {
1122 # We try to select the best default tab to show, according to what
1123 # the user wants, and what's available for display
1124 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1126 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1128 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1129 ? 'serialcollection' :
1130 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1132 $subscriptionsnumber
1134 @serialcollections > 0
1135 ? 'serialcollection' : 'subscriptions';
1136 $template->param('defaulttab' => $defaulttab);
1138 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1139 my @images = ListImagesForBiblio($biblionumber);
1140 $template->{VARS}->{localimages} = \@images;
1143 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1144 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1145 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1146 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1148 if (C4::Context->preference('OpacHighlightedWords')) {
1149 $template->{VARS}->{query_desc} = $query->param('query_desc');
1151 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1153 if ( C4::Context->preference('UseCourseReserves') ) {
1154 foreach my $i ( @items ) {
1155 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1160 'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay') ,
1161 'OpacLocationBranchToDisplayShelving' => C4::Context->preference('OpacLocationBranchToDisplayShelving'),
1164 output_html_with_http_headers $query, $cookie, $template->output;