Bug 26145: Display the cover image at the OPAC
[koha.git] / opac / opac-detail.pl
blob326c7f5d1224580aabe29518839073cec1f604be
1 #!/usr/bin/perl
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
10 # under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # Koha is distributed in the hope that it will be useful, but
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with Koha; if not, see <http://www.gnu.org/licenses>.
23 use Modern::Perl;
25 use CGI qw ( -utf8 );
26 use C4::Acquisition qw( SearchOrders );
27 use C4::Auth qw(:DEFAULT get_session);
28 use C4::Koha;
29 use C4::Serials; #uses getsubscriptionfrom biblionumber
30 use C4::Output;
31 use C4::Biblio;
32 use C4::Items;
33 use C4::Circulation;
34 use C4::Tags qw(get_tags);
35 use C4::XISBN qw(get_xisbns);
36 use C4::External::Amazon;
37 use C4::External::BakerTaylor qw( image_url link_url );
38 use C4::External::Syndetics qw(get_syndetics_index get_syndetics_summary get_syndetics_toc get_syndetics_excerpt get_syndetics_reviews get_syndetics_anotes );
39 use C4::Members;
40 use C4::XSLT;
41 use C4::ShelfBrowser;
42 use C4::Reserves;
43 use C4::Charset;
44 use C4::Letters;
45 use MARC::Record;
46 use MARC::Field;
47 use List::MoreUtils qw/any none/;
48 use C4::Images;
49 use Koha::DateUtils;
50 use C4::HTML5Media;
51 use C4::CourseReserves qw(GetItemCourseReservesInfo);
53 use Koha::Biblios;
54 use Koha::RecordProcessor;
55 use Koha::AuthorisedValues;
56 use Koha::CirculationRules;
57 use Koha::Items;
58 use Koha::ItemTypes;
59 use Koha::Acquisition::Orders;
60 use Koha::Virtualshelves;
61 use Koha::Patrons;
62 use Koha::Plugins;
63 use Koha::Ratings;
64 use Koha::Reviews;
65 use Koha::SearchEngine::Search;
67 use Try::Tiny;
69 my $query = CGI->new();
71 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
72 $biblionumber = int($biblionumber);
74 my $specific_item = $query->param('itemnumber') ? Koha::Items->find( scalar $query->param('itemnumber') ) : undef;
75 $biblionumber = $specific_item->biblionumber if $specific_item;
77 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
79 template_name => "opac-detail.tt",
80 query => $query,
81 type => "opac",
82 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
86 my @all_items = GetItemsInfo($biblionumber);
87 if( $specific_item ) {
88 @all_items = grep { $_->{itemnumber} == $query->param('itemnumber') } @all_items;
89 $template->param( specific_item => 1 );
91 my @hiddenitems;
92 my $patron = Koha::Patrons->find( $borrowernumber );
93 our $borcat= q{};
94 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
95 $borcat = $patron ? $patron->categorycode : q{};
98 my $record = GetMarcBiblio({
99 biblionumber => $biblionumber,
100 opac => 1 });
101 if ( ! $record ) {
102 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
103 exit;
106 if ( scalar @all_items >= 1 ) {
107 push @hiddenitems,
108 GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } );
110 if (scalar @hiddenitems == scalar @all_items ) {
111 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
112 exit;
116 my $biblio = Koha::Biblios->find( $biblionumber );
117 my $framework = $biblio ? $biblio->frameworkcode : q{};
118 my $record_processor = Koha::RecordProcessor->new({
119 filters => 'ViewPolicy',
120 options => {
121 interface => 'opac',
122 frameworkcode => $framework
125 $record_processor->process($record);
127 # redirect if opacsuppression is enabled and biblio is suppressed
128 if (C4::Context->preference('OpacSuppression')) {
129 # FIXME hardcoded; the suppression flag ought to be materialized
130 # as a column on biblio or the like
131 my $opacsuppressionfield = '942';
132 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
133 # redirect to opac-blocked info page or 404?
134 my $opacsuppressionredirect;
135 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
136 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
137 } else {
138 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
140 if ( $opacsuppressionfieldvalue &&
141 $opacsuppressionfieldvalue->subfield("n") &&
142 $opacsuppressionfieldvalue->subfield("n") == 1) {
143 # if OPAC suppression by IP address
144 if (C4::Context->preference('OpacSuppressionByIPRange')) {
145 my $IPAddress = $ENV{'REMOTE_ADDR'};
146 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
147 if ($IPAddress !~ /^$IPRange/) {
148 print $query->redirect($opacsuppressionredirect);
149 exit;
151 } else {
152 print $query->redirect($opacsuppressionredirect);
153 exit;
158 $template->param(
159 biblio => $biblio
162 # get biblionumbers stored in the cart
163 my @cart_list;
165 if($query->cookie("bib_list")){
166 my $cart_list = $query->cookie("bib_list");
167 @cart_list = split(/\//, $cart_list);
168 if ( grep {$_ eq $biblionumber} @cart_list) {
169 $template->param( incart => 1 );
174 SetUTF8Flag($record);
175 my $marcflavour = C4::Context->preference("marcflavour");
176 my $ean = GetNormalizedEAN( $record, $marcflavour );
178 # XSLT processing of some stuff
179 my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
180 my $lang = $xslfile ? C4::Languages::getlanguage() : undef;
181 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
183 if ( $xslfile ) {
185 my $searcher = Koha::SearchEngine::Search->new(
186 { index => $Koha::SearchEngine::BIBLIOS_INDEX }
188 my $cleaned_title = $biblio->title;
189 $cleaned_title =~ tr|/||;
190 my $query =
191 ( C4::Context->preference('UseControlNumber') and $record->field('001') )
192 ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
193 : "Host-item:$cleaned_title";
194 my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
196 warn "Warning from simple_search_compat: $err"
197 if $err;
199 my $variables = {
200 anonymous_session => ($borrowernumber) ? 0 : 1,
201 show_analytics_link => $count > 0 ? 1 : 0
204 my @plugin_responses = Koha::Plugins->call(
205 'opac_detail_xslt_variables',
207 biblio_id => $biblionumber,
208 lang => $lang,
209 patron_id => $borrowernumber
213 for my $plugin_variables ( @plugin_responses ) {
214 $variables = { %$variables, %$plugin_variables };
217 $template->param(
218 XSLTBloc => XSLTParse4Display(
219 $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
220 $sysxml, $xslfile, $lang, $variables
225 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
227 # We look for the busc param to build the simple paging from the search
228 if ($OpacBrowseResults) {
229 my $session = get_session($query->cookie("CGISESSID"));
230 my %paging = (previous => {}, next => {});
231 if ($session->param('busc')) {
232 use C4::Search;
233 use URI::Escape;
235 # Rebuild the string to store on session
236 # param value is URI encoded and params separator is HTML encode (&amp;)
237 sub rebuildBuscParam
239 my $arrParamsBusc = shift;
241 my $pasarParams = '';
242 my $j = 0;
243 for (keys %$arrParamsBusc) {
244 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
245 if (defined($arrParamsBusc->{$_})) {
246 $pasarParams .= '&amp;' if ($j);
247 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
248 $j++;
250 } else {
251 for my $value (@{$arrParamsBusc->{$_}}) {
252 next if !defined($value);
253 $pasarParams .= '&amp;' if ($j);
254 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
255 $j++;
259 return $pasarParams;
260 }#rebuildBuscParam
262 # Search given the current values from the busc param
263 sub searchAgain
265 my ($arrParamsBusc, $offset, $results_per_page) = @_;
267 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
268 my @servers;
269 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
270 @servers = ("biblioserver") unless (@servers);
272 my ($default_sort_by, @sort_by);
273 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
274 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
275 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
276 my ($error, $results_hashref, $facets);
277 eval {
278 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
280 my $hits;
281 my @newresults;
282 my $search_context = {
283 'interface' => 'opac',
284 'category' => $borcat
286 for (my $i=0;$i<@servers;$i++) {
287 my $server = $servers[$i];
288 $hits = $results_hashref->{$server}->{"hits"};
289 @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
291 return \@newresults;
292 }#searchAgain
294 # Build the current list of biblionumbers in this search
295 sub buildListBiblios
297 my ($newresultsRef, $results_per_page) = @_;
299 my $listBiblios = '';
300 my $j = 0;
301 foreach (@$newresultsRef) {
302 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
303 $listBiblios .= $bibnum . ',';
304 $j++;
305 last if ($j == $results_per_page);
307 chop $listBiblios if ($listBiblios =~ /,$/);
308 return $listBiblios;
309 }#buildListBiblios
311 my $busc = $session->param("busc");
312 my @arrBusc = split(/\&(?:amp;)?/, $busc);
313 my ($key, $value);
314 my %arrParamsBusc = ();
315 for (@arrBusc) {
316 ($key, $value) = split(/=/, $_, 2);
317 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
318 $arrParamsBusc{$key} = uri_unescape($value);
319 } else {
320 unless (exists($arrParamsBusc{$key})) {
321 $arrParamsBusc{$key} = [];
323 push @{$arrParamsBusc{$key}}, uri_unescape($value);
326 my $searchAgain = 0;
327 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
328 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
329 $arrParamsBusc{'count'} = $results_per_page;
330 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
331 # The value OPACnumSearchResults has changed and the search has to be rebuild
332 if ($count != $results_per_page) {
333 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
334 my $indexBiblio = 0;
335 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
336 for (@arrBibliosAux) {
337 last if ($_ == $biblionumber);
338 $indexBiblio++;
340 $indexBiblio += $offset;
341 $offset = int($indexBiblio / $count) * $count;
342 $arrParamsBusc{'offset'} = $offset;
344 $arrParamsBusc{'count'} = $count;
345 $results_per_page = $count;
346 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
347 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
348 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
349 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
350 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
351 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
352 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
353 $session->param("busc" => $newbusc);
354 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
355 } else {
356 my $modifyListBiblios = 0;
357 # We come from a previous click
358 if (exists($arrParamsBusc{'previous'})) {
359 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
360 delete $arrParamsBusc{'previous'};
361 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
362 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
363 delete $arrParamsBusc{'next'};
365 if ($modifyListBiblios) {
366 if (exists($arrParamsBusc{'newlistBiblios'})) {
367 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
368 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
369 my @arrAux = split(',', $listBibliosAux);
370 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
371 if ($modifyListBiblios == 1) {
372 $arrParamsBusc{'next'} = $arrAux[0];
373 $paging{'next'}->{biblionumber} = $arrAux[0];
374 }else {
375 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
376 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
378 } else {
379 delete $arrParamsBusc{'listBiblios'};
381 my $offsetAux = $arrParamsBusc{'offset'};
382 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
383 $arrParamsBusc{'offsetSearch'} = $offsetAux;
384 $offset = $arrParamsBusc{'offset'};
385 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
386 $session->param("busc" => $newbusc);
387 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
390 my $buscParam = '';
391 my $j = 0;
392 # Rebuild the query for the button "back to results"
393 for (@arrBusc) {
394 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
395 $buscParam .= '&amp;' unless ($j == 0);
396 $buscParam .= $_; # string already URI encoded
397 $j++;
400 $template->param('busc' => $buscParam);
401 my $offsetSearch;
402 my @arrBiblios;
403 # We are inside the list of biblios and we don't have to search
404 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
405 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
406 if (@arrBiblios) {
407 # We are at the first item of the list
408 if ($arrBiblios[0] == $biblionumber) {
409 if (@arrBiblios > 1) {
410 for (my $j = 1; $j < @arrBiblios; $j++) {
411 next unless ($arrBiblios[$j]);
412 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
413 last;
416 # search again if we are not at the first searching list
417 if ($offset && !$arrParamsBusc{'previous'}) {
418 $searchAgain = 1;
419 $offsetSearch = $offset - $results_per_page;
421 # we are at the last item of the list
422 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
423 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
424 next unless ($arrBiblios[$j]);
425 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
426 last;
428 if (!$offset) {
429 # search again if we are at the first list and there is more results
430 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
431 } else {
432 # search again if we aren't at the first list and there is more results
433 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
435 $offsetSearch = $offset + $results_per_page if ($searchAgain);
436 } else {
437 for (my $j = 1; $j < $#arrBiblios; $j++) {
438 if ($arrBiblios[$j] == $biblionumber) {
439 for (my $z = $j - 1; $z >= 0; $z--) {
440 next unless ($arrBiblios[$z]);
441 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
442 last;
444 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
445 next unless ($arrBiblios[$z]);
446 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
447 last;
449 last;
454 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
456 if ($searchAgain) {
457 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
458 my @newresults = @$newresultsRef;
459 # build the new listBiblios
460 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
461 unless (exists($arrParamsBusc{'listBiblios'})) {
462 $arrParamsBusc{'listBiblios'} = $listBiblios;
463 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
464 } else {
465 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
467 # From the new list we build again the next and previous result
468 if (@arrBiblios) {
469 if ($arrBiblios[0] == $biblionumber) {
470 for (my $j = $#newresults; $j >= 0; $j--) {
471 next unless ($newresults[$j]);
472 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
473 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
474 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
475 last;
477 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
478 for (my $j = 0; $j < @newresults; $j++) {
479 next unless ($newresults[$j]);
480 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
481 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
482 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
483 last;
487 # build new busc param
488 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
489 $session->param("busc" => $newbusc);
491 my ($numberBiblioPaging, $dataBiblioPaging);
492 # Previous biblio
493 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
494 if ($numberBiblioPaging) {
495 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
496 $dataBiblioPaging = Koha::Biblios->find( $numberBiblioPaging );
497 $template->param('previousTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
499 # Next biblio
500 $numberBiblioPaging = $paging{'next'}->{biblionumber};
501 if ($numberBiblioPaging) {
502 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
503 $dataBiblioPaging = Koha::Biblios->find( $numberBiblioPaging );
504 $template->param('nextTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
506 # Partial list of biblio results
507 my @listResults;
508 for (my $j = 0; $j < @arrBiblios; $j++) {
509 next unless ($arrBiblios[$j]);
510 $dataBiblioPaging = Koha::Biblios->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber);
511 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]};
513 $template->param('listResults' => \@listResults) if (@listResults);
514 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
515 $template->param( 'offset' => $offset );
519 $template->param(
520 OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"),
523 if ( C4::Context->preference('EasyAnalyticalRecords') ) {
524 # adding items linked via host biblios
525 my $analyticfield = '773';
526 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
527 $analyticfield = '773';
528 } elsif ($marcflavour eq 'UNIMARC') {
529 $analyticfield = '461';
531 foreach my $hostfield ( $record->field($analyticfield)) {
532 my $hostbiblionumber = $hostfield->subfield("0");
533 my $linkeditemnumber = $hostfield->subfield("9");
534 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
535 foreach my $hostitemInfo (@hostitemInfos){
536 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
537 push(@all_items, $hostitemInfo);
543 my @items;
545 # Are there items to hide?
546 my $hideitems;
547 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
549 # Hide items
550 if ($hideitems) {
551 for my $itm (@all_items) {
552 if ( C4::Context->preference('hidelostitems') ) {
553 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
554 } else {
555 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
558 } else {
559 # Or not
560 @items = @all_items;
563 my $branch = '';
564 if (C4::Context->userenv){
565 $branch = C4::Context->userenv->{branch};
567 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
568 if (
569 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
571 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
573 my $branchcode;
574 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
575 $branchcode = $branch;
577 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
578 $branchcode = $ENV{'BRANCHCODE'};
581 my @our_items;
582 my @other_items;
584 foreach my $item ( @items ) {
585 if ( $item->{branchcode} eq $branchcode ) {
586 $item->{'this_branch'} = 1;
587 push( @our_items, $item );
588 } else {
589 push( @other_items, $item );
593 @items = ( @our_items, @other_items );
597 my $dat = &GetBiblioData($biblionumber);
598 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
600 frameworkcode => $dat->{'frameworkcode'},
601 interface => 'opac',
602 } );
604 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
605 # imageurl:
606 my $itemtype = $dat->{'itemtype'};
607 if ( $itemtype ) {
608 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
609 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
612 my $shelflocations =
613 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
614 my $collections =
615 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
616 my $copynumbers =
617 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.copynumber' } ) };
619 #coping with subscriptions
620 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
621 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
623 my @subs;
624 $dat->{'serial'}=1 if $subscriptionsnumber;
625 foreach my $subscription (@subscriptions) {
626 my $serials_to_display;
627 my %cell;
628 $cell{subscriptionid} = $subscription->{subscriptionid};
629 $cell{subscriptionnotes} = $subscription->{notes};
630 $cell{missinglist} = $subscription->{missinglist};
631 $cell{opacnote} = $subscription->{opacnote};
632 $cell{histstartdate} = $subscription->{histstartdate};
633 $cell{histenddate} = $subscription->{histenddate};
634 $cell{branchcode} = $subscription->{branchcode};
635 $cell{callnumber} = $subscription->{callnumber};
636 $cell{location} = $subscription->{location};
637 $cell{closed} = $subscription->{closed};
638 $cell{letter} = $subscription->{letter};
639 $cell{biblionumber} = $subscription->{biblionumber};
640 #get the three latest serials.
641 $serials_to_display = $subscription->{opacdisplaycount};
642 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
643 $cell{opacdisplaycount} = $serials_to_display;
644 $cell{latestserials} =
645 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
646 if ( $borrowernumber ) {
647 my $subscription_object = Koha::Subscriptions->find( $subscription->{subscriptionid} );
648 my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
649 $cell{hasalert} = 1 if $subscriber;
651 push @subs, \%cell;
654 $dat->{'count'} = scalar(@items);
657 my (%item_reserves, %priority);
658 my ($show_holds_count, $show_priority);
659 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
660 m/holds/o and $show_holds_count = 1;
661 m/priority/ and $show_priority = 1;
663 my $has_hold;
664 if ( $show_holds_count || $show_priority) {
665 my $holds = $biblio->holds;
666 $template->param( holds_count => $holds->count );
667 while ( my $hold = $holds->next ) {
668 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
669 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
670 $has_hold = 1;
671 $hold->itemnumber
672 ? ($priority{ $hold->itemnumber } = $hold->priority)
673 : ($template->param( priority => $hold->priority ));
677 $template->param( show_priority => $has_hold ) ;
679 my $norequests = 1;
680 my %itemfields;
681 my (@itemloop, @otheritemloop);
682 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
683 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
684 $template->param(SeparateHoldings => 1);
686 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
687 my $viewallitems = $query->param('viewallitems');
688 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
690 # Get items on order
691 my ( @itemnumbers_on_order );
692 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
693 my $orders = C4::Acquisition::SearchOrders({
694 biblionumber => $biblionumber,
695 ordered => 1,
697 my $total_quantity = 0;
698 for my $order ( @$orders ) {
699 my $order = Koha::Acquisition::Orders->find( $order->{ordernumber} );
700 my $basket = $order->basket;
701 if ( $basket->effective_create_items eq 'ordering' ) {
702 @itemnumbers_on_order = $order->items->get_column('itemnumber');
704 $total_quantity += $order->quantity;
706 $template->{VARS}->{acquisition_details} = {
707 total_quantity => $total_quantity,
711 my $allow_onshelf_holds;
712 my ( $itemloop_has_images, $otheritemloop_has_images );
713 if ( not $viewallitems and @items > $max_items_to_display ) {
714 $template->param(
715 too_many_items => 1,
716 items_count => scalar( @items ),
718 } else {
719 for my $itm (@items) {
720 my $item = Koha::Items->find( $itm->{itemnumber} );
721 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
722 $itm->{priority} = $priority{ $itm->{itemnumber} };
723 $norequests = 0
724 if $norequests
725 && !$itm->{'withdrawn'}
726 && !$itm->{'itemlost'}
727 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
728 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
729 && $itm->{'itemnumber'};
731 $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
732 unless $allow_onshelf_holds;
734 # get collection code description, too
735 my $ccode = $itm->{'ccode'};
736 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
737 my $copynumber = $itm->{'copynumber'};
738 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
739 if ( defined $itm->{'location'} ) {
740 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
742 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
743 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
744 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description};
746 foreach (qw(ccode materials enumchron copynumber itemnotes location_description uri)) {
747 $itemfields{$_} = 1 if ($itm->{$_});
750 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
751 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
752 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
754 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
755 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
756 $itm->{transfertwhen} = $transfertwhen;
757 $itm->{transfertfrom} = $transfertfrom;
758 $itm->{transfertto} = $transfertto;
761 if ( C4::Context->preference('OPACAcquisitionDetails') ) {
762 $itm->{on_order} = 1
763 if grep { $_ eq $itm->{itemnumber} } @itemnumbers_on_order;
766 if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
767 $itm->{imagenumber} =
768 C4::Images::GetImageForItem( $itm->{itemnumber} );
771 my $itembranch = $itm->{$separatebranch};
772 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
773 if ($itembranch and $itembranch eq $currentbranch) {
774 push @itemloop, $itm;
775 $itemloop_has_images++ if $itm->{imagenumber};
776 } else {
777 push @otheritemloop, $itm;
778 $otheritemloop_has_images++ if $itm->{imagenumber};
780 } else {
781 push @itemloop, $itm;
782 $itemloop_has_images++ if $itm->{imagenumber};
787 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
788 $template->param( ReservableItems => 1 );
791 $template->param(
792 itemloop_has_images => $itemloop_has_images,
793 otheritemloop_has_images => $otheritemloop_has_images,
796 # Display only one tab if one items list is empty
797 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
798 $template->param(SeparateHoldings => 0);
799 if (scalar(@itemloop) == 0) {
800 @itemloop = @otheritemloop;
804 ## get notes and subjects from MARC record
805 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
806 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
807 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
808 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
809 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
810 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
812 $template->param(
813 MARCSUBJCTS => $marcsubjctsarray,
814 MARCAUTHORS => $marcauthorsarray,
815 MARCSERIES => $marcseriesarray,
816 MARCURLS => $marcurlsarray,
817 MARCISBNS => $marcisbnsarray,
821 my $marcnotesarray = GetMarcNotes ($record,$marcflavour,1);
823 if( C4::Context->preference('ArticleRequests') ) {
824 my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
825 my $itemtype = Koha::ItemTypes->find($biblio->itemtype);
826 my $artreqpossible = $patron
827 ? $biblio->can_article_request( $patron )
828 : $itemtype
829 ? $itemtype->may_article_request
830 : q{};
831 $template->param( artreqpossible => $artreqpossible );
834 $template->param(
835 MARCNOTES => $marcnotesarray,
836 norequests => $norequests,
837 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
838 itemdata_ccode => $itemfields{ccode},
839 itemdata_materials => $itemfields{materials},
840 itemdata_enumchron => $itemfields{enumchron},
841 itemdata_uri => $itemfields{uri},
842 itemdata_copynumber => $itemfields{copynumber},
843 itemdata_itemnotes => $itemfields{itemnotes},
844 itemdata_location => $itemfields{location_description},
845 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
848 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
849 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
850 my $subfields = substr $fieldspec, 3;
851 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
852 my @alternateholdingsinfo = ();
853 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
855 for my $field (@holdingsfields) {
856 my %holding = ( holding => '' );
857 my $havesubfield = 0;
858 for my $subfield ($field->subfields()) {
859 if ((index $subfields, $$subfield[0]) >= 0) {
860 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
861 $holding{'holding'} .= $$subfield[1];
862 $havesubfield++;
865 if ($havesubfield) {
866 push(@alternateholdingsinfo, \%holding);
870 $template->param(
871 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
875 # FIXME: The template uses this hash directly. Need to filter.
876 foreach ( keys %{$dat} ) {
877 next if ( $HideMARC->{$_} );
878 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
881 # some useful variables for enhanced content;
882 # in each case, we're grabbing the first value we find in
883 # the record and normalizing it
884 my $upc = GetNormalizedUPC($record,$marcflavour);
885 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
886 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
887 my $content_identifier_exists;
888 if ( $isbn or $ean or $oclc or $upc ) {
889 $content_identifier_exists = 1;
891 $template->param(
892 normalized_upc => $upc,
893 normalized_ean => $ean,
894 normalized_oclc => $oclc,
895 normalized_isbn => $isbn,
896 content_identifier_exists => $content_identifier_exists,
899 # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid
900 # COinS format FIXME: for books Only
901 my $coins = eval { $biblio->get_coins };
902 $template->param( ocoins => $coins );
904 my ( $loggedincommenter, $reviews );
905 if ( C4::Context->preference('reviewson') ) {
906 $reviews = Koha::Reviews->search(
908 biblionumber => $biblionumber,
909 -or => { approved => 1, borrowernumber => $borrowernumber }
912 order_by => { -desc => 'datereviewed' }
914 )->unblessed;
915 my $libravatar_enabled = 0;
916 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto') ) {
917 eval {
918 require Libravatar::URL;
919 Libravatar::URL->import();
921 if ( !$@ ) {
922 $libravatar_enabled = 1;
925 for my $review (@$reviews) {
926 my $review_patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
928 # setting some borrower info into this hash
929 if ( $review_patron ) {
930 $review->{patron} = $review_patron;
931 if ( $libravatar_enabled and $review_patron->email ) {
932 $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} );
935 if ( $review_patron->borrowernumber eq $borrowernumber ) {
936 $loggedincommenter = 1;
942 if ( C4::Context->preference("OPACISBD") ) {
943 $template->param( ISBD => 1 );
946 $template->param(
947 itemloop => \@itemloop,
948 otheritemloop => \@otheritemloop,
949 biblionumber => $biblionumber,
950 subscriptions => \@subs,
951 subscriptionsnumber => $subscriptionsnumber,
952 reviews => $reviews,
953 loggedincommenter => $loggedincommenter
956 # Lists
957 if (C4::Context->preference("virtualshelves") ) {
958 my $shelves = Koha::Virtualshelves->search(
960 biblionumber => $biblionumber,
961 category => 2,
964 join => 'virtualshelfcontents',
967 $template->param( shelves => $shelves );
970 # XISBN Stuff
971 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
972 eval {
973 $template->param(
974 XISBNS => scalar get_xisbns($isbn, $biblionumber)
977 if ($@) { warn "XISBN Failed $@"; }
980 # Serial Collection
981 my @sc_fields = $record->field(955);
982 my @lc_fields = $marcflavour eq 'UNIMARC'
983 ? $record->field(930)
984 : $record->field(852);
985 my @serialcollections = ();
987 foreach my $sc_field (@sc_fields) {
988 my %row_data;
990 $row_data{text} = $sc_field->subfield('r');
991 $row_data{branch} = $sc_field->subfield('9');
992 foreach my $lc_field (@lc_fields) {
993 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
994 ? $lc_field->subfield('a') # 930$a
995 : $lc_field->subfield('h') # 852$h
996 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
999 if ($row_data{text} && $row_data{branch}) {
1000 push (@serialcollections, \%row_data);
1004 if (scalar(@serialcollections) > 0) {
1005 $template->param(
1006 serialcollection => 1,
1007 serialcollections => \@serialcollections);
1010 # Local cover Images stuff
1011 if (C4::Context->preference("OPACLocalCoverImages")){
1012 $template->param(OPACLocalCoverImages => 1);
1015 # HTML5 Media
1016 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
1017 $template->param( C4::HTML5Media->gethtml5media($record));
1020 my $syndetics_elements;
1022 if ( C4::Context->preference("SyndeticsEnabled") ) {
1023 $template->param("SyndeticsEnabled" => 1);
1024 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
1025 eval {
1026 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
1027 for my $element (values %$syndetics_elements) {
1028 $template->param("Syndetics$element"."Exists" => 1 );
1029 #warn "Exists: "."Syndetics$element"."Exists";
1032 warn $@ if $@;
1035 if ( C4::Context->preference("SyndeticsEnabled")
1036 && C4::Context->preference("SyndeticsSummary")
1037 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
1038 eval {
1039 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
1040 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
1042 warn $@ if $@;
1046 if ( C4::Context->preference("SyndeticsEnabled")
1047 && C4::Context->preference("SyndeticsTOC")
1048 && exists($syndetics_elements->{'TOC'}) ) {
1049 eval {
1050 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
1051 $template->param( SYNDETICS_TOC => $syndetics_toc );
1053 warn $@ if $@;
1056 if ( C4::Context->preference("SyndeticsEnabled")
1057 && C4::Context->preference("SyndeticsExcerpt")
1058 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
1059 eval {
1060 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
1061 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
1063 warn $@ if $@;
1066 if ( C4::Context->preference("SyndeticsEnabled")
1067 && C4::Context->preference("SyndeticsReviews")) {
1068 eval {
1069 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
1070 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
1072 warn $@ if $@;
1075 if ( C4::Context->preference("SyndeticsEnabled")
1076 && C4::Context->preference("SyndeticsAuthorNotes")
1077 && exists($syndetics_elements->{'ANOTES'}) ) {
1078 eval {
1079 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
1080 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
1082 warn $@ if $@;
1085 # LibraryThingForLibraries ID Code and Tabbed View Option
1086 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
1088 $template->param(LibraryThingForLibrariesID =>
1089 C4::Context->preference('LibraryThingForLibrariesID') );
1090 $template->param(LibraryThingForLibrariesTabbedView =>
1091 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
1094 # Novelist Select
1095 if( C4::Context->preference('NovelistSelectEnabled') )
1097 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
1098 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
1099 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
1103 # Babelthèque
1104 if ( C4::Context->preference("Babeltheque") ) {
1105 $template->param(
1106 Babeltheque => 1,
1107 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
1111 # Social Networks
1112 if ( C4::Context->preference( "SocialNetworks" ) ) {
1113 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1114 $template->param( SocialNetworks => 1 );
1117 # Shelf Browser Stuff
1118 if (C4::Context->preference("OPACShelfBrowser")) {
1119 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1120 if (defined($starting_itemnumber)) {
1121 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
1122 my $nearby = GetNearbyItems($starting_itemnumber);
1124 $template->param(
1125 starting_itemnumber => $starting_itemnumber,
1126 starting_homebranch => $nearby->{starting_homebranch}->{description},
1127 starting_location => $nearby->{starting_location}->{description},
1128 starting_ccode => $nearby->{starting_ccode}->{description},
1129 shelfbrowser_prev_item => $nearby->{prev_item},
1130 shelfbrowser_next_item => $nearby->{next_item},
1131 shelfbrowser_items => $nearby->{items},
1134 # in which tab shelf browser should open ?
1135 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
1136 $template->param(shelfbrowser_tab => 'holdings');
1137 } else {
1138 $template->param(shelfbrowser_tab => 'otherholdings');
1143 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
1145 if (C4::Context->preference("BakerTaylorEnabled")) {
1146 $template->param(
1147 BakerTaylorEnabled => 1,
1148 BakerTaylorImageURL => &image_url(),
1149 BakerTaylorLinkURL => &link_url(),
1150 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1152 my ($bt_user, $bt_pass);
1153 if ($isbn and
1154 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1155 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1157 $template->param(
1158 BakerTaylorContentURL =>
1159 sprintf("https://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1160 $bt_user,$bt_pass,$isbn)
1165 my $tag_quantity;
1166 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1167 $template->param(
1168 TagsEnabled => 1,
1169 TagsShowOnDetail => $tag_quantity,
1170 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1172 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1173 'sort'=>'-weight', limit=>$tag_quantity}));
1176 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1177 # These values are going to be read by Javascript, at least in the case
1178 # of the google covers
1179 $template->param(covernewwindow => 'true');
1180 } else {
1181 $template->param(covernewwindow => 'false');
1184 $template->param(borrowernumber => $borrowernumber);
1186 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1187 my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
1188 my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
1189 $template->param(
1190 ratings => $ratings,
1191 my_rating => $my_rating,
1195 #Search for title in links
1196 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1197 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1198 my $issn = $marcissns->[0] || '';
1200 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1201 $dat->{title} =~ s/\/+$//; # remove trailing slash
1202 $dat->{title} =~ s/\s+$//; # remove trailing space
1203 $search_for_title = parametrized_url(
1204 $search_for_title,
1206 TITLE => $dat->{title},
1207 AUTHOR => $dat->{author},
1208 ISBN => $isbn,
1209 ISSN => $issn,
1210 CONTROLNUMBER => $marccontrolnumber,
1211 BIBLIONUMBER => $biblionumber,
1214 $template->param('OPACSearchForTitleIn' => $search_for_title);
1217 #IDREF
1218 if ( C4::Context->preference("IDREF") ) {
1219 # If the record comes from the SUDOC
1220 if ( $record->field('009') ) {
1221 my $unimarc3 = $record->field("009")->data;
1222 if ( $unimarc3 =~ /^\d+$/ ) {
1223 $template->param(
1224 IDREF => 1,
1230 # We try to select the best default tab to show, according to what
1231 # the user wants, and what's available for display
1232 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1233 my $defaulttab =
1234 $viewallitems
1235 ? 'holdings' :
1236 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1237 ? 'subscriptions' :
1238 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1239 ? 'serialcollection' :
1240 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1241 ? 'holdings' :
1242 scalar (@itemloop) == 0
1243 ? 'media' :
1244 $subscriptionsnumber
1245 ? 'subscriptions' :
1246 @serialcollections > 0
1247 ? 'serialcollection' : 'subscriptions';
1248 $template->param('defaulttab' => $defaulttab);
1250 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1251 my @images = ListImagesForBiblio($biblionumber);
1252 $template->{VARS}->{localimages} = \@images;
1255 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1257 if (C4::Context->preference('OpacHighlightedWords')) {
1258 $template->{VARS}->{query_desc} = $query->param('query_desc');
1260 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1262 if ( C4::Context->preference('UseCourseReserves') ) {
1263 foreach my $i ( @items ) {
1264 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1268 $template->param(
1269 'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay'),
1272 output_html_with_http_headers $query, $cookie, $template->output;