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;
60 # if the user is not logged in via cookie, route them to the login page
61 if(!(verify_login( $cgi->cookie("ses") ))) {
65 print "Content-type: text/html; charset=utf-8\n\n";
69 template => "$ttk.ttk",
70 params => { stage_dir => $ttk, config_xml => $base_xml },
73 return Apache2::Const::OK;
77 sub _process_template {
80 my $ttk = $params{template} || return undef;
81 my $apache = $params{apache} || undef;
82 my $param_hash = $params{params} || {};
86 $template = Template->new( {
90 PLUGIN_BASE => $plugin_base,
91 INCLUDE_PATH => $includes,
100 if( ! $template->process( $ttk, $param_hash ) ) {
101 warn "Error Processing Template: " . $template->error();
102 my $err = $template->error();
103 $err =~ s/\n/\<br\/\>/g;
104 warn "Error processing template $ttk\n";
105 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
106 print "ERROR: $string";
107 #$template->process( $error_ttk , { error => $string } );
112 warn "Error processing template $ttk: $e - $@ \n";
113 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
119 # returns 1 if the session is valid, 0 otherwise
121 my $auth_token = shift;
122 return 0 unless $auth_token;
124 my $session = OpenSRF::AppSession->create("open-ils.auth");
125 my $req = $session->request("open-ils.auth.session.retrieve", $auth_token );
126 my $user = $req->gather(1);
128 return 1 if ref($user);