--- /dev/null
+#**************************************************************************
+# Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
+# *
+# 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. *
+#**************************************************************************/
+
+use strict;
+use POSIX;
+our $BODY;
+our $DBH;
+our $LOG;
+
+$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
+WHERE x = ? AND y = ? AND z = ?});
+ $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3);
+}
+
+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 ($planet){
+ 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})){
+ $planet->{nick} = $value;
+ }else{
+ print "<p> Something went wrong: ".$DBH->errstr."</p>";
+ }
+ }
+ if (param('cchannel')){
+ my $value = escapeHTML(param('channel'));
+ if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?}
+ ,undef,$value,$planet->{id})){
+ $planet->{channel} = $value;
+ }else{
+ print "<p> Something went wrong: ".$DBH->errstr."</p>";
+ }
+ }
+ if (param('cstatus')){
+ my $value = escapeHTML(param('status'));
+ if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?}
+ ,undef,$value,$planet->{id})){
+ $planet->{planet_status} = $value;
+ }else{
+ print "<p> Something went wrong: ".$DBH->errstr."</p>";
+ }
+ }
+ if (param('calliance')){
+ if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?}
+ ,undef,param('alliance'),$planet->{id})){
+ $planet->{alliance_id} = param('alliance');
+ }else{
+ print "<p> Something went wrong: ".$DBH->errstr."</p>";
+ }
+ }
+ $DBH->commit or print "<p> Something went wrong: ".$DBH->errstr."</p>";
+ }
+}
+
+if (param('coords')){
+ my $channel = param('coords');
+ $channel = $planet->{channel} if ($planet);
+ my $findchannel = $DBH->prepare('SELECT coords(x,y,z),alliance,nick,channel FROM current_planet_stats WHERE channel ILIKE ? ');
+ $findchannel->execute($channel);
+ my @channelusers;
+ while (my $user = $findchannel->fetchrow_hashref){
+ push @channelusers,$user;
+ }
+ $BODY->param(ChannelUsers => \@channelusers);
+}
+
+if ($planet){
+ $BODY->param(Coords => $planet->{coords});
+ $BODY->param(Planet => $planet->{id});
+ $BODY->param(Nick => $planet->{nick});
+ $BODY->param(Channel => $planet->{channel});
+ my @status;
+ for my $status (" ","Friendly", "NAP", "Hostile"){
+ push @status,{Status => $status, Selected => $status eq $planet->{planet_status}}
+ }
+ $BODY->param(PlanetStatus => \@status);
+ my @alliances = alliances($planet->{alliance_id});
+ $BODY->param(Alliances => \@alliances);
+
+ 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 print $DBH->errstr;
+ my @intellists;
+ my @intel;
+ while (my $intel = $query->fetchrow_hashref){
+ if ($intel->{ingal}){
+ $intel->{missionclass} = 'ingal';
+ }else{
+ $intel->{missionclass} = $intel->{mission};
+ }
+ push @intel,$intel;
+ }
+ push @intellists,{Message => 'Incoming fleets', Intel => \@intel, Origin => 1};
+
+ my $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 print $DBH->errstr;
+ my @intel;
+ while (my $intel = $query->fetchrow_hashref){
+ if ($intel->{ingal}){
+ $intel->{missionclass} = 'ingal';
+ }else{
+ $intel->{missionclass} = $intel->{mission};
+ }
+ push @intel,$intel;
+ }
+ push @intellists,{Message => 'Outgoing Fleets', Intel => \@intel, Target => 1};
+
+ $BODY->param(IntelLIsts => \@intellists);
+
+}elsif(!param('coords')){
+ my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',qq{not ingal
+ AND ((( t.alliance_id != o.alliance_id OR t.alliance_id IS NULL OR o.alliance_id IS NULL) AND i.mission != 'Attack')
+ OR ( t.alliance_id = o.alliance_id AND i.mission = 'Attack'))
+ AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
+ $showticks}));
+
+ my @intellists;
+ my @intel;
+ while (my $intel = $query->fetchrow_hashref){
+ if ($intel->{ingal}){
+ $intel->{missionclass} = 'ingal';
+ }else{
+ $intel->{missionclass} = $intel->{mission};
+ }
+ push @intel,$intel;
+ }
+ push @intellists,{Message => q{Missions where alliances doesn't match}, Intel => \@intel, Origin => 1, Target => 1};
+ $BODY->param(IntelLIsts => \@intellists);
+}
+my $query = $DBH->prepare(q{SELECT i.id, u.username, i.message, report_date FROM intel_messages i
+ JOIN users u ON u.uid = i.uid
+ WHERE NOT handled ORDER BY report_date});
+$query->execute;
+my @messages;
+while (my $message = $query->fetchrow_hashref){
+ $message->{message} = parseMarkup($message->{message});
+ push @messages,$message;
+}
+$BODY->param(IntelMessages => \@messages);
+1;
--- /dev/null
+<form action="index.pl" method="post"><p>
+ <input type="text" name="coords" value="<TMPL_VAR NAME=Coords>"/>
+ <input type="submit" value="Check"/>
+ <input type="hidden" name="page" value="intel"/>
+ </p>
+</form>
+<p><a href="index.pl?page=intel&show=all&coords=<TMPL_VAR NAME=Coords>">Show all ticks</a></p>
+
+<TMPL_IF Coords>
+<form action="index.pl" method="post">
+ <input type="hidden" name="coords" value="<TMPL_VAR NAME=Coords>"/>
+ <input type="hidden" name="planet" value="<TMPL_VAR NAME=Planet>"/>
+ <input type="hidden" name="cmd" value="change"/>
+ <input type="hidden" name="page" value="intel"/>
+ <table>
+ <tr>
+ <th></th>
+ <th>Value</th>
+ <th>Change?</th>
+ </tr>
+ <tr><td>Nick</td>
+ <td><input type="text" name="nick" value="<TMPL_VAR NAME=Nick>"/></td>
+ <td><input type="checkbox" name="cnick"/></td>
+ </tr>
+ <tr><td>Channel</td>
+ <td><input type="text" name="channel" value="<TMPL_VAR NAME=Channel>"/></td>
+ <td><input type="checkbox" name="cchannel"/></td>
+ </tr>
+ <tr><td>Planet status</td>
+ <td><select name="status">
+ <TMPL_LOOP PlanetStatus>
+ <option value="<TMPL_VAR NAME=Status>" <TMPL_IF NAME=Selected>selected="selected"</TMPL_IF>><TMPL_VAR NAME=Status></option>
+ </TMPL_LOOP>
+ </select></td>
+ <td><input type="checkbox" name="cstatus"/></td>
+ </tr>
+ <tr><td>Alliance</td>
+ <td><select name="alliance">
+ <TMPL_LOOP Alliances>
+ <option value="<TMPL_VAR NAME=Id>" <TMPL_IF NAME=Selected>selected="selected"</TMPL_IF>><TMPL_VAR NAME=Name></option>
+ </TMPL_LOOP>
+ </select></td>
+ <td><input type="checkbox" name="calliance"/></td>
+ </tr>
+ </table>
+ <p><input type="submit" value="Change"/>
+ </p>
+</form>
+</TMPL_IF>
+<TMPL_IF ChannelUsers>
+<p>Planets sharing this channel</p>
+<table>
+ <tr>
+ <th>Coords</th><th>Alliance</th><th>Nick</th><th>Channel</th>
+ </tr>
+<TMPL_LOOP ChannelUsers>
+ <tr>
+ <td><a href="index.pl?page=intel&coords=<TMPL_VAR NAME=Coords>"><TMPL_VAR NAME=Coords></a></td>
+ <td><TMPL_VAR NAME=Alliance></td><td><TMPL_VAR NAME=Nick></td><td><TMPL_VAR NAME=Channel></td>
+ </tr>
+</TMPL_LOOP>
+</table>
+</TMPL_IF>
+
+<TMPL_LOOP IntelLists>
+<TMPL_IF Message><p><TMPL_VAR NAME=Message></p></TMPL_IF>
+<table>
+ <tr>
+ <TMPL_IF Origin><th>Alliance</th><th>Sender</th></TMPL_IF>
+ <th>Mission</th><th>Landing tick</th><th>ETA</th><th>Amount</th>
+ <TMPL_IF Target><th>Target</th><th>Alliance</th></TMPL_IF>
+ <th>Ingal</th><th>Reported by</th>
+ </tr>
+ <TMPL_LOOP Intel>
+ <tr>
+ <TMPL_IF Origin>
+ <td><a href="index.pl?page=intel&coords=<TMPL_VAR NAME=Origin>"><TMPL_VAR NAME=Origin></a></td>
+ <td><TMPL_VAR NAME=OAlliance></td>
+ </TMPL_IF>
+ <td class="<TMPL_VAR NAME=MissionClass>"><TMPL_VAR NAME=Mission></td>
+ <td align="center"><TMPL_VAR NAME=landingtick></td>
+ <td align="center"><TMPL_VAR NAME=ETA></td>
+ <td><TMPL_VAR NAME=Amount></td>
+ <TMPL_IF Target>
+ <td><a href="index.pl?page=intel&coords=<TMPL_VAR NAME=Target>"><TMPL_VAR NAME=Target></a></td>
+ <td><TMPL_VAR NAME=TAlliance></td>
+ </TMPL_IF>
+ <td><TMPL_VAR NAME=Ingal></td>
+ <td><TMPL_VAR NAME=Username></td>
+ </tr>
+ </TMPL_LOOP>
+</table>
+</TMPL_LOOP>
+
+<table border="1">
+ <tr>
+ <th>Reported by</th>
+ <th>Report time</th>
+ <th>Message</th>
+ <th></th>
+ </tr>
+ <TMPL_LOOP IntelMessages>
+ <tr>
+ <td><TMPL_VAR NAME=Username></td>
+ <td><TMPL_VAR NAME=Report_date></td>
+ <td><TMPL_VAR NAME=Message></td>
+ <td><a href="index.pl?page=intel&handle=<TMPL_VAR NAME=Id>">remove</a></td>
+ </tr>
+ </TMPL_LOOP>
+</table>
+
+ <form action="index.pl" method="post"><fieldset> <legend>Coords</legend>
+ <p>Paste a list of coords here</p>
+ <textarea rows="25" cols="80" name="coords"></textarea>
+ <input type="hidden" name="cmd" value="coords"/>
+ <input type="hidden" name="page" value="intel"/>
+ <br/><input type="submit" value="Submit"/>
+</fieldset></form>