]> ruin.nu Git - ndwebbie.git/commitdiff
Add support for attack group
authorMichael Andreen <harv@ruin.nu>
Tue, 25 Aug 2009 14:15:56 +0000 (16:15 +0200)
committerMichael Andreen <harv@ruin.nu>
Tue, 25 Aug 2009 14:15:56 +0000 (16:15 +0200)
lib/NDWeb/Controller/Members.pm
root/src/members/index.tt2

index 89997ba64b41202ce2f043cc798aa0b118222ce8..e14cdcc7092d864971703d88d2b11a6b7e4bd427 100644 (file)
@@ -82,6 +82,12 @@ ORDER BY landing_tick DESC
                });
        $announcements->execute($c->user->id);
        $c->stash(announcements => $announcements->fetchall_arrayref({}) );
+
+       my ($attackgroups) = $dbh->selectrow_array(q{
+SELECT array_agg(gid) FROM groupmembers WHERE gid IN ('x','y','z') AND uid = $1
+               }, undef, $c->user->id);
+       $c->stash(attackgroups => $attackgroups);
+
 }
 
 sub posthostupdate : Local {
@@ -94,6 +100,23 @@ sub posthostupdate : Local {
        $c->res->redirect($c->uri_for(''));
 }
 
+sub postattackgroups : Local {
+       my ( $self, $c ) = @_;
+       my $dbh = $c->model;
+
+       my @groups = $c->req->param('class');
+       $dbh->do(q{DELETE FROM groupmembers WHERE gid IN ('x','y','z') AND gid <> ALL($1) AND uid = $2
+               },undef, \@groups, $c->user->id);
+
+       $dbh->do(q{INSERT INTO groupmembers (uid,gid) (
+               SELECT $2, gid FROM unnest($1::text[]) AS gid WHERE gid IN ('x','y','z')
+       EXCEPT
+               SELECT uid,gid FROM groupmembers WHERE uid = $2
+               )},undef, \@groups, $c->user->id);
+
+       $c->res->redirect($c->uri_for(''));
+}
+
 sub postsmsupdate : Local {
        my ( $self, $c ) = @_;
        my $dbh = $c->model;
index 7f1bc7df92858f2020c13c02bc69f24fe6d698f8..d9b7559098992db1d141b256079fb313e6774154 100644 (file)
@@ -83,7 +83,7 @@
        <li> Scan points: [% u.scan_points %] </li>
        <li> Humor points: [% u.humor_points %] </li>
        <li> Total points: [% u.total_points %] </li>
-       <li> Member of the following groups: [% groups.join(',') %]</li>
+       <li> Member of the following groups: [% groups.join(', ') %]</li>
        </ul>
 </fieldset>
 
        </p>
 </form>
 </fieldset>
+<fieldset class="forum-post"> <legend>Attack classes</legend>
+<form action="[% c.uri_for('postattackgroups') %]" method="post">
+<p>Pick the classes you use for your attack fleets:</p>
+<p>
+FiCo: <input type="checkbox" name="class" value="x"[% IF attackgroups.grep('x').size > 0 %] checked[%END%]>
+FrDe: <input type="checkbox" name="class" value="y"[% IF attackgroups.grep('y').size > 0 %] checked[%END%]>
+CrBs: <input type="checkbox" name="class" value="z"[% IF attackgroups.grep('z').size > 0 %] checked[%END%]>
+<input type="submit" name="cmd" value="Submit">
+</p>
+</form>
+</fieldset>
 <form action="[% c.uri_for('posthostupdate') %]" method="post">
 <fieldset class="forum-post"> <legend>Hostname</legend>
        <p>Hostname: