combine ticket notification scrips, #15353
[freeside.git] / htetc / handler.pl
1 #!/usr/bin/perl
2
3 package HTML::Mason;
4
5 use strict;
6 use warnings;
7 use FS::Mason qw( mason_interps );
8
9 #use vars qw($r);
10
11 # Bring in ApacheHandler, necessary for mod_perl integration.
12 # Uncomment the second line (and comment the first) to use
13 # Apache::Request instead of CGI.pm to parse arguments.
14 use HTML::Mason::ApacheHandler;
15 # use HTML::Mason::ApacheHandler (args_method=>'mod_perl');
16
17 ###use Module::Refresh;###
18
19 # Create Mason objects
20
21 my( $fs_interp, $rt_interp ) = mason_interps('apache');
22
23 my $ah = new HTML::Mason::ApacheHandler (
24   interp        => $fs_interp,
25   request_class => 'FS::Mason::Request',
26   args_method   => 'CGI', #(and FS too)
27 );
28
29 # Activate the following if running httpd as root (the normal case).
30 # Resets ownership of all files created by Mason at startup.
31 #
32 #chown (Apache->server->uid, Apache->server->gid, $interp->files_written);
33
34 sub handler
35 {
36     #($r) = @_;
37     my $r = shift;
38
39     # If you plan to intermix images in the same directory as
40     # components, activate the following to prevent Mason from
41     # evaluating image files as components.
42     #
43     #return -1 if $r->content_type && $r->content_type !~ m|^text/|i;
44
45     ###Module::Refresh->refresh;###
46
47     $r->content_type('text/html; charset=utf-8');
48     #$r->content_type('text/html; charset=iso-8859-1');
49     #eorar
50
51     my $headers = $r->headers_out;
52     $headers->{'Cache-control'} = 'no-cache';
53     #$r->no_cache(1);
54     $headers->{'Expires'} = '0';
55
56 #    $r->send_http_header;
57
58     if ( $r->filename =~ /\/rt\// ) { #RT
59
60       # We don't need to handle non-text, non-xml items
61       return -1 if defined( $r->content_type )
62                 && $r->content_type !~ m!(^text/|\bxml\b)!io;
63
64
65       local $SIG{__WARN__};
66       local $SIG{__DIE__};
67
68       RT::Init();
69
70       $ah->interp($rt_interp);
71
72     } else {
73
74       local $SIG{__WARN__};
75       local $SIG{__DIE__};
76
77       RT::Init() if $RT::VERSION; #for lack of something else
78
79       #we don't want the RT error handlers under FS
80       {
81         no warnings 'uninitialized';
82         undef($SIG{__WARN__}) if defined($SIG{__WARN__});
83         undef($SIG{__DIE__})  if defined($SIG{__DIE__} );
84       }
85
86       $ah->interp($fs_interp);
87
88     }
89
90     my %session;
91     my $status;
92     eval { $status = $ah->handle_request($r); };
93 #!!
94 #    if ( $@ ) {
95 #       $RT::Logger->crit($@);
96 #    }
97     warn $@ if $@;
98
99     undef %session;
100
101 #!!
102 #    if ($RT::Handle->TransactionDepth) {
103 #       $RT::Handle->ForceRollback;
104 #       $RT::Logger->crit(
105 #"Transaction not committed. Usually indicates a software fault. Data loss may have occurred"
106 #       );
107 #    }
108
109     $status;
110 }
111
112 1;