1 package OpenILS::WWW::Reporter;
2 use strict; use warnings;
6 use Apache2::Const -compile => qw(OK REDIRECT :log);
7 use APR::Const -compile => qw(:error SUCCESS);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10 use Apache2::RequestUtil;
13 use Template qw(:template);
15 use OpenSRF::EX qw(:try);
19 use OpenSRF::Utils::SettingsParser;
20 use OpenILS::Utils::Fieldmapper;
24 # set the bootstrap config and template include directory when
25 # this module is loaded
32 my( $self, $bs_config, $core_xml, @incs ) = @_;
33 $bootstrap = $bs_config;
34 $base_xml = $core_xml;
35 $includes = [ @incs ];
39 # our templates plugins are here
40 my $plugin_base = 'OpenILS::Template::Plugin';
43 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
45 #parse the base xml file
46 #my $parser = XML::LibXML->new;
47 #$parser->expand_xinclude(1);
49 #$base_xml_doc = $parser->parse_file($base_xml);
58 my $path = $apache->path_info;
59 (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
61 $ttk = "s1" unless $ttk;
64 # if the user is not logged in via cookie, route them to the login page
65 if(! ($user = verify_login($cgi->cookie("ses"))) ) {
69 print "Content-type: text/html; charset=utf-8\n\n";
73 template => "$ttk.ttk",
77 config_xml => $base_xml,
81 return Apache2::Const::OK;
85 sub _process_template {
88 my $ttk = $params{template} || return undef;
89 my $apache = $params{apache} || undef;
90 my $param_hash = $params{params} || {};
94 $template = Template->new( {
98 PLUGIN_BASE => $plugin_base,
99 INCLUDE_PATH => $includes,
108 if( ! $template->process( $ttk, $param_hash ) ) {
109 warn "Error Processing Template: " . $template->error();
110 my $err = $template->error();
111 $err =~ s/\n/\<br\/\>/g;
112 warn "Error processing template $ttk\n";
113 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
114 print "ERROR: $string";
115 #$template->process( $error_ttk , { error => $string } );
120 warn "Error processing template $ttk: $e - $@ \n";
121 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
127 # returns the user object if the session is valid, 0 otherwise
129 my $auth_token = shift;
130 return 0 unless $auth_token;
132 my $session = OpenSRF::AppSession->create("open-ils.auth");
133 my $req = $session->request(
134 "open-ils.auth.session.retrieve", $auth_token );
135 my $user = $req->gather(1);
137 return $user if ref($user);