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