forked from thekabal/tki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preset.php
106 lines (94 loc) · 4.21 KB
/
preset.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
<?php
// The Kabal Invasion - A web-based 4X space game
// Copyright © 2014 The Kabal Invasion development team, Ron Harwood, and the BNT development team
//
// 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/>.
//
// File: preset.php
require_once './common.php';
Tki\Login::checkLogin($pdo_db, $lang, $tkireg, $template);
$langvars = Tki\Translate::load($pdo_db, $lang, array('presets'));
$title = $langvars['l_pre_title'];
$body_class = 'tki';
Tki\Header::display($pdo_db, $lang, $template, $title, $body_class);
// Database driven language entries
$langvars = Tki\Translate::load($pdo_db, $lang, array('presets', 'common', 'global_includes', 'global_funcs', 'combat', 'footer', 'news'));
echo "<h1>" . $title . "</h1>\n";
echo "<body class ='" . $body_class . "'>";
// Get playerinfo from database
$sql = "SELECT * FROM ::prefix::ships WHERE email=:email LIMIT 1";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':email', $_SESSION['username']);
$stmt->execute();
$playerinfo = $stmt->fetch(PDO::FETCH_ASSOC);
// Pull the presets for the player from the db.
$sql = "SELECT * FROM ::prefix::presets WHERE ship_id=:ship_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':ship_id', $playerinfo['ship_id']);
$stmt->execute();
$presetinfo = $stmt->fetchAll(PDO::FETCH_ASSOC);
$preset_list = array();
// Filter the array of presets from the form submission
if (array_key_exists('preset', $_POST))
{
foreach ($_POST['preset'] as $key => $value)
{
// Returns null if it doesn't have it set, bool false if its set but fails to validate and the actual value if it all passes.
$preset_list[$key] = filter_var($_POST['preset'][$key], FILTER_VALIDATE_INT, array('options' => array('min_range' => 1, 'max_range' => $tkireg->max_sectors)));
}
}
$change = filter_input(INPUT_POST, 'change', FILTER_VALIDATE_INT, array('options' => array('min_range' => 0, 'max_range' => 1)));
foreach ($preset_list as $index => $preset)
{
if ($preset === false)
{
$change = 0;
$result = str_replace("[preset]", $_POST['preset'][$index], $langvars['l_pre_exceed']);
$result = str_replace("[max_sectors]", $tkireg->max_sectors, $result);
$result = htmlentities($result, ENT_QUOTES | ENT_HTML5, 'UTF-8');
echo $result . "<br>\n";
}
}
echo "<br>\n";
if ($change !== 1)
{
echo "<form accept-charset='utf-8' action='preset.php' method='post'>";
for ($x = 0; $x < $tkireg->max_presets; $x++)
{
echo "<div style='padding:2px;'>Preset " . ($x + 1) . ": <input type='text' name='preset[$x]' size='6' maxlength='6' value='" . $presetinfo[$x]['preset'] . "'></div>";
}
echo "<input type='hidden' name='change' value='1'>";
echo "<div style='padding:2px;'><input type='submit' value=" . $langvars['l_pre_save'] . "></div>";
echo "</form>";
echo "<br>\n";
}
else
{
foreach ($_POST['preset'] as $key => $value)
{
if ($key < $tkireg->max_presets)
{
$sql = "UPDATE ::prefix::presets SET preset=:preset WHERE preset_id=:preset_id";
$stmt = $pdo_db->prepare($sql);
$stmt->bindParam(':preset', $preset_list[key]);
$stmt->bindParam(':preset_id', $presetinfo[key]['preset_id']);
$stmt->execute();
$preset_result_echo = str_replace("[preset]", "<a href=rsmove.php?engage=1&destination=$preset_list[$key]>$preset_list[$key]</a>", $langvars['l_pre_set_loop']);
$preset_result_echo = str_replace("[num]", $key + 1, $preset_result_echo);
echo $preset_result_echo . "<br>";
}
}
}
Tki\Text::gotoMain($pdo_db, $lang);
Tki\Footer::display($pdo_db, $lang, $tkireg, $template);