MT 1713 : Updated opacSerialDefaultTab syspref
[koha_gimpoz] / opac / opac-detail.pl
index bd4dc0a..2eb819b 100755 (executable)
@@ -40,6 +40,7 @@ use C4::Serials;
 use C4::Members;
 use C4::VirtualShelves;
 use C4::XSLT;
+use Switch;
 
 BEGIN {
        if (C4::Context->preference('BakerTaylorEnabled')) {
@@ -283,6 +284,28 @@ if (C4::Context->preference("OPACFRBRizeEditions")==1) {
     };
     if ($@) { warn "XISBN Failed $@"; }
 }
+
+# Serial Collection
+my @sc_fields = $record->field(955);
+my @serialcollections = ();
+
+foreach my $sc_field (@sc_fields) {
+    my %row_data;
+
+    $row_data{text}    = $sc_field->subfield('r');
+    $row_data{branch}  = $sc_field->subfield('9');
+
+    if ($row_data{text} && $row_data{branch}) { 
+       push (@serialcollections, \%row_data);
+    }
+}
+
+if (scalar(@serialcollections) > 0) {
+    $template->param(
+       serialcollection  => 1,
+       serialcollections => \@serialcollections);
+}
+
 # Amazon.com Stuff
 if ( C4::Context->preference("OPACAmazonEnabled") ) {
     $template->param( AmazonTld => get_amazon_tld() );
@@ -558,5 +581,47 @@ if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
  $template->param('OPACSearchForTitleIn' => $search_for_title);
 }
 
+# We try to select the best default tab to show, according to what
+# the user wants, and what's available for display
+my $defaulttab;
+switch (C4::Context->preference('opacSerialDefaultTab')) {
+
+    # If the user wants subscriptions by default
+    case "subscriptions" { 
+       # And there are subscriptions, we display them
+       if ($subscriptionsnumber) {
+           $defaulttab = 'subscriptions';
+       } else {
+          # Else, we try next option
+          next; 
+       }
+    }
+
+    case "serialcollection" {
+       if (scalar(@serialcollections) > 0) {
+           $defaulttab = 'serialcollection' ;
+       } else {
+           next;
+       }
+    }
+
+    case "holdings" {
+       if ($dat->{'count'} > 0) {
+          $dat->{'defaultholdings'} = 1; 
+       } else {
+            # As this is the last option, we try other options if there are no items
+            if ($subscriptionsnumber) {
+               $defaulttab = 'subscriptions';
+            } elsif (scalar(@serialcollections) > 0) {
+               $defaulttab = 'serialcollection' ;
+            }
+       }
+
+    }
+
+}
+$template->param('defaulttab' => $defaulttab);
+
+
 
 output_html_with_http_headers $query, $cookie, $template->output;