X-Git-Url: https://ruin.nu/git/?a=blobdiff_plain;f=lib%2FNDWeb%2FController%2FJSRPC.pm;h=bf7e5940256f6bf056d3cfbb3d268e4f77b86175;hb=816fe5105ca7111b535a2729094e65a2ad83718a;hp=80912c10732e5b53045de5e071b1f53cb7de2a3f;hpb=25cfbba80f992bd251751782e30cb8c3d57b53d3;p=ndwebbie.git diff --git a/lib/NDWeb/Controller/JSRPC.pm b/lib/NDWeb/Controller/JSRPC.pm index 80912c1..bf7e594 100644 --- a/lib/NDWeb/Controller/JSRPC.pm +++ b/lib/NDWeb/Controller/JSRPC.pm @@ -219,6 +219,39 @@ sub assertTarget : Private { } } +sub addscans : Local { + my ( $self, $c ) = @_; + my $dbh = $c->model; + + my $findscan = $dbh->prepare(q{SELECT scan_id FROM scans + WHERE scan_id = LOWER(?) AND tick >= tick() - 168 AND groupscan = ? + }); + my $addscan = $dbh->prepare(q{INSERT INTO scans (scan_id,tick,uid,groupscan) + VALUES (LOWER(?),tick(),?,?) + }); + my $addpoint = $dbh->prepare(q{UPDATE users SET scan_points = scan_points + 1 + WHERE uid = ? + }); + my $message = $c->req->param('message'); + my @scans; + while ($message =~ m{scan(_id|_grp)?=(\w+)}g){ + my $groupscan = (defined $1 && $1 eq '_grp') || 0; + my %scan; + $scan{id} = $2; + $scan{group} = $groupscan; + $findscan->execute($2,$groupscan); + if ($findscan->rows == 0){ + if ($addscan->execute($2,$c->stash->{UID},$groupscan)){ + $addpoint->execute($c->stash->{UID}) unless $groupscan; + $scan{added} = 1; + } + }else{ + $scan{message} = 'already exists'; + } + push @scans,\%scan; + } +} + sub end : ActionClass('RenderView') { my ($self,$c) = @_; $c->res->content_type('application/xml');