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