]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/WWW/Reporter.pm
67b69470180673a7c5c37fd2d800d636407d3a34
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / Reporter.pm
1 package OpenILS::WWW::Reporter;
2 use strict; use warnings;
3
4 use Apache2 ();
5 use Apache2::Log;
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;
11
12 use Template qw(:template);
13
14 use OpenSRF::EX qw(:try);
15 use OpenSRF::System;
16
17
18
19
20 # set the bootstrap config and template include directory when 
21 # this module is loaded
22 my $bootstrap;
23 my $includes = [];  
24
25 sub import {
26         my( $self, $bs_config, $tdir ) = @_;
27         $bootstrap = $bs_config;
28         $includes = [ $tdir ];
29 }
30
31
32 # our templates plugins are here
33 my $plugin_base = 'OpenILS::Template::Plugin';
34
35 sub child_init {
36         warn "Initing child with bootstrap $bootstrap\n";
37         OpenSRF::System->bootstrap_client( config_file => $bootstrap );
38 }
39
40 sub handler {
41
42         warn "TEST\n";
43         my $apache = shift;
44         my $path = $apache->path_info;
45         (my $ttk = $path) =~ s{^/?([a-zA-Z0-9_]+).*?$}{$1}o;
46
47         print "Content-type: text/html; charset=utf-8\n\n";
48
49         _process_template(
50                         apache          => $apache,
51                         template                => "$ttk.ttk",
52                         );
53
54         return Apache2::Const::OK;
55 }
56
57
58 sub _process_template {
59
60         my %params = @_;
61         my $ttk                         = $params{template}             || return undef;
62         my $apache                      = $params{apache}                       || undef;
63         my $param_hash          = $params{params}                       || {};
64
65         my $template;
66
67         $template = Template->new( { 
68                 OUTPUT                  => $apache, 
69                 ABSOLUTE                        => 1, 
70                 RELATIVE                        => 1,
71                 PLUGIN_BASE             => $plugin_base,
72                 INCLUDE_PATH    => $includes, 
73                 PRE_CHOMP               => 1,
74                 POST_CHOMP              => 1,
75                 LOAD_PERL               => 1,
76                 } 
77         );
78
79         try {
80
81                 if( ! $template->process( $ttk, $param_hash ) ) { 
82                         warn  "Error Processing Template: " . $template->error();
83                         my $err = $template->error();
84                         $err =~ s/\n/\<br\/\>/g;
85                         warn "Error processing template $ttk\n";        
86                         my $string =  "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
87                         print "ERROR: $string";
88                         #$template->process( $error_ttk , { error => $string } );
89                 }
90
91         } catch Error with {
92                 my $e = shift;
93                 warn "Error processing template $ttk:  $e - $@ \n";     
94                 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
95                 return;
96         };
97
98 }
99
100
101 1;