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 );
45 use List
::MoreUtils qw
/any none/;
49 use C4
::CourseReserves
qw(GetItemCourseReservesInfo);
50 use Koha
::RecordProcessor
;
51 use Koha
::AuthorisedValues
;
53 use Koha
::Virtualshelves
;
58 if (C4
::Context
->preference('BakerTaylorEnabled')) {
59 require C4
::External
::BakerTaylor
;
60 import C4
::External
::BakerTaylor
qw(&image_url &link_url);
65 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
67 template_name
=> "opac-detail.tt",
70 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
74 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
75 $biblionumber = int($biblionumber);
77 my @all_items = GetItemsInfo
($biblionumber);
79 if (scalar @all_items >= 1) {
80 push @hiddenitems, GetHiddenItemnumbers
(@all_items);
82 if (scalar @hiddenitems == scalar @all_items ) {
83 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
88 my $record = GetMarcBiblio
($biblionumber);
90 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
93 my $framework = &GetFrameworkCode
( $biblionumber );
94 my $record_processor = Koha
::RecordProcessor
->new({
95 filters
=> 'ViewPolicy',
98 frameworkcode
=> $framework
101 $record_processor->process($record);
103 # redirect if opacsuppression is enabled and biblio is suppressed
104 if (C4
::Context
->preference('OpacSuppression')) {
105 # FIXME hardcoded; the suppression flag ought to be materialized
106 # as a column on biblio or the like
107 my $opacsuppressionfield = '942';
108 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
109 # redirect to opac-blocked info page or 404?
110 my $opacsuppressionredirect;
111 if ( C4
::Context
->preference("OpacSuppressionRedirect") ) {
112 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
114 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
116 if ( $opacsuppressionfieldvalue &&
117 $opacsuppressionfieldvalue->subfield("n") &&
118 $opacsuppressionfieldvalue->subfield("n") == 1) {
119 # if OPAC suppression by IP address
120 if (C4
::Context
->preference('OpacSuppressionByIPRange')) {
121 my $IPAddress = $ENV{'REMOTE_ADDR'};
122 my $IPRange = C4
::Context
->preference('OpacSuppressionByIPRange');
123 if ($IPAddress !~ /^$IPRange/) {
124 print $query->redirect($opacsuppressionredirect);
128 print $query->redirect($opacsuppressionredirect);
134 $template->param( biblionumber
=> $biblionumber );
136 # get biblionumbers stored in the cart
139 if($query->cookie("bib_list")){
140 my $cart_list = $query->cookie("bib_list");
141 @cart_list = split(/\//, $cart_list);
142 if ( grep {$_ eq $biblionumber} @cart_list) {
143 $template->param( incart
=> 1 );
148 SetUTF8Flag
($record);
149 my $marcflavour = C4
::Context
->preference("marcflavour");
150 my $ean = GetNormalizedEAN
( $record, $marcflavour );
152 # XSLT processing of some stuff
153 my $xslfile = C4
::Context
->preference('OPACXSLTDetailsDisplay');
154 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
155 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
159 XSLTBloc
=> XSLTParse4Display
(
160 $biblionumber, $record, "OPACXSLTDetailsDisplay",
161 1, undef, $sysxml, $xslfile, $lang
166 my $OpacBrowseResults = C4
::Context
->preference("OpacBrowseResults");
167 $template->{VARS
}->{'OpacBrowseResults'} = $OpacBrowseResults;
169 # We look for the busc param to build the simple paging from the search
170 if ($OpacBrowseResults) {
171 my $session = get_session
($query->cookie("CGISESSID"));
172 my %paging = (previous
=> {}, next => {});
173 if ($session->param('busc')) {
177 # Rebuild the string to store on session
178 # param value is URI encoded and params separator is HTML encode (&)
181 my $arrParamsBusc = shift;
183 my $pasarParams = '';
185 for (keys %$arrParamsBusc) {
186 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
187 if (defined($arrParamsBusc->{$_})) {
188 $pasarParams .= '&' if ($j);
189 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
193 for my $value (@
{$arrParamsBusc->{$_}}) {
194 $pasarParams .= '&' if ($j);
195 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
203 # Search given the current values from the busc param
206 my ($arrParamsBusc, $offset, $results_per_page) = @_;
208 my $expanded_facet = $arrParamsBusc->{'expand'};
209 my $itemtypes = GetItemTypes
;
211 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
212 @servers = ("biblioserver") unless (@servers);
214 my ($default_sort_by, @sort_by);
215 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
216 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
217 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
218 my ($error, $results_hashref, $facets);
220 ($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'});
224 for (my $i=0;$i<@servers;$i++) {
225 my $server = $servers[$i];
226 $hits = $results_hashref->{$server}->{"hits"};
227 @newresults = searchResults
('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
232 # Build the current list of biblionumbers in this search
235 my ($newresultsRef, $results_per_page) = @_;
237 my $listBiblios = '';
239 foreach (@
$newresultsRef) {
240 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
241 $listBiblios .= $bibnum . ',';
243 last if ($j == $results_per_page);
245 chop $listBiblios if ($listBiblios =~ /,$/);
249 my $busc = $session->param("busc");
250 my @arrBusc = split(/\&(?:amp;)?/, $busc);
252 my %arrParamsBusc = ();
254 ($key, $value) = split(/=/, $_, 2);
255 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
256 $arrParamsBusc{$key} = uri_unescape
($value);
258 unless (exists($arrParamsBusc{$key})) {
259 $arrParamsBusc{$key} = [];
261 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
265 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
266 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
267 $arrParamsBusc{'count'} = $results_per_page;
268 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
269 # The value OPACnumSearchResults has changed and the search has to be rebuild
270 if ($count != $results_per_page) {
271 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
273 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
274 for (@arrBibliosAux) {
275 last if ($_ == $biblionumber);
278 $indexBiblio += $offset;
279 $offset = int($indexBiblio / $count) * $count;
280 $arrParamsBusc{'offset'} = $offset;
282 $arrParamsBusc{'count'} = $count;
283 $results_per_page = $count;
284 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
285 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
286 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
287 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
288 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
289 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
290 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
291 $session->param("busc" => $newbusc);
292 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
294 my $modifyListBiblios = 0;
295 # We come from a previous click
296 if (exists($arrParamsBusc{'previous'})) {
297 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
298 delete $arrParamsBusc{'previous'};
299 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
300 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
301 delete $arrParamsBusc{'next'};
303 if ($modifyListBiblios) {
304 if (exists($arrParamsBusc{'newlistBiblios'})) {
305 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
306 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
307 my @arrAux = split(',', $listBibliosAux);
308 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
309 if ($modifyListBiblios == 1) {
310 $arrParamsBusc{'next'} = $arrAux[0];
311 $paging{'next'}->{biblionumber
} = $arrAux[0];
313 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
314 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
317 delete $arrParamsBusc{'listBiblios'};
319 my $offsetAux = $arrParamsBusc{'offset'};
320 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
321 $arrParamsBusc{'offsetSearch'} = $offsetAux;
322 $offset = $arrParamsBusc{'offset'};
323 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
324 $session->param("busc" => $newbusc);
325 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
330 # Rebuild the query for the button "back to results"
332 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
333 $buscParam .= '&' unless ($j == 0);
334 $buscParam .= $_; # string already URI encoded
338 $template->param('busc' => $buscParam);
341 # We are inside the list of biblios and we don't have to search
342 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
343 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
345 # We are at the first item of the list
346 if ($arrBiblios[0] == $biblionumber) {
347 if (@arrBiblios > 1) {
348 for (my $j = 1; $j < @arrBiblios; $j++) {
349 next unless ($arrBiblios[$j]);
350 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
354 # search again if we are not at the first searching list
355 if ($offset && !$arrParamsBusc{'previous'}) {
357 $offsetSearch = $offset - $results_per_page;
359 # we are at the last item of the list
360 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
361 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
362 next unless ($arrBiblios[$j]);
363 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
367 # search again if we are at the first list and there is more results
368 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
370 # search again if we aren't at the first list and there is more results
371 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
373 $offsetSearch = $offset + $results_per_page if ($searchAgain);
375 for (my $j = 1; $j < $#arrBiblios; $j++) {
376 if ($arrBiblios[$j] == $biblionumber) {
377 for (my $z = $j - 1; $z >= 0; $z--) {
378 next unless ($arrBiblios[$z]);
379 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
382 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
383 next unless ($arrBiblios[$z]);
384 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
392 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
395 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
396 my @newresults = @
$newresultsRef;
397 # build the new listBiblios
398 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
399 unless (exists($arrParamsBusc{'listBiblios'})) {
400 $arrParamsBusc{'listBiblios'} = $listBiblios;
401 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
403 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
405 # From the new list we build again the next and previous result
407 if ($arrBiblios[0] == $biblionumber) {
408 for (my $j = $#newresults; $j >= 0; $j--) {
409 next unless ($newresults[$j]);
410 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
411 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
412 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
415 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
416 for (my $j = 0; $j < @newresults; $j++) {
417 next unless ($newresults[$j]);
418 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
419 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
420 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
425 # build new busc param
426 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
427 $session->param("busc" => $newbusc);
429 my ($numberBiblioPaging, $dataBiblioPaging);
431 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
432 if ($numberBiblioPaging) {
433 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
434 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
435 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
438 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
439 if ($numberBiblioPaging) {
440 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
441 $dataBiblioPaging = GetBiblioData
($numberBiblioPaging);
442 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
444 # Partial list of biblio results
446 for (my $j = 0; $j < @arrBiblios; $j++) {
447 next unless ($arrBiblios[$j]);
448 $dataBiblioPaging = GetBiblioData
($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
449 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]};
451 $template->param('listResults' => \
@listResults) if (@listResults);
452 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
457 $template->param( 'ItemsIssued' => CountItemsIssued
( $biblionumber ) );
458 $template->param('OPACShowCheckoutName' => C4
::Context
->preference("OPACShowCheckoutName") );
459 $template->param('OPACShowBarcode' => C4
::Context
->preference("OPACShowBarcode") );
461 # adding items linked via host biblios
463 my $analyticfield = '773';
464 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
465 $analyticfield = '773';
466 } elsif ($marcflavour eq 'UNIMARC') {
467 $analyticfield = '461';
469 foreach my $hostfield ( $record->field($analyticfield)) {
470 my $hostbiblionumber = $hostfield->subfield("0");
471 my $linkeditemnumber = $hostfield->subfield("9");
472 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
473 foreach my $hostitemInfo (@hostitemInfos){
474 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
475 push(@all_items, $hostitemInfo);
482 # Are there items to hide?
484 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
488 for my $itm (@all_items) {
489 if ( C4
::Context
->preference('hidelostitems') ) {
490 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
492 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
501 if (C4
::Context
->userenv){
502 $branch = C4
::Context
->userenv->{branch
};
504 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
506 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
508 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
511 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
512 $branchcode = $branch;
514 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
515 $branchcode = $ENV{'BRANCHCODE'};
521 foreach my $item ( @items ) {
522 if ( $item->{branchcode
} eq $branchcode ) {
523 $item->{'this_branch'} = 1;
524 push( @our_items, $item );
526 push( @other_items, $item );
530 @items = ( @our_items, @other_items );
534 my $dat = &GetBiblioData
($biblionumber);
535 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
537 frameworkcode
=> $dat->{'frameworkcode'},
541 my $itemtypes = GetItemTypes
();
543 my $itemtype = $dat->{'itemtype'};
545 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
546 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description
};
550 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.location' } ) };
552 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.ccode' } ) };
554 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.copynumber' } ) };
556 #coping with subscriptions
557 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
558 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
561 $dat->{'serial'}=1 if $subscriptionsnumber;
562 foreach my $subscription (@subscriptions) {
563 my $serials_to_display;
565 $cell{subscriptionid
} = $subscription->{subscriptionid
};
566 $cell{subscriptionnotes
} = $subscription->{notes
};
567 $cell{missinglist
} = $subscription->{missinglist
};
568 $cell{opacnote
} = $subscription->{opacnote
};
569 $cell{histstartdate
} = $subscription->{histstartdate
};
570 $cell{histenddate
} = $subscription->{histenddate
};
571 $cell{branchcode
} = $subscription->{branchcode
};
572 $cell{hasalert
} = $subscription->{hasalert
};
573 $cell{callnumber
} = $subscription->{callnumber
};
574 $cell{closed
} = $subscription->{closed
};
575 #get the three latest serials.
576 $serials_to_display = $subscription->{opacdisplaycount
};
577 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
578 $cell{opacdisplaycount
} = $serials_to_display;
579 $cell{latestserials
} =
580 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
584 $dat->{'count'} = scalar(@items);
587 my (%item_reserves, %priority);
588 my ($show_holds_count, $show_priority);
589 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
590 m/holds/o and $show_holds_count = 1;
591 m/priority/ and $show_priority = 1;
594 if ( $show_holds_count || $show_priority) {
595 my $biblio = Koha
::Biblios
->find( $biblionumber );
596 my $holds = $biblio->holds;
597 $template->param( holds_count
=> $holds->count );
598 while ( my $hold = $holds->next ) {
599 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
600 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
603 ?
($priority{ $hold->itemnumber } = $hold->priority)
604 : ($template->param( priority
=> $hold->priority ));
608 $template->param( show_priority
=> $has_hold ) ;
612 my (@itemloop, @otheritemloop);
613 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
614 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
615 $template->param(SeparateHoldings
=> 1);
617 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
618 my $viewallitems = $query->param('viewallitems');
619 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
622 my ( @itemnumbers_on_order );
623 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
624 my $orders = C4
::Acquisition
::SearchOrders
({
625 biblionumber
=> $biblionumber,
628 my $total_quantity = 0;
629 for my $order ( @
$orders ) {
630 if ( C4
::Context
->preference('AcqCreateItem') eq 'ordering' ) {
631 for my $itemnumber ( C4
::Acquisition
::GetItemnumbersFromOrder
( $order->{ordernumber
} ) ) {
632 push @itemnumbers_on_order, $itemnumber;
635 $total_quantity += $order->{quantity
};
637 $template->{VARS
}->{acquisition_details
} = {
638 total_quantity
=> $total_quantity,
642 if ( not $viewallitems and @items > $max_items_to_display ) {
645 items_count
=> scalar( @items ),
648 my $allow_onshelf_holds;
649 my $borrower = GetMember
( 'borrowernumber' => $borrowernumber );
650 for my $itm (@items) {
651 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
652 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
655 && !$itm->{'withdrawn'}
656 && !$itm->{'itemlost'}
657 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
658 && !$itemtypes->{$itm->{'itype'}}->{notforloan
}
659 && $itm->{'itemnumber'};
661 $allow_onshelf_holds = C4
::Reserves
::OnShelfHoldsAllowed
( $itm, $borrower )
662 unless $allow_onshelf_holds;
664 # get collection code description, too
665 my $ccode = $itm->{'ccode'};
666 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
667 my $copynumber = $itm->{'copynumber'};
668 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
669 if ( defined $itm->{'location'} ) {
670 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
672 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
673 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
674 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{translated_description
};
676 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
677 $itemfields{$_} = 1 if ($itm->{$_});
680 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
681 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
682 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
684 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
685 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
686 $itm->{transfertwhen
} = $transfertwhen;
687 $itm->{transfertfrom
} = $transfertfrom;
688 $itm->{transfertto
} = $transfertto;
691 if ( C4
::Context
->preference('OPACAcquisitionDetails')
692 and C4
::Context
->preference('AcqCreateItem') eq 'ordering' )
695 if grep /^$itm->{itemnumber}$/, @itemnumbers_on_order;
698 my $itembranch = $itm->{$separatebranch};
699 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
700 if ($itembranch and $itembranch eq $currentbranch) {
701 push @itemloop, $itm;
703 push @otheritemloop, $itm;
706 push @itemloop, $itm;
709 $template->param( 'AllowOnShelfHolds' => $allow_onshelf_holds );
712 # Display only one tab if one items list is empty
713 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
714 $template->param(SeparateHoldings
=> 0);
715 if (scalar(@itemloop) == 0) {
716 @itemloop = @otheritemloop;
720 ## get notes and subjects from MARC record
721 if (!C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
722 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
723 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
724 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
725 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
726 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
727 my $marchostsarray = GetMarcHosts
($record,$marcflavour);
730 MARCSUBJCTS
=> $marcsubjctsarray,
731 MARCAUTHORS
=> $marcauthorsarray,
732 MARCSERIES
=> $marcseriesarray,
733 MARCURLS
=> $marcurlsarray,
734 MARCISBNS
=> $marcisbnsarray,
735 MARCHOSTS
=> $marchostsarray,
739 my $marcnotesarray = GetMarcNotes
($record,$marcflavour);
740 my $subtitle = GetRecordValue
('subtitle', $record, GetFrameworkCode
($biblionumber));
743 MARCNOTES
=> $marcnotesarray,
744 norequests
=> $norequests,
745 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
746 itemdata_ccode
=> $itemfields{ccode
},
747 itemdata_enumchron
=> $itemfields{enumchron
},
748 itemdata_uri
=> $itemfields{uri
},
749 itemdata_copynumber
=> $itemfields{copynumber
},
750 itemdata_itemnotes
=> $itemfields{itemnotes
},
751 subtitle
=> $subtitle,
752 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
755 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
756 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
757 my $subfields = substr $fieldspec, 3;
758 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
759 my @alternateholdingsinfo = ();
760 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
762 for my $field (@holdingsfields) {
763 my %holding = ( holding
=> '' );
764 my $havesubfield = 0;
765 for my $subfield ($field->subfields()) {
766 if ((index $subfields, $$subfield[0]) >= 0) {
767 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
768 $holding{'holding'} .= $$subfield[1];
773 push(@alternateholdingsinfo, \
%holding);
778 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
782 # FIXME: The template uses this hash directly. Need to filter.
783 foreach ( keys %{$dat} ) {
784 next if ( $HideMARC->{$_} );
785 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
788 # some useful variables for enhanced content;
789 # in each case, we're grabbing the first value we find in
790 # the record and normalizing it
791 my $upc = GetNormalizedUPC
($record,$marcflavour);
792 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
793 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
794 my $content_identifier_exists;
795 if ( $isbn or $ean or $oclc or $upc ) {
796 $content_identifier_exists = 1;
799 normalized_upc
=> $upc,
800 normalized_ean
=> $ean,
801 normalized_oclc
=> $oclc,
802 normalized_isbn
=> $isbn,
803 content_identifier_exists
=> $content_identifier_exists,
806 # COinS format FIXME: for books Only
808 ocoins
=> GetCOinSBiblio
($record),
811 my ( $loggedincommenter, $reviews );
812 if ( C4
::Context
->preference('reviewson') ) {
813 $reviews = Koha
::Reviews
->search(
815 biblionumber
=> $biblionumber,
816 -or => { approved
=> 1, borrowernumber
=> $borrowernumber }
819 order_by
=> { -desc
=> 'datereviewed' }
822 my $libravatar_enabled = 0;
823 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto') ) {
825 require Libravatar
::URL
;
826 Libravatar
::URL
->import();
829 $libravatar_enabled = 1;
832 for my $review (@
$reviews) {
833 my $borrowerData = GetMember
( 'borrowernumber' => $review->{borrowernumber
} );
835 # setting some borrower info into this hash
836 $review->{title
} = $borrowerData->{'title'};
837 $review->{surname
} = $borrowerData->{'surname'};
838 $review->{firstname
} = $borrowerData->{'firstname'};
839 if ( $libravatar_enabled and $borrowerData->{'email'} ) {
840 $review->{avatarurl
} = libravatar_url
( email
=> $borrowerData->{'email'}, https
=> $ENV{HTTPS
} );
842 $review->{userid
} = $borrowerData->{'userid'};
843 $review->{cardnumber
} = $borrowerData->{'cardnumber'};
845 if ( $borrowerData->{'borrowernumber'} eq $borrowernumber ) {
846 $review->{your_comment
} = 1;
847 $loggedincommenter = 1;
852 if ( C4
::Context
->preference("OPACISBD") ) {
853 $template->param( ISBD
=> 1 );
857 itemloop
=> \
@itemloop,
858 otheritemloop
=> \
@otheritemloop,
859 biblionumber
=> $biblionumber,
860 subscriptions
=> \
@subs,
861 subscriptionsnumber
=> $subscriptionsnumber,
863 loggedincommenter
=> $loggedincommenter
867 if (C4
::Context
->preference("virtualshelves") ) {
868 my $shelves = Koha
::Virtualshelves
->search(
870 biblionumber
=> $biblionumber,
874 join => 'virtualshelfcontents',
877 $template->param( shelves
=> $shelves );
881 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
884 XISBNS
=> get_xisbns
($isbn)
887 if ($@
) { warn "XISBN Failed $@"; }
891 my @sc_fields = $record->field(955);
892 my @lc_fields = $marcflavour eq 'UNIMARC'
893 ?
$record->field(930)
894 : $record->field(852);
895 my @serialcollections = ();
897 foreach my $sc_field (@sc_fields) {
900 $row_data{text
} = $sc_field->subfield('r');
901 $row_data{branch
} = $sc_field->subfield('9');
902 foreach my $lc_field (@lc_fields) {
903 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
904 ?
$lc_field->subfield('a') # 930$a
905 : $lc_field->subfield('h') # 852$h
906 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
909 if ($row_data{text
} && $row_data{branch
}) {
910 push (@serialcollections, \
%row_data);
914 if (scalar(@serialcollections) > 0) {
916 serialcollection
=> 1,
917 serialcollections
=> \
@serialcollections);
920 # Local cover Images stuff
921 if (C4
::Context
->preference("OPACLocalCoverImages")){
922 $template->param(OPACLocalCoverImages
=> 1);
926 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
927 $template->param( C4
::HTML5Media
->gethtml5media($record));
930 my $syndetics_elements;
932 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
933 $template->param("SyndeticsEnabled" => 1);
934 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
936 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
937 for my $element (values %$syndetics_elements) {
938 $template->param("Syndetics$element"."Exists" => 1 );
939 #warn "Exists: "."Syndetics$element"."Exists";
945 if ( C4
::Context
->preference("SyndeticsEnabled")
946 && C4
::Context
->preference("SyndeticsSummary")
947 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
949 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
950 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
956 if ( C4
::Context
->preference("SyndeticsEnabled")
957 && C4
::Context
->preference("SyndeticsTOC")
958 && exists($syndetics_elements->{'TOC'}) ) {
960 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
961 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
966 if ( C4
::Context
->preference("SyndeticsEnabled")
967 && C4
::Context
->preference("SyndeticsExcerpt")
968 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
970 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
971 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
976 if ( C4
::Context
->preference("SyndeticsEnabled")
977 && C4
::Context
->preference("SyndeticsReviews")) {
979 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
980 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
985 if ( C4
::Context
->preference("SyndeticsEnabled")
986 && C4
::Context
->preference("SyndeticsAuthorNotes")
987 && exists($syndetics_elements->{'ANOTES'}) ) {
989 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
990 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
995 # LibraryThingForLibraries ID Code and Tabbed View Option
996 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
998 $template->param(LibraryThingForLibrariesID
=>
999 C4
::Context
->preference('LibraryThingForLibrariesID') );
1000 $template->param(LibraryThingForLibrariesTabbedView
=>
1001 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
1005 if( C4
::Context
->preference('NovelistSelectEnabled') )
1007 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
1008 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
1009 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
1014 if ( C4
::Context
->preference("Babeltheque") ) {
1017 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
1022 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
1023 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1024 $template->param( SocialNetworks
=> 1 );
1027 # Shelf Browser Stuff
1028 if (C4
::Context
->preference("OPACShelfBrowser")) {
1029 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1030 if (defined($starting_itemnumber)) {
1031 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
1032 my $nearby = GetNearbyItems
($starting_itemnumber);
1035 starting_itemnumber
=> $starting_itemnumber,
1036 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1037 starting_location
=> $nearby->{starting_location
}->{description
},
1038 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1039 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1040 shelfbrowser_next_item
=> $nearby->{next_item
},
1041 shelfbrowser_items
=> $nearby->{items
},
1044 # in which tab shelf browser should open ?
1045 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1046 $template->param(shelfbrowser_tab
=> 'holdings');
1048 $template->param(shelfbrowser_tab
=> 'otherholdings');
1053 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1055 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1057 BakerTaylorEnabled
=> 1,
1058 BakerTaylorImageURL
=> &image_url
(),
1059 BakerTaylorLinkURL
=> &link_url
(),
1060 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1062 my ($bt_user, $bt_pass);
1064 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1065 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1068 BakerTaylorContentURL
=>
1069 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1070 $bt_user,$bt_pass,$isbn)
1076 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1079 TagsShowOnDetail
=> $tag_quantity,
1080 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1082 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1083 'sort'=>'-weight', limit
=>$tag_quantity}));
1086 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1087 # These values are going to be read by Javascript, at least in the case
1088 # of the google covers
1089 $template->param(covernewwindow
=> 'true');
1091 $template->param(covernewwindow
=> 'false');
1094 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1095 my $ratings = Koha
::Ratings
->search({ biblionumber
=> $biblionumber });
1096 my $my_rating = $borrowernumber ?
$ratings->search({ borrowernumber
=> $borrowernumber })->next : undef;
1098 ratings
=> $ratings,
1099 my_rating
=> $my_rating,
1100 borrowernumber
=> $borrowernumber
1104 #Search for title in links
1105 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1106 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1107 my $issn = $marcissns->[0] || '';
1109 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1110 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1111 $dat->{title
} =~ s/\s+$//; # remove trailing space
1112 $search_for_title = parametrized_url
(
1115 TITLE
=> $dat->{title
},
1116 AUTHOR
=> $dat->{author
},
1119 CONTROLNUMBER
=> $marccontrolnumber,
1120 BIBLIONUMBER
=> $biblionumber,
1123 $template->param('OPACSearchForTitleIn' => $search_for_title);
1127 if ( C4
::Context
->preference("IDREF") ) {
1128 # If the record comes from the SUDOC
1129 if ( $record->field('009') ) {
1130 my $unimarc3 = $record->field("009")->data;
1131 if ( $unimarc3 =~ /^\d+$/ ) {
1139 # We try to select the best default tab to show, according to what
1140 # the user wants, and what's available for display
1141 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1145 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1147 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1148 ?
'serialcollection' :
1149 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1151 scalar (@itemloop) == 0
1153 $subscriptionsnumber
1155 @serialcollections > 0
1156 ?
'serialcollection' : 'subscriptions';
1157 $template->param('defaulttab' => $defaulttab);
1159 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1160 my @images = ListImagesForBiblio
($biblionumber);
1161 $template->{VARS
}->{localimages
} = \
@images;
1164 $template->{VARS
}->{IDreamBooksReviews
} = C4
::Context
->preference('IDreamBooksReviews');
1165 $template->{VARS
}->{IDreamBooksReadometer
} = C4
::Context
->preference('IDreamBooksReadometer');
1166 $template->{VARS
}->{IDreamBooksResults
} = C4
::Context
->preference('IDreamBooksResults');
1167 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1169 if (C4
::Context
->preference('OpacHighlightedWords')) {
1170 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1172 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1174 if ( C4
::Context
->preference('UseCourseReserves') ) {
1175 foreach my $i ( @items ) {
1176 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1181 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay') ,
1182 'OpacLocationBranchToDisplayShelving' => C4
::Context
->preference('OpacLocationBranchToDisplayShelving'),
1185 output_html_with_http_headers
$query, $cookie, $template->output;