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;
23 # set the bootstrap config and template include directory when
24 # this module is loaded
31 my( $self, $bs_config, $tdir, $core_xml ) = @_;
32 $bootstrap = $bs_config;
33 $base_xml = $core_xml;
34 $includes = [ $tdir ];
38 # our templates plugins are here
39 my $plugin_base = 'OpenILS::Template::Plugin';
42 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
44 #parse the base xml file
45 #my $parser = XML::LibXML->new;
46 #$base_xml_doc = $parser->parse_file($base_xml);
55 my $path = $apache->path_info;
56 (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
58 $ttk = "s1" unless $ttk;
61 # if the user is not logged in via cookie, route them to the login page
62 if(! ($user = verify_login($cgi->cookie("ses"))) ) {
66 print "Content-type: text/html; charset=utf-8\n\n";
70 template => "$ttk.ttk",
74 config_xml => $base_xml,
78 return Apache2::Const::OK;
82 sub _process_template {
85 my $ttk = $params{template} || return undef;
86 my $apache = $params{apache} || undef;
87 my $param_hash = $params{params} || {};
91 $template = Template->new( {
95 PLUGIN_BASE => $plugin_base,
96 INCLUDE_PATH => $includes,
105 if( ! $template->process( $ttk, $param_hash ) ) {
106 warn "Error Processing Template: " . $template->error();
107 my $err = $template->error();
108 $err =~ s/\n/\<br\/\>/g;
109 warn "Error processing template $ttk\n";
110 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
111 print "ERROR: $string";
112 #$template->process( $error_ttk , { error => $string } );
117 warn "Error processing template $ttk: $e - $@ \n";
118 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
124 # returns 1 if the session is valid, 0 otherwise
126 my $auth_token = shift;
127 return 0 unless $auth_token;
129 my $session = OpenSRF::AppSession->create("open-ils.auth");
130 my $req = $session->request("open-ils.auth.session.retrieve", $auth_token );
131 my $user = $req->gather(1);
133 return 1 if ref($user);