]> ruin.nu Git - ndwebbie.git/blob - include.pl
76c4541db78caf171f5e722dc222aaddadc20a6f
[ndwebbie.git] / include.pl
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 use strict;
21
22
23 sub isMember {
24         return exists $ND::GROUPS{Members};
25 }
26
27 sub isHC {
28         return exists $ND::GROUPS{HC};
29 }
30
31 sub isDC {
32         return exists $ND::GROUPS{DC};
33 }
34
35 sub isBC {
36         return exists $ND::GROUPS{BC};
37 }
38
39 sub isOfficer {
40         return exists $ND::GROUPS{Officers};
41 }
42
43 sub isScanner {
44         return exists $ND::GROUPS{Scanners};
45 }
46
47 sub isIntel {
48         return exists $ND::GROUPS{Intel};
49 }
50
51 sub parseMarkup {
52         my ($text) = @_;
53
54         $text =~ s{\n}{\n<br/>}g;
55         $text =~ s{\[B\](.*?)\[/B\]}{<b>$1</b>};
56         return $text;
57 }
58
59 sub min {
60     my ($x,$y) = @_;
61     return ($x > $y ? $y : $x);
62 }
63
64 sub max {
65     my ($x,$y) = @_;
66     return ($x < $y ? $y : $x);
67 }
68
69 sub listTargets {
70         my $query = $ND::DBH->prepare(qq{SELECT t.id, r.id AS raid, r.tick+c.wave-1 AS landingtick, released_coords, coords(x,y,z),c.launched,c.wave,c.joinable
71 FROM raid_claims c
72         JOIN raid_targets t ON c.target = t.id
73         JOIN raids r ON t.raid = r.id
74         JOIN current_planet_stats p ON t.planet = p.id
75 WHERE c.uid = ? AND r.tick+c.wave > ? AND r.open AND not r.removed
76 ORDER BY r.tick+c.wave,x,y,z});
77         $query->execute($ND::UID,$ND::TICK);
78         my @targets;
79         while (my $target = $query->fetchrow_hashref){
80                 my $coords = "Target $target->{id}";
81                 $coords = $target->{coords} if $target->{released_coords};
82                 push @targets,{Coords => $coords, Launched => $target->{launched}, Raid => $target->{raid}
83                         , Target => $target->{id}, Tick => $target->{landingtick}, Wave => $target->{wave}
84                         , AJAX => $ND::AJAX, JoinName => $target->{joinable} ? 'N' : 'J'
85                         , Joinable => $target->{joinable} ? 'FALSE' : 'TRUE'};
86         }
87         my $template = HTML::Template->new(filename => "templates/targetlist.tmpl", cache => 1);
88         $template->param(Targets => \@targets);
89         return $template->output;
90 }
91
92 sub alliances {
93         my ($alliance) = @_;
94         my @alliances;
95         push @alliances,{Id => -1, Name => '&nbsp;', Selected => not $alliance};
96         my $query = $ND::DBH->prepare(q{SELECT id,name FROM alliances ORDER BY name});
97         $query->execute;        
98         while (my $ally = $query->fetchrow_hashref){
99                 push @alliances,{Id => $ally->{id}, Name => $ally->{name}, Selected => $alliance == $ally->{id}};
100         }
101         return @alliances;
102 }
103
104 sub intelquery {
105         my ($columns,$where) = @_;
106         return qq{
107 SELECT $columns, i.mission, i.tick AS landingtick,MIN(i.eta) AS eta, i.amount, i.ingal, u.username
108 FROM (intel i NATURAL JOIN users u)
109         JOIN current_planet_stats t ON i.target = t.id
110         JOIN current_planet_stats o ON i.sender = o.id
111 WHERE $where 
112 GROUP BY i.tick,i.mission,t.x,t.y,t.z,o.x,o.y,o.z,i.amount,i.ingal,u.username,t.alliance,o.alliance,t.nick,o.nick
113 ORDER BY i.tick DESC, i.mission};
114 }
115
116 1;