]> ruin.nu Git - ndwebbie.git/blob - top100.pl
oops, guess I had forgotten about this file
[ndwebbie.git] / top100.pl
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 use strict;
21 use warnings FATAL => 'all';
22 no warnings qw(uninitialized);
23
24 $ND::TEMPLATE->param(TITLE => 'Top100 ');
25
26 our $BODY;
27 our $DBH;
28 our $LOG;
29
30 $BODY->param(isHC => isHC());
31
32
33 die "You don't have access" unless isMember();
34
35 my $offset = 0;
36 if (param('offset') =~ /^(\d+)$/){
37         $offset = $1;
38 }
39 $BODY->param(Offset => $offset);
40 $BODY->param(PrevOffset => $offset - 100);
41 $BODY->param(NextOffset => $offset + 100);
42
43 my $order = 'scorerank';
44 if (param('order') =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){
45         $order = $1;
46 }
47 $BODY->param(Order => $order);
48 $order .= ' DESC' if ($order eq 'hit_us');
49
50
51 my $extra_columns = '';
52 if (isHC()){
53         $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
54 }
55 my $query = $DBH->prepare(qq{SELECT id,coords(x,y,z), ruler, planet,race,
56         size, score, value, xp, sizerank, scorerank, valuerank, xprank
57         $extra_columns FROM current_planet_stats ORDER BY $order LIMIT 100 OFFSET ?});
58 $query->execute($offset);
59 my @planets;
60 my $i = 0;
61 while (my ($id,$coords,$ruler,$planet,$race,$size,$score,$value,$xp,$sizerank,$scorerank,$valuerank,$xprank
62                 ,$planet_status,$hit_us,$alliance,$relationship,$nick) = $query->fetchrow){
63         my %planet = (Coords => $coords, Planet => "$ruler OF $planet", Race => $race, Size => "$size ($sizerank)"
64                 , Score => "$score ($scorerank)", Value => "$value ($valuerank)", XP => "$xp ($xprank)");
65         if (isHC){
66                 $planet{HitUs} = $hit_us;
67                 $planet{Alliance} = "$alliance ($relationship)";
68                 $planet{Nick} = "$nick ($planet_status)";
69                 $planet{PlanetStatus} = $planet_status;
70                 $planet{Relationship} = $relationship;
71                 $planet{isHC} = 1;
72         }
73         $i++;
74         $planet{ODD} = $i % 2;
75         push @planets,\%planet;
76 }
77 $BODY->param(Planets => \@planets);
78
79 1;