From: Michael Andreen Date: Tue, 15 Jul 2008 15:16:46 +0000 (+0200) Subject: Converted editRaid page X-Git-Url: https://ruin.nu/git/?p=ndwebbie.git;a=commitdiff_plain;h=57f880656c4486f68583058121a5bcb3b316199c Converted editRaid page --- diff --git a/NDWeb/Pages/EditRaid.pm b/NDWeb/Pages/EditRaid.pm deleted file mode 100644 index cbcc3b2..0000000 --- a/NDWeb/Pages/EditRaid.pm +++ /dev/null @@ -1,261 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# This program is free software; you can redistribute it and/or modify * -# it under the terms of the GNU General Public License as published by * -# the Free Software Foundation; either version 2 of the License, or * -# (at your option) any later version. * -# * -# This program is distributed in the hope that it will be useful, * -# but WITHOUT ANY WARRANTY; without even the implied warranty of * -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * -# GNU General Public License for more details. * -# * -# You should have received a copy of the GNU General Public License * -# along with this program; if not, write to the * -# Free Software Foundation, Inc., * -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * -#**************************************************************************/ -package NDWeb::Pages::EditRaid; -use strict; -use warnings FATAL => 'all'; -use ND::Include; -use CGI qw/:standard/; -use NDWeb::Include; - -use base qw/NDWeb::XMLPage/; - -$NDWeb::Page::PAGES{editRaid} = __PACKAGE__; - -sub render_body { - my $self = shift; - my ($BODY) = @_; - $self->{TITLE} = 'Create/Edit Raids'; - my $DBH = $self->{DBH}; - - return $self->noAccess unless $self->isBC; - my $error; - - my @alliances = alliances(); - $BODY->param(Alliances => \@alliances); - - my $raid; - if (defined param 'raid' and param('raid') =~ /^(\d+)$/){ - my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?}); - $raid = $DBH->selectrow_hashref($query,undef,$1); - } - if (defined param('cmd') && param('cmd') eq 'submit'){ - my $query = $DBH->prepare(q{INSERT INTO raids (tick,waves,message) VALUES(?,?,'')}); - if ($query->execute(param('tick'),param('waves'))){ - $raid = $DBH->last_insert_id(undef,undef,undef,undef,"raids_id_seq"); - my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?}); - $raid = $DBH->selectrow_hashref($query,undef,$raid); - }else{ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - } - - if ($raid && defined param('cmd')){ - if (param('cmd') eq 'remove'){ - $DBH->do(q{UPDATE raids SET open = FALSE, removed = TRUE WHERE id = ?},undef,$raid->{id}); - }elsif (param('cmd') eq 'Open'){ - if($DBH->do(q{UPDATE raids SET open = TRUE, removed = FALSE WHERE id = ?},undef,$raid->{id})){ - $raid->{open} = 1; - $raid->{removed} = 0; - } - }elsif (param('cmd') eq 'Close'){ - if ($DBH->do(q{UPDATE raids SET open = FALSE WHERE id = ?},undef,$raid->{id})){ - $raid->{open} = 0; - } - }elsif (param('cmd') eq 'showcoords'){ - if($DBH->do(q{UPDATE raids SET released_coords = TRUE WHERE id = ?},undef,$raid->{id})){ - $raid->{released_coords} = 1; - } - }elsif (param('cmd') eq 'hidecoords'){ - if($DBH->do(q{UPDATE raids SET released_coords = FALSE WHERE id = ?},undef,$raid->{id})){ - $raid->{released_coords} = 0; - } - }elsif (param('cmd') eq 'comment'){ - $DBH->do(q{UPDATE raid_targets SET comment = ? WHERE id = ?} - ,undef,escapeHTML(param('comment')),param('target')) - or $error .= p($DBH->errstr); - - }elsif (param('cmd') eq 'change' || param('cmd') eq 'submit'){ - $DBH->begin_work; - my $message = escapeHTML(param('message')); - $raid->{message} = $message; - $raid->{waves} = param('waves'); - $raid->{tick} = param('tick'); - unless ($DBH->do(qq{UPDATE raids SET message = ?, tick = ?, waves = ? WHERE id = ?} - ,undef,$message,param('tick'),param('waves'),$raid->{id})){ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - my $sizelimit = ''; - if (param('sizelimit') =~ /^(\d+)$/){ - $sizelimit = "AND p.size >= $1"; - unless ($DBH->do(qq{DELETE FROM raid_targets WHERE id IN (SELECT t.id FROM current_planet_stats p - JOIN raid_targets t ON p.id = t.planet WHERE p.size < ? AND t.raid = ?)},undef,$1,$raid->{id})){ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - } - my $targets = param('targets'); - my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) ( - SELECT ?, id FROM current_planet_stats p WHERE x = ? AND y = ? AND COALESCE(z = ?,TRUE) $sizelimit)}); - while ($targets =~ m/(\d+):(\d+)(?::(\d+))?/g){ - unless ($addtarget->execute($raid->{id},$1,$2,$3)){ - $error .= "

Something went wrong when adding $1:$2".($3 ? ":$3" : '').": ".$DBH->errstr."

"; - } - } - if (param('alliance') =~ /^(\d+)$/ && $1 != 1){ - log_message $ND::UID,"BC adding alliance $1 to raid"; - my $addtarget = $DBH->prepare(qq{INSERT INTO raid_targets(raid,planet) ( - SELECT ?,id FROM current_planet_stats p WHERE alliance_id = ? $sizelimit)}); - unless ($addtarget->execute($raid->{id},$1)){ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - } - my $groups = $DBH->prepare('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(?,?)}); - $groups->execute(); - while (my $group = $groups->fetchrow_hashref){ - my $query; - next unless defined param $group->{gid}; - if (param($group->{gid}) eq 'remove'){ - $query = $delgroup; - }elsif(param($group->{gid}) eq 'add'){ - $query = $addgroup; - } - if ($query){ - unless ($query->execute($raid->{id},$group->{gid})){ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - } - } - unless ($DBH->commit){ - $error .= "

Something went wrong: ".$DBH->errstr."

"; - } - }elsif (param('cmd') eq 'targets'){ - $DBH->begin_work; - my $comment = $DBH->prepare(q{UPDATE raid_targets SET comment = ? WHERE id = ?}); - my $unclaim = $DBH->prepare(q{DELETE FROM raid_claims WHERE target = ? AND wave = ?}); - my $block = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave) VALUES(?,-2,?)}); - my $claim = $DBH->prepare(q{INSERT INTO raid_claims (target,uid,wave) - VALUES($1,(SELECT uid FROM users WHERE username ILIKE $3),$2) - }); - my $unblock = $DBH->prepare(q{DELETE FROM raid_claims WHERE target = ? AND wave = ? AND uid = -2}); - my $remove = $DBH->prepare(q{DELETE FROM raid_targets WHERE raid = ? AND id = ?}); - for $_ (param()){ - if (/^comment:(\d+)$/){ - $comment->execute(escapeHTML(param($_)),$1) or $error .= p($DBH->errstr); - }elsif(/^unclaim:(\d+):(\d+)$/){ - $unclaim->execute($1,$2) or $error .= p($DBH->errstr); - log_message $ND::UID,"BC unclaimed target $1 wave $2."; - }elsif(/^block:(\d+):(\d+)$/){ - $block->execute($1,$2) or $error .= p($DBH->errstr); - }elsif(/^claim:(\d+):(\d+)$/){ - my $target = $1; - my $wave = $2; - my @claims = split /[, ]+/, param($_); - $unblock->execute($target,$wave) if @claims; - for (@claims){ - $claim->execute($target,$wave,$_) or warn $DBH->errstr; - } - }elsif(/^remove:(\d+)$/){ - $remove->execute($raid->{id},$1) or $error .= p($DBH->errstr); - } - } - $DBH->commit or $error .= p($DBH->errstr); - } - } - - 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}); - $groups->execute($raid ? $raid->{id} : undef); - - my @addgroups; - my @remgroups; - while (my $group = $groups->fetchrow_hashref){ - if ($group->{raid}){ - push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}}; - }else{ - push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}}; - } - } - $BODY->param(RemoveGroups => \@remgroups); - $BODY->param(AddGroups => \@addgroups); - - - if ($raid){ - - $BODY->param(Raid => $raid->{id}); - if($raid->{open}){ - $BODY->param(Open => 'Close'); - }else{ - $BODY->param(Open => 'Open'); - } - if($raid->{released_coords}){ - $BODY->param(ShowCoords => 'hidecoords'); - $BODY->param(ShowCoordsName => 'Hide'); - }else{ - $BODY->param(ShowCoords => 'showcoords'); - $BODY->param(ShowCoordsName => 'Show'); - } - $BODY->param(Waves => $raid->{waves}); - $BODY->param(LandingTick => $raid->{tick}); - $BODY->param(Message => $raid->{message}); - - my $order = "p.x,p.y,p.z"; - if (param('order') && param('order') =~ /^(score|size|value|xp|race)$/){ - $order = "$1 DESC"; - } - - my $targetquery = $DBH->prepare(qq{SELECT r.id,coords(x,y,z),comment,size,score,value,race,planet_status AS planetstatus,relationship,comment,r.planet - FROM current_planet_stats p JOIN raid_targets r ON p.id = r.planet - WHERE r.raid = ? - ORDER BY $order}); - my $claims = $DBH->prepare(qq{ SELECT username,launched FROM raid_claims - NATURAL JOIN users WHERE target = ? AND wave = ?}); - $targetquery->execute($raid->{id}) or $error .= $DBH->errstr; - my @targets; - while (my $target = $targetquery->fetchrow_hashref){ - my @waves; - for my $i (1 .. $raid->{waves}){ - $claims->execute($target->{id},$i); - my $claimers; - if ($claims->rows != 0){ - my $owner = 0; - my @claimers; - while (my $claim = $claims->fetchrow_hashref){ - $claim->{username} .= '*' if ($claim->{launched}); - push @claimers,$claim->{username}; - } - $claimers = join '/', @claimers; - } - push @waves,{Wave => $i, Claimers => $claimers}; - } - $target->{waves} = \@waves; - - my $scans = $DBH->prepare(q{SELECT DISTINCT ON (type) scan_id,type, tick FROM scans - WHERE planet = ? AND type ~ 'Unit|Planet|Advanced Unit|.* Analysis' AND tick + 24 > tick() - ORDER BY type ,tick DESC}); - $scans->execute($target->{planet}); - delete $target->{planet}; - - my @scans; - while (my $scan = $scans->fetchrow_hashref){ - push @scans,$scan; - } - $target->{Scans} = \@scans; - push @targets,$target; - } - $BODY->param(Targets => \@targets); - }else{ - $BODY->param(Waves => 3); - my @time = gmtime; - $BODY->param(LandingTick => $self->{TICK} + 24 - $time[2] + 12); - } - $BODY->param(Error => $error); - return $BODY; -} - -1; diff --git a/database/raids.sql b/database/raids.sql index 3df4bd1..57de47f 100644 --- a/database/raids.sql +++ b/database/raids.sql @@ -1,4 +1,6 @@ -INSERT INTO forum_boards (fcid,fbid,board) VALUES(9,-5,'Raid logs'); +INSERT INTO forum_boards (fcid,fbid,board) VALUES(7,-5,'Raid logs'); +INSERT INTO forum_access (fbid,gid) VALUES(-5,1); +INSERT INTO forum_access (fbid,gid) VALUES(-5,3); ALTER TABLE raids ADD COLUMN ftid INTEGER; diff --git a/lib/NDWeb.pm b/lib/NDWeb.pm index df1da17..135bcf6 100644 --- a/lib/NDWeb.pm +++ b/lib/NDWeb.pm @@ -77,6 +77,11 @@ __PACKAGE__->deny_access_unless('/calls/list',[qw/calls_list/]); __PACKAGE__->deny_access_unless('/calls/postcallcomment',[qw/calls_edit/]); __PACKAGE__->deny_access_unless('/calls/postcallupdate',[qw/calls_edit/]); __PACKAGE__->deny_access_unless('/calls/postattackerupdate',[qw/calls_edit/]); +__PACKAGE__->deny_access_unless('/raids',[qw/raids_edit/]); +__PACKAGE__->allow_access_if('/raids/index',1); +__PACKAGE__->allow_access_if('/raids/view',1); +__PACKAGE__->allow_access_if('/raids/findRaid',1); +__PACKAGE__->allow_access_if('/raids/log',1); =head1 NAME diff --git a/lib/NDWeb/Controller/Raids.pm b/lib/NDWeb/Controller/Raids.pm index 13a2956..df29577 100644 --- a/lib/NDWeb/Controller/Raids.pm +++ b/lib/NDWeb/Controller/Raids.pm @@ -220,6 +220,297 @@ sub view : Local { $c->stash(targets => \@targets); } +sub edit : Local { + my ($self, $c, $raid, $order) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{SELECT id,tick,waves,message,released_coords,open,ftid + FROM raids WHERE id = ? + }); + $raid = $dbh->selectrow_hashref($query,undef,$raid); + + $c->stash(raid => $raid); + + $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}); + $groups->execute($raid ? $raid->{id} : undef); + + my @addgroups; + my @remgroups; + while (my $group = $groups->fetchrow_hashref){ + if ($group->{raid}){ + push @remgroups,$group; + }else{ + push @addgroups,$group; + } + } + $c->stash(removegroups => \@remgroups); + $c->stash(addgroups => \@addgroups); + + if ($order =~ /^(score|size|value|xp)rank$/){ + $order .= " ASC"; + }elsif ($order eq 'race'){ + $order .= ' ASC'; + }else { + $order .= 'p.x,p.y,p.z'; + } + + my $targetquery = $dbh->prepare(qq{SELECT r.id,coords(x,y,z),comment,size,score,value,race,planet_status AS planetstatus,relationship,comment,r.planet, s.scans + FROM raid_targets r + JOIN current_planet_stats p ON p.id = r.planet + LEFT OUTER JOIN ( SELECT planet, array_accum(s::text) AS scans + FROM ( SELECT DISTINCT ON (planet,type) planet,scan_id,type, tick + FROM scans + WHERE tick > tick() - 24 + ORDER BY planet,type ,tick DESC + ) s + GROUP BY planet + ) s ON s.planet = r.planet + WHERE r.raid = ? + ORDER BY $order + }); + my $claims = $dbh->prepare(q{ SELECT username,launched FROM raid_claims + NATURAL JOIN users WHERE target = ? AND wave = ?}); + + $targetquery->execute($raid->{id}); + my @targets; + while (my $target = $targetquery->fetchrow_hashref){ + my @waves; + for my $i (1 .. $raid->{waves}){ + $claims->execute($target->{id},$i); + my $claimers; + if ($claims->rows != 0){ + my $owner = 0; + my @claimers; + while (my $claim = $claims->fetchrow_hashref){ + $claim->{username} .= '*' if ($claim->{launched}); + push @claimers,$claim->{username}; + } + $claimers = join '/', @claimers; + } + push @waves,{wave => $i, claimers => $claimers}; + } + $target->{waves} = \@waves; + + $target->{scans} = array_expand $target->{scans}; + push @targets,$target; + } + $c->stash(targets => \@targets); + + $c->forward('/listAlliances'); +} + +sub postraidupdate : Local { + my ($self, $c, $raid) = @_; + my $dbh = $c->model; + + $dbh->begin_work; + $dbh->do(q{UPDATE raids SET message = ?, tick = ?, waves = ? WHERE id = ?} + ,undef,html_escape $c->req->param('message') + ,$c->req->param('tick'),$c->req->param('waves') + ,$raid); + + $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(?,?)}); + + $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})"]); + } + } + $dbh->commit; + + $c->res->redirect($c->uri_for('edit',$raid)); +} + +sub postaddtargets : Local { + my ($self, $c, $raid) = @_; + my $dbh = $c->model; + + my $sizelimit = $c->req->param('sizelimit'); + $sizelimit = -1 unless $sizelimit; + + my $targets = $c->req->param('targets'); + my $addtarget = $dbh->prepare(qq{INSERT INTO raid_targets(raid,planet) ( + SELECT ?, id FROM current_planet_stats p + WHERE x = ? AND y = ? AND COALESCE(z = ?,TRUE) + AND p.size > ? + )}); + my @errors; + while ($targets =~ m/(\d+):(\d+)(?::(\d+))?/g){ + my ($x,$y,$z) = ($1, $2, $3); + eval { + $addtarget->execute($raid,$1,$2,$3,$sizelimit); + }; + + if ($@ =~ /duplicate key value violates unique constraint "raid_targets_raid_key"/){ + if ($z){ + push @errors, "Planet already exists: $x:$y:$z"; + }else{ + push @errors, "A planet from $x:$y already exists in the raid," + ." either remove it or add the planets separately."; + } + }else { + push @errors, $@; + } + } + if ($c->req->param('alliance') =~ /^(\d+)$/ && $1 != 1){ + my $addtarget = $dbh->prepare(qq{INSERT INTO raid_targets(raid,planet) ( + SELECT ?,id FROM current_planet_stats p WHERE alliance_id = ? AND p.size > ?) + }); + eval { + $addtarget->execute($raid,$1,$sizelimit); + $c->forward('log',[$raid,"BC adding alliance $1 to raid"]); + }; + if ($@ =~ /duplicate key value violates unique constraint "raid_targets_raid_key"/){ + push @errors, "A planet from this alliance has already been added to the raid," + ." either remove it or add the planets separately."; + }else { + push @errors, $@; + } + } + + $c->flash(errors => \@errors) if @errors; + $c->res->redirect($c->uri_for('edit',$raid)); +} + +sub posttargetupdates : Local { + my ($self, $c, $raid) = @_; + my $dbh = $c->model; + + my @errors; + my $comment = $dbh->prepare(q{UPDATE raid_targets SET comment = ? WHERE id = ?}); + my $unclaim = $dbh->prepare(q{DELETE FROM raid_claims WHERE target = ? AND wave = ?}); + my $block = $dbh->prepare(q{INSERT INTO raid_claims (target,uid,wave) VALUES(?,-2,?)}); + my $claim = $dbh->prepare(q{INSERT INTO raid_claims (target,uid,wave) + VALUES($1,(SELECT uid FROM users WHERE username ILIKE $3),$2) + }); + my $unblock = $dbh->prepare(q{DELETE FROM raid_claims + WHERE target = ? AND wave = ? AND uid = -2 + }); + my $remove = $dbh->prepare(q{DELETE FROM raid_targets WHERE raid = ? AND id = ?}); + for $_ ($c->req->param()){ + if (/^comment:(\d+)$/){ + $comment->execute(html_escape $c->req->param($_),$1); + }elsif(/^unclaim:(\d+):(\d+)$/){ + $unclaim->execute($1,$2); + $c->forward('log',[$raid,"BC unclaimed target $1 wave $2."]); + }elsif(/^block:(\d+):(\d+)$/){ + $block->execute($1,$2); + $c->forward('log',[$raid,"BC blocked target $1 wave $2."]); + }elsif(/^claim:(\d+):(\d+)$/){ + my $target = $1; + my $wave = $2; + my @claims = split /[, ]+/, $c->req->param($_); + for (@claims){ + eval { + $claim->execute($target,$wave,$_); + }; + if ($@ =~ /null value in column "uid"/){ + push @errors, "Could not find user: " . html_escape $_; + }elsif ($@ =~ /more than one row returned by a subquery/){ + push @errors, "This matched several users, please refine: " . html_escape $_; + }else { + push @errors, $@; + } + } + if(@claims){ + $unblock->execute($target,$wave); + $c->forward('log',[$raid,"BC claimed target $1 wave $2 for @claims."]); + } + }elsif(/^remove:(\d+)$/){ + $remove->execute($raid,$1); + $c->forward('log',[$raid,"BC removed target $1"]); + } + } + + $c->flash(errors => \@errors) if @errors; + $c->res->redirect($c->uri_for('edit',$raid)); +} + +sub open : Local { + my ($self, $c, $raid) = @_; + + $c->model->do(q{UPDATE raids SET open = TRUE, removed = FALSE WHERE id = ?} + ,undef,$raid); + $c->forward('log',[$raid, "BC opened raid"]); + + $c->res->redirect($c->req->referer); +} + +sub close : Local { + my ($self, $c, $raid) = @_; + + $c->model->do(q{UPDATE raids SET open = FALSE WHERE id = ?} + ,undef,$raid); + $c->forward('log',[$raid, "BC closed raid"]); + + $c->res->redirect($c->req->referer); +} + +sub remove : Local { + my ($self, $c, $raid) = @_; + + $c->model->do(q{UPDATE raids SET open = FALSE, removed = TRUE WHERE id = ?} + ,undef,$raid); + $c->forward('log',[$raid, "BC removed raid"]); + + $c->res->redirect($c->req->referer); +} + +sub showcoords : Local { + my ($self, $c, $raid) = @_; + + $c->model->do(q{UPDATE raids SET released_coords = TRUE WHERE id = ?} + ,undef,$raid); + $c->forward('log',[$raid, "BC released coords"]); + + $c->res->redirect($c->req->referer); +} + +sub hidecoords : Local { + my ($self, $c, $raid) = @_; + + $c->model->do(q{UPDATE raids SET released_coords = FALSE WHERE id = ?} + ,undef,$raid); + $c->forward('log',[$raid, "BC hid coords"]); + + $c->res->redirect($c->req->referer); +} + +sub create : Local { + my ($self, $c) = @_; + $c->stash(waves => 3); + my @time = gmtime; + $c->stash(landingtick => $c->stash->{TICK} + 24 - $time[2] + 12); +} + +sub postcreate : Local { + my ($self, $c) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{INSERT INTO raids (tick,waves,message) VALUES(?,?,?) RETURNING (id)}); + $query->execute($c->req->param('tick'),$c->req->param('waves') + ,html_escape $c->req->param('message')); + my $raid = $query->fetchrow_array; + $c->forward('log',[$raid,"Created raid landing at tick: ".$c->req->param('tick')]); + $c->res->redirect($c->uri_for('edit',$raid)); +} + sub log : Private { my ($self, $c, $raid, $message) = @_; my $dbh = $c->model; diff --git a/lib/NDWeb/Controller/Root.pm b/lib/NDWeb/Controller/Root.pm index 16f0e8c..9bf0dd5 100644 --- a/lib/NDWeb/Controller/Root.pm +++ b/lib/NDWeb/Controller/Root.pm @@ -89,6 +89,18 @@ ORDER BY r.tick+c.wave,x,y,z}); $c->stash(claimedtargets => \@targets); } +sub listAlliances : Private { + my ($self, $c) = @_; + my @alliances; + push @alliances,{id => -1, name => ''}; + my $query = $c->model->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)}); + $query->execute; + while (my $ally = $query->fetchrow_hashref){ + push @alliances,$ally; + } + $c->stash(alliances => \@alliances); +} + sub auto : Private { my ($self, $c) = @_; my $dbh = $c ->model; diff --git a/lib/NDWeb/Include.pm b/lib/NDWeb/Include.pm index 4b94597..5bea31b 100644 --- a/lib/NDWeb/Include.pm +++ b/lib/NDWeb/Include.pm @@ -27,8 +27,8 @@ use CGI qw/:standard/; our @ISA = qw/Exporter/; our @EXPORT = qw/parseMarkup min max - alliances intelquery html_escape - comma_value/; + intelquery html_escape + comma_value array_expand/; sub html_escape($) { return CGI::escapeHTML @_; @@ -71,20 +71,6 @@ sub max { return ($x < $y ? $y : $x); } - -sub alliances { - my ($alliance) = @_; - my @alliances; - $alliance = -1 unless defined $alliance; - push @alliances,{Id => -1, Name => '', Selected => not $alliance}; - my $query = $ND::DBH->prepare(q{SELECT id,name FROM alliances ORDER BY LOWER(name)}); - $query->execute; - while (my $ally = $query->fetchrow_hashref){ - push @alliances,{Id => $ally->{id}, Name => $ally->{name}, Selected => $alliance == $ally->{id}}; - } - return @alliances; -} - sub intelquery { my ($columns,$where) = @_; return qq{ @@ -97,6 +83,19 @@ GROUP BY i.tick,i.mission,t.x,t.y,t.z,o.x,o.y,o.z,i.amount,i.ingal,u.username,t. ORDER BY i.tick DESC, i.mission}; } +sub array_expand ($) { + my ($array) = @_; + + my @arrays; + for my $string (@{$array}){ + $string =~ s/^\((.*)\)$/$1/; + $string =~ s/"//g; + my @array = split /,/, $string; + push @arrays,\@array; + } + return \@arrays; +} + 1; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index 733ac21..3c1a250 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -65,7 +65,7 @@ [% IF c.check_user_roles("bc_menu") %]

BC menu

[% END %] [% IF c.check_user_roles("dc_menu") %] diff --git a/root/src/raids/create.tt2 b/root/src/raids/create.tt2 new file mode 100644 index 0000000..f1c78ed --- /dev/null +++ b/root/src/raids/create.tt2 @@ -0,0 +1,12 @@ +[% META title = 'Create raid' %] +
+
Create raid +
+

Landing tick:

+

Number of waves:

+

+
+

Raid message here

+ +
+
diff --git a/root/src/raids/edit.tt2 b/root/src/raids/edit.tt2 new file mode 100644 index 0000000..e332c91 --- /dev/null +++ b/root/src/raids/edit.tt2 @@ -0,0 +1,123 @@ +[% META title = 'Edit raid' %] +[% FOR e IN errors %] +

[% e %]

+[% END %] +
+
+
Edit raid +
+

[% raid.open ? 'Close' : 'Open'%] raid.

+

[% raid.released_coords ? 'Hide' : 'Show' %] coords.

+

Remove raid

+

Landing tick:

+

Number of waves:

+ [% IF removegroups.size > 0 %] +

The following groups has access to the raid

+ + + [% FOR g IN removegroups %] + + + [% END %] +
GroupRemove
[% g.groupname %]
+ [% END %] + [% IF addgroups.size > 0 %] +

These does not have access to the raid

+ + + [% FOR g IN addgroups %] + + + [% END %] +
GroupAdd
[% g.groupname %]
+ [% END %] +
+

Raid message here

+ +

+
+
+
+
+
+
Add targets +

List all target coords here

+ +

Add all coords from: +
Size limit (Filters out smaller planets): + +
+

+
+
+
+
 
+

Sort by: + Coords + Race + Size + Score + Value + XP +

+
+
+[% FOR t IN targets %] +
Target: #[% t.id %] [% t.coords %] +
+

Remove target:

+
    +
  • Size: [% t.size %]
  • +
  • Score: [% t.score %]
  • +
  • Value: [% t.value %]
  • +
  • Race: [% t.race %]
  • +
+ + + + + + +
Planet statusAlliance relationship
[% t.planet_status %][% t.relationship %]
+
+
+

Comment:
+ +

+ [% t.planetscan %] +
+ + + [% FOR s IN t.scans %] + + + + + [% END %] +
TickScan
[% s.3 %][% s.2 %]
+
 
+ + [% FOR w IN t.waves %] + + + + + [% END %] +
+ [% IF w.claimers %] + Unclaim wave [% w.wave %] ([% w.claimers %]): + [% ELSE %] + Block wave [% w.wave %]: + [% END %] +
+
+[% END %] +

+
+
diff --git a/templates/editRaid.tmpl b/templates/editRaid.tmpl deleted file mode 100644 index 931ca51..0000000 --- a/templates/editRaid.tmpl +++ /dev/null @@ -1,121 +0,0 @@ - -
-
Edit raidNew raid - - -
- - - -

raid.

-

coords.

-

Remove raid

- - -
-

Landing tick:

-

Number of waves:

- -

The following groups has access to the raid

- - - - - -
GroupRemove
-
- -

These does not have access to the raid

- - - - - -
GroupAdd
-
-
-
-

Raid message here

- -
-
-

List all target coords here

- -
-
 
- -
-
- -

Sort by: - Coords - Race - Size - Score - Value - XP -

-
- - - - -
Target: # -
-

Remove target:

-
    -
  • Size:
  • -
  • Score:
  • -
  • Value:
  • -
  • Race:
  • -
- - - - - - -
Planet statusAlliance relationship
- - - - - - - -
- - Unclaim wave (): - - Block wave : - -
-
-
-

Comment:
- -

- -
- - - - - - - - -
TickScan
-
-
-
-
-