5 use FS::Record qw(dbdef);
14 sub parse_beginning_ending {
18 if ( $cgi->param('begin') =~ /^(\d+)$/ ) {
20 } elsif ( $cgi->param('beginning') =~ /^([ 0-9\-\/]{1,64})$/ ) {
21 $beginning = str2time($1) || 0;
24 my $ending = 4294967295; #2^32-1
25 if ( $cgi->param('end') =~ /^(\d+)$/ ) {
27 } elsif ( $cgi->param('ending') =~ /^([ 0-9\-\/]{1,64})$/ ) {
28 #probably need an option to turn off the + 86399
29 $ending = str2time($1) + 86399;
32 ( $beginning, $ending );
36 # cust_main report subroutines
40 =item cust_header [ CUST_FIELDS_VALUE ]
42 Returns an array of customer information headers according to the supplied
43 customer fields value, or if no value is supplied, the B<cust-fields>
48 use vars qw( @cust_fields );
52 warn "FS::svc_Common::cust_header called"
59 'Company' => 'company',
60 '(bill) Customer' => 'name',
61 '(service) Customer' => 'ship_name',
62 '(bill) Name' => 'contact',
63 '(service) Name' => 'ship_contact',
64 '(bill) Company' => 'company',
65 '(service) Company' => 'ship_company',
66 'Address 1' => 'address1',
67 'Address 2' => 'address2',
71 'Country' => 'country_full',
72 'Day phone' => 'daytime', # XXX should use msgcat, but how?
73 'Night phone' => 'night', # XXX should use msgcat, but how?
74 'Invoicing email(s)' => 'invoicing_list_emailonly',
81 warn " using supplied cust-fields override".
82 " (ignoring cust-fields config file)"
88 my $conf = new FS::Conf;
89 if ( $conf->exists('cust-fields')
90 && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):?/
93 warn " found cust-fields configuration value"
97 warn " no cust-fields configuration value found; using default 'Customer'"
99 $cust_fields = 'Customer';
104 @cust_header = split(/ \| /, $cust_fields);
105 @cust_fields = map { $header2method{$_} } @cust_header;
111 =item cust_sql_fields [ CUST_FIELDS_VALUE ]
113 Returns a list of fields for the SELECT portion of an SQL query.
115 As with L<the cust_header subroutine|/cust_header>, the fields returned are
116 defined by the supplied customer fields setting, or if no customer fields
117 setting is supplied, the <B>cust-fields</B> configuration value.
121 sub cust_sql_fields {
123 my @fields = qw( last first company );
124 push @fields, map "ship_$_", @fields;
125 push @fields, 'country';
128 #inefficientish, but tiny lists and only run once per page
130 grep { my $field = $_; grep { $_ eq $field } @cust_fields }
131 qw( address1 address2 city state zip daytime night );
133 map "cust_main.$_", @fields;
136 =item cust_fields SVC_OBJECT [ CUST_FIELDS_VALUE ]
138 Given a svc_ object that contains fields from cust_main (say, from a
139 JOINed search. See httemplate/search/svc_* for examples), returns an array
140 of customer information, or "(unlinked)" if this service is not linked to a
143 As with L<the cust_header subroutine|/cust_header>, the fields returned are
144 defined by the supplied customer fields setting, or if no customer fields
145 setting is supplied, the <B>cust-fields</B> configuration value.
151 warn "FS::svc_Common::cust_fields called for $svc_x ".
152 "(cust_fields: @cust_fields)"
155 #cust_header(@_) unless @cust_fields; #now need to cache to keep cust_fields
156 # #override incase we were passed as a sub
158 my $seen_unlinked = 0;
160 if ( $svc_x->custnum ) {
165 warn " ($svc_x unlinked)"
167 $seen_unlinked++ ? '' : '(unlinked)';
173 # begin JSRPC code...
176 package FS::UI::Web::JSRPC;
181 use Storable qw(nfreeze);
185 use FS::Record qw(qsearchs);
200 croak "CGI object required as second argument" unless $self->{'cgi'};
209 my $cgi = $self->{'cgi'};
211 # XXX this should parse JSON foo and build a proper data structure
212 my @args = $cgi->param('arg');
214 #work around konqueror bug!
215 @args = map { s/\x00$//; $_; } @args;
217 my $sub = $cgi->param('sub'); #????
219 warn "FS::UI::Web::JSRPC::process:\n".
222 " args=".join(', ',@args)."\n"
225 if ( $sub eq 'start_job' ) {
227 $self->start_job(@args);
229 } elsif ( $sub eq 'job_status' ) {
231 $self->job_status(@args);
235 die "unknown sub $sub";
244 warn "FS::UI::Web::start_job: ". join(', ', @_) if $DEBUG;
248 my( $field, $value ) = splice(@_, 0, 2);
249 unless ( exists( $param{$field} ) ) {
250 $param{$field} = $value;
251 } elsif ( ! ref($param{$field}) ) {
252 $param{$field} = [ $param{$field}, $value ];
254 push @{$param{$field}}, $value;
257 warn "FS::UI::Web::start_job\n".
259 if ( ref($param{$_}) ) {
260 " $_ => [ ". join(', ', @{$param{$_}}). " ]\n";
262 " $_ => $param{$_}\n";
267 #first get the CGI params shipped off to a job ASAP so an id can be returned
270 my $job = new FS::queue { 'job' => $self->{'job'} };
272 #too slow to insert all the cgi params as individual args..,?
273 #my $error = $queue->insert('_JOB', $cgi->Vars);
275 #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n"
278 my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
282 warn "job not inserted: $error\n"
285 $error; #this doesn't seem to be handled well,
286 # will trigger "illegal jobnum" below?
287 # (should never be an error inserting the job, though, only thing
288 # would be Pg f%*kage)
291 warn "job inserted successfully with jobnum ". $job->jobnum. "\n"
300 my( $self, $jobnum ) = @_; #$url ???
302 sleep 1; # XXX could use something better...
305 if ( $jobnum =~ /^(\d+)$/ ) {
306 $job = qsearchs('queue', { 'jobnum' => $jobnum } );
308 die "FS::UI::Web::job_status: illegal jobnum $jobnum\n";
312 if ( $job && $job->status ne 'failed' ) {
313 @return = ( 'progress', $job->statustext );
314 } elsif ( !$job ) { #handle job gone case : job successful
315 # so close popup, redirect parent window...
316 @return = ( 'complete' );
318 @return = ( 'error', $job ? $job->statustext : $jobnum );