]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGKPacLoader.pm
kpac : rename files/paths for tpac consistency
[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("home") if $path =~ m|kpac/home|;
29     return $self->load_simple("category") if $path =~ m|kpac/category|;
30     return $self->load_rresults if $path =~ m|kpac/results|; # inherited 
31     return $self->load_record(no_search => 1) if $path =~ m|kpac/record|; # inherited
32
33     # ----------------------------------------------------------------
34     #  Everything below here requires SSL
35     # ----------------------------------------------------------------
36     return $self->redirect_ssl unless $self->cgi->https;
37
38     # XXX auth vs. no-auth, pending list answers
39     return $self->load_simple("getit_results") if $path =~ m|kpac/getit_results|;
40
41     if ($path =~ m|kpac/getit|) { # after getit_results
42         my $stat = $self->load_record(no_search => 1);
43         $self->ctx->{page} = 'getit'; # repair the page
44         return $stat;
45     }
46
47     # ----------------------------------------------------------------
48     #  Everything below here requires authentication
49     # ----------------------------------------------------------------
50     return $self->redirect_auth unless $self->editor->requestor;
51
52     # AUTH pages
53
54     return Apache2::Const::OK;
55 }
56
57
58 sub load_kpac_config {
59     my $self = shift;
60     my $path = '/home/berick/code/Evergreen/Open-ILS/examples/kpac.xml'; # TODO: apache config
61
62     unless ($kpac_config) {
63         $kpac_config = XMLin(
64             $path,
65             KeyAttr => ['id'],
66             ForceArray => ['layout', 'page', 'cell'],
67             NormaliseSpace => 2
68         );
69     }
70
71     # TODO: make generic "whereami" sub for EGCatLoader.
72     my $ou = $self->ctx->{physical_loc} || $self->cgi->param('loc') || $self->ctx->{aou_tree}->()->id;
73     my $layout;
74
75     # Search up the org tree to find the nearest config for the context org unit
76     while (my $org = $self->ctx->{get_aou}->($ou)) {
77         ($layout) = grep {$_->{owner} eq $org->id} @{$kpac_config->{layout}};
78         last if $layout;
79         $ou = $org->parent_ou;
80     }
81
82     $self->ctx->{kpac_layout} = $layout;
83     $self->ctx->{kpac_config} = $kpac_config;
84     $self->ctx->{kpac_root} = $self->ctx->{base_path} . "/kpac"; 
85 }
86
87
88 1;