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