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')) {
159 # Rebuild the string to store on session
160 # param value is URI encoded and params separator is HTML encode (&)
163 my $arrParamsBusc = shift;
165 my $pasarParams = '';
167 for (keys %$arrParamsBusc) {
168 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
169 if (defined($arrParamsBusc->{$_})) {
170 $pasarParams .= '&' if ($j);
171 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
175 for my $value (@
{$arrParamsBusc->{$_}}) {
176 $pasarParams .= '&' if ($j);
177 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
185 # Search given the current values from the busc param
188 my ($arrParamsBusc, $offset, $results_per_page) = @_;
190 my $expanded_facet = $arrParamsBusc->{'expand'};
191 my $branches = GetBranches
();
192 my $itemtypes = GetItemTypes
;
194 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
195 @servers = ("biblioserver") unless (@servers);
197 my ($default_sort_by, @sort_by);
198 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
199 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
200 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
201 my ($error, $results_hashref, $facets);
203 ($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'});
207 for (my $i=0;$i<@servers;$i++) {
208 my $server = $servers[$i];
209 $hits = $results_hashref->{$server}->{"hits"};
210 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
215 # Build the current list of biblionumbers in this search
218 my ($newresultsRef, $results_per_page) = @_;
220 my $listBiblios = '';
222 foreach (@
$newresultsRef) {
223 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
224 $listBiblios .= $bibnum . ',';
226 last if ($j == $results_per_page);
228 chop $listBiblios if ($listBiblios =~ /,$/);
232 my $busc = $session->param("busc");
233 my @arrBusc = split(/\&(?:amp;)?/, $busc);
235 my %arrParamsBusc = ();
237 ($key, $value) = split(/=/, $_, 2);
238 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
239 $arrParamsBusc{$key} = uri_unescape
($value);
241 unless (exists($arrParamsBusc{$key})) {
242 $arrParamsBusc{$key} = [];
244 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
248 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
249 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
250 $arrParamsBusc{'count'} = $results_per_page;
251 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
252 # The value OPACnumSearchResults has changed and the search has to be rebuild
253 if ($count != $results_per_page) {
254 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
256 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
257 for (@arrBibliosAux) {
258 last if ($_ == $biblionumber);
261 $indexBiblio += $offset;
262 $offset = int($indexBiblio / $count) * $count;
263 $arrParamsBusc{'offset'} = $offset;
265 $arrParamsBusc{'count'} = $count;
266 $results_per_page = $count;
267 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
268 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
269 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
270 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
271 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
272 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
273 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
274 $session->param("busc" => $newbusc);
275 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
277 my $modifyListBiblios = 0;
278 # We come from a previous click
279 if (exists($arrParamsBusc{'previous'})) {
280 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
281 delete $arrParamsBusc{'previous'};
282 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
283 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
284 delete $arrParamsBusc{'next'};
286 if ($modifyListBiblios) {
287 if (exists($arrParamsBusc{'newlistBiblios'})) {
288 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
289 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
290 my @arrAux = split(',', $listBibliosAux);
291 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
292 if ($modifyListBiblios == 1) {
293 $arrParamsBusc{'next'} = $arrAux[0];
294 $paging{'next'}->{biblionumber
} = $arrAux[0];
296 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
297 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
300 delete $arrParamsBusc{'listBiblios'};
302 my $offsetAux = $arrParamsBusc{'offset'};
303 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
304 $arrParamsBusc{'offsetSearch'} = $offsetAux;
305 $offset = $arrParamsBusc{'offset'};
306 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
307 $session->param("busc" => $newbusc);
308 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
313 # Rebuild the query for the button "back to results"
315 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
316 $buscParam .= '&' unless ($j == 0);
317 $buscParam .= $_; # string already URI encoded
321 $template->param('busc' => $buscParam);
324 # We are inside the list of biblios and we don't have to search
325 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
326 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
328 # We are at the first item of the list
329 if ($arrBiblios[0] == $biblionumber) {
330 if (@arrBiblios > 1) {
331 for (my $j = 1; $j < @arrBiblios; $j++) {
332 next unless ($arrBiblios[$j]);
333 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
337 # search again if we are not at the first searching list
338 if ($offset && !$arrParamsBusc{'previous'}) {
340 $offsetSearch = $offset - $results_per_page;
342 # we are at the last item of the list
343 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
344 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
345 next unless ($arrBiblios[$j]);
346 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
350 # search again if we are at the first list and there is more results
351 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
353 # search again if we aren't at the first list and there is more results
354 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
356 $offsetSearch = $offset + $results_per_page if ($searchAgain);
358 for (my $j = 1; $j < $#arrBiblios; $j++) {
359 if ($arrBiblios[$j] == $biblionumber) {
360 for (my $z = $j - 1; $z >= 0; $z--) {
361 next unless ($arrBiblios[$z]);
362 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
365 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
366 next unless ($arrBiblios[$z]);
367 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
375 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
378 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
379 my @newresults = @
$newresultsRef;
380 # build the new listBiblios
381 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
382 unless (exists($arrParamsBusc{'listBiblios'})) {
383 $arrParamsBusc{'listBiblios'} = $listBiblios;
384 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
386 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
388 # From the new list we build again the next and previous result
390 if ($arrBiblios[0] == $biblionumber) {
391 for (my $j = $#newresults; $j >= 0; $j--) {
392 next unless ($newresults[$j]);
393 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
394 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
395 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
398 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
399 for (my $j = 0; $j < @newresults; $j++) {
400 next unless ($newresults[$j]);
401 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
402 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
403 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
408 # build new busc param
409 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
410 $session->param("busc" => $newbusc);
412 my ($numberBiblioPaging, $dataBiblioPaging);
414 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
415 if ($numberBiblioPaging) {
416 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
417 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
418 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
421 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
422 if ($numberBiblioPaging) {
423 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
424 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
425 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
427 # Partial list of biblio results
429 for (my $j = 0; $j < @arrBiblios; $j++) {
430 next unless ($arrBiblios[$j]);
431 $dataBiblioPaging = GetBiblioData
($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
432 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]};
434 $template->param('listResults' => \
@listResults) if (@listResults);
435 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
441 $template->param( 'AllowOnShelfHolds' => C4
::Context
->preference('AllowOnShelfHolds') );
442 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
446 $template->param('OPACShowCheckoutName' => C4
::Context
->preference("OPACShowCheckoutName") );
447 $template->param('OPACShowBarcode' => C4
::Context
->preference("OPACShowBarcode") );
449 # adding items linked via host biblios
451 my $analyticfield = '773';
452 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
453 $analyticfield = '773';
454 } elsif ($marcflavour eq 'UNIMARC') {
455 $analyticfield = '461';
457 foreach my $hostfield ( $record->field($analyticfield)) {
458 my $hostbiblionumber = $hostfield->subfield("0");
459 my $linkeditemnumber = $hostfield->subfield("9");
460 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
461 foreach my $hostitemInfo (@hostitemInfos){
462 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
463 push(@all_items, $hostitemInfo);
470 # Are there items to hide?
472 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
476 for my $itm (@all_items) {
477 if ( C4
::Context
->preference('hidelostitems') ) {
478 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
480 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
488 my $branches = GetBranches
();
490 if (C4
::Context
->userenv){
491 $branch = C4
::Context
->userenv->{branch
};
493 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
495 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
497 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
500 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
501 $branchname = $branches->{$branch}->{'branchname'};
503 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
504 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
510 foreach my $item ( @items ) {
511 if ( $item->{'branchname'} eq $branchname ) {
512 $item->{'this_branch'} = 1;
513 push( @our_items, $item );
515 push( @other_items, $item );
519 @items = ( @our_items, @other_items );
523 my $dat = &GetBiblioData
($biblionumber);
525 my $itemtypes = GetItemTypes
();
527 my $itemtype = $dat->{'itemtype'};
529 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
530 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
532 my $shelflocations =GetKohaAuthorisedValues
('items.location',$dat->{'frameworkcode'}, 'opac');
533 my $collections = GetKohaAuthorisedValues
('items.ccode',$dat->{'frameworkcode'}, 'opac');
534 my $copynumbers = GetKohaAuthorisedValues
('items.copynumber',$dat->{'frameworkcode'}, 'opac');
536 #coping with subscriptions
537 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
538 my @subscriptions = GetSubscriptions
($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
541 $dat->{'serial'}=1 if $subscriptionsnumber;
542 foreach my $subscription (@subscriptions) {
543 my $serials_to_display;
545 $cell{subscriptionid
} = $subscription->{subscriptionid
};
546 $cell{subscriptionnotes
} = $subscription->{notes
};
547 $cell{missinglist
} = $subscription->{missinglist
};
548 $cell{opacnote
} = $subscription->{opacnote
};
549 $cell{histstartdate
} = $subscription->{histstartdate
};
550 $cell{histenddate
} = $subscription->{histenddate
};
551 $cell{branchcode
} = $subscription->{branchcode
};
552 $cell{branchname
} = GetBranchName
($subscription->{branchcode
});
553 $cell{hasalert
} = $subscription->{hasalert
};
554 $cell{callnumber
} = $subscription->{callnumber
};
555 $cell{closed
} = $subscription->{closed
};
556 #get the three latest serials.
557 $serials_to_display = $subscription->{opacdisplaycount
};
558 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
559 $cell{opacdisplaycount
} = $serials_to_display;
560 $cell{latestserials
} =
561 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
565 $dat->{'count'} = scalar(@items);
568 my $biblio_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Biblio
::get_biblio_authorised_values
( $biblionumber, $record ) );
570 my (%item_reserves, %priority);
571 my ($show_holds_count, $show_priority);
572 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
573 m/holds/o and $show_holds_count = 1;
574 m/priority/ and $show_priority = 1;
577 if ( $show_holds_count || $show_priority) {
578 my $reserves = GetReservesFromBiblionumber
({ biblionumber
=> $biblionumber, all_dates
=> 1 });
579 $template->param( holds_count
=> scalar( @
$reserves ) ) if $show_holds_count;
580 foreach (@
$reserves) {
581 $item_reserves{ $_->{itemnumber
} }++ if $_->{itemnumber
};
582 if ($show_priority && $_->{borrowernumber
} == $borrowernumber) {
585 ?
($priority{ $_->{itemnumber
} } = $_->{priority
})
586 : ($template->param( priority
=> $_->{priority
} ));
590 $template->param( show_priority
=> $has_hold ) ;
594 my (@itemloop, @otheritemloop);
595 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
596 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
597 $template->param(SeparateHoldings
=> 1);
599 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
600 my $viewallitems = $query->param('viewallitems');
601 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
604 my ( @itemnumbers_on_order );
605 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
606 my $orders = C4
::Acquisition
::SearchOrders
({
607 biblionumber
=> $biblionumber,
610 my $total_quantity = 0;
611 for my $order ( @
$orders ) {
612 if ( C4
::Context
->preference('AcqCreateItem') eq 'ordering' ) {
613 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
614 push @itemnumbers_on_order, $itemnumber;
617 $total_quantity += $order->{quantity
};
619 $template->{VARS
}->{acquisition_details
} = {
620 total_quantity
=> $total_quantity,
624 if ( not $viewallitems and @items > $max_items_to_display ) {
627 items_count
=> scalar( @items ),
630 for my $itm (@items) {
631 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
632 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
634 if ( (not $itm->{'withdrawn'} )
635 && (not $itm->{'itemlost'} )
636 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
637 && (not $itemtypes->{$itm->{'itype'}}->{notforloan
} )
638 && ($itm->{'itemnumber'} ) );
640 # get collection code description, too
641 my $ccode = $itm->{'ccode'};
642 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
643 my $copynumber = $itm->{'copynumber'};
644 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
645 if ( defined $itm->{'location'} ) {
646 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
648 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
649 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
650 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{'description'};
652 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
653 $itemfields{$_} = 1 if ($itm->{$_});
656 # walk through the item-level authorised values and populate some images
657 my $item_authorised_value_images = C4
::Items
::get_authorised_value_images
( C4
::Items
::get_item_authorised_values
( $itm->{'itemnumber'} ) );
658 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
660 if ( $itm->{'itemlost'} ) {
661 my $lostimageinfo = List
::Util
::first
{ $_->{'category'} eq 'LOST' } @
$item_authorised_value_images;
662 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
663 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
665 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
666 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
667 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
669 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
670 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
671 $itm->{transfertwhen
} = $transfertwhen;
672 $itm->{transfertfrom
} = $branches->{$transfertfrom}{branchname
};
673 $itm->{transfertto
} = $branches->{$transfertto}{branchname
};
676 if ( C4
::Context
->preference('OPACAcquisitionDetails')
677 and C4
::Context
->preference('AcqCreateItem') eq 'ordering' )
680 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
683 my $itembranch = $itm->{$separatebranch};
684 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
685 if ($itembranch and $itembranch eq $currentbranch) {
686 push @itemloop, $itm;
688 push @otheritemloop, $itm;
691 push @itemloop, $itm;
696 # Display only one tab if one items list is empty
697 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
698 $template->param(SeparateHoldings
=> 0);
699 if (scalar(@itemloop) == 0) {
700 @itemloop = @otheritemloop;
704 ## get notes and subjects from MARC record
705 my $dbh = C4
::Context
->dbh;
706 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
707 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
708 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
709 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
710 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
711 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
712 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
713 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
716 MARCNOTES
=> $marcnotesarray,
717 MARCSUBJCTS
=> $marcsubjctsarray,
718 MARCAUTHORS
=> $marcauthorsarray,
719 MARCSERIES
=> $marcseriesarray,
720 MARCURLS
=> $marcurlsarray,
721 MARCISBNS
=> $marcisbnsarray,
722 MARCHOSTS
=> $marchostsarray,
723 norequests
=> $norequests,
724 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
725 itemdata_ccode
=> $itemfields{ccode
},
726 itemdata_enumchron
=> $itemfields{enumchron
},
727 itemdata_uri
=> $itemfields{uri
},
728 itemdata_copynumber
=> $itemfields{copynumber
},
729 itemdata_itemnotes
=> $itemfields{itemnotes
},
730 authorised_value_images
=> $biblio_authorised_value_images,
731 subtitle
=> $subtitle,
732 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
735 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
736 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
737 my $subfields = substr $fieldspec, 3;
738 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
739 my @alternateholdingsinfo = ();
740 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
742 for my $field (@holdingsfields) {
743 my %holding = ( holding
=> '' );
744 my $havesubfield = 0;
745 for my $subfield ($field->subfields()) {
746 if ((index $subfields, $$subfield[0]) >= 0) {
747 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
748 $holding{'holding'} .= $$subfield[1];
753 push(@alternateholdingsinfo, \
%holding);
758 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
762 foreach ( keys %{$dat} ) {
763 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
766 # some useful variables for enhanced content;
767 # in each case, we're grabbing the first value we find in
768 # the record and normalizing it
769 my $upc = GetNormalizedUPC
($record,$marcflavour);
770 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
771 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
772 my $content_identifier_exists;
773 if ( $isbn or $ean or $oclc or $upc ) {
774 $content_identifier_exists = 1;
777 normalized_upc
=> $upc,
778 normalized_ean
=> $ean,
779 normalized_oclc
=> $oclc,
780 normalized_isbn
=> $isbn,
781 content_identifier_exists
=> $content_identifier_exists,
784 # COinS format FIXME: for books Only
786 ocoins
=> GetCOinSBiblio
($record),
789 my $libravatar_enabled = 0;
790 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto')) {
792 require Libravatar
::URL
;
793 Libravatar
::URL
->import();
796 $libravatar_enabled = 1;
800 my $reviews = getreviews
( $biblionumber, 1 );
801 my $loggedincommenter;
806 foreach ( @
$reviews ) {
807 my $borrowerData = GetMember
('borrowernumber' => $_->{borrowernumber
});
808 # setting some borrower info into this hash
809 $_->{title
} = $borrowerData->{'title'};
810 $_->{surname
} = $borrowerData->{'surname'};
811 $_->{firstname
} = $borrowerData->{'firstname'};
812 if ($libravatar_enabled and $borrowerData->{'email'}) {
813 $_->{avatarurl
} = libravatar_url
(email
=> $borrowerData->{'email'}, https
=> $ENV{HTTPS
});
815 $_->{userid
} = $borrowerData->{'userid'};
816 $_->{cardnumber
} = $borrowerData->{'cardnumber'};
818 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
819 $_->{your_comment
} = 1;
820 $loggedincommenter = 1;
825 if(C4
::Context
->preference("ISBD")) {
826 $template->param(ISBD
=> 1);
830 itemloop
=> \
@itemloop,
831 otheritemloop
=> \
@otheritemloop,
832 subscriptionsnumber
=> $subscriptionsnumber,
833 biblionumber
=> $biblionumber,
834 subscriptions
=> \
@subs,
835 subscriptionsnumber
=> $subscriptionsnumber,
837 loggedincommenter
=> $loggedincommenter
842 if (C4
::Context
->preference("virtualshelves") ) {
843 $template->param( 'GetShelves' => GetBibliosShelves
( $biblionumber ) );
848 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
851 XISBNS
=> get_xisbns
($isbn)
854 if ($@
) { warn "XISBN Failed $@"; }
858 my @sc_fields = $record->field(955);
859 my @lc_fields = $marcflavour eq 'UNIMARC'
860 ?
$record->field(930)
861 : $record->field(852);
862 my @serialcollections = ();
864 foreach my $sc_field (@sc_fields) {
867 $row_data{text
} = $sc_field->subfield('r');
868 $row_data{branch
} = $sc_field->subfield('9');
869 foreach my $lc_field (@lc_fields) {
870 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
871 ?
$lc_field->subfield('a') # 930$a
872 : $lc_field->subfield('h') # 852$h
873 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
876 if ($row_data{text
} && $row_data{branch
}) {
877 push (@serialcollections, \
%row_data);
881 if (scalar(@serialcollections) > 0) {
883 serialcollection
=> 1,
884 serialcollections
=> \
@serialcollections);
887 # Local cover Images stuff
888 if (C4
::Context
->preference("OPACLocalCoverImages")){
889 $template->param(OPACLocalCoverImages
=> 1);
893 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
894 $template->param( C4
::HTML5Media
->gethtml5media($record));
897 my $syndetics_elements;
899 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
900 $template->param("SyndeticsEnabled" => 1);
901 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
903 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
904 for my $element (values %$syndetics_elements) {
905 $template->param("Syndetics$element"."Exists" => 1 );
906 #warn "Exists: "."Syndetics$element"."Exists";
912 if ( C4
::Context
->preference("SyndeticsEnabled")
913 && C4
::Context
->preference("SyndeticsSummary")
914 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
916 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
917 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
923 if ( C4
::Context
->preference("SyndeticsEnabled")
924 && C4
::Context
->preference("SyndeticsTOC")
925 && exists($syndetics_elements->{'TOC'}) ) {
927 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
928 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
933 if ( C4
::Context
->preference("SyndeticsEnabled")
934 && C4
::Context
->preference("SyndeticsExcerpt")
935 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
937 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
938 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
943 if ( C4
::Context
->preference("SyndeticsEnabled")
944 && C4
::Context
->preference("SyndeticsReviews")) {
946 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
947 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
952 if ( C4
::Context
->preference("SyndeticsEnabled")
953 && C4
::Context
->preference("SyndeticsAuthorNotes")
954 && exists($syndetics_elements->{'ANOTES'}) ) {
956 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
957 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
962 # LibraryThingForLibraries ID Code and Tabbed View Option
963 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
965 $template->param(LibraryThingForLibrariesID
=>
966 C4
::Context
->preference('LibraryThingForLibrariesID') );
967 $template->param(LibraryThingForLibrariesTabbedView
=>
968 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
972 if( C4
::Context
->preference('NovelistSelectEnabled') )
974 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
975 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
976 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
981 if ( C4
::Context
->preference("Babeltheque") ) {
984 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
989 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
990 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
991 $template->param( SocialNetworks
=> 1 );
994 # Shelf Browser Stuff
995 if (C4
::Context
->preference("OPACShelfBrowser")) {
996 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
997 if (defined($starting_itemnumber)) {
998 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
999 my $nearby = GetNearbyItems
($starting_itemnumber);
1002 starting_itemnumber
=> $starting_itemnumber,
1003 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1004 starting_location
=> $nearby->{starting_location
}->{description
},
1005 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1006 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1007 shelfbrowser_next_item
=> $nearby->{next_item
},
1008 shelfbrowser_items
=> $nearby->{items
},
1011 # in which tab shelf browser should open ?
1012 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1013 $template->param(shelfbrowser_tab
=> 'holdings');
1015 $template->param(shelfbrowser_tab
=> 'otherholdings');
1020 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1022 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1024 BakerTaylorEnabled
=> 1,
1025 BakerTaylorImageURL
=> &image_url
(),
1026 BakerTaylorLinkURL
=> &link_url
(),
1027 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1029 my ($bt_user, $bt_pass);
1031 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1032 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1035 BakerTaylorContentURL
=>
1036 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1037 $bt_user,$bt_pass,$isbn)
1043 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1046 TagsShowOnDetail
=> $tag_quantity,
1047 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1049 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1050 'sort'=>'-weight', limit
=>$tag_quantity}));
1053 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1054 # These values are going to be read by Javascript, at least in the case
1055 # of the google covers
1056 $template->param(covernewwindow
=> 'true');
1058 $template->param(covernewwindow
=> 'false');
1061 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1062 my $rating = GetRating
( $biblionumber, $borrowernumber );
1064 rating_value
=> $rating->{'rating_value'},
1065 rating_total
=> $rating->{'rating_total'},
1066 rating_avg
=> $rating->{'rating_avg'},
1067 rating_avg_int
=> $rating->{'rating_avg_int'},
1068 borrowernumber
=> $borrowernumber
1072 #Search for title in links
1073 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1074 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1075 my $issn = $marcissns->[0] || '';
1077 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1078 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1079 $dat->{title
} =~ s/\s+$//; # remove trailing space
1080 $search_for_title = parametrized_url
(
1083 TITLE
=> $dat->{title
},
1084 AUTHOR
=> $dat->{author
},
1087 CONTROLNUMBER
=> $marccontrolnumber,
1088 BIBLIONUMBER
=> $biblionumber,
1091 $template->param('OPACSearchForTitleIn' => $search_for_title);
1094 # We try to select the best default tab to show, according to what
1095 # the user wants, and what's available for display
1096 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1098 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1100 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1101 ?
'serialcollection' :
1102 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1104 $subscriptionsnumber
1106 @serialcollections > 0
1107 ?
'serialcollection' : 'subscriptions';
1108 $template->param('defaulttab' => $defaulttab);
1110 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1111 my @images = ListImagesForBiblio
($biblionumber);
1112 $template->{VARS
}->{localimages
} = \
@images;
1115 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1116 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1117 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1118 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1120 if (C4
::Context
->preference('OpacHighlightedWords')) {
1121 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1123 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1125 if ( C4
::Context
->preference('UseCourseReserves') ) {
1126 foreach my $i ( @items ) {
1127 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1132 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay') ,
1133 'OpacLocationBranchToDisplayShelving' => C4
::Context
->preference('OpacLocationBranchToDisplayShelving'),
1136 output_html_with_http_headers
$query, $cookie, $template->output;