Bug 26145: Refactoring - Move C4::Images to Koha::CoverImages
[koha.git] / opac / opac-detail.pl
blob67c074cd70ab25a6c4bd8510d646e65199fd8099
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 Koha::DateUtils;
49 use C4::HTML5Media;
50 use C4::CourseReserves qw(GetItemCourseReservesInfo);
52 use Koha::Biblios;
53 use Koha::RecordProcessor;
54 use Koha::AuthorisedValues;
55 use Koha::CirculationRules;
56 use Koha::Items;
57 use Koha::ItemTypes;
58 use Koha::Acquisition::Orders;
59 use Koha::Virtualshelves;
60 use Koha::Patrons;
61 use Koha::Plugins;
62 use Koha::Ratings;
63 use Koha::Reviews;
64 use Koha::SearchEngine::Search;
66 use Try::Tiny;
68 my $query = CGI->new();
70 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || 0;
71 $biblionumber = int($biblionumber);
73 my $specific_item = $query->param('itemnumber') ? Koha::Items->find( scalar $query->param('itemnumber') ) : undef;
74 $biblionumber = $specific_item->biblionumber if $specific_item;
76 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
78 template_name => "opac-detail.tt",
79 query => $query,
80 type => "opac",
81 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
85 my @all_items = GetItemsInfo($biblionumber);
86 if( $specific_item ) {
87 @all_items = grep { $_->{itemnumber} == $query->param('itemnumber') } @all_items;
88 $template->param( specific_item => 1 );
90 my @hiddenitems;
91 my $patron = Koha::Patrons->find( $borrowernumber );
92 our $borcat= q{};
93 if ( C4::Context->preference('OpacHiddenItemsExceptions') ) {
94 $borcat = $patron ? $patron->categorycode : q{};
97 my $record = GetMarcBiblio({
98 biblionumber => $biblionumber,
99 opac => 1 });
100 if ( ! $record ) {
101 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
102 exit;
105 if ( scalar @all_items >= 1 ) {
106 push @hiddenitems,
107 GetHiddenItemnumbers( { items => \@all_items, borcat => $borcat } );
109 if (scalar @hiddenitems == scalar @all_items ) {
110 print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
111 exit;
115 my $biblio = Koha::Biblios->find( $biblionumber );
116 my $framework = $biblio ? $biblio->frameworkcode : q{};
117 my $record_processor = Koha::RecordProcessor->new({
118 filters => 'ViewPolicy',
119 options => {
120 interface => 'opac',
121 frameworkcode => $framework
124 $record_processor->process($record);
126 # redirect if opacsuppression is enabled and biblio is suppressed
127 if (C4::Context->preference('OpacSuppression')) {
128 # FIXME hardcoded; the suppression flag ought to be materialized
129 # as a column on biblio or the like
130 my $opacsuppressionfield = '942';
131 my $opacsuppressionfieldvalue = $record->field($opacsuppressionfield);
132 # redirect to opac-blocked info page or 404?
133 my $opacsuppressionredirect;
134 if ( C4::Context->preference("OpacSuppressionRedirect") ) {
135 $opacsuppressionredirect = "/cgi-bin/koha/opac-blocked.pl";
136 } else {
137 $opacsuppressionredirect = "/cgi-bin/koha/errors/404.pl";
139 if ( $opacsuppressionfieldvalue &&
140 $opacsuppressionfieldvalue->subfield("n") &&
141 $opacsuppressionfieldvalue->subfield("n") == 1) {
142 # if OPAC suppression by IP address
143 if (C4::Context->preference('OpacSuppressionByIPRange')) {
144 my $IPAddress = $ENV{'REMOTE_ADDR'};
145 my $IPRange = C4::Context->preference('OpacSuppressionByIPRange');
146 if ($IPAddress !~ /^$IPRange/) {
147 print $query->redirect($opacsuppressionredirect);
148 exit;
150 } else {
151 print $query->redirect($opacsuppressionredirect);
152 exit;
157 $template->param(
158 biblio => $biblio
161 # get biblionumbers stored in the cart
162 my @cart_list;
164 if($query->cookie("bib_list")){
165 my $cart_list = $query->cookie("bib_list");
166 @cart_list = split(/\//, $cart_list);
167 if ( grep {$_ eq $biblionumber} @cart_list) {
168 $template->param( incart => 1 );
173 SetUTF8Flag($record);
174 my $marcflavour = C4::Context->preference("marcflavour");
175 my $ean = GetNormalizedEAN( $record, $marcflavour );
177 # XSLT processing of some stuff
178 my $xslfile = C4::Context->preference('OPACXSLTDetailsDisplay');
179 my $lang = $xslfile ? C4::Languages::getlanguage() : undef;
180 my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
182 if ( $xslfile ) {
184 my $searcher = Koha::SearchEngine::Search->new(
185 { index => $Koha::SearchEngine::BIBLIOS_INDEX }
187 my $cleaned_title = $biblio->title;
188 $cleaned_title =~ tr|/||;
189 my $query =
190 ( C4::Context->preference('UseControlNumber') and $record->field('001') )
191 ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
192 : "Host-item:$cleaned_title";
193 my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
195 warn "Warning from simple_search_compat: $err"
196 if $err;
198 my $variables = {
199 anonymous_session => ($borrowernumber) ? 0 : 1,
200 show_analytics_link => $count > 0 ? 1 : 0
203 my @plugin_responses = Koha::Plugins->call(
204 'opac_detail_xslt_variables',
206 biblio_id => $biblionumber,
207 lang => $lang,
208 patron_id => $borrowernumber
212 for my $plugin_variables ( @plugin_responses ) {
213 $variables = { %$variables, %$plugin_variables };
216 $template->param(
217 XSLTBloc => XSLTParse4Display(
218 $biblionumber, $record, "OPACXSLTDetailsDisplay", 1, undef,
219 $sysxml, $xslfile, $lang, $variables
224 my $OpacBrowseResults = C4::Context->preference("OpacBrowseResults");
226 # We look for the busc param to build the simple paging from the search
227 if ($OpacBrowseResults) {
228 my $session = get_session($query->cookie("CGISESSID"));
229 my %paging = (previous => {}, next => {});
230 if ($session->param('busc')) {
231 use C4::Search;
232 use URI::Escape;
234 # Rebuild the string to store on session
235 # param value is URI encoded and params separator is HTML encode (&amp;)
236 sub rebuildBuscParam
238 my $arrParamsBusc = shift;
240 my $pasarParams = '';
241 my $j = 0;
242 for (keys %$arrParamsBusc) {
243 if ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|total|offset|offsetSearch|next|previous|count|expand|scan)/) {
244 if (defined($arrParamsBusc->{$_})) {
245 $pasarParams .= '&amp;' if ($j);
246 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8( $arrParamsBusc->{$_} ));
247 $j++;
249 } else {
250 for my $value (@{$arrParamsBusc->{$_}}) {
251 next if !defined($value);
252 $pasarParams .= '&amp;' if ($j);
253 $pasarParams .= $_ . '=' . Encode::decode('UTF-8', uri_escape_utf8($value));
254 $j++;
258 return $pasarParams;
259 }#rebuildBuscParam
261 # Search given the current values from the busc param
262 sub searchAgain
264 my ($arrParamsBusc, $offset, $results_per_page) = @_;
266 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
267 my @servers;
268 @servers = @{$arrParamsBusc->{'server'}} if $arrParamsBusc->{'server'};
269 @servers = ("biblioserver") unless (@servers);
271 my ($default_sort_by, @sort_by);
272 $default_sort_by = C4::Context->preference('OPACdefaultSortField')."_".C4::Context->preference('OPACdefaultSortOrder') if (C4::Context->preference('OPACdefaultSortField') && C4::Context->preference('OPACdefaultSortOrder'));
273 @sort_by = @{$arrParamsBusc->{'sort_by'}} if $arrParamsBusc->{'sort_by'};
274 $sort_by[0] = $default_sort_by if !$sort_by[0] && defined($default_sort_by);
275 my ($error, $results_hashref, $facets);
276 eval {
277 ($error, $results_hashref, $facets) = getRecords($arrParamsBusc->{'query'},$arrParamsBusc->{'simple_query'},\@sort_by,\@servers,$results_per_page,$offset,undef,$itemtypes,$arrParamsBusc->{'query_type'},$arrParamsBusc->{'scan'});
279 my $hits;
280 my @newresults;
281 my $search_context = {
282 'interface' => 'opac',
283 'category' => $borcat
285 for (my $i=0;$i<@servers;$i++) {
286 my $server = $servers[$i];
287 $hits = $results_hashref->{$server}->{"hits"};
288 @newresults = searchResults( $search_context, '', $hits, $results_per_page, $offset, $arrParamsBusc->{'scan'}, $results_hashref->{$server}->{"RECORDS"});
290 return \@newresults;
291 }#searchAgain
293 # Build the current list of biblionumbers in this search
294 sub buildListBiblios
296 my ($newresultsRef, $results_per_page) = @_;
298 my $listBiblios = '';
299 my $j = 0;
300 foreach (@$newresultsRef) {
301 my $bibnum = ($_->{biblionumber})?$_->{biblionumber}:0;
302 $listBiblios .= $bibnum . ',';
303 $j++;
304 last if ($j == $results_per_page);
306 chop $listBiblios if ($listBiblios =~ /,$/);
307 return $listBiblios;
308 }#buildListBiblios
310 my $busc = $session->param("busc");
311 my @arrBusc = split(/\&(?:amp;)?/, $busc);
312 my ($key, $value);
313 my %arrParamsBusc = ();
314 for (@arrBusc) {
315 ($key, $value) = split(/=/, $_, 2);
316 if ($key =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|offset|offsetSearch|count|expand|scan)/) {
317 $arrParamsBusc{$key} = uri_unescape($value);
318 } else {
319 unless (exists($arrParamsBusc{$key})) {
320 $arrParamsBusc{$key} = [];
322 push @{$arrParamsBusc{$key}}, uri_unescape($value);
325 my $searchAgain = 0;
326 my $count = C4::Context->preference('OPACnumSearchResults') || 20;
327 my $results_per_page = ($arrParamsBusc{'count'} && $arrParamsBusc{'count'} =~ /^[0-9]+?/)?$arrParamsBusc{'count'}:$count;
328 $arrParamsBusc{'count'} = $results_per_page;
329 my $offset = ($arrParamsBusc{'offset'} && $arrParamsBusc{'offset'} =~ /^[0-9]+?/)?$arrParamsBusc{'offset'}:0;
330 # The value OPACnumSearchResults has changed and the search has to be rebuild
331 if ($count != $results_per_page) {
332 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
333 my $indexBiblio = 0;
334 my @arrBibliosAux = split(',', $arrParamsBusc{'listBiblios'});
335 for (@arrBibliosAux) {
336 last if ($_ == $biblionumber);
337 $indexBiblio++;
339 $indexBiblio += $offset;
340 $offset = int($indexBiblio / $count) * $count;
341 $arrParamsBusc{'offset'} = $offset;
343 $arrParamsBusc{'count'} = $count;
344 $results_per_page = $count;
345 my $newresultsRef = searchAgain(\%arrParamsBusc, $offset, $results_per_page);
346 $arrParamsBusc{'listBiblios'} = buildListBiblios($newresultsRef, $results_per_page);
347 delete $arrParamsBusc{'previous'} if (exists($arrParamsBusc{'previous'}));
348 delete $arrParamsBusc{'next'} if (exists($arrParamsBusc{'next'}));
349 delete $arrParamsBusc{'offsetSearch'} if (exists($arrParamsBusc{'offsetSearch'}));
350 delete $arrParamsBusc{'newlistBiblios'} if (exists($arrParamsBusc{'newlistBiblios'}));
351 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
352 $session->param("busc" => $newbusc);
353 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
354 } else {
355 my $modifyListBiblios = 0;
356 # We come from a previous click
357 if (exists($arrParamsBusc{'previous'})) {
358 $modifyListBiblios = 1 if ($biblionumber == $arrParamsBusc{'previous'});
359 delete $arrParamsBusc{'previous'};
360 } elsif (exists($arrParamsBusc{'next'})) { # We come from a next click
361 $modifyListBiblios = 2 if ($biblionumber == $arrParamsBusc{'next'});
362 delete $arrParamsBusc{'next'};
364 if ($modifyListBiblios) {
365 if (exists($arrParamsBusc{'newlistBiblios'})) {
366 my $listBibliosAux = $arrParamsBusc{'listBiblios'};
367 $arrParamsBusc{'listBiblios'} = $arrParamsBusc{'newlistBiblios'};
368 my @arrAux = split(',', $listBibliosAux);
369 $arrParamsBusc{'newlistBiblios'} = $listBibliosAux;
370 if ($modifyListBiblios == 1) {
371 $arrParamsBusc{'next'} = $arrAux[0];
372 $paging{'next'}->{biblionumber} = $arrAux[0];
373 }else {
374 $arrParamsBusc{'previous'} = $arrAux[$#arrAux];
375 $paging{'previous'}->{biblionumber} = $arrAux[$#arrAux];
377 } else {
378 delete $arrParamsBusc{'listBiblios'};
380 my $offsetAux = $arrParamsBusc{'offset'};
381 $arrParamsBusc{'offset'} = $arrParamsBusc{'offsetSearch'};
382 $arrParamsBusc{'offsetSearch'} = $offsetAux;
383 $offset = $arrParamsBusc{'offset'};
384 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
385 $session->param("busc" => $newbusc);
386 @arrBusc = split(/\&(?:amp;)?/, $newbusc);
389 my $buscParam = '';
390 my $j = 0;
391 # Rebuild the query for the button "back to results"
392 for (@arrBusc) {
393 unless ($_ =~ /^(?:query|listBiblios|newlistBiblios|query_type|simple_query|next|previous|total|count|offsetSearch)/) {
394 $buscParam .= '&amp;' unless ($j == 0);
395 $buscParam .= $_; # string already URI encoded
396 $j++;
399 $template->param('busc' => $buscParam);
400 my $offsetSearch;
401 my @arrBiblios;
402 # We are inside the list of biblios and we don't have to search
403 if (exists($arrParamsBusc{'listBiblios'}) && $arrParamsBusc{'listBiblios'} =~ /^[0-9]+(?:,[0-9]+)*$/) {
404 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
405 if (@arrBiblios) {
406 # We are at the first item of the list
407 if ($arrBiblios[0] == $biblionumber) {
408 if (@arrBiblios > 1) {
409 for (my $j = 1; $j < @arrBiblios; $j++) {
410 next unless ($arrBiblios[$j]);
411 $paging{'next'}->{biblionumber} = $arrBiblios[$j];
412 last;
415 # search again if we are not at the first searching list
416 if ($offset && !$arrParamsBusc{'previous'}) {
417 $searchAgain = 1;
418 $offsetSearch = $offset - $results_per_page;
420 # we are at the last item of the list
421 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
422 for (my $j = $#arrBiblios - 1; $j >= 0; $j--) {
423 next unless ($arrBiblios[$j]);
424 $paging{'previous'}->{biblionumber} = $arrBiblios[$j];
425 last;
427 if (!$offset) {
428 # search again if we are at the first list and there is more results
429 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} != @arrBiblios);
430 } else {
431 # search again if we aren't at the first list and there is more results
432 $searchAgain = 1 if (!$arrParamsBusc{'next'} && $arrParamsBusc{'total'} > ($offset + @arrBiblios));
434 $offsetSearch = $offset + $results_per_page if ($searchAgain);
435 } else {
436 for (my $j = 1; $j < $#arrBiblios; $j++) {
437 if ($arrBiblios[$j] == $biblionumber) {
438 for (my $z = $j - 1; $z >= 0; $z--) {
439 next unless ($arrBiblios[$z]);
440 $paging{'previous'}->{biblionumber} = $arrBiblios[$z];
441 last;
443 for (my $z = $j + 1; $z < @arrBiblios; $z++) {
444 next unless ($arrBiblios[$z]);
445 $paging{'next'}->{biblionumber} = $arrBiblios[$z];
446 last;
448 last;
453 $offsetSearch = 0 if (defined($offsetSearch) && $offsetSearch < 0);
455 if ($searchAgain) {
456 my $newresultsRef = searchAgain(\%arrParamsBusc, $offsetSearch, $results_per_page);
457 my @newresults = @$newresultsRef;
458 # build the new listBiblios
459 my $listBiblios = buildListBiblios(\@newresults, $results_per_page);
460 unless (exists($arrParamsBusc{'listBiblios'})) {
461 $arrParamsBusc{'listBiblios'} = $listBiblios;
462 @arrBiblios = split(',', $arrParamsBusc{'listBiblios'});
463 } else {
464 $arrParamsBusc{'newlistBiblios'} = $listBiblios;
466 # From the new list we build again the next and previous result
467 if (@arrBiblios) {
468 if ($arrBiblios[0] == $biblionumber) {
469 for (my $j = $#newresults; $j >= 0; $j--) {
470 next unless ($newresults[$j]);
471 $paging{'previous'}->{biblionumber} = $newresults[$j]->{biblionumber};
472 $arrParamsBusc{'previous'} = $paging{'previous'}->{biblionumber};
473 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
474 last;
476 } elsif ($arrBiblios[$#arrBiblios] == $biblionumber) {
477 for (my $j = 0; $j < @newresults; $j++) {
478 next unless ($newresults[$j]);
479 $paging{'next'}->{biblionumber} = $newresults[$j]->{biblionumber};
480 $arrParamsBusc{'next'} = $paging{'next'}->{biblionumber};
481 $arrParamsBusc{'offsetSearch'} = $offsetSearch;
482 last;
486 # build new busc param
487 my $newbusc = rebuildBuscParam(\%arrParamsBusc);
488 $session->param("busc" => $newbusc);
490 my ($numberBiblioPaging, $dataBiblioPaging);
491 # Previous biblio
492 $numberBiblioPaging = $paging{'previous'}->{biblionumber};
493 if ($numberBiblioPaging) {
494 $template->param( 'previousBiblionumber' => $numberBiblioPaging );
495 $dataBiblioPaging = Koha::Biblios->find( $numberBiblioPaging );
496 $template->param('previousTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
498 # Next biblio
499 $numberBiblioPaging = $paging{'next'}->{biblionumber};
500 if ($numberBiblioPaging) {
501 $template->param( 'nextBiblionumber' => $numberBiblioPaging );
502 $dataBiblioPaging = Koha::Biblios->find( $numberBiblioPaging );
503 $template->param('nextTitle' => $dataBiblioPaging->title) if $dataBiblioPaging;
505 # Partial list of biblio results
506 my @listResults;
507 for (my $j = 0; $j < @arrBiblios; $j++) {
508 next unless ($arrBiblios[$j]);
509 $dataBiblioPaging = Koha::Biblios->find( $arrBiblios[$j] ) if ($arrBiblios[$j] != $biblionumber);
510 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]};
512 $template->param('listResults' => \@listResults) if (@listResults);
513 $template->param('indexPag' => 1 + $offset, 'totalPag' => $arrParamsBusc{'total'}, 'indexPagEnd' => scalar(@arrBiblios) + $offset);
514 $template->param( 'offset' => $offset );
518 $template->param(
519 OPACShowCheckoutName => C4::Context->preference("OPACShowCheckoutName"),
522 if ( C4::Context->preference('EasyAnalyticalRecords') ) {
523 # adding items linked via host biblios
524 my $analyticfield = '773';
525 if ($marcflavour eq 'MARC21' || $marcflavour eq 'NORMARC'){
526 $analyticfield = '773';
527 } elsif ($marcflavour eq 'UNIMARC') {
528 $analyticfield = '461';
530 foreach my $hostfield ( $record->field($analyticfield)) {
531 my $hostbiblionumber = $hostfield->subfield("0");
532 my $linkeditemnumber = $hostfield->subfield("9");
533 my @hostitemInfos = GetItemsInfo($hostbiblionumber);
534 foreach my $hostitemInfo (@hostitemInfos){
535 if ($hostitemInfo->{itemnumber} eq $linkeditemnumber){
536 push(@all_items, $hostitemInfo);
542 my @items;
544 # Are there items to hide?
545 my $hideitems;
546 $hideitems = 1 if C4::Context->preference('hidelostitems') or scalar(@hiddenitems) > 0;
548 # Hide items
549 if ($hideitems) {
550 for my $itm (@all_items) {
551 if ( C4::Context->preference('hidelostitems') ) {
552 push @items, $itm unless $itm->{itemlost} or any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
553 } else {
554 push @items, $itm unless any { $itm->{'itemnumber'} eq $_ } @hiddenitems;
557 } else {
558 # Or not
559 @items = @all_items;
562 my $branch = '';
563 if (C4::Context->userenv){
564 $branch = C4::Context->userenv->{branch};
566 if ( C4::Context->preference('HighlightOwnItemsOnOPAC') ) {
567 if (
568 ( ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) && $branch )
570 C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch'
572 my $branchcode;
573 if ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'PatronBranch' ) {
574 $branchcode = $branch;
576 elsif ( C4::Context->preference('HighlightOwnItemsOnOPACWhich') eq 'OpacURLBranch' ) {
577 $branchcode = $ENV{'BRANCHCODE'};
580 my @our_items;
581 my @other_items;
583 foreach my $item ( @items ) {
584 if ( $item->{branchcode} eq $branchcode ) {
585 $item->{'this_branch'} = 1;
586 push( @our_items, $item );
587 } else {
588 push( @other_items, $item );
592 @items = ( @our_items, @other_items );
596 my $dat = &GetBiblioData($biblionumber);
597 my $HideMARC = $record_processor->filters->[0]->should_hide_marc(
599 frameworkcode => $dat->{'frameworkcode'},
600 interface => 'opac',
601 } );
603 my $itemtypes = { map { $_->{itemtype} => $_ } @{ Koha::ItemTypes->search_with_localization->unblessed } };
604 # imageurl:
605 my $itemtype = $dat->{'itemtype'};
606 if ( $itemtype ) {
607 $dat->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{$itemtype}->{'imageurl'} );
608 $dat->{'description'} = $itemtypes->{$itemtype}->{translated_description};
611 my $shelflocations =
612 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.location' } ) };
613 my $collections =
614 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.ccode' } ) };
615 my $copynumbers =
616 { map { $_->{authorised_value} => $_->{opac_description} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $dat->{frameworkcode}, kohafield => 'items.copynumber' } ) };
618 #coping with subscriptions
619 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
620 my @subscriptions = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
622 my @subs;
623 $dat->{'serial'}=1 if $subscriptionsnumber;
624 foreach my $subscription (@subscriptions) {
625 my $serials_to_display;
626 my %cell;
627 $cell{subscriptionid} = $subscription->{subscriptionid};
628 $cell{subscriptionnotes} = $subscription->{notes};
629 $cell{missinglist} = $subscription->{missinglist};
630 $cell{opacnote} = $subscription->{opacnote};
631 $cell{histstartdate} = $subscription->{histstartdate};
632 $cell{histenddate} = $subscription->{histenddate};
633 $cell{branchcode} = $subscription->{branchcode};
634 $cell{callnumber} = $subscription->{callnumber};
635 $cell{location} = $subscription->{location};
636 $cell{closed} = $subscription->{closed};
637 $cell{letter} = $subscription->{letter};
638 $cell{biblionumber} = $subscription->{biblionumber};
639 #get the three latest serials.
640 $serials_to_display = $subscription->{opacdisplaycount};
641 $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
642 $cell{opacdisplaycount} = $serials_to_display;
643 $cell{latestserials} =
644 GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
645 if ( $borrowernumber ) {
646 my $subscription_object = Koha::Subscriptions->find( $subscription->{subscriptionid} );
647 my $subscriber = $subscription_object->subscribers->find( $borrowernumber );
648 $cell{hasalert} = 1 if $subscriber;
650 push @subs, \%cell;
653 $dat->{'count'} = scalar(@items);
656 my (%item_reserves, %priority);
657 my ($show_holds_count, $show_priority);
658 for ( C4::Context->preference("OPACShowHoldQueueDetails") ) {
659 m/holds/o and $show_holds_count = 1;
660 m/priority/ and $show_priority = 1;
662 my $has_hold;
663 if ( $show_holds_count || $show_priority) {
664 my $holds = $biblio->holds;
665 $template->param( holds_count => $holds->count );
666 while ( my $hold = $holds->next ) {
667 $item_reserves{ $hold->itemnumber }++ if $hold->itemnumber;
668 if ($show_priority && $hold->borrowernumber == $borrowernumber) {
669 $has_hold = 1;
670 $hold->itemnumber
671 ? ($priority{ $hold->itemnumber } = $hold->priority)
672 : ($template->param( priority => $hold->priority ));
676 $template->param( show_priority => $has_hold ) ;
678 my $norequests = 1;
679 my %itemfields;
680 my (@itemloop, @otheritemloop);
681 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
682 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
683 $template->param(SeparateHoldings => 1);
685 my $separatebranch = C4::Context->preference('OpacSeparateHoldingsBranch');
686 my $viewallitems = $query->param('viewallitems');
687 my $max_items_to_display = C4::Context->preference('OpacMaxItemsToDisplay') // 50;
689 # Get items on order
690 my ( @itemnumbers_on_order );
691 if ( C4::Context->preference('OPACAcquisitionDetails' ) ) {
692 my $orders = C4::Acquisition::SearchOrders({
693 biblionumber => $biblionumber,
694 ordered => 1,
696 my $total_quantity = 0;
697 for my $order ( @$orders ) {
698 my $order = Koha::Acquisition::Orders->find( $order->{ordernumber} );
699 my $basket = $order->basket;
700 if ( $basket->effective_create_items eq 'ordering' ) {
701 @itemnumbers_on_order = $order->items->get_column('itemnumber');
703 $total_quantity += $order->quantity;
705 $template->{VARS}->{acquisition_details} = {
706 total_quantity => $total_quantity,
710 my $allow_onshelf_holds;
711 my ( $itemloop_has_images, $otheritemloop_has_images );
712 if ( not $viewallitems and @items > $max_items_to_display ) {
713 $template->param(
714 too_many_items => 1,
715 items_count => scalar( @items ),
717 } else {
718 for my $itm (@items) {
719 my $item = Koha::Items->find( $itm->{itemnumber} );
720 $itm->{holds_count} = $item_reserves{ $itm->{itemnumber} };
721 $itm->{priority} = $priority{ $itm->{itemnumber} };
722 $norequests = 0
723 if $norequests
724 && !$itm->{'withdrawn'}
725 && !$itm->{'itemlost'}
726 && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
727 && !$itemtypes->{$itm->{'itype'}}->{notforloan}
728 && $itm->{'itemnumber'};
730 $allow_onshelf_holds = Koha::CirculationRules->get_onshelfholds_policy( { item => $item, patron => $patron } )
731 unless $allow_onshelf_holds;
733 # get collection code description, too
734 my $ccode = $itm->{'ccode'};
735 $itm->{'ccode'} = $collections->{$ccode} if defined($ccode) && $collections && exists( $collections->{$ccode} );
736 my $copynumber = $itm->{'copynumber'};
737 $itm->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumbers) && defined($copynumber) && exists( $copynumbers->{$copynumber} ) );
738 if ( defined $itm->{'location'} ) {
739 $itm->{'location_description'} = $shelflocations->{ $itm->{'location'} };
741 if (exists $itm->{itype} && defined($itm->{itype}) && exists $itemtypes->{ $itm->{itype} }) {
742 $itm->{'imageurl'} = getitemtypeimagelocation( 'opac', $itemtypes->{ $itm->{itype} }->{'imageurl'} );
743 $itm->{'description'} = $itemtypes->{ $itm->{itype} }->{translated_description};
745 foreach (qw(ccode materials enumchron copynumber itemnotes location_description uri)) {
746 $itemfields{$_} = 1 if ($itm->{$_});
749 my $reserve_status = C4::Reserves::GetReserveStatus($itm->{itemnumber});
750 if( $reserve_status eq "Waiting"){ $itm->{'waiting'} = 1; }
751 if( $reserve_status eq "Reserved"){ $itm->{'onhold'} = 1; }
753 my ( $transfertwhen, $transfertfrom, $transfertto ) = GetTransfers($itm->{itemnumber});
754 if ( defined( $transfertwhen ) && $transfertwhen ne '' ) {
755 $itm->{transfertwhen} = $transfertwhen;
756 $itm->{transfertfrom} = $transfertfrom;
757 $itm->{transfertto} = $transfertto;
760 if ( C4::Context->preference('OPACAcquisitionDetails') ) {
761 $itm->{on_order} = 1
762 if grep { $_ eq $itm->{itemnumber} } @itemnumbers_on_order;
765 if ( C4::Context->preference("OPACLocalCoverImages") == 1 ) {
766 my $cover_image = $item->cover_image;
767 $itm->{imagenumber} = $cover_image ? $cover_image->imagenumber : undef;
770 my $itembranch = $itm->{$separatebranch};
771 if ($currentbranch and C4::Context->preference('OpacSeparateHoldings')) {
772 if ($itembranch and $itembranch eq $currentbranch) {
773 push @itemloop, $itm;
774 $itemloop_has_images++ if $itm->{imagenumber};
775 } else {
776 push @otheritemloop, $itm;
777 $otheritemloop_has_images++ if $itm->{imagenumber};
779 } else {
780 push @itemloop, $itm;
781 $itemloop_has_images++ if $itm->{imagenumber};
786 if( $allow_onshelf_holds || CountItemsIssued($biblionumber) || $biblio->has_items_waiting_or_intransit ) {
787 $template->param( ReservableItems => 1 );
790 $template->param(
791 itemloop_has_images => $itemloop_has_images,
792 otheritemloop_has_images => $otheritemloop_has_images,
795 # Display only one tab if one items list is empty
796 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
797 $template->param(SeparateHoldings => 0);
798 if (scalar(@itemloop) == 0) {
799 @itemloop = @otheritemloop;
803 ## get notes and subjects from MARC record
804 if (!C4::Context->preference("OPACXSLTDetailsDisplay") ) {
805 my $marcisbnsarray = GetMarcISBN ($record,$marcflavour);
806 my $marcauthorsarray = GetMarcAuthors ($record,$marcflavour);
807 my $marcsubjctsarray = GetMarcSubjects($record,$marcflavour);
808 my $marcseriesarray = GetMarcSeries ($record,$marcflavour);
809 my $marcurlsarray = GetMarcUrls ($record,$marcflavour);
811 $template->param(
812 MARCSUBJCTS => $marcsubjctsarray,
813 MARCAUTHORS => $marcauthorsarray,
814 MARCSERIES => $marcseriesarray,
815 MARCURLS => $marcurlsarray,
816 MARCISBNS => $marcisbnsarray,
820 my $marcnotesarray = GetMarcNotes ($record,$marcflavour,1);
822 if( C4::Context->preference('ArticleRequests') ) {
823 my $patron = $borrowernumber ? Koha::Patrons->find($borrowernumber) : undef;
824 my $itemtype = Koha::ItemTypes->find($biblio->itemtype);
825 my $artreqpossible = $patron
826 ? $biblio->can_article_request( $patron )
827 : $itemtype
828 ? $itemtype->may_article_request
829 : q{};
830 $template->param( artreqpossible => $artreqpossible );
833 $template->param(
834 MARCNOTES => $marcnotesarray,
835 norequests => $norequests,
836 RequestOnOpac => C4::Context->preference("RequestOnOpac"),
837 itemdata_ccode => $itemfields{ccode},
838 itemdata_materials => $itemfields{materials},
839 itemdata_enumchron => $itemfields{enumchron},
840 itemdata_uri => $itemfields{uri},
841 itemdata_copynumber => $itemfields{copynumber},
842 itemdata_itemnotes => $itemfields{itemnotes},
843 itemdata_location => $itemfields{location_description},
844 OpacStarRatings => C4::Context->preference("OpacStarRatings"),
847 if (C4::Context->preference("AlternateHoldingsField") && scalar @items == 0) {
848 my $fieldspec = C4::Context->preference("AlternateHoldingsField");
849 my $subfields = substr $fieldspec, 3;
850 my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
851 my @alternateholdingsinfo = ();
852 my @holdingsfields = $record->field(substr $fieldspec, 0, 3);
854 for my $field (@holdingsfields) {
855 my %holding = ( holding => '' );
856 my $havesubfield = 0;
857 for my $subfield ($field->subfields()) {
858 if ((index $subfields, $$subfield[0]) >= 0) {
859 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
860 $holding{'holding'} .= $$subfield[1];
861 $havesubfield++;
864 if ($havesubfield) {
865 push(@alternateholdingsinfo, \%holding);
869 $template->param(
870 ALTERNATEHOLDINGS => \@alternateholdingsinfo,
874 # FIXME: The template uses this hash directly. Need to filter.
875 foreach ( keys %{$dat} ) {
876 next if ( $HideMARC->{$_} );
877 $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
880 # some useful variables for enhanced content;
881 # in each case, we're grabbing the first value we find in
882 # the record and normalizing it
883 my $upc = GetNormalizedUPC($record,$marcflavour);
884 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
885 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
886 my $content_identifier_exists;
887 if ( $isbn or $ean or $oclc or $upc ) {
888 $content_identifier_exists = 1;
890 $template->param(
891 normalized_upc => $upc,
892 normalized_ean => $ean,
893 normalized_oclc => $oclc,
894 normalized_isbn => $isbn,
895 content_identifier_exists => $content_identifier_exists,
898 # Catch the exception as Koha::Biblio::Metadata->record can explode if the MARCXML is invalid
899 # COinS format FIXME: for books Only
900 my $coins = eval { $biblio->get_coins };
901 $template->param( ocoins => $coins );
903 my ( $loggedincommenter, $reviews );
904 if ( C4::Context->preference('reviewson') ) {
905 $reviews = Koha::Reviews->search(
907 biblionumber => $biblionumber,
908 -or => { approved => 1, borrowernumber => $borrowernumber }
911 order_by => { -desc => 'datereviewed' }
913 )->unblessed;
914 my $libravatar_enabled = 0;
915 if ( C4::Context->preference('ShowReviewer') and C4::Context->preference('ShowReviewerPhoto') ) {
916 eval {
917 require Libravatar::URL;
918 Libravatar::URL->import();
920 if ( !$@ ) {
921 $libravatar_enabled = 1;
924 for my $review (@$reviews) {
925 my $review_patron = Koha::Patrons->find( $review->{borrowernumber} ); # FIXME Should be Koha::Review->reviewer or similar
927 # setting some borrower info into this hash
928 if ( $review_patron ) {
929 $review->{patron} = $review_patron;
930 if ( $libravatar_enabled and $review_patron->email ) {
931 $review->{avatarurl} = libravatar_url( email => $review_patron->email, https => $ENV{HTTPS} );
934 if ( $review_patron->borrowernumber eq $borrowernumber ) {
935 $loggedincommenter = 1;
941 if ( C4::Context->preference("OPACISBD") ) {
942 $template->param( ISBD => 1 );
945 $template->param(
946 itemloop => \@itemloop,
947 otheritemloop => \@otheritemloop,
948 biblionumber => $biblionumber,
949 subscriptions => \@subs,
950 subscriptionsnumber => $subscriptionsnumber,
951 reviews => $reviews,
952 loggedincommenter => $loggedincommenter
955 # Lists
956 if (C4::Context->preference("virtualshelves") ) {
957 my $shelves = Koha::Virtualshelves->search(
959 biblionumber => $biblionumber,
960 category => 2,
963 join => 'virtualshelfcontents',
966 $template->param( shelves => $shelves );
969 # XISBN Stuff
970 if (C4::Context->preference("OPACFRBRizeEditions")==1) {
971 eval {
972 $template->param(
973 XISBNS => scalar get_xisbns($isbn, $biblionumber)
976 if ($@) { warn "XISBN Failed $@"; }
979 # Serial Collection
980 my @sc_fields = $record->field(955);
981 my @lc_fields = $marcflavour eq 'UNIMARC'
982 ? $record->field(930)
983 : $record->field(852);
984 my @serialcollections = ();
986 foreach my $sc_field (@sc_fields) {
987 my %row_data;
989 $row_data{text} = $sc_field->subfield('r');
990 $row_data{branch} = $sc_field->subfield('9');
991 foreach my $lc_field (@lc_fields) {
992 $row_data{itemcallnumber} = $marcflavour eq 'UNIMARC'
993 ? $lc_field->subfield('a') # 930$a
994 : $lc_field->subfield('h') # 852$h
995 if ($sc_field->subfield('5') eq $lc_field->subfield('5'));
998 if ($row_data{text} && $row_data{branch}) {
999 push (@serialcollections, \%row_data);
1003 if (scalar(@serialcollections) > 0) {
1004 $template->param(
1005 serialcollection => 1,
1006 serialcollections => \@serialcollections);
1009 # Local cover Images stuff
1010 if (C4::Context->preference("OPACLocalCoverImages")){
1011 $template->param(OPACLocalCoverImages => 1);
1014 # HTML5 Media
1015 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'opac') ) {
1016 $template->param( C4::HTML5Media->gethtml5media($record));
1019 my $syndetics_elements;
1021 if ( C4::Context->preference("SyndeticsEnabled") ) {
1022 $template->param("SyndeticsEnabled" => 1);
1023 $template->param("SyndeticsClientCode" => C4::Context->preference("SyndeticsClientCode"));
1024 eval {
1025 $syndetics_elements = &get_syndetics_index($isbn,$upc,$oclc);
1026 for my $element (values %$syndetics_elements) {
1027 $template->param("Syndetics$element"."Exists" => 1 );
1028 #warn "Exists: "."Syndetics$element"."Exists";
1031 warn $@ if $@;
1034 if ( C4::Context->preference("SyndeticsEnabled")
1035 && C4::Context->preference("SyndeticsSummary")
1036 && ( exists($syndetics_elements->{'SUMMARY'}) || exists($syndetics_elements->{'AVSUMMARY'}) ) ) {
1037 eval {
1038 my $syndetics_summary = &get_syndetics_summary($isbn,$upc,$oclc, $syndetics_elements);
1039 $template->param( SYNDETICS_SUMMARY => $syndetics_summary );
1041 warn $@ if $@;
1045 if ( C4::Context->preference("SyndeticsEnabled")
1046 && C4::Context->preference("SyndeticsTOC")
1047 && exists($syndetics_elements->{'TOC'}) ) {
1048 eval {
1049 my $syndetics_toc = &get_syndetics_toc($isbn,$upc,$oclc);
1050 $template->param( SYNDETICS_TOC => $syndetics_toc );
1052 warn $@ if $@;
1055 if ( C4::Context->preference("SyndeticsEnabled")
1056 && C4::Context->preference("SyndeticsExcerpt")
1057 && exists($syndetics_elements->{'DBCHAPTER'}) ) {
1058 eval {
1059 my $syndetics_excerpt = &get_syndetics_excerpt($isbn,$upc,$oclc);
1060 $template->param( SYNDETICS_EXCERPT => $syndetics_excerpt );
1062 warn $@ if $@;
1065 if ( C4::Context->preference("SyndeticsEnabled")
1066 && C4::Context->preference("SyndeticsReviews")) {
1067 eval {
1068 my $syndetics_reviews = &get_syndetics_reviews($isbn,$upc,$oclc,$syndetics_elements);
1069 $template->param( SYNDETICS_REVIEWS => $syndetics_reviews );
1071 warn $@ if $@;
1074 if ( C4::Context->preference("SyndeticsEnabled")
1075 && C4::Context->preference("SyndeticsAuthorNotes")
1076 && exists($syndetics_elements->{'ANOTES'}) ) {
1077 eval {
1078 my $syndetics_anotes = &get_syndetics_anotes($isbn,$upc,$oclc);
1079 $template->param( SYNDETICS_ANOTES => $syndetics_anotes );
1081 warn $@ if $@;
1084 # LibraryThingForLibraries ID Code and Tabbed View Option
1085 if( C4::Context->preference('LibraryThingForLibrariesEnabled') )
1087 $template->param(LibraryThingForLibrariesID =>
1088 C4::Context->preference('LibraryThingForLibrariesID') );
1089 $template->param(LibraryThingForLibrariesTabbedView =>
1090 C4::Context->preference('LibraryThingForLibrariesTabbedView') );
1093 # Novelist Select
1094 if( C4::Context->preference('NovelistSelectEnabled') )
1096 $template->param(NovelistSelectProfile => C4::Context->preference('NovelistSelectProfile') );
1097 $template->param(NovelistSelectPassword => C4::Context->preference('NovelistSelectPassword') );
1098 $template->param(NovelistSelectView => C4::Context->preference('NovelistSelectView') );
1102 # Babelthèque
1103 if ( C4::Context->preference("Babeltheque") ) {
1104 $template->param(
1105 Babeltheque => 1,
1106 Babeltheque_url_js => C4::Context->preference("Babeltheque_url_js"),
1110 # Social Networks
1111 if ( C4::Context->preference( "SocialNetworks" ) ) {
1112 $template->param( current_url => C4::Context->preference('OPACBaseURL') . "/cgi-bin/koha/opac-detail.pl?biblionumber=$biblionumber" );
1113 $template->param( SocialNetworks => 1 );
1116 # Shelf Browser Stuff
1117 if (C4::Context->preference("OPACShelfBrowser")) {
1118 my $starting_itemnumber = $query->param('shelfbrowse_itemnumber');
1119 if (defined($starting_itemnumber)) {
1120 $template->param( OpenOPACShelfBrowser => 1) if $starting_itemnumber;
1121 my $nearby = GetNearbyItems($starting_itemnumber);
1123 $template->param(
1124 starting_itemnumber => $starting_itemnumber,
1125 starting_homebranch => $nearby->{starting_homebranch}->{description},
1126 starting_location => $nearby->{starting_location}->{description},
1127 starting_ccode => $nearby->{starting_ccode}->{description},
1128 shelfbrowser_prev_item => $nearby->{prev_item},
1129 shelfbrowser_next_item => $nearby->{next_item},
1130 shelfbrowser_items => $nearby->{items},
1133 # in which tab shelf browser should open ?
1134 if (grep { $starting_itemnumber == $_->{itemnumber} } @itemloop) {
1135 $template->param(shelfbrowser_tab => 'holdings');
1136 } else {
1137 $template->param(shelfbrowser_tab => 'otherholdings');
1142 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("OPACAmazonCoverImages"));
1144 if (C4::Context->preference("BakerTaylorEnabled")) {
1145 $template->param(
1146 BakerTaylorEnabled => 1,
1147 BakerTaylorImageURL => &image_url(),
1148 BakerTaylorLinkURL => &link_url(),
1149 BakerTaylorBookstoreURL => C4::Context->preference('BakerTaylorBookstoreURL'),
1151 my ($bt_user, $bt_pass);
1152 if ($isbn and
1153 $bt_user = C4::Context->preference('BakerTaylorUsername') and
1154 $bt_pass = C4::Context->preference('BakerTaylorPassword') )
1156 $template->param(
1157 BakerTaylorContentURL =>
1158 sprintf("https://contentcafe2.btol.com/ContentCafeClient/ContentCafe.aspx?UserID=%s&Password=%s&ItemKey=%s&Options=Y",
1159 $bt_user,$bt_pass,$isbn)
1164 my $tag_quantity;
1165 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
1166 $template->param(
1167 TagsEnabled => 1,
1168 TagsShowOnDetail => $tag_quantity,
1169 TagsInputOnDetail => C4::Context->preference('TagsInputOnDetail')
1171 $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
1172 'sort'=>'-weight', limit=>$tag_quantity}));
1175 if (C4::Context->preference("OPACURLOpenInNewWindow")) {
1176 # These values are going to be read by Javascript, at least in the case
1177 # of the google covers
1178 $template->param(covernewwindow => 'true');
1179 } else {
1180 $template->param(covernewwindow => 'false');
1183 $template->param(borrowernumber => $borrowernumber);
1185 if ( C4::Context->preference('OpacStarRatings') !~ /disable/ ) {
1186 my $ratings = Koha::Ratings->search({ biblionumber => $biblionumber });
1187 my $my_rating = $borrowernumber ? $ratings->search({ borrowernumber => $borrowernumber })->next : undef;
1188 $template->param(
1189 ratings => $ratings,
1190 my_rating => $my_rating,
1194 #Search for title in links
1195 my $marccontrolnumber = GetMarcControlnumber ($record, $marcflavour);
1196 my $marcissns = GetMarcISSN ( $record, $marcflavour );
1197 my $issn = $marcissns->[0] || '';
1199 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
1200 $dat->{title} =~ s/\/+$//; # remove trailing slash
1201 $dat->{title} =~ s/\s+$//; # remove trailing space
1202 $search_for_title = parametrized_url(
1203 $search_for_title,
1205 TITLE => $dat->{title},
1206 AUTHOR => $dat->{author},
1207 ISBN => $isbn,
1208 ISSN => $issn,
1209 CONTROLNUMBER => $marccontrolnumber,
1210 BIBLIONUMBER => $biblionumber,
1213 $template->param('OPACSearchForTitleIn' => $search_for_title);
1216 #IDREF
1217 if ( C4::Context->preference("IDREF") ) {
1218 # If the record comes from the SUDOC
1219 if ( $record->field('009') ) {
1220 my $unimarc3 = $record->field("009")->data;
1221 if ( $unimarc3 =~ /^\d+$/ ) {
1222 $template->param(
1223 IDREF => 1,
1229 # We try to select the best default tab to show, according to what
1230 # the user wants, and what's available for display
1231 my $opac_serial_default = C4::Context->preference('opacSerialDefaultTab');
1232 my $defaulttab =
1233 $viewallitems
1234 ? 'holdings' :
1235 $opac_serial_default eq 'subscriptions' && $subscriptionsnumber
1236 ? 'subscriptions' :
1237 $opac_serial_default eq 'serialcollection' && @serialcollections > 0
1238 ? 'serialcollection' :
1239 $opac_serial_default eq 'holdings' && scalar (@itemloop) > 0
1240 ? 'holdings' :
1241 scalar (@itemloop) == 0
1242 ? 'media' :
1243 $subscriptionsnumber
1244 ? 'subscriptions' :
1245 @serialcollections > 0
1246 ? 'serialcollection' : 'subscriptions';
1247 $template->param('defaulttab' => $defaulttab);
1249 if (C4::Context->preference('OPACLocalCoverImages') == 1) {
1250 $template->param( localimages => $biblio->cover_images );
1253 $template->{VARS}->{OPACPopupAuthorsSearch} = C4::Context->preference('OPACPopupAuthorsSearch');
1255 if (C4::Context->preference('OpacHighlightedWords')) {
1256 $template->{VARS}->{query_desc} = $query->param('query_desc');
1258 $template->{VARS}->{'trackclicks'} = C4::Context->preference('TrackClicks');
1260 if ( C4::Context->preference('UseCourseReserves') ) {
1261 foreach my $i ( @items ) {
1262 $i->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $i->{'itemnumber'} );
1266 $template->param(
1267 'OpacLocationBranchToDisplay' => C4::Context->preference('OpacLocationBranchToDisplay'),
1270 output_html_with_http_headers $query, $cookie, $template->output;