]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/WWW/Web.pm
moved redirect to latest mod_perl
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / Web.pm
1 package OpenILS::WWW::Web;
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 CGI ();
13 use Template qw(:template);
14
15 use OpenSRF::EX qw(:try);
16 use OpenSRF::System;
17
18 my $main_ttk = "opac/logic/page_router.ttk";
19 my $error_ttk = "opac/pages/error.ttk";
20 my $init_ttk = "opac/logic/page_init.ttk";
21 my $bootstrap = "/pines/conf/bootstrap.conf";
22 my $child_init_ttk = "opac/logic/child_init.ttk";
23
24 my $includes = [];  # [  '/pines/cvs/ILS/Open-ILS/src/templates' ];
25
26 sub import {
27         my( $self, $tdir ) = @_;
28         $includes = [ $tdir ];
29 }
30
31
32
33 my $plugin_base = 'OpenILS::Template::Plugin';
34
35 sub handler {
36
37         my $apache = shift;
38         print "Content-type: text/html; charset=utf-8\n\n";
39
40         _process_template(
41                         apache          => $apache,
42                         template                => $main_ttk,
43                         pre_process     => $init_ttk );
44
45         return Apache2::Const::OK;
46 }
47
48 sub child_init_handler {
49         _process_template(  template => $child_init_ttk );
50 }
51
52 sub _process_template {
53
54         my %params = @_;
55         my $ttk                         = $params{template}             || return undef;
56         my $apache                      = $params{apache}                       || undef;
57         my $pre_process = $params{pre_process}  || undef;
58         my $param_hash          = $params{params}                       || {};
59
60         my $template;
61
62         $template = Template->new( { 
63                 OUTPUT                  => $apache, 
64                 ABSOLUTE                        => 1, 
65                 RELATIVE                        => 1,
66                 PLUGIN_BASE             => $plugin_base,
67                 PRE_PROCESS             => $pre_process,
68                 INCLUDE_PATH    => $includes, 
69                 PRE_CHOMP               => 1,
70                 POST_CHOMP              => 1,
71                 } 
72         );
73
74         try {
75
76                 if( ! $template->process( $ttk, $param_hash ) ) { 
77                         warn  "Error Occured: " . $template->error();
78                         my $err = $template->error();
79                         $err =~ s/\n/\<br\/\>/g;
80                         warn "Error processing template $ttk\n";        
81                         my $string =  "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
82                         $template->process( $error_ttk , { error => $string } );
83                 }
84
85         } catch Error with {
86                 my $e = shift;
87                 warn "Error processing template $ttk:  $e - $@ \n";     
88                 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
89                 return;
90         };
91
92 }
93
94
95 1;