JBAS-1132 Biblio CMS remote header/footer
authorBill Erickson <berickxx@gmail.com>
Thu, 24 Mar 2016 16:05:13 +0000 (12:05 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/openils/var/templates_kcls/opac/register.tt2
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm

index 3126f93..40b44b9 100644 (file)
@@ -54,6 +54,7 @@ END; # input_field()
     <meta http-equiv="refresh" content="[% ctx.refresh %]">
     <title>[% l('[_1]', ctx.page_title) %]</title>
     [% INCLUDE 'opac/parts/goog_analytics.tt2' %]
+    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
     <script type="text/javascript"
       src="[% ctx.media_prefix %]/js/ui/default/opac/register.js"></script>
 
index 1638bce..9201f88 100644 (file)
@@ -2,15 +2,21 @@ package OpenILS::WWW::EGCatLoader;
 use strict; use warnings;
 use Apache2::Const -compile => qw(OK FORBIDDEN HTTP_INTERNAL_SERVER_ERROR);
 use OpenSRF::Utils::Logger qw/$logger/;
+use OpenSRF::Utils::JSON;
 use OpenILS::Utils::Fieldmapper;
 use OpenILS::Application::AppUtils;
 use OpenILS::Utils::CStoreEditor qw/:funcs/;
 use OpenILS::Event;
 use Data::Dumper;
+use LWP::UserAgent;
 use OpenILS::Utils::KCLSNormalize;
 $Data::Dumper::Indent = 0;
 my $U = 'OpenILS::Application::AppUtils';
 
+my $HEADER_FOOTER_URL = 
+  'http://kcls.bibliocms.com/template_api.json?return_data=all';
+my $HEADER_FOOTER_TIMEOUT = 5;
+
 sub load_patron_reg {
     my $self = shift;
     my $ctx = $self->ctx;
@@ -18,6 +24,7 @@ sub load_patron_reg {
     $ctx->{register} = {};
     $self->collect_register_validation_settings;
     $self->collect_requestor_info;
+    $self->collect_header_footer;
 
     # in the home org unit selector, we only want to present 
     # org units to the patron which support self-registration.
@@ -447,5 +454,50 @@ sub inspect_register_value {
     return $value;
 }
 
+# cache for re-use
+my $header;
+my $footer;
+sub collect_header_footer {
+    my $self = shift;
+
+    if ($header) {
+        $self->ctx->{register_header} = $header;
+        $self->ctx->{register_footer} = $footer;
+        return;
+    }
+
+    my $agent = LWP::UserAgent->new(timeout => 5);
+    my $res = $agent->get($HEADER_FOOTER_URL); 
+    $logger->info("Self-reg header/footer request returned code ".$res->code);
+    
+    if (!$res->is_success) {
+        $logger->error("Self-reg header/footer request ".
+          "[$HEADER_FOOTER_URL] failed with error " . $res->status_line);
+
+        return;
+    }
+
+    my $json = $res->content;
+
+    if (!$json) {
+        $logger->error("Self-reg header/footer ".
+            "[$HEADER_FOOTER_URL] returned an empty response");
+        return;
+    }
+        
+
+    my $blob;
+    eval { $blob = OpenSRF::Utils::JSON->JSON2perl($json) };
+
+    if ($@) {
+        $logger->error("Self-reg header/footer ".
+            "[$HEADER_FOOTER_URL] returned invalid JSON : $@");
+        return;
+    }
+
+    $self->ctx->{register_header} = $header = $blob->{header};
+    $self->ctx->{register_footer} = $footer = $blob->{footer};
+}
 
+1;