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, $tdir, $core_xml ) = @_;
33 $bootstrap = $bs_config;
34 $base_xml = $core_xml;
35 $includes = [ $tdir ];
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 #$base_xml_doc = $parser->parse_file($base_xml);
56 my $path = $apache->path_info;
57 (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
59 $ttk = "s1" unless $ttk;
62 # if the user is not logged in via cookie, route them to the login page
63 if(! ($user = verify_login($cgi->cookie("ses"))) ) {
67 print "Content-type: text/html; charset=utf-8\n\n";
71 template => "$ttk.ttk",
75 config_xml => $base_xml,
79 return Apache2::Const::OK;
83 sub _process_template {
86 my $ttk = $params{template} || return undef;
87 my $apache = $params{apache} || undef;
88 my $param_hash = $params{params} || {};
92 $template = Template->new( {
96 PLUGIN_BASE => $plugin_base,
97 INCLUDE_PATH => $includes,
106 if( ! $template->process( $ttk, $param_hash ) ) {
107 warn "Error Processing Template: " . $template->error();
108 my $err = $template->error();
109 $err =~ s/\n/\<br\/\>/g;
110 warn "Error processing template $ttk\n";
111 my $string = "<br><b>Unable to process template:<br/><br/> " . $err . "</b>";
112 print "ERROR: $string";
113 #$template->process( $error_ttk , { error => $string } );
118 warn "Error processing template $ttk: $e - $@ \n";
119 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
125 # returns the user object if the session is valid, 0 otherwise
127 my $auth_token = shift;
128 return 0 unless $auth_token;
130 my $session = OpenSRF::AppSession->create("open-ils.auth");
131 my $req = $session->request("open-ils.auth.session.retrieve", $auth_token );
132 my $user = $req->gather(1);
134 return $user if ref($user);