forked from thekabal/tki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoneedit.php
314 lines (280 loc) · 10.9 KB
/
zoneedit.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php declare(strict_types = 1);
/**
* zoneedit.php from The Kabal Invasion.
* The Kabal Invasion is a Free & Opensource (FOSS), web-based 4X space/strategy game.
*
* @copyright 2020 The Kabal Invasion development team, Ron Harwood, and the BNT development team
*
* @license GNU AGPL version 3.0 or (at your option) any later version.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
require_once './common.php';
$login = new Tki\Login();
$login->checkLogin($pdo_db, $lang, $tkireg, $tkitimer, $template);
$title = $langvars['l_ze_title'];
$header = new Tki\Header();
$header->display($pdo_db, $lang, $template, $title);
// Database driven language entries
$langvars = Tki\Translate::load($pdo_db, $lang, array('common', 'footer',
'insignias', 'main', 'news', 'port', 'report',
'universal', 'zoneedit', 'zoneinfo'));
echo "<h1>" . $title . "</h1>\n";
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$command = null;
$command = filter_input(INPUT_GET, 'command', FILTER_SANITIZE_EMAIL);
if (strlen(trim($command)) === 0)
{
$command = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$zone = null;
$zone = filter_input(INPUT_GET, 'zone', FILTER_SANITIZE_EMAIL);
if (strlen(trim($zone)) === 0)
{
$zone = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$name = null;
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_EMAIL);
if (strlen(trim($name)) === 0)
{
$name = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$beacons = null;
$beacons = filter_input(INPUT_POST, 'beacons', FILTER_SANITIZE_EMAIL);
if (strlen(trim($beacons)) === 0)
{
$beacons = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$attacks = null;
$attacks = filter_input(INPUT_POST, 'attacks', FILTER_SANITIZE_EMAIL);
if (strlen(trim($attacks)) === 0)
{
$attacks = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$warpedits = null;
$warpedits = filter_input(INPUT_POST, 'warpedits', FILTER_SANITIZE_EMAIL);
if (strlen(trim($warpedits)) === 0)
{
$warpedits = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$defenses = null;
$defenses = filter_input(INPUT_POST, 'defenses', FILTER_SANITIZE_EMAIL);
if (strlen(trim($defenses)) === 0)
{
$defenses = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$planets = null;
$planets = filter_input(INPUT_POST, 'planets', FILTER_SANITIZE_EMAIL);
if (strlen(trim($planets)) === 0)
{
$planets = false;
}
// Detect if this variable exists, and filter it.
// Returns false if anything wasn't right.
$trades = null;
$trades = filter_input(INPUT_POST, 'trades', FILTER_SANITIZE_EMAIL);
if (strlen(trim($trades)) === 0)
{
$trades = false;
}
// Get zoneinfo from database
$zones_gateway = new \Tki\Zones\ZonesGateway($pdo_db);
$zoneinfo = $zones_gateway->selectZoneInfo($zone);
if (empty($zoneinfo))
{
echo "<p>" . $langvars['l_zi_nexist'] . "<p>";
Tki\Text::gotoMain($pdo_db, $lang);
$footer = new Tki\Footer();
$footer->display($pdo_db, $lang, $tkireg, $tkitimer, $template);
die();
}
if (array_key_exists('zone_name', $zoneinfo))
{
// Sanitize zone_name.
$zoneinfo['zone_name'] = preg_replace('/[^A-Za-z0-9\_\s\-\.\']+/', '', $zoneinfo['zone_name']);
}
if ($zoneinfo['team_zone'] == 'N')
{
$players_gateway = new \Tki\Players\PlayersGateway($pdo_db);
$ownerinfo = $players_gateway->selectPlayerInfo($_SESSION['username']);
}
else
{
$sql = "SELECT creator, id FROM ::prefix::teams WHERE creator = :creator LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':creator', $zoneinfo['owner'], PDO::PARAM_INT);
$stmt->execute();
$ownerinfo = $stmt->fetch(PDO::FETCH_ASSOC);
}
if (($zoneinfo['team_zone'] == 'N' && $zoneinfo['owner'] != $ownerinfo['ship_id']) || ($zoneinfo['team_zone'] == 'Y' && $zoneinfo['owner'] != $ownerinfo['id'] && $row['owner'] == $ownerinfo['creator']))
{
echo "<p>" . $langvars['l_ze_notowner'] . "<p>";
Tki\Text::gotoMain($pdo_db, $lang);
$footer = new Tki\Footer();
$footer->display($pdo_db, $lang, $tkireg, $tkitimer, $template);
die();
}
if ($command == 'change')
{
// Sanitize zone name.
$name = preg_replace('/[^A-Za-z0-9\_\s\-\.\']+/', '', $name);
$sql = "UPDATE ::prefix::zones SET zone_name = :zone_name, allow_beacon = :allow_beacon, allow_attack = :allow_attack, allow_warpedit = :allow_warpedit, allow_planet = :allow_planet, allow_trade = :allow_trade, allow_defenses = :allow_defenses WHERE zone_id = :zone_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':zone_name', $name, PDO::PARAM_STR);
$stmt->bindParam(':allow_beacon', $beacons, \PDO::PARAM_STR);
$stmt->bindParam(':allow_attack', $attacks, \PDO::PARAM_STR);
$stmt->bindParam(':allow_warpedit', $warpedits, \PDO::PARAM_STR);
$stmt->bindParam(':allow_planet', $planets, \PDO::PARAM_STR);
$stmt->bindParam(':allow_trade', $trades, \PDO::PARAM_STR);
$stmt->bindParam(':allow_defenses', $defenses, \PDO::PARAM_STR);
$stmt->bindParam(':zone_id', $zone, PDO::PARAM_INT);
$stmt->execute();
echo $langvars['l_ze_saved'] . "<p>";
echo "<a href=zoneinfo.php?zone=$zone>" . $langvars['l_clickme'] . "</a> " . $langvars['l_ze_return'] . ".<p>";
Tki\Text::gotoMain($pdo_db, $lang);
$footer = new Tki\Footer();
$footer->display($pdo_db, $lang, $tkireg, $tkitimer, $template);
die();
}
$ybeacon = null;
$nbeacon = null;
$lbeacon = null;
if ($zoneinfo['allow_beacon'] == 'Y')
{
$ybeacon = "checked";
}
elseif ($zoneinfo['allow_beacon'] == 'N')
{
$nbeacon = "checked";
}
else
{
$lbeacon = "checked";
}
$yattack = null;
$nattack = null;
if ($zoneinfo['allow_attack'] == 'Y')
{
$yattack = "checked";
}
else
{
$nattack = "checked";
}
$ywarpedit = null;
$nwarpedit = null;
$lwarpedit = null;
if ($zoneinfo['allow_warpedit'] == 'Y')
{
$ywarpedit = "checked";
}
elseif ($zoneinfo['allow_warpedit'] == 'N')
{
$nwarpedit = "checked";
}
else
{
$lwarpedit = "checked";
}
$yplanet = null;
$nplanet = null;
$lplanet = null;
if ($zoneinfo['allow_planet'] == 'Y')
{
$yplanet = "checked";
}
elseif ($zoneinfo['allow_planet'] == 'N')
{
$nplanet = "checked";
}
else
{
$lplanet = "checked";
}
$ytrade = null;
$ntrade = null;
$ltrade = null;
if ($zoneinfo['allow_trade'] == 'Y')
{
$ytrade = "checked";
}
elseif ($zoneinfo['allow_trade'] == 'N')
{
$ntrade = "checked";
}
else
{
$ltrade = "checked";
}
$ydefense = null;
$ndefense = null;
$ldefense = null;
if ($zoneinfo['allow_defenses'] == 'Y')
{
$ydefense = "checked";
}
elseif ($zoneinfo['allow_defenses'] == 'N')
{
$ndefense = "checked";
}
else
{
$ldefense = "checked";
}
echo "<form accept-charset='utf-8' action=zoneedit.php?command=change&zone=$zone method=post>" .
"<table border=0><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_ze_name'] . " : </strong></font></td>" .
"<td><input type=text name=name size=30 maxlength=30 value=\"$zoneinfo[zone_name]\"></td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_ze_allow'] . " " . $langvars['l_beacons'] . " : </strong></font></td>" .
"<td><input type=radio name=beacons value=Y $ybeacon> " . $langvars['l_yes'] . " <input type=radio name=beacons value=N $nbeacon> " . $langvars['l_no'] . " <input type=radio name=beacons value=L $lbeacon> " . $langvars['l_zi_limit'] . "</td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_ze_attacks'] . " : </strong></font></td>" .
"<td><input type=radio name=attacks value=Y $yattack> " . $langvars['l_yes'] . " <input type=radio name=attacks value=N $nattack> " . $langvars['l_no'] . "</td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_ze_allow'] . " " . $langvars['l_warpedit'] . " : </strong></font></td>" .
"<td><input type=radio name=warpedits value=Y $ywarpedit> " . $langvars['l_yes'] . " <input type=radio name=warpedits value=N $nwarpedit> " . $langvars['l_no'] . " <input type=radio name=warpedits value=L $lwarpedit> " . $langvars['l_zi_limit'] . "</td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_zi_allow'] . " " . $langvars['l_sector_def'] . " : </strong></font></td>" .
"<td><input type=radio name=defenses value=Y $ydefense> " . $langvars['l_yes'] . " <input type=radio name=defenses value=N $ndefense> " . $langvars['l_no'] . " <input type=radio name=defenses value=L $ldefense> " . $langvars['l_zi_limit'] . "</td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_ze_genesis'] . " : </strong></font></td>" .
"<td><input type=radio name=planets value=Y $yplanet> " . $langvars['l_yes'] . " <input type=radio name=planets value=N $nplanet> " . $langvars['l_no'] . " <input type=radio name=planets value=L $lplanet> " . $langvars['l_zi_limit'] . "</td>" .
"</tr><tr>" .
"<td align=right><font size=2><strong>" . $langvars['l_zi_allow'] . " " . $langvars['l_title_port'] . " : </strong></font></td>" .
"<td><input type=radio name=trades value=Y $ytrade> " . $langvars['l_yes'] . " <input type=radio name=trades value=N $ntrade> " . $langvars['l_no'] . " <input type=radio name=trades value=L $ltrade> " . $langvars['l_zi_limit'] . "</td>" .
"</tr><tr>" .
"<td colspan=2 align=center><br><input type=submit value=" . $langvars['l_submit'] . "></td></tr>" .
"</table>" .
"</form>";
echo "<a href=zoneinfo.php?zone=$zone>" . $langvars['l_clickme'] . "</a> " . $langvars['l_ze_return'] . ".<p>";
Tki\Text::gotoMain($pdo_db, $lang);
$footer = new Tki\Footer();
$footer->display($pdo_db, $lang, $tkireg, $tkitimer, $template);