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');
72 $biblionumber = int($biblionumber);
74 my $record = GetMarcBiblio($biblionumber);
76 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
79 $template->param( biblionumber => $biblionumber );
81 # get biblionumbers stored in the cart
84 if($query->cookie("bib_list")){
85 my $cart_list = $query->cookie("bib_list");
86 @cart_list = split(/\//, $cart_list);
87 if ( grep {$_ eq $biblionumber} @cart_list) {
88 $template->param( incart => 1 );
94 my $marcflavour = C4::Context->preference("marcflavour");
95 my $ean = GetNormalizedEAN( $record, $marcflavour );
97 # XSLT processing of some stuff
98 if (C4::Context->preference("OPACXSLTDetailsDisplay") ) {
99 $template->param( 'XSLTBloc' => XSLTParse4Display($biblionumber, $record, "OPACXSLTDetailsDisplay" ) );
102 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
103 $template->{VARS}->{'OpacBrowseResults'} = $OpacBrowseResults;
105 # We look for the busc param to build the simple paging from the search
106 if ($OpacBrowseResults) {
107 my $session = get_session($query->cookie("CGISESSID"));
108 my %paging = (previous => {}, next => {});
109 if ($session->param('busc')) {
112 # Rebuild the string to store on session
115 my $arrParamsBusc = shift;
117 my $pasarParams = '';
119 for (keys %$arrParamsBusc) {
120 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
121 if (defined($arrParamsBusc->{$_})) {
122 $pasarParams .= '&' if ($j);
123 $pasarParams .= $_ . '=' . $arrParamsBusc->{$_};
127 for my $value (@{$arrParamsBusc->{$_}}) {
128 $pasarParams .= '&' if ($j);
129 $pasarParams .= $_ . '=' . $value;
137 # Search given the current values from the busc param
140 my ($arrParamsBusc, $offset, $results_per_page) = @_;
142 my $expanded_facet = $arrParamsBusc->{'expand'};
143 my $branches = GetBranches();
145 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
146 @servers = ("biblioserver") unless (@servers);
148 my ($default_sort_by, @sort_by);
149 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
150 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
151 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
152 my ($error, $results_hashref, $facets);
154 ($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'});
158 for (my $i=0;$i<@servers;$i++) {
159 my $server = $servers[$i];
160 $hits = $results_hashref->{$server}->{"hits"};
161 @newresults = searchResults('opac', '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
166 # Build the current list of biblionumbers in this search
169 my ($newresultsRef, $results_per_page) = @_;
171 my $listBiblios = '';
173 foreach (@$newresultsRef) {
174 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
175 $listBiblios .= $bibnum . ',';
177 last if ($j == $results_per_page);
179 chop $listBiblios if ($listBiblios =~ /,$/);
183 my $busc = $session->param("busc");
184 my @arrBusc = split(/\&(?:amp;)?/, $busc);
186 my %arrParamsBusc = ();
188 ($key, $value) = split(/=/, $_, 2);
189 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
190 $arrParamsBusc{$key} = $value;
192 unless (exists($arrParamsBusc{$key})) {
193 $arrParamsBusc{$key} = [];
195 push @{$arrParamsBusc{$key}}, $value;
199 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
200 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
201 $arrParamsBusc{'count'} = $results_per_page;
202 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
203 # The value OPACnumSearchResults has changed and the search has to be rebuild
204 if ($count != $results_per_page) {
205 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
207 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
208 for (@arrBibliosAux) {
209 last if ($_ == $biblionumber);
212 $indexBiblio += $offset;
213 $offset = int($indexBiblio / $count) * $count;
214 $arrParamsBusc{'offset'} = $offset;
216 $arrParamsBusc{'count'} = $count;
217 $results_per_page = $count;
218 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
219 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
220 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
221 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
222 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
223 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
224 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
225 $session->param("busc" => $newbusc);
226 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
228 my $modifyListBiblios = 0;
229 # We come from a previous click
230 if (exists($arrParamsBusc{'previous'})) {
231 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
232 delete $arrParamsBusc{'previous'};
233 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
234 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
235 delete $arrParamsBusc{'next'};
237 if ($modifyListBiblios) {
238 if (exists($arrParamsBusc{'newlistBiblios'})) {
239 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
240 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
241 my @arrAux = split(',', $listBibliosAux);
242 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
243 if ($modifyListBiblios == 1) {
244 $arrParamsBusc{'next'} = $arrAux[0];
245 $paging{'next'}->{biblionumber} = $arrAux[0];
247 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
248 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
251 delete $arrParamsBusc{'listBiblios'};
253 my $offsetAux = $arrParamsBusc{'offset'};
254 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
255 $arrParamsBusc{'offsetSearch'} = $offsetAux;
256 $offset = $arrParamsBusc{'offset'};
257 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
258 $session->param("busc" => $newbusc);
259 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
264 # Rebuild the query for the button "back to results"
266 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
267 $buscParam .= '&' unless ($j == 0);
272 $template->param('busc' => $buscParam);
275 # We are inside the list of biblios and we don't have to search
276 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
277 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
279 # We are at the first item of the list
280 if ($arrBiblios[0] == $biblionumber) {
281 if (@arrBiblios > 1) {
282 for (my $j = 1; $j < @arrBiblios; $j++) {
283 next unless ($arrBiblios[$j]);
284 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
288 # search again if we are not at the first searching list
289 if ($offset && !$arrParamsBusc{'previous'}) {
291 $offsetSearch = $offset - $results_per_page;
293 # we are at the last item of the list
294 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
295 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
296 next unless ($arrBiblios[$j]);
297 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
301 # search again if we are at the first list and there is more results
302 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
304 # search again if we aren't at the first list and there is more results
305 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
307 $offsetSearch = $offset + $results_per_page if ($searchAgain);
309 for (my $j = 1; $j < $#arrBiblios; $j++) {
310 if ($arrBiblios[$j] == $biblionumber) {
311 for (my $z = $j - 1; $z >= 0; $z--) {
312 next unless ($arrBiblios[$z]);
313 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
316 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
317 next unless ($arrBiblios[$z]);
318 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
326 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
329 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
330 my @newresults = @$newresultsRef;
331 # build the new listBiblios
332 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
333 unless (exists($arrParamsBusc{'listBiblios'})) {
334 $arrParamsBusc{'listBiblios'} = $listBiblios;
335 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
337 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
339 # From the new list we build again the next and previous result
341 if ($arrBiblios[0] == $biblionumber) {
342 for (my $j = $#newresults; $j >= 0; $j--) {
343 next unless ($newresults[$j]);
344 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
345 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
346 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
349 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
350 for (my $j = 0; $j < @newresults; $j++) {
351 next unless ($newresults[$j]);
352 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
353 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
354 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
359 # build new busc param
360 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
361 $session->param("busc" => $newbusc);
363 my ($previous, $next, $dataBiblioPaging);
365 if ($paging{'previous'}->{biblionumber}) {
366 $previous = 'opac-detail.pl?biblionumber=' . $paging{'previous'}->{biblionumber};
367 $dataBiblioPaging = GetBiblioData($paging{'previous'}->{biblionumber});
368 $template->param('previousTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
371 if ($paging{'next'}->{biblionumber}) {
372 $next = 'opac-detail.pl?biblionumber=' . $paging{'next'}->{biblionumber};
373 $dataBiblioPaging = GetBiblioData($paging{'next'}->{biblionumber});
374 $template->param('nextTitle' => $dataBiblioPaging->{'title'}) if ($dataBiblioPaging);
376 $template->param('previous' => $previous, 'next' => $next);
377 # Partial list of biblio results
379 for (my $j = 0; $j < @arrBiblios; $j++) {
380 next unless ($arrBiblios[$j]);
381 $dataBiblioPaging = GetBiblioData($arrBiblios[$j]) if ($arrBiblios[$j] != $biblionumber);
382 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]};
384 $template->param('listResults' => \@listResults) if (@listResults);
385 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
391 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
392 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
396 $template->param('OPACShowCheckoutName' => C4::Context->preference("OPACShowCheckoutName") );
397 $template->param('OPACShowBarcode' => C4::Context->preference("OPACShowBarcode") );
398 # change back when ive fixed request.pl
399 my @all_items = GetItemsInfo( $biblionumber );
401 # adding items linked via host biblios
403 my $analyticfield = '773';
404 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
405 $analyticfield = '773';
406 } elsif ($marcflavour eq 'UNIMARC') {
407 $analyticfield = '461';
409 foreach my $hostfield ( $record->field($analyticfield)) {
410 my $hostbiblionumber = $hostfield->subfield("0");
411 my $linkeditemnumber = $hostfield->subfield("9");
412 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
413 foreach my $hostitemInfo (@hostitemInfos){
414 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
415 push(@all_items, $hostitemInfo);
422 # Getting items to be hidden
423 my @hiddenitems = GetHiddenItemnumbers(@all_items);
425 # Are there items to hide?
427 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
431 for my $itm (@all_items) {
432 if ( C4::Context->preference('hidelostitems') ) {
433 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
435 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
443 my $dat = &GetBiblioData($biblionumber);
445 my $itemtypes = GetItemTypes();
447 my $itemtype = $dat->{'itemtype'};
449 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
450 $dat->{'description'} = $itemtypes->{$itemtype}->{'description'};
452 my $shelflocations =GetKohaAuthorisedValues('items.location',$dat->{'frameworkcode'}, 'opac');
453 my $collections = GetKohaAuthorisedValues('items.ccode',$dat->{'frameworkcode'}, 'opac');
454 my $copynumbers = GetKohaAuthorisedValues('items.copynumber',$dat->{'frameworkcode'}, 'opac');
456 #coping with subscriptions
457 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
458 my @subscriptions = GetSubscriptions($dat->{'title'}, $dat->{'issn'}, $ean, $biblionumber );
461 $dat->{'serial'}=1 if $subscriptionsnumber;
462 foreach my $subscription (@subscriptions) {
463 my $serials_to_display;
465 $cell{subscriptionid} = $subscription->{subscriptionid};
466 $cell{subscriptionnotes} = $subscription->{notes};
467 $cell{missinglist} = $subscription->{missinglist};
468 $cell{opacnote} = $subscription->{opacnote};
469 $cell{histstartdate} = $subscription->{histstartdate};
470 $cell{histenddate} = $subscription->{histenddate};
471 $cell{branchcode} = $subscription->{branchcode};
472 $cell{branchname} = GetBranchName($subscription->{branchcode});
473 $cell{hasalert} = $subscription->{hasalert};
474 $cell{callnumber} = $subscription->{callnumber};
475 $cell{closed} = $subscription->{closed};
476 #get the three latest serials.
477 $serials_to_display = $subscription->{opacdisplaycount};
478 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
479 $cell{opacdisplaycount} = $serials_to_display;
480 $cell{latestserials} =
481 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
485 $dat->{'count'} = scalar(@items);
487 # If there is a lot of items, and the user has not decided
488 # to view them all yet, we first warn him
489 # TODO: The limit of 50 could be a syspref
490 my $viewallitems = $query->param('viewallitems');
491 if ($dat->{'count'} >= 50 && !$viewallitems) {
492 $template->param('lotsofitems' => 1);
495 my $biblio_authorised_value_images = C4::Items::get_authorised_value_images( C4::Biblio::get_biblio_authorised_values( $biblionumber, $record ) );
497 my (%item_reserves, %priority);
498 my ($show_holds_count, $show_priority);
499 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
500 m/holds/o and $show_holds_count = 1;
501 m/priority/ and $show_priority = 1;
504 if ( $show_holds_count || $show_priority) {
505 my ($reserve_count,$reserves) = GetReservesFromBiblionumber($biblionumber);
506 $template->param( holds_count => $reserve_count ) if $show_holds_count;
507 foreach (@$reserves) {
508 $item_reserves{ $_->{itemnumber} }++ if $_->{itemnumber};
509 if ($show_priority && $_->{borrowernumber} == $borrowernumber) {
512 ? ($priority{ $_->{itemnumber} } = $_->{priority})
513 : ($template->param( priority => $_->{priority} ));
517 $template->param( show_priority => $has_hold ) ;
520 my $branches = GetBranches();
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 if ( defined $itm->{'publictype'} ) {
533 # I can't actually find any case in which this is defined. --amoore 2008-12-09
534 $itm->{ $itm->{'publictype'} } = 1;
537 # get collection code description, too
538 my $ccode = $itm->{'ccode'};
539 $itm->{'ccode'} = $collections->{$ccode} if ( defined($collections) && exists( $collections->{$ccode} ) );
540 my $copynumber = $itm->{'copynumber'};
541 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
542 if ( defined $itm->{'location'} ) {
543 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
545 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
546 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
547 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{'description'};
549 foreach (qw(ccode enumchron copynumber itemnotes uri)) {
550 $itemfields{$_} = 1 if ($itm->{$_});
553 # walk through the item-level authorised values and populate some images
554 my $item_authorised_value_images = C4::Items::get_authorised_value_images( C4::Items::get_item_authorised_values( $itm->{'itemnumber'} ) );
555 # warn( Data::Dumper->Dump( [ $item_authorised_value_images ], [ 'item_authorised_value_images' ] ) );
557 if ( $itm->{'itemlost'} ) {
558 my $lostimageinfo = List::Util::first { $_->{'category'} eq 'LOST' } @$item_authorised_value_images;
559 $itm->{'lostimageurl'} = $lostimageinfo->{ 'imageurl' };
560 $itm->{'lostimagelabel'} = $lostimageinfo->{ 'label' };
562 my ($reserve_status) = C4::Reserves::CheckReserves($itm->{itemnumber});
563 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
564 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
566 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
567 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
568 $itm->{transfertwhen} = $transfertwhen;
569 $itm->{transfertfrom} = $branches->{$transfertfrom}{branchname};
570 $itm->{transfertto} = $branches->{$transfertto}{branchname};
574 ## get notes and subjects from MARC record
575 my $dbh = C4::Context->dbh;
576 my $marcnotesarray = GetMarcNotes ($record,$marcflavour);
577 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
578 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
579 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
580 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
581 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
582 my $marchostsarray = GetMarcHosts($record,$marcflavour);
583 my $subtitle = GetRecordValue('subtitle', $record, GetFrameworkCode($biblionumber));
586 MARCNOTES => $marcnotesarray,
587 MARCSUBJCTS => $marcsubjctsarray,
588 MARCAUTHORS => $marcauthorsarray,
589 MARCSERIES => $marcseriesarray,
590 MARCURLS => $marcurlsarray,
591 MARCISBNS => $marcisbnsarray,
592 MARCHOSTS => $marchostsarray,
593 norequests => $norequests,
594 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
595 itemdata_ccode => $itemfields{ccode},
596 itemdata_enumchron => $itemfields{enumchron},
597 itemdata_uri => $itemfields{uri},
598 itemdata_copynumber => $itemfields{copynumber},
599 itemdata_itemnotes => $itemfields{itemnotes},
600 authorised_value_images => $biblio_authorised_value_images,
601 subtitle => $subtitle,
602 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
605 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
606 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
607 my $subfields = substr $fieldspec, 3;
608 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
609 my @alternateholdingsinfo = ();
610 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
612 for my $field (@holdingsfields) {
613 my %holding = ( holding => '' );
614 my $havesubfield = 0;
615 for my $subfield ($field->subfields()) {
616 if ((index $subfields, $$subfield[0]) >= 0) {
617 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
618 $holding{'holding'} .= $$subfield[1];
623 push(@alternateholdingsinfo, \%holding);
628 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
632 foreach ( keys %{$dat} ) {
633 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
636 # some useful variables for enhanced content;
637 # in each case, we're grabbing the first value we find in
638 # the record and normalizing it
639 my $upc = GetNormalizedUPC($record,$marcflavour);
640 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
641 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
642 my $content_identifier_exists;
643 if ( $isbn or $ean or $oclc or $upc ) {
644 $content_identifier_exists = 1;
647 normalized_upc => $upc,
648 normalized_ean => $ean,
649 normalized_oclc => $oclc,
650 normalized_isbn => $isbn,
651 content_identifier_exists => $content_identifier_exists,
654 # COinS format FIXME: for books Only
656 ocoins => GetCOinSBiblio($record),
659 my $libravatar_enabled = 0;
660 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto')) {
662 require Libravatar::URL;
663 Libravatar::URL->import();
666 $libravatar_enabled = 1;
670 my $reviews = getreviews( $biblionumber, 1 );
671 my $loggedincommenter;
676 foreach ( @$reviews ) {
677 my $borrowerData = GetMember('borrowernumber' => $_->{borrowernumber});
678 # setting some borrower info into this hash
679 $_->{title} = $borrowerData->{'title'};
680 $_->{surname} = $borrowerData->{'surname'};
681 $_->{firstname} = $borrowerData->{'firstname'};
682 if ($libravatar_enabled and $borrowerData->{'email'}) {
683 $_->{avatarurl} = libravatar_url(email => $borrowerData->{'email'}, https => $ENV{HTTPS});
685 $_->{userid} = $borrowerData->{'userid'};
686 $_->{cardnumber} = $borrowerData->{'cardnumber'};
688 if ($borrowerData->{'borrowernumber'} eq $borrowernumber) {
689 $_->{your_comment} = 1;
690 $loggedincommenter = 1;
695 if(C4::Context->preference("ISBD")) {
696 $template->param(ISBD => 1);
700 ITEM_RESULTS => \@items,
701 subscriptionsnumber => $subscriptionsnumber,
702 biblionumber => $biblionumber,
703 subscriptions => \@subs,
704 subscriptionsnumber => $subscriptionsnumber,
706 loggedincommenter => $loggedincommenter
711 if (C4::Context->preference("virtualshelves") ) {
712 $template->param( 'GetShelves' => GetBibliosShelves( $biblionumber ) );
717 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
720 XISBNS => get_xisbns($isbn)
723 if ($@) { warn "XISBN Failed $@"; }
727 my @sc_fields = $record->field(955);
728 my @lc_fields = $marcflavour eq 'UNIMARC'
729 ? $record->field(930)
730 : $record->field(852);
731 my @serialcollections = ();
733 foreach my $sc_field (@sc_fields) {
736 $row_data{text} = $sc_field->subfield('r');
737 $row_data{branch} = $sc_field->subfield('9');
738 foreach my $lc_field (@lc_fields) {
739 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
740 ? $lc_field->subfield('a') # 930$a
741 : $lc_field->subfield('h') # 852$h
742 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
745 if ($row_data{text} && $row_data{branch}) {
746 push (@serialcollections, \%row_data);
750 if (scalar(@serialcollections) > 0) {
752 serialcollection => 1,
753 serialcollections => \@serialcollections);
756 # Local cover Images stuff
757 if (C4::Context->preference("OPACLocalCoverImages")){
758 $template->param(OPACLocalCoverImages => 1);
761 my $syndetics_elements;
763 if ( C4::Context->preference("SyndeticsEnabled") ) {
764 $template->param("SyndeticsEnabled" => 1);
765 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
767 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
768 for my $element (values %$syndetics_elements) {
769 $template->param("Syndetics$element"."Exists" => 1 );
770 #warn "Exists: "."Syndetics$element"."Exists";
776 if ( C4::Context->preference("SyndeticsEnabled")
777 && C4::Context->preference("SyndeticsSummary")
778 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
780 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
781 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
787 if ( C4::Context->preference("SyndeticsEnabled")
788 && C4::Context->preference("SyndeticsTOC")
789 && exists($syndetics_elements->{'TOC'}) ) {
791 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
792 $template->param( SYNDETICS_TOC => $syndetics_toc );
797 if ( C4::Context->preference("SyndeticsEnabled")
798 && C4::Context->preference("SyndeticsExcerpt")
799 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
801 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
802 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
807 if ( C4::Context->preference("SyndeticsEnabled")
808 && C4::Context->preference("SyndeticsReviews")) {
810 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
811 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
816 if ( C4::Context->preference("SyndeticsEnabled")
817 && C4::Context->preference("SyndeticsAuthorNotes")
818 && exists($syndetics_elements->{'ANOTES'}) ) {
820 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
821 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
826 # LibraryThingForLibraries ID Code and Tabbed View Option
827 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
829 $template->param(LibraryThingForLibrariesID =>
830 C4::Context->preference('LibraryThingForLibrariesID') );
831 $template->param(LibraryThingForLibrariesTabbedView =>
832 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
836 if( C4::Context->preference('NovelistSelectEnabled') )
838 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
839 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
840 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
845 if ( C4::Context->preference("Babeltheque") ) {
848 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
853 if ( C4::Context->preference( "SocialNetworks" ) ) {
854 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
855 $template->param( SocialNetworks => 1 );
858 # Shelf Browser Stuff
859 if (C4::Context->preference("OPACShelfBrowser")) {
860 # pick the first itemnumber unless one was selected by the user
861 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber'); # || $items[0]->{itemnumber};
862 if (defined($starting_itemnumber)) {
863 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
864 my $nearby = GetNearbyItems($starting_itemnumber,3);
867 starting_homebranch => $nearby->{starting_homebranch}->{description},
868 starting_location => $nearby->{starting_location}->{description},
869 starting_ccode => $nearby->{starting_ccode}->{description},
870 starting_itemnumber => $nearby->{starting_itemnumber},
871 shelfbrowser_prev_itemnumber => $nearby->{prev_itemnumber},
872 shelfbrowser_next_itemnumber => $nearby->{next_itemnumber},
873 shelfbrowser_prev_biblionumber => $nearby->{prev_biblionumber},
874 shelfbrowser_next_biblionumber => $nearby->{next_biblionumber},
875 PREVIOUS_SHELF_BROWSE => $nearby->{prev},
876 NEXT_SHELF_BROWSE => $nearby->{next},
881 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
883 if (C4::Context->preference("BakerTaylorEnabled")) {
885 BakerTaylorEnabled => 1,
886 BakerTaylorImageURL => &image_url(),
887 BakerTaylorLinkURL => &link_url(),
888 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
890 my ($bt_user, $bt_pass);
892 $bt_user = C4::Context->preference('BakerTaylorUsername') and
893 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
896 BakerTaylorContentURL =>
897 sprintf("http://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
898 $bt_user,$bt_pass,$isbn)
904 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
907 TagsShowOnDetail => $tag_quantity,
908 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
910 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
911 'sort'=>'-weight', limit=>$tag_quantity}));
914 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
915 # These values are going to be read by Javascript, at least in the case
916 # of the google covers
917 $template->param(covernewwindow => 'true');
919 $template->param(covernewwindow => 'false');
923 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
924 my @export_options = split(/\|/,$OpacExportOptions);
925 $template->{VARS}->{'export_options'} = \@export_options;
927 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
928 my $rating = GetRating( $biblionumber, $borrowernumber );
930 rating_value => $rating->{'rating_value'},
931 rating_total => $rating->{'rating_total'},
932 rating_avg => $rating->{'rating_avg'},
933 rating_avg_int => $rating->{'rating_avg_int'},
934 borrowernumber => $borrowernumber
938 #Search for title in links
939 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
940 my $marcissns = GetMarcISSN ( $record, $marcflavour );
941 my $issn = $marcissns->[0] || '';
943 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
944 $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
945 $dat->{title} =~ s/\/+$//; # remove trailing slash
946 $dat->{title} =~ s/\s+$//; # remove trailing space
947 $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
948 $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
949 $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g;
950 $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
951 $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
952 $template->param('OPACSearchForTitleIn' => $search_for_title);
955 # We try to select the best default tab to show, according to what
956 # the user wants, and what's available for display
957 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
959 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
961 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
962 ? 'serialcollection' :
963 $opac_serial_default eq 'holdings' && $dat->{'count'} > 0
967 @serialcollections > 0
968 ? 'serialcollection' : 'subscription';
969 $template->param('defaulttab' => $defaulttab);
971 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
972 my @images = ListImagesForBiblio($biblionumber);
973 $template->{VARS}->{localimages} = \@images;
976 if (C4::Context->preference('OpacHighlightedWords')) {
977 $template->{VARS}->{query_desc} = $query->param('query_desc');
980 output_html_with_http_headers $query, $cookie, $template->output;