]> ruin.nu Git - ndwebbie.git/blobdiff - NDWeb/Pages/Alliances.pm
Converted editRaid page
[ndwebbie.git] / NDWeb / Pages / Alliances.pm
index 311adb3c7b726d41d452a7fdfd67dc4d21ce9154..59106e6262858920223de314a9e93dd14714ce29 100644 (file)
 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
 #**************************************************************************/
 
-package ND::Web::Pages::Alliances;
+package NDWeb::Pages::Alliances;
 use strict;
 use warnings FATAL => 'all';
 use ND::Include;
 use CGI qw/:standard/;
-use ND::Web::Include;
+use NDWeb::Include;
 
-use base qw/ND::Web::XMLPage/;
+use base qw/NDWeb::XMLPage/;
 
-$ND::Web::Page::PAGES{alliances} = __PACKAGE__;
+$NDWeb::Page::PAGES{alliances} = __PACKAGE__;
 
 sub render_body {
        my $self = shift;
        my ($BODY) = @_;
        $self->{TITLE} = 'Alliances';
        my $DBH = $self->{DBH};
-       my $error;
 
        return $self->noAccess unless $self->isHC;
 
@@ -46,12 +45,12 @@ sub render_body {
                $DBH->begin_work;
                if (param('crelationship')){
                        my $value = escapeHTML(param('relationship'));
-                       if ($DBH->do(q{UPDATE alliances SET relationship = NULLIF(?,'') WHERE id =?}
+                       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){
@@ -95,10 +110,7 @@ sub render_body {
                        ORDER BY $order});
                my @members;
                $members->execute($alliance->{id});
-               my $i = 0;
                while (my $member = $members->fetchrow_hashref){
-                       $i++;
-                       $member->{ODD} = $i % 2;
                        push @members,$member;
                }
                $BODY->param(Members => \@members);
@@ -107,19 +119,17 @@ sub render_body {
                                AND (i.mission = 'Defend' OR i.mission = 'AllyDef')
                                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)
+                               AND NOT (i.back IS NOT NULL AND i.back = i.tick + 4)
                                }));
-               $query->execute($alliance->{id}) or $error .= $DBH->errstr;
+               $query->execute($alliance->{id}) or warn $DBH->errstr;
 
                my @intel;
-               $i = 0;
                while (my $intel = $query->fetchrow_hashref){
                        if ($intel->{ingal}){
                                $intel->{missionclass} = 'ingal';
                        }else{
                                $intel->{missionclass} = $intel->{mission};
                        }
-                       $i++;
-                       $intel->{ODD} = $i % 2;
                        push @intel,$intel;
                }
                $BODY->param(Intel => \@intel);
@@ -139,19 +149,15 @@ 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;
-               my $i = 0;
                while (my $alliance = $query->fetchrow_hashref){
                        next unless (defined $alliance->{score} || $alliance->{kscore} > 0);
-                       $i++;
-                       $alliance->{ODD} = $i % 2;
                        push @alliances, $alliance;
                }
                $BODY->param(Alliances => \@alliances);
        }
-       $BODY->param(Error => $error);
        return $BODY;
 }
 1;