]> ruin.nu Git - ndwebbie.git/blob - ND/Web/Pages/PlanetNaps.pm
big restructure
[ndwebbie.git] / ND / Web / 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 ND::Web::Pages::PlanetNaps;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use ND::Web::Include;
25
26 $ND::PAGES{planetNaps} = {parse => \&parse, process => \&process, render=> \&render};
27
28 sub parse {
29         my ($uri) = @_;
30 }
31
32 sub process {
33
34 }
35
36 sub render {
37         my ($DBH,$BODY) = @_;
38         my $error;
39
40         $ND::TEMPLATE->param(TITLE => 'List planet naps');
41
42         return $ND::NOACCESS unless isHC();
43
44         my $query = $DBH->prepare(qq{Select coords(x,y,z), ((ruler || ' OF ') || p.planet) as planet,race, size, score, value, xp, sizerank, scorerank, valuerank, xprank, p.value - p.size*200 - coalesce(c.metal+c.crystal+c.eonium,0)/150 - coalesce(c.structures,(SELECT avg(structures) FROM covop_targets)::int)*1500 AS fleetvalue,(c.metal+c.crystal+c.eonium)/100 AS resvalue, planet_status,hit_us, alliance,relationship,nick from current_planet_stats p LEFT OUTER JOIN covop_targets c ON p.id = c.planet WHERE planet_status IN ('Friendly','NAP') order by x,y,z asc});
45
46         $query->execute or $error .= p($DBH->errstr);
47         my @planets;
48         my $i = 0;
49         while (my $planet = $query->fetchrow_hashref){
50                 $i++;
51                 $planet->{ODD} = $i % 2;
52                 push @planets,$planet;
53         }
54         $BODY->param(Planets => \@planets);
55         $BODY->param(Error => $error);
56         return $BODY;
57 }
58
59 1;