1 package OpenILS::WWW::Reporter;
2 use strict; use warnings;
4 use vars qw/$dtype_xform_map $dtype_xform/;
8 use Apache2::Const -compile => qw(OK REDIRECT DECLINED :log);
9 use APR::Const -compile => qw(:error SUCCESS);
10 use Apache2::RequestRec ();
11 use Apache2::RequestIO ();
12 use Apache2::RequestUtil;
18 use OpenSRF::EX qw(:try);
22 use OpenSRF::Utils::SettingsParser;
23 use OpenILS::Utils::Fieldmapper;
24 use OpenILS::WWW::Reporter::transforms;
27 # set the bootstrap config and template include directory when
28 # this module is loaded
35 my( $self, $bs_config, $core_xml, @incs ) = @_;
36 $bootstrap = $bs_config;
37 $base_xml = $core_xml;
38 $includes = [ @incs ];
42 # our templates plugins are here
43 my $plugin_base = 'OpenILS::Template::Plugin';
46 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
48 #parse the base xml file
49 #my $parser = XML::LibXML->new;
50 #$parser->expand_xinclude(1);
52 #$base_xml_doc = $parser->parse_file($base_xml);
59 return Apache2::Const::DECLINED if (-e $apache->filename);
63 my $path = $apache->path_info;
64 (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
66 $ttk = $apache->filename unless $ttk;
67 $ttk = "dashboard" unless $ttk;
69 $ttk = (split '/', $ttk)[-1];
73 # if the user is not logged in via cookie, route them to the login page
74 if(! ($user = verify_login($cgi->cookie("ses"))) ) {
79 print "Content-type: text/html; charset=utf-8\n\n";
80 #print "Content-type: text/html\n\n";
84 template => "$ttk.ttk",
88 config_xml => $base_xml,
92 return Apache2::Const::OK;
96 sub _process_template {
99 my $ttk = $params{template} || return undef;
100 my $apache = $params{apache} || undef;
101 my $param_hash = $params{params} || {};
102 $$param_hash{dtype_xform_map} = $OpenILS::WWW::Reporter::dtype_xform_map;
103 $$param_hash{dtype_xforms} = $OpenILS::WWW::Reporter::dtype_xforms;
107 $template = Template->new( {
111 PLUGIN_BASE => $plugin_base,
112 INCLUDE_PATH => $includes,
121 if( ! $template->process( $ttk, $param_hash ) ) {
122 warn "Error Processing Template: " . $template->error();
123 my $err = $template->error();
124 $err =~ s/\n/\<br\/\>/g;
125 warn "Error processing template $ttk\n";
126 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
127 print "ERROR: $string";
128 #$template->process( $error_ttk , { error => $string } );
133 warn "Error processing template $ttk: $e - $@ \n";
134 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
140 # returns the user object if the session is valid, 0 otherwise
142 my $auth_token = shift;
143 return 0 unless $auth_token;
145 my $session = OpenSRF::AppSession->create("open-ils.auth");
146 my $req = $session->request(
147 "open-ils.auth.session.retrieve", $auth_token );
148 my $user = $req->gather(1);
150 if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
154 return $user if ref($user);