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/;
55 if (C4::Context->preference('BakerTaylorEnabled')) {
56 require C4::External::BakerTaylor;
57 import C4::External::BakerTaylor qw(&image_url &link_url);
62 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
64 template_name => "opac-detail.tmpl",
67 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
68 flagsrequired => { borrow => 1 },
72 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
73 $biblionumber = int($biblionumber);
75 my $record = GetMarcBiblio($biblionumber);
77 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
80 $template->param( biblionumber => $biblionumber );
82 # get biblionumbers stored in the cart
85 if($query->cookie("bib_list")){
86 my $cart_list = $query->cookie("bib_list");
87 @cart_list = split(/\//, $cart_list);
88 if ( grep {$_ eq $biblionumber} @cart_list) {
89 $template->param( incart => 1 );
95 my $marcflavour = C4::Context->preference("marcflavour");
96 my $ean = GetNormalizedEAN( $record, $marcflavour );
98 # XSLT processing of some stuff
99 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
100 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
103 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
104 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
106 # We look for the busc param to build the simple paging from the search
107 if ($OpacBrowseResults) {
108 my $session = get_session($query->cookie("CGISESSID"));
109 my %paging = (previous => {}, next => {});
110 if ($session->param('busc')) {
113 # Rebuild the string to store on session
116 my $arrParamsBusc = shift;
118 my $pasarParams = '';
120 for (keys %$arrParamsBusc) {
121 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
122 if (defined($arrParamsBusc->{$_})) {
123 $pasarParams .= '&' if ($j);
124 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
128 for my $value (@{$arrParamsBusc->{$_}}) {
129 $pasarParams .= '&' if ($j);
130 $pasarParams .= $_ . '=' . $value;
138 # Search given the current values from the busc param
141 my ($arrParamsBusc, $offset, $results_per_page) = @_;
143 my $expanded_facet = $arrParamsBusc->{'expand'};
144 my $branches = GetBranches();
146 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
147 @servers = ("biblioserver") unless (@servers);
149 my ($default_sort_by, @sort_by);
150 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
151 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
152 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
153 my ($error, $results_hashref, $facets);
155 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,$expanded_facet,$branches,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
159 for (my $i=0;$i<@servers;$i++) {
160 my $server = $servers[$i];
161 $hits = $results_hashref->{$server}->{"hits"};
162 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
167 # Build the current list of biblionumbers in this search
170 my ($newresultsRef, $results_per_page) = @_;
172 my $listBiblios = '';
174 foreach (@$newresultsRef) {
175 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
176 $listBiblios .= $bibnum . ',';
178 last if ($j == $results_per_page);
180 chop $listBiblios if ($listBiblios =~ /,$/);
184 my $busc = $session->param("busc");
185 my @arrBusc = split(/\&(?:amp;)?/, $busc);
187 my %arrParamsBusc = ();
189 ($key, $value) = split(/=/, $_, 2);
190 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
191 $arrParamsBusc{$key} = $value;
193 unless (exists($arrParamsBusc{$key})) {
194 $arrParamsBusc{$key} = [];
196 push @{$arrParamsBusc{$key}}, $value;
200 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
201 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
202 $arrParamsBusc{'count'} = $results_per_page;
203 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
204 # The value OPACnumSearchResults has changed and the search has to be rebuild
205 if ($count != $results_per_page) {
206 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
208 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
209 for (@arrBibliosAux) {
210 last if ($_ == $biblionumber);
213 $indexBiblio += $offset;
214 $offset = int($indexBiblio / $count) * $count;
215 $arrParamsBusc{'offset'} = $offset;
217 $arrParamsBusc{'count'} = $count;
218 $results_per_page = $count;
219 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
220 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
221 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
222 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
223 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
224 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
225 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
226 $session->param("busc" => $newbusc);
227 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
229 my $modifyListBiblios = 0;
230 # We come from a previous click
231 if (exists($arrParamsBusc{'previous'})) {
232 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
233 delete $arrParamsBusc{'previous'};
234 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
235 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
236 delete $arrParamsBusc{'next'};
238 if ($modifyListBiblios) {
239 if (exists($arrParamsBusc{'newlistBiblios'})) {
240 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
241 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
242 my @arrAux = split(',', $listBibliosAux);
243 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
244 if ($modifyListBiblios == 1) {
245 $arrParamsBusc{'next'} = $arrAux[0];
246 $paging{'next'}->{biblionumber} = $arrAux[0];
248 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
249 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
252 delete $arrParamsBusc{'listBiblios'};
254 my $offsetAux = $arrParamsBusc{'offset'};
255 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
256 $arrParamsBusc{'offsetSearch'} = $offsetAux;
257 $offset = $arrParamsBusc{'offset'};
258 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
259 $session->param("busc" => $newbusc);
260 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
265 # Rebuild the query for the button "back to results"
267 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
268 $buscParam .= '&' unless ($j == 0);
273 $template->param('busc' => $buscParam);
276 # We are inside the list of biblios and we don't have to search
277 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
278 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
280 # We are at the first item of the list
281 if ($arrBiblios[0] == $biblionumber) {
282 if (@arrBiblios > 1) {
283 for (my $j = 1; $j < @arrBiblios; $j++) {
284 next unless ($arrBiblios[$j]);
285 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
289 # search again if we are not at the first searching list
290 if ($offset && !$arrParamsBusc{'previous'}) {
292 $offsetSearch = $offset - $results_per_page;
294 # we are at the last item of the list
295 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
296 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
297 next unless ($arrBiblios[$j]);
298 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
302 # search again if we are at the first list and there is more results
303 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
305 # search again if we aren't at the first list and there is more results
306 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
308 $offsetSearch = $offset + $results_per_page if ($searchAgain);
310 for (my $j = 1; $j < $#arrBiblios; $j++) {
311 if ($arrBiblios[$j] == $biblionumber) {
312 for (my $z = $j - 1; $z >= 0; $z--) {
313 next unless ($arrBiblios[$z]);
314 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
317 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
318 next unless ($arrBiblios[$z]);
319 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
327 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
330 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
331 my @newresults = @$newresultsRef;
332 # build the new listBiblios
333 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
334 unless (exists($arrParamsBusc{'listBiblios'})) {
335 $arrParamsBusc{'listBiblios'} = $listBiblios;
336 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
338 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
340 # From the new list we build again the next and previous result
342 if ($arrBiblios[0] == $biblionumber) {
343 for (my $j = $#newresults; $j >= 0; $j--) {
344 next unless ($newresults[$j]);
345 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
346 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
347 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
350 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
351 for (my $j = 0; $j < @newresults; $j++) {
352 next unless ($newresults[$j]);
353 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
354 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
355 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
360 # build new busc param
361 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
362 $session->param("busc" => $newbusc);
364 my ($previous, $next, $dataBiblioPaging);
366 if ($paging{'previous'}->{biblionumber}) {
367 $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber};
368 $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
369 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
372 if ($paging{'next'}->{biblionumber}) {
373 $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber};
374 $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
375 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
377 $template->param('previous' => $previous, 'next' => $next);
378 # Partial list of biblio results
380 for (my $j = 0; $j < @arrBiblios; $j++) {
381 next unless ($arrBiblios[$j]);
382 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
383 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]};
385 $template->param('listResults' => \@listResults) if (@listResults);
386 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
392 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
393 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
397 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
398 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
399 # change back when ive fixed request.pl
400 my @all_items = GetItemsInfo( $biblionumber );
402 # adding items linked via host biblios
404 my $analyticfield = '773';
405 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
406 $analyticfield = '773';
407 } elsif ($marcflavour eq 'UNIMARC') {
408 $analyticfield = '461';
410 foreach my $hostfield ( $record->field($analyticfield)) {
411 my $hostbiblionumber = $hostfield->subfield("0");
412 my $linkeditemnumber = $hostfield->subfield("9");
413 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
414 foreach my $hostitemInfo (@hostitemInfos){
415 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
416 push(@all_items, $hostitemInfo);
423 # Getting items to be hidden
424 my @hiddenitems = GetHiddenItemnumbers(@all_items);
426 # Are there items to hide?
428 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
432 for my $itm (@all_items) {
433 if ( C4::Context->preference('hidelostitems') ) {
434 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
436 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
444 my $dat = &GetBiblioData($biblionumber);
446 my $itemtypes = GetItemTypes();
448 my $itemtype = $dat->{'itemtype'};
450 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
451 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
453 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
454 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
455 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
457 #coping with subscriptions
458 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
459 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
462 $dat->{'serial'}=1 if $subscriptionsnumber;
463 foreach my $subscription (@subscriptions) {
464 my $serials_to_display;
466 $cell{subscriptionid} = $subscription->{subscriptionid};
467 $cell{subscriptionnotes} = $subscription->{notes};
468 $cell{missinglist} = $subscription->{missinglist};
469 $cell{opacnote} = $subscription->{opacnote};
470 $cell{histstartdate} = $subscription->{histstartdate};
471 $cell{histenddate} = $subscription->{histenddate};
472 $cell{branchcode} = $subscription->{branchcode};
473 $cell{branchname} = GetBranchName($subscription->{branchcode});
474 $cell{hasalert} = $subscription->{hasalert};
475 $cell{callnumber} = $subscription->{callnumber};
476 $cell{closed} = $subscription->{closed};
477 #get the three latest serials.
478 $serials_to_display = $subscription->{opacdisplaycount};
479 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
480 $cell{opacdisplaycount} = $serials_to_display;
481 $cell{latestserials} =
482 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
486 $dat->{'count'} = scalar(@items);
489 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
491 my (%item_reserves, %priority);
492 my ($show_holds_count, $show_priority);
493 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
494 m/holds/o and $show_holds_count = 1;
495 m/priority/ and $show_priority = 1;
498 if ( $show_holds_count || $show_priority) {
499 my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber);
500 $template->param( holds_count => $reserve_count ) if $show_holds_count;
501 foreach (@$reserves) {
502 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
503 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
506 ? ($priority{ $_->{itemnumber} } = $_->{priority})
507 : ($template->param( priority => $_->{priority} ));
511 $template->param( show_priority => $has_hold ) ;
514 my $branches = GetBranches();
516 my (@itemloop, @otheritemloop);
517 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
518 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
519 $template->param(SeparateHoldings => 1);
521 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
522 for my $itm (@items) {
523 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
524 $itm->{priority} = $priority{ $itm->{itemnumber} };
526 if ( (not $itm->{'wthdrawn'} )
527 && (not $itm->{'itemlost'} )
528 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
529 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
530 && ($itm->{'itemnumber'} ) );
532 # get collection code description, too
533 my $ccode = $itm->{'ccode'};
534 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
535 my $copynumber = $itm->{'copynumber'};
536 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
537 if ( defined $itm->{'location'} ) {
538 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
540 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
541 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
542 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
544 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
545 $itemfields{$_} = 1 if ($itm->{$_});
548 # walk through the item-level authorised values and populate some images
549 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
550 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
552 if ( $itm->{'itemlost'} ) {
553 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
554 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
555 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
557 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
558 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
559 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
561 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
562 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
563 $itm->{transfertwhen} = $transfertwhen;
564 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
565 $itm->{transfertto} = $branches->{$transfertto}{branchname};
567 my $itembranch = $itm->{$separatebranch};
568 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
569 if ($itembranch and $itembranch eq $currentbranch) {
570 push @itemloop, $itm;
572 push @otheritemloop, $itm;
575 push @itemloop, $itm;
579 # Display only one tab if one items list is empty
580 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
581 $template->param(SeparateHoldings => 0);
582 if (scalar(@itemloop) == 0) {
583 @itemloop = @otheritemloop;
587 # If there is a lot of items, and the user has not decided
588 # to view them all yet, we first warn him
589 # TODO: The limit of 50 could be a syspref
590 my $viewallitems = $query->param('viewallitems');
591 if (scalar(@itemloop) >= 50 && !$viewallitems) {
592 $template->param('lotsofitems' => 1);
595 ## get notes and subjects from MARC record
596 my $dbh = C4::Context->dbh;
597 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
598 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
599 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
600 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
601 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
602 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
603 my $marchostsarray = GetMarcHosts($record,$marcflavour);
604 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
607 MARCNOTES => $marcnotesarray,
608 MARCSUBJCTS => $marcsubjctsarray,
609 MARCAUTHORS => $marcauthorsarray,
610 MARCSERIES => $marcseriesarray,
611 MARCURLS => $marcurlsarray,
612 MARCISBNS => $marcisbnsarray,
613 MARCHOSTS => $marchostsarray,
614 norequests => $norequests,
615 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
616 itemdata_ccode => $itemfields{ccode},
617 itemdata_enumchron => $itemfields{enumchron},
618 itemdata_uri => $itemfields{uri},
619 itemdata_copynumber => $itemfields{copynumber},
620 itemdata_itemnotes => $itemfields{itemnotes},
621 authorised_value_images => $biblio_authorised_value_images,
622 subtitle => $subtitle,
623 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
626 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
627 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
628 my $subfields = substr $fieldspec, 3;
629 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
630 my @alternateholdingsinfo = ();
631 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
633 for my $field (@holdingsfields) {
634 my %holding = ( holding => '' );
635 my $havesubfield = 0;
636 for my $subfield ($field->subfields()) {
637 if ((index $subfields, $$subfield[0]) >= 0) {
638 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
639 $holding{'holding'} .= $$subfield[1];
644 push(@alternateholdingsinfo, \%holding);
649 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
653 foreach ( keys %{$dat} ) {
654 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
657 # some useful variables for enhanced content;
658 # in each case, we're grabbing the first value we find in
659 # the record and normalizing it
660 my $upc = GetNormalizedUPC($record,$marcflavour);
661 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
662 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
663 my $content_identifier_exists;
664 if ( $isbn or $ean or $oclc or $upc ) {
665 $content_identifier_exists = 1;
668 normalized_upc => $upc,
669 normalized_ean => $ean,
670 normalized_oclc => $oclc,
671 normalized_isbn => $isbn,
672 content_identifier_exists => $content_identifier_exists,
675 # COinS format FIXME: for books Only
677 ocoins => GetCOinSBiblio($record),
680 my $libravatar_enabled = 0;
681 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
683 require Libravatar::URL;
684 Libravatar::URL->import();
687 $libravatar_enabled = 1;
691 my $reviews = getreviews( $biblionumber, 1 );
692 my $loggedincommenter;
697 foreach ( @$reviews ) {
698 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
699 # setting some borrower info into this hash
700 $_->{title} = $borrowerData->{'title'};
701 $_->{surname} = $borrowerData->{'surname'};
702 $_->{firstname} = $borrowerData->{'firstname'};
703 if ($libravatar_enabled and $borrowerData->{'email'}) {
704 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
706 $_->{userid} = $borrowerData->{'userid'};
707 $_->{cardnumber} = $borrowerData->{'cardnumber'};
709 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
710 $_->{your_comment} = 1;
711 $loggedincommenter = 1;
716 if(C4::Context->preference("ISBD")) {
717 $template->param(ISBD => 1);
721 itemloop => \@itemloop,
722 otheritemloop => \@otheritemloop,
723 subscriptionsnumber => $subscriptionsnumber,
724 biblionumber => $biblionumber,
725 subscriptions => \@subs,
726 subscriptionsnumber => $subscriptionsnumber,
728 loggedincommenter => $loggedincommenter
733 if (C4::Context->preference("virtualshelves") ) {
734 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
739 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
742 XISBNS => get_xisbns($isbn)
745 if ($@) { warn "XISBN Failed $@"; }
749 my @sc_fields = $record->field(955);
750 my @lc_fields = $marcflavour eq 'UNIMARC'
751 ? $record->field(930)
752 : $record->field(852);
753 my @serialcollections = ();
755 foreach my $sc_field (@sc_fields) {
758 $row_data{text} = $sc_field->subfield('r');
759 $row_data{branch} = $sc_field->subfield('9');
760 foreach my $lc_field (@lc_fields) {
761 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
762 ? $lc_field->subfield('a') # 930$a
763 : $lc_field->subfield('h') # 852$h
764 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
767 if ($row_data{text} && $row_data{branch}) {
768 push (@serialcollections, \%row_data);
772 if (scalar(@serialcollections) > 0) {
774 serialcollection => 1,
775 serialcollections => \@serialcollections);
778 # Local cover Images stuff
779 if (C4::Context->preference("OPACLocalCoverImages")){
780 $template->param(OPACLocalCoverImages => 1);
784 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
785 $template->param( C4::HTML5Media->gethtml5media($record));
788 my $syndetics_elements;
790 if ( C4::Context->preference("SyndeticsEnabled") ) {
791 $template->param("SyndeticsEnabled" => 1);
792 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
794 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
795 for my $element (values %$syndetics_elements) {
796 $template->param("Syndetics$element"."Exists" => 1 );
797 #warn "Exists: "."Syndetics$element"."Exists";
803 if ( C4::Context->preference("SyndeticsEnabled")
804 && C4::Context->preference("SyndeticsSummary")
805 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
807 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
808 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
814 if ( C4::Context->preference("SyndeticsEnabled")
815 && C4::Context->preference("SyndeticsTOC")
816 && exists($syndetics_elements->{'TOC'}) ) {
818 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
819 $template->param( SYNDETICS_TOC => $syndetics_toc );
824 if ( C4::Context->preference("SyndeticsEnabled")
825 && C4::Context->preference("SyndeticsExcerpt")
826 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
828 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
829 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
834 if ( C4::Context->preference("SyndeticsEnabled")
835 && C4::Context->preference("SyndeticsReviews")) {
837 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
838 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
843 if ( C4::Context->preference("SyndeticsEnabled")
844 && C4::Context->preference("SyndeticsAuthorNotes")
845 && exists($syndetics_elements->{'ANOTES'}) ) {
847 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
848 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
853 # LibraryThingForLibraries ID Code and Tabbed View Option
854 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
856 $template->param(LibraryThingForLibrariesID =>
857 C4::Context->preference('LibraryThingForLibrariesID') );
858 $template->param(LibraryThingForLibrariesTabbedView =>
859 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
863 if( C4::Context->preference('NovelistSelectEnabled') )
865 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
866 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
867 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
872 if ( C4::Context->preference("Babeltheque") ) {
875 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
880 if ( C4::Context->preference( "SocialNetworks" ) ) {
881 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
882 $template->param( SocialNetworks => 1 );
885 # Shelf Browser Stuff
886 if (C4::Context->preference("OPACShelfBrowser")) {
887 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
888 if (defined($starting_itemnumber)) {
889 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
890 my $nearby = GetNearbyItems($starting_itemnumber,3);
893 starting_homebranch => $nearby->{starting_homebranch}->{description},
894 starting_location => $nearby->{starting_location}->{description},
895 starting_ccode => $nearby->{starting_ccode}->{description},
896 starting_itemnumber => $nearby->{starting_itemnumber},
897 shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
898 shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
899 shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
900 shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
901 PREVIOUS_SHELF_BROWSE => $nearby->{prev},
902 NEXT_SHELF_BROWSE => $nearby->{next},
905 # in which tab shelf browser should open ?
906 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
907 $template->param(shelfbrowser_tab => 'holdings');
909 $template->param(shelfbrowser_tab => 'otherholdings');
914 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
916 if (C4::Context->preference("BakerTaylorEnabled")) {
918 BakerTaylorEnabled => 1,
919 BakerTaylorImageURL => &image_url(),
920 BakerTaylorLinkURL => &link_url(),
921 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
923 my ($bt_user, $bt_pass);
925 $bt_user = C4::Context->preference('BakerTaylorUsername') and
926 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
929 BakerTaylorContentURL =>
930 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
931 $bt_user,$bt_pass,$isbn)
937 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
940 TagsShowOnDetail => $tag_quantity,
941 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
943 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
944 'sort'=>'-weight', limit=>$tag_quantity}));
947 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
948 # These values are going to be read by Javascript, at least in the case
949 # of the google covers
950 $template->param(covernewwindow => 'true');
952 $template->param(covernewwindow => 'false');
956 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
957 my @export_options = split(/\|/,$OpacExportOptions);
958 $template->{VARS}->{'export_options'} = \@export_options;
960 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
961 my $rating = GetRating( $biblionumber, $borrowernumber );
963 rating_value => $rating->{'rating_value'},
964 rating_total => $rating->{'rating_total'},
965 rating_avg => $rating->{'rating_avg'},
966 rating_avg_int => $rating->{'rating_avg_int'},
967 borrowernumber => $borrowernumber
971 #Search for title in links
972 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
973 my $marcissns = GetMarcISSN ( $record, $marcflavour );
974 my $issn = $marcissns->[0] || '';
976 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
977 $dat->{title} =~ s/\/+$//; # remove trailing slash
978 $dat->{title} =~ s/\s+$//; # remove trailing space
979 $search_for_title = parametrized_url(
982 TITLE => $dat->{title},
983 AUTHOR => $dat->{author},
986 CONTROLNUMBER => $marccontrolnumber,
987 BIBLIONUMBER => $biblionumber,
990 $template->param('OPACSearchForTitleIn' => $search_for_title);
993 # We try to select the best default tab to show, according to what
994 # the user wants, and what's available for display
995 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
997 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
999 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1000 ? 'serialcollection' :
1001 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1003 $subscriptionsnumber
1005 @serialcollections > 0
1006 ? 'serialcollection' : 'subscriptions';
1007 $template->param('defaulttab' => $defaulttab);
1009 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1010 my @images = ListImagesForBiblio($biblionumber);
1011 $template->{VARS}->{localimages} = \@images;
1014 $template->{VARS}->{IDreamBooksReviews} = C4::Context->preference('IDreamBooksReviews');
1015 $template->{VARS}->{IDreamBooksReadometer} = C4::Context->preference('IDreamBooksReadometer');
1016 $template->{VARS}->{IDreamBooksResults} = C4::Context->preference('IDreamBooksResults');
1017 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1019 if (C4::Context->preference('OpacHighlightedWords')) {
1020 $template->{VARS}->{query_desc} = $query->param('query_desc');
1022 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1024 output_html_with_http_headers $query, $cookie, $template->output;