]> ruin.nu Git - ndwebbie.git/blob - ND/Web/Pages/Top100.pm
possible to chose stylesheet
[ndwebbie.git] / ND / Web / Pages / Top100.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::Top100;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use ND::Web::Include;
25
26 $ND::PAGES{top100} = {parse => \&parse, process => \&process, render=> \&render};
27
28 sub parse {
29         my ($uri) = @_;
30         #TODO: Need to fix some links first
31         #if ($uri =~ m{^/[^/]+/(\w+)}){
32         #       param('order',$1);
33         #}
34 }
35
36 sub process {
37
38 }
39
40 sub render {
41         my ($DBH,$BODY) = @_;
42         $ND::TEMPLATE->param(TITLE => 'Top100 ');
43
44         my $error = '';
45
46         $BODY->param(isHC => isHC());
47
48         return $ND::NOACCESS unless isMember();
49
50         my $offset = 0;
51         if (defined param('offset') && param('offset') =~ /^(\d+)$/){
52                 $offset = $1;
53         }
54         $BODY->param(Offset => $offset);
55         $BODY->param(PrevOffset => $offset - 100);
56         $BODY->param(NextOffset => $offset + 100);
57
58         my $order = 'scorerank';
59         if (defined param('order') && param('order') =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){
60                 $order = $1;
61         }
62         $BODY->param(Order => $order);
63         $order .= ' DESC' if ($order eq 'hit_us');
64
65
66         my $extra_columns = '';
67         if (isHC()){
68                 $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
69         }
70         my $query = $DBH->prepare(qq{SELECT coords(x,y,z),((ruler || ' OF ') || planet) as planet,race,
71                 size, score, value, xp, sizerank, scorerank, valuerank, xprank
72                 $extra_columns FROM current_planet_stats ORDER BY $order LIMIT 100 OFFSET ?});
73         $query->execute($offset) or $error .= p($DBH->errstr);
74         my @planets;
75         my $i = 0;
76         while (my $planet = $query->fetchrow_hashref){
77                 if (isHC){
78                         $planet->{isHC} = 1;
79                 }
80                 $i++;
81                 $planet->{ODD} = $i % 2;
82                 push @planets,$planet;
83         }
84         $BODY->param(Planets => \@planets);
85         $BODY->param(Error => $error);
86         return $BODY;
87 }
88
89 1;