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");
177 # We look for the busc param to build the simple paging from the search
178 if ($OpacBrowseResults) {
179 my $session = get_session
($query->cookie("CGISESSID"));
180 my %paging = (previous
=> {}, next => {});
181 if ($session->param('busc')) {
185 # Rebuild the string to store on session
186 # param value is URI encoded and params separator is HTML encode (&)
189 my $arrParamsBusc = shift;
191 my $pasarParams = '';
193 for (keys %$arrParamsBusc) {
194 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
195 if (defined($arrParamsBusc->{$_})) {
196 $pasarParams .= '&' if ($j);
197 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
201 for my $value (@
{$arrParamsBusc->{$_}}) {
202 next if !defined($value);
203 $pasarParams .= '&' if ($j);
204 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
212 # Search given the current values from the busc param
215 my ($arrParamsBusc, $offset, $results_per_page) = @_;
217 my $expanded_facet = $arrParamsBusc->{'expand'};
218 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
220 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
221 @servers = ("biblioserver") unless (@servers);
223 my ($default_sort_by, @sort_by);
224 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
225 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
226 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
227 my ($error, $results_hashref, $facets);
229 ($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'});
233 for (my $i=0;$i<@servers;$i++) {
234 my $server = $servers[$i];
235 $hits = $results_hashref->{$server}->{"hits"};
236 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
241 # Build the current list of biblionumbers in this search
244 my ($newresultsRef, $results_per_page) = @_;
246 my $listBiblios = '';
248 foreach (@
$newresultsRef) {
249 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
250 $listBiblios .= $bibnum . ',';
252 last if ($j == $results_per_page);
254 chop $listBiblios if ($listBiblios =~ /,$/);
258 my $busc = $session->param("busc");
259 my @arrBusc = split(/\&(?:amp;)?/, $busc);
261 my %arrParamsBusc = ();
263 ($key, $value) = split(/=/, $_, 2);
264 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
265 $arrParamsBusc{$key} = uri_unescape
($value);
267 unless (exists($arrParamsBusc{$key})) {
268 $arrParamsBusc{$key} = [];
270 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
274 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
275 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
276 $arrParamsBusc{'count'} = $results_per_page;
277 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
278 # The value OPACnumSearchResults has changed and the search has to be rebuild
279 if ($count != $results_per_page) {
280 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
282 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
283 for (@arrBibliosAux) {
284 last if ($_ == $biblionumber);
287 $indexBiblio += $offset;
288 $offset = int($indexBiblio / $count) * $count;
289 $arrParamsBusc{'offset'} = $offset;
291 $arrParamsBusc{'count'} = $count;
292 $results_per_page = $count;
293 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
294 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
295 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
296 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
297 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
298 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
299 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
300 $session->param("busc" => $newbusc);
301 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
303 my $modifyListBiblios = 0;
304 # We come from a previous click
305 if (exists($arrParamsBusc{'previous'})) {
306 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
307 delete $arrParamsBusc{'previous'};
308 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
309 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
310 delete $arrParamsBusc{'next'};
312 if ($modifyListBiblios) {
313 if (exists($arrParamsBusc{'newlistBiblios'})) {
314 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
315 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
316 my @arrAux = split(',', $listBibliosAux);
317 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
318 if ($modifyListBiblios == 1) {
319 $arrParamsBusc{'next'} = $arrAux[0];
320 $paging{'next'}->{biblionumber
} = $arrAux[0];
322 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
323 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
326 delete $arrParamsBusc{'listBiblios'};
328 my $offsetAux = $arrParamsBusc{'offset'};
329 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
330 $arrParamsBusc{'offsetSearch'} = $offsetAux;
331 $offset = $arrParamsBusc{'offset'};
332 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
333 $session->param("busc" => $newbusc);
334 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
339 # Rebuild the query for the button "back to results"
341 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
342 $buscParam .= '&' unless ($j == 0);
343 $buscParam .= $_; # string already URI encoded
347 $template->param('busc' => $buscParam);
350 # We are inside the list of biblios and we don't have to search
351 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
352 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
354 # We are at the first item of the list
355 if ($arrBiblios[0] == $biblionumber) {
356 if (@arrBiblios > 1) {
357 for (my $j = 1; $j < @arrBiblios; $j++) {
358 next unless ($arrBiblios[$j]);
359 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
363 # search again if we are not at the first searching list
364 if ($offset && !$arrParamsBusc{'previous'}) {
366 $offsetSearch = $offset - $results_per_page;
368 # we are at the last item of the list
369 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
370 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
371 next unless ($arrBiblios[$j]);
372 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
376 # search again if we are at the first list and there is more results
377 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
379 # search again if we aren't at the first list and there is more results
380 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
382 $offsetSearch = $offset + $results_per_page if ($searchAgain);
384 for (my $j = 1; $j < $#arrBiblios; $j++) {
385 if ($arrBiblios[$j] == $biblionumber) {
386 for (my $z = $j - 1; $z >= 0; $z--) {
387 next unless ($arrBiblios[$z]);
388 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
391 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
392 next unless ($arrBiblios[$z]);
393 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
401 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
404 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
405 my @newresults = @
$newresultsRef;
406 # build the new listBiblios
407 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
408 unless (exists($arrParamsBusc{'listBiblios'})) {
409 $arrParamsBusc{'listBiblios'} = $listBiblios;
410 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
412 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
414 # From the new list we build again the next and previous result
416 if ($arrBiblios[0] == $biblionumber) {
417 for (my $j = $#newresults; $j >= 0; $j--) {
418 next unless ($newresults[$j]);
419 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
420 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
421 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
424 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
425 for (my $j = 0; $j < @newresults; $j++) {
426 next unless ($newresults[$j]);
427 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
428 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
429 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
434 # build new busc param
435 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
436 $session->param("busc" => $newbusc);
438 my ($numberBiblioPaging, $dataBiblioPaging);
440 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
441 if ($numberBiblioPaging) {
442 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
443 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
444 $template->param('previousTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
447 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
448 if ($numberBiblioPaging) {
449 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
450 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
451 $template->param('nextTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
453 # Partial list of biblio results
455 for (my $j = 0; $j < @arrBiblios; $j++) {
456 next unless ($arrBiblios[$j]);
457 $dataBiblioPaging = Koha
::Biblios
->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber);
458 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]};
460 $template->param('listResults' => \
@listResults) if (@listResults);
461 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
462 $template->param( 'offset' => $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 $subscription_object = Koha
::Subscriptions
->find( $subscription->{subscriptionid
} );
593 my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
594 $cell{hasalert
} = 1 if $subscriber;
599 $dat->{'count'} = scalar(@items);
602 my (%item_reserves, %priority);
603 my ($show_holds_count, $show_priority);
604 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
605 m/holds/o and $show_holds_count = 1;
606 m/priority/ and $show_priority = 1;
609 if ( $show_holds_count || $show_priority) {
610 my $holds = $biblio->holds;
611 $template->param( holds_count
=> $holds->count );
612 while ( my $hold = $holds->next ) {
613 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
614 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
617 ?
($priority{ $hold->itemnumber } = $hold->priority)
618 : ($template->param( priority
=> $hold->priority ));
622 $template->param( show_priority
=> $has_hold ) ;
626 my (@itemloop, @otheritemloop);
627 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
628 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
629 $template->param(SeparateHoldings
=> 1);
631 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
632 my $viewallitems = $query->param('viewallitems');
633 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
636 my ( @itemnumbers_on_order );
637 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
638 my $orders = C4
::Acquisition
::SearchOrders
({
639 biblionumber
=> $biblionumber,
642 my $total_quantity = 0;
643 for my $order ( @
$orders ) {
644 my $basket = Koha
::Acquisition
::Orders
->find( $order->{ordernumber
} )->basket;
645 if ( $basket->effective_create_items eq 'ordering' ) {
646 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
647 push @itemnumbers_on_order, $itemnumber;
650 $total_quantity += $order->{quantity
};
652 $template->{VARS
}->{acquisition_details
} = {
653 total_quantity
=> $total_quantity,
657 my $allow_onshelf_holds;
658 if ( not $viewallitems and @items > $max_items_to_display ) {
661 items_count
=> scalar( @items ),
664 my $patron = Koha
::Patrons
->find( $borrowernumber );
665 for my $itm (@items) {
666 my $item = Koha
::Items
->find( $itm->{itemnumber
} );
667 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
668 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
671 && !$itm->{'withdrawn'}
672 && !$itm->{'itemlost'}
673 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
674 && !$itemtypes->{$itm->{'itype'}}->{notforloan
}
675 && $itm->{'itemnumber'};
677 $allow_onshelf_holds = Koha
::IssuingRules
->get_onshelfholds_policy( { item
=> $item, patron
=> $patron } )
678 unless $allow_onshelf_holds;
680 # get collection code description, too
681 my $ccode = $itm->{'ccode'};
682 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
683 my $copynumber = $itm->{'copynumber'};
684 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
685 if ( defined $itm->{'location'} ) {
686 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
688 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
689 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
690 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{translated_description
};
692 foreach (qw(ccode enumchron copynumber itemnotes location_description uri)) {
693 $itemfields{$_} = 1 if ($itm->{$_});
696 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
697 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
698 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
700 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
701 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
702 $itm->{transfertwhen
} = $transfertwhen;
703 $itm->{transfertfrom
} = $transfertfrom;
704 $itm->{transfertto
} = $transfertto;
707 if ( C4
::Context
->preference('OPACAcquisitionDetails') ) {
709 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
712 my $itembranch = $itm->{$separatebranch};
713 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
714 if ($itembranch and $itembranch eq $currentbranch) {
715 push @itemloop, $itm;
717 push @otheritemloop, $itm;
720 push @itemloop, $itm;
725 if( $allow_onshelf_holds || CountItemsIssued
($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
726 $template->param( ReservableItems
=> 1 );
729 # Display only one tab if one items list is empty
730 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
731 $template->param(SeparateHoldings
=> 0);
732 if (scalar(@itemloop) == 0) {
733 @itemloop = @otheritemloop;
737 ## get notes and subjects from MARC record
738 if (!C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
739 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
740 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
741 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
742 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
743 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
744 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
747 MARCSUBJCTS
=> $marcsubjctsarray,
748 MARCAUTHORS
=> $marcauthorsarray,
749 MARCSERIES
=> $marcseriesarray,
750 MARCURLS
=> $marcurlsarray,
751 MARCISBNS
=> $marcisbnsarray,
752 MARCHOSTS
=> $marchostsarray,
756 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
757 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
760 MARCNOTES
=> $marcnotesarray,
761 norequests
=> $norequests,
762 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
763 itemdata_ccode
=> $itemfields{ccode
},
764 itemdata_enumchron
=> $itemfields{enumchron
},
765 itemdata_uri
=> $itemfields{uri
},
766 itemdata_copynumber
=> $itemfields{copynumber
},
767 itemdata_itemnotes
=> $itemfields{itemnotes
},
768 itemdata_location
=> $itemfields{location_description
},
769 subtitle
=> $subtitle,
770 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
773 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
774 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
775 my $subfields = substr $fieldspec, 3;
776 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
777 my @alternateholdingsinfo = ();
778 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
780 for my $field (@holdingsfields) {
781 my %holding = ( holding
=> '' );
782 my $havesubfield = 0;
783 for my $subfield ($field->subfields()) {
784 if ((index $subfields, $$subfield[0]) >= 0) {
785 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
786 $holding{'holding'} .= $$subfield[1];
791 push(@alternateholdingsinfo, \
%holding);
796 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
800 # FIXME: The template uses this hash directly. Need to filter.
801 foreach ( keys %{$dat} ) {
802 next if ( $HideMARC->{$_} );
803 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
806 # some useful variables for enhanced content;
807 # in each case, we're grabbing the first value we find in
808 # the record and normalizing it
809 my $upc = GetNormalizedUPC
($record,$marcflavour);
810 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
811 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
812 my $content_identifier_exists;
813 if ( $isbn or $ean or $oclc or $upc ) {
814 $content_identifier_exists = 1;
817 normalized_upc
=> $upc,
818 normalized_ean
=> $ean,
819 normalized_oclc
=> $oclc,
820 normalized_isbn
=> $isbn,
821 content_identifier_exists
=> $content_identifier_exists,
824 # COinS format FIXME: for books Only
826 ocoins
=> GetCOinSBiblio
($record),
829 my ( $loggedincommenter, $reviews );
830 if ( C4
::Context
->preference('reviewson') ) {
831 $reviews = Koha
::Reviews
->search(
833 biblionumber
=> $biblionumber,
834 -or => { approved
=> 1, borrowernumber
=> $borrowernumber }
837 order_by
=> { -desc
=> 'datereviewed' }
840 my $libravatar_enabled = 0;
841 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto') ) {
843 require Libravatar
::URL
;
844 Libravatar
::URL
->import();
847 $libravatar_enabled = 1;
850 for my $review (@
$reviews) {
851 my $patron = Koha
::Patrons
->find( $review->{borrowernumber
} ); # FIXME Should be Koha::Review->reviewer or similar
853 # setting some borrower info into this hash
855 $review->{patron
} = $patron;
856 if ( $libravatar_enabled and $patron->email ) {
857 $review->{avatarurl
} = libravatar_url
( email
=> $patron->email, https
=> $ENV{HTTPS
} );
860 if ( $patron->borrowernumber eq $borrowernumber ) {
861 $loggedincommenter = 1;
867 if ( C4
::Context
->preference("OPACISBD") ) {
868 $template->param( ISBD
=> 1 );
872 itemloop
=> \
@itemloop,
873 otheritemloop
=> \
@otheritemloop,
874 biblionumber
=> $biblionumber,
875 subscriptions
=> \
@subs,
876 subscriptionsnumber
=> $subscriptionsnumber,
878 loggedincommenter
=> $loggedincommenter
882 if (C4
::Context
->preference("virtualshelves") ) {
883 my $shelves = Koha
::Virtualshelves
->search(
885 biblionumber
=> $biblionumber,
889 join => 'virtualshelfcontents',
892 $template->param( shelves
=> $shelves );
896 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
899 XISBNS
=> scalar get_xisbns
($isbn)
902 if ($@
) { warn "XISBN Failed $@"; }
906 my @sc_fields = $record->field(955);
907 my @lc_fields = $marcflavour eq 'UNIMARC'
908 ?
$record->field(930)
909 : $record->field(852);
910 my @serialcollections = ();
912 foreach my $sc_field (@sc_fields) {
915 $row_data{text
} = $sc_field->subfield('r');
916 $row_data{branch
} = $sc_field->subfield('9');
917 foreach my $lc_field (@lc_fields) {
918 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
919 ?
$lc_field->subfield('a') # 930$a
920 : $lc_field->subfield('h') # 852$h
921 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
924 if ($row_data{text
} && $row_data{branch
}) {
925 push (@serialcollections, \
%row_data);
929 if (scalar(@serialcollections) > 0) {
931 serialcollection
=> 1,
932 serialcollections
=> \
@serialcollections);
935 # Local cover Images stuff
936 if (C4
::Context
->preference("OPACLocalCoverImages")){
937 $template->param(OPACLocalCoverImages
=> 1);
941 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
942 $template->param( C4
::HTML5Media
->gethtml5media($record));
945 my $syndetics_elements;
947 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
948 $template->param("SyndeticsEnabled" => 1);
949 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
951 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
952 for my $element (values %$syndetics_elements) {
953 $template->param("Syndetics$element"."Exists" => 1 );
954 #warn "Exists: "."Syndetics$element"."Exists";
960 if ( C4
::Context
->preference("SyndeticsEnabled")
961 && C4
::Context
->preference("SyndeticsSummary")
962 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
964 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
965 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
971 if ( C4
::Context
->preference("SyndeticsEnabled")
972 && C4
::Context
->preference("SyndeticsTOC")
973 && exists($syndetics_elements->{'TOC'}) ) {
975 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
976 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
981 if ( C4
::Context
->preference("SyndeticsEnabled")
982 && C4
::Context
->preference("SyndeticsExcerpt")
983 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
985 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
986 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
991 if ( C4
::Context
->preference("SyndeticsEnabled")
992 && C4
::Context
->preference("SyndeticsReviews")) {
994 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
995 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
1000 if ( C4
::Context
->preference("SyndeticsEnabled")
1001 && C4
::Context
->preference("SyndeticsAuthorNotes")
1002 && exists($syndetics_elements->{'ANOTES'}) ) {
1004 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
1005 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
1010 # LibraryThingForLibraries ID Code and Tabbed View Option
1011 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
1013 $template->param(LibraryThingForLibrariesID
=>
1014 C4
::Context
->preference('LibraryThingForLibrariesID') );
1015 $template->param(LibraryThingForLibrariesTabbedView
=>
1016 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
1020 if( C4
::Context
->preference('NovelistSelectEnabled') )
1022 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
1023 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
1024 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
1029 if ( C4
::Context
->preference("Babeltheque") ) {
1032 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
1037 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
1038 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1039 $template->param( SocialNetworks
=> 1 );
1042 # Shelf Browser Stuff
1043 if (C4
::Context
->preference("OPACShelfBrowser")) {
1044 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1045 if (defined($starting_itemnumber)) {
1046 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
1047 my $nearby = GetNearbyItems
($starting_itemnumber);
1050 starting_itemnumber
=> $starting_itemnumber,
1051 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1052 starting_location
=> $nearby->{starting_location
}->{description
},
1053 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1054 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1055 shelfbrowser_next_item
=> $nearby->{next_item
},
1056 shelfbrowser_items
=> $nearby->{items
},
1059 # in which tab shelf browser should open ?
1060 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1061 $template->param(shelfbrowser_tab
=> 'holdings');
1063 $template->param(shelfbrowser_tab
=> 'otherholdings');
1068 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1070 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1072 BakerTaylorEnabled
=> 1,
1073 BakerTaylorImageURL
=> &image_url
(),
1074 BakerTaylorLinkURL
=> &link_url
(),
1075 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1077 my ($bt_user, $bt_pass);
1079 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1080 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1083 BakerTaylorContentURL
=>
1084 sprintf("https://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1085 $bt_user,$bt_pass,$isbn)
1091 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1094 TagsShowOnDetail
=> $tag_quantity,
1095 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1097 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1098 'sort'=>'-weight', limit
=>$tag_quantity}));
1101 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1102 # These values are going to be read by Javascript, at least in the case
1103 # of the google covers
1104 $template->param(covernewwindow
=> 'true');
1106 $template->param(covernewwindow
=> 'false');
1109 $template->param(borrowernumber
=> $borrowernumber);
1111 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1112 my $ratings = Koha
::Ratings
->search({ biblionumber
=> $biblionumber });
1113 my $my_rating = $borrowernumber ?
$ratings->search({ borrowernumber
=> $borrowernumber })->next : undef;
1115 ratings
=> $ratings,
1116 my_rating
=> $my_rating,
1120 #Search for title in links
1121 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1122 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1123 my $issn = $marcissns->[0] || '';
1125 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1126 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1127 $dat->{title
} =~ s/\s+$//; # remove trailing space
1128 $search_for_title = parametrized_url
(
1131 TITLE
=> $dat->{title
},
1132 AUTHOR
=> $dat->{author
},
1135 CONTROLNUMBER
=> $marccontrolnumber,
1136 BIBLIONUMBER
=> $biblionumber,
1139 $template->param('OPACSearchForTitleIn' => $search_for_title);
1143 if ( C4
::Context
->preference("IDREF") ) {
1144 # If the record comes from the SUDOC
1145 if ( $record->field('009') ) {
1146 my $unimarc3 = $record->field("009")->data;
1147 if ( $unimarc3 =~ /^\d+$/ ) {
1155 # We try to select the best default tab to show, according to what
1156 # the user wants, and what's available for display
1157 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1161 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1163 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1164 ?
'serialcollection' :
1165 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1167 scalar (@itemloop) == 0
1169 $subscriptionsnumber
1171 @serialcollections > 0
1172 ?
'serialcollection' : 'subscriptions';
1173 $template->param('defaulttab' => $defaulttab);
1175 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1176 my @images = ListImagesForBiblio
($biblionumber);
1177 $template->{VARS
}->{localimages
} = \
@images;
1180 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1181 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1182 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1183 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1185 if (C4
::Context
->preference('OpacHighlightedWords')) {
1186 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1188 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1190 if ( C4
::Context
->preference('UseCourseReserves') ) {
1191 foreach my $i ( @items ) {
1192 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1197 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay'),
1200 output_html_with_http_headers
$query, $cookie, $template->output;