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>.
26 use C4
::Acquisition
qw( SearchOrders );
27 use C4
::Auth
qw(:DEFAULT get_session);
29 use C4
::Serials
; #uses getsubscriptionfrom biblionumber
34 use C4
::Tags
qw(get_tags);
35 use C4
::XISBN
qw(get_xisbns);
36 use C4
::External
::Amazon
;
37 use C4
::External
::Syndetics
qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
46 use List
::MoreUtils qw
/any none/;
50 use C4
::CourseReserves
qw(GetItemCourseReservesInfo);
53 use Koha
::RecordProcessor
;
54 use Koha
::AuthorisedValues
;
55 use Koha
::IssuingRules
;
58 use Koha
::Acquisition
::Orders
;
59 use Koha
::Virtualshelves
;
65 if (C4
::Context
->preference('BakerTaylorEnabled')) {
66 require C4
::External
::BakerTaylor
;
67 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
72 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
74 template_name
=> "opac-detail.tt",
77 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
81 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
82 $biblionumber = int($biblionumber);
84 my @all_items = GetItemsInfo
($biblionumber);
86 if (scalar @all_items >= 1) {
87 push @hiddenitems, GetHiddenItemnumbers
(@all_items);
89 if (scalar @hiddenitems == scalar @all_items ) {
90 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
95 my $record = GetMarcBiblio
({ biblionumber
=> $biblionumber });
97 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
101 my $biblio = Koha
::Biblios
->find( $biblionumber );
102 my $framework = &GetFrameworkCode
( $biblionumber );
103 my $record_processor = Koha
::RecordProcessor
->new({
104 filters
=> 'ViewPolicy',
107 frameworkcode
=> $framework
110 $record_processor->process($record);
112 # redirect if opacsuppression is enabled and biblio is suppressed
113 if (C4
::Context
->preference('OpacSuppression')) {
114 # FIXME hardcoded; the suppression flag ought to be materialized
115 # as a column on biblio or the like
116 my $opacsuppressionfield = '942';
117 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
118 # redirect to opac-blocked info page or 404?
119 my $opacsuppressionredirect;
120 if ( C4
::Context
->preference("OpacSuppressionRedirect") ) {
121 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
123 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
125 if ( $opacsuppressionfieldvalue &&
126 $opacsuppressionfieldvalue->subfield("n") &&
127 $opacsuppressionfieldvalue->subfield("n") == 1) {
128 # if OPAC suppression by IP address
129 if (C4
::Context
->preference('OpacSuppressionByIPRange')) {
130 my $IPAddress = $ENV{'REMOTE_ADDR'};
131 my $IPRange = C4
::Context
->preference('OpacSuppressionByIPRange');
132 if ($IPAddress !~ /^$IPRange/) {
133 print $query->redirect($opacsuppressionredirect);
137 print $query->redirect($opacsuppressionredirect);
143 $template->param( biblio
=> $biblio );
145 # get biblionumbers stored in the cart
148 if($query->cookie("bib_list")){
149 my $cart_list = $query->cookie("bib_list");
150 @cart_list = split(/\//, $cart_list);
151 if ( grep {$_ eq $biblionumber} @cart_list) {
152 $template->param( incart
=> 1 );
157 SetUTF8Flag
($record);
158 my $marcflavour = C4
::Context
->preference("marcflavour");
159 my $ean = GetNormalizedEAN
( $record, $marcflavour );
161 # XSLT processing of some stuff
162 my $xslfile = C4
::Context
->preference('OPACXSLTDetailsDisplay');
163 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
164 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
168 XSLTBloc
=> XSLTParse4Display
(
169 $biblionumber, $record, "OPACXSLTDetailsDisplay",
170 1, undef, $sysxml, $xslfile, $lang
175 my $OpacBrowseResults = C4
::Context
->preference("OpacBrowseResults");
176 $template->{VARS
}->{'OpacBrowseResults'} = $OpacBrowseResults;
178 # We look for the busc param to build the simple paging from the search
179 if ($OpacBrowseResults) {
180 my $session = get_session
($query->cookie("CGISESSID"));
181 my %paging = (previous
=> {}, next => {});
182 if ($session->param('busc')) {
186 # Rebuild the string to store on session
187 # param value is URI encoded and params separator is HTML encode (&)
190 my $arrParamsBusc = shift;
192 my $pasarParams = '';
194 for (keys %$arrParamsBusc) {
195 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
196 if (defined($arrParamsBusc->{$_})) {
197 $pasarParams .= '&' if ($j);
198 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
202 for my $value (@
{$arrParamsBusc->{$_}}) {
203 next if !defined($value);
204 $pasarParams .= '&' if ($j);
205 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
213 # Search given the current values from the busc param
216 my ($arrParamsBusc, $offset, $results_per_page) = @_;
218 my $expanded_facet = $arrParamsBusc->{'expand'};
219 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
221 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
222 @servers = ("biblioserver") unless (@servers);
224 my ($default_sort_by, @sort_by);
225 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
226 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
227 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
228 my ($error, $results_hashref, $facets);
230 ($error, $results_hashref, $facets) = getRecords
($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\
@sort_by,\
@servers,$results_per_page,$offset,$expanded_facet,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
234 for (my $i=0;$i<@servers;$i++) {
235 my $server = $servers[$i];
236 $hits = $results_hashref->{$server}->{"hits"};
237 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
242 # Build the current list of biblionumbers in this search
245 my ($newresultsRef, $results_per_page) = @_;
247 my $listBiblios = '';
249 foreach (@
$newresultsRef) {
250 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
251 $listBiblios .= $bibnum . ',';
253 last if ($j == $results_per_page);
255 chop $listBiblios if ($listBiblios =~ /,$/);
259 my $busc = $session->param("busc");
260 my @arrBusc = split(/\&(?:amp;)?/, $busc);
262 my %arrParamsBusc = ();
264 ($key, $value) = split(/=/, $_, 2);
265 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
266 $arrParamsBusc{$key} = uri_unescape
($value);
268 unless (exists($arrParamsBusc{$key})) {
269 $arrParamsBusc{$key} = [];
271 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
275 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
276 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
277 $arrParamsBusc{'count'} = $results_per_page;
278 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
279 # The value OPACnumSearchResults has changed and the search has to be rebuild
280 if ($count != $results_per_page) {
281 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
283 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
284 for (@arrBibliosAux) {
285 last if ($_ == $biblionumber);
288 $indexBiblio += $offset;
289 $offset = int($indexBiblio / $count) * $count;
290 $arrParamsBusc{'offset'} = $offset;
292 $arrParamsBusc{'count'} = $count;
293 $results_per_page = $count;
294 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
295 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
296 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
297 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
298 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
299 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
300 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
301 $session->param("busc" => $newbusc);
302 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
304 my $modifyListBiblios = 0;
305 # We come from a previous click
306 if (exists($arrParamsBusc{'previous'})) {
307 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
308 delete $arrParamsBusc{'previous'};
309 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
310 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
311 delete $arrParamsBusc{'next'};
313 if ($modifyListBiblios) {
314 if (exists($arrParamsBusc{'newlistBiblios'})) {
315 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
316 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
317 my @arrAux = split(',', $listBibliosAux);
318 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
319 if ($modifyListBiblios == 1) {
320 $arrParamsBusc{'next'} = $arrAux[0];
321 $paging{'next'}->{biblionumber
} = $arrAux[0];
323 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
324 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
327 delete $arrParamsBusc{'listBiblios'};
329 my $offsetAux = $arrParamsBusc{'offset'};
330 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
331 $arrParamsBusc{'offsetSearch'} = $offsetAux;
332 $offset = $arrParamsBusc{'offset'};
333 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
334 $session->param("busc" => $newbusc);
335 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
340 # Rebuild the query for the button "back to results"
342 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
343 $buscParam .= '&' unless ($j == 0);
344 $buscParam .= $_; # string already URI encoded
348 $template->param('busc' => $buscParam);
351 # We are inside the list of biblios and we don't have to search
352 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
353 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
355 # We are at the first item of the list
356 if ($arrBiblios[0] == $biblionumber) {
357 if (@arrBiblios > 1) {
358 for (my $j = 1; $j < @arrBiblios; $j++) {
359 next unless ($arrBiblios[$j]);
360 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
364 # search again if we are not at the first searching list
365 if ($offset && !$arrParamsBusc{'previous'}) {
367 $offsetSearch = $offset - $results_per_page;
369 # we are at the last item of the list
370 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
371 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
372 next unless ($arrBiblios[$j]);
373 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
377 # search again if we are at the first list and there is more results
378 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
380 # search again if we aren't at the first list and there is more results
381 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
383 $offsetSearch = $offset + $results_per_page if ($searchAgain);
385 for (my $j = 1; $j < $#arrBiblios; $j++) {
386 if ($arrBiblios[$j] == $biblionumber) {
387 for (my $z = $j - 1; $z >= 0; $z--) {
388 next unless ($arrBiblios[$z]);
389 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
392 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
393 next unless ($arrBiblios[$z]);
394 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
402 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
405 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
406 my @newresults = @
$newresultsRef;
407 # build the new listBiblios
408 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
409 unless (exists($arrParamsBusc{'listBiblios'})) {
410 $arrParamsBusc{'listBiblios'} = $listBiblios;
411 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
413 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
415 # From the new list we build again the next and previous result
417 if ($arrBiblios[0] == $biblionumber) {
418 for (my $j = $#newresults; $j >= 0; $j--) {
419 next unless ($newresults[$j]);
420 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
421 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
422 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
425 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
426 for (my $j = 0; $j < @newresults; $j++) {
427 next unless ($newresults[$j]);
428 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
429 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
430 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
435 # build new busc param
436 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
437 $session->param("busc" => $newbusc);
439 my ($numberBiblioPaging, $dataBiblioPaging);
441 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
442 if ($numberBiblioPaging) {
443 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
444 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
445 $template->param('previousTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
448 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
449 if ($numberBiblioPaging) {
450 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
451 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
452 $template->param('nextTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
454 # Partial list of biblio results
456 for (my $j = 0; $j < @arrBiblios; $j++) {
457 next unless ($arrBiblios[$j]);
458 $dataBiblioPaging = Koha
::Biblios
->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber);
459 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]};
461 $template->param('listResults' => \
@listResults) if (@listResults);
462 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
467 OPACShowCheckoutName
=> C4
::Context
->preference("OPACShowCheckoutName"),
470 # adding items linked via host biblios
472 my $analyticfield = '773';
473 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
474 $analyticfield = '773';
475 } elsif ($marcflavour eq 'UNIMARC') {
476 $analyticfield = '461';
478 foreach my $hostfield ( $record->field($analyticfield)) {
479 my $hostbiblionumber = $hostfield->subfield("0");
480 my $linkeditemnumber = $hostfield->subfield("9");
481 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
482 foreach my $hostitemInfo (@hostitemInfos){
483 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
484 push(@all_items, $hostitemInfo);
491 # Are there items to hide?
493 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
497 for my $itm (@all_items) {
498 if ( C4
::Context
->preference('hidelostitems') ) {
499 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
501 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
510 if (C4
::Context
->userenv){
511 $branch = C4
::Context
->userenv->{branch
};
513 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
515 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
517 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
520 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
521 $branchcode = $branch;
523 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
524 $branchcode = $ENV{'BRANCHCODE'};
530 foreach my $item ( @items ) {
531 if ( $item->{branchcode
} eq $branchcode ) {
532 $item->{'this_branch'} = 1;
533 push( @our_items, $item );
535 push( @other_items, $item );
539 @items = ( @our_items, @other_items );
543 my $dat = &GetBiblioData
($biblionumber);
544 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
546 frameworkcode
=> $dat->{'frameworkcode'},
550 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
552 my $itemtype = $dat->{'itemtype'};
554 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
555 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description
};
559 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.location' } ) };
561 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.ccode' } ) };
563 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.copynumber' } ) };
565 #coping with subscriptions
566 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
567 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
570 $dat->{'serial'}=1 if $subscriptionsnumber;
571 foreach my $subscription (@subscriptions) {
572 my $serials_to_display;
574 $cell{subscriptionid
} = $subscription->{subscriptionid
};
575 $cell{subscriptionnotes
} = $subscription->{notes
};
576 $cell{missinglist
} = $subscription->{missinglist
};
577 $cell{opacnote
} = $subscription->{opacnote
};
578 $cell{histstartdate
} = $subscription->{histstartdate
};
579 $cell{histenddate
} = $subscription->{histenddate
};
580 $cell{branchcode
} = $subscription->{branchcode
};
581 $cell{callnumber
} = $subscription->{callnumber
};
582 $cell{closed
} = $subscription->{closed
};
583 $cell{letter
} = $subscription->{letter
};
584 $cell{biblionumber
} = $subscription->{biblionumber
};
585 #get the three latest serials.
586 $serials_to_display = $subscription->{opacdisplaycount
};
587 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
588 $cell{opacdisplaycount
} = $serials_to_display;
589 $cell{latestserials
} =
590 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
591 if ( $borrowernumber ) {
592 my $sub = getalert
($borrowernumber,'issue',$subscription->{subscriptionid
});
600 $dat->{'count'} = scalar(@items);
603 my (%item_reserves, %priority);
604 my ($show_holds_count, $show_priority);
605 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
606 m/holds/o and $show_holds_count = 1;
607 m/priority/ and $show_priority = 1;
610 if ( $show_holds_count || $show_priority) {
611 my $holds = $biblio->holds;
612 $template->param( holds_count
=> $holds->count );
613 while ( my $hold = $holds->next ) {
614 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
615 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
618 ?
($priority{ $hold->itemnumber } = $hold->priority)
619 : ($template->param( priority
=> $hold->priority ));
623 $template->param( show_priority
=> $has_hold ) ;
627 my (@itemloop, @otheritemloop);
628 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
629 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
630 $template->param(SeparateHoldings
=> 1);
632 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
633 my $viewallitems = $query->param('viewallitems');
634 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
637 my ( @itemnumbers_on_order );
638 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
639 my $orders = C4
::Acquisition
::SearchOrders
({
640 biblionumber
=> $biblionumber,
643 my $total_quantity = 0;
644 for my $order ( @
$orders ) {
645 my $basket = Koha
::Acquisition
::Orders
->find( $order->{ordernumber
} )->basket;
646 if ( $basket->effective_create_items eq 'ordering' ) {
647 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
648 push @itemnumbers_on_order, $itemnumber;
651 $total_quantity += $order->{quantity
};
653 $template->{VARS
}->{acquisition_details
} = {
654 total_quantity
=> $total_quantity,
658 my $allow_onshelf_holds;
659 if ( not $viewallitems and @items > $max_items_to_display ) {
662 items_count
=> scalar( @items ),
665 my $patron = Koha
::Patrons
->find( $borrowernumber );
666 for my $itm (@items) {
667 my $item = Koha
::Items
->find( $itm->{itemnumber
} );
668 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
669 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
672 && !$itm->{'withdrawn'}
673 && !$itm->{'itemlost'}
674 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
675 && !$itemtypes->{$itm->{'itype'}}->{notforloan
}
676 && $itm->{'itemnumber'};
678 $allow_onshelf_holds = Koha
::IssuingRules
->get_onshelfholds_policy( { item
=> $item, patron
=> $patron } )
679 unless $allow_onshelf_holds;
681 # get collection code description, too
682 my $ccode = $itm->{'ccode'};
683 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
684 my $copynumber = $itm->{'copynumber'};
685 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
686 if ( defined $itm->{'location'} ) {
687 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
689 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
690 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
691 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{translated_description
};
693 foreach (qw(ccode enumchron copynumber itemnotes location_description uri)) {
694 $itemfields{$_} = 1 if ($itm->{$_});
697 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
698 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
699 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
701 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
702 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
703 $itm->{transfertwhen
} = $transfertwhen;
704 $itm->{transfertfrom
} = $transfertfrom;
705 $itm->{transfertto
} = $transfertto;
708 if ( C4
::Context
->preference('OPACAcquisitionDetails') ) {
710 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
713 my $itembranch = $itm->{$separatebranch};
714 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
715 if ($itembranch and $itembranch eq $currentbranch) {
716 push @itemloop, $itm;
718 push @otheritemloop, $itm;
721 push @itemloop, $itm;
726 if( $allow_onshelf_holds || CountItemsIssued
($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
727 $template->param( ReservableItems
=> 1 );
730 # Display only one tab if one items list is empty
731 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
732 $template->param(SeparateHoldings
=> 0);
733 if (scalar(@itemloop) == 0) {
734 @itemloop = @otheritemloop;
738 ## get notes and subjects from MARC record
739 if (!C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
740 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
741 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
742 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
743 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
744 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
745 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
748 MARCSUBJCTS
=> $marcsubjctsarray,
749 MARCAUTHORS
=> $marcauthorsarray,
750 MARCSERIES
=> $marcseriesarray,
751 MARCURLS
=> $marcurlsarray,
752 MARCISBNS
=> $marcisbnsarray,
753 MARCHOSTS
=> $marchostsarray,
757 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
758 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
761 MARCNOTES
=> $marcnotesarray,
762 norequests
=> $norequests,
763 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
764 itemdata_ccode
=> $itemfields{ccode
},
765 itemdata_enumchron
=> $itemfields{enumchron
},
766 itemdata_uri
=> $itemfields{uri
},
767 itemdata_copynumber
=> $itemfields{copynumber
},
768 itemdata_itemnotes
=> $itemfields{itemnotes
},
769 itemdata_location
=> $itemfields{location_description
},
770 subtitle
=> $subtitle,
771 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
774 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
775 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
776 my $subfields = substr $fieldspec, 3;
777 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
778 my @alternateholdingsinfo = ();
779 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
781 for my $field (@holdingsfields) {
782 my %holding = ( holding
=> '' );
783 my $havesubfield = 0;
784 for my $subfield ($field->subfields()) {
785 if ((index $subfields, $$subfield[0]) >= 0) {
786 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
787 $holding{'holding'} .= $$subfield[1];
792 push(@alternateholdingsinfo, \
%holding);
797 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
801 # FIXME: The template uses this hash directly. Need to filter.
802 foreach ( keys %{$dat} ) {
803 next if ( $HideMARC->{$_} );
804 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
807 # some useful variables for enhanced content;
808 # in each case, we're grabbing the first value we find in
809 # the record and normalizing it
810 my $upc = GetNormalizedUPC
($record,$marcflavour);
811 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
812 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
813 my $content_identifier_exists;
814 if ( $isbn or $ean or $oclc or $upc ) {
815 $content_identifier_exists = 1;
818 normalized_upc
=> $upc,
819 normalized_ean
=> $ean,
820 normalized_oclc
=> $oclc,
821 normalized_isbn
=> $isbn,
822 content_identifier_exists
=> $content_identifier_exists,
825 # COinS format FIXME: for books Only
827 ocoins
=> GetCOinSBiblio
($record),
830 my ( $loggedincommenter, $reviews );
831 if ( C4
::Context
->preference('reviewson') ) {
832 $reviews = Koha
::Reviews
->search(
834 biblionumber
=> $biblionumber,
835 -or => { approved
=> 1, borrowernumber
=> $borrowernumber }
838 order_by
=> { -desc
=> 'datereviewed' }
841 my $libravatar_enabled = 0;
842 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto') ) {
844 require Libravatar
::URL
;
845 Libravatar
::URL
->import();
848 $libravatar_enabled = 1;
851 for my $review (@
$reviews) {
852 my $patron = Koha
::Patrons
->find( $review->{borrowernumber
} ); # FIXME Should be Koha::Review->reviewer or similar
854 # setting some borrower info into this hash
856 $review->{patron
} = $patron;
857 if ( $libravatar_enabled and $patron->email ) {
858 $review->{avatarurl
} = libravatar_url
( email
=> $patron->email, https
=> $ENV{HTTPS
} );
861 if ( $patron->borrowernumber eq $borrowernumber ) {
862 $loggedincommenter = 1;
868 if ( C4
::Context
->preference("OPACISBD") ) {
869 $template->param( ISBD
=> 1 );
873 itemloop
=> \
@itemloop,
874 otheritemloop
=> \
@otheritemloop,
875 biblionumber
=> $biblionumber,
876 subscriptions
=> \
@subs,
877 subscriptionsnumber
=> $subscriptionsnumber,
879 loggedincommenter
=> $loggedincommenter
883 if (C4
::Context
->preference("virtualshelves") ) {
884 my $shelves = Koha
::Virtualshelves
->search(
886 biblionumber
=> $biblionumber,
890 join => 'virtualshelfcontents',
893 $template->param( shelves
=> $shelves );
897 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
900 XISBNS
=> scalar get_xisbns
($isbn)
903 if ($@
) { warn "XISBN Failed $@"; }
907 my @sc_fields = $record->field(955);
908 my @lc_fields = $marcflavour eq 'UNIMARC'
909 ?
$record->field(930)
910 : $record->field(852);
911 my @serialcollections = ();
913 foreach my $sc_field (@sc_fields) {
916 $row_data{text
} = $sc_field->subfield('r');
917 $row_data{branch
} = $sc_field->subfield('9');
918 foreach my $lc_field (@lc_fields) {
919 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
920 ?
$lc_field->subfield('a') # 930$a
921 : $lc_field->subfield('h') # 852$h
922 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
925 if ($row_data{text
} && $row_data{branch
}) {
926 push (@serialcollections, \
%row_data);
930 if (scalar(@serialcollections) > 0) {
932 serialcollection
=> 1,
933 serialcollections
=> \
@serialcollections);
936 # Local cover Images stuff
937 if (C4
::Context
->preference("OPACLocalCoverImages")){
938 $template->param(OPACLocalCoverImages
=> 1);
942 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
943 $template->param( C4
::HTML5Media
->gethtml5media($record));
946 my $syndetics_elements;
948 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
949 $template->param("SyndeticsEnabled" => 1);
950 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
952 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
953 for my $element (values %$syndetics_elements) {
954 $template->param("Syndetics$element"."Exists" => 1 );
955 #warn "Exists: "."Syndetics$element"."Exists";
961 if ( C4
::Context
->preference("SyndeticsEnabled")
962 && C4
::Context
->preference("SyndeticsSummary")
963 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
965 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
966 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
972 if ( C4
::Context
->preference("SyndeticsEnabled")
973 && C4
::Context
->preference("SyndeticsTOC")
974 && exists($syndetics_elements->{'TOC'}) ) {
976 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
977 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
982 if ( C4
::Context
->preference("SyndeticsEnabled")
983 && C4
::Context
->preference("SyndeticsExcerpt")
984 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
986 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
987 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
992 if ( C4
::Context
->preference("SyndeticsEnabled")
993 && C4
::Context
->preference("SyndeticsReviews")) {
995 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
996 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
1001 if ( C4
::Context
->preference("SyndeticsEnabled")
1002 && C4
::Context
->preference("SyndeticsAuthorNotes")
1003 && exists($syndetics_elements->{'ANOTES'}) ) {
1005 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
1006 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
1011 # LibraryThingForLibraries ID Code and Tabbed View Option
1012 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
1014 $template->param(LibraryThingForLibrariesID
=>
1015 C4
::Context
->preference('LibraryThingForLibrariesID') );
1016 $template->param(LibraryThingForLibrariesTabbedView
=>
1017 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
1021 if( C4
::Context
->preference('NovelistSelectEnabled') )
1023 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
1024 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
1025 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
1030 if ( C4
::Context
->preference("Babeltheque") ) {
1033 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
1038 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
1039 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1040 $template->param( SocialNetworks
=> 1 );
1043 # Shelf Browser Stuff
1044 if (C4
::Context
->preference("OPACShelfBrowser")) {
1045 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1046 if (defined($starting_itemnumber)) {
1047 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
1048 my $nearby = GetNearbyItems
($starting_itemnumber);
1051 starting_itemnumber
=> $starting_itemnumber,
1052 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1053 starting_location
=> $nearby->{starting_location
}->{description
},
1054 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1055 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1056 shelfbrowser_next_item
=> $nearby->{next_item
},
1057 shelfbrowser_items
=> $nearby->{items
},
1060 # in which tab shelf browser should open ?
1061 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1062 $template->param(shelfbrowser_tab
=> 'holdings');
1064 $template->param(shelfbrowser_tab
=> 'otherholdings');
1069 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1071 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1073 BakerTaylorEnabled
=> 1,
1074 BakerTaylorImageURL
=> &image_url
(),
1075 BakerTaylorLinkURL
=> &link_url
(),
1076 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1078 my ($bt_user, $bt_pass);
1080 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1081 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1084 BakerTaylorContentURL
=>
1085 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1086 $bt_user,$bt_pass,$isbn)
1092 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1095 TagsShowOnDetail
=> $tag_quantity,
1096 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1098 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1099 'sort'=>'-weight', limit
=>$tag_quantity}));
1102 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1103 # These values are going to be read by Javascript, at least in the case
1104 # of the google covers
1105 $template->param(covernewwindow
=> 'true');
1107 $template->param(covernewwindow
=> 'false');
1110 $template->param(borrowernumber
=> $borrowernumber);
1112 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1113 my $ratings = Koha
::Ratings
->search({ biblionumber
=> $biblionumber });
1114 my $my_rating = $borrowernumber ?
$ratings->search({ borrowernumber
=> $borrowernumber })->next : undef;
1116 ratings
=> $ratings,
1117 my_rating
=> $my_rating,
1121 #Search for title in links
1122 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1123 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1124 my $issn = $marcissns->[0] || '';
1126 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1127 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1128 $dat->{title
} =~ s/\s+$//; # remove trailing space
1129 $search_for_title = parametrized_url
(
1132 TITLE
=> $dat->{title
},
1133 AUTHOR
=> $dat->{author
},
1136 CONTROLNUMBER
=> $marccontrolnumber,
1137 BIBLIONUMBER
=> $biblionumber,
1140 $template->param('OPACSearchForTitleIn' => $search_for_title);
1144 if ( C4
::Context
->preference("IDREF") ) {
1145 # If the record comes from the SUDOC
1146 if ( $record->field('009') ) {
1147 my $unimarc3 = $record->field("009")->data;
1148 if ( $unimarc3 =~ /^\d+$/ ) {
1156 # We try to select the best default tab to show, according to what
1157 # the user wants, and what's available for display
1158 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1162 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1164 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1165 ?
'serialcollection' :
1166 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1168 scalar (@itemloop) == 0
1170 $subscriptionsnumber
1172 @serialcollections > 0
1173 ?
'serialcollection' : 'subscriptions';
1174 $template->param('defaulttab' => $defaulttab);
1176 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1177 my @images = ListImagesForBiblio
($biblionumber);
1178 $template->{VARS
}->{localimages
} = \
@images;
1181 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1182 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1183 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1184 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1186 if (C4
::Context
->preference('OpacHighlightedWords')) {
1187 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1189 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1191 if ( C4
::Context
->preference('UseCourseReserves') ) {
1192 foreach my $i ( @items ) {
1193 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1198 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay'),
1201 output_html_with_http_headers
$query, $cookie, $template->output;