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 my($cgi, $field) = @_;
45 foreach my $op (keys %op) {
47 warn "checking for ${field}_$op field\n"
50 if ( $cgi->param($field."_$op") =~ /^\s*\$?\s*([\d\,\s]+(\.\d\d)?)\s*$/ ) {
54 my $search = "$field $op{$op} $num";
55 push @search, $search;
57 warn "found ${field}_$op field; adding search element $search\n"
68 # cust_main report subroutines
72 =item cust_header [ CUST_FIELDS_VALUE ]
74 Returns an array of customer information headers according to the supplied
75 customer fields value, or if no value is supplied, the B<cust-fields>
80 use vars qw( @cust_fields );
84 warn "FS::svc_Common::cust_header called"
91 'Company' => 'company',
92 '(bill) Customer' => 'name',
93 '(service) Customer' => 'ship_name',
94 '(bill) Name' => 'contact',
95 '(service) Name' => 'ship_contact',
96 '(bill) Company' => 'company',
97 '(service) Company' => 'ship_company',
98 'Address 1' => 'address1',
99 'Address 2' => 'address2',
103 'Country' => 'country_full',
104 'Day phone' => 'daytime', # XXX should use msgcat, but how?
105 'Night phone' => 'night', # XXX should use msgcat, but how?
106 'Invoicing email(s)' => 'invoicing_list_emailonly',
113 warn " using supplied cust-fields override".
114 " (ignoring cust-fields config file)"
116 $cust_fields = shift;
120 my $conf = new FS::Conf;
121 if ( $conf->exists('cust-fields')
122 && $conf->config('cust-fields') =~ /^([\w \|\#\(\)]+):?/
125 warn " found cust-fields configuration value"
129 warn " no cust-fields configuration value found; using default 'Customer'"
131 $cust_fields = 'Customer';
136 @cust_header = split(/ \| /, $cust_fields);
137 @cust_fields = map { $header2method{$_} } @cust_header;
143 =item cust_sql_fields [ CUST_FIELDS_VALUE ]
145 Returns a list of fields for the SELECT portion of an SQL query.
147 As with L<the cust_header subroutine|/cust_header>, the fields returned are
148 defined by the supplied customer fields setting, or if no customer fields
149 setting is supplied, the <B>cust-fields</B> configuration value.
153 sub cust_sql_fields {
155 my @fields = qw( last first company );
156 push @fields, map "ship_$_", @fields;
157 push @fields, 'country';
160 #inefficientish, but tiny lists and only run once per page
162 grep { my $field = $_; grep { $_ eq $field } @cust_fields }
163 qw( address1 address2 city state zip daytime night );
165 map "cust_main.$_", @fields;
168 =item cust_fields SVC_OBJECT [ CUST_FIELDS_VALUE ]
170 Given a svc_ object that contains fields from cust_main (say, from a
171 JOINed search. See httemplate/search/svc_* for examples), returns an array
172 of customer information, or "(unlinked)" if this service is not linked to a
175 As with L<the cust_header subroutine|/cust_header>, the fields returned are
176 defined by the supplied customer fields setting, or if no customer fields
177 setting is supplied, the <B>cust-fields</B> configuration value.
183 warn "FS::svc_Common::cust_fields called for $svc_x ".
184 "(cust_fields: @cust_fields)"
187 #cust_header(@_) unless @cust_fields; #now need to cache to keep cust_fields
188 # #override incase we were passed as a sub
190 my $seen_unlinked = 0;
192 if ( $svc_x->custnum ) {
197 warn " ($svc_x unlinked)"
199 $seen_unlinked++ ? '' : '(unlinked)';
205 # begin JSRPC code...
208 package FS::UI::Web::JSRPC;
213 use Storable qw(nfreeze);
217 use FS::Record qw(qsearchs);
232 croak "CGI object required as second argument" unless $self->{'cgi'};
241 my $cgi = $self->{'cgi'};
243 # XXX this should parse JSON foo and build a proper data structure
244 my @args = $cgi->param('arg');
246 #work around konqueror bug!
247 @args = map { s/\x00$//; $_; } @args;
249 my $sub = $cgi->param('sub'); #????
251 warn "FS::UI::Web::JSRPC::process:\n".
254 " args=".join(', ',@args)."\n"
257 if ( $sub eq 'start_job' ) {
259 $self->start_job(@args);
261 } elsif ( $sub eq 'job_status' ) {
263 $self->job_status(@args);
267 die "unknown sub $sub";
276 warn "FS::UI::Web::start_job: ". join(', ', @_) if $DEBUG;
280 my( $field, $value ) = splice(@_, 0, 2);
281 unless ( exists( $param{$field} ) ) {
282 $param{$field} = $value;
283 } elsif ( ! ref($param{$field}) ) {
284 $param{$field} = [ $param{$field}, $value ];
286 push @{$param{$field}}, $value;
289 warn "FS::UI::Web::start_job\n".
291 if ( ref($param{$_}) ) {
292 " $_ => [ ". join(', ', @{$param{$_}}). " ]\n";
294 " $_ => $param{$_}\n";
299 #first get the CGI params shipped off to a job ASAP so an id can be returned
302 my $job = new FS::queue { 'job' => $self->{'job'} };
304 #too slow to insert all the cgi params as individual args..,?
305 #my $error = $queue->insert('_JOB', $cgi->Vars);
307 #warn 'froze string of size '. length(nfreeze(\%param)). " for job args\n"
310 my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
314 warn "job not inserted: $error\n"
317 $error; #this doesn't seem to be handled well,
318 # will trigger "illegal jobnum" below?
319 # (should never be an error inserting the job, though, only thing
320 # would be Pg f%*kage)
323 warn "job inserted successfully with jobnum ". $job->jobnum. "\n"
332 my( $self, $jobnum ) = @_; #$url ???
334 sleep 1; # XXX could use something better...
337 if ( $jobnum =~ /^(\d+)$/ ) {
338 $job = qsearchs('queue', { 'jobnum' => $jobnum } );
340 die "FS::UI::Web::job_status: illegal jobnum $jobnum\n";
344 if ( $job && $job->status ne 'failed' ) {
345 @return = ( 'progress', $job->statustext );
346 } elsif ( !$job ) { #handle job gone case : job successful
347 # so close popup, redirect parent window...
348 @return = ( 'complete' );
350 @return = ( 'error', $job ? $job->statustext : $jobnum );