]> ruin.nu Git - ndwebbie.git/blobdiff - intel.pl
order by last post
[ndwebbie.git] / intel.pl
index c1beff473da2c6281a714af4d1fe9e2d4d9ed25d..e5ce1e071fe24b7eb51ae1fde9987bce1c4ebef4 100644 (file)
--- a/intel.pl
+++ b/intel.pl
 #**************************************************************************/
 
 use strict;
-use POSIX;
+use warnings FATAL => 'all';
+use ND::Web::Forum;
+use ND::Include;
+
 our $BODY;
 our $DBH;
-our $LOG;
+our $ERROR;
 my $error;
 
 $ND::TEMPLATE->param(TITLE => 'Intel');
@@ -29,20 +32,28 @@ $ND::TEMPLATE->param(TITLE => 'Intel');
 die "You don't have access" unless isIntel() || isHC();
 
 my $planet;
-if (param('coords') =~ /^(\d+)(?: |:)(\d+)(?: |:)(\d+)$/){
-       my $query = $DBH->prepare(q{SELECT x,y,z,coords(x,y,z),id, nick, alliance,alliance_id, planet_status,channel FROM current_planet_stats
+if (defined param('coords') && param('coords') =~ /^(\d+)(?: |:)(\d+)(?: |:)(\d+)$/){
+       my $query = $DBH->prepare(q{SELECT x,y,z,coords(x,y,z),id, nick, alliance,alliance_id, planet_status,channel,ftid FROM current_planet_stats
 WHERE  x = ? AND y = ? AND z = ?});
-       $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3);
+       $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3) or $ND::ERROR .= p $DBH->errstr;
 }
 
 my $showticks = 'AND (i.tick - i.eta) > (tick() - 48)';
-if (param('show') eq 'all'){
-       $showticks = '';
-}elsif (param('show') =~ /^(\d+)$/){
-       $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+if (defined param('show')){
+       if (param('show') eq 'all'){
+               $showticks = '';
+       }elsif (param('show') =~ /^(\d+)$/){
+               $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
+       }
 }
 
-if (param('cmd') eq 'coords'){
+my $thread;
+if (defined $planet){
+       $thread = $DBH->selectrow_hashref(q{SELECT ftid AS id, subject FROM forum_threads
+               where ftid = $1},undef,$planet->{ftid}) or $ERROR .= p($DBH->errstr);
+}
+
+if (defined param('cmd') && param('cmd') eq 'coords'){
        my $coords = param('coords');
        $DBH->do(q{CREATE TEMPORARY TABLE coordlist (
        x integer NOT NULL,
@@ -64,14 +75,18 @@ ORDER BY alliance, p.x, p.y, p.z});
        }
        $BODY->param(CoordList => \@planets);
 }
+if (defined $thread and defined param('cmd') and param('cmd') eq 'forumpost'){
+       addForumPost($DBH,$thread,$ND::UID,param('message'));
+}
 
-if ($planet){
+if ($planet && defined param('cmd')){
        if (param('cmd') eq 'change'){
                $DBH->begin_work;
                if (param('cnick')){
                        my $value = escapeHTML(param('nick'));
                        if ($DBH->do(q{UPDATE planets SET nick = ? WHERE id =?}
                                        ,undef,$value,$planet->{id})){
+                               intel_log $ND::UID,$planet->{id},"Set nick to: $value";
                                $planet->{nick} = $value;
                        }else{
                                $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
@@ -81,6 +96,7 @@ if ($planet){
                        my $value = escapeHTML(param('channel'));
                        if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?}
                                        ,undef,$value,$planet->{id})){
+                               intel_log $ND::UID,$planet->{id},"Set channel to: $value";
                                $planet->{channel} = $value;
                        }else{
                                $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
@@ -90,6 +106,7 @@ if ($planet){
                        my $value = escapeHTML(param('status'));
                        if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?}
                                        ,undef,$value,$planet->{id})){
+                               intel_log $ND::UID,$planet->{id},"Set planet_status to: $value";
                                $planet->{planet_status} = $value;
                        }else{
                                $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
@@ -98,6 +115,7 @@ if ($planet){
                if (param('calliance')){
                        if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?}
                                        ,undef,param('alliance'),$planet->{id})){
+                               intel_log $ND::UID,$planet->{id},"Set alliance_id to: ".param('alliance');
                                $planet->{alliance_id} = param('alliance');
                        }else{
                                $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
@@ -126,16 +144,18 @@ if ($planet){
        $BODY->param(Channel => $planet->{channel});
        my @status;
        for my $status ("&nbsp;","Friendly", "NAP", "Hostile"){
-               push @status,{Status => $status, Selected => $status eq $planet->{planet_status}}
+               push @status,{Status => $status, Selected => defined $planet->{planet_status} && $status eq $planet->{planet_status}}
        }
        $BODY->param(PlanetStatus => \@status);
        my @alliances = alliances($planet->{alliance_id});
        $BODY->param(Alliances => \@alliances);
 
+       $BODY->param(Thread => viewForumThread $thread);
+
        my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin',"t.id = ? $showticks"));
        $query->execute($planet->{id}) or $error .= $DBH->errstr;
        my @intellists;
-       my @intel;
+       my @incomings;
        my $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
@@ -143,27 +163,27 @@ if ($planet){
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
-               $intel->{ODD} = $i % 2;
-               push @intel,$intel;
                $i++;
+               $intel->{ODD} = $i % 2;
+               push @incomings,$intel;
        }
-       push @intellists,{Message => 'Incoming fleets', Intel => \@intel, Origin => 1};
+       push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
 
-       my $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
+       $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
        $query->execute($planet->{id}) or $error .= $DBH->errstr;
-       my @intel;
-       my $i = 0;
+       my @outgoings;
+       $i = 0;
        while (my $intel = $query->fetchrow_hashref){
                if ($intel->{ingal}){
                        $intel->{missionclass} = 'ingal';
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
-               $intel->{ODD} = $i % 2;
-               push @intel,$intel;
                $i++;
+               $intel->{ODD} = $i % 2;
+               push @outgoings,$intel;
        }
-       push @intellists,{Message => 'Outgoing Fleets', Intel => \@intel, Target => 1};
+       push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
 
        $BODY->param(IntelLIsts => \@intellists);
 
@@ -184,9 +204,9 @@ if ($planet){
                }else{
                        $intel->{missionclass} = $intel->{mission};
                }
+               $i++;
                $intel->{ODD} = $i % 2;
                push @intel,$intel;
-               $i++;
        }
        push @intellists,{Message => q{Intel where alliances doesn't match}, Intel => \@intel, Origin => 1, Target => 1};
        $BODY->param(IntelLIsts => \@intellists);
@@ -200,6 +220,6 @@ while (my $message = $query->fetchrow_hashref){
        $message->{message} = parseMarkup($message->{message});
        push @messages,$message;
 }
-$BODY->param(IntelMessages => \@messages);
+#$BODY->param(IntelMessages => \@messages);
 $BODY->param(Error => $error);
 1;