utf-8, RT#12514
[freeside.git] / FS / FS / Mason / Request.pm
1 package FS::Mason::Request;
2
3 use strict;
4 use warnings;
5 use vars qw( $FSURL $QUERY_STRING );
6 use base 'HTML::Mason::Request';
7
8 $FSURL = 'http://Set/FS_Mason_Request_FSURL/in_standalone_mode/';
9 $QUERY_STRING = '';
10
11 sub new {
12     my $class = shift;
13
14     my $superclass = $HTML::Mason::ApacheHandler::VERSION ?
15                      'HTML::Mason::Request::ApacheHandler' :
16                      $HTML::Mason::CGIHandler::VERSION ?
17                      'HTML::Mason::Request::CGI' :
18                      'HTML::Mason::Request';
19
20     $class->alter_superclass( $superclass );
21
22     #huh... shouldn't alter_superclass take care of this for us?
23     __PACKAGE__->valid_params( %{ $superclass->valid_params() } );
24
25     my %opt = @_;
26     my $mode = $superclass =~ /Apache/i ? 'apache' : 'standalone';
27     $class->freeside_setup($opt{'comp'}, $mode);
28
29     $class->SUPER::new(@_);
30
31 }
32
33 #override alter_superclass ala RT::Interface::Web::Request ??
34 # for Mason 1.39 vs. Perl 5.10.0
35
36 sub freeside_setup {
37     my( $class, $filename, $mode ) = @_;
38
39     if ( $filename =~ qr(/REST/\d+\.\d+/NoAuth/) ) {
40
41       package HTML::Mason::Commands; #?
42       use FS::UID qw( adminsuidsetup );
43
44       #need to log somebody in for the mail gw
45
46       ##old installs w/fs_selfs or selfserv??
47       #&adminsuidsetup('fs_selfservice');
48
49       &adminsuidsetup('fs_queue');
50
51     } else {
52
53       package HTML::Mason::Commands;
54       use vars qw( $cgi $p $fsurl );
55       use Encode;
56       use FS::UID qw( cgisuidsetup );
57       use FS::CGI qw( popurl rooturl );
58
59       if ( $mode eq 'apache' ) {
60         $cgi = new CGI;
61         &cgisuidsetup($cgi);
62         #&cgisuidsetup($r);
63         $fsurl = rooturl();
64         $p = popurl(2);
65       } elsif ( $mode eq 'standalone' ) {
66         $cgi = new CGI $FS::Mason::Request::QUERY_STRING; #better keep setting
67                                                           #if you set it once
68         $FS::UID::cgi = $cgi;
69         $fsurl = $FS::Mason::Request::FSURL; #kludgy, but what the hell
70         $p = popurl(2, "$fsurl$filename");
71       } else {
72         die "unknown mode $mode";
73       }
74
75     #
76     foreach my $param ( $cgi->param ) {
77       my @values = $cgi->param($param);
78       next if $cgi->uploadInfo($values[0]);
79       #warn $param;
80       @values = map decode(utf8=>$_), @values;
81       $cgi->param($param, @values);
82     }
83     
84   }
85
86 }
87
88 sub callback {
89   RT::Interface::Web::Request::callback(@_);
90 }
91
92 sub request_path {
93   RT::Interface::Web::Request::request_path(@_);
94 }
95
96 1;