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 get_biblionumber_from_isbn);
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);
51 use Koha
::RecordProcessor
;
52 use Koha
::AuthorisedValues
;
55 use Koha
::Virtualshelves
;
60 if (C4
::Context
->preference('BakerTaylorEnabled')) {
61 require C4
::External
::BakerTaylor
;
62 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
67 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
69 template_name
=> "opac-detail.tt",
72 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
76 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
77 $biblionumber = int($biblionumber);
79 my @all_items = GetItemsInfo
($biblionumber);
81 if (scalar @all_items >= 1) {
82 push @hiddenitems, GetHiddenItemnumbers
(@all_items);
84 if (scalar @hiddenitems == scalar @all_items ) {
85 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90 my $record = GetMarcBiblio
($biblionumber);
92 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
95 my $framework = &GetFrameworkCode
( $biblionumber );
96 my $record_processor = Koha
::RecordProcessor
->new({
97 filters
=> 'ViewPolicy',
100 frameworkcode
=> $framework
103 $record_processor->process($record);
105 # redirect if opacsuppression is enabled and biblio is suppressed
106 if (C4
::Context
->preference('OpacSuppression')) {
107 # FIXME hardcoded; the suppression flag ought to be materialized
108 # as a column on biblio or the like
109 my $opacsuppressionfield = '942';
110 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
111 # redirect to opac-blocked info page or 404?
112 my $opacsuppressionredirect;
113 if ( C4
::Context
->preference("OpacSuppressionRedirect") ) {
114 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
116 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
118 if ( $opacsuppressionfieldvalue &&
119 $opacsuppressionfieldvalue->subfield("n") &&
120 $opacsuppressionfieldvalue->subfield("n") == 1) {
121 # if OPAC suppression by IP address
122 if (C4
::Context
->preference('OpacSuppressionByIPRange')) {
123 my $IPAddress = $ENV{'REMOTE_ADDR'};
124 my $IPRange = C4
::Context
->preference('OpacSuppressionByIPRange');
125 if ($IPAddress !~ /^$IPRange/) {
126 print $query->redirect($opacsuppressionredirect);
130 print $query->redirect($opacsuppressionredirect);
136 $template->param( biblionumber
=> $biblionumber );
138 # get biblionumbers stored in the cart
141 if($query->cookie("bib_list")){
142 my $cart_list = $query->cookie("bib_list");
143 @cart_list = split(/\//, $cart_list);
144 if ( grep {$_ eq $biblionumber} @cart_list) {
145 $template->param( incart
=> 1 );
150 SetUTF8Flag
($record);
151 my $marcflavour = C4
::Context
->preference("marcflavour");
152 my $ean = GetNormalizedEAN
( $record, $marcflavour );
154 # XSLT processing of some stuff
155 my $xslfile = C4
::Context
->preference('OPACXSLTDetailsDisplay');
156 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
157 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
161 XSLTBloc
=> XSLTParse4Display
(
162 $biblionumber, $record, "OPACXSLTDetailsDisplay",
163 1, undef, $sysxml, $xslfile, $lang
168 my $OpacBrowseResults = C4
::Context
->preference("OpacBrowseResults");
169 $template->{VARS
}->{'OpacBrowseResults'} = $OpacBrowseResults;
171 # We look for the busc param to build the simple paging from the search
172 if ($OpacBrowseResults) {
173 my $session = get_session
($query->cookie("CGISESSID"));
174 my %paging = (previous
=> {}, next => {});
175 if ($session->param('busc')) {
179 # Rebuild the string to store on session
180 # param value is URI encoded and params separator is HTML encode (&)
183 my $arrParamsBusc = shift;
185 my $pasarParams = '';
187 for (keys %$arrParamsBusc) {
188 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
189 if (defined($arrParamsBusc->{$_})) {
190 $pasarParams .= '&' if ($j);
191 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
195 for my $value (@
{$arrParamsBusc->{$_}}) {
196 $pasarParams .= '&' if ($j);
197 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
205 # Search given the current values from the busc param
208 my ($arrParamsBusc, $offset, $results_per_page) = @_;
210 my $expanded_facet = $arrParamsBusc->{'expand'};
211 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
213 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
214 @servers = ("biblioserver") unless (@servers);
216 my ($default_sort_by, @sort_by);
217 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
218 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
219 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
220 my ($error, $results_hashref, $facets);
222 ($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'});
226 for (my $i=0;$i<@servers;$i++) {
227 my $server = $servers[$i];
228 $hits = $results_hashref->{$server}->{"hits"};
229 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
234 # Build the current list of biblionumbers in this search
237 my ($newresultsRef, $results_per_page) = @_;
239 my $listBiblios = '';
241 foreach (@
$newresultsRef) {
242 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
243 $listBiblios .= $bibnum . ',';
245 last if ($j == $results_per_page);
247 chop $listBiblios if ($listBiblios =~ /,$/);
251 my $busc = $session->param("busc");
252 my @arrBusc = split(/\&(?:amp;)?/, $busc);
254 my %arrParamsBusc = ();
256 ($key, $value) = split(/=/, $_, 2);
257 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
258 $arrParamsBusc{$key} = uri_unescape
($value);
260 unless (exists($arrParamsBusc{$key})) {
261 $arrParamsBusc{$key} = [];
263 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
267 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
268 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
269 $arrParamsBusc{'count'} = $results_per_page;
270 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
271 # The value OPACnumSearchResults has changed and the search has to be rebuild
272 if ($count != $results_per_page) {
273 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
275 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
276 for (@arrBibliosAux) {
277 last if ($_ == $biblionumber);
280 $indexBiblio += $offset;
281 $offset = int($indexBiblio / $count) * $count;
282 $arrParamsBusc{'offset'} = $offset;
284 $arrParamsBusc{'count'} = $count;
285 $results_per_page = $count;
286 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
287 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
288 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
289 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
290 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
291 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
292 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
293 $session->param("busc" => $newbusc);
294 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
296 my $modifyListBiblios = 0;
297 # We come from a previous click
298 if (exists($arrParamsBusc{'previous'})) {
299 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
300 delete $arrParamsBusc{'previous'};
301 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
302 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
303 delete $arrParamsBusc{'next'};
305 if ($modifyListBiblios) {
306 if (exists($arrParamsBusc{'newlistBiblios'})) {
307 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
308 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
309 my @arrAux = split(',', $listBibliosAux);
310 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
311 if ($modifyListBiblios == 1) {
312 $arrParamsBusc{'next'} = $arrAux[0];
313 $paging{'next'}->{biblionumber
} = $arrAux[0];
315 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
316 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
319 delete $arrParamsBusc{'listBiblios'};
321 my $offsetAux = $arrParamsBusc{'offset'};
322 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
323 $arrParamsBusc{'offsetSearch'} = $offsetAux;
324 $offset = $arrParamsBusc{'offset'};
325 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
326 $session->param("busc" => $newbusc);
327 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
332 # Rebuild the query for the button "back to results"
334 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
335 $buscParam .= '&' unless ($j == 0);
336 $buscParam .= $_; # string already URI encoded
340 $template->param('busc' => $buscParam);
343 # We are inside the list of biblios and we don't have to search
344 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
345 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
347 # We are at the first item of the list
348 if ($arrBiblios[0] == $biblionumber) {
349 if (@arrBiblios > 1) {
350 for (my $j = 1; $j < @arrBiblios; $j++) {
351 next unless ($arrBiblios[$j]);
352 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
356 # search again if we are not at the first searching list
357 if ($offset && !$arrParamsBusc{'previous'}) {
359 $offsetSearch = $offset - $results_per_page;
361 # we are at the last item of the list
362 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
363 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
364 next unless ($arrBiblios[$j]);
365 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
369 # search again if we are at the first list and there is more results
370 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
372 # search again if we aren't at the first list and there is more results
373 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
375 $offsetSearch = $offset + $results_per_page if ($searchAgain);
377 for (my $j = 1; $j < $#arrBiblios; $j++) {
378 if ($arrBiblios[$j] == $biblionumber) {
379 for (my $z = $j - 1; $z >= 0; $z--) {
380 next unless ($arrBiblios[$z]);
381 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
384 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
385 next unless ($arrBiblios[$z]);
386 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
394 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
397 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
398 my @newresults = @
$newresultsRef;
399 # build the new listBiblios
400 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
401 unless (exists($arrParamsBusc{'listBiblios'})) {
402 $arrParamsBusc{'listBiblios'} = $listBiblios;
403 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
405 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
407 # From the new list we build again the next and previous result
409 if ($arrBiblios[0] == $biblionumber) {
410 for (my $j = $#newresults; $j >= 0; $j--) {
411 next unless ($newresults[$j]);
412 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
413 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
414 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
417 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
418 for (my $j = 0; $j < @newresults; $j++) {
419 next unless ($newresults[$j]);
420 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
421 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
422 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
427 # build new busc param
428 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
429 $session->param("busc" => $newbusc);
431 my ($numberBiblioPaging, $dataBiblioPaging);
433 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
434 if ($numberBiblioPaging) {
435 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
436 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
437 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
440 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
441 if ($numberBiblioPaging) {
442 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
443 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
444 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
446 # Partial list of biblio results
448 for (my $j = 0; $j < @arrBiblios; $j++) {
449 next unless ($arrBiblios[$j]);
450 $dataBiblioPaging = GetBiblioData
($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
451 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]};
453 $template->param('listResults' => \
@listResults) if (@listResults);
454 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
459 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
460 $template->param('OPACShowCheckoutName' => C4
::Context
->preference("OPACShowCheckoutName") );
461 $template->param('OPACShowBarcode' => C4
::Context
->preference("OPACShowBarcode") );
463 # adding items linked via host biblios
465 my $analyticfield = '773';
466 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
467 $analyticfield = '773';
468 } elsif ($marcflavour eq 'UNIMARC') {
469 $analyticfield = '461';
471 foreach my $hostfield ( $record->field($analyticfield)) {
472 my $hostbiblionumber = $hostfield->subfield("0");
473 my $linkeditemnumber = $hostfield->subfield("9");
474 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
475 foreach my $hostitemInfo (@hostitemInfos){
476 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
477 push(@all_items, $hostitemInfo);
484 # Are there items to hide?
486 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
490 for my $itm (@all_items) {
491 if ( C4
::Context
->preference('hidelostitems') ) {
492 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
494 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
503 if (C4
::Context
->userenv){
504 $branch = C4
::Context
->userenv->{branch
};
506 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
508 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
510 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
513 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
514 $branchcode = $branch;
516 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
517 $branchcode = $ENV{'BRANCHCODE'};
523 foreach my $item ( @items ) {
524 if ( $item->{branchcode
} eq $branchcode ) {
525 $item->{'this_branch'} = 1;
526 push( @our_items, $item );
528 push( @other_items, $item );
532 @items = ( @our_items, @other_items );
536 my $dat = &GetBiblioData
($biblionumber);
537 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
539 frameworkcode
=> $dat->{'frameworkcode'},
543 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
545 my $itemtype = $dat->{'itemtype'};
547 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
548 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description
};
552 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.location' } ) };
554 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.ccode' } ) };
556 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.copynumber' } ) };
558 #coping with subscriptions
559 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
560 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
563 $dat->{'serial'}=1 if $subscriptionsnumber;
564 foreach my $subscription (@subscriptions) {
565 my $serials_to_display;
567 $cell{subscriptionid
} = $subscription->{subscriptionid
};
568 $cell{subscriptionnotes
} = $subscription->{notes
};
569 $cell{missinglist
} = $subscription->{missinglist
};
570 $cell{opacnote
} = $subscription->{opacnote
};
571 $cell{histstartdate
} = $subscription->{histstartdate
};
572 $cell{histenddate
} = $subscription->{histenddate
};
573 $cell{branchcode
} = $subscription->{branchcode
};
574 $cell{callnumber
} = $subscription->{callnumber
};
575 $cell{closed
} = $subscription->{closed
};
576 $cell{letter
} = $subscription->{letter
};
577 $cell{biblionumber
} = $subscription->{biblionumber
};
578 #get the three latest serials.
579 $serials_to_display = $subscription->{opacdisplaycount
};
580 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
581 $cell{opacdisplaycount
} = $serials_to_display;
582 $cell{latestserials
} =
583 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
584 if ( $borrowernumber ) {
585 my $sub = getalert
($borrowernumber,'issue_det',$subscription->{subscriptionid
});
586 if ( !defined $sub ) {
587 $sub = getalert
($borrowernumber,'issue_ser',$subscription->{subscriptionid
});
596 $dat->{'count'} = scalar(@items);
599 my (%item_reserves, %priority);
600 my ($show_holds_count, $show_priority);
601 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
602 m/holds/o and $show_holds_count = 1;
603 m/priority/ and $show_priority = 1;
606 if ( $show_holds_count || $show_priority) {
607 my $biblio = Koha
::Biblios
->find( $biblionumber );
608 my $holds = $biblio->holds;
609 $template->param( holds_count
=> $holds->count );
610 while ( my $hold = $holds->next ) {
611 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
612 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
615 ?
($priority{ $hold->itemnumber } = $hold->priority)
616 : ($template->param( priority
=> $hold->priority ));
620 $template->param( show_priority
=> $has_hold ) ;
624 my (@itemloop, @otheritemloop);
625 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
626 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
627 $template->param(SeparateHoldings
=> 1);
629 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
630 my $viewallitems = $query->param('viewallitems');
631 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
634 my ( @itemnumbers_on_order );
635 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
636 my $orders = C4
::Acquisition
::SearchOrders
({
637 biblionumber
=> $biblionumber,
640 my $total_quantity = 0;
641 for my $order ( @
$orders ) {
642 if ( C4
::Context
->preference('AcqCreateItem') eq 'ordering' ) {
643 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
644 push @itemnumbers_on_order, $itemnumber;
647 $total_quantity += $order->{quantity
};
649 $template->{VARS
}->{acquisition_details
} = {
650 total_quantity
=> $total_quantity,
654 if ( not $viewallitems and @items > $max_items_to_display ) {
657 items_count
=> scalar( @items ),
660 my $allow_onshelf_holds;
661 my $borrower = GetMember
( 'borrowernumber' => $borrowernumber );
662 for my $itm (@items) {
663 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
664 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
667 && !$itm->{'withdrawn'}
668 && !$itm->{'itemlost'}
669 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
670 && !$itemtypes->{$itm->{'itype'}}->{notforloan
}
671 && $itm->{'itemnumber'};
673 $allow_onshelf_holds = C4
::Reserves
::OnShelfHoldsAllowed
( $itm, $borrower )
674 unless $allow_onshelf_holds;
676 # get collection code description, too
677 my $ccode = $itm->{'ccode'};
678 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
679 my $copynumber = $itm->{'copynumber'};
680 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
681 if ( defined $itm->{'location'} ) {
682 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
684 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
685 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
686 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{translated_description
};
688 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
689 $itemfields{$_} = 1 if ($itm->{$_});
692 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
693 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
694 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
696 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
697 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
698 $itm->{transfertwhen
} = $transfertwhen;
699 $itm->{transfertfrom
} = $transfertfrom;
700 $itm->{transfertto
} = $transfertto;
703 if ( C4
::Context
->preference('OPACAcquisitionDetails')
704 and C4
::Context
->preference('AcqCreateItem') eq 'ordering' )
707 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
710 my $itembranch = $itm->{$separatebranch};
711 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
712 if ($itembranch and $itembranch eq $currentbranch) {
713 push @itemloop, $itm;
715 push @otheritemloop, $itm;
718 push @itemloop, $itm;
721 $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
724 # Display only one tab if one items list is empty
725 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
726 $template->param(SeparateHoldings
=> 0);
727 if (scalar(@itemloop) == 0) {
728 @itemloop = @otheritemloop;
732 ## get notes and subjects from MARC record
733 if (!C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
734 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
735 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
736 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
737 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
738 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
739 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
742 MARCSUBJCTS
=> $marcsubjctsarray,
743 MARCAUTHORS
=> $marcauthorsarray,
744 MARCSERIES
=> $marcseriesarray,
745 MARCURLS
=> $marcurlsarray,
746 MARCISBNS
=> $marcisbnsarray,
747 MARCHOSTS
=> $marchostsarray,
751 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
752 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
755 MARCNOTES
=> $marcnotesarray,
756 norequests
=> $norequests,
757 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
758 itemdata_ccode
=> $itemfields{ccode
},
759 itemdata_enumchron
=> $itemfields{enumchron
},
760 itemdata_uri
=> $itemfields{uri
},
761 itemdata_copynumber
=> $itemfields{copynumber
},
762 itemdata_itemnotes
=> $itemfields{itemnotes
},
763 subtitle
=> $subtitle,
764 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
767 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
768 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
769 my $subfields = substr $fieldspec, 3;
770 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
771 my @alternateholdingsinfo = ();
772 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
774 for my $field (@holdingsfields) {
775 my %holding = ( holding
=> '' );
776 my $havesubfield = 0;
777 for my $subfield ($field->subfields()) {
778 if ((index $subfields, $$subfield[0]) >= 0) {
779 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
780 $holding{'holding'} .= $$subfield[1];
785 push(@alternateholdingsinfo, \
%holding);
790 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
794 # FIXME: The template uses this hash directly. Need to filter.
795 foreach ( keys %{$dat} ) {
796 next if ( $HideMARC->{$_} );
797 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
800 # some useful variables for enhanced content;
801 # in each case, we're grabbing the first value we find in
802 # the record and normalizing it
803 my $upc = GetNormalizedUPC
($record,$marcflavour);
804 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
805 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
806 my $content_identifier_exists;
807 if ( $isbn or $ean or $oclc or $upc ) {
808 $content_identifier_exists = 1;
811 normalized_upc
=> $upc,
812 normalized_ean
=> $ean,
813 normalized_oclc
=> $oclc,
814 normalized_isbn
=> $isbn,
815 content_identifier_exists
=> $content_identifier_exists,
818 # COinS format FIXME: for books Only
820 ocoins
=> GetCOinSBiblio
($record),
823 my ( $loggedincommenter, $reviews );
824 if ( C4
::Context
->preference('reviewson') ) {
825 $reviews = Koha
::Reviews
->search(
827 biblionumber
=> $biblionumber,
828 -or => { approved
=> 1, borrowernumber
=> $borrowernumber }
831 order_by
=> { -desc
=> 'datereviewed' }
834 my $libravatar_enabled = 0;
835 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto') ) {
837 require Libravatar
::URL
;
838 Libravatar
::URL
->import();
841 $libravatar_enabled = 1;
844 for my $review (@
$reviews) {
845 my $borrowerData = GetMember
( 'borrowernumber' => $review->{borrowernumber
} );
847 # setting some borrower info into this hash
848 $review->{title
} = $borrowerData->{'title'};
849 $review->{surname
} = $borrowerData->{'surname'};
850 $review->{firstname
} = $borrowerData->{'firstname'};
851 if ( $libravatar_enabled and $borrowerData->{'email'} ) {
852 $review->{avatarurl
} = libravatar_url
( email
=> $borrowerData->{'email'}, https
=> $ENV{HTTPS
} );
854 $review->{userid
} = $borrowerData->{'userid'};
855 $review->{cardnumber
} = $borrowerData->{'cardnumber'};
857 if ( $borrowerData->{'borrowernumber'} eq $borrowernumber ) {
858 $review->{your_comment
} = 1;
859 $loggedincommenter = 1;
864 if ( C4
::Context
->preference("OPACISBD") ) {
865 $template->param( ISBD
=> 1 );
869 itemloop
=> \
@itemloop,
870 otheritemloop
=> \
@otheritemloop,
871 biblionumber
=> $biblionumber,
872 subscriptions
=> \
@subs,
873 subscriptionsnumber
=> $subscriptionsnumber,
875 loggedincommenter
=> $loggedincommenter
879 if (C4
::Context
->preference("virtualshelves") ) {
880 my $shelves = Koha
::Virtualshelves
->search(
882 biblionumber
=> $biblionumber,
886 join => 'virtualshelfcontents',
889 $template->param( shelves
=> $shelves );
893 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
896 XISBNS
=> get_xisbns
($isbn)
899 if ($@
) { warn "XISBN Failed $@"; }
903 my @sc_fields = $record->field(955);
904 my @lc_fields = $marcflavour eq 'UNIMARC'
905 ?
$record->field(930)
906 : $record->field(852);
907 my @serialcollections = ();
909 foreach my $sc_field (@sc_fields) {
912 $row_data{text
} = $sc_field->subfield('r');
913 $row_data{branch
} = $sc_field->subfield('9');
914 foreach my $lc_field (@lc_fields) {
915 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
916 ?
$lc_field->subfield('a') # 930$a
917 : $lc_field->subfield('h') # 852$h
918 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
921 if ($row_data{text
} && $row_data{branch
}) {
922 push (@serialcollections, \
%row_data);
926 if (scalar(@serialcollections) > 0) {
928 serialcollection
=> 1,
929 serialcollections
=> \
@serialcollections);
932 # Local cover Images stuff
933 if (C4
::Context
->preference("OPACLocalCoverImages")){
934 $template->param(OPACLocalCoverImages
=> 1);
938 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
939 $template->param( C4
::HTML5Media
->gethtml5media($record));
942 my $syndetics_elements;
944 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
945 $template->param("SyndeticsEnabled" => 1);
946 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
948 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
949 for my $element (values %$syndetics_elements) {
950 $template->param("Syndetics$element"."Exists" => 1 );
951 #warn "Exists: "."Syndetics$element"."Exists";
957 if ( C4
::Context
->preference("SyndeticsEnabled")
958 && C4
::Context
->preference("SyndeticsSummary")
959 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
961 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
962 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
968 if ( C4
::Context
->preference("SyndeticsEnabled")
969 && C4
::Context
->preference("SyndeticsTOC")
970 && exists($syndetics_elements->{'TOC'}) ) {
972 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
973 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
978 if ( C4
::Context
->preference("SyndeticsEnabled")
979 && C4
::Context
->preference("SyndeticsExcerpt")
980 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
982 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
983 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
988 if ( C4
::Context
->preference("SyndeticsEnabled")
989 && C4
::Context
->preference("SyndeticsReviews")) {
991 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
992 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
997 if ( C4
::Context
->preference("SyndeticsEnabled")
998 && C4
::Context
->preference("SyndeticsAuthorNotes")
999 && exists($syndetics_elements->{'ANOTES'}) ) {
1001 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
1002 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
1007 # LibraryThingForLibraries ID Code and Tabbed View Option
1008 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
1010 $template->param(LibraryThingForLibrariesID
=>
1011 C4
::Context
->preference('LibraryThingForLibrariesID') );
1012 $template->param(LibraryThingForLibrariesTabbedView
=>
1013 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
1017 if( C4
::Context
->preference('NovelistSelectEnabled') )
1019 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
1020 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
1021 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
1026 if ( C4
::Context
->preference("Babeltheque") ) {
1029 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
1034 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
1035 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1036 $template->param( SocialNetworks
=> 1 );
1039 # Shelf Browser Stuff
1040 if (C4
::Context
->preference("OPACShelfBrowser")) {
1041 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1042 if (defined($starting_itemnumber)) {
1043 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
1044 my $nearby = GetNearbyItems
($starting_itemnumber);
1047 starting_itemnumber
=> $starting_itemnumber,
1048 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1049 starting_location
=> $nearby->{starting_location
}->{description
},
1050 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1051 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1052 shelfbrowser_next_item
=> $nearby->{next_item
},
1053 shelfbrowser_items
=> $nearby->{items
},
1056 # in which tab shelf browser should open ?
1057 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1058 $template->param(shelfbrowser_tab
=> 'holdings');
1060 $template->param(shelfbrowser_tab
=> 'otherholdings');
1065 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1067 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1069 BakerTaylorEnabled
=> 1,
1070 BakerTaylorImageURL
=> &image_url
(),
1071 BakerTaylorLinkURL
=> &link_url
(),
1072 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1074 my ($bt_user, $bt_pass);
1076 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1077 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1080 BakerTaylorContentURL
=>
1081 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1082 $bt_user,$bt_pass,$isbn)
1088 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1091 TagsShowOnDetail
=> $tag_quantity,
1092 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1094 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1095 'sort'=>'-weight', limit
=>$tag_quantity}));
1098 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1099 # These values are going to be read by Javascript, at least in the case
1100 # of the google covers
1101 $template->param(covernewwindow
=> 'true');
1103 $template->param(covernewwindow
=> 'false');
1106 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1107 my $ratings = Koha
::Ratings
->search({ biblionumber
=> $biblionumber });
1108 my $my_rating = $borrowernumber ?
$ratings->search({ borrowernumber
=> $borrowernumber })->next : undef;
1110 ratings
=> $ratings,
1111 my_rating
=> $my_rating,
1112 borrowernumber
=> $borrowernumber
1116 #Search for title in links
1117 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1118 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1119 my $issn = $marcissns->[0] || '';
1121 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1122 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1123 $dat->{title
} =~ s/\s+$//; # remove trailing space
1124 $search_for_title = parametrized_url
(
1127 TITLE
=> $dat->{title
},
1128 AUTHOR
=> $dat->{author
},
1131 CONTROLNUMBER
=> $marccontrolnumber,
1132 BIBLIONUMBER
=> $biblionumber,
1135 $template->param('OPACSearchForTitleIn' => $search_for_title);
1139 if ( C4
::Context
->preference("IDREF") ) {
1140 # If the record comes from the SUDOC
1141 if ( $record->field('009') ) {
1142 my $unimarc3 = $record->field("009")->data;
1143 if ( $unimarc3 =~ /^\d+$/ ) {
1151 # We try to select the best default tab to show, according to what
1152 # the user wants, and what's available for display
1153 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1157 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1159 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1160 ?
'serialcollection' :
1161 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1163 scalar (@itemloop) == 0
1165 $subscriptionsnumber
1167 @serialcollections > 0
1168 ?
'serialcollection' : 'subscriptions';
1169 $template->param('defaulttab' => $defaulttab);
1171 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1172 my @images = ListImagesForBiblio
($biblionumber);
1173 $template->{VARS
}->{localimages
} = \
@images;
1176 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1177 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1178 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1179 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1181 if (C4
::Context
->preference('OpacHighlightedWords')) {
1182 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1184 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1186 if ( C4
::Context
->preference('UseCourseReserves') ) {
1187 foreach my $i ( @items ) {
1188 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1193 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay') ,
1194 'OpacLocationBranchToDisplayShelving' => C4
::Context
->preference('OpacLocationBranchToDisplayShelving'),
1197 output_html_with_http_headers
$query, $cookie, $template->output;