1 package OpenILS::WWW::Reporter;
2 use strict; use warnings;
4 use vars qw/$dtype_xform_map $dtype_xform/;
7 use Apache2::Const -compile => qw(OK REDIRECT DECLINED :log);
8 use APR::Const -compile => qw(:error SUCCESS);
9 use Apache2::RequestRec ();
10 use Apache2::RequestIO ();
11 use Apache2::RequestUtil;
17 use OpenSRF::EX qw(:try);
21 use OpenSRF::Utils::SettingsParser;
22 use OpenILS::Utils::Fieldmapper;
23 use OpenILS::WWW::Reporter::transforms;
26 # set the bootstrap config and template include directory when
27 # this module is loaded
34 my( $self, $bs_config, $core_xml, @incs ) = @_;
35 $bootstrap = $bs_config;
36 $base_xml = $core_xml;
37 $includes = [ @incs ];
41 # our templates plugins are here
42 my $plugin_base = 'OpenILS::Template::Plugin';
45 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
47 #parse the base xml file
48 #my $parser = XML::LibXML->new;
49 #$parser->expand_xinclude(1);
51 #$base_xml_doc = $parser->parse_file($base_xml);
58 return Apache2::Const::DECLINED if (-e $apache->filename);
62 my $path = $apache->path_info;
63 (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
65 $ttk = $apache->filename unless $ttk;
66 $ttk = "dashboard" unless $ttk;
68 $ttk = (split '/', $ttk)[-1];
72 # if the user is not logged in via cookie, route them to the login page
73 if(! ($user = verify_login($cgi->cookie("ses"))) ) {
78 print "Content-type: text/html; charset=utf-8\n\n";
79 #print "Content-type: text/html\n\n";
83 template => "$ttk.ttk",
87 config_xml => $base_xml,
91 return Apache2::Const::OK;
95 sub _process_template {
98 my $ttk = $params{template} || return undef;
99 my $apache = $params{apache} || undef;
100 my $param_hash = $params{params} || {};
101 $$param_hash{dtype_xform_map} = $OpenILS::WWW::Reporter::dtype_xform_map;
102 $$param_hash{dtype_xforms} = $OpenILS::WWW::Reporter::dtype_xforms;
106 $template = Template->new( {
110 PLUGIN_BASE => $plugin_base,
111 INCLUDE_PATH => $includes,
120 if( ! $template->process( $ttk, $param_hash ) ) {
121 warn "Error Processing Template: " . $template->error();
122 my $err = $template->error();
123 $err =~ s/\n/\<br\/\>/g;
124 warn "Error processing template $ttk\n";
125 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
126 print "ERROR: $string";
127 #$template->process( $error_ttk , { error => $string } );
132 warn "Error processing template $ttk: $e - $@ \n";
133 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
139 # returns the user object if the session is valid, 0 otherwise
141 my $auth_token = shift;
142 return 0 unless $auth_token;
144 my $session = OpenSRF::AppSession->create("open-ils.auth");
145 my $req = $session->request(
146 "open-ils.auth.session.retrieve", $auth_token );
147 my $user = $req->gather(1);
149 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
153 return $user if ref($user);