fixing session timeout bug
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / FastJS.pm
1 package OpenILS::WWW::FastJS;
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
17
18 my $main_ttk = "opac/logic/fastjs.ttk";
19 my $init_ttk = "opac/logic/page_init.ttk";
20
21 my $includes = ['/pines/cvs/ILS/Open-ILS/src/templates'];
22
23 my $plugin_base = 'OpenILS::Template::Plugin';
24
25 sub handler {
26
27         my $apache = shift;
28         my $cgi = CGI->new( $apache );
29         print "Content-type: text/javascript; charset=utf-8\n\n";
30         
31         my @files = $cgi->param("file");
32         warn "INcluding js files @files\n";
33
34         _process_template(
35                         apache          => $apache,
36                         template                => $main_ttk,
37                         pre_process     => $init_ttk,
38                         files                   => \@files,
39                         );
40
41         return Apache::OK;
42 }
43
44 sub _process_template {
45
46         my %params = @_;
47         my $ttk                         = $params{template}             || return undef;
48         my $apache                      = $params{apache}                       || undef;
49         my $pre_process = $params{pre_process}  || undef;
50         my $files                       = $params{files}                        || [];
51
52         my $template;
53
54         $template = Template->new( { 
55                 OUTPUT                  => $apache, 
56                 ABSOLUTE                        => 1, 
57                 RELATIVE                        => 1,
58                 PLUGIN_BASE             => $plugin_base,
59                 PRE_PROCESS             => $pre_process,
60                 INCLUDE_PATH    => $includes, 
61                 PRE_CHOMP               => 1,
62                 POST_CHOMP              => 1,
63                 } 
64         );
65
66         try {
67
68                 if( ! $template->process( $ttk, 
69                                 { files => $files, doc_root => $ENV{"DOCUMENT_ROOT"} }  ) ) { 
70
71                         warn  "Error Occured: " . $template->error();
72                         my $err = $template->error();
73                         $err =~ s/\n/\<br\/\>/g;
74                         warn "Error processing template $ttk\n";        
75                         my $string =  "<br><b>Unable to process template:<br/><br/> " . $err . "!!!</b>";
76                         #$template->process( $error_ttk , { error => $string } );
77                 }
78
79         } catch Error with {
80                 my $e = shift;
81                 warn "Error processing template $ttk:  $e - $@ \n";     
82                 print "<center><br/><br/><b>Error<br/><br/> $e <br/><br/> $@ </b><br/></center>";
83                 return;
84         };
85
86 }
87
88
89 1;