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