1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
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. *
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. *
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 #**************************************************************************/
20 package NDWeb::Pages::MemberIntel;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
26 use base qw/NDWeb::XMLPage/;
28 $NDWeb::Page::PAGES{memberIntel} = __PACKAGE__;
33 $self->{TITLE} = 'Member Intel';
34 my $DBH = $self->{DBH};
37 return $self->noAccess unless $self->isHC;
39 my $showticks = 'AND i.tick > tick()';
40 if (defined param('show')){
41 if (param('show') eq 'all'){
43 }elsif (param('show') =~ /^(\d+)$/){
44 $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
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
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
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;
61 while (my $intel = $query->fetchrow_hashref){
63 $intel->{ODD} = $i % 2;
67 $BODY->param(Members => \@members);
69 $BODY->param(Error => $error);