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 my $opacsuppressionfield = '942';
96 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
97 # redirect to opac-blocked info page or 404?
98 my $opacsuppressionredirect;
99 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
100 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
103 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
105 if ( $opacsuppressionfieldvalue->subfield("n") == 1) {
106 # if OPAC suppression by IP address
107 if (C4::Context->preference('OpacSuppressionByIPRange')) {
108 my $IPAddress = $ENV{'REMOTE_ADDR'};
109 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
110 if ($IPAddress !~ /^$IPRange/) {
111 print $query->redirect($opacsuppressionredirect);
116 print $query->redirect($opacsuppressionredirect);
122 $template->param( biblionumber => $biblionumber );
124 # get biblionumbers stored in the cart
127 if($query->cookie("bib_list")){
128 my $cart_list = $query->cookie("bib_list");
129 @cart_list = split(/\//, $cart_list);
130 if ( grep {$_ eq $biblionumber} @cart_list) {
131 $template->param( incart => 1 );
136 SetUTF8Flag($record);
137 my $marcflavour = C4::Context->preference("marcflavour");
138 my $ean = GetNormalizedEAN( $record, $marcflavour );
140 # XSLT processing of some stuff
141 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
142 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
145 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
146 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
148 # We look for the busc param to build the simple paging from the search
149 if ($OpacBrowseResults) {
150 my $session = get_session($query->cookie("CGISESSID"));
151 my %paging = (previous => {}, next => {});
152 if ($session->param('busc')) {
155 # Rebuild the string to store on session
158 my $arrParamsBusc = shift;
160 my $pasarParams = '';
162 for (keys %$arrParamsBusc) {
163 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
164 if (defined($arrParamsBusc->{$_})) {
165 $pasarParams .= '&' if ($j);
166 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
170 for my $value (@{$arrParamsBusc->{$_}}) {
171 $pasarParams .= '&' if ($j);
172 $pasarParams .= $_ . '=' . $value;
180 # Search given the current values from the busc param
183 my ($arrParamsBusc, $offset, $results_per_page) = @_;
185 my $expanded_facet = $arrParamsBusc->{'expand'};
186 my $branches = GetBranches();
187 my $itemtypes = GetItemTypes;
189 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
190 @servers = ("biblioserver") unless (@servers);
192 my ($default_sort_by, @sort_by);
193 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
194 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
195 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
196 my ($error, $results_hashref, $facets);
198 ($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'});
202 for (my $i=0;$i<@servers;$i++) {
203 my $server = $servers[$i];
204 $hits = $results_hashref->{$server}->{"hits"};
205 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
210 # Build the current list of biblionumbers in this search
213 my ($newresultsRef, $results_per_page) = @_;
215 my $listBiblios = '';
217 foreach (@$newresultsRef) {
218 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
219 $listBiblios .= $bibnum . ',';
221 last if ($j == $results_per_page);
223 chop $listBiblios if ($listBiblios =~ /,$/);
227 my $busc = $session->param("busc");
228 my @arrBusc = split(/\&(?:amp;)?/, $busc);
230 my %arrParamsBusc = ();
232 ($key, $value) = split(/=/, $_, 2);
233 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
234 $arrParamsBusc{$key} = $value;
236 unless (exists($arrParamsBusc{$key})) {
237 $arrParamsBusc{$key} = [];
239 push @{$arrParamsBusc{$key}}, $value;
243 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
244 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
245 $arrParamsBusc{'count'} = $results_per_page;
246 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
247 # The value OPACnumSearchResults has changed and the search has to be rebuild
248 if ($count != $results_per_page) {
249 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
251 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
252 for (@arrBibliosAux) {
253 last if ($_ == $biblionumber);
256 $indexBiblio += $offset;
257 $offset = int($indexBiblio / $count) * $count;
258 $arrParamsBusc{'offset'} = $offset;
260 $arrParamsBusc{'count'} = $count;
261 $results_per_page = $count;
262 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
263 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
264 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
265 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
266 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
267 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
268 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
269 $session->param("busc" => $newbusc);
270 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
272 my $modifyListBiblios = 0;
273 # We come from a previous click
274 if (exists($arrParamsBusc{'previous'})) {
275 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
276 delete $arrParamsBusc{'previous'};
277 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
278 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
279 delete $arrParamsBusc{'next'};
281 if ($modifyListBiblios) {
282 if (exists($arrParamsBusc{'newlistBiblios'})) {
283 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
284 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
285 my @arrAux = split(',', $listBibliosAux);
286 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
287 if ($modifyListBiblios == 1) {
288 $arrParamsBusc{'next'} = $arrAux[0];
289 $paging{'next'}->{biblionumber} = $arrAux[0];
291 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
292 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
295 delete $arrParamsBusc{'listBiblios'};
297 my $offsetAux = $arrParamsBusc{'offset'};
298 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
299 $arrParamsBusc{'offsetSearch'} = $offsetAux;
300 $offset = $arrParamsBusc{'offset'};
301 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
302 $session->param("busc" => $newbusc);
303 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
308 # Rebuild the query for the button "back to results"
310 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
311 $buscParam .= '&' unless ($j == 0);
316 $template->param('busc' => $buscParam);
319 # We are inside the list of biblios and we don't have to search
320 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
321 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
323 # We are at the first item of the list
324 if ($arrBiblios[0] == $biblionumber) {
325 if (@arrBiblios > 1) {
326 for (my $j = 1; $j < @arrBiblios; $j++) {
327 next unless ($arrBiblios[$j]);
328 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
332 # search again if we are not at the first searching list
333 if ($offset && !$arrParamsBusc{'previous'}) {
335 $offsetSearch = $offset - $results_per_page;
337 # we are at the last item of the list
338 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
339 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
340 next unless ($arrBiblios[$j]);
341 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
345 # search again if we are at the first list and there is more results
346 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
348 # search again if we aren't at the first list and there is more results
349 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
351 $offsetSearch = $offset + $results_per_page if ($searchAgain);
353 for (my $j = 1; $j < $#arrBiblios; $j++) {
354 if ($arrBiblios[$j] == $biblionumber) {
355 for (my $z = $j - 1; $z >= 0; $z--) {
356 next unless ($arrBiblios[$z]);
357 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
360 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
361 next unless ($arrBiblios[$z]);
362 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
370 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
373 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
374 my @newresults = @$newresultsRef;
375 # build the new listBiblios
376 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
377 unless (exists($arrParamsBusc{'listBiblios'})) {
378 $arrParamsBusc{'listBiblios'} = $listBiblios;
379 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
381 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
383 # From the new list we build again the next and previous result
385 if ($arrBiblios[0] == $biblionumber) {
386 for (my $j = $#newresults; $j >= 0; $j--) {
387 next unless ($newresults[$j]);
388 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
389 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
390 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
393 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
394 for (my $j = 0; $j < @newresults; $j++) {
395 next unless ($newresults[$j]);
396 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
397 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
398 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
403 # build new busc param
404 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
405 $session->param("busc" => $newbusc);
407 my ($numberBiblioPaging, $dataBiblioPaging);
409 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
410 if ($numberBiblioPaging) {
411 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
412 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
413 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
416 $numberBiblioPaging = $paging{'next'}->{biblionumber};
417 if ($numberBiblioPaging) {
418 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
419 $dataBiblioPaging = GetBiblioData($numberBiblioPaging);
420 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
422 # Partial list of biblio results
424 for (my $j = 0; $j < @arrBiblios; $j++) {
425 next unless ($arrBiblios[$j]);
426 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
427 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]};
429 $template->param('listResults' => \@listResults) if (@listResults);
430 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
436 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
437 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
441 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
442 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
444 # adding items linked via host biblios
446 my $analyticfield = '773';
447 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
448 $analyticfield = '773';
449 } elsif ($marcflavour eq 'UNIMARC') {
450 $analyticfield = '461';
452 foreach my $hostfield ( $record->field($analyticfield)) {
453 my $hostbiblionumber = $hostfield->subfield("0");
454 my $linkeditemnumber = $hostfield->subfield("9");
455 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
456 foreach my $hostitemInfo (@hostitemInfos){
457 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
458 push(@all_items, $hostitemInfo);
465 # Are there items to hide?
467 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
471 for my $itm (@all_items) {
472 if ( C4::Context->preference('hidelostitems') ) {
473 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
475 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
483 my $branches = GetBranches();
485 if (C4::Context->userenv){
486 $branch = C4::Context->userenv->{branch};
488 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
490 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
492 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
495 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
496 $branchname = $branches->{$branch}->{'branchname'};
498 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
499 $branchname = $branches->{ $ENV{'BRANCHCODE'} }->{'branchname'};
505 foreach my $item ( @items ) {
506 if ( $item->{'branchname'} eq $branchname ) {
507 $item->{'this_branch'} = 1;
508 push( @our_items, $item );
510 push( @other_items, $item );
514 @items = ( @our_items, @other_items );
518 my $dat = &GetBiblioData($biblionumber);
520 my $itemtypes = GetItemTypes();
522 my $itemtype = $dat->{'itemtype'};
524 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
525 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
527 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
528 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
529 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
531 #coping with subscriptions
532 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
533 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
536 $dat->{'serial'}=1 if $subscriptionsnumber;
537 foreach my $subscription (@subscriptions) {
538 my $serials_to_display;
540 $cell{subscriptionid} = $subscription->{subscriptionid};
541 $cell{subscriptionnotes} = $subscription->{notes};
542 $cell{missinglist} = $subscription->{missinglist};
543 $cell{opacnote} = $subscription->{opacnote};
544 $cell{histstartdate} = $subscription->{histstartdate};
545 $cell{histenddate} = $subscription->{histenddate};
546 $cell{branchcode} = $subscription->{branchcode};
547 $cell{branchname} = GetBranchName($subscription->{branchcode});
548 $cell{hasalert} = $subscription->{hasalert};
549 $cell{callnumber} = $subscription->{callnumber};
550 $cell{closed} = $subscription->{closed};
551 #get the three latest serials.
552 $serials_to_display = $subscription->{opacdisplaycount};
553 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
554 $cell{opacdisplaycount} = $serials_to_display;
555 $cell{latestserials} =
556 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
560 $dat->{'count'} = scalar(@items);
563 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
565 my (%item_reserves, %priority);
566 my ($show_holds_count, $show_priority);
567 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
568 m/holds/o and $show_holds_count = 1;
569 m/priority/ and $show_priority = 1;
572 if ( $show_holds_count || $show_priority) {
573 my $reserves = GetReservesFromBiblionumber({ biblionumber => $biblionumber, all_dates => 1 });
574 $template->param( holds_count => scalar( @$reserves ) ) if $show_holds_count;
575 foreach (@$reserves) {
576 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
577 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
580 ? ($priority{ $_->{itemnumber} } = $_->{priority})
581 : ($template->param( priority => $_->{priority} ));
585 $template->param( show_priority => $has_hold ) ;
589 my (@itemloop, @otheritemloop);
590 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
591 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
592 $template->param(SeparateHoldings => 1);
594 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
595 my $viewallitems = $query->param('viewallitems');
596 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
597 if ( not $viewallitems and @items > $max_items_to_display ) {
600 items_count => scalar( @items ),
603 for my $itm (@items) {
604 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
605 $itm->{priority} = $priority{ $itm->{itemnumber} };
607 if ( (not $itm->{'withdrawn'} )
608 && (not $itm->{'itemlost'} )
609 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
610 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
611 && ($itm->{'itemnumber'} ) );
613 # get collection code description, too
614 my $ccode = $itm->{'ccode'};
615 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
616 my $copynumber = $itm->{'copynumber'};
617 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
618 if ( defined $itm->{'location'} ) {
619 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
621 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
622 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
623 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
625 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
626 $itemfields{$_} = 1 if ($itm->{$_});
629 # walk through the item-level authorised values and populate some images
630 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
631 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
633 if ( $itm->{'itemlost'} ) {
634 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
635 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
636 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
638 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
639 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
640 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
642 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
643 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
644 $itm->{transfertwhen} = $transfertwhen;
645 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
646 $itm->{transfertto} = $branches->{$transfertto}{branchname};
648 my $itembranch = $itm->{$separatebranch};
649 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
650 if ($itembranch and $itembranch eq $currentbranch) {
651 push @itemloop, $itm;
653 push @otheritemloop, $itm;
656 push @itemloop, $itm;
661 # Display only one tab if one items list is empty
662 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
663 $template->param(SeparateHoldings => 0);
664 if (scalar(@itemloop) == 0) {
665 @itemloop = @otheritemloop;
669 ## get notes and subjects from MARC record
670 my $dbh = C4::Context->dbh;
671 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
672 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
673 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
674 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
675 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
676 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
677 my $marchostsarray = GetMarcHosts($record,$marcflavour);
678 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
681 MARCNOTES => $marcnotesarray,
682 MARCSUBJCTS => $marcsubjctsarray,
683 MARCAUTHORS => $marcauthorsarray,
684 MARCSERIES => $marcseriesarray,
685 MARCURLS => $marcurlsarray,
686 MARCISBNS => $marcisbnsarray,
687 MARCHOSTS => $marchostsarray,
688 norequests => $norequests,
689 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
690 itemdata_ccode => $itemfields{ccode},
691 itemdata_enumchron => $itemfields{enumchron},
692 itemdata_uri => $itemfields{uri},
693 itemdata_copynumber => $itemfields{copynumber},
694 itemdata_itemnotes => $itemfields{itemnotes},
695 authorised_value_images => $biblio_authorised_value_images,
696 subtitle => $subtitle,
697 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
700 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
701 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
702 my $subfields = substr $fieldspec, 3;
703 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
704 my @alternateholdingsinfo = ();
705 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
707 for my $field (@holdingsfields) {
708 my %holding = ( holding => '' );
709 my $havesubfield = 0;
710 for my $subfield ($field->subfields()) {
711 if ((index $subfields, $$subfield[0]) >= 0) {
712 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
713 $holding{'holding'} .= $$subfield[1];
718 push(@alternateholdingsinfo, \%holding);
723 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
727 foreach ( keys %{$dat} ) {
728 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
731 # some useful variables for enhanced content;
732 # in each case, we're grabbing the first value we find in
733 # the record and normalizing it
734 my $upc = GetNormalizedUPC($record,$marcflavour);
735 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
736 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
737 my $content_identifier_exists;
738 if ( $isbn or $ean or $oclc or $upc ) {
739 $content_identifier_exists = 1;
742 normalized_upc => $upc,
743 normalized_ean => $ean,
744 normalized_oclc => $oclc,
745 normalized_isbn => $isbn,
746 content_identifier_exists => $content_identifier_exists,
749 # COinS format FIXME: for books Only
751 ocoins => GetCOinSBiblio($record),
754 my $libravatar_enabled = 0;
755 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
757 require Libravatar::URL;
758 Libravatar::URL->import();
761 $libravatar_enabled = 1;
765 my $reviews = getreviews( $biblionumber, 1 );
766 my $loggedincommenter;
771 foreach ( @$reviews ) {
772 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
773 # setting some borrower info into this hash
774 $_->{title} = $borrowerData->{'title'};
775 $_->{surname} = $borrowerData->{'surname'};
776 $_->{firstname} = $borrowerData->{'firstname'};
777 if ($libravatar_enabled and $borrowerData->{'email'}) {
778 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
780 $_->{userid} = $borrowerData->{'userid'};
781 $_->{cardnumber} = $borrowerData->{'cardnumber'};
783 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
784 $_->{your_comment} = 1;
785 $loggedincommenter = 1;
790 if(C4::Context->preference("ISBD")) {
791 $template->param(ISBD => 1);
795 itemloop => \@itemloop,
796 otheritemloop => \@otheritemloop,
797 subscriptionsnumber => $subscriptionsnumber,
798 biblionumber => $biblionumber,
799 subscriptions => \@subs,
800 subscriptionsnumber => $subscriptionsnumber,
802 loggedincommenter => $loggedincommenter
807 if (C4::Context->preference("virtualshelves") ) {
808 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
813 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
816 XISBNS => get_xisbns($isbn)
819 if ($@) { warn "XISBN Failed $@"; }
823 my @sc_fields = $record->field(955);
824 my @lc_fields = $marcflavour eq 'UNIMARC'
825 ? $record->field(930)
826 : $record->field(852);
827 my @serialcollections = ();
829 foreach my $sc_field (@sc_fields) {
832 $row_data{text} = $sc_field->subfield('r');
833 $row_data{branch} = $sc_field->subfield('9');
834 foreach my $lc_field (@lc_fields) {
835 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
836 ? $lc_field->subfield('a') # 930$a
837 : $lc_field->subfield('h') # 852$h
838 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
841 if ($row_data{text} && $row_data{branch}) {
842 push (@serialcollections, \%row_data);
846 if (scalar(@serialcollections) > 0) {
848 serialcollection => 1,
849 serialcollections => \@serialcollections);
852 # Local cover Images stuff
853 if (C4::Context->preference("OPACLocalCoverImages")){
854 $template->param(OPACLocalCoverImages => 1);
858 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
859 $template->param( C4::HTML5Media->gethtml5media($record));
862 my $syndetics_elements;
864 if ( C4::Context->preference("SyndeticsEnabled") ) {
865 $template->param("SyndeticsEnabled" => 1);
866 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
868 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
869 for my $element (values %$syndetics_elements) {
870 $template->param("Syndetics$element"."Exists" => 1 );
871 #warn "Exists: "."Syndetics$element"."Exists";
877 if ( C4::Context->preference("SyndeticsEnabled")
878 && C4::Context->preference("SyndeticsSummary")
879 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
881 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
882 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
888 if ( C4::Context->preference("SyndeticsEnabled")
889 && C4::Context->preference("SyndeticsTOC")
890 && exists($syndetics_elements->{'TOC'}) ) {
892 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
893 $template->param( SYNDETICS_TOC => $syndetics_toc );
898 if ( C4::Context->preference("SyndeticsEnabled")
899 && C4::Context->preference("SyndeticsExcerpt")
900 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
902 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
903 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
908 if ( C4::Context->preference("SyndeticsEnabled")
909 && C4::Context->preference("SyndeticsReviews")) {
911 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
912 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
917 if ( C4::Context->preference("SyndeticsEnabled")
918 && C4::Context->preference("SyndeticsAuthorNotes")
919 && exists($syndetics_elements->{'ANOTES'}) ) {
921 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
922 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
927 # LibraryThingForLibraries ID Code and Tabbed View Option
928 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
930 $template->param(LibraryThingForLibrariesID =>
931 C4::Context->preference('LibraryThingForLibrariesID') );
932 $template->param(LibraryThingForLibrariesTabbedView =>
933 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
937 if( C4::Context->preference('NovelistSelectEnabled') )
939 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
940 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
941 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
946 if ( C4::Context->preference("Babeltheque") ) {
949 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
954 if ( C4::Context->preference( "SocialNetworks" ) ) {
955 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
956 $template->param( SocialNetworks => 1 );
959 # Shelf Browser Stuff
960 if (C4::Context->preference("OPACShelfBrowser")) {
961 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
962 if (defined($starting_itemnumber)) {
963 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
964 my $nearby = GetNearbyItems($starting_itemnumber);
967 starting_itemnumber => $starting_itemnumber,
968 starting_homebranch => $nearby->{starting_homebranch}->{description},
969 starting_location => $nearby->{starting_location}->{description},
970 starting_ccode => $nearby->{starting_ccode}->{description},
971 shelfbrowser_prev_item => $nearby->{prev_item},
972 shelfbrowser_next_item => $nearby->{next_item},
973 shelfbrowser_items => $nearby->{items},
976 # in which tab shelf browser should open ?
977 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
978 $template->param(shelfbrowser_tab => 'holdings');
980 $template->param(shelfbrowser_tab => 'otherholdings');
985 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
987 if (C4::Context->preference("BakerTaylorEnabled")) {
989 BakerTaylorEnabled => 1,
990 BakerTaylorImageURL => &image_url(),
991 BakerTaylorLinkURL => &link_url(),
992 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
994 my ($bt_user, $bt_pass);
996 $bt_user = C4::Context->preference('BakerTaylorUsername') and
997 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1000 BakerTaylorContentURL =>
1001 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1002 $bt_user,$bt_pass,$isbn)
1008 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1011 TagsShowOnDetail => $tag_quantity,
1012 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1014 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1015 'sort'=>'-weight', limit=>$tag_quantity}));
1018 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1019 # These values are going to be read by Javascript, at least in the case
1020 # of the google covers
1021 $template->param(covernewwindow => 'true');
1023 $template->param(covernewwindow => 'false');
1027 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
1028 my @export_options = split(/\|/,$OpacExportOptions);
1029 $template->{VARS}->{'export_options'} = \@export_options;
1031 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1032 my $rating = GetRating( $biblionumber, $borrowernumber );
1034 rating_value => $rating->{'rating_value'},
1035 rating_total => $rating->{'rating_total'},
1036 rating_avg => $rating->{'rating_avg'},
1037 rating_avg_int => $rating->{'rating_avg_int'},
1038 borrowernumber => $borrowernumber
1042 #Search for title in links
1043 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1044 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1045 my $issn = $marcissns->[0] || '';
1047 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1048 $dat->{title} =~ s/\/+$//; # remove trailing slash
1049 $dat->{title} =~ s/\s+$//; # remove trailing space
1050 $search_for_title = parametrized_url(
1053 TITLE => $dat->{title},
1054 AUTHOR => $dat->{author},
1057 CONTROLNUMBER => $marccontrolnumber,
1058 BIBLIONUMBER => $biblionumber,
1061 $template->param('OPACSearchForTitleIn' => $search_for_title);
1064 # We try to select the best default tab to show, according to what
1065 # the user wants, and what's available for display
1066 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1068 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1070 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1071 ? 'serialcollection' :
1072 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1074 $subscriptionsnumber
1076 @serialcollections > 0
1077 ? 'serialcollection' : 'subscriptions';
1078 $template->param('defaulttab' => $defaulttab);
1080 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1081 my @images = ListImagesForBiblio($biblionumber);
1082 $template->{VARS}->{localimages} = \@images;
1085 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1086 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1087 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1088 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1090 if (C4::Context->preference('OpacHighlightedWords')) {
1091 $template->{VARS}->{query_desc} = $query->param('query_desc');
1093 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1095 if ( C4::Context->preference('UseCourseReserves') ) {
1096 foreach my $i ( @items ) {
1097 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1101 output_html_with_http_headers $query, $cookie, $template->output;