]> ruin.nu Git - ndwebbie.git/blob - NDWeb/Pages/MemberIntel.pm
2958e44f64ad6e920d9fa9a146d36da9824d1d47
[ndwebbie.git] / NDWeb / Pages / MemberIntel.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::MemberIntel;
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{memberIntel} = __PACKAGE__;
29
30 sub render_body {
31         my $self = shift;
32         my ($BODY) = @_;
33         $self->{TITLE} = 'Member Intel';
34         my $DBH = $self->{DBH};
35         my $error;
36
37         return $self->noAccess unless $self->isHC;
38
39         my $showticks = 'AND i.tick > tick()';
40         if (defined param('show')){
41                 if (param('show') eq 'all'){
42                         $showticks = '';
43                 }elsif (param('show') =~ /^(\d+)$/){
44                         $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
45                 }
46         }
47
48         my $query = $DBH->prepare(q{SELECT u.uid,u.username,u.attack_points, u.defense_points
49                 ,count(CASE WHEN i.mission = 'Attack' THEN 1 ELSE NULL END) AS attacks
50                 ,count(CASE WHEN (i.mission = 'Defend' OR i.mission = 'AllyDef') THEN 1 ELSE NULL END) AS defenses
51                 FROM users u
52                 JOIN groupmembers gm USING (uid)
53                 LEFT OUTER JOIN (SELECT * FROM intel WHERE amount = -1) i ON i.sender = u.planet
54                 LEFT OUTER JOIN current_planet_stats t ON i.target = t.id
55                 WHERE gm.gid = 2
56                 GROUP BY u.uid,u.username,u.attack_points, u.defense_points
57                 ORDER BY attacks DESC,defenses DESC});
58         $query->execute() or $error .= $DBH->errstr;
59         my @members;
60         my $i = 0;
61         while (my $intel = $query->fetchrow_hashref){
62                 $i++;
63                 $intel->{ODD} = $i % 2;
64                 push @members,$intel;
65         }
66
67         $BODY->param(Members => \@members);
68
69         $BODY->param(Error => $error);
70         return $BODY;
71 }
72 1;