TPAC: Add physical_dept arg/cookie
authorJeff Godin <jgodin@tadl.org>
Mon, 11 Mar 2013 20:25:40 +0000 (16:25 -0400)
committerJeff Godin <jgodin@tadl.org>
Sun, 22 May 2016 03:59:06 +0000 (23:59 -0400)
Add physical_dept variable to TPAC -- set by url argument, backed by
a session cookie.

This is accessible to TPAC templates as ctx.physical_dept, and can
be used by conditionals to show/hide UI components based on the
provided location of a catalog terminal within a library.

physical_dept is independent from, and can be used in combination
with, physical_loc: /eg/opac/home?physical_loc=2&physical_dept=teen

Signed-off-by: Jeff Godin <jgodin@tadl.org>
Conflicts:
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm

Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader.pm

index fb54f10..69ddede 100644 (file)
@@ -31,6 +31,7 @@ my $U = 'OpenILS::Application::AppUtils';
 
 use constant COOKIE_SES => 'ses';
 use constant COOKIE_LOGGEDIN => 'eg_loggedin';
+use constant COOKIE_PHYSICAL_DEPT => 'eg_physical_dept';
 use constant COOKIE_PHYSICAL_LOC => 'eg_physical_loc';
 use constant COOKIE_SSS_EXPAND => 'eg_sss_expand';
 
@@ -273,6 +274,7 @@ sub load_common {
         $ctx->{hostname} = 'remote';
     }
 
+    $ctx->{physical_dept} = $self->get_physical_dept;
     $ctx->{physical_loc} = $self->get_physical_loc;
 
     # capture some commonly accessed pages
@@ -362,6 +364,24 @@ sub staff_saved_searches_set_expansion_state {
     $self->ctx->{saved_searches_expanded} = $value;
 }
 
+sub get_physical_dept {
+    my $self = shift;
+
+    if(my $physical_dept = $self->cgi->param('physical_dept')) {
+        $self->apache->headers_out->add(
+            "Set-Cookie" => $self->cgi->cookie(
+                -name => COOKIE_PHYSICAL_DEPT,
+                -path => $self->ctx->{base_path},
+                -value => $physical_dept,
+                -expires => undef
+            )
+        );
+        return $physical_dept;
+    }
+
+    return $self->cgi->cookie(COOKIE_PHYSICAL_DEPT);
+}
+
 # physical_loc (i.e. "original location") passed in as a URL 
 # param will replace any existing physical_loc stored as a cookie.
 # If specified via ENV that rules over all and we don't set cookies.