Bug 11175: Add syspref MaxComponentRecords to remove hardcoded limit
[srvgit] / catalogue / detail.pl
index 7e8d05d..8eae183 100755 (executable)
@@ -20,26 +20,31 @@ use Modern::Perl;
 
 use CGI qw ( -utf8 );
 use HTML::Entities;
-use Try::Tiny;
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use C4::Context;
-use C4::Koha;
-use C4::Serials;    #uses getsubscriptionfrom biblionumber
-use C4::Output;
-use C4::Biblio;
-use C4::Items;
-use C4::Circulation;
+use C4::Koha qw(
+    GetAuthorisedValues
+    getitemtypeimagelocation
+    GetNormalizedEAN
+    GetNormalizedISBN
+    GetNormalizedOCLCNumber
+    GetNormalizedUPC
+);
+use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
+use C4::Output qw( output_html_with_http_headers );
+use C4::Biblio qw( GetBiblioData GetFrameworkCode GetMarcBiblio );
+use C4::Items qw( GetAnalyticsCount GetHostItemsInfo GetItemsInfo );
+use C4::Circulation qw( GetTransfers );
 use C4::Reserves;
-use C4::Serials;
-use C4::XISBN qw(get_xisbns);
-use C4::External::Amazon;
-use C4::Search;        # enabled_staff_search_views
-use C4::Tags qw(get_tags);
-use C4::XSLT;
-use Koha::DateUtils;
+use C4::Serials qw( CountSubscriptionFromBiblionumber SearchSubscriptions GetLatestSerials );
+use C4::XISBN qw( get_xisbns );
+use C4::External::Amazon qw( get_amazon_tld );
+use C4::Search qw( z3950_search_args enabled_staff_search_views new_record_from_zebra );
+use C4::Tags qw( get_tags );
+use C4::XSLT qw( XSLTParse4Display );
+use Koha::DateUtils qw( format_sqldatetime );
 use C4::HTML5Media;
-use C4::CourseReserves qw(GetItemCourseReservesInfo);
-use C4::Acquisition qw(GetOrdersByBiblionumber);
+use C4::CourseReserves qw( GetItemCourseReservesInfo );
 use Koha::AuthorisedValues;
 use Koha::Biblios;
 use Koha::CoverImages;
@@ -50,6 +55,7 @@ use Koha::Patrons;
 use Koha::Virtualshelves;
 use Koha::Plugins;
 use Koha::SearchEngine::Search;
+use Koha::SearchEngine::QueryBuilder;
 
 my $query = CGI->new();
 
@@ -70,31 +76,8 @@ if ( C4::Context->config('enable_plugins') ) {
     my @plugins = Koha::Plugins->new()->GetPlugins({
         method => 'intranet_catalog_biblio_enhancements_toolbar_button'
     });
-
-    my @tab_plugins = Koha::Plugins->new()->GetPlugins({
-        method => 'intranet_catalog_biblio_tab',
-    });
-    my @tabs;
-    foreach my $tab_plugin (@tab_plugins) {
-        my @biblio_tabs;
-
-        try {
-            @biblio_tabs = $tab_plugin->intranet_catalog_biblio_tab();
-            foreach my $tab (@biblio_tabs) {
-                my $tab_id = 'tab-' . $tab->title;
-                $tab_id =~ s/[^0-9A-Za-z]+/-/g;
-                $tab->id( $tab_id );
-                push @tabs, $tab,
-            }
-        }
-        catch {
-            warn "Error calling 'intranet_catalog_biblio_tab' on the " . $tab_plugin->{class} . "plugin ($_)";
-        };
-    }
-
     $template->param(
         plugins => \@plugins,
-        tabs => \@tabs,
     );
 }
 
@@ -115,15 +98,17 @@ if ( not defined $record ) {
 eval { $biblio->metadata->record };
 $template->param( decoding_error => $@ );
 
-if($query->cookie("holdfor")){ 
+if($query->cookie("holdfor")){
     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
-    $template->param(
-        # FIXME Should pass the patron object
-        holdfor => $query->cookie("holdfor"),
-        holdfor_surname => $holdfor_patron->surname,
-        holdfor_firstname => $holdfor_patron->firstname,
-        holdfor_cardnumber => $holdfor_patron->cardnumber,
-    );
+    if ( $holdfor_patron ) {
+        $template->param(
+            # FIXME Should pass the patron object
+            holdfor => $query->cookie("holdfor"),
+            holdfor_surname => $holdfor_patron->surname,
+            holdfor_firstname => $holdfor_patron->firstname,
+            holdfor_cardnumber => $holdfor_patron->cardnumber,
+        );
+    }
 }
 
 if($query->cookie("searchToOrder")){
@@ -138,38 +123,19 @@ my $fw           = GetFrameworkCode($biblionumber);
 my $showallitems = $query->param('showallitems');
 my $marcflavour  = C4::Context->preference("marcflavour");
 
-# XSLT processing of some stuff
-my $xslfile = C4::Context->preference('XSLTDetailsDisplay') || "default";
-my $lang   = $xslfile ? C4::Languages::getlanguage()  : undef;
-my $sysxml = $xslfile ? C4::XSLT::get_xslt_sysprefs() : undef;
-
-if ( $xslfile ) {
-
-    my $searcher = Koha::SearchEngine::Search->new(
-        { index => $Koha::SearchEngine::BIBLIOS_INDEX }
-    );
-    my $cleaned_title = $biblio->title;
-    $cleaned_title =~ tr|/||;
-    my $query =
-      ( C4::Context->preference('UseControlNumber') and $record->field('001') )
-      ? 'rcn:'. $record->field('001')->data . ' AND (bib-level:a OR bib-level:b)'
-      : "Host-item:$cleaned_title";
-    my ( $err, $result, $count ) = $searcher->simple_search_compat( $query, 0, 0 );
-
-    warn "Warning from simple_search_compat: $err"
-        if $err;
-
-    my $variables = {
-        show_analytics_link => $count > 0 ? 1 : 0
-    };
+{
+    # XSLT processing of some stuff
 
     $template->param(
         XSLTDetailsDisplay => '1',
-        XSLTBloc           => XSLTParse4Display(
-            $biblionumber, $record, "XSLTDetailsDisplay", 1,
-            undef,         $sysxml, $xslfile,             $lang,
-            $variables
-        )
+        XSLTBloc => XSLTParse4Display(
+            {
+                biblionumber   => $biblionumber,
+                record         => $record,
+                xsl_syspref    => "XSLTDetailsDisplay",
+                fix_amps       => 1,
+            }
+        ),
     );
 }
 
@@ -245,6 +211,28 @@ foreach my $subscription (@subscriptions) {
     push @subs, \%cell;
 }
 
+# Get component parts details
+my $showcomp = C4::Context->preference('ShowComponentRecords');
+if ( $showcomp eq 'both' || $showcomp eq 'staff' ) {
+    if ( my $components = $biblio->get_marc_components(C4::Context->preference('MaxComponentRecords')) ) {
+        my $parts;
+        for my $part ( @{$components} ) {
+            $part = C4::Search::new_record_from_zebra( 'biblioserver', $part );
+
+            push @{$parts},
+              XSLTParse4Display(
+                {
+                    biblionumber => $biblionumber,
+                    record       => $part,
+                    xsl_syspref  => "XSLTResultsDisplay",
+                    fix_amps     => 1,
+                }
+              );
+        }
+        $template->param( ComponentParts => $parts );
+        $template->param( ComponentPartsQuery => $biblio->get_components_query );
+    }
+}
 
 # Get acquisition details
 if ( C4::Context->preference('AcquisitionDetails') ) {
@@ -466,6 +454,7 @@ $template->param(
     itemdata_uri        => $itemfields{uri},
     itemdata_copynumber => $itemfields{copynumber},
     itemdata_stocknumber => $itemfields{stocknumber},
+    itemdata_publisheddate => $itemfields{publisheddate},
     volinfo                => $itemfields{enumchron},
         itemdata_itemnotes  => $itemfields{itemnotes},
         itemdata_nonpublicnotes => $itemfields{itemnotes_nonpublic},
@@ -522,8 +511,6 @@ $template->param(
     searchid            => scalar $query->param('searchid'),
 );
 
-# $debug and $template->param(debug_display => 1);
-
 # Lists
 
 if (C4::Context->preference("virtualshelves") ) {
@@ -611,6 +598,11 @@ if($query->cookie("intranet_bib_list")){
     }
 }
 
+if ( C4::Context->preference('UseCourseReserves') ) {
+    my $course_reserves = GetItemCourseReservesInfo( biblionumber => $biblionumber );
+    $template->param( course_reserves => $course_reserves );
+}
+
 $template->param(biblio => $biblio);
 
 output_html_with_http_headers $query, $cookie, $template->output;