]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/PlanetNaps.pm
Converted mail page
[ndwebbie.git] / NDWeb / Pages / PlanetNaps.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::PlanetNaps;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use NDWeb::Include;
25
26 use base qw/NDWeb::XMLPage/;
27
28 $NDWeb::Page::PAGES{planetNaps} = __PACKAGE__;
29
30 sub render_body {
31         my $self = shift;
32         my ($BODY) = @_;
33         $self->{TITLE} = 'List planet naps';
34         my $DBH = $self->{DBH};
35
36         return $self->noAccess unless $self->isHC;
37         my $error;
38
39         my $query = $DBH->prepare(q{SELECT coords(x,y,z)
40                 , ((ruler || ' OF ') || p.planet) AS planet,race, size, score, value
41                 , xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 
42                         - COALESCE(ps.metal+ps.crystal+ps.eonium,0)/150
43                         - COALESCE(ss.total ,(SELECT COALESCE(avg(total),0) FROM structure_scans)::int)*1500 AS fleetvalue
44                 ,(metal+crystal+eonium)/100 AS resvalue, planet_status,hit_us
45                 , alliance,relationship,nick 
46                 FROM current_planet_stats p
47                         LEFT OUTER JOIN planet_scans ps ON p.id = ps.planet
48                         LEFT OUTER JOIN structure_scans ss ON p.id = ss.planet
49                 WHERE planet_status IN ('Friendly','NAP') order by x,y,z asc});
50
51         $query->execute or $error .= p($DBH->errstr);
52         my @planets;
53         while (my $planet = $query->fetchrow_hashref){
54                 push @planets,$planet;
55         }
56         $BODY->param(Planets => \@planets);
57         $BODY->param(Error => $error);
58         return $BODY;
59 }
60
61 1;