5 use FS::Record qw(dbdef);
12 sub parse_beginning_ending {
16 if ( $cgi->param('begin') =~ /^(\d+)$/ ) {
18 } elsif ( $cgi->param('beginning') =~ /^([ 0-9\-\/]{1,64})$/ ) {
19 $beginning = str2time($1) || 0;
22 my $ending = 4294967295; #2^32-1
23 if ( $cgi->param('end') =~ /^(\d+)$/ ) {
25 } elsif ( $cgi->param('ending') =~ /^([ 0-9\-\/]{1,64})$/ ) {
26 #probably need an option to turn off the + 86399
27 $ending = str2time($1) + 86399;
30 ( $beginning, $ending );
34 # cust_main report methods
39 Returns an array of customer information headers according to the
40 B<cust-fields> configuration setting.
44 use vars qw( @cust_fields );
47 my @fields = qw( last first company );
48 push @fields, map "ship_$_", @fields
49 if dbdef->table('cust_main')->column('ship_last');
50 map "cust_main.$_", @fields;
55 warn "FS::svc_Common::cust_header called"
58 my $conf = new FS::Conf;
64 'Company' => 'company',
65 '(bill) Customer' => 'name',
66 '(service) Customer' => 'ship_name',
67 '(bill) Name' => 'contact',
68 '(service) Name' => 'ship_contact',
69 '(bill) Company' => 'company',
70 '(service) Company' => 'ship_company',
74 if ( $conf->exists('cust-fields')
75 && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):/
78 warn " found cust-fields configuration value"
82 @cust_header = split(/ \| /, $cust_fields);
83 @cust_fields = map { $header2method{$_} } @cust_header;
85 warn " no cust-fields configuration value found; using default 'Customer'"
87 @cust_header = ( 'Customer' );
88 @cust_fields = ( 'name' );
97 Given a svc_ object that contains fields from cust_main (say, from a
98 JOINed search. See httemplate/search/svc_* for examples), returns an array
99 of customer information according to the <B>cust-fields</B> configuration
100 setting, or "(unlinked)" if this service is not linked to a customer.
106 warn "FS::svc_Common::cust_fields called for $svc_x ".
107 "(cust_fields: @cust_fields)"
110 cust_header() unless @cust_fields;
112 my $seen_unlinked = 0;
114 if ( $svc_x->custnum ) {
119 warn " ($svc_x unlinked)"
121 $seen_unlinked++ ? '' : '(unlinked)';
127 # begin JSRPC code...
130 package FS::UI::Web::JSRPC;
133 use vars qw(@ISA $DEBUG);
134 use Storable qw(nfreeze);
136 #use JavaScript::RPC::Server::CGI;
138 use FS::Record qw(qsearchs);
141 #@ISA = qw( JavaScript::RPC::Server::CGI );
161 my $cgi = $self->{'cgi'};
163 # XXX this should parse JSON foo and build a proper data structure
164 my @args = $cgi->param('arg');
166 my $sub = $cgi->param('sub'); #????
168 warn "FS::UI::Web::JSRPC::process:\n".
171 " args=".join(', ',@args)."\n"
174 if ( $sub eq 'start_job' ) {
176 $self->start_job(@args);
178 } elsif ( $sub eq 'job_status' ) {
180 $self->job_status(@args);
189 warn "FS::UI::Web::start_job: ". join(', ', @_) if $DEBUG;
193 my( $field, $value ) = splice(@_, 0, 2);
194 unless ( exists( $param{$field} ) ) {
195 $param{$field} = $value;
196 } elsif ( ! ref($param{$field}) ) {
197 $param{$field} = [ $param{$field}, $value ];
199 push @{$param{$field}}, $value;
202 warn "FS::UI::Web::start_job\n".
204 if ( ref($param{$_}) ) {
205 " $_ => [ ". join(', ', @{$param{$_}}). " ]\n";
207 " $_ => $param{$_}\n";
212 #first get the CGI params shipped off to a job ASAP so an id can be returned
215 my $job = new FS::queue { 'job' => $self->{'job'} };
217 #too slow to insert all the cgi params as individual args..,?
218 #my $error = $queue->insert('_JOB', $cgi->Vars);
220 #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n"
223 my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
226 $error; #this doesn't seem to be handled well,
227 # will trigger "illegal jobnum" below?
228 # (should never be an error inserting the job, though, only thing
229 # would be Pg f%*kage)
237 my( $self, $jobnum ) = @_; #$url ???
239 sleep 1; # XXX could use something better...
242 if ( $jobnum =~ /^(\d+)$/ ) {
243 $job = qsearchs('queue', { 'jobnum' => $jobnum } );
245 die "FS::UI::Web::job_status: illegal jobnum $jobnum\n";
249 if ( $job && $job->status ne 'failed' ) {
250 @return = ( 'progress', $job->statustext );
251 } elsif ( !$job ) { #handle job gone case : job sucessful
252 # so close popup, redirect parent window...
253 @return = ( 'complete' );
255 @return = ( 'error', $job ? $job->statustext : $jobnum );
260 #XXX should use JSON!
268 '[ '. join(', ', map { qq("$_") } @return). " ]\n";