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
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.
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);
57 if (C4
::Context
->preference('BakerTaylorEnabled')) {
58 require C4
::External
::BakerTaylor
;
59 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
64 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
66 template_name
=> "opac-detail.tt",
69 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
70 flagsrequired
=> { borrow
=> 1 },
74 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
75 $biblionumber = int($biblionumber);
77 my @all_items = GetItemsInfo
($biblionumber);
79 if (scalar @all_items >= 1) {
80 push @hiddenitems, GetHiddenItemnumbers
(@all_items);
82 if (scalar @hiddenitems == scalar @all_items ) {
83 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
88 my $record = GetMarcBiblio
($biblionumber);
90 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
94 # redirect if opacsuppression is enabled and biblio is suppressed
95 if (C4
::Context
->preference('OpacSuppression')) {
96 # FIXME hardcoded; the suppression flag ought to be materialized
97 # as a column on biblio or the like
98 my $opacsuppressionfield = '942';
99 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
100 # redirect to opac-blocked info page or 404?
101 my $opacsuppressionredirect;
102 if ( C4
::Context
->preference("OpacSuppressionRedirect") ) {
103 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
105 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
107 if ( $opacsuppressionfieldvalue &&
108 $opacsuppressionfieldvalue->subfield("n") &&
109 $opacsuppressionfieldvalue->subfield("n") == 1) {
110 # if OPAC suppression by IP address
111 if (C4
::Context
->preference('OpacSuppressionByIPRange')) {
112 my $IPAddress = $ENV{'REMOTE_ADDR'};
113 my $IPRange = C4
::Context
->preference('OpacSuppressionByIPRange');
114 if ($IPAddress !~ /^$IPRange/) {
115 print $query->redirect($opacsuppressionredirect);
119 print $query->redirect($opacsuppressionredirect);
125 $template->param( biblionumber
=> $biblionumber );
127 # get biblionumbers stored in the cart
130 if($query->cookie("bib_list")){
131 my $cart_list = $query->cookie("bib_list");
132 @cart_list = split(/\//, $cart_list);
133 if ( grep {$_ eq $biblionumber} @cart_list) {
134 $template->param( incart
=> 1 );
139 SetUTF8Flag
($record);
140 my $marcflavour = C4
::Context
->preference("marcflavour");
141 my $ean = GetNormalizedEAN
( $record, $marcflavour );
143 # XSLT processing of some stuff
144 if (C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
145 $template->param( 'XSLTBloc' => XSLTParse4Display
($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
148 my $OpacBrowseResults = C4
::Context
->preference("OpacBrowseResults");
149 $template->{VARS
}->{'OpacBrowseResults'} = $OpacBrowseResults;
151 # We look for the busc param to build the simple paging from the search
152 if ($OpacBrowseResults) {
153 my $session = get_session
($query->cookie("CGISESSID"));
154 my %paging = (previous
=> {}, next => {});
155 if ($session->param('busc')) {
158 # Rebuild the string to store on session
161 my $arrParamsBusc = shift;
163 my $pasarParams = '';
165 for (keys %$arrParamsBusc) {
166 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
167 if (defined($arrParamsBusc->{$_})) {
168 $pasarParams .= '&' if ($j);
169 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
173 for my $value (@
{$arrParamsBusc->{$_}}) {
174 $pasarParams .= '&' if ($j);
175 $pasarParams .= $_ . '=' . $value;
183 # Search given the current values from the busc param
186 my ($arrParamsBusc, $offset, $results_per_page) = @_;
188 my $expanded_facet = $arrParamsBusc->{'expand'};
189 my $branches = GetBranches
();
190 my $itemtypes = GetItemTypes
;
192 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
193 @servers = ("biblioserver") unless (@servers);
195 my ($default_sort_by, @sort_by);
196 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
197 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
198 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
199 my ($error, $results_hashref, $facets);
201 ($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'});
205 for (my $i=0;$i<@servers;$i++) {
206 my $server = $servers[$i];
207 $hits = $results_hashref->{$server}->{"hits"};
208 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
213 # Build the current list of biblionumbers in this search
216 my ($newresultsRef, $results_per_page) = @_;
218 my $listBiblios = '';
220 foreach (@
$newresultsRef) {
221 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
222 $listBiblios .= $bibnum . ',';
224 last if ($j == $results_per_page);
226 chop $listBiblios if ($listBiblios =~ /,$/);
230 my $busc = $session->param("busc");
231 my @arrBusc = split(/\&(?:amp;)?/, $busc);
233 my %arrParamsBusc = ();
235 ($key, $value) = split(/=/, $_, 2);
236 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
237 $arrParamsBusc{$key} = $value;
239 unless (exists($arrParamsBusc{$key})) {
240 $arrParamsBusc{$key} = [];
242 push @
{$arrParamsBusc{$key}}, $value;
246 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
247 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
248 $arrParamsBusc{'count'} = $results_per_page;
249 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
250 # The value OPACnumSearchResults has changed and the search has to be rebuild
251 if ($count != $results_per_page) {
252 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
254 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
255 for (@arrBibliosAux) {
256 last if ($_ == $biblionumber);
259 $indexBiblio += $offset;
260 $offset = int($indexBiblio / $count) * $count;
261 $arrParamsBusc{'offset'} = $offset;
263 $arrParamsBusc{'count'} = $count;
264 $results_per_page = $count;
265 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
266 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
267 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
268 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
269 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
270 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
271 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
272 $session->param("busc" => $newbusc);
273 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
275 my $modifyListBiblios = 0;
276 # We come from a previous click
277 if (exists($arrParamsBusc{'previous'})) {
278 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
279 delete $arrParamsBusc{'previous'};
280 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
281 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
282 delete $arrParamsBusc{'next'};
284 if ($modifyListBiblios) {
285 if (exists($arrParamsBusc{'newlistBiblios'})) {
286 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
287 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
288 my @arrAux = split(',', $listBibliosAux);
289 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
290 if ($modifyListBiblios == 1) {
291 $arrParamsBusc{'next'} = $arrAux[0];
292 $paging{'next'}->{biblionumber
} = $arrAux[0];
294 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
295 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
298 delete $arrParamsBusc{'listBiblios'};
300 my $offsetAux = $arrParamsBusc{'offset'};
301 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
302 $arrParamsBusc{'offsetSearch'} = $offsetAux;
303 $offset = $arrParamsBusc{'offset'};
304 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
305 $session->param("busc" => $newbusc);
306 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
311 # Rebuild the query for the button "back to results"
313 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
314 $buscParam .= '&' unless ($j == 0);
319 $template->param('busc' => $buscParam);
322 # We are inside the list of biblios and we don't have to search
323 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
324 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
326 # We are at the first item of the list
327 if ($arrBiblios[0] == $biblionumber) {
328 if (@arrBiblios > 1) {
329 for (my $j = 1; $j < @arrBiblios; $j++) {
330 next unless ($arrBiblios[$j]);
331 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
335 # search again if we are not at the first searching list
336 if ($offset && !$arrParamsBusc{'previous'}) {
338 $offsetSearch = $offset - $results_per_page;
340 # we are at the last item of the list
341 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
342 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
343 next unless ($arrBiblios[$j]);
344 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
348 # search again if we are at the first list and there is more results
349 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
351 # search again if we aren't at the first list and there is more results
352 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
354 $offsetSearch = $offset + $results_per_page if ($searchAgain);
356 for (my $j = 1; $j < $#arrBiblios; $j++) {
357 if ($arrBiblios[$j] == $biblionumber) {
358 for (my $z = $j - 1; $z >= 0; $z--) {
359 next unless ($arrBiblios[$z]);
360 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
363 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
364 next unless ($arrBiblios[$z]);
365 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
373 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
376 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
377 my @newresults = @
$newresultsRef;
378 # build the new listBiblios
379 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
380 unless (exists($arrParamsBusc{'listBiblios'})) {
381 $arrParamsBusc{'listBiblios'} = $listBiblios;
382 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
384 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
386 # From the new list we build again the next and previous result
388 if ($arrBiblios[0] == $biblionumber) {
389 for (my $j = $#newresults; $j >= 0; $j--) {
390 next unless ($newresults[$j]);
391 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
392 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
393 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
396 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
397 for (my $j = 0; $j < @newresults; $j++) {
398 next unless ($newresults[$j]);
399 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
400 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
401 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
406 # build new busc param
407 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
408 $session->param("busc" => $newbusc);
410 my ($numberBiblioPaging, $dataBiblioPaging);
412 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
413 if ($numberBiblioPaging) {
414 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
415 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
416 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
419 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
420 if ($numberBiblioPaging) {
421 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
422 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
423 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
425 # Partial list of biblio results
427 for (my $j = 0; $j < @arrBiblios; $j++) {
428 next unless ($arrBiblios[$j]);
429 $dataBiblioPaging = GetBiblioData
($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
430 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]};
432 $template->param('listResults' => \
@listResults) if (@listResults);
433 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
439 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
440 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
444 $template->param('OPACShowCheckoutName' => C4
::Context
->preference("OPACShowCheckoutName") );
445 $template->param('OPACShowBarcode' => C4
::Context
->preference("OPACShowBarcode") );
447 # adding items linked via host biblios
449 my $analyticfield = '773';
450 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
451 $analyticfield = '773';
452 } elsif ($marcflavour eq 'UNIMARC') {
453 $analyticfield = '461';
455 foreach my $hostfield ( $record->field($analyticfield)) {
456 my $hostbiblionumber = $hostfield->subfield("0");
457 my $linkeditemnumber = $hostfield->subfield("9");
458 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
459 foreach my $hostitemInfo (@hostitemInfos){
460 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
461 push(@all_items, $hostitemInfo);
468 # Are there items to hide?
470 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
474 for my $itm (@all_items) {
475 if ( C4
::Context
->preference('hidelostitems') ) {
476 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
478 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
486 my $branches = GetBranches
();
488 if (C4
::Context
->userenv){
489 $branch = C4
::Context
->userenv->{branch
};
491 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
493 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
495 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
498 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
499 $branchname = $branches->{$branch}->{'branchname'};
501 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
502 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
508 foreach my $item ( @items ) {
509 if ( $item->{'branchname'} eq $branchname ) {
510 $item->{'this_branch'} = 1;
511 push( @our_items, $item );
513 push( @other_items, $item );
517 @items = ( @our_items, @other_items );
521 my $dat = &GetBiblioData
($biblionumber);
523 my $itemtypes = GetItemTypes
();
525 my $itemtype = $dat->{'itemtype'};
527 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
528 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
530 my $shelflocations =GetKohaAuthorisedValues
('items.location',$dat->{'frameworkcode'}, 'opac');
531 my $collections = GetKohaAuthorisedValues
('items.ccode',$dat->{'frameworkcode'}, 'opac');
532 my $copynumbers = GetKohaAuthorisedValues
('items.copynumber',$dat->{'frameworkcode'}, 'opac');
534 #coping with subscriptions
535 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
536 my @subscriptions = GetSubscriptions
($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
539 $dat->{'serial'}=1 if $subscriptionsnumber;
540 foreach my $subscription (@subscriptions) {
541 my $serials_to_display;
543 $cell{subscriptionid
} = $subscription->{subscriptionid
};
544 $cell{subscriptionnotes
} = $subscription->{notes
};
545 $cell{missinglist
} = $subscription->{missinglist
};
546 $cell{opacnote
} = $subscription->{opacnote
};
547 $cell{histstartdate
} = $subscription->{histstartdate
};
548 $cell{histenddate
} = $subscription->{histenddate
};
549 $cell{branchcode
} = $subscription->{branchcode
};
550 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
551 $cell{hasalert
} = $subscription->{hasalert
};
552 $cell{callnumber
} = $subscription->{callnumber
};
553 $cell{closed
} = $subscription->{closed
};
554 #get the three latest serials.
555 $serials_to_display = $subscription->{opacdisplaycount
};
556 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
557 $cell{opacdisplaycount
} = $serials_to_display;
558 $cell{latestserials
} =
559 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
563 $dat->{'count'} = scalar(@items);
566 my $biblio_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Biblio
::get_biblio_authorised_values
( $biblionumber, $record ) );
568 my (%item_reserves, %priority);
569 my ($show_holds_count, $show_priority);
570 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
571 m/holds/o and $show_holds_count = 1;
572 m/priority/ and $show_priority = 1;
575 if ( $show_holds_count || $show_priority) {
576 my $reserves = GetReservesFromBiblionumber
({ biblionumber
=> $biblionumber, all_dates
=> 1 });
577 $template->param( holds_count
=> scalar( @
$reserves ) ) if $show_holds_count;
578 foreach (@
$reserves) {
579 $item_reserves{ $_->{itemnumber
} }++ if $_->{itemnumber
};
580 if ($show_priority && $_->{borrowernumber
} == $borrowernumber) {
583 ?
($priority{ $_->{itemnumber
} } = $_->{priority
})
584 : ($template->param( priority
=> $_->{priority
} ));
588 $template->param( show_priority
=> $has_hold ) ;
592 my (@itemloop, @otheritemloop);
593 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
594 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
595 $template->param(SeparateHoldings
=> 1);
597 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
598 my $viewallitems = $query->param('viewallitems');
599 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
602 my ( @itemnumbers_on_order );
603 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
604 my $orders = C4
::Acquisition
::SearchOrders
({
605 biblionumber
=> $biblionumber,
608 my $total_quantity = 0;
609 for my $order ( @
$orders ) {
610 if ( C4
::Context
->preference('AcqCreateItem') eq 'ordering' ) {
611 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
612 push @itemnumbers_on_order, $itemnumber;
615 $total_quantity += $order->{quantity
};
617 $template->{VARS
}->{acquisition_details
} = {
618 total_quantity
=> $total_quantity,
622 if ( not $viewallitems and @items > $max_items_to_display ) {
625 items_count
=> scalar( @items ),
628 for my $itm (@items) {
629 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
630 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
632 if ( (not $itm->{'withdrawn'} )
633 && (not $itm->{'itemlost'} )
634 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
635 && (not $itemtypes->{$itm->{'itype'}}->{notforloan
} )
636 && ($itm->{'itemnumber'} ) );
638 # get collection code description, too
639 my $ccode = $itm->{'ccode'};
640 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
641 my $copynumber = $itm->{'copynumber'};
642 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
643 if ( defined $itm->{'location'} ) {
644 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
646 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
647 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
648 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{'description'};
650 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
651 $itemfields{$_} = 1 if ($itm->{$_});
654 # walk through the item-level authorised values and populate some images
655 my $item_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Items
::get_item_authorised_values
( $itm->{'itemnumber'} ) );
656 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
658 if ( $itm->{'itemlost'} ) {
659 my $lostimageinfo = List
::Util
::first
{ $_->{'category'} eq 'LOST' } @
$item_authorised_value_images;
660 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
661 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
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' )
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;
686 push @otheritemloop, $itm;
689 push @itemloop, $itm;
694 # Display only one tab if one items list is empty
695 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
696 $template->param(SeparateHoldings
=> 0);
697 if (scalar(@itemloop) == 0) {
698 @itemloop = @otheritemloop;
702 ## get notes and subjects from MARC record
703 my $dbh = C4
::Context
->dbh;
704 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
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);
711 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
714 MARCNOTES
=> $marcnotesarray,
715 MARCSUBJCTS
=> $marcsubjctsarray,
716 MARCAUTHORS
=> $marcauthorsarray,
717 MARCSERIES
=> $marcseriesarray,
718 MARCURLS
=> $marcurlsarray,
719 MARCISBNS
=> $marcisbnsarray,
720 MARCHOSTS
=> $marchostsarray,
721 norequests
=> $norequests,
722 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
723 itemdata_ccode
=> $itemfields{ccode
},
724 itemdata_enumchron
=> $itemfields{enumchron
},
725 itemdata_uri
=> $itemfields{uri
},
726 itemdata_copynumber
=> $itemfields{copynumber
},
727 itemdata_itemnotes
=> $itemfields{itemnotes
},
728 authorised_value_images
=> $biblio_authorised_value_images,
729 subtitle
=> $subtitle,
730 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
733 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
734 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
735 my $subfields = substr $fieldspec, 3;
736 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
737 my @alternateholdingsinfo = ();
738 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
740 for my $field (@holdingsfields) {
741 my %holding = ( holding
=> '' );
742 my $havesubfield = 0;
743 for my $subfield ($field->subfields()) {
744 if ((index $subfields, $$subfield[0]) >= 0) {
745 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
746 $holding{'holding'} .= $$subfield[1];
751 push(@alternateholdingsinfo, \
%holding);
756 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
760 foreach ( keys %{$dat} ) {
761 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
764 # some useful variables for enhanced content;
765 # in each case, we're grabbing the first value we find in
766 # the record and normalizing it
767 my $upc = GetNormalizedUPC
($record,$marcflavour);
768 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
769 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
770 my $content_identifier_exists;
771 if ( $isbn or $ean or $oclc or $upc ) {
772 $content_identifier_exists = 1;
775 normalized_upc
=> $upc,
776 normalized_ean
=> $ean,
777 normalized_oclc
=> $oclc,
778 normalized_isbn
=> $isbn,
779 content_identifier_exists
=> $content_identifier_exists,
782 # COinS format FIXME: for books Only
784 ocoins
=> GetCOinSBiblio
($record),
787 my $libravatar_enabled = 0;
788 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto')) {
790 require Libravatar
::URL
;
791 Libravatar
::URL
->import();
794 $libravatar_enabled = 1;
798 my $reviews = getreviews
( $biblionumber, 1 );
799 my $loggedincommenter;
804 foreach ( @
$reviews ) {
805 my $borrowerData = GetMember
('borrowernumber' => $_->{borrowernumber
});
806 # setting some borrower info into this hash
807 $_->{title
} = $borrowerData->{'title'};
808 $_->{surname
} = $borrowerData->{'surname'};
809 $_->{firstname
} = $borrowerData->{'firstname'};
810 if ($libravatar_enabled and $borrowerData->{'email'}) {
811 $_->{avatarurl
} = libravatar_url
(email
=> $borrowerData->{'email'}, https
=> $ENV{HTTPS
});
813 $_->{userid
} = $borrowerData->{'userid'};
814 $_->{cardnumber
} = $borrowerData->{'cardnumber'};
816 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
817 $_->{your_comment
} = 1;
818 $loggedincommenter = 1;
823 if(C4
::Context
->preference("ISBD")) {
824 $template->param(ISBD
=> 1);
828 itemloop
=> \
@itemloop,
829 otheritemloop
=> \
@otheritemloop,
830 subscriptionsnumber
=> $subscriptionsnumber,
831 biblionumber
=> $biblionumber,
832 subscriptions
=> \
@subs,
833 subscriptionsnumber
=> $subscriptionsnumber,
835 loggedincommenter
=> $loggedincommenter
840 if (C4
::Context
->preference("virtualshelves") ) {
841 $template->param( 'GetShelves' => GetBibliosShelves
( $biblionumber ) );
846 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
849 XISBNS
=> get_xisbns
($isbn)
852 if ($@
) { warn "XISBN Failed $@"; }
856 my @sc_fields = $record->field(955);
857 my @lc_fields = $marcflavour eq 'UNIMARC'
858 ?
$record->field(930)
859 : $record->field(852);
860 my @serialcollections = ();
862 foreach my $sc_field (@sc_fields) {
865 $row_data{text
} = $sc_field->subfield('r');
866 $row_data{branch
} = $sc_field->subfield('9');
867 foreach my $lc_field (@lc_fields) {
868 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
869 ?
$lc_field->subfield('a') # 930$a
870 : $lc_field->subfield('h') # 852$h
871 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
874 if ($row_data{text
} && $row_data{branch
}) {
875 push (@serialcollections, \
%row_data);
879 if (scalar(@serialcollections) > 0) {
881 serialcollection
=> 1,
882 serialcollections
=> \
@serialcollections);
885 # Local cover Images stuff
886 if (C4
::Context
->preference("OPACLocalCoverImages")){
887 $template->param(OPACLocalCoverImages
=> 1);
891 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
892 $template->param( C4
::HTML5Media
->gethtml5media($record));
895 my $syndetics_elements;
897 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
898 $template->param("SyndeticsEnabled" => 1);
899 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
901 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
902 for my $element (values %$syndetics_elements) {
903 $template->param("Syndetics$element"."Exists" => 1 );
904 #warn "Exists: "."Syndetics$element"."Exists";
910 if ( C4
::Context
->preference("SyndeticsEnabled")
911 && C4
::Context
->preference("SyndeticsSummary")
912 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
914 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
915 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
921 if ( C4
::Context
->preference("SyndeticsEnabled")
922 && C4
::Context
->preference("SyndeticsTOC")
923 && exists($syndetics_elements->{'TOC'}) ) {
925 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
926 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
931 if ( C4
::Context
->preference("SyndeticsEnabled")
932 && C4
::Context
->preference("SyndeticsExcerpt")
933 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
935 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
936 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
941 if ( C4
::Context
->preference("SyndeticsEnabled")
942 && C4
::Context
->preference("SyndeticsReviews")) {
944 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
945 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
950 if ( C4
::Context
->preference("SyndeticsEnabled")
951 && C4
::Context
->preference("SyndeticsAuthorNotes")
952 && exists($syndetics_elements->{'ANOTES'}) ) {
954 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
955 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
960 # LibraryThingForLibraries ID Code and Tabbed View Option
961 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
963 $template->param(LibraryThingForLibrariesID
=>
964 C4
::Context
->preference('LibraryThingForLibrariesID') );
965 $template->param(LibraryThingForLibrariesTabbedView
=>
966 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
970 if( C4
::Context
->preference('NovelistSelectEnabled') )
972 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
973 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
974 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
979 if ( C4
::Context
->preference("Babeltheque") ) {
982 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
987 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
988 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
989 $template->param( SocialNetworks
=> 1 );
992 # Shelf Browser Stuff
993 if (C4
::Context
->preference("OPACShelfBrowser")) {
994 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
995 if (defined($starting_itemnumber)) {
996 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
997 my $nearby = GetNearbyItems
($starting_itemnumber);
1000 starting_itemnumber
=> $starting_itemnumber,
1001 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1002 starting_location
=> $nearby->{starting_location
}->{description
},
1003 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1004 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1005 shelfbrowser_next_item
=> $nearby->{next_item
},
1006 shelfbrowser_items
=> $nearby->{items
},
1009 # in which tab shelf browser should open ?
1010 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1011 $template->param(shelfbrowser_tab
=> 'holdings');
1013 $template->param(shelfbrowser_tab
=> 'otherholdings');
1018 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1020 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1022 BakerTaylorEnabled
=> 1,
1023 BakerTaylorImageURL
=> &image_url
(),
1024 BakerTaylorLinkURL
=> &link_url
(),
1025 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1027 my ($bt_user, $bt_pass);
1029 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1030 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1033 BakerTaylorContentURL
=>
1034 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1035 $bt_user,$bt_pass,$isbn)
1041 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1044 TagsShowOnDetail
=> $tag_quantity,
1045 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1047 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1048 'sort'=>'-weight', limit
=>$tag_quantity}));
1051 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1052 # These values are going to be read by Javascript, at least in the case
1053 # of the google covers
1054 $template->param(covernewwindow
=> 'true');
1056 $template->param(covernewwindow
=> 'false');
1060 my $OpacExportOptions=C4
::Context
->preference("OpacExportOptions");
1061 my @export_options = split(/\|/,$OpacExportOptions);
1062 $template->{VARS
}->{'export_options'} = \
@export_options;
1064 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1065 my $rating = GetRating
( $biblionumber, $borrowernumber );
1067 rating_value
=> $rating->{'rating_value'},
1068 rating_total
=> $rating->{'rating_total'},
1069 rating_avg
=> $rating->{'rating_avg'},
1070 rating_avg_int
=> $rating->{'rating_avg_int'},
1071 borrowernumber
=> $borrowernumber
1075 #Search for title in links
1076 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1077 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1078 my $issn = $marcissns->[0] || '';
1080 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1081 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1082 $dat->{title
} =~ s/\s+$//; # remove trailing space
1083 $search_for_title = parametrized_url
(
1086 TITLE
=> $dat->{title
},
1087 AUTHOR
=> $dat->{author
},
1090 CONTROLNUMBER
=> $marccontrolnumber,
1091 BIBLIONUMBER
=> $biblionumber,
1094 $template->param('OPACSearchForTitleIn' => $search_for_title);
1097 # We try to select the best default tab to show, according to what
1098 # the user wants, and what's available for display
1099 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1101 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1103 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1104 ?
'serialcollection' :
1105 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1107 $subscriptionsnumber
1109 @serialcollections > 0
1110 ?
'serialcollection' : 'subscriptions';
1111 $template->param('defaulttab' => $defaulttab);
1113 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1114 my @images = ListImagesForBiblio
($biblionumber);
1115 $template->{VARS
}->{localimages
} = \
@images;
1118 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1119 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1120 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1121 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1123 if (C4
::Context
->preference('OpacHighlightedWords')) {
1124 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1126 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1128 if ( C4
::Context
->preference('UseCourseReserves') ) {
1129 foreach my $i ( @items ) {
1130 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1135 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay') ,
1136 'OpacLocationBranchToDisplayShelving' => C4
::Context
->preference('OpacLocationBranchToDisplayShelving'),
1139 output_html_with_http_headers
$query, $cookie, $template->output;