-
Notifications
You must be signed in to change notification settings - Fork 0
/
simulator.php
303 lines (245 loc) · 8.49 KB
/
simulator.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
<!doctype html>
<html
<head>
<!--- Responsive Platform --->
<meta name="viewport" content="width=device-width, initial-scale=1.0"&gt>
<meta charset="utf-8">
<meta name="robots" content="noindex">
<!--- Favicon --->
<link rel="apple-touch-icon" sizes="180x180" href="./images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./images/favicon-16x16.png">
<link rel="manifest" href="./images/site.webmanifest">
<meta name="msapplication-TileColor" content="#fade95">
<meta name="theme-color" content="#fade95">
<!--- Check JavaScript --->
<noscript>
<meta http-equiv="refresh" content="0;URL='./javascript_disabled.html'" />
</noscript>
<!--- CSS Style --->
<link rel="stylesheet" type="text/css" href="./simulator.css">
<title>Ghost Archery Simulator</title>
</head>
<main>
<body>
<!--- Check PHP URL Arguments --->
<?php
try {
// Get the values of the variables from the GET request
$max_points = $_GET["max_points"];
$min_points = $_GET["min_points"];
$type = $_GET["type"];
$location = $_GET["location"];
$modality = $_GET["modality"];
// Validate that all the variables are present
if (!isset($max_points)) {
throw new Exception("The value of the max_points variable could not be obtained.");
}
if (!isset($min_points)) {
throw new Exception("The value of the min_points variable could not be obtained.");
}
if (!isset($type)) {
throw new Exception("The value of the type variable could not be obtained.");
}
if (!isset($location)) {
throw new Exception("The value of the location variable could not be obtained.");
}
if (!isset($modality)) {
throw new Exception("The value of the modality variable could not be obtained.");
}
//Check that all variables meet the requirements
if (filter_var($max_points, FILTER_VALIDATE_INT) == false) {
throw new Exception("The value of the max_points variable needs to be a Int.");
}
if (filter_var($min_points, FILTER_VALIDATE_INT) == false) {
if ($min_points != 0){
throw new Exception("The value of the max_points variable needs to be a Int.");
}
}
if ($min_points < 0){
throw new Exception("The value of the max_points and the type value are incompatible");
}
if ( $max_points <= $min_points){
throw new Exception("The value of the max_points needs to be bigger than min_points");
}
if ( $type != "qualifiers"){
if ( $type != "competition"){
throw new Exception("The value of the type variable needs to be qualifiers or competition");
}
}
if ($type == "qualifiers"){
if ($max_points > 30){
throw new Exception("The value of the max_points and the type value are incompatible");
}
}
if ( $location != "indoor"){
if ( $type != "outdoor"){
throw new Exception("The value of the type variable needs to be indoor or outdoor");
}
}
if ($location == "indoor"){
if ($max_points > 30){
throw new Exception("The value of the max_points and the type & location value are incompatible");
}
}
if ($location == "outdoor"){
if ($type == "competition"){
if ($max_points > 60){
throw new Exception("The value of the max_points and the type & location value are incompatible");
}
}
}
if ( $modality != "compound"){
if ( $modality != "other"){
throw new Exception("The value of the type variable needs to be compound or other");
}
}
} catch (Exception $e) {
// Display an error message and redirect the user to the home page
echo '
<div class="simulation_form">
<h1>Error</h1>
<p>La configuración no se ha realizado correctamente, pulse le botón a continuación para volver a la página de configuración.</p>
<br>
<p>ERROR: ' . $e . '<p>
<a href="./"><button>Volver a la configuración</button></a>
</div>
';
die();
}
?>
<a href="./" ><button>🏠 Home</button></a>
<br>
<div class="simulation_form">
<p class="issue_message"> 💡 Consejo: Para poder acceder más rapido a la configuración que estas usando ahora mismo añade esta página como marcador</p>
<!--- Web Page Banner --->
<center>
<img src="./images/Archery_Ghost_Simulator.png" alt="Ghost Simulator Logo" width="150" height="150">
<h1>Simulator</h1>
</center>
<hr>
<!--- Simulator Setting Display --->
<h3>⚙️ Ajustes</h3>
<?php
//Max / Min Points
echo 'Puntos Máximos: ' . htmlspecialchars($_GET["max_points"]) . ' | ' . 'Puntos Mínimos: ' . htmlspecialchars($_GET["min_points"]);
//Location
echo ' | ';
if ($_GET["location"] == "indoor"){
echo 'Localización: Interior';
}
else{
echo 'Localización: Exterior';
}
//Type
echo ' | ';
if ($_GET["type"] == "qualifiers"){
echo 'Tipo: Eliminatorias';
}
else{
echo 'Tipo: Competición';
}
//Modality
echo ' | ';
if ($_GET["modality"] == "compound"){
echo 'Modalidad: Compuesto';
}
else{
echo 'Modalidad: Olímpico, Tradiciónal, LogBow o Desnudo';
}
//Competiton Split
// I have used this method replacing $_GET["competition_split"], because if the argument is not in the URL the server may generate WARNINGS or ERRORS.
$url = $_SERVER['REQUEST_URI'];
if (str_contains($url, "competition_split")) {
echo ' | ';
echo 'Media Competicion: Activado';
}
?>
<hr>
<!--- Simulator PHP Area --->
<?php
$max_points = $_GET["max_points"];
$min_points = $_GET["min_points"];
$type = $_GET["type"];
$location = $_GET["location"];
$modality = $_GET["modality"];
// Ghost Data Display
//Table Data Storage
//Ghost
$Ghost_R1 = rand($min_points, $max_points);
$Ghost_R2 = rand($min_points, $max_points);
$Ghost_R3 = rand($min_points, $max_points);
?>
<?php
//Users
$Users_R1 = $_POST['Users_R1'];
$Users_R2 = $_POST['Users_R2'];
$Users_R3 = $_POST['Users_R3'];
?>
<center>
<table class="simulator_table" id="ghost_table">
<center>
<h1>Ghost User</h1>
</center>
<tr>
<th>Entrada | </th>
<th>Total | </th>
<th>Entrada | </th>
<th>Total</th>
</tr>
<tr>
<td><?php echo $Ghost_R1; ?></td>
<td><?php echo $Ghost_R1; ?></td>
<td></td>
<td><?php echo $Ghost_R1_user; ?></td>
<td><?php echo $Users_R1; ?></td>
<td><input type="submit" value="Enviar" /></td>
</tr>
<tr>
<td hidden id="Row2_ghost"><?php echo $Ghost_R1; ?></td>
<td hidden id="Row2_total_ghost"><?php echo $Ghost_R1 + $Ghost_R2; ?></td>
<td hidden id="Row2_user"></td>
<td hidden id="Row2_total_user"><?php echo $Ghost_R1_user + $Ghost_R2_user; ?></td>
</tr>
<tr>
<td hidden id="Row3_ghost"><?php echo $Ghost_R3; ?></td>
<td hidden id="Row3_total_ghost"><?php echo $Ghost_R1 + $Ghost_R2 + $Ghost_R3; ?></td>
<td hidden id="Row3_user"></td>
<td hidden id="Row3_total_user"><?php echo $Ghost_R1_user + $Ghost_R2_user + $Ghost_R3_user; ?></td>
</tr>
</table>
</center>
<!--- Make table data visible --->
<br>
<center>
<button class="shadow__btn" id="hideButton">Siguiente</button>
</center>
<script>
const hideButton = document.getElementById('hideButton');
const rows = [null, 'Row2', 'Row3', 'Row4', 'Row5', 'Row6', 'Row7', 'Row8', 'Row9', 'Row10'];
const max_rows = 3
let current_row = 1;
hideButton.addEventListener('click', function() {
if (current_row <= max_rows) {
const row_ghost = document.getElementById(rows[current_row] + '_ghost');
const row_total_ghost = document.getElementById(rows[current_row] + '_total_ghost');
const row_user = document.getElementById(rows[current_row] + '_user');
const row_total_user = document.getElementById(rows[current_row] + '_total_user');
row_id.style.display = 'table-row';
row_total_id.style.display = 'table-cell';
current_row += 1;
}
if (current_row > max_rows) {
hideButton.style.display = 'hidden';
}
});
</script>
</div>
<br>
</body>
<footer>
<center><a href="https://piscinadeentropia.es">Creado por: Isaac Hernán Martí </a></center>
<center><a href="https://github.com/Isaaker/Ghost_Simulator_ES/blob/main/LICENSE.txt">© CC BY-NC-ND 4.0 </a></center>
</footer>
</main>
</html>