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
::BakerTaylor
qw( image_url link_url );
38 use C4
::External
::Syndetics
qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
47 use List
::MoreUtils qw
/any none/;
51 use C4
::CourseReserves
qw(GetItemCourseReservesInfo);
54 use Koha
::RecordProcessor
;
55 use Koha
::AuthorisedValues
;
56 use Koha
::CirculationRules
;
59 use Koha
::Acquisition
::Orders
;
60 use Koha
::Virtualshelves
;
65 use Koha
::SearchEngine
::Search
;
69 my $query = CGI
->new();
71 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
72 $biblionumber = int($biblionumber);
74 my $specific_item = $query->param('itemnumber') ? Koha
::Items
->find( scalar $query->param('itemnumber') ) : undef;
75 $biblionumber = $specific_item->biblionumber if $specific_item;
77 my ( $template, $borrowernumber, $cookie ) = get_template_and_user
(
79 template_name
=> "opac-detail.tt",
82 authnotrequired
=> ( C4
::Context
->preference("OpacPublic") ?
1 : 0 ),
86 my @all_items = GetItemsInfo
($biblionumber);
87 if( $specific_item ) {
88 @all_items = grep { $_->{itemnumber
} == $query->param('itemnumber') } @all_items;
89 $template->param( specific_item
=> 1 );
92 my $patron = Koha
::Patrons
->find( $borrowernumber );
94 if ( C4
::Context
->preference('OpacHiddenItemsExceptions') ) {
95 $borcat = $patron ?
$patron->categorycode : q{};
98 my $record = GetMarcBiblio
({
99 biblionumber
=> $biblionumber,
102 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
106 if ( scalar @all_items >= 1 ) {
108 GetHiddenItemnumbers
( { items
=> \
@all_items, borcat
=> $borcat } );
110 if (scalar @hiddenitems == scalar @all_items ) {
111 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
116 my $biblio = Koha
::Biblios
->find( $biblionumber );
117 my $framework = $biblio ?
$biblio->frameworkcode : q{};
118 my $record_processor = Koha
::RecordProcessor
->new({
119 filters
=> 'ViewPolicy',
122 frameworkcode
=> $framework
125 $record_processor->process($record);
127 # redirect if opacsuppression is enabled and biblio is suppressed
128 if (C4
::Context
->preference('OpacSuppression')) {
129 # FIXME hardcoded; the suppression flag ought to be materialized
130 # as a column on biblio or the like
131 my $opacsuppressionfield = '942';
132 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
133 # redirect to opac-blocked info page or 404?
134 my $opacsuppressionredirect;
135 if ( C4
::Context
->preference("OpacSuppressionRedirect") ) {
136 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
138 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
140 if ( $opacsuppressionfieldvalue &&
141 $opacsuppressionfieldvalue->subfield("n") &&
142 $opacsuppressionfieldvalue->subfield("n") == 1) {
143 # if OPAC suppression by IP address
144 if (C4
::Context
->preference('OpacSuppressionByIPRange')) {
145 my $IPAddress = $ENV{'REMOTE_ADDR'};
146 my $IPRange = C4
::Context
->preference('OpacSuppressionByIPRange');
147 if ($IPAddress !~ /^$IPRange/) {
148 print $query->redirect($opacsuppressionredirect);
152 print $query->redirect($opacsuppressionredirect);
162 # get biblionumbers stored in the cart
165 if($query->cookie("bib_list")){
166 my $cart_list = $query->cookie("bib_list");
167 @cart_list = split(/\//, $cart_list);
168 if ( grep {$_ eq $biblionumber} @cart_list) {
169 $template->param( incart
=> 1 );
174 SetUTF8Flag
($record);
175 my $marcflavour = C4
::Context
->preference("marcflavour");
176 my $ean = GetNormalizedEAN
( $record, $marcflavour );
178 # XSLT processing of some stuff
179 my $xslfile = C4
::Context
->preference('OPACXSLTDetailsDisplay');
180 my $lang = $xslfile ? C4
::Languages
::getlanguage
() : undef;
181 my $sysxml = $xslfile ? C4
::XSLT
::get_xslt_sysprefs
() : undef;
185 my $searcher = Koha
::SearchEngine
::Search
->new(
186 { index => $Koha::SearchEngine
::BIBLIOS_INDEX
}
188 my $cleaned_title = $biblio->title;
189 $cleaned_title =~ tr
|/||;
191 ( C4
::Context
->preference('UseControlNumber') and $record->field('001') )
192 ?
'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
193 : "Host-item:$cleaned_title";
194 my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
196 warn "Warning from simple_search_compat: $err"
200 anonymous_session
=> ($borrowernumber) ?
0 : 1,
201 show_analytics_link
=> $count > 0 ?
1 : 0
204 my @plugin_responses = Koha
::Plugins
->call(
205 'opac_detail_xslt_variables',
207 biblio_id
=> $biblionumber,
209 patron_id
=> $borrowernumber
213 for my $plugin_variables ( @plugin_responses ) {
214 $variables = { %$variables, %$plugin_variables };
218 XSLTBloc
=> XSLTParse4Display
(
219 $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
220 $sysxml, $xslfile, $lang, $variables
225 my $OpacBrowseResults = C4
::Context
->preference("OpacBrowseResults");
227 # We look for the busc param to build the simple paging from the search
228 if ($OpacBrowseResults) {
229 my $session = get_session
($query->cookie("CGISESSID"));
230 my %paging = (previous
=> {}, next => {});
231 if ($session->param('busc')) {
235 # Rebuild the string to store on session
236 # param value is URI encoded and params separator is HTML encode (&)
239 my $arrParamsBusc = shift;
241 my $pasarParams = '';
243 for (keys %$arrParamsBusc) {
244 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
245 if (defined($arrParamsBusc->{$_})) {
246 $pasarParams .= '&' if ($j);
247 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
( $arrParamsBusc->{$_} ));
251 for my $value (@
{$arrParamsBusc->{$_}}) {
252 next if !defined($value);
253 $pasarParams .= '&' if ($j);
254 $pasarParams .= $_ . '=' . Encode
::decode
('UTF-8', uri_escape_utf8
($value));
262 # Search given the current values from the busc param
265 my ($arrParamsBusc, $offset, $results_per_page) = @_;
267 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
269 @servers = @
{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
270 @servers = ("biblioserver") unless (@servers);
272 my ($default_sort_by, @sort_by);
273 $default_sort_by = C4
::Context
->preference('OPACdefaultSortField')."_".C4
::Context
->preference('OPACdefaultSortOrder') if (C4
::Context
->preference('OPACdefaultSortField') && C4
::Context
->preference('OPACdefaultSortOrder'));
274 @sort_by = @
{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
275 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
276 my ($error, $results_hashref, $facets);
278 ($error, $results_hashref, $facets) = getRecords
($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\
@sort_by,\
@servers,$results_per_page,$offset,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
282 my $search_context = {
283 'interface' => 'opac',
284 'category' => $borcat
286 for (my $i=0;$i<@servers;$i++) {
287 my $server = $servers[$i];
288 $hits = $results_hashref->{$server}->{"hits"};
289 @newresults = searchResults
( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
294 # Build the current list of biblionumbers in this search
297 my ($newresultsRef, $results_per_page) = @_;
299 my $listBiblios = '';
301 foreach (@
$newresultsRef) {
302 my $bibnum = ($_->{biblionumber
})?
$_->{biblionumber
}:0;
303 $listBiblios .= $bibnum . ',';
305 last if ($j == $results_per_page);
307 chop $listBiblios if ($listBiblios =~ /,$/);
311 my $busc = $session->param("busc");
312 my @arrBusc = split(/\&(?:amp;)?/, $busc);
314 my %arrParamsBusc = ();
316 ($key, $value) = split(/=/, $_, 2);
317 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
318 $arrParamsBusc{$key} = uri_unescape
($value);
320 unless (exists($arrParamsBusc{$key})) {
321 $arrParamsBusc{$key} = [];
323 push @
{$arrParamsBusc{$key}}, uri_unescape
($value);
327 my $count = C4
::Context
->preference('OPACnumSearchResults') || 20;
328 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?
$arrParamsBusc{'count'}:$count;
329 $arrParamsBusc{'count'} = $results_per_page;
330 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?
$arrParamsBusc{'offset'}:0;
331 # The value OPACnumSearchResults has changed and the search has to be rebuild
332 if ($count != $results_per_page) {
333 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
335 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
336 for (@arrBibliosAux) {
337 last if ($_ == $biblionumber);
340 $indexBiblio += $offset;
341 $offset = int($indexBiblio / $count) * $count;
342 $arrParamsBusc{'offset'} = $offset;
344 $arrParamsBusc{'count'} = $count;
345 $results_per_page = $count;
346 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offset, $results_per_page);
347 $arrParamsBusc{'listBiblios'} = buildListBiblios
($newresultsRef, $results_per_page);
348 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
349 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
350 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
351 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
352 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
353 $session->param("busc" => $newbusc);
354 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
356 my $modifyListBiblios = 0;
357 # We come from a previous click
358 if (exists($arrParamsBusc{'previous'})) {
359 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
360 delete $arrParamsBusc{'previous'};
361 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
362 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
363 delete $arrParamsBusc{'next'};
365 if ($modifyListBiblios) {
366 if (exists($arrParamsBusc{'newlistBiblios'})) {
367 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
368 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
369 my @arrAux = split(',', $listBibliosAux);
370 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
371 if ($modifyListBiblios == 1) {
372 $arrParamsBusc{'next'} = $arrAux[0];
373 $paging{'next'}->{biblionumber
} = $arrAux[0];
375 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
376 $paging{'previous'}->{biblionumber
} = $arrAux[$#arrAux];
379 delete $arrParamsBusc{'listBiblios'};
381 my $offsetAux = $arrParamsBusc{'offset'};
382 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
383 $arrParamsBusc{'offsetSearch'} = $offsetAux;
384 $offset = $arrParamsBusc{'offset'};
385 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
386 $session->param("busc" => $newbusc);
387 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
392 # Rebuild the query for the button "back to results"
394 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
395 $buscParam .= '&' unless ($j == 0);
396 $buscParam .= $_; # string already URI encoded
400 $template->param('busc' => $buscParam);
403 # We are inside the list of biblios and we don't have to search
404 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
405 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
407 # We are at the first item of the list
408 if ($arrBiblios[0] == $biblionumber) {
409 if (@arrBiblios > 1) {
410 for (my $j = 1; $j < @arrBiblios; $j++) {
411 next unless ($arrBiblios[$j]);
412 $paging{'next'}->{biblionumber
} = $arrBiblios[$j];
416 # search again if we are not at the first searching list
417 if ($offset && !$arrParamsBusc{'previous'}) {
419 $offsetSearch = $offset - $results_per_page;
421 # we are at the last item of the list
422 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
423 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
424 next unless ($arrBiblios[$j]);
425 $paging{'previous'}->{biblionumber
} = $arrBiblios[$j];
429 # search again if we are at the first list and there is more results
430 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
432 # search again if we aren't at the first list and there is more results
433 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
435 $offsetSearch = $offset + $results_per_page if ($searchAgain);
437 for (my $j = 1; $j < $#arrBiblios; $j++) {
438 if ($arrBiblios[$j] == $biblionumber) {
439 for (my $z = $j - 1; $z >= 0; $z--) {
440 next unless ($arrBiblios[$z]);
441 $paging{'previous'}->{biblionumber
} = $arrBiblios[$z];
444 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
445 next unless ($arrBiblios[$z]);
446 $paging{'next'}->{biblionumber
} = $arrBiblios[$z];
454 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
457 my $newresultsRef = searchAgain
(\
%arrParamsBusc, $offsetSearch, $results_per_page);
458 my @newresults = @
$newresultsRef;
459 # build the new listBiblios
460 my $listBiblios = buildListBiblios
(\
@newresults, $results_per_page);
461 unless (exists($arrParamsBusc{'listBiblios'})) {
462 $arrParamsBusc{'listBiblios'} = $listBiblios;
463 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
465 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
467 # From the new list we build again the next and previous result
469 if ($arrBiblios[0] == $biblionumber) {
470 for (my $j = $#newresults; $j >= 0; $j--) {
471 next unless ($newresults[$j]);
472 $paging{'previous'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
473 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber
};
474 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
477 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
478 for (my $j = 0; $j < @newresults; $j++) {
479 next unless ($newresults[$j]);
480 $paging{'next'}->{biblionumber
} = $newresults[$j]->{biblionumber
};
481 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber
};
482 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
487 # build new busc param
488 my $newbusc = rebuildBuscParam
(\
%arrParamsBusc);
489 $session->param("busc" => $newbusc);
491 my ($numberBiblioPaging, $dataBiblioPaging);
493 $numberBiblioPaging = $paging{'previous'}->{biblionumber
};
494 if ($numberBiblioPaging) {
495 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
496 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
497 $template->param('previousTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
500 $numberBiblioPaging = $paging{'next'}->{biblionumber
};
501 if ($numberBiblioPaging) {
502 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
503 $dataBiblioPaging = Koha
::Biblios
->find( $numberBiblioPaging );
504 $template->param('nextTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
506 # Partial list of biblio results
508 for (my $j = 0; $j < @arrBiblios; $j++) {
509 next unless ($arrBiblios[$j]);
510 $dataBiblioPaging = Koha
::Biblios
->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber);
511 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]};
513 $template->param('listResults' => \
@listResults) if (@listResults);
514 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
515 $template->param( 'offset' => $offset );
520 OPACShowCheckoutName
=> C4
::Context
->preference("OPACShowCheckoutName"),
523 if ( C4
::Context
->preference('EasyAnalyticalRecords') ) {
524 # adding items linked via host biblios
525 my $analyticfield = '773';
526 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
527 $analyticfield = '773';
528 } elsif ($marcflavour eq 'UNIMARC') {
529 $analyticfield = '461';
531 foreach my $hostfield ( $record->field($analyticfield)) {
532 my $hostbiblionumber = $hostfield->subfield("0");
533 my $linkeditemnumber = $hostfield->subfield("9");
534 my @hostitemInfos = GetItemsInfo
($hostbiblionumber);
535 foreach my $hostitemInfo (@hostitemInfos){
536 if ($hostitemInfo->{itemnumber
} eq $linkeditemnumber){
537 push(@all_items, $hostitemInfo);
545 # Are there items to hide?
547 $hideitems = 1 if C4
::Context
->preference('hidelostitems') or scalar(@hiddenitems) > 0;
551 for my $itm (@all_items) {
552 if ( C4
::Context
->preference('hidelostitems') ) {
553 push @items, $itm unless $itm->{itemlost
} or any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
555 push @items, $itm unless any
{ $itm->{'itemnumber'} eq $_ } @hiddenitems;
564 if (C4
::Context
->userenv){
565 $branch = C4
::Context
->userenv->{branch
};
567 if ( C4
::Context
->preference('HighlightOwnItemsOnOPAC') ) {
569 ( ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
571 C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
574 if ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
575 $branchcode = $branch;
577 elsif ( C4
::Context
->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
578 $branchcode = $ENV{'BRANCHCODE'};
584 foreach my $item ( @items ) {
585 if ( $item->{branchcode
} eq $branchcode ) {
586 $item->{'this_branch'} = 1;
587 push( @our_items, $item );
589 push( @other_items, $item );
593 @items = ( @our_items, @other_items );
597 my $dat = &GetBiblioData
($biblionumber);
598 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
600 frameworkcode
=> $dat->{'frameworkcode'},
604 my $itemtypes = { map { $_->{itemtype
} => $_ } @
{ Koha
::ItemTypes
->search_with_localization->unblessed } };
606 my $itemtype = $dat->{'itemtype'};
608 $dat->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
609 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description
};
613 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.location' } ) };
615 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.ccode' } ) };
617 { map { $_->{authorised_value
} => $_->{opac_description
} } Koha
::AuthorisedValues
->get_descriptions_by_koha_field( { frameworkcode
=> $dat->{frameworkcode
}, kohafield
=> 'items.copynumber' } ) };
619 #coping with subscriptions
620 my $subscriptionsnumber = CountSubscriptionFromBiblionumber
($biblionumber);
621 my @subscriptions = SearchSubscriptions
({ biblionumber
=> $biblionumber, orderby
=> 'title' });
624 $dat->{'serial'}=1 if $subscriptionsnumber;
625 foreach my $subscription (@subscriptions) {
626 my $serials_to_display;
628 $cell{subscriptionid
} = $subscription->{subscriptionid
};
629 $cell{subscriptionnotes
} = $subscription->{notes
};
630 $cell{missinglist
} = $subscription->{missinglist
};
631 $cell{opacnote
} = $subscription->{opacnote
};
632 $cell{histstartdate
} = $subscription->{histstartdate
};
633 $cell{histenddate
} = $subscription->{histenddate
};
634 $cell{branchcode
} = $subscription->{branchcode
};
635 $cell{callnumber
} = $subscription->{callnumber
};
636 $cell{location
} = $subscription->{location
};
637 $cell{closed
} = $subscription->{closed
};
638 $cell{letter
} = $subscription->{letter
};
639 $cell{biblionumber
} = $subscription->{biblionumber
};
640 #get the three latest serials.
641 $serials_to_display = $subscription->{opacdisplaycount
};
642 $serials_to_display = C4
::Context
->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
643 $cell{opacdisplaycount
} = $serials_to_display;
644 $cell{latestserials
} =
645 GetLatestSerials
( $subscription->{subscriptionid
}, $serials_to_display );
646 if ( $borrowernumber ) {
647 my $subscription_object = Koha
::Subscriptions
->find( $subscription->{subscriptionid
} );
648 my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
649 $cell{hasalert
} = 1 if $subscriber;
654 $dat->{'count'} = scalar(@items);
657 my (%item_reserves, %priority);
658 my ($show_holds_count, $show_priority);
659 for ( C4
::Context
->preference("OPACShowHoldQueueDetails") ) {
660 m/holds/o and $show_holds_count = 1;
661 m/priority/ and $show_priority = 1;
664 if ( $show_holds_count || $show_priority) {
665 my $holds = $biblio->holds;
666 $template->param( holds_count
=> $holds->count );
667 while ( my $hold = $holds->next ) {
668 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
669 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
672 ?
($priority{ $hold->itemnumber } = $hold->priority)
673 : ($template->param( priority
=> $hold->priority ));
677 $template->param( show_priority
=> $has_hold ) ;
681 my (@itemloop, @otheritemloop);
682 my $currentbranch = C4
::Context
->userenv ? C4
::Context
->userenv->{branch
} : undef;
683 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
684 $template->param(SeparateHoldings
=> 1);
686 my $separatebranch = C4
::Context
->preference('OpacSeparateHoldingsBranch');
687 my $viewallitems = $query->param('viewallitems');
688 my $max_items_to_display = C4
::Context
->preference('OpacMaxItemsToDisplay') // 50;
691 my ( @itemnumbers_on_order );
692 if ( C4
::Context
->preference('OPACAcquisitionDetails' ) ) {
693 my $orders = C4
::Acquisition
::SearchOrders
({
694 biblionumber
=> $biblionumber,
697 my $total_quantity = 0;
698 for my $order ( @
$orders ) {
699 my $order = Koha
::Acquisition
::Orders
->find( $order->{ordernumber
} );
700 my $basket = $order->basket;
701 if ( $basket->effective_create_items eq 'ordering' ) {
702 @itemnumbers_on_order = $order->items->get_column('itemnumber');
704 $total_quantity += $order->quantity;
706 $template->{VARS
}->{acquisition_details
} = {
707 total_quantity
=> $total_quantity,
711 my $allow_onshelf_holds;
712 if ( not $viewallitems and @items > $max_items_to_display ) {
715 items_count
=> scalar( @items ),
718 for my $itm (@items) {
719 my $item = Koha
::Items
->find( $itm->{itemnumber
} );
720 $itm->{holds_count
} = $item_reserves{ $itm->{itemnumber
} };
721 $itm->{priority
} = $priority{ $itm->{itemnumber
} };
724 && !$itm->{'withdrawn'}
725 && !$itm->{'itemlost'}
726 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
727 && !$itemtypes->{$itm->{'itype'}}->{notforloan
}
728 && $itm->{'itemnumber'};
730 $allow_onshelf_holds = Koha
::CirculationRules
->get_onshelfholds_policy( { item
=> $item, patron
=> $patron } )
731 unless $allow_onshelf_holds;
733 # get collection code description, too
734 my $ccode = $itm->{'ccode'};
735 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
736 my $copynumber = $itm->{'copynumber'};
737 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
738 if ( defined $itm->{'location'} ) {
739 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
741 if (exists $itm->{itype
} && defined($itm->{itype
}) && exists $itemtypes->{ $itm->{itype
} }) {
742 $itm->{'imageurl'} = getitemtypeimagelocation
( 'opac', $itemtypes->{ $itm->{itype
} }->{'imageurl'} );
743 $itm->{'description'} = $itemtypes->{ $itm->{itype
} }->{translated_description
};
745 foreach (qw(ccode materials enumchron copynumber itemnotes location_description uri)) {
746 $itemfields{$_} = 1 if ($itm->{$_});
749 my $reserve_status = C4
::Reserves
::GetReserveStatus
($itm->{itemnumber
});
750 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
751 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
753 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers
($itm->{itemnumber
});
754 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
755 $itm->{transfertwhen
} = $transfertwhen;
756 $itm->{transfertfrom
} = $transfertfrom;
757 $itm->{transfertto
} = $transfertto;
760 if ( C4
::Context
->preference('OPACAcquisitionDetails') ) {
762 if grep { $_ eq $itm->{itemnumber
} } @itemnumbers_on_order;
765 my $itembranch = $itm->{$separatebranch};
766 if ($currentbranch and C4
::Context
->preference('OpacSeparateHoldings')) {
767 if ($itembranch and $itembranch eq $currentbranch) {
768 push @itemloop, $itm;
770 push @otheritemloop, $itm;
773 push @itemloop, $itm;
778 if( $allow_onshelf_holds || CountItemsIssued
($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
779 $template->param( ReservableItems
=> 1 );
782 # Display only one tab if one items list is empty
783 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
784 $template->param(SeparateHoldings
=> 0);
785 if (scalar(@itemloop) == 0) {
786 @itemloop = @otheritemloop;
790 ## get notes and subjects from MARC record
791 if (!C4
::Context
->preference("OPACXSLTDetailsDisplay") ) {
792 my $marcisbnsarray = GetMarcISBN
($record,$marcflavour);
793 my $marcauthorsarray = GetMarcAuthors
($record,$marcflavour);
794 my $marcsubjctsarray = GetMarcSubjects
($record,$marcflavour);
795 my $marcseriesarray = GetMarcSeries
($record,$marcflavour);
796 my $marcurlsarray = GetMarcUrls
($record,$marcflavour);
799 MARCSUBJCTS
=> $marcsubjctsarray,
800 MARCAUTHORS
=> $marcauthorsarray,
801 MARCSERIES
=> $marcseriesarray,
802 MARCURLS
=> $marcurlsarray,
803 MARCISBNS
=> $marcisbnsarray,
807 my $marcnotesarray = GetMarcNotes
($record,$marcflavour,1);
809 if( C4
::Context
->preference('ArticleRequests') ) {
810 my $patron = $borrowernumber ? Koha
::Patrons
->find($borrowernumber) : undef;
811 my $itemtype = Koha
::ItemTypes
->find($biblio->itemtype);
812 my $artreqpossible = $patron
813 ?
$biblio->can_article_request( $patron )
815 ?
$itemtype->may_article_request
817 $template->param( artreqpossible
=> $artreqpossible );
821 MARCNOTES
=> $marcnotesarray,
822 norequests
=> $norequests,
823 RequestOnOpac
=> C4
::Context
->preference("RequestOnOpac"),
824 itemdata_ccode
=> $itemfields{ccode
},
825 itemdata_materials
=> $itemfields{materials
},
826 itemdata_enumchron
=> $itemfields{enumchron
},
827 itemdata_uri
=> $itemfields{uri
},
828 itemdata_copynumber
=> $itemfields{copynumber
},
829 itemdata_itemnotes
=> $itemfields{itemnotes
},
830 itemdata_location
=> $itemfields{location_description
},
831 OpacStarRatings
=> C4
::Context
->preference("OpacStarRatings"),
834 if (C4
::Context
->preference("AlternateHoldingsField") && scalar @items == 0) {
835 my $fieldspec = C4
::Context
->preference("AlternateHoldingsField");
836 my $subfields = substr $fieldspec, 3;
837 my $holdingsep = C4
::Context
->preference("AlternateHoldingsSeparator") || ' ';
838 my @alternateholdingsinfo = ();
839 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
841 for my $field (@holdingsfields) {
842 my %holding = ( holding
=> '' );
843 my $havesubfield = 0;
844 for my $subfield ($field->subfields()) {
845 if ((index $subfields, $$subfield[0]) >= 0) {
846 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
847 $holding{'holding'} .= $$subfield[1];
852 push(@alternateholdingsinfo, \
%holding);
857 ALTERNATEHOLDINGS
=> \
@alternateholdingsinfo,
861 # FIXME: The template uses this hash directly. Need to filter.
862 foreach ( keys %{$dat} ) {
863 next if ( $HideMARC->{$_} );
864 $template->param( "$_" => defined $dat->{$_} ?
$dat->{$_} : '' );
867 # some useful variables for enhanced content;
868 # in each case, we're grabbing the first value we find in
869 # the record and normalizing it
870 my $upc = GetNormalizedUPC
($record,$marcflavour);
871 my $oclc = GetNormalizedOCLCNumber
($record,$marcflavour);
872 my $isbn = GetNormalizedISBN
(undef,$record,$marcflavour);
873 my $content_identifier_exists;
874 if ( $isbn or $ean or $oclc or $upc ) {
875 $content_identifier_exists = 1;
878 normalized_upc
=> $upc,
879 normalized_ean
=> $ean,
880 normalized_oclc
=> $oclc,
881 normalized_isbn
=> $isbn,
882 content_identifier_exists
=> $content_identifier_exists,
885 # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid
886 # COinS format FIXME: for books Only
887 my $coins = eval { $biblio->get_coins };
888 $template->param( ocoins
=> $coins );
890 my ( $loggedincommenter, $reviews );
891 if ( C4
::Context
->preference('reviewson') ) {
892 $reviews = Koha
::Reviews
->search(
894 biblionumber
=> $biblionumber,
895 -or => { approved
=> 1, borrowernumber
=> $borrowernumber }
898 order_by
=> { -desc
=> 'datereviewed' }
901 my $libravatar_enabled = 0;
902 if ( C4
::Context
->preference('ShowReviewer') and C4
::Context
->preference('ShowReviewerPhoto') ) {
904 require Libravatar
::URL
;
905 Libravatar
::URL
->import();
908 $libravatar_enabled = 1;
911 for my $review (@
$reviews) {
912 my $review_patron = Koha
::Patrons
->find( $review->{borrowernumber
} ); # FIXME Should be Koha::Review->reviewer or similar
914 # setting some borrower info into this hash
915 if ( $review_patron ) {
916 $review->{patron
} = $review_patron;
917 if ( $libravatar_enabled and $review_patron->email ) {
918 $review->{avatarurl
} = libravatar_url
( email
=> $review_patron->email, https
=> $ENV{HTTPS
} );
921 if ( $review_patron->borrowernumber eq $borrowernumber ) {
922 $loggedincommenter = 1;
928 if ( C4
::Context
->preference("OPACISBD") ) {
929 $template->param( ISBD
=> 1 );
933 itemloop
=> \
@itemloop,
934 otheritemloop
=> \
@otheritemloop,
935 biblionumber
=> $biblionumber,
936 subscriptions
=> \
@subs,
937 subscriptionsnumber
=> $subscriptionsnumber,
939 loggedincommenter
=> $loggedincommenter
943 if (C4
::Context
->preference("virtualshelves") ) {
944 my $shelves = Koha
::Virtualshelves
->search(
946 biblionumber
=> $biblionumber,
950 join => 'virtualshelfcontents',
953 $template->param( shelves
=> $shelves );
957 if (C4
::Context
->preference("OPACFRBRizeEditions")==1) {
960 XISBNS
=> scalar get_xisbns
($isbn, $biblionumber)
963 if ($@
) { warn "XISBN Failed $@"; }
967 my @sc_fields = $record->field(955);
968 my @lc_fields = $marcflavour eq 'UNIMARC'
969 ?
$record->field(930)
970 : $record->field(852);
971 my @serialcollections = ();
973 foreach my $sc_field (@sc_fields) {
976 $row_data{text
} = $sc_field->subfield('r');
977 $row_data{branch
} = $sc_field->subfield('9');
978 foreach my $lc_field (@lc_fields) {
979 $row_data{itemcallnumber
} = $marcflavour eq 'UNIMARC'
980 ?
$lc_field->subfield('a') # 930$a
981 : $lc_field->subfield('h') # 852$h
982 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
985 if ($row_data{text
} && $row_data{branch
}) {
986 push (@serialcollections, \
%row_data);
990 if (scalar(@serialcollections) > 0) {
992 serialcollection
=> 1,
993 serialcollections
=> \
@serialcollections);
996 # Local cover Images stuff
997 if (C4
::Context
->preference("OPACLocalCoverImages")){
998 $template->param(OPACLocalCoverImages
=> 1);
1002 if ( (C4
::Context
->preference("HTML5MediaEnabled") eq 'both') or (C4
::Context
->preference("HTML5MediaEnabled") eq 'opac') ) {
1003 $template->param( C4
::HTML5Media
->gethtml5media($record));
1006 my $syndetics_elements;
1008 if ( C4
::Context
->preference("SyndeticsEnabled") ) {
1009 $template->param("SyndeticsEnabled" => 1);
1010 $template->param("SyndeticsClientCode" => C4
::Context
->preference("SyndeticsClientCode"));
1012 $syndetics_elements = &get_syndetics_index
($isbn,$upc,$oclc);
1013 for my $element (values %$syndetics_elements) {
1014 $template->param("Syndetics$element"."Exists" => 1 );
1015 #warn "Exists: "."Syndetics$element"."Exists";
1021 if ( C4
::Context
->preference("SyndeticsEnabled")
1022 && C4
::Context
->preference("SyndeticsSummary")
1023 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
1025 my $syndetics_summary = &get_syndetics_summary
($isbn,$upc,$oclc, $syndetics_elements);
1026 $template->param( SYNDETICS_SUMMARY
=> $syndetics_summary );
1032 if ( C4
::Context
->preference("SyndeticsEnabled")
1033 && C4
::Context
->preference("SyndeticsTOC")
1034 && exists($syndetics_elements->{'TOC'}) ) {
1036 my $syndetics_toc = &get_syndetics_toc
($isbn,$upc,$oclc);
1037 $template->param( SYNDETICS_TOC
=> $syndetics_toc );
1042 if ( C4
::Context
->preference("SyndeticsEnabled")
1043 && C4
::Context
->preference("SyndeticsExcerpt")
1044 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
1046 my $syndetics_excerpt = &get_syndetics_excerpt
($isbn,$upc,$oclc);
1047 $template->param( SYNDETICS_EXCERPT
=> $syndetics_excerpt );
1052 if ( C4
::Context
->preference("SyndeticsEnabled")
1053 && C4
::Context
->preference("SyndeticsReviews")) {
1055 my $syndetics_reviews = &get_syndetics_reviews
($isbn,$upc,$oclc,$syndetics_elements);
1056 $template->param( SYNDETICS_REVIEWS
=> $syndetics_reviews );
1061 if ( C4
::Context
->preference("SyndeticsEnabled")
1062 && C4
::Context
->preference("SyndeticsAuthorNotes")
1063 && exists($syndetics_elements->{'ANOTES'}) ) {
1065 my $syndetics_anotes = &get_syndetics_anotes
($isbn,$upc,$oclc);
1066 $template->param( SYNDETICS_ANOTES
=> $syndetics_anotes );
1071 # LibraryThingForLibraries ID Code and Tabbed View Option
1072 if( C4
::Context
->preference('LibraryThingForLibrariesEnabled') )
1074 $template->param(LibraryThingForLibrariesID
=>
1075 C4
::Context
->preference('LibraryThingForLibrariesID') );
1076 $template->param(LibraryThingForLibrariesTabbedView
=>
1077 C4
::Context
->preference('LibraryThingForLibrariesTabbedView') );
1081 if( C4
::Context
->preference('NovelistSelectEnabled') )
1083 $template->param(NovelistSelectProfile
=> C4
::Context
->preference('NovelistSelectProfile') );
1084 $template->param(NovelistSelectPassword
=> C4
::Context
->preference('NovelistSelectPassword') );
1085 $template->param(NovelistSelectView
=> C4
::Context
->preference('NovelistSelectView') );
1090 if ( C4
::Context
->preference("Babeltheque") ) {
1093 Babeltheque_url_js
=> C4
::Context
->preference("Babeltheque_url_js"),
1098 if ( C4
::Context
->preference( "SocialNetworks" ) ) {
1099 $template->param( current_url
=> C4
::Context
->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1100 $template->param( SocialNetworks
=> 1 );
1103 # Shelf Browser Stuff
1104 if (C4
::Context
->preference("OPACShelfBrowser")) {
1105 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1106 if (defined($starting_itemnumber)) {
1107 $template->param( OpenOPACShelfBrowser
=> 1) if $starting_itemnumber;
1108 my $nearby = GetNearbyItems
($starting_itemnumber);
1111 starting_itemnumber
=> $starting_itemnumber,
1112 starting_homebranch
=> $nearby->{starting_homebranch
}->{description
},
1113 starting_location
=> $nearby->{starting_location
}->{description
},
1114 starting_ccode
=> $nearby->{starting_ccode
}->{description
},
1115 shelfbrowser_prev_item
=> $nearby->{prev_item
},
1116 shelfbrowser_next_item
=> $nearby->{next_item
},
1117 shelfbrowser_items
=> $nearby->{items
},
1120 # in which tab shelf browser should open ?
1121 if (grep { $starting_itemnumber == $_->{itemnumber
} } @itemloop) {
1122 $template->param(shelfbrowser_tab
=> 'holdings');
1124 $template->param(shelfbrowser_tab
=> 'otherholdings');
1129 $template->param( AmazonTld
=> get_amazon_tld
() ) if ( C4
::Context
->preference("OPACAmazonCoverImages"));
1131 if (C4
::Context
->preference("BakerTaylorEnabled")) {
1133 BakerTaylorEnabled
=> 1,
1134 BakerTaylorImageURL
=> &image_url
(),
1135 BakerTaylorLinkURL
=> &link_url
(),
1136 BakerTaylorBookstoreURL
=> C4
::Context
->preference('BakerTaylorBookstoreURL'),
1138 my ($bt_user, $bt_pass);
1140 $bt_user = C4
::Context
->preference('BakerTaylorUsername') and
1141 $bt_pass = C4
::Context
->preference('BakerTaylorPassword') )
1144 BakerTaylorContentURL
=>
1145 sprintf("https://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1146 $bt_user,$bt_pass,$isbn)
1152 if (C4
::Context
->preference('TagsEnabled') and $tag_quantity = C4
::Context
->preference('TagsShowOnDetail')) {
1155 TagsShowOnDetail
=> $tag_quantity,
1156 TagsInputOnDetail
=> C4
::Context
->preference('TagsInputOnDetail')
1158 $template->param(TagLoop
=> get_tags
({biblionumber
=>$biblionumber, approved
=>1,
1159 'sort'=>'-weight', limit
=>$tag_quantity}));
1162 if (C4
::Context
->preference("OPACURLOpenInNewWindow")) {
1163 # These values are going to be read by Javascript, at least in the case
1164 # of the google covers
1165 $template->param(covernewwindow
=> 'true');
1167 $template->param(covernewwindow
=> 'false');
1170 $template->param(borrowernumber
=> $borrowernumber);
1172 if ( C4
::Context
->preference('OpacStarRatings') !~ /disable/ ) {
1173 my $ratings = Koha
::Ratings
->search({ biblionumber
=> $biblionumber });
1174 my $my_rating = $borrowernumber ?
$ratings->search({ borrowernumber
=> $borrowernumber })->next : undef;
1176 ratings
=> $ratings,
1177 my_rating
=> $my_rating,
1181 #Search for title in links
1182 my $marccontrolnumber = GetMarcControlnumber
($record, $marcflavour);
1183 my $marcissns = GetMarcISSN
( $record, $marcflavour );
1184 my $issn = $marcissns->[0] || '';
1186 if (my $search_for_title = C4
::Context
->preference('OPACSearchForTitleIn')){
1187 $dat->{title
} =~ s/\/+$//; # remove trailing slash
1188 $dat->{title
} =~ s/\s+$//; # remove trailing space
1189 $search_for_title = parametrized_url
(
1192 TITLE
=> $dat->{title
},
1193 AUTHOR
=> $dat->{author
},
1196 CONTROLNUMBER
=> $marccontrolnumber,
1197 BIBLIONUMBER
=> $biblionumber,
1200 $template->param('OPACSearchForTitleIn' => $search_for_title);
1204 if ( C4
::Context
->preference("IDREF") ) {
1205 # If the record comes from the SUDOC
1206 if ( $record->field('009') ) {
1207 my $unimarc3 = $record->field("009")->data;
1208 if ( $unimarc3 =~ /^\d+$/ ) {
1216 # We try to select the best default tab to show, according to what
1217 # the user wants, and what's available for display
1218 my $opac_serial_default = C4
::Context
->preference('opacSerialDefaultTab');
1222 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1224 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1225 ?
'serialcollection' :
1226 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1228 scalar (@itemloop) == 0
1230 $subscriptionsnumber
1232 @serialcollections > 0
1233 ?
'serialcollection' : 'subscriptions';
1234 $template->param('defaulttab' => $defaulttab);
1236 if (C4
::Context
->preference('OPACLocalCoverImages') == 1) {
1237 my @images = ListImagesForBiblio
($biblionumber);
1238 $template->{VARS
}->{localimages
} = \
@images;
1241 $template->{VARS
}->{OPACPopupAuthorsSearch
} = C4
::Context
->preference('OPACPopupAuthorsSearch');
1243 if (C4
::Context
->preference('OpacHighlightedWords')) {
1244 $template->{VARS
}->{query_desc
} = $query->param('query_desc');
1246 $template->{VARS
}->{'trackclicks'} = C4
::Context
->preference('TrackClicks');
1248 if ( C4
::Context
->preference('UseCourseReserves') ) {
1249 foreach my $i ( @items ) {
1250 $i->{'course_reserves'} = GetItemCourseReservesInfo
( itemnumber
=> $i->{'itemnumber'} );
1255 'OpacLocationBranchToDisplay' => C4
::Context
->preference('OpacLocationBranchToDisplay'),
1258 output_html_with_http_headers
$query, $cookie, $template->output;