$ending = $1 - 1;
} elsif ( $cgi->param('ending') =~ /^([ 0-9\-\/]{1,64})$/ ) {
#probably need an option to turn off the + 86399
- my $ending = str2time($1) + 86399;
+ $ending = str2time($1) + 86399;
}
( $beginning, $ending );
package FS::UI::Web::JSRPC;
use strict;
-use vars qw(@ISA $DEBUG);
+use vars qw($DEBUG);
use Storable qw(nfreeze);
use MIME::Base64;
-use JavaScript::RPC::Server::CGI;
+use JSON;
use FS::UID;
use FS::Record qw(qsearchs);
use FS::queue;
-@ISA = qw( JavaScript::RPC::Server::CGI );
-$DEBUG = 0;
+$DEBUG = 1;
sub new {
my $class = shift;
my $self = {
env => {},
job => shift,
+ cgi => shift,
};
bless $self, $class;
+ die "CGI object required as second argument" unless $self->{'cgi'};
+
return $self;
}
+sub process {
+
+ my $self = shift;
+
+ my $cgi = $self->{'cgi'};
+
+ # XXX this should parse JSON foo and build a proper data structure
+ my @args = $cgi->param('arg');
+
+ #work around konqueror bug!
+ @args = map { s/\x00$//; $_; } @args;
+
+ my $sub = $cgi->param('sub'); #????
+
+ warn "FS::UI::Web::JSRPC::process:\n".
+ " cgi=$cgi\n".
+ " sub=$sub\n".
+ " args=".join(', ',@args)."\n"
+ if $DEBUG;
+
+ if ( $sub eq 'start_job' ) {
+
+ $self->start_job(@args);
+
+ } elsif ( $sub eq 'job_status' ) {
+
+ $self->job_status(@args);
+
+ }
+
+}
+
sub start_job {
my $self = shift;
my $error = $job->insert( '_JOB', encode_base64(nfreeze(\%param)) );
if ( $error ) {
- $error;
+ $error; #this doesn't seem to be handled well,
+ # will trigger "illegal jobnum" below?
+ # (should never be an error inserting the job, though, only thing
+ # would be Pg f%*kage)
} else {
$job->jobnum;
}
sub job_status {
my( $self, $jobnum ) = @_; #$url ???
- sleep 5; #could use something better...
+ sleep 1; # XXX could use something better...
my $job;
if ( $jobnum =~ /^(\d+)$/ ) {
@return = ( 'error', $job ? $job->statustext : $jobnum );
}
- join("\n",@return);
-
-}
+ objToJson(\@return);
-sub get_new_query {
- FS::UID::cgi();
}
1;