1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
21 use warnings FATAL => 'all';
30 $ND::TEMPLATE->param(TITLE => 'Intel');
32 die "You don't have access" unless isIntel() || isHC();
35 if (defined param('coords') && param('coords') =~ /^(\d+)(?: |:)(\d+)(?: |:)(\d+)$/){
36 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
37 WHERE x = ? AND y = ? AND z = ?});
38 $planet = $DBH->selectrow_hashref($query,undef,$1,$2,$3);
41 my $showticks = 'AND (i.tick - i.eta) > (tick() - 48)';
42 if (defined param('show')){
43 if (param('show') eq 'all'){
45 }elsif (param('show') =~ /^(\d+)$/){
46 $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
52 $thread = $DBH->selectrow_hashref(q{SELECT ftid AS id, subject FROM forum_threads
53 where planet = $1},undef,$planet->{id}) or $ERROR .= p($DBH->errstr);
56 if (defined param('cmd') && param('cmd') eq 'coords'){
57 my $coords = param('coords');
58 $DBH->do(q{CREATE TEMPORARY TABLE coordlist (
64 my $insert = $DBH->prepare(q{INSERT INTO coordlist (x,y,z) VALUES(?,?,?)});
65 while ($coords =~ m/(\d+):(\d+):(\d+)/g){
66 $insert->execute($1,$2,$3);
68 my $planets = $DBH->prepare(q{SELECT (((p.x || ':') || p.y) || ':') || p.z AS coords, alliance FROM current_planet_stats p
69 JOIN coordlist c ON p.x = c.x AND p.y = c.y AND p.z = c.z
70 ORDER BY alliance, p.x, p.y, p.z});
73 while (my $planet = $planets->fetchrow_hashref){
74 push @planets,$planet;
76 $BODY->param(CoordList => \@planets);
78 if (defined $thread and defined param('cmd') and param('cmd') eq 'forumpost'){
79 addForumPost($DBH,$thread,$ND::UID,param('message'));
82 if ($planet && defined param('cmd')){
83 if (param('cmd') eq 'change'){
86 my $value = escapeHTML(param('nick'));
87 if ($DBH->do(q{UPDATE planets SET nick = ? WHERE id =?}
88 ,undef,$value,$planet->{id})){
89 $planet->{nick} = $value;
91 $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
94 if (param('cchannel')){
95 my $value = escapeHTML(param('channel'));
96 if ($DBH->do(q{UPDATE planets SET channel = ? WHERE id =?}
97 ,undef,$value,$planet->{id})){
98 $planet->{channel} = $value;
100 $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
103 if (param('cstatus')){
104 my $value = escapeHTML(param('status'));
105 if ($DBH->do(q{UPDATE planets SET planet_status = ? WHERE id =?}
106 ,undef,$value,$planet->{id})){
107 $planet->{planet_status} = $value;
109 $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
112 if (param('calliance')){
113 if ($DBH->do(q{UPDATE planets SET alliance_id = NULLIF(?,-1) WHERE id =?}
114 ,undef,param('alliance'),$planet->{id})){
115 $planet->{alliance_id} = param('alliance');
117 $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
120 $DBH->commit or $error .= "<p> Something went wrong: ".$DBH->errstr."</p>";
124 if (param('coords')){
125 my $channel = param('coords');
126 $channel = $planet->{channel} if ($planet);
127 my $findchannel = $DBH->prepare('SELECT coords(x,y,z),alliance,nick,channel FROM current_planet_stats WHERE channel ILIKE ? ');
128 $findchannel->execute($channel);
130 while (my $user = $findchannel->fetchrow_hashref){
131 push @channelusers,$user;
133 $BODY->param(ChannelUsers => \@channelusers);
137 $BODY->param(Coords => $planet->{coords});
138 $BODY->param(Planet => $planet->{id});
139 $BODY->param(Nick => $planet->{nick});
140 $BODY->param(Channel => $planet->{channel});
142 for my $status (" ","Friendly", "NAP", "Hostile"){
143 push @status,{Status => $status, Selected => defined $planet->{planet_status} && $status eq $planet->{planet_status}}
145 $BODY->param(PlanetStatus => \@status);
146 my @alliances = alliances($planet->{alliance_id});
147 $BODY->param(Alliances => \@alliances);
149 $BODY->param(Thread => viewForumThread $thread);
151 my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin',"t.id = ? $showticks"));
152 $query->execute($planet->{id}) or $error .= $DBH->errstr;
156 while (my $intel = $query->fetchrow_hashref){
157 if ($intel->{ingal}){
158 $intel->{missionclass} = 'ingal';
160 $intel->{missionclass} = $intel->{mission};
163 $intel->{ODD} = $i % 2;
164 push @incomings,$intel;
166 push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
168 $query = $DBH->prepare(intelquery('t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.id = ? $showticks"));
169 $query->execute($planet->{id}) or $error .= $DBH->errstr;
172 while (my $intel = $query->fetchrow_hashref){
173 if ($intel->{ingal}){
174 $intel->{missionclass} = 'ingal';
176 $intel->{missionclass} = $intel->{mission};
179 $intel->{ODD} = $i % 2;
180 push @outgoings,$intel;
182 push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
184 $BODY->param(IntelLIsts => \@intellists);
186 }elsif(!param('coords')){
187 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
188 AND ((( t.alliance_id != o.alliance_id OR t.alliance_id IS NULL OR o.alliance_id IS NULL) AND i.mission != 'Attack')
189 OR ( t.alliance_id = o.alliance_id AND i.mission = 'Attack'))
190 AND i.sender NOT IN (SELECT planet FROM users u NATURAL JOIN groupmembers gm WHERE gid = 8 AND planet IS NOT NULL)
192 $query->execute() or $error .= $DBH->errstr;
197 while (my $intel = $query->fetchrow_hashref){
198 if ($intel->{ingal}){
199 $intel->{missionclass} = 'ingal';
201 $intel->{missionclass} = $intel->{mission};
204 $intel->{ODD} = $i % 2;
207 push @intellists,{Message => q{Intel where alliances doesn't match}, Intel => \@intel, Origin => 1, Target => 1};
208 $BODY->param(IntelLIsts => \@intellists);
210 my $query = $DBH->prepare(q{SELECT i.id, u.username, i.message, report_date FROM intel_messages i
211 JOIN users u ON u.uid = i.uid
212 WHERE NOT handled ORDER BY report_date});
215 while (my $message = $query->fetchrow_hashref){
216 $message->{message} = parseMarkup($message->{message});
217 push @messages,$message;
219 #$BODY->param(IntelMessages => \@messages);
220 $BODY->param(Error => $error);