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 /edit/cust_main/first_pkg/select-part_pkg.html
32 my %session_callbacks = (
34 '/elements/location.html' => sub {
35 my( $custnum, $argsref ) = @_;
36 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
37 or return "unknown custnum $custnum";
39 $args{object} = $cust_main;
40 @$argsref = ( %args );
44 '/edit/cust_main/first_pkg/select-part_pkg.html' => sub {
45 my( $custnum, $argsref ) = @_;
46 my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } )
47 or return "unknown custnum $custnum";
49 my $pkgpart = $cust_main->agent->pkgpart_hashref;
51 #false laziness w/ edit/cust_main/first_pkg.html
52 my @first_svc = ( 'svc_acct', 'svc_phone' );
55 grep { $_->svcpart(\@first_svc)
56 && ( $pkgpart->{ $_->pkgpart }
57 || ( $_->agentnum && $_->agentnum == $cust_main->agentnum )
60 qsearch( 'part_pkg', { 'disabled' => '' }, '', 'ORDER BY pkg' ); # case?
62 my $conf = new FS::Conf;
63 if ( $conf->exists('pkg-addon_classnum') ) {
65 my %classnum = map { ( $_->addon_classnum => 1 ) }
66 grep { $_->freq !~ /^0/ }
68 $cust_main->ncancelled_pkgs;
70 unless ( $classnum{''} || ! keys %classnum ) {
71 @part_pkg = grep $classnum{ $_->classnum }, @part_pkg;
76 $args{part_pkg} = \@part_pkg;
77 $args{first_svc} = \@first_svc;
78 @$argsref = ( %args );
86 my( $fs_interp, $rt_interp ) = mason_interps('standalone', 'outbuf'=>\$outbuf);
91 warn "$me mason_comp called on $packet\n" if $DEBUG;
93 my $comp = $packet->{'comp'};
94 unless ( $allowed_comps{$comp} || $session_comps{$comp} ) {
95 return { 'error' => 'Illegal component' };
98 my @args = $packet->{'args'} ? @{ $packet->{'args'} } : ();
100 if ( $session_comps{$comp} ) {
102 my $session = _cache->get($packet->{'session_id'})
103 or return ( 'error' => "Can't resume session" ); #better error message
104 my $custnum = $session->{'custnum'};
106 my $error = &{ $session_callbacks{$comp} }( $custnum, \@args );
107 return { 'error' => $error } if $error;
111 my $conf = new FS::Conf;
112 $FS::Mason::Request::FSURL = $conf->config('selfservice_server-base_url');
113 $FS::Mason::Request::FSURL .= '/' unless $FS::Mason::Request::FSURL =~ /\/$/;
114 $FS::Mason::Request::QUERY_STRING = $packet->{'query_string'} || '';
117 $fs_interp->exec($comp, @args); #only FS for now alas...
119 #errors? (turn off in-line error reporting?)
121 return { 'output' => $outbuf };
127 $cache ||= new FS::ClientAPI_SessionCache( {
128 'namespace' => 'FS::ClientAPI::MyAccount',