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