]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/DefLeeches.pm
Converted intel page
[ndwebbie.git] / NDWeb / Pages / DefLeeches.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 NDWeb::Pages::DefLeeches;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use NDWeb::Include;
25
26 use base qw/NDWeb::XMLPage/;
27
28 $NDWeb::Page::PAGES{defLeeches} = __PACKAGE__;
29
30
31 sub render_body {
32         my $self = shift;
33         my ($BODY) = @_;
34         $self->{TITLE} = 'Def Leeches';
35         my $DBH = $self->{DBH};
36
37         return $self->noAccess unless $self->isDC;
38
39         my $query = $DBH->prepare(q{SELECT username,defense_points,count(id) AS calls, SUM(fleets) AS fleets, SUM(recalled) AS recalled
40                 FROM (SELECT username,defense_points,c.id,count(f.target) AS fleets, count(NULLIF(f.tick + f.eta -1 = f.back,TRUE)) AS recalled
41                         FROM users u JOIN calls c ON c.member = u.uid LEFT OUTER JOIN fleets f ON u.planet = f.target AND c.landing_tick = f.tick
42                         WHERE (f.mission = 'Defend' AND f.uid > 0 AND f.back IS NOT NULL AND NOT ingal)
43                                 OR f.target IS NULL
44                         GROUP BY username,defense_points,c.id
45                         ) d
46                 GROUP BY username,defense_points ORDER BY fleets DESC, defense_points
47                 });
48         $query->execute;
49
50         my @members;
51         while ( my $member = $query->fetchrow_hashref){
52                 push @members,$member;
53         }
54         $BODY->param(Members => \@members);
55         return $BODY;
56 }
57
58 1;