]> ruin.nu Git - ndwebbie.git/blob - editRaid.pl
74c2c63f67f3814d97058cb3bcebe01acc1a8d75
[ndwebbie.git] / editRaid.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 use POSIX;
22 our $BODY;
23 our $DBH;
24 our $LOG;
25
26 $ND::TEMPLATE->param(TITLE => 'Create/Edit Raids');
27
28 die "You don't have access" unless isBC();
29
30 my @alliances = alliances();
31 $BODY->param(Alliances => \@alliances);
32
33 my $raid;
34 if (param('raid') =~ /^(\d+)$/){
35         my $query = $DBH->prepare(q{SELECT id,tick,waves,message,released_coords,open FROM raids WHERE id = ?});
36         $raid = $DBH->selectrow_hashref($query,undef,$1);
37 }
38
39 my $groups = $DBH->prepare(q{SELECT g.gid,g.groupname,raid FROM groups g LEFT OUTER JOIN (SELECT gid,raid FROM raid_access WHERE raid = ?) AS ra ON g.gid = ra.gid WHERE g.attack});
40 $groups->execute($raid ? $raid->{id} : undef);
41
42 my @addgroups;
43 my @remgroups;
44 while (my $group = $groups->fetchrow_hashref){
45         if ($group->{raid}){
46                 push @remgroups,{Id => $group->{gid}, Name => $group->{groupname}};
47         }else{
48                 push @addgroups,{Id => $group->{gid}, Name => $group->{groupname}};
49         }
50 }
51 $BODY->param(RemoveGroups => \@remgroups);
52 $BODY->param(AddGroups => \@addgroups);
53
54 if ($raid){
55         $BODY->param(Raid => $raid->{id});
56         if($raid->{open}){
57                 $BODY->param(Open => 'Open');
58         }else{
59                 $BODY->param(Open => 'Close');
60         }
61         if($raid->{released_coords}){
62                 $BODY->param(ShowCoords => 'hidecoords');
63                 $BODY->param(ShowCoordsName => 'Hide');
64         }else{
65                 $BODY->param(ShowCoords => 'showcoords');
66                 $BODY->param(ShowCoordsName => 'Show');
67         }
68         $BODY->param(Waves => $raid->{waves});
69         $BODY->param(LandingTick => $raid->{tick});
70         $BODY->param(Message => $raid->{message});
71         
72         my $order = "p.x,p.y,p.z";
73         if (param('order') =~ /^(score|size|value|xp|race)$/){
74                 $order = "$1 DESC";
75         }
76
77         my $targetquery = $DBH->prepare(qq{SELECT p.id,coords(x,y,z),raid,comment,size,score,value,race,planet_status AS planetstatus,relationship,comment
78                 FROM current_planet_stats p JOIN raid_targets r ON p.id = r.planet 
79                         LEFT OUTER JOIN covop_targets c ON p.id = c.planet
80                 WHERE r.raid = ?
81                 ORDER BY $order});
82         $targetquery->execute($raid->{id}) or print $DBH->errstr;
83         my @targets;
84         while (my $target = $targetquery->fetchrow_hashref){
85                 push @targets,$target;
86         }
87         $BODY->param(Targets => \@targets);
88 }else{
89         $BODY->param(Waves => 3);
90         $BODY->param(LandingTick => $ND::TICK+12);
91 }
92
93 1;