Bug 33497: (follow-up) Remove unecessary scalar
[koha.git] / catalogue / detail.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18
19 use Modern::Perl;
20
21 use CGI qw ( -utf8 );
22 use HTML::Entities;
23 use C4::Auth qw( get_template_and_user );
24 use C4::Context;
25 use C4::Koha qw(
26     GetAuthorisedValues
27     getitemtypeimagelocation
28     GetNormalizedEAN
29     GetNormalizedISBN
30     GetNormalizedOCLCNumber
31     GetNormalizedUPC
32 );
33 use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
34 use C4::Output qw( output_html_with_http_headers );
35 use C4::Biblio qw( GetBiblioData GetFrameworkCode );
36 use C4::Items qw( GetAnalyticsCount );
37 use C4::Reserves;
38 use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
39 use C4::XISBN qw( get_xisbns );
40 use C4::External::Amazon qw( get_amazon_tld );
41 use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra );
42 use C4::Tags qw( get_tags );
43 use C4::XSLT qw( XSLTParse4Display );
44 use Koha::DateUtils qw( format_sqldatetime );
45 use C4::HTML5Media;
46 use C4::CourseReserves qw( GetItemCourseReservesInfo );
47 use Koha::AuthorisedValues;
48 use Koha::Biblios;
49 use Koha::Biblio::ItemGroup::Items;
50 use Koha::Biblio::ItemGroups;
51 use Koha::CoverImages;
52 use Koha::DateUtils;
53 use Koha::Illrequests;
54 use Koha::Items;
55 use Koha::ItemTypes;
56 use Koha::Patrons;
57 use Koha::Virtualshelves;
58 use Koha::Plugins;
59 use Koha::Recalls;
60 use Koha::SearchEngine::Search;
61 use Koha::SearchEngine::QueryBuilder;
62 use Koha::Serial::Items;
63
64 my $query = CGI->new();
65
66 my $analyze = $query->param('analyze');
67
68 my ( $template, $borrowernumber, $cookie, $flags ) = get_template_and_user(
69     {
70     template_name   =>  'catalogue/detail.tt',
71         query           => $query,
72         type            => "intranet",
73         flagsrequired   => { catalogue => 1 },
74     }
75 );
76
77 # Determine if we should be offering any enhancement plugin buttons
78 if ( C4::Context->config('enable_plugins') ) {
79     # Only pass plugins that can offer a toolbar button
80     my @plugins = Koha::Plugins->new()->GetPlugins({
81         method => 'intranet_catalog_biblio_enhancements_toolbar_button'
82     });
83     $template->param(
84         plugins => \@plugins,
85     );
86 }
87
88 my $biblionumber = $query->param('biblionumber');
89 $biblionumber = HTML::Entities::encode($biblionumber);
90 my $biblio = Koha::Biblios->find( $biblionumber );
91 $template->param( 'biblio', $biblio );
92
93 unless ( $biblio ) {
94     # biblionumber invalid -> report and exit
95     $template->param( unknownbiblionumber => 1,
96                       biblionumber => $biblionumber );
97     output_html_with_http_headers $query, $cookie, $template->output;
98     exit;
99 }
100
101 my $marc_record = eval { $biblio->metadata->record };
102 my $invalid_marc_record = $@ || !$marc_record;
103 if ($invalid_marc_record) {
104     $template->param( decoding_error => $@ );
105     my $marc_xml = C4::Charset::StripNonXmlChars( $biblio->metadata->metadata );
106
107     $marc_record = eval {
108         MARC::Record::new_from_xml( $marc_xml, 'UTF-8',
109             C4::Context->preference('marcflavour') );
110     };
111 }
112
113 my $op = $query->param('op') || q{};
114 if ( $op eq 'set_item_group' ) {
115     my $item_group_id = $query->param('item_group_id');
116     my @itemnumbers   = $query->multi_param('itemnumber');
117
118     foreach my $item_id (@itemnumbers) {
119         my $item_group_item = Koha::Biblio::ItemGroup::Items->find( { item_id => $item_id } );
120
121         if ($item_group_item) {
122             $item_group_item->item_group_id($item_group_id);
123         }
124         else {
125             $item_group_item = Koha::Biblio::ItemGroup::Item->new(
126                 {
127                     item_id        => $item_id,
128                     item_group_id  => $item_group_id,
129                 }
130             );
131         }
132
133         $item_group_item->store();
134     }
135 }
136 elsif ( $op eq 'unset_item_group' ) {
137     my $item_group_id   = $query->param('item_group_id');
138     my @itemnumbers = $query->multi_param('itemnumber');
139
140     foreach my $item_id (@itemnumbers) {
141         my $item_group_item = Koha::Biblio::ItemGroup::Items->find( { item_id => $item_id } );
142         $item_group_item->delete() if $item_group_item;
143     }
144 }
145
146 if($query->cookie("holdfor")){
147     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
148     if ( $holdfor_patron ) {
149         $template->param(
150             holdfor        => $query->cookie("holdfor"),
151             holdfor_patron => $holdfor_patron,
152         );
153     }
154 }
155
156 if($query->cookie("searchToOrder")){
157     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
158     $template->param(
159         searchtoorder_basketno => $basketno,
160         searchtoorder_vendorid => $vendorid
161     );
162 }
163
164 my $fw           = GetFrameworkCode($biblionumber);
165 my $showallitems = $query->param('showallitems');
166 my $marcflavour  = C4::Context->preference("marcflavour");
167
168 $template->param( 'SpineLabelShowPrintOnBibDetails' => C4::Context->preference("SpineLabelShowPrintOnBibDetails") );
169
170 $template->param( ocoins => !$invalid_marc_record ? $biblio->get_coins : undef );
171
172 # some useful variables for enhanced content;
173 # in each case, we're grabbing the first value we find in
174 # the record and normalizing it
175 my $upc = GetNormalizedUPC($marc_record,$marcflavour);
176 my $ean = GetNormalizedEAN($marc_record,$marcflavour);
177 my $oclc = GetNormalizedOCLCNumber($marc_record,$marcflavour);
178 my $isbn = GetNormalizedISBN(undef,$marc_record,$marcflavour);
179 my $content_identifier_exists;
180 if ( $isbn or $ean or $oclc or $upc ) {
181     $content_identifier_exists = 1;
182 }
183
184 $template->param(
185     normalized_upc => $upc,
186     normalized_ean => $ean,
187     normalized_oclc => $oclc,
188     normalized_isbn => $isbn,
189     content_identifier_exists =>  $content_identifier_exists,
190 );
191
192 my $itemtypes = { map { $_->itemtype => $_ } @{ Koha::ItemTypes->search_with_localization->as_list } };
193 my $all_items = $biblio->items->search_ordered;
194 my @items;
195 my $patron = Koha::Patrons->find( $borrowernumber );
196 $params->{ itemlost } = 0 if $patron->category->hidelostitems && !$showallitems;
197 my $items = $biblio->items({ host_items => 1 })->search_ordered( $params, { prefetch => ['issue','branchtransfer'] } );
198
199 # flag indicating existence of at least one item linked via a host record
200 my $hostrecords = $biblio->host_items->count;
201
202 my $dat = &GetBiblioData($biblionumber);
203 $dat->{'count'} = $biblio->items({ host_items => 1 })->count;
204 $dat->{'showncount'} = $items->count;
205 $dat->{'hiddencount'} = $dat->{'count'} - $dat->{'showncount'};
206
207 #is biblio a collection and are bundles enabled
208 my $leader = $marc_record->leader();
209 $dat->{bundlesEnabled} = ( ( substr( $leader, 7, 1 ) eq 'c' )
210       && C4::Context->preference('BundleNotLoanValue') ) ? 1 : 0;
211
212 #coping with subscriptions
213 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
214 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
215 my @subs;
216
217 foreach my $subscription (@subscriptions) {
218     my %cell;
219     my $serials_to_display;
220     $cell{subscriptionid}    = $subscription->{subscriptionid};
221     $cell{subscriptionnotes} = $subscription->{internalnotes};
222     $cell{missinglist}       = $subscription->{missinglist};
223     $cell{librariannote}     = $subscription->{librariannote};
224     $cell{branchcode}        = $subscription->{branchcode};
225     $cell{hasalert}          = $subscription->{hasalert};
226     $cell{callnumber}        = $subscription->{callnumber};
227     $cell{location}          = $subscription->{location};
228     $cell{closed}            = $subscription->{closed};
229     #get the three latest serials.
230     $serials_to_display = $subscription->{staffdisplaycount};
231     $serials_to_display = C4::Context->preference('StaffSerialIssueDisplayCount') unless $serials_to_display;
232     $cell{staffdisplaycount} = $serials_to_display;
233     $cell{latestserials} =
234       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
235     push @subs, \%cell;
236 }
237
238 # Get component parts details
239 my $showcomp = C4::Context->preference('ShowComponentRecords');
240 my $show_analytics;
241 if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
242     if ( my $components = !$invalid_marc_record ? $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) : undef ) {
243         $show_analytics = 1 if @{$components}; # just show link when having results
244         $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages};
245         my $parts;
246         for my $part ( @{$components} ) {
247             $part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
248             my $id = Koha::SearchEngine::Search::extract_biblionumber( $part );
249
250             push @{$parts},
251               XSLTParse4Display(
252                 {
253                     biblionumber => $id,
254                     record       => $part,
255                     xsl_syspref  => "XSLTResultsDisplay",
256                     fix_amps     => 1,
257                 }
258               );
259         }
260         $template->param( ComponentParts => $parts );
261         my ( $comp_query, $comp_query_str, $comp_sort ) = $biblio->get_components_query;
262         my $cpq = $comp_query_str . "&sort_by=" . $comp_sort;
263         $template->param( ComponentPartsQuery => $cpq );
264     }
265 } else { # check if we should show analytics anyway
266     $show_analytics = 1 if !$invalid_marc_record && @{$biblio->get_marc_components(1)}; # count matters here, results does not
267     $template->param( analytics_error => 1 ) if grep { $_->message eq 'component_search' } @{$biblio->object_messages};
268 }
269
270 # XSLT processing of some stuff
271 my $xslt_variables = { show_analytics_link => $show_analytics };
272 $template->param(
273     XSLTDetailsDisplay => '1',
274     XSLTBloc => XSLTParse4Display({
275         biblionumber   => $biblionumber,
276         record         => $marc_record,
277         xsl_syspref    => "XSLTDetailsDisplay",
278         fix_amps       => 1,
279         xslt_variables => $xslt_variables,
280     }),
281 );
282
283 # Get acquisition details
284 if ( C4::Context->preference('AcquisitionDetails') ) {
285     my $orders = Koha::Acquisition::Orders->search(
286         { biblionumber => $biblionumber },
287         {
288             join => 'basketno',
289             order_by => 'basketno.booksellerid'
290         }
291     );    # GetHistory sorted by aqbooksellerid, but does it make sense?
292
293     $template->param(
294         orders => $orders,
295     );
296 }
297
298 if ( C4::Context->preference('suggestion') ) {
299     my $suggestions = Koha::Suggestions->search(
300         {
301             biblionumber => $biblionumber,
302             archived     => 0,
303         },
304         {
305             order_by => { -desc => 'suggesteddate' }
306         }
307     );
308     my $nb_archived_suggestions = Koha::Suggestions->search({ biblionumber => $biblionumber, archived => 1 })->count;
309     $template->param( suggestions => $suggestions, nb_archived_suggestions => $nb_archived_suggestions );
310 }
311
312 if ( defined $dat->{'itemtype'} ) {
313     $dat->{imageurl} = getitemtypeimagelocation( 'intranet', $itemtypes->{ $dat->{itemtype} }->imageurl );
314 }
315
316 $dat->{'count'} = $all_items->count + $hostitems->count;
317 $dat->{'showncount'} = scalar @items + $hostitems->count;
318 $dat->{'hiddencount'} = $all_items->count + $hostitems->count - scalar @items;
319
320 my $shelflocations =
321   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.location' } ) };
322 my $collections =
323   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.ccode' } ) };
324 my $copynumbers =
325   { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => $fw, kohafield => 'items.copynumber' } ) };
326 my (@itemloop, @otheritemloop, %itemfields);
327
328 my $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.itemlost', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
329 if ( $mss->count ) {
330     $template->param( itemlostloop => GetAuthorisedValues( $mss->next->authorised_value ) );
331 }
332 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.damaged', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
333 if ( $mss->count ) {
334     $template->param( itemdamagedloop => GetAuthorisedValues( $mss->next->authorised_value ) );
335 }
336 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.withdrawn', authorised_value => { not => undef } });
337 if ( $mss->count ) {
338     $template->param( itemwithdrawnloop => GetAuthorisedValues( $mss->next->authorised_value) );
339 }
340
341 $mss = Koha::MarcSubfieldStructures->search({ frameworkcode => $fw, kohafield => 'items.materials', authorised_value => [ -and => {'!=' => undef }, {'!=' => ''}] });
342 my %materials_map;
343 if ($mss->count) {
344     my $materials_authvals = GetAuthorisedValues($mss->next->authorised_value);
345     if ($materials_authvals) {
346         foreach my $value (@$materials_authvals) {
347             $materials_map{$value->{authorised_value}} = $value->{lib};
348         }
349     }
350 }
351
352 my $analytics_flag;
353 my $materials_flag; # set this if the items have anything in the materials field
354 my $currentbranch = C4::Context->userenv ? C4::Context->userenv->{branch} : undef;
355 if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
356     $template->param(SeparateHoldings => 1);
357 }
358 my $separatebranch = C4::Context->preference('SeparateHoldingsBranch') || 'homebranch';
359 my ( $itemloop_has_images, $otheritemloop_has_images );
360
361 while ( my $item = $items->next ) {
362     my $itembranchcode = $item->$separatebranch;
363
364     my $item_info = $item->unblessed;
365     $item_info->{itemtype} = $itemtypes->{$item->effective_itemtype};
366
367     #get shelf location and collection code description if they are authorised value.
368     # same thing for copy number
369     my $shelfcode = $item->location;
370     $item_info->{'location'} = $shelflocations->{$shelfcode} if ( defined( $shelfcode ) && defined($shelflocations) && exists( $shelflocations->{$shelfcode} ) );
371     my $ccode = $item->ccode;
372     $item_info->{'ccode'} = $collections->{$ccode} if ( defined( $ccode ) && defined($collections) && exists( $collections->{$ccode} ) );
373     my $copynumber = $item->copynumber;
374     $item_info->{'copynumber'} = $copynumbers->{$copynumber} if ( defined($copynumber) && defined($copynumbers) && exists( $copynumbers->{$copynumber} ) );
375     foreach (qw(ccode enumchron copynumber stocknumber itemnotes itemnotes_nonpublic uri )) {
376         $itemfields{$_} = 1 if $item->$_;
377     }
378
379     # FIXME The following must be Koha::Item->serial
380     my $serial_item = Koha::Serial::Items->find($item->itemnumber);
381     if ( $serial_item ) {
382         my $serial = Koha::Serials->find($serial_item->serialid);
383         $item_info->{serial} = $serial if $serial;
384         $itemfields{publisheddate} = 1;
385     }
386
387     $item_info->{object} = $item;
388
389     # checking for holds
390     my $holds = $item->current_holds;
391     if ( my $first_hold = $holds->next ) {
392         $item_info->{first_hold} = $first_hold;
393     }
394
395     $item_info->{checkout} = $item->checkout;
396
397     # Check the transit status
398     my $transfer = $item->get_transfer;
399     if ( $transfer ) {
400         $item_info->{transfer} = $transfer;
401     }
402
403     foreach my $f (qw( itemnotes )) {
404         if ($item_info->{$f}) {
405             $item_info->{$f} =~ s|\n|<br />|g;
406             $itemfields{$f} = 1;
407         }
408     }
409
410     #item has a host number if its biblio number does not match the current bib
411
412     if ($item->biblionumber ne $biblionumber){
413         $item_info->{hostbiblionumber} = $item->biblionumber;
414         $item_info->{hosttitle} = $item->biblio->title;
415     }
416
417
418     if ( $analyze ) {
419         # count if item is used in analytical bibliorecords
420         # The 'countanalytics' flag is only used in the templates if analyze is set
421         my $countanalytics = GetAnalyticsCount( $item->itemnumber );
422         if ($countanalytics > 0){
423             $analytics_flag=1;
424             $item_info->{countanalytics} = $countanalytics;
425         }
426     }
427
428     if (defined($item->materials) && $item->materials =~ /\S/){
429         $materials_flag = 1;
430         if (defined $materials_map{ $item->materials }) {
431             $item_info->{materials} = $materials_map{ $item->materials };
432         }
433     }
434
435     if ( C4::Context->preference('UseCourseReserves') ) {
436         $item_info->{'course_reserves'} = GetItemCourseReservesInfo( itemnumber => $item->itemnumber );
437     }
438
439     if ( C4::Context->preference("LocalCoverImages") == 1 ) {
440         $item_info->{cover_images} = $item->cover_images;
441     }
442
443     if ( C4::Context->preference('UseRecalls') ) {
444         $item_info->{recall} = $item->recall;
445     }
446
447     if ( C4::Context->preference('IndependentBranches') ) {
448         my $userenv = C4::Context->userenv();
449         if ( not C4::Context->IsSuperLibrarian()
450             and $userenv->{branch} ne $item->homebranch ) {
451             $item_info->{cannot_be_edited} = 1;
452             $item_info->{not_same_branch} = 1;
453         }
454     }
455
456     if ( $item->is_bundle ) {
457         $item_info->{bundled} =
458           $item->bundle_items->search( { itemlost => { '!=' => 0 } } )
459           ->count;
460         $item_info->{bundled_lost} =
461           $item->bundle_items->search( { itemlost => 0 } )->count;
462         $item_info->{is_bundle} = 1;
463     }
464
465     if ($item->in_bundle) {
466         $item_info->{bundle_host} = $item->bundle_host;
467     }
468
469     if ($currentbranch and C4::Context->preference('SeparateHoldings')) {
470         if ($itembranchcode and $itembranchcode eq $currentbranch) {
471             push @itemloop, $item_info;
472             $itemloop_has_images++ if $item->cover_images->count;
473         } else {
474             push @otheritemloop, $item_info;
475             $otheritemloop_has_images++ if $item->cover_images->count;
476         }
477     } else {
478         push @itemloop, $item_info;
479         $itemloop_has_images++ if $item->cover_images->count;
480     }
481 }
482
483 $template->param(
484     itemloop_has_images      => $itemloop_has_images,
485     otheritemloop_has_images => $otheritemloop_has_images,
486 );
487
488 # Display only one tab if one items list is empty
489 if (scalar(@itemloop) == 0 || scalar(@otheritemloop) == 0) {
490     $template->param(SeparateHoldings => 0);
491     if (scalar(@itemloop) == 0) {
492         @itemloop = @otheritemloop;
493     }
494 }
495
496 my $some_private_shelves = Koha::Virtualshelves->get_some_shelves(
497     {
498         borrowernumber => $borrowernumber,
499         add_allowed    => 1,
500         public         => 0,
501     }
502 );
503 my $some_public_shelves = Koha::Virtualshelves->get_some_shelves(
504     {
505         borrowernumber => $borrowernumber,
506         add_allowed    => 1,
507         public         => 1,
508     }
509 );
510
511
512 $template->param(
513     add_to_some_private_shelves => $some_private_shelves,
514     add_to_some_public_shelves  => $some_public_shelves,
515 );
516
517 $template->param(
518     MARCNOTES               => !$invalid_marc_record ? $biblio->get_marc_notes() : undef,
519     itemdata_ccode          => $itemfields{ccode},
520     itemdata_enumchron      => $itemfields{enumchron},
521     itemdata_uri            => $itemfields{uri},
522     itemdata_copynumber     => $itemfields{copynumber},
523     itemdata_stocknumber    => $itemfields{stocknumber},
524     itemdata_publisheddate  => $itemfields{publisheddate},
525     volinfo                 => $itemfields{enumchron},
526     itemdata_itemnotes      => $itemfields{itemnotes},
527     itemdata_nonpublicnotes => $itemfields{itemnotes_nonpublic},
528     z3950_search_params     => C4::Search::z3950_search_args($dat),
529     hostrecords             => $hostrecords,
530     analytics_flag          => $analytics_flag,
531     C4::Search::enabled_staff_search_views,
532     materials => $materials_flag,
533 );
534
535 if (C4::Context->preference("AlternateHoldingsField") && $items->count == 0) {
536     my $fieldspec = C4::Context->preference("AlternateHoldingsField");
537     my $subfields = substr $fieldspec, 3;
538     my $holdingsep = C4::Context->preference("AlternateHoldingsSeparator") || ' ';
539     my @alternateholdingsinfo = ();
540     my @holdingsfields = $marc_record->field(substr $fieldspec, 0, 3);
541
542     for my $field (@holdingsfields) {
543         my %holding = ( holding => '' );
544         my $havesubfield = 0;
545         for my $subfield ($field->subfields()) {
546             if ((index $subfields, $$subfield[0]) >= 0) {
547                 $holding{'holding'} .= $holdingsep if (length $holding{'holding'} > 0);
548                 $holding{'holding'} .= $$subfield[1];
549                 $havesubfield++;
550             }
551         }
552         if ($havesubfield) {
553             push(@alternateholdingsinfo, \%holding);
554         }
555     }
556
557     $template->param(
558         ALTERNATEHOLDINGS   => \@alternateholdingsinfo,
559         );
560 }
561
562 my @results = ( $dat, );
563 foreach ( keys %{$dat} ) {
564     $template->param( "$_" => defined $dat->{$_} ? $dat->{$_} : '' );
565 }
566
567 # does not work: my %views_enabled = map { $_ => 1 } $template->query(loop => 'EnableViews');
568 # method query not found?!?!
569 $template->param( AmazonTld => get_amazon_tld() ) if ( C4::Context->preference("AmazonCoverImages"));
570 $template->param(
571     itemloop        => \@itemloop,
572     otheritemloop   => \@otheritemloop,
573     biblionumber        => $biblionumber,
574     ($analyze? 'analyze':'detailview') =>1,
575     subscriptions       => \@subs,
576     subscriptionsnumber => $subscriptionsnumber,
577     subscriptiontitle   => $dat->{title},
578     searchid            => scalar $query->param('searchid'),
579 );
580
581 # Lists
582
583 if (C4::Context->preference("virtualshelves") ) {
584     my $shelves = Koha::Virtualshelves->search(
585         {
586             biblionumber => $biblionumber,
587             public => 1,
588         },
589         {
590             join => 'virtualshelfcontents',
591         }
592     );
593     $template->param( 'shelves' => $shelves );
594 }
595
596 # XISBN Stuff
597 if (C4::Context->preference("FRBRizeEditions")==1) {
598     eval {
599         $template->param(
600             XISBNS => scalar get_xisbns($isbn, $biblionumber)
601         );
602     };
603     if ($@) { warn "XISBN Failed $@"; }
604 }
605
606 if ( C4::Context->preference("LocalCoverImages") == 1 ) {
607     my $images = $biblio->cover_images;
608     $template->param(
609         localimages => $biblio->cover_images->search(
610             {}, { order_by => [ \"COALESCE(itemnumber, 0, 1)", 'timestamp' ] }
611         ),
612     );
613 }
614
615 # HTML5 Media
616 if ( (C4::Context->preference("HTML5MediaEnabled") eq 'both') or (C4::Context->preference("HTML5MediaEnabled") eq 'staff') ) {
617     $template->param( C4::HTML5Media->gethtml5media($marc_record));
618 }
619
620 # Displaying tags
621 my $tag_quantity;
622 if (C4::Context->preference('TagsEnabled') and $tag_quantity = C4::Context->preference('TagsShowOnDetail')) {
623     $template->param(
624         TagsEnabled => 1,
625         TagsShowOnDetail => $tag_quantity
626     );
627     $template->param(TagLoop => get_tags({biblionumber=>$biblionumber, approved=>1,
628                                 'sort'=>'-weight', limit=>$tag_quantity}));
629 }
630
631 #we only need to pass the number of holds to the template
632 my $holds = $biblio->holds;
633 $template->param( holdcount => $holds->count );
634
635 # Check if there are any ILL requests connected to the biblio
636 my $illrequests =
637     C4::Context->preference('ILLModule')
638   ? Koha::Illrequests->search( { biblio_id => $biblionumber } )
639   : [];
640 $template->param( illrequests => $illrequests );
641
642 my $StaffDetailItemSelection = C4::Context->preference('StaffDetailItemSelection');
643 if ($StaffDetailItemSelection) {
644     # Only enable item selection if user can execute at least one action
645     if (
646         $flags->{superlibrarian}
647         || (
648             ref $flags->{tools} eq 'HASH' && (
649                 $flags->{tools}->{items_batchmod}       # Modify selected items
650                 || $flags->{tools}->{items_batchdel}    # Delete selected items
651             )
652         )
653         || ( ref $flags->{tools} eq '' && $flags->{tools} )
654       )
655     {
656         $template->param(
657             StaffDetailItemSelection => $StaffDetailItemSelection );
658     }
659 }
660
661 # get biblionumbers stored in the cart
662 my @cart_list;
663
664 if($query->cookie("intranet_bib_list")){
665     my $cart_list = $query->cookie("intranet_bib_list");
666     @cart_list = split(/\//, $cart_list);
667     if ( grep {$_ eq $biblionumber} @cart_list) {
668         $template->param( incart => 1 );
669     }
670 }
671
672 if ( C4::Context->preference('UseCourseReserves') ) {
673     my $course_reserves = GetItemCourseReservesInfo( biblionumber => $biblionumber );
674     $template->param( course_reserves => $course_reserves );
675 }
676
677 $template->param(found1 => scalar $query->param('found1') );
678
679 $template->param(biblio => $biblio);
680
681 output_html_with_http_headers $query, $cookie, $template->output;