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/;
54 if (C4::Context->preference('BakerTaylorEnabled')) {
55 require C4::External::BakerTaylor;
56 import C4::External::BakerTaylor qw(&image_url &link_url);
61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "opac-detail.tmpl",
66 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
67 flagsrequired => { borrow => 1 },
71 my $biblionumber = $query->param('biblionumber') || $query->param('bib');
73 my $record = GetMarcBiblio($biblionumber);
75 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
78 $template->param( biblionumber => $biblionumber );
80 # get biblionumbers stored in the cart
83 if($query->cookie("bib_list")){
84 my $cart_list = $query->cookie("bib_list");
85 @cart_list = split(/\//, $cart_list);
86 if ( grep {$_ eq $biblionumber} @cart_list) {
87 $template->param( incart => 1 );
93 my $marcflavour = C4::Context->preference("marcflavour");
94 my $ean = GetNormalizedEAN( $record, $marcflavour );
96 # XSLT processing of some stuff
97 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
98 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
101 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
102 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
104 # We look for the busc param to build the simple paging from the search
105 if ($OpacBrowseResults) {
106 my $session = get_session($query->cookie("CGISESSID"));
107 my %paging = (previous => {}, next => {});
108 if ($session->param('busc')) {
111 # Rebuild the string to store on session
114 my $arrParamsBusc = shift;
116 my $pasarParams = '';
118 for (keys %$arrParamsBusc) {
119 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
120 if (defined($arrParamsBusc->{$_})) {
121 $pasarParams .= '&' if ($j);
122 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
126 for my $value (@{$arrParamsBusc->{$_}}) {
127 $pasarParams .= '&' if ($j);
128 $pasarParams .= $_ . '=' . $value;
136 # Search given the current values from the busc param
139 my ($arrParamsBusc, $offset, $results_per_page) = @_;
141 my $expanded_facet = $arrParamsBusc->{'expand'};
142 my $branches = GetBranches();
144 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
145 @servers = ("biblioserver") unless (@servers);
147 my ($default_sort_by, @sort_by);
148 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
149 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
150 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
151 my ($error, $results_hashref, $facets);
153 ($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'});
157 for (my $i=0;$i<@servers;$i++) {
158 my $server = $servers[$i];
159 $hits = $results_hashref->{$server}->{"hits"};
160 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
165 # Build the current list of biblionumbers in this search
168 my ($newresultsRef, $results_per_page) = @_;
170 my $listBiblios = '';
172 foreach (@$newresultsRef) {
173 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
174 $listBiblios .= $bibnum . ',';
176 last if ($j == $results_per_page);
178 chop $listBiblios if ($listBiblios =~ /,$/);
182 my $busc = $session->param("busc");
183 my @arrBusc = split(/\&(?:amp;)?/, $busc);
185 my %arrParamsBusc = ();
187 ($key, $value) = split(/=/, $_, 2);
188 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
189 $arrParamsBusc{$key} = $value;
191 unless (exists($arrParamsBusc{$key})) {
192 $arrParamsBusc{$key} = [];
194 push @{$arrParamsBusc{$key}}, $value;
198 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
199 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
200 $arrParamsBusc{'count'} = $results_per_page;
201 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
202 # The value OPACnumSearchResults has changed and the search has to be rebuild
203 if ($count != $results_per_page) {
204 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
206 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
207 for (@arrBibliosAux) {
208 last if ($_ == $biblionumber);
211 $indexBiblio += $offset;
212 $offset = int($indexBiblio / $count) * $count;
213 $arrParamsBusc{'offset'} = $offset;
215 $arrParamsBusc{'count'} = $count;
216 $results_per_page = $count;
217 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
218 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
219 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
220 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
221 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
222 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
223 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
224 $session->param("busc" => $newbusc);
225 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
227 my $modifyListBiblios = 0;
228 # We come from a previous click
229 if (exists($arrParamsBusc{'previous'})) {
230 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
231 delete $arrParamsBusc{'previous'};
232 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
233 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
234 delete $arrParamsBusc{'next'};
236 if ($modifyListBiblios) {
237 if (exists($arrParamsBusc{'newlistBiblios'})) {
238 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
239 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
240 my @arrAux = split(',', $listBibliosAux);
241 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
242 if ($modifyListBiblios == 1) {
243 $arrParamsBusc{'next'} = $arrAux[0];
244 $paging{'next'}->{biblionumber} = $arrAux[0];
246 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
247 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
250 delete $arrParamsBusc{'listBiblios'};
252 my $offsetAux = $arrParamsBusc{'offset'};
253 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
254 $arrParamsBusc{'offsetSearch'} = $offsetAux;
255 $offset = $arrParamsBusc{'offset'};
256 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
257 $session->param("busc" => $newbusc);
258 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
263 # Rebuild the query for the button "back to results"
265 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
266 $buscParam .= '&' unless ($j == 0);
271 $template->param('busc' => $buscParam);
274 # We are inside the list of biblios and we don't have to search
275 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
276 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
278 # We are at the first item of the list
279 if ($arrBiblios[0] == $biblionumber) {
280 if (@arrBiblios > 1) {
281 for (my $j = 1; $j < @arrBiblios; $j++) {
282 next unless ($arrBiblios[$j]);
283 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
287 # search again if we are not at the first searching list
288 if ($offset && !$arrParamsBusc{'previous'}) {
290 $offsetSearch = $offset - $results_per_page;
292 # we are at the last item of the list
293 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
294 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
295 next unless ($arrBiblios[$j]);
296 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
300 # search again if we are at the first list and there is more results
301 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
303 # search again if we aren't at the first list and there is more results
304 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
306 $offsetSearch = $offset + $results_per_page if ($searchAgain);
308 for (my $j = 1; $j < $#arrBiblios; $j++) {
309 if ($arrBiblios[$j] == $biblionumber) {
310 for (my $z = $j - 1; $z >= 0; $z--) {
311 next unless ($arrBiblios[$z]);
312 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
315 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
316 next unless ($arrBiblios[$z]);
317 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
325 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
328 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
329 my @newresults = @$newresultsRef;
330 # build the new listBiblios
331 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
332 unless (exists($arrParamsBusc{'listBiblios'})) {
333 $arrParamsBusc{'listBiblios'} = $listBiblios;
334 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
336 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
338 # From the new list we build again the next and previous result
340 if ($arrBiblios[0] == $biblionumber) {
341 for (my $j = $#newresults; $j >= 0; $j--) {
342 next unless ($newresults[$j]);
343 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
344 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
345 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
348 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
349 for (my $j = 0; $j < @newresults; $j++) {
350 next unless ($newresults[$j]);
351 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
352 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
353 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
358 # build new busc param
359 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
360 $session->param("busc" => $newbusc);
362 my ($previous, $next, $dataBiblioPaging);
364 if ($paging{'previous'}->{biblionumber}) {
365 $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber};
366 $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
367 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
370 if ($paging{'next'}->{biblionumber}) {
371 $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber};
372 $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
373 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
375 $template->param('previous' => $previous, 'next' => $next);
376 # Partial list of biblio results
378 for (my $j = 0; $j < @arrBiblios; $j++) {
379 next unless ($arrBiblios[$j]);
380 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
381 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]};
383 $template->param('listResults' => \@listResults) if (@listResults);
384 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
390 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
391 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
395 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
396 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
397 # change back when ive fixed request.pl
398 my @all_items = GetItemsInfo( $biblionumber );
400 # adding items linked via host biblios
402 my $analyticfield = '773';
403 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
404 $analyticfield = '773';
405 } elsif ($marcflavour eq 'UNIMARC') {
406 $analyticfield = '461';
408 foreach my $hostfield ( $record->field($analyticfield)) {
409 my $hostbiblionumber = $hostfield->subfield("0");
410 my $linkeditemnumber = $hostfield->subfield("9");
411 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
412 foreach my $hostitemInfo (@hostitemInfos){
413 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
414 push(@all_items, $hostitemInfo);
421 # Getting items to be hidden
422 my @hiddenitems = GetHiddenItemnumbers(@all_items);
424 # Are there items to hide?
426 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
430 for my $itm (@all_items) {
431 if ( C4::Context->preference('hidelostitems') ) {
432 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
434 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
442 my $dat = &GetBiblioData($biblionumber);
444 my $itemtypes = GetItemTypes();
446 my $itemtype = $dat->{'itemtype'};
448 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
449 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
451 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
452 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
453 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
455 #coping with subscriptions
456 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
457 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
460 $dat->{'serial'}=1 if $subscriptionsnumber;
461 foreach my $subscription (@subscriptions) {
462 my $serials_to_display;
464 $cell{subscriptionid} = $subscription->{subscriptionid};
465 $cell{subscriptionnotes} = $subscription->{notes};
466 $cell{missinglist} = $subscription->{missinglist};
467 $cell{opacnote} = $subscription->{opacnote};
468 $cell{histstartdate} = $subscription->{histstartdate};
469 $cell{histenddate} = $subscription->{histenddate};
470 $cell{branchcode} = $subscription->{branchcode};
471 $cell{branchname} = GetBranchName($subscription->{branchcode});
472 $cell{hasalert} = $subscription->{hasalert};
473 #get the three latest serials.
474 $serials_to_display = $subscription->{opacdisplaycount};
475 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
476 $cell{opacdisplaycount} = $serials_to_display;
477 $cell{latestserials} =
478 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
482 $dat->{'count'} = scalar(@items);
484 # If there is a lot of items, and the user has not decided
485 # to view them all yet, we first warn him
486 # TODO: The limit of 50 could be a syspref
487 my $viewallitems = $query->param('viewallitems');
488 if ($dat->{'count'} >= 50 && !$viewallitems) {
489 $template->param('lotsofitems' => 1);
492 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
494 my (%item_reserves, %priority);
495 my ($show_holds_count, $show_priority);
496 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
497 m/holds/o and $show_holds_count = 1;
498 m/priority/ and $show_priority = 1;
501 if ( $show_holds_count || $show_priority) {
502 my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber);
503 $template->param( holds_count => $reserve_count ) if $show_holds_count;
504 foreach (@$reserves) {
505 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
506 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
509 ? ($priority{ $_->{itemnumber} } = $_->{priority})
510 : ($template->param( priority => $_->{priority} ));
514 $template->param( show_priority => $has_hold ) ;
517 my $branches = GetBranches();
519 for my $itm (@items) {
520 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
521 $itm->{priority} = $priority{ $itm->{itemnumber} };
523 if ( (not $itm->{'wthdrawn'} )
524 && (not $itm->{'itemlost'} )
525 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
526 && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
527 && ($itm->{'itemnumber'} ) );
529 if ( defined $itm->{'publictype'} ) {
530 # I can't actually find any case in which this is defined. --amoore 2008-12-09
531 $itm->{ $itm->{'publictype'} } = 1;
534 # get collection code description, too
535 my $ccode = $itm->{'ccode'};
536 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
537 my $copynumber = $itm->{'copynumber'};
538 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
539 if ( defined $itm->{'location'} ) {
540 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
542 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
543 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
544 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
546 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
547 $itemfields{$_} = 1 if ($itm->{$_});
550 # walk through the item-level authorised values and populate some images
551 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
552 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
554 if ( $itm->{'itemlost'} ) {
555 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
556 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
557 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
559 my ($reserve_status) = C4::Reserves::CheckReserves($itm->{itemnumber});
560 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
561 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
563 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
564 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
565 $itm->{transfertwhen} = $transfertwhen;
566 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
567 $itm->{transfertto} = $branches->{$transfertto}{branchname};
571 ## get notes and subjects from MARC record
572 my $dbh = C4::Context->dbh;
573 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
574 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
575 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
576 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
577 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
578 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
579 my $marchostsarray = GetMarcHosts($record,$marcflavour);
580 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
583 MARCNOTES => $marcnotesarray,
584 MARCSUBJCTS => $marcsubjctsarray,
585 MARCAUTHORS => $marcauthorsarray,
586 MARCSERIES => $marcseriesarray,
587 MARCURLS => $marcurlsarray,
588 MARCISBNS => $marcisbnsarray,
589 MARCHOSTS => $marchostsarray,
590 norequests => $norequests,
591 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
592 itemdata_ccode => $itemfields{ccode},
593 itemdata_enumchron => $itemfields{enumchron},
594 itemdata_uri => $itemfields{uri},
595 itemdata_copynumber => $itemfields{copynumber},
596 itemdata_itemnotes => $itemfields{itemnotes},
597 authorised_value_images => $biblio_authorised_value_images,
598 subtitle => $subtitle,
599 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
602 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
603 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
604 my $subfields = substr $fieldspec, 3;
605 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
606 my @alternateholdingsinfo = ();
607 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
609 for my $field (@holdingsfields) {
610 my %holding = ( holding => '' );
611 my $havesubfield = 0;
612 for my $subfield ($field->subfields()) {
613 if ((index $subfields, $$subfield[0]) >= 0) {
614 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
615 $holding{'holding'} .= $$subfield[1];
620 push(@alternateholdingsinfo, \%holding);
625 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
629 foreach ( keys %{$dat} ) {
630 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
633 # some useful variables for enhanced content;
634 # in each case, we're grabbing the first value we find in
635 # the record and normalizing it
636 my $upc = GetNormalizedUPC($record,$marcflavour);
637 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
638 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
639 my $content_identifier_exists;
640 if ( $isbn or $ean or $oclc or $upc ) {
641 $content_identifier_exists = 1;
644 normalized_upc => $upc,
645 normalized_ean => $ean,
646 normalized_oclc => $oclc,
647 normalized_isbn => $isbn,
648 content_identifier_exists => $content_identifier_exists,
651 # COinS format FIXME: for books Only
653 ocoins => GetCOinSBiblio($record),
656 my $libravatar_enabled = 0;
657 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
659 require Libravatar::URL;
660 Libravatar::URL->import();
663 $libravatar_enabled = 1;
667 my $reviews = getreviews( $biblionumber, 1 );
668 my $loggedincommenter;
673 foreach ( @$reviews ) {
674 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
675 # setting some borrower info into this hash
676 $_->{title} = $borrowerData->{'title'};
677 $_->{surname} = $borrowerData->{'surname'};
678 $_->{firstname} = $borrowerData->{'firstname'};
679 if ($libravatar_enabled and $borrowerData->{'email'}) {
680 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
682 $_->{userid} = $borrowerData->{'userid'};
683 $_->{cardnumber} = $borrowerData->{'cardnumber'};
685 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
686 $_->{your_comment} = 1;
687 $loggedincommenter = 1;
692 if(C4::Context->preference("ISBD")) {
693 $template->param(ISBD => 1);
697 ITEM_RESULTS => \@items,
698 subscriptionsnumber => $subscriptionsnumber,
699 biblionumber => $biblionumber,
700 subscriptions => \@subs,
701 subscriptionsnumber => $subscriptionsnumber,
703 loggedincommenter => $loggedincommenter
708 if (C4::Context->preference("virtualshelves") ) {
709 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
714 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
717 XISBNS => get_xisbns($isbn)
720 if ($@) { warn "XISBN Failed $@"; }
724 my @sc_fields = $record->field(955);
725 my @lc_fields = $marcflavour eq 'UNIMARC'
726 ? $record->field(930)
727 : $record->field(852);
728 my @serialcollections = ();
730 foreach my $sc_field (@sc_fields) {
733 $row_data{text} = $sc_field->subfield('r');
734 $row_data{branch} = $sc_field->subfield('9');
735 foreach my $lc_field (@lc_fields) {
736 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
737 ? $lc_field->subfield('a') # 930$a
738 : $lc_field->subfield('h') # 852$h
739 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
742 if ($row_data{text} && $row_data{branch}) {
743 push (@serialcollections, \%row_data);
747 if (scalar(@serialcollections) > 0) {
749 serialcollection => 1,
750 serialcollections => \@serialcollections);
753 # Local cover Images stuff
754 if (C4::Context->preference("OPACLocalCoverImages")){
755 $template->param(OPACLocalCoverImages => 1);
758 my $syndetics_elements;
760 if ( C4::Context->preference("SyndeticsEnabled") ) {
761 $template->param("SyndeticsEnabled" => 1);
762 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
764 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
765 for my $element (values %$syndetics_elements) {
766 $template->param("Syndetics$element"."Exists" => 1 );
767 #warn "Exists: "."Syndetics$element"."Exists";
773 if ( C4::Context->preference("SyndeticsEnabled")
774 && C4::Context->preference("SyndeticsSummary")
775 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
777 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
778 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
784 if ( C4::Context->preference("SyndeticsEnabled")
785 && C4::Context->preference("SyndeticsTOC")
786 && exists($syndetics_elements->{'TOC'}) ) {
788 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
789 $template->param( SYNDETICS_TOC => $syndetics_toc );
794 if ( C4::Context->preference("SyndeticsEnabled")
795 && C4::Context->preference("SyndeticsExcerpt")
796 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
798 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
799 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
804 if ( C4::Context->preference("SyndeticsEnabled")
805 && C4::Context->preference("SyndeticsReviews")) {
807 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
808 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
813 if ( C4::Context->preference("SyndeticsEnabled")
814 && C4::Context->preference("SyndeticsAuthorNotes")
815 && exists($syndetics_elements->{'ANOTES'}) ) {
817 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
818 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
823 # LibraryThingForLibraries ID Code and Tabbed View Option
824 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
826 $template->param(LibraryThingForLibrariesID =>
827 C4::Context->preference('LibraryThingForLibrariesID') );
828 $template->param(LibraryThingForLibrariesTabbedView =>
829 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
833 if( C4::Context->preference('NovelistSelectEnabled') )
835 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
836 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
837 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
842 if ( C4::Context->preference("Babeltheque") ) {
845 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
850 if ( C4::Context->preference( "SocialNetworks" ) ) {
851 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
852 $template->param( SocialNetworks => 1 );
855 # Shelf Browser Stuff
856 if (C4::Context->preference("OPACShelfBrowser")) {
857 # pick the first itemnumber unless one was selected by the user
858 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
859 if (defined($starting_itemnumber)) {
860 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
861 my $nearby = GetNearbyItems($starting_itemnumber,3);
864 starting_homebranch => $nearby->{starting_homebranch}->{description},
865 starting_location => $nearby->{starting_location}->{description},
866 starting_ccode => $nearby->{starting_ccode}->{description},
867 starting_itemnumber => $nearby->{starting_itemnumber},
868 shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
869 shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
870 shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
871 shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
872 PREVIOUS_SHELF_BROWSE => $nearby->{prev},
873 NEXT_SHELF_BROWSE => $nearby->{next},
878 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
880 if (C4::Context->preference("BakerTaylorEnabled")) {
882 BakerTaylorEnabled => 1,
883 BakerTaylorImageURL => &image_url(),
884 BakerTaylorLinkURL => &link_url(),
885 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
887 my ($bt_user, $bt_pass);
889 $bt_user = C4::Context->preference('BakerTaylorUsername') and
890 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
893 BakerTaylorContentURL =>
894 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
895 $bt_user,$bt_pass,$isbn)
901 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
904 TagsShowOnDetail => $tag_quantity,
905 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
907 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
908 'sort'=>'-weight', limit=>$tag_quantity}));
911 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
912 # These values are going to be read by Javascript, at least in the case
913 # of the google covers
914 $template->param(covernewwindow => 'true');
916 $template->param(covernewwindow => 'false');
920 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
921 my @export_options = split(/\|/,$OpacExportOptions);
922 $template->{VARS}->{'export_options'} = \@export_options;
924 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
925 my $rating = GetRating( $biblionumber, $borrowernumber );
927 rating_value => $rating->{'rating_value'},
928 rating_total => $rating->{'rating_total'},
929 rating_avg => $rating->{'rating_avg'},
930 rating_avg_int => $rating->{'rating_avg_int'},
931 borrowernumber => $borrowernumber
935 #Search for title in links
936 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
937 my $marcissns = GetMarcISSN ( $record, $marcflavour );
938 my $issn = $marcissns->[0] || '';
940 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
941 $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
942 $dat->{title} =~ s/\/+$//; # remove trailing slash
943 $dat->{title} =~ s/\s+$//; # remove trailing space
944 $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
945 $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
946 $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g;
947 $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
948 $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
949 $template->param('OPACSearchForTitleIn' => $search_for_title);
952 # We try to select the best default tab to show, according to what
953 # the user wants, and what's available for display
954 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
956 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
958 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
959 ? 'serialcollection' :
960 $opac_serial_default eq 'holdings' && $dat->{'count'} > 0
964 @serialcollections > 0
965 ? 'serialcollection' : 'subscription';
966 $template->param('defaulttab' => $defaulttab);
968 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
969 my @images = ListImagesForBiblio($biblionumber);
970 $template->{VARS}->{localimages} = \@images;
973 if (C4::Context->preference('OpacHighlightedWords')) {
974 $template->{VARS}->{query_desc} = $query->param('query_desc');
977 output_html_with_http_headers $query, $cookie, $template->output;