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 );
57 use DateTime::Format::Strptime;
58 use Lingua::EN::Inflect qw(PL);
63 use HTML::TreeBuilder;
70 #not actually using this yet anyway...# use IPC::Run3 0.036;
71 use Net::Whois::Raw qw(whois);
73 eval "use Net::Whois::Raw 0.32 qw(whois)";
77 use Spreadsheet::WriteExcel;
78 use Business::CreditCard 0.30; #for mask-aware cardtype()
80 use String::Approx qw(amatch);
81 use Chart::LinesPoints;
84 use HTML::Widgets::SelectLayers 0.07; #should go away in favor of
87 use Business::US::USPS::WebTools::AddressStandardization;
89 use FS::UID qw( getotaker dbh datasrc driver_name );
90 use FS::Record qw( qsearch qsearchs fields dbdef
91 str2time_sql str2time_sql_closing
94 use FS::CGI qw(header menubar table itable ntable idiot
95 eidiot myexit http_header);
96 use FS::UI::Web qw(svc_url);
97 use FS::UI::Web::small_custview qw(small_custview);
98 use FS::UI::bytecount;
99 use FS::Msgcat qw(gettext geterror);
100 use FS::Misc qw( send_email send_fax states_hash counties state_label );
101 use FS::Misc::eps2png qw( eps2png );
102 use FS::Report::Table::Monthly;
103 use FS::TicketSystem;
104 use FS::Tron qw( tron_lint );
108 use FS::domain_record;
110 use FS::cust_bill_pay;
112 use FS::cust_credit_bill;
113 use FS::cust_main qw(smart_search);
114 use FS::cust_main::Import;
115 use FS::cust_main_county;
116 use FS::cust_location;
119 use FS::part_pkg_taxclass;
120 use FS::cust_pkg_reason;
122 use FS::cust_credit_refund;
123 use FS::cust_pay_refund;
126 use FS::part_bill_event;
128 use FS::part_event_condition;
130 use FS::part_referral;
132 use FS::part_svc_router;
133 use FS::part_virtual_field;
137 use FS::queue qw(joblisting);
141 use FS::svc_acct_pop qw(popselector);
142 use FS::acct_rt_transaction;
148 use FS::svc_broadband;
149 use FS::svc_external;
152 use FS::part_export_option;
160 use FS::payment_gateway;
161 use FS::agent_payment_gateway;
165 use FS::inventory_class;
166 use FS::inventory_item;
167 use FS::pkg_category;
170 use FS::access_user_pref;
171 use FS::access_group;
172 use FS::access_usergroup;
173 use FS::access_groupagent;
174 use FS::access_right;
177 use FS::phone_device;
181 use FS::cust_main_note;
183 use FS::cust_tax_location;
184 use FS::part_pkg_taxproduct;
185 use FS::part_pkg_taxoverride;
186 use FS::part_pkg_taxrate;
188 use FS::part_pkg_report_option;
189 use FS::cust_attachment;
192 use FS::h_svc_broadband;
193 use FS::h_svc_domain;
194 #use FS::h_domain_record;
195 use FS::h_svc_external;
196 use FS::h_svc_forward;
198 #use FS::h_phone_device;
200 use FS::cust_statement;
203 if ( %%%RT_ENABLED%%% ) {
205 use lib ( "/opt/rt3/local/lib", "/opt/rt3/lib" );
206 use vars qw($Nobody $SystemUser);
209 use RT::Transactions;
214 use RT::ScripActions;
215 use RT::ScripConditions;
218 use RT::GroupMembers;
219 use RT::CustomFields;
220 use RT::CustomFieldValues;
221 use RT::ObjectCustomFieldValues;
223 #blah. manually updated from RT::Interface::Web::Handler
224 use RT::Interface::Web;
231 #blah. not even in RT::Interface::Web::Handler, just in
232 #html/NoAuth/css/dhandler and rt-test-dependencies. ask for it here
233 #to throw a real error instead of just a mysterious unstyled RT
234 use CSS::Squish 0.06;
236 #slow, unreliable, segfaults and is optional
237 #see rt/html/Ticket/Elements/ShowTransactionAttachments
240 #?#use File::Path qw( rmtree );
241 #?#use File::Glob qw( bsd_glob );
242 #?#use File::Spec::Unix;
248 *CGI::redirect = sub {
251 if ( $_[0] eq '-cookie' ) { #this isn't actually used at the moment
252 (my $x, $cookie) = (shift, shift);
253 $HTML::Mason::r->err_headers_out->add( 'Set-cookie' => $cookie );
255 my $location = shift;
259 # false laziness w/below
260 if ( defined(@DBIx::Profile::ISA) ) {
262 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
267 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
269 ( UNIVERSAL::can(dbh, 'sprintProfile')
270 ? encode_entities(dbh->sprintProfile())
271 : 'DBIx::Profile missing sprintProfile method;'.
272 'unpatched or too old?' ).
273 #"\n\n". &sprintAutoProfile(). '</PRE>'.
278 dbh->{'private_profile'} = {};
283 #clear db profile, but normal redirect
284 dbh->{'private_profile'} = {};
285 $m->redirect($location);
290 } else { #normal redirect
292 $m->redirect($location);
306 $m->comp('/elements/errorpage.html', @_);
310 my( $location ) = @_;
313 #false laziness w/above
314 if ( defined(@DBIx::Profile::ISA) ) {
316 if ( $FS::CurrentUser::CurrentUser->option('show_db_profile') ) {
321 qq!<HTML><BODY>Redirect to <A HREF="$location">$location</A>!.
323 ( UNIVERSAL::can(dbh, 'sprintProfile')
324 ? encode_entities(dbh->sprintProfile())
325 : 'DBIx::Profile missing sprintProfile method;'.
326 'unpatched or too old?' ).
327 #"\n\n". &sprintAutoProfile(). '</PRE>'.
332 dbh->{'private_profile'} = {};
336 #clear db profile, but normal redirect
337 dbh->{'private_profile'} = {};
338 $m->redirect($location);
342 } else { #normal redirect
344 $m->redirect($location);
350 } # end package HTML::Mason::Commands;
356 =item mason_interps [ MODE ]
358 Returns a list consisting of two HTML::Mason::Interp objects, the first for
359 Freeside pages, and the second for RT pages.
361 #MODE can be 'apache' or 'standalone'. If not specified, defaults to 'apache'.
366 my $mode = shift || 'apache';
369 #my $request_class = 'HTML::Mason::Request'.
370 #( $mode eq 'apache' ? '::ApacheHandler' : '' );
371 my $request_class = 'FS::Mason::Request';
373 #not entirely sure it belongs here, but what the hey
374 if ( %%%RT_ENABLED%%% ) {
379 request_class => $request_class,
380 data_dir => '%%%MASONDATA%%%',
381 error_mode => 'output',
382 error_format => 'html',
383 ignore_warnings_expr => '.',
385 [ 'freeside'=>'%%%FREESIDE_DOCUMENT_ROOT%%%' ],
386 [ 'rt' =>'%%%FREESIDE_DOCUMENT_ROOT%%%/rt' ],
390 $interp{out_method} = $opt{outbuf} if $mode eq 'standalone' && $opt{outbuf};
392 my $fs_interp = new HTML::Mason::Interp (
394 escape_flags => { 'js_string' => sub {
395 #${$_[0]} =~ s/(['\\\n])/'\\'.($1 eq "\n" ? 'n' : $1)/ge;
396 ${$_[0]} =~ s/(['\\])/\\$1/g;
397 ${$_[0]} =~ s/\n/\\n/g;
398 ${$_[0]} = "'". ${$_[0]}. "'";
401 compiler => HTML::Mason::Compiler::ToObject->new(
402 allow_globals => [qw(%session)],
406 my $rt_interp = new HTML::Mason::Interp (
408 escape_flags => { 'h' => \&RT::Interface::Web::EscapeUTF8 },
409 compiler => HTML::Mason::Compiler::ToObject->new(
410 default_escape_flags => 'h',
411 allow_globals => [qw(%session)],
415 ( $fs_interp, $rt_interp );
423 Lurking in the darkness...
427 L<HTML::Mason>, L<FS>, L<RT>