1 package FS::ClientAPI::MasonComponent;
4 use vars qw( $cache $DEBUG $me );
6 use FS::Mason qw( mason_interps );
8 use FS::ClientAPI_SessionCache;
9 use FS::Record qw( qsearch qsearchs );
14 $me = '[FS::ClientAPI::MasonComponent]';
16 my %allowed_comps = map { $_=>1 } qw(
17 /elements/select-did.html
23 /misc/svc_acct-domains.cgi
24 /misc/part_svc-columns.cgi
27 my %session_comps = map { $_=>1 } qw(
28 /elements/location.html
29 /elements/tr-amount_fee.html
30 /edit/cust_main/first_pkg/select-part_pkg.html
33 my %session_callbacks = (
35 '/elements/location.html' => sub {
36 my( $custnum, $argsref ) = @_;
37 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
38 or return "unknown custnum $custnum";
40 $args{object} = $cust_main->bill_location;
41 @$argsref = ( %args );
45 '/elements/tr-amount_fee.html' => sub {
46 my( $custnum, $argsref ) = @_;
48 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
49 or return "unknown custnum $custnum";
51 my $conf = new FS::Conf;
57 scalar($conf->config('selfservice_process-pkgpart', $cust_main->agentnum)),
58 'process-display' => scalar($conf->config('selfservice_process-display')),
59 'process-skip_first' => $conf->exists('selfservice_process-skip_first'),
60 'num_payments' => scalar($cust_main->cust_pay),
61 'surcharge_percentage' => scalar($conf->config('credit-card-surcharge-percentage')),
63 @$argsref = ( %args );
68 '/edit/cust_main/first_pkg/select-part_pkg.html' => sub {
69 my( $custnum, $argsref ) = @_;
70 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
71 or return "unknown custnum $custnum";
73 my $pkgpart = $cust_main->agent->pkgpart_hashref;
75 #false laziness w/ edit/cust_main/first_pkg.html
76 my @first_svc = ( 'svc_acct', 'svc_phone' );
79 grep { $_->svcpart(\@first_svc)
80 && ( $pkgpart->{ $_->pkgpart }
81 || ( $_->agentnum && $_->agentnum == $cust_main->agentnum )
84 qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
86 my $conf = new FS::Conf;
87 if ( $conf->exists('pkg-addon_classnum') ) {
89 my %classnum = map { ( $_->addon_classnum => 1 ) }
90 grep { $_->freq !~ /^0/ }
92 $cust_main->ncancelled_pkgs;
94 unless ( $classnum{''} || ! keys %classnum ) {
95 @part_pkg = grep $classnum{ $_->classnum }, @part_pkg;
100 $args{part_pkg} = \@part_pkg;
101 $args{first_svc} = \@first_svc;
102 $args{no_comment} = 1;
103 $args{label_callback} = sub { shift->pkg_comment };
104 @$argsref = ( %args );
112 my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
117 warn "$me mason_comp called on $packet\n" if $DEBUG;
119 my $comp = $packet->{'comp'};
120 unless ( $allowed_comps{$comp} || $session_comps{$comp} ) {
121 return { 'error' => 'Illegal component' };
124 my @args = $packet->{'args'} ? @{ $packet->{'args'} } : ();
126 if ( $session_comps{$comp} ) {
128 my $session = _cache->get($packet->{'session_id'})
129 or return ( 'error' => "Can't resume session" ); #better error message
130 my $custnum = $session->{'custnum'};
132 my $error = &{ $session_callbacks{$comp} }( $custnum, \@args );
133 return { 'error' => $error } if $error;
137 my $conf = new FS::Conf;
138 $FS::Mason::Request::FSURL = $conf->config('selfservice_server-base_url');
139 $FS::Mason::Request::FSURL .= '/' unless $FS::Mason::Request::FSURL =~ /\/$/;
140 $FS::Mason::Request::QUERY_STRING = $packet->{'query_string'} || '';
143 $fs_interp->exec($comp, @args); #only FS for now alas...
145 #errors? (turn off in-line error reporting?)
147 return { 'output' => $outbuf };
153 $cache ||= new FS::ClientAPI_SessionCache( {
154 'namespace' => 'FS::ClientAPI::MyAccount',