use feature ':5.10';
use POSIX qw/floor pow/;
-use List::Util qw/min/;
use NDWeb::Include;
use ND::Include;
$c->stash(errors => $c->flash->{errors});
- my $groups = $dbh->prepare(q{SELECT g.gid,g.groupname,raid FROM groups g LEFT OUTER JOIN (SELECT gid,raid FROM raid_access WHERE raid = ?) AS ra ON g.gid = ra.gid WHERE g.attack});
+ my $groups = $dbh->prepare(q{
+SELECT g.gid,g.groupname,raid
+FROM groups g
+ LEFT OUTER JOIN (SELECT gid,raid FROM raid_access WHERE raid = ?) AS ra USING (gid)
+WHERE gid IN (SELECT gid FROM group_roles WHERE role = 'attack_menu')
+ });
$groups->execute($raid ? $raid->{id} : undef);
my @addgroups;
$c->forward('log',[$raid, 'BC updated raid']);
- my $groups = $dbh->prepare(q{SELECT gid,groupname FROM groups WHERE attack});
- my $delgroup = $dbh->prepare(q{DELETE FROM raid_access WHERE raid = ? AND gid = ?});
- my $addgroup = $dbh->prepare(q{INSERT INTO raid_access (raid,gid) VALUES(?,?)});
+ my $delgroups = $dbh->prepare(q{DELETE FROM raid_access WHERE raid = $1 AND gid = ANY($2)});
+ my $addgroups = $dbh->prepare(q{INSERT INTO raid_access (raid,gid) VALUES($1,unnest($2::text[]))});
- $groups->execute();
- while (my $group = $groups->fetchrow_hashref){
- my $query;
- next unless defined $c->req->param($group->{gid});
- my $command = $c->req->param($group->{gid});
- if ( $command eq 'remove'){
- $query = $delgroup;
- }elsif($command eq 'add'){
- $query = $addgroup;
- }
- if ($query){
- $query->execute($raid,$group->{gid});
- $c->forward('log',[$raid, "BC '$command' access for $group->{gid} ($group->{groupname})"]);
- }
+ if ($c->req->param('add_group')){
+ my @groups = $c->req->param('add_group');
+ warn "GROUPS!!!!: @groups";
+ $addgroups->execute($raid,\@groups);
+ $c->forward('log',[$raid, "BC added access to groups: @groups"]);
+ }
+ if ($c->req->param('remove_group')){
+ my @groups = $c->req->param('remove_group');
+ $delgroups->execute($raid,\@groups);
+ $c->forward('log',[$raid, "BC removed access for groups: @groups"]);
}
$dbh->commit;
$addtarget->execute($raid,\@targets,\@gals,$c->req->param('sizelimit'));
$c->forward('log',[$raid,"BC added planets (@targets) and the gals for (@gals)"]);
}
- $dbh->do(q{INSERT INTO raid_access (raid,gid) VALUES(?,2)}
+ $dbh->do(q{INSERT INTO raid_access (raid,gid) VALUES(?,'M')}
,undef,$raid);
$dbh->commit;
my $dbh = $c->model;
$target = $dbh->selectrow_hashref(q{
-SELECT p.id,p.value,p.score,metal_roids, crystal_roids, eonium_roids, ds.total, race
+SELECT pid,p.value,p.score,metal_roids, crystal_roids, eonium_roids, ds.total, race
FROM raids r
JOIN raid_targets rt ON r.id = rt.raid
- JOIN current_planet_stats p ON rt.planet = p.id
- LEFT OUTER JOIN current_planet_scans ps ON p.id = ps.planet
- LEFT OUTER JOIN current_development_scans ds ON p.id = ds.planet
+ JOIN current_planet_stats p USING (pid)
+ LEFT OUTER JOIN current_planet_scans ps USING (pid)
+ LEFT OUTER JOIN current_development_scans ds USING (pid)
WHERE rt.id = ? AND r.open AND not r.removed
AND r.id IN (SELECT raid FROM raid_access NATURAL JOIN groupmembers WHERE uid = ?)
},undef,$target,$c->user->id);
my $planet = $dbh->selectrow_hashref(q{
-SELECT score,value FROM current_planet_stats WHERE id = $1
+SELECT score,value FROM current_planet_stats WHERE pid = $1
},undef,$c->user->planet);
my %races = (Ter => 1, Cat => 2, Xan => 3, Zik => 4, Etd => 5);
my $fleets = $dbh->prepare(q{
SELECT DISTINCT ON (name) name, tick, fid FROM fleets
-WHERE planet = $1 AND mission = 'Full fleet'
+WHERE pid = $1 AND mission = 'Full fleet'
ORDER BY name ASC, tick DESC
});
my $ships = $dbh->prepare(q{
for ('def','att'){
my $planet = $c->user->planet;
- $planet = $target->{id} if /^def/;
+ $planet = $target->{pid} if /^def/;
$fleets->execute($planet);
my $nrfleets = 0;
my $tick = 0;