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