]> ruin.nu Git - ndwebbie.git/commitdiff
Possible to remove all planets from an alliance, plus some cleanup
authorMichael Andreen <harv@ruin.nu>
Sat, 12 Apr 2008 12:48:13 +0000 (14:48 +0200)
committerMichael Andreen <harv@ruin.nu>
Sat, 12 Apr 2008 12:48:13 +0000 (14:48 +0200)
NDWeb/Pages/Alliances.pm
templates/alliances.tmpl

index 9a4ec6196b3553734f8d6f039489fc2074d6f482..7fc022494796a3ea14da99c1597fbcc5b1998a3a 100644 (file)
@@ -33,7 +33,6 @@ sub render_body {
        my ($BODY) = @_;
        $self->{TITLE} = 'Alliances';
        my $DBH = $self->{DBH};
-       my $error;
 
        return $self->noAccess unless $self->isHC;
 
@@ -49,9 +48,9 @@ sub render_body {
                        if ($DBH->do(q{UPDATE alliances SET relationship = ? WHERE id =?}
                                        ,undef,$value,$alliance->{id})){
                                $alliance->{relationship} = $value;
-                               log_message $ND::UID,"HC set alliance: $alliance->{id} relationship: $value";
+                               log_message $ND::UID,"HC set alliance: $alliance->{id} ($alliance->{name}) relationship: $value";
                        }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               warn $DBH->errstr;
                        }
                }
                my $coords = param('coords');
@@ -65,13 +64,29 @@ sub render_body {
                        if ($addplanet->execute($id,$alliance->{id},$4)){
                                my $nick = '';
                                $nick = "(nick $4)" if defined $4;
-                               $error .= "<p> Added planet $1:$2:$3 $nick to this alliance</p>";
+                               warn "Added planet $1:$2:$3 $nick to this alliance\n";
                                intel_log $ND::UID,$id,"HC Added planet $1:$2:$3 $nick to alliance: $alliance->{id} ($alliance->{name})";
                        }else{
-                               $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+                               warn $DBH->errstr;
                        }
                }
-               $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
+               $DBH->commit or warn $DBH->errstr;
+       }elsif ($alliance && defined param('cmd') && param ('cmd') eq 'remove_all'){
+               $DBH->begin_work;
+               my ($coords) = $DBH->selectrow_array(q{SELECT CONCAT(coords(x,y,z) || ' ') 
+                               FROM current_planet_stats where alliance_id = $1
+                       },undef,$alliance->{id});
+               my $removeplanets = $DBH->prepare(q{
+                       UPDATE planets SET alliance_id = NULL
+                       WHERE alliance_id = $1;
+               }) or warn $DBH->errstr;
+               if ($removeplanets->execute($alliance->{id})){
+                       log_message $ND::UID, "HC cleaned alliance: $alliance->{id} ($alliance->{name})\n\n$coords";
+                       $DBH->commit or warn $DBH->errstr;
+               }else{
+                       warn $DBH->errstr;
+                       $DBH->rollback;
+               }
        }
 
        if ($alliance){
@@ -105,7 +120,7 @@ sub render_body {
                                AND ((( t.alliance_id != o.alliance_id OR t.alliance_id IS NULL OR o.alliance_id IS NULL)))
                                AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
                                }));
-               $query->execute($alliance->{id}) or $error .= $DBH->errstr;
+               $query->execute($alliance->{id}) or warn $DBH->errstr;
 
                my @intel;
                while (my $intel = $query->fetchrow_hashref){
@@ -133,8 +148,8 @@ sub render_body {
                        LEFT OUTER JOIN current_planet_stats p ON p.alliance_id = a.id
                        GROUP BY a.id,a.name,s.score,s.size,s.members
                        ORDER BY $order
-                       })or $error .= $DBH->errstr;
-               $query->execute or $error .= $DBH->errstr;
+                       })or warn $DBH->errstr;
+               $query->execute or warn $DBH->errstr;
                my @alliances;
                while (my $alliance = $query->fetchrow_hashref){
                        next unless (defined $alliance->{score} || $alliance->{kscore} > 0);
@@ -142,7 +157,6 @@ sub render_body {
                }
                $BODY->param(Alliances => \@alliances);
        }
-       $BODY->param(Error => $error);
        return $BODY;
 }
 1;
index e10127ae151bcbc27375f3691f3cab965c44c287..e009fcfd976e8a4120974612c5fdb3f4e1b3a389 100644 (file)
@@ -1,10 +1,9 @@
-<TMPL_VAR NAME=Error>
 <TMPL_IF Alliance>
-<form action="<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend>Alliances: </legend>
+<fieldset> <legend>Alliances: </legend><form action="<TMPL_VAR NAME=PAGE>" method="post">
+<div class="leftinfo">
        <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
        <input type="hidden" name="cmd" value="change"/>
        <input type="hidden" name="alliance" value="<TMPL_VAR NAME=Id>"/>
-<div class="leftinfo">
        <p>Alliance: <TMPL_VAR NAME=Alliance></p>
        <p>Relationship: <select name="relationship">
                <TMPL_LOOP Relationships>
                </TMPL_LOOP>
                </select>
                <input type="checkbox" name="crelationship"/></p>
-</div>
 
-<div class="leftinfo">
        <p>Paste a list of coords that you want to add to this alliance</p>
        <textarea rows="10" cols="40" name="coords"></textarea>
-</div>
-<div class="clear">&nbsp;</div>
        <p class="claimlinks"><input type="submit" value="Submit"/></p>
+</div>
+</form>
+<div class="leftinfo">
+<form action="<TMPL_VAR NAME=PAGE>" method="post"><fieldset> <legend></legend>
+       <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
+       <input type="hidden" name="cmd" value="remove_all"/>
+       <input type="hidden" name="alliance" value="<TMPL_VAR NAME=Id>"/>
+       <p>Yes, remove all planets <input type="checkbox" name="crelationship"/></p>
+       <input type="submit" value="Remove All Planets"/>
 </fieldset></form>
+</div>
+</fieldset>
 <div class="leftinfo">
 <img class="graph" src="/graph/alliance/<TMPL_VAR NAME=Id>" alt="Alliance size and score vs members" height="300" width="500"/>
 <img class="graph" src="/graph/allianceavg/<TMPL_VAR NAME=Id>" alt="Avg alliance size and score vs members" height="300" width="500"/>