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 under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License along
19 # with Koha; if not, write to the Free Software Foundation, Inc.,
20 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use C4::Auth qw(:DEFAULT get_session);
30 use C4::Serials; #uses getsubscriptionfrom biblionumber
35 use C4::Tags qw(get_tags);
36 use C4::XISBN qw(get_xisbns get_biblionumber_from_isbn);
37 use C4::External::Amazon;
38 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
42 use C4::VirtualShelves;
49 use List::MoreUtils qw/any none/;
53 use C4::CourseReserves qw(GetItemCourseReservesInfo);
56 if (C4::Context->preference('BakerTaylorEnabled')) {
57 require C4::External::BakerTaylor;
58 import C4::External::BakerTaylor qw(&image_url &link_url);
63 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
65 template_name => "opac-detail.tmpl",
68 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
69 flagsrequired => { borrow => 1 },
73 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
74 $biblionumber = int($biblionumber);
76 my @all_items = GetItemsInfo($biblionumber);
78 if (scalar @all_items >= 1) {
79 push @hiddenitems, GetHiddenItemnumbers(@all_items);
81 if (scalar @hiddenitems == scalar @all_items ) {
82 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
87 my $record = GetMarcBiblio($biblionumber);
89 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
93 # redirect if opacsuppression is enabled and biblio is suppressed
94 if (C4::Context->preference('OpacSuppression')) {
95 # FIXME hardcoded; the suppression flag ought to be materialized
96 # as a column on biblio or the like
97 my $opacsuppressionfield = '942';
98 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
99 # redirect to opac-blocked info page or 404?
100 my $opacsuppressionredirect;
101 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
102 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
104 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
106 if ( $opacsuppressionfieldvalue &&
107 $opacsuppressionfieldvalue->subfield("n") &&
108 $opacsuppressionfieldvalue->subfield("n") == 1) {
109 # if OPAC suppression by IP address
110 if (C4::Context->preference('OpacSuppressionByIPRange')) {
111 my $IPAddress = $ENV{'REMOTE_ADDR'};
112 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
113 if ($IPAddress !~ /^$IPRange/) {
114 print $query->redirect($opacsuppressionredirect);
118 print $query->redirect($opacsuppressionredirect);
124 $template->param( biblionumber => $biblionumber );
126 # get biblionumbers stored in the cart
129 if($query->cookie("bib_list")){
130 my $cart_list = $query->cookie("bib_list");
131 @cart_list = split(/\//, $cart_list);
132 if ( grep {$_ eq $biblionumber} @cart_list) {
133 $template->param( incart => 1 );
138 SetUTF8Flag($record);
139 my $marcflavour = C4::Context->preference("marcflavour");
140 my $ean = GetNormalizedEAN( $record, $marcflavour );
142 # XSLT processing of some stuff
143 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
144 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
147 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
148 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
150 # We look for the busc param to build the simple paging from the search
151 if ($OpacBrowseResults) {
152 my $session = get_session($query->cookie("CGISESSID"));
153 my %paging = (previous => {}, next => {});
154 if ($session->param('busc')) {
157 # Rebuild the string to store on session
160 my $arrParamsBusc = shift;
162 my $pasarParams = '';
164 for (keys %$arrParamsBusc) {
165 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
166 if (defined($arrParamsBusc->{$_})) {
167 $pasarParams .= '&' if ($j);
168 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
172 for my $value (@{$arrParamsBusc->{$_}}) {
173 $pasarParams .= '&' if ($j);
174 $pasarParams .= $_ . '=' . $value;
182 # Search given the current values from the busc param
185 my ($arrParamsBusc, $offset, $results_per_page) = @_;
187 my $expanded_facet = $arrParamsBusc->{'expand'};
188 my $branches = GetBranches();
189 my $itemtypes = GetItemTypes;
191 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
192 @servers = ("biblioserver") unless (@servers);
194 my ($default_sort_by, @sort_by);
195 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
196 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
197 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
198 my ($error, $results_hashref, $facets);
200 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
204 for (my $i=0;$i<@servers;$i++) {
205 my $server = $servers[$i];
206 $hits = $results_hashref->{$server}->{"hits"};
207 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
212 # Build the current list of biblionumbers in this search
215 my ($newresultsRef, $results_per_page) = @_;
217 my $listBiblios = '';
219 foreach (@$newresultsRef) {
220 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
221 $listBiblios .= $bibnum . ',';
223 last if ($j == $results_per_page);
225 chop $listBiblios if ($listBiblios =~ /,$/);
229 my $busc = $session->param("busc");
230 my @arrBusc = split(/\&(?:amp;)?/, $busc);
232 my %arrParamsBusc = ();
234 ($key, $value) = split(/=/, $_, 2);
235 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
236 $arrParamsBusc{$key} = $value;
238 unless (exists($arrParamsBusc{$key})) {
239 $arrParamsBusc{$key} = [];
241 push @{$arrParamsBusc{$key}}, $value;
245 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
246 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
247 $arrParamsBusc{'count'} = $results_per_page;
248 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
249 # The value OPACnumSearchResults has changed and the search has to be rebuild
250 if ($count != $results_per_page) {
251 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
253 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
254 for (@arrBibliosAux) {
255 last if ($_ == $biblionumber);
258 $indexBiblio += $offset;
259 $offset = int($indexBiblio / $count) * $count;
260 $arrParamsBusc{'offset'} = $offset;
262 $arrParamsBusc{'count'} = $count;
263 $results_per_page = $count;
264 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
265 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
266 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
267 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
268 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
269 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
270 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
271 $session->param("busc" => $newbusc);
272 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
274 my $modifyListBiblios = 0;
275 # We come from a previous click
276 if (exists($arrParamsBusc{'previous'})) {
277 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
278 delete $arrParamsBusc{'previous'};
279 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
280 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
281 delete $arrParamsBusc{'next'};
283 if ($modifyListBiblios) {
284 if (exists($arrParamsBusc{'newlistBiblios'})) {
285 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
286 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
287 my @arrAux = split(',', $listBibliosAux);
288 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
289 if ($modifyListBiblios == 1) {
290 $arrParamsBusc{'next'} = $arrAux[0];
291 $paging{'next'}->{biblionumber} = $arrAux[0];
293 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
294 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
297 delete $arrParamsBusc{'listBiblios'};
299 my $offsetAux = $arrParamsBusc{'offset'};
300 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
301 $arrParamsBusc{'offsetSearch'} = $offsetAux;
302 $offset = $arrParamsBusc{'offset'};
303 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
304 $session->param("busc" => $newbusc);
305 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
310 # Rebuild the query for the button "back to results"
312 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
313 $buscParam .= '&' unless ($j == 0);
318 $template->param('busc' => $buscParam);
321 # We are inside the list of biblios and we don't have to search
322 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
323 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
325 # We are at the first item of the list
326 if ($arrBiblios[0] == $biblionumber) {
327 if (@arrBiblios > 1) {
328 for (my $j = 1; $j < @arrBiblios; $j++) {
329 next unless ($arrBiblios[$j]);
330 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
334 # search again if we are not at the first searching list
335 if ($offset && !$arrParamsBusc{'previous'}) {
337 $offsetSearch = $offset - $results_per_page;
339 # we are at the last item of the list
340 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
341 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
342 next unless ($arrBiblios[$j]);
343 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
347 # search again if we are at the first list and there is more results
348 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
350 # search again if we aren't at the first list and there is more results
351 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
353 $offsetSearch = $offset + $results_per_page if ($searchAgain);
355 for (my $j = 1; $j < $#arrBiblios; $j++) {
356 if ($arrBiblios[$j] == $biblionumber) {
357 for (my $z = $j - 1; $z >= 0; $z--) {
358 next unless ($arrBiblios[$z]);
359 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
362 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
363 next unless ($arrBiblios[$z]);
364 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
372 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
375 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
376 my @newresults = @$newresultsRef;
377 # build the new listBiblios
378 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
379 unless (exists($arrParamsBusc{'listBiblios'})) {
380 $arrParamsBusc{'listBiblios'} = $listBiblios;
381 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
383 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
385 # From the new list we build again the next and previous result
387 if ($arrBiblios[0] == $biblionumber) {
388 for (my $j = $#newresults; $j >= 0; $j--) {
389 next unless ($newresults[$j]);
390 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
391 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
392 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
395 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
396 for (my $j = 0; $j < @newresults; $j++) {
397 next unless ($newresults[$j]);
398 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
399 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
400 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
405 # build new busc param
406 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
407 $session->param("busc" => $newbusc);
409 my ($numberBiblioPaging, $dataBiblioPaging);
411 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
412 if ($numberBiblioPaging) {
413 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
414 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
415 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
418 $numberBiblioPaging = $paging{'next'}->{biblionumber};
419 if ($numberBiblioPaging) {
420 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
421 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
422 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
424 # Partial list of biblio results
426 for (my $j = 0; $j < @arrBiblios; $j++) {
427 next unless ($arrBiblios[$j]);
428 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
429 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]};
431 $template->param('listResults' => \@listResults) if (@listResults);
432 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
438 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
439 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
443 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
444 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
446 # adding items linked via host biblios
448 my $analyticfield = '773';
449 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
450 $analyticfield = '773';
451 } elsif ($marcflavour eq 'UNIMARC') {
452 $analyticfield = '461';
454 foreach my $hostfield ( $record->field($analyticfield)) {
455 my $hostbiblionumber = $hostfield->subfield("0");
456 my $linkeditemnumber = $hostfield->subfield("9");
457 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
458 foreach my $hostitemInfo (@hostitemInfos){
459 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
460 push(@all_items, $hostitemInfo);
467 # Are there items to hide?
469 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
473 for my $itm (@all_items) {
474 if ( C4::Context->preference('hidelostitems') ) {
475 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
477 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
485 my $branches = GetBranches();
487 if (C4::Context->userenv){
488 $branch = C4::Context->userenv->{branch};
490 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
492 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
494 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
497 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
498 $branchname = $branches->{$branch}->{'branchname'};
500 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
501 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
507 foreach my $item ( @items ) {
508 if ( $item->{'branchname'} eq $branchname ) {
509 $item->{'this_branch'} = 1;
510 push( @our_items, $item );
512 push( @other_items, $item );
516 @items = ( @our_items, @other_items );
520 my $dat = &GetBiblioData($biblionumber);
522 my $itemtypes = GetItemTypes();
524 my $itemtype = $dat->{'itemtype'};
526 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
527 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
529 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
530 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
531 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
533 #coping with subscriptions
534 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
535 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
538 $dat->{'serial'}=1 if $subscriptionsnumber;
539 foreach my $subscription (@subscriptions) {
540 my $serials_to_display;
542 $cell{subscriptionid} = $subscription->{subscriptionid};
543 $cell{subscriptionnotes} = $subscription->{notes};
544 $cell{missinglist} = $subscription->{missinglist};
545 $cell{opacnote} = $subscription->{opacnote};
546 $cell{histstartdate} = $subscription->{histstartdate};
547 $cell{histenddate} = $subscription->{histenddate};
548 $cell{branchcode} = $subscription->{branchcode};
549 $cell{branchname} = GetBranchName($subscription->{branchcode});
550 $cell{hasalert} = $subscription->{hasalert};
551 $cell{callnumber} = $subscription->{callnumber};
552 $cell{closed} = $subscription->{closed};
553 #get the three latest serials.
554 $serials_to_display = $subscription->{opacdisplaycount};
555 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
556 $cell{opacdisplaycount} = $serials_to_display;
557 $cell{latestserials} =
558 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
562 $dat->{'count'} = scalar(@items);
565 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
567 my (%item_reserves, %priority);
568 my ($show_holds_count, $show_priority);
569 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
570 m/holds/o and $show_holds_count = 1;
571 m/priority/ and $show_priority = 1;
574 if ( $show_holds_count || $show_priority) {
575 my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
576 $template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
577 foreach (@$reserves) {
578 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
579 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
582 ? ($priority{ $_->{itemnumber} } = $_->{priority})
583 : ($template->param( priority => $_->{priority} ));
587 $template->param( show_priority => $has_hold ) ;
591 my (@itemloop, @otheritemloop);
592 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
593 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
594 $template->param(SeparateHoldings => 1);
596 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
597 my $viewallitems = $query->param('viewallitems');
598 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
599 if ( not $viewallitems and @items > $max_items_to_display ) {
602 items_count => scalar( @items ),
605 for my $itm (@items) {
606 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
607 $itm->{priority} = $priority{ $itm->{itemnumber} };
609 if ( (not $itm->{'withdrawn'} )
610 && (not $itm->{'itemlost'} )
611 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
612 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
613 && ($itm->{'itemnumber'} ) );
615 # get collection code description, too
616 my $ccode = $itm->{'ccode'};
617 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
618 my $copynumber = $itm->{'copynumber'};
619 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
620 if ( defined $itm->{'location'} ) {
621 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
623 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
624 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
625 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
627 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
628 $itemfields{$_} = 1 if ($itm->{$_});
631 # walk through the item-level authorised values and populate some images
632 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
633 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
635 if ( $itm->{'itemlost'} ) {
636 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
637 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
638 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
640 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
641 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
642 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
644 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
645 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
646 $itm->{transfertwhen} = $transfertwhen;
647 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
648 $itm->{transfertto} = $branches->{$transfertto}{branchname};
650 my $itembranch = $itm->{$separatebranch};
651 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
652 if ($itembranch and $itembranch eq $currentbranch) {
653 push @itemloop, $itm;
655 push @otheritemloop, $itm;
658 push @itemloop, $itm;
663 # Display only one tab if one items list is empty
664 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
665 $template->param(SeparateHoldings => 0);
666 if (scalar(@itemloop) == 0) {
667 @itemloop = @otheritemloop;
671 ## get notes and subjects from MARC record
672 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
673 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
674 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
675 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
676 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
677 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
678 my $marchostsarray = GetMarcHosts($record,$marcflavour);
681 MARCSUBJCTS => $marcsubjctsarray,
682 MARCAUTHORS => $marcauthorsarray,
683 MARCSERIES => $marcseriesarray,
684 MARCURLS => $marcurlsarray,
685 MARCISBNS => $marcisbnsarray,
686 MARCHOSTS => $marchostsarray,
690 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
691 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
694 MARCNOTES => $marcnotesarray,
695 norequests => $norequests,
696 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
697 itemdata_ccode => $itemfields{ccode},
698 itemdata_enumchron => $itemfields{enumchron},
699 itemdata_uri => $itemfields{uri},
700 itemdata_copynumber => $itemfields{copynumber},
701 itemdata_itemnotes => $itemfields{itemnotes},
702 authorised_value_images => $biblio_authorised_value_images,
703 subtitle => $subtitle,
704 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
707 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
708 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
709 my $subfields = substr $fieldspec, 3;
710 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
711 my @alternateholdingsinfo = ();
712 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
714 for my $field (@holdingsfields) {
715 my %holding = ( holding => '' );
716 my $havesubfield = 0;
717 for my $subfield ($field->subfields()) {
718 if ((index $subfields, $$subfield[0]) >= 0) {
719 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
720 $holding{'holding'} .= $$subfield[1];
725 push(@alternateholdingsinfo, \%holding);
730 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
734 foreach ( keys %{$dat} ) {
735 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
738 # some useful variables for enhanced content;
739 # in each case, we're grabbing the first value we find in
740 # the record and normalizing it
741 my $upc = GetNormalizedUPC($record,$marcflavour);
742 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
743 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
744 my $content_identifier_exists;
745 if ( $isbn or $ean or $oclc or $upc ) {
746 $content_identifier_exists = 1;
749 normalized_upc => $upc,
750 normalized_ean => $ean,
751 normalized_oclc => $oclc,
752 normalized_isbn => $isbn,
753 content_identifier_exists => $content_identifier_exists,
756 # COinS format FIXME: for books Only
758 ocoins => GetCOinSBiblio($record),
761 my $libravatar_enabled = 0;
762 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
764 require Libravatar::URL;
765 Libravatar::URL->import();
768 $libravatar_enabled = 1;
772 my $reviews = getreviews( $biblionumber, 1 );
773 my $loggedincommenter;
778 foreach ( @$reviews ) {
779 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
780 # setting some borrower info into this hash
781 $_->{title} = $borrowerData->{'title'};
782 $_->{surname} = $borrowerData->{'surname'};
783 $_->{firstname} = $borrowerData->{'firstname'};
784 if ($libravatar_enabled and $borrowerData->{'email'}) {
785 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
787 $_->{userid} = $borrowerData->{'userid'};
788 $_->{cardnumber} = $borrowerData->{'cardnumber'};
790 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
791 $_->{your_comment} = 1;
792 $loggedincommenter = 1;
797 if(C4::Context->preference("ISBD")) {
798 $template->param(ISBD => 1);
802 itemloop => \@itemloop,
803 otheritemloop => \@otheritemloop,
804 subscriptionsnumber => $subscriptionsnumber,
805 biblionumber => $biblionumber,
806 subscriptions => \@subs,
807 subscriptionsnumber => $subscriptionsnumber,
809 loggedincommenter => $loggedincommenter
814 if (C4::Context->preference("virtualshelves") ) {
815 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
820 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
823 XISBNS => get_xisbns($isbn)
826 if ($@) { warn "XISBN Failed $@"; }
830 my @sc_fields = $record->field(955);
831 my @lc_fields = $marcflavour eq 'UNIMARC'
832 ? $record->field(930)
833 : $record->field(852);
834 my @serialcollections = ();
836 foreach my $sc_field (@sc_fields) {
839 $row_data{text} = $sc_field->subfield('r');
840 $row_data{branch} = $sc_field->subfield('9');
841 foreach my $lc_field (@lc_fields) {
842 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
843 ? $lc_field->subfield('a') # 930$a
844 : $lc_field->subfield('h') # 852$h
845 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
848 if ($row_data{text} && $row_data{branch}) {
849 push (@serialcollections, \%row_data);
853 if (scalar(@serialcollections) > 0) {
855 serialcollection => 1,
856 serialcollections => \@serialcollections);
859 # Local cover Images stuff
860 if (C4::Context->preference("OPACLocalCoverImages")){
861 $template->param(OPACLocalCoverImages => 1);
865 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
866 $template->param( C4::HTML5Media->gethtml5media($record));
869 my $syndetics_elements;
871 if ( C4::Context->preference("SyndeticsEnabled") ) {
872 $template->param("SyndeticsEnabled" => 1);
873 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
875 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
876 for my $element (values %$syndetics_elements) {
877 $template->param("Syndetics$element"."Exists" => 1 );
878 #warn "Exists: "."Syndetics$element"."Exists";
884 if ( C4::Context->preference("SyndeticsEnabled")
885 && C4::Context->preference("SyndeticsSummary")
886 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
888 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
889 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
895 if ( C4::Context->preference("SyndeticsEnabled")
896 && C4::Context->preference("SyndeticsTOC")
897 && exists($syndetics_elements->{'TOC'}) ) {
899 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
900 $template->param( SYNDETICS_TOC => $syndetics_toc );
905 if ( C4::Context->preference("SyndeticsEnabled")
906 && C4::Context->preference("SyndeticsExcerpt")
907 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
909 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
910 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
915 if ( C4::Context->preference("SyndeticsEnabled")
916 && C4::Context->preference("SyndeticsReviews")) {
918 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
919 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
924 if ( C4::Context->preference("SyndeticsEnabled")
925 && C4::Context->preference("SyndeticsAuthorNotes")
926 && exists($syndetics_elements->{'ANOTES'}) ) {
928 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
929 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
934 # LibraryThingForLibraries ID Code and Tabbed View Option
935 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
937 $template->param(LibraryThingForLibrariesID =>
938 C4::Context->preference('LibraryThingForLibrariesID') );
939 $template->param(LibraryThingForLibrariesTabbedView =>
940 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
944 if( C4::Context->preference('NovelistSelectEnabled') )
946 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
947 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
948 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
953 if ( C4::Context->preference("Babeltheque") ) {
956 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
961 if ( C4::Context->preference( "SocialNetworks" ) ) {
962 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
963 $template->param( SocialNetworks => 1 );
966 # Shelf Browser Stuff
967 if (C4::Context->preference("OPACShelfBrowser")) {
968 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
969 if (defined($starting_itemnumber)) {
970 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
971 my $nearby = GetNearbyItems($starting_itemnumber);
974 starting_itemnumber => $starting_itemnumber,
975 starting_homebranch => $nearby->{starting_homebranch}->{description},
976 starting_location => $nearby->{starting_location}->{description},
977 starting_ccode => $nearby->{starting_ccode}->{description},
978 shelfbrowser_prev_item => $nearby->{prev_item},
979 shelfbrowser_next_item => $nearby->{next_item},
980 shelfbrowser_items => $nearby->{items},
983 # in which tab shelf browser should open ?
984 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
985 $template->param(shelfbrowser_tab => 'holdings');
987 $template->param(shelfbrowser_tab => 'otherholdings');
992 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
994 if (C4::Context->preference("BakerTaylorEnabled")) {
996 BakerTaylorEnabled => 1,
997 BakerTaylorImageURL => &image_url(),
998 BakerTaylorLinkURL => &link_url(),
999 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1001 my ($bt_user, $bt_pass);
1003 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1004 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1007 BakerTaylorContentURL =>
1008 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1009 $bt_user,$bt_pass,$isbn)
1015 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1018 TagsShowOnDetail => $tag_quantity,
1019 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1021 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1022 'sort'=>'-weight', limit=>$tag_quantity}));
1025 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1026 # These values are going to be read by Javascript, at least in the case
1027 # of the google covers
1028 $template->param(covernewwindow => 'true');
1030 $template->param(covernewwindow => 'false');
1034 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
1035 my @export_options = split(/\|/,$OpacExportOptions);
1036 $template->{VARS}->{'export_options'} = \@export_options;
1038 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1039 my $rating = GetRating( $biblionumber, $borrowernumber );
1041 rating_value => $rating->{'rating_value'},
1042 rating_total => $rating->{'rating_total'},
1043 rating_avg => $rating->{'rating_avg'},
1044 rating_avg_int => $rating->{'rating_avg_int'},
1045 borrowernumber => $borrowernumber
1049 #Search for title in links
1050 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1051 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1052 my $issn = $marcissns->[0] || '';
1054 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1055 $dat->{title} =~ s/\/+$//; # remove trailing slash
1056 $dat->{title} =~ s/\s+$//; # remove trailing space
1057 $search_for_title = parametrized_url(
1060 TITLE => $dat->{title},
1061 AUTHOR => $dat->{author},
1064 CONTROLNUMBER => $marccontrolnumber,
1065 BIBLIONUMBER => $biblionumber,
1068 $template->param('OPACSearchForTitleIn' => $search_for_title);
1071 # We try to select the best default tab to show, according to what
1072 # the user wants, and what's available for display
1073 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1075 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1077 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1078 ? 'serialcollection' :
1079 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1081 $subscriptionsnumber
1083 @serialcollections > 0
1084 ? 'serialcollection' : 'subscriptions';
1085 $template->param('defaulttab' => $defaulttab);
1087 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1088 my @images = ListImagesForBiblio($biblionumber);
1089 $template->{VARS}->{localimages} = \@images;
1092 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1093 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1094 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1095 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1097 if (C4::Context->preference('OpacHighlightedWords')) {
1098 $template->{VARS}->{query_desc} = $query->param('query_desc');
1100 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1102 if ( C4::Context->preference('UseCourseReserves') ) {
1103 foreach my $i ( @items ) {
1104 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1108 output_html_with_http_headers $query, $cookie, $template->output;