]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/TargetList.pm
Make relationship and planet_status an enum
[ndwebbie.git] / NDWeb / Pages / TargetList.pm
1 #**************************************************************************
2 #   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
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.                                   *
8 #                                                                         *
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.                          *
13 #                                                                         *
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 #**************************************************************************/
19
20 package NDWeb::Pages::TargetList;
21 use strict;
22 use warnings FATAL => 'all';
23 use ND::Include;
24 use CGI qw/:standard/;
25 use NDWeb::Include;
26
27 use base qw/NDWeb::XMLPage/;
28
29 $NDWeb::Page::PAGES{targetList} = __PACKAGE__;
30
31 sub render_body {
32         my $self = shift;
33         my ($BODY) = @_;
34         $self->{TITLE} = 'NF Value';
35         my $DBH = $self->{DBH};
36
37         return $self->noAccess unless $self->isHC;
38
39         my $order = 'nfvalue';
40         if (local $_ = param('order')){
41                 if (/^(size|value|score|xp)$/){
42                         $order = "$1 DESC";
43                 }elsif (/^(nfvalue|nfvalue2)$/){
44                         $order = "$1 ASC";
45                 }
46         }
47
48         my $alliances = '15';
49         if (param('alliances') && param('alliances') =~ /^([\d,]+)$/){
50                 $alliances = $1;
51         }
52         my $query = $DBH->prepare(qq{
53 SELECT coords(p.x,p.y,p.z),p.alliance, p.score, p.value, p.size, p.xp,nfvalue, nfvalue - sum(pa.value) AS nfvalue2, p.race
54 FROM current_planet_stats p
55         JOIN (SELECT g.x,g.y, sum(p.value) AS nfvalue
56         FROM galaxies g join current_planet_stats p on g.x = p.x AND g.y = p.y 
57         WHERE g.tick = (SELECT max(tick) from galaxies)
58                 AND ((NOT planet_status IN ('Friendly','NAP')) AND  (NOT relationship IN ('Friendly','NAP'))) 
59         GROUP BY g.x,g.y
60         ) g ON p.x = g.x AND p.y = g.y
61         JOIN current_planet_stats pa ON pa.x = g.x AND pa.y = g.y
62 WHERE p.alliance_id IN ($alliances)
63         AND pa.alliance_id IN ($alliances)
64 GROUP BY p.x,p.y,p.z,p.alliance, p.score, p.value, p.size, p.xp, nfvalue,p.race
65 ORDER BY $order
66                 });
67         $query->execute;
68         my @alliances;
69         while (my $alliance = $query->fetchrow_hashref){
70                 push @alliances,$alliance;
71         }
72         $BODY->param(Alliances => \@alliances);
73
74         return $BODY;
75 }
76 1;