]> ruin.nu Git - ndwebbie.git/blob - ND/Web/Pages/MemberIntel.pm
big restructure
[ndwebbie.git] / ND / Web / 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 ND::Web::Pages::MemberIntel;
21 use strict;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
24 use ND::Web::Include;
25
26 $ND::PAGES{memberIntel} = {parse => \&parse, process => \&process, render=> \&render};
27
28 sub parse {
29         my ($uri) = @_;
30         if ($uri =~ m{^/.*/(\w+)$}){
31                 param('list',$1);
32         }
33 }
34
35 sub process {
36
37 }
38
39 sub render {
40         my ($DBH,$BODY) = @_;
41         my $error;
42
43         $ND::TEMPLATE->param(TITLE => 'Member Intel');
44
45         return $ND::NOACCESS unless isHC();
46
47         my $showticks = 'AND i.tick > tick()';
48         if (defined param('show')){
49                 if (param('show') eq 'all'){
50                         $showticks = '';
51                 }elsif (param('show') =~ /^(\d+)$/){
52                         $showticks = "AND (i.tick - i.eta) > (tick() - $1)";
53                 }
54         }
55
56
57         my $query = $DBH->prepare(intelquery('o.alliance AS oalliance,coords(o.x,o.y,o.z) AS origin, coords(t.x,t.y,t.z) AS target, t.nick',"t.alliance_id = 1 $showticks"));
58         $query->execute() or $error .= $DBH->errstr;
59         my @intellists;
60         my @incomings;
61         my $i = 0;
62         while (my $intel = $query->fetchrow_hashref){
63                 if ($intel->{ingal}){
64                         $intel->{missionclass} = 'ingal';
65                 }else{
66                         $intel->{missionclass} = $intel->{mission};
67                 }
68                 $intel->{oalliance} = ' ' unless $intel->{oalliance};
69                 $i++;
70                 $intel->{ODD} = $i % 2;
71                 push @incomings,$intel;
72         }
73         push @intellists,{Message => 'Incoming fleets', Intel => \@incomings, Origin => 1};
74
75         $query = $DBH->prepare(intelquery('o.nick,coords(o.x,o.y,o.z) AS origin,t.alliance AS talliance,coords(t.x,t.y,t.z) AS target',"o.alliance_id = 1 $showticks"));
76         $query->execute() or $error .= $DBH->errstr;
77         my @outgoings;
78         $i = 0;
79         while (my $intel = $query->fetchrow_hashref){
80                 if ($intel->{ingal}){
81                         $intel->{missionclass} = 'ingal';
82                 }else{
83                         $intel->{missionclass} = $intel->{mission};
84                 }
85                 $intel->{talliance} = ' ' unless $intel->{talliance};
86                 $i++;
87                 $intel->{ODD} = $i % 2;
88                 push @outgoings,$intel;
89         }
90         push @intellists,{Message => 'Outgoing Fleets', Intel => \@outgoings, Target => 1};
91
92         $BODY->param(IntelLIsts => \@intellists);
93
94         $BODY->param(Error => $error);
95         return $BODY;
96 }
97 1;