]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm
kpac : copy table; record details
[working/Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / EGKPacLoader.pm
1 package OpenILS::WWW::EGKPacLoader;
2 use base 'OpenILS::WWW::EGCatLoader';
3 use strict; use warnings;
4 use XML::Simple;
5 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
6 use OpenSRF::Utils::Logger qw/$logger/;
7 use OpenILS::Application::AppUtils;
8 use OpenILS::Utils::CStoreEditor qw/:funcs/;
9 my $U = 'OpenILS::Application::AppUtils';
10 my $kpac_config;
11
12 # -----------------------------------------------------------------------------
13 # Override our parent's load() sub so we can do kpac-specific path routing.
14 # -----------------------------------------------------------------------------
15 sub load {
16     my $self = shift;
17
18     $self->init_ro_object_cache;
19
20     my $stat = $self->load_common;
21     return $stat unless $stat == Apache2::Const::OK;
22
23     $self->load_kpac_config;
24
25     my $path = $self->apache->path_info;
26     ($self->ctx->{page} = $path) =~ s#.*/(.*)#$1#g;
27
28     return $self->load_simple("index") if $path =~ m|kpac/index|;
29     return $self->load_simple("category") if $path =~ m|kpac/category|;
30     return $self->load_simple("checkout") if $path =~ m|kpac/checkout|;
31     return $self->load_simple("checkout_results") if $path =~ m|kpac/checkout_results|;
32
33     # note: sets page=rresult
34     return $self->load_rresults if $path =~ m|kpac/search_results|; # inherited from tpac
35
36     # note: sets page=record
37     return $self->load_record(no_search => 1) if $path =~ m|kpac/detailed|;
38
39     # ----------------------------------------------------------------
40     #  Everything below here requires SSL
41     # ----------------------------------------------------------------
42     return $self->redirect_ssl unless $self->cgi->https;
43     return $self->load_logout if $path =~ m|kpac/logout|;
44
45     if($path =~ m|kpac/login|) {
46         return $self->load_login unless $self->editor->requestor; # already logged in?
47
48         # This will be less confusing to users than to be shown a login form
49         # when they're already logged in.
50         return $self->generic_redirect(
51             sprintf(
52                 "https://%s%s/kpac/index",
53                 $self->apache->hostname, $self->ctx->{base_path}
54             )
55         );
56     }
57
58
59     # ----------------------------------------------------------------
60     #  Everything below here requires authentication
61     # ----------------------------------------------------------------
62     return $self->redirect_auth unless $self->editor->requestor;
63
64     # AUTH pages
65
66     return Apache2::Const::OK;
67 }
68
69
70 sub load_kpac_config {
71     my $self = shift;
72     my $path = '/home/berick/code/Evergreen/Open-ILS/examples/kpac.xml'; # TODO: apache config
73
74     unless ($kpac_config) {
75         $kpac_config = XMLin(
76             $path,
77             KeyAttr => ['id'],
78             ForceArray => ['layout', 'page', 'cell'],
79             NormaliseSpace => 2
80         );
81     }
82
83     # TODO: make generic "whereami" sub for EGCatLoader.
84     my $ou = $self->ctx->{physical_loc} || $self->cgi->param('loc') || $self->ctx->{aou_tree}->()->id;
85     my $layout;
86
87     # Search up the org tree to find the nearest config for the context org unit
88     while (my $org = $self->ctx->{get_aou}->($ou)) {
89         ($layout) = grep {$_->{owner} eq $org->id} @{$kpac_config->{layout}};
90         last if $layout;
91         $ou = $org->parent_ou;
92     }
93
94     $self->ctx->{kpac_layout} = $layout;
95     $self->ctx->{kpac_config} = $kpac_config;
96     $self->ctx->{kpac_root} = $self->ctx->{base_path} . "/kpac"; 
97 }
98
99
100
101 1;
102