-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_armor.php
More file actions
208 lines (190 loc) · 8.2 KB
/
update_armor.php
File metadata and controls
208 lines (190 loc) · 8.2 KB
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
<?php
require_once 'database.php';
$con=mysqli_connect($db_host, $db_username, $db_password,$db_name);
$survivor_id = $_POST['id'];
if($_POST['type'] == 'insanity' || $_POST['type'] == 'box_insanity_1'){
$value = $_POST['value'];
$sql = "UPDATE insanity SET INSANITY ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$insanity = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM insanity WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" style="width:5%;" class="form-control update_armor" id="insanity" value='.($insanity['INSANITY'] >= 0 ? $insanity['INSANITY'] : 0).' >';
echo '<input class=".form-check-inline update_armor" type="checkbox" value="-1" id="box_insanity_1" '.($insanity['INSANITY'] <= -1 ? 'checked' : '').' >';
echo'<p>Brain. If your insanity is 3+, you are <strong>insane</strong></p>';
} else if($_POST['type'] == 'head' || $_POST['type'] == 'box_head_1'){
$value = $_POST['value'];
$sql = "UPDATE armor_stat SET HEAD ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$head = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM armor_stat WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" class="form-control update_armor" id="head" value='.($head['HEAD'] >= 0 ? $head['HEAD'] : 0).' >';
echo '<input class=".form-check-inline update_armor" type="checkbox" value="-1" id="box_head_1" '.($head['HEAD'] <= -1 ? 'checked' : '').' >';
echo '<input class=".form-check-inline update_armor" type="hidden" value="-1" id="box_head_1" '.($head['HEAD'] <= -1 ? 'checked' : '').' >';
} else if ($_POST['type'] == 'arm' || $_POST['type'] == 'arm_box_1' || $_POST['type'] == 'arm_box_2'){
$value = $_POST['value'];
$sql = "UPDATE armor_stat SET ARMS ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$arms = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM armor_stat WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" class="form-control update_armor" id="arm" value='.($arms['ARMS'] >= 0 ? $arms['ARMS'] : 0).'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-1" id="arm_box_1"'.($arms['ARMS'] < 0 ? 'checked' : '').'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-2" id="arm_box_2" '.($arms['ARMS'] < -1 ? 'checked' : '').'>';
}else if ($_POST['type'] == 'body' || $_POST['type'] == 'body_box_1' || $_POST['type'] == 'body_box_2'){
$value = $_POST['value'];
$sql = "UPDATE armor_stat SET BODY ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$body = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM armor_stat WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" class="form-control update_armor" id="body" value='.($body['BODY'] >= 0 ? $body['BODY'] : 0).'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-1" id="body_box_1" '.($body['BODY'] < 0 ? 'checked' : '').'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-2" id="body_box_2" '.($body['BODY'] < -1 ? 'checked' : '').'>';
}else if ($_POST['type'] == 'waist' || $_POST['type'] == 'waist_box_1' || $_POST['type'] == 'waist_box_2'){
$value = $_POST['value'];
$sql = "UPDATE armor_stat SET WAIST ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$waist = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM armor_stat WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" class="form-control update_armor" id="waist" value='.($waist['WAIST'] >= 0 ? $waist['WAIST'] : 0).'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-1" id="waist_box_1" '.($waist['WAIST'] < 0 ? 'checked' : '').'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-2" id="waist_box_2" '.($waist['WAIST'] < -1 ? 'checked' : '').'>';
}else if ($_POST['type'] == 'legs' || $_POST['type'] == 'legs_box_1' || $_POST['type'] == 'legs_box_2'){
$value = $_POST['value'];
$sql = "UPDATE armor_stat SET LEGS ='".$value."' WHERE ID_SURVIVOR='".$_POST['id']."'";
if ($con->query($sql) === TRUE) {
error_log('sucess');
} else {
error_log( "Error updating record: " . $con->error);
}
$legs = mysqli_fetch_assoc(mysqli_query($con, "SELECT * FROM armor_stat WHERE ID_SURVIVOR = $survivor_id"));
echo '<input type="text" class="form-control update_armor" id="legs" value='.($legs['LEGS'] >= 0 ? $legs['LEGS'] : 0).'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-1" id="legs_box_1" '.($legs['LEGS'] < 0 ? 'checked' : '').'>';
echo' <input class="form-check-input update_armor" type="checkbox" value="-2" id="legs_box_2" '.($legs['LEGS'] < -1 ? 'checked' : '').'>';
}
?>
<script>
$('.update_armor').off().on('change', function() {
var itemVal = $(this).val();
var character = <?php echo $survivor_id; ?>;
var itemID = $(this).attr('id');
if(itemID == 'insanity' && itemVal == '3'){
alert('You are INSANE!');
}
if ($(this).is('input:checkbox')){
switch (itemID) {
case 'box_insanity_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
alert('uncheckd ' + itemVal);
}
break;
case 'box_head_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
}
break;
case 'arm_box_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
}
break;
case 'arm_box_2':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = -1;
}
break;
case 'body_box_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
}
break;
case 'body_box_2':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = -1;
}
break;
case 'waist_box_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
}
break;
case 'waist_box_2':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = -1;
}
break;
case 'legs_box_1':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = 0;
}
break;
case 'legs_box_2':
var ischecked= $(this).is(':checked');
if(!ischecked){
itemVal = -1;
}
break;
}
}
$.ajax({
url: "update_armor.php",
type: 'POST',
data: { value: itemVal, id : character, type: itemID} ,
}).success(function(data){
switch (itemID) {
case 'insanity':
case 'box_insanity_1':
var section = '#update_insanity';
break;
case 'head':
case 'box_head_1':
var section = '#update_head';
break;
case 'arm':
case 'arm_box_1':
case 'arm_box_2':
var section = '#update_arms';
break;
case 'body':
case 'body_box_1':
case 'body_box_2':
var section = '#update_body';
break;
case 'waist':
case 'waist_box_1':
case 'waist_box_2':
var section = '#update_waist';
break;
case 'legs':
case 'legs_box_1':
case 'legs_box_2':
var section = '#update_legs';
break;
}
$(section).html(data);
});
});
</script>