4 use vars qw( @ISA @EXPORT_OK );
6 use HTML::Mason 1.27; #http://www.masonhq.com/?ApacheModPerl2Redirect
7 use HTML::Mason::Interp;
8 use HTML::Mason::Compiler::ToObject;
10 @ISA = qw( Exporter );
11 @EXPORT_OK = qw( mason_interps );
15 FS::Mason - Initialize the Mason environment
19 use FS::Mason qw( mason_interps );
21 my( $fs_interp, $rt_interp ) = mason_interps('apache');
25 my( $fs_interp, $rt_interp ) = mason_interps('standalone'); #XXX name?
29 Initializes the Mason environment, loads all Freeside and RT libraries, etc.
33 # List of modules that you want to use from components (see Admin
36 package HTML::Mason::Commands;
39 use vars qw( %session );
40 use CGI 3.29 qw(-private_tempfiles); #3.29 to fix RT attachment problems
41 #use CGI::Carp qw(fatalsToBrowser);
43 use List::Util qw( max min );
50 use DateTime::Format::Strptime;
51 use Lingua::EN::Inflect qw(PL);
56 use HTML::TreeBuilder;
63 #not actually using this yet anyway...# use IPC::Run3 0.036;
64 use Net::Whois::Raw qw(whois);
66 eval "use Net::Whois::Raw 0.32 qw(whois)";
70 use Spreadsheet::WriteExcel;
71 use Business::CreditCard 0.30; #for mask-aware cardtype()
73 use String::Approx qw(amatch);
74 use Chart::LinesPoints;
77 use HTML::Widgets::SelectLayers 0.07; #should go away in favor of
80 use Business::US::USPS::WebTools::AddressStandardization;
82 use FS::UID qw( getotaker dbh datasrc driver_name );
83 use FS::Record qw( qsearch qsearchs fields dbdef
84 str2time_sql str2time_sql_closing
87 use FS::CGI qw(header menubar table itable ntable idiot
88 eidiot myexit http_header);
89 use FS::UI::Web qw(svc_url);
90 use FS::UI::Web::small_custview qw(small_custview);
91 use FS::UI::bytecount;
92 use FS::Msgcat qw(gettext geterror);
93 use FS::Misc qw( send_email send_fax states_hash counties state_label );
94 use FS::Report::Table::Monthly;
96 use FS::Tron qw( tron_lint );
100 use FS::domain_record;
102 use FS::cust_bill_pay;
104 use FS::cust_credit_bill;
105 use FS::cust_main qw(smart_search);
106 use FS::cust_main::Import;
107 use FS::cust_main_county;
108 use FS::cust_location;
111 use FS::part_pkg_taxclass;
112 use FS::cust_pkg_reason;
114 use FS::cust_credit_refund;
115 use FS::cust_pay_refund;
118 use FS::part_bill_event;
120 use FS::part_event_condition;
122 use FS::part_referral;
124 use FS::part_svc_router;
125 use FS::part_virtual_field;
129 use FS::queue qw(joblisting);
133 use FS::svc_acct_pop qw(popselector);
134 use FS::acct_rt_transaction;
140 use FS::svc_broadband;
141 use FS::svc_external;
144 use FS::part_export_option;
152 use FS::payment_gateway;
153 use FS::agent_payment_gateway;
157 use FS::inventory_class;
158 use FS::inventory_item;
159 use FS::pkg_category;
162 use FS::access_user_pref;
163 use FS::access_group;
164 use FS::access_usergroup;
165 use FS::access_groupagent;
166 use FS::access_right;
171 use FS::cust_main_note;
173 use FS::cust_tax_location;
174 use FS::part_pkg_taxproduct;
175 use FS::part_pkg_taxoverride;
176 use FS::part_pkg_taxrate;
179 if ( %%%RT_ENABLED%%% ) {
181 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
182 use vars qw($Nobody $SystemUser);
185 use RT::Transactions;
190 use RT::ScripActions;
191 use RT::ScripConditions;
194 use RT::GroupMembers;
195 use RT::CustomFields;
196 use RT::CustomFieldValues;
197 use RT::ObjectCustomFieldValues;
199 #blah. manually updated from RT::Interface::Web::Handler
200 use RT::Interface::Web;
207 #blah. not even in RT::Interface::Web::Handler, just in
208 #html/NoAuth/css/dhandler and rt-test-dependencies. ask for it here
209 #to throw a real error instead of just a mysterious unstyled RT
210 use CSS::Squish 0.06;
212 #slow, unreliable, segfaults and is optional
213 #see rt/html/Ticket/Elements/ShowTransactionAttachments
216 #?#use File::Path qw( rmtree );
217 #?#use File::Glob qw( bsd_glob );
218 #?#use File::Spec::Unix;
224 *CGI::redirect = sub {
227 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
228 (my $x, $cookie) = (shift, shift);
229 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
231 my $location = shift;
235 # false laziness w/below
236 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
239 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
241 ( UNIVERSAL::can(dbh, 'sprintProfile')
242 ? encode_entities(dbh->sprintProfile())
243 : 'DBIx::Profile missing sprintProfile method;'.
244 'unpatched or too old?' ).
245 #"\n\n". &sprintAutoProfile(). '</PRE>'.
248 dbh->{'private_profile'} = {};
251 } else { #normal redirect
253 $m->redirect($location);
267 $m->comp('/elements/errorpage.html', @_);
271 my( $location ) = @_;
274 #false laziness w/above
275 if ( defined(@DBIx::Profile::ISA) ) { #profiling redirect
278 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
280 ( UNIVERSAL::can(dbh, 'sprintProfile')
281 ? encode_entities(dbh->sprintProfile())
282 : 'DBIx::Profile missing sprintProfile method;'.
283 'unpatched or too old?' ).
284 #"\n\n". &sprintAutoProfile(). '</PRE>'.
288 dbh->{'private_profile'} = {};
290 } else { #normal redirect
292 $m->redirect($location);
298 } # end package HTML::Mason::Commands;
304 =item mason_interps [ MODE ]
306 Returns a list consisting of two HTML::Mason::Interp objects, the first for
307 Freeside pages, and the second for RT pages.
309 #MODE can be 'apache' or 'standalone'. If not specified, defaults to 'apache'.
314 my $mode = shift || 'apache';
317 #my $request_class = 'HTML::Mason::Request'.
318 #( $mode eq 'apache' ? '::ApacheHandler' : '' );
319 my $request_class = 'FS::Mason::Request';
321 #not entirely sure it belongs here, but what the hey
322 if ( %%%RT_ENABLED%%% ) {
327 request_class => $request_class,
328 data_dir => '%%%MASONDATA%%%',
329 error_mode => 'output',
330 error_format => 'html',
331 ignore_warnings_expr => '.',
333 [ 'freeside'=>'%%%FREESIDE_DOCUMENT_ROOT%%%' ],
334 [ 'rt' =>'%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
338 $interp{out_method} = $opt{outbuf} if $mode eq 'standalone' && $opt{outbuf};
340 my $fs_interp = new HTML::Mason::Interp (
342 escape_flags => { 'js_string' => sub {
343 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
344 ${$_[0]} =~ s/(['\\])/\\$1/g;
345 ${$_[0]} =~ s/\n/\\n/g;
346 ${$_[0]} = "'". ${$_[0]}. "'";
351 my $rt_interp = new HTML::Mason::Interp (
353 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
354 compiler => HTML::Mason::Compiler::ToObject->new(
355 default_escape_flags => 'h',
356 allow_globals => [qw(%session)],
360 ( $fs_interp, $rt_interp );
368 Lurking in the darkness...
372 L<HTML::Mason>, L<FS>, L<RT>