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
42 #breaks quick payment entry
43 #http://rt.cpan.org/Public/Bug/Display.html?id=37365
44 die "CGI.pm v3.38 is broken, use any other version >= 3.29".
45 " (Debian 5.0? aptitude remove libcgi-pm-perl)"
46 if $CGI::VERSION == 3.38;
48 #use CGI::Carp qw(fatalsToBrowser);
50 use List::Util qw( max min );
58 use DateTime::Format::Strptime;
59 use Lingua::EN::Inflect qw(PL);
64 use HTML::TreeBuilder;
71 #not actually using this yet anyway...# use IPC::Run3 0.036;
72 use Net::Whois::Raw qw(whois);
74 eval "use Net::Whois::Raw 0.32 qw(whois)";
78 use Spreadsheet::WriteExcel;
79 use Business::CreditCard 0.30; #for mask-aware cardtype()
82 use Net::Ping::External;
83 #if CPAN #7815 ever gets fixed# if ( $Net::Ping::External::VERSION <= 0.12 ) {
84 eval 'sub Net::Ping::External::_ping_linux {
86 my $command = "ping -s $args{size} -c $args{count} -w $args{timeout} $args{host}";
87 return Net::Ping::External::_ping_system($command, 0);
92 use String::Approx qw(amatch);
93 use Chart::LinesPoints;
96 use HTML::Widgets::SelectLayers 0.07; #should go away in favor of
99 use Business::US::USPS::WebTools::AddressStandardization;
101 use FS::UID qw( getotaker dbh datasrc driver_name );
102 use FS::Record qw( qsearch qsearchs fields dbdef
103 str2time_sql str2time_sql_closing
106 use FS::CGI qw(header menubar table itable ntable idiot
107 eidiot myexit http_header);
108 use FS::UI::Web qw(svc_url);
109 use FS::UI::Web::small_custview qw(small_custview);
110 use FS::UI::bytecount;
111 use FS::Msgcat qw(gettext geterror);
112 use FS::Misc qw( send_email send_fax states_hash counties state_label );
113 use FS::Misc::eps2png qw( eps2png );
114 use FS::Report::Table::Monthly;
115 use FS::TicketSystem;
116 use FS::Tron qw( tron_lint );
120 use FS::domain_record;
122 use FS::cust_bill_pay;
124 use FS::cust_credit_bill;
125 use FS::cust_main qw(smart_search);
126 use FS::cust_main::Import;
127 use FS::cust_main_county;
128 use FS::cust_location;
131 use FS::part_pkg_taxclass;
132 use FS::cust_pkg_reason;
134 use FS::cust_credit_refund;
135 use FS::cust_pay_refund;
138 use FS::part_bill_event;
140 use FS::part_event_condition;
142 use FS::part_referral;
144 use FS::part_svc_router;
145 use FS::part_virtual_field;
149 use FS::queue qw(joblisting);
153 use FS::svc_acct_pop qw(popselector);
154 use FS::acct_rt_transaction;
160 use FS::svc_broadband;
161 use FS::svc_external;
164 use FS::part_export_option;
172 use FS::payment_gateway;
173 use FS::agent_payment_gateway;
177 use FS::inventory_class;
178 use FS::inventory_item;
179 use FS::pkg_category;
182 use FS::access_user_pref;
183 use FS::access_group;
184 use FS::access_usergroup;
185 use FS::access_groupagent;
186 use FS::access_right;
189 use FS::phone_device;
193 use FS::cust_main_note;
195 use FS::cust_tax_location;
196 use FS::part_pkg_taxproduct;
197 use FS::part_pkg_taxoverride;
198 use FS::part_pkg_taxrate;
200 use FS::part_pkg_report_option;
201 use FS::cust_attachment;
204 use FS::h_svc_broadband;
205 use FS::h_svc_domain;
206 #use FS::h_domain_record;
207 use FS::h_svc_external;
208 use FS::h_svc_forward;
210 #use FS::h_phone_device;
212 use FS::cust_statement;
215 if ( %%%RT_ENABLED%%% ) {
217 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
218 use vars qw($Nobody $SystemUser);
221 use RT::Transactions;
226 use RT::ScripActions;
227 use RT::ScripConditions;
230 use RT::GroupMembers;
231 use RT::CustomFields;
232 use RT::CustomFieldValues;
233 use RT::ObjectCustomFieldValues;
235 #blah. manually updated from RT::Interface::Web::Handler
236 use RT::Interface::Web;
243 #blah. not even in RT::Interface::Web::Handler, just in
244 #html/NoAuth/css/dhandler and rt-test-dependencies. ask for it here
245 #to throw a real error instead of just a mysterious unstyled RT
246 use CSS::Squish 0.06;
248 #slow, unreliable, segfaults and is optional
249 #see rt/html/Ticket/Elements/ShowTransactionAttachments
252 #?#use File::Path qw( rmtree );
253 #?#use File::Glob qw( bsd_glob );
254 #?#use File::Spec::Unix;
260 *CGI::redirect = sub {
263 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
264 (my $x, $cookie) = (shift, shift);
265 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
267 my $location = shift;
271 # false laziness w/below
272 if ( defined(@DBIx::Profile::ISA) ) {
274 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
279 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
281 ( UNIVERSAL::can(dbh, 'sprintProfile')
282 ? encode_entities(dbh->sprintProfile())
283 : 'DBIx::Profile missing sprintProfile method;'.
284 'unpatched or too old?' ).
285 #"\n\n". &sprintAutoProfile(). '</PRE>'.
290 dbh->{'private_profile'} = {};
295 #clear db profile, but normal redirect
296 dbh->{'private_profile'} = {};
297 $m->redirect($location);
302 } else { #normal redirect
304 $m->redirect($location);
318 $m->comp('/elements/errorpage.html', @_);
322 my( $location ) = @_;
325 #false laziness w/above
326 if ( defined(@DBIx::Profile::ISA) ) {
328 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
333 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
335 ( UNIVERSAL::can(dbh, 'sprintProfile')
336 ? encode_entities(dbh->sprintProfile())
337 : 'DBIx::Profile missing sprintProfile method;'.
338 'unpatched or too old?' ).
339 #"\n\n". &sprintAutoProfile(). '</PRE>'.
344 dbh->{'private_profile'} = {};
348 #clear db profile, but normal redirect
349 dbh->{'private_profile'} = {};
350 $m->redirect($location);
354 } else { #normal redirect
356 $m->redirect($location);
362 } # end package HTML::Mason::Commands;
368 =item mason_interps [ MODE ]
370 Returns a list consisting of two HTML::Mason::Interp objects, the first for
371 Freeside pages, and the second for RT pages.
373 #MODE can be 'apache' or 'standalone'. If not specified, defaults to 'apache'.
378 my $mode = shift || 'apache';
381 #my $request_class = 'HTML::Mason::Request'.
382 #( $mode eq 'apache' ? '::ApacheHandler' : '' );
383 my $request_class = 'FS::Mason::Request';
385 #not entirely sure it belongs here, but what the hey
386 if ( %%%RT_ENABLED%%% ) {
391 request_class => $request_class,
392 data_dir => '%%%MASONDATA%%%',
393 error_mode => 'output',
394 error_format => 'html',
395 ignore_warnings_expr => '.',
397 [ 'freeside'=>'%%%FREESIDE_DOCUMENT_ROOT%%%' ],
398 [ 'rt' =>'%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
402 $interp{out_method} = $opt{outbuf} if $mode eq 'standalone' && $opt{outbuf};
404 my $fs_interp = new HTML::Mason::Interp (
406 escape_flags => { 'js_string' => sub {
407 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
408 ${$_[0]} =~ s/(['\\])/\\$1/g;
409 ${$_[0]} =~ s/\n/\\n/g;
410 ${$_[0]} = "'". ${$_[0]}. "'";
413 compiler => HTML::Mason::Compiler::ToObject->new(
414 allow_globals => [qw(%session)],
418 my $rt_interp = new HTML::Mason::Interp (
420 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
421 compiler => HTML::Mason::Compiler::ToObject->new(
422 default_escape_flags => 'h',
423 allow_globals => [qw(%session)],
427 ( $fs_interp, $rt_interp );
435 Lurking in the darkness...
439 L<HTML::Mason>, L<FS>, L<RT>