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