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