-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
213 lines (209 loc) · 9.53 KB
/
index.php
File metadata and controls
213 lines (209 loc) · 9.53 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
209
210
211
212
213
<?php
session_start();
if (isset($_SESSION['points'])) {
unset($_SESSION['points']);
}
if (isset($_SESSION['name'])){
$_SESSION['name'] = preg_replace('/\s*\(permadeath\)$/i', '', $_SESSION['name']);
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CipherType</title>
<link href="https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400..800;1,400..800&family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Nunito:ital,wght@0,200..1000;1,200..1000&family=Oswald:[email protected]&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles.css?no-cache=<?php echo time(); ?>">
<link rel="icon" href="media/lupa.ico">
</head>
<body class="play">
<?php
if (isset($_SESSION['name'])) {
echo "<div class='cancelSession'>";
echo "<p>". $_SESSION['lang_data']['TEXT_NAME'].": ".$_SESSION['name']."</p>";
echo "<button type='submit' id='closeSession' onclick='destroySession()'>". $_SESSION['lang_data']['TEXT_LOGOUT']."</button>";
echo "</div>";
}
if (!isset($_POST['lenguageselect']) && !isset($_SESSION['selected_lang'])) {
echo "<div class='languageMain'>";
echo "<form method='post'>";
echo "<select name='lenguageselect' id='lenguageselect' onchange='this.form.submit()'>";
echo "<option value='' selected disabled hidden>CASTELLANO</option>";
$archivo = fopen('idiomas.txt', 'r');
if ($archivo) {
while (($linea = fgets($archivo)) !== false) {
$linea = trim($linea);
if ($linea === '') continue;
if (strpos($linea, '[') === 0 && substr($linea, -1) === ']') {
$idioma = substr($linea, 1, -1); // quita los corchetes
echo "<option value='".$idioma."'>".$idioma."</option>";
}
}
fclose($archivo);
}
echo "</select>";
echo "</form>";
echo "</div>";
} else {
if (isset($_POST['lenguageselect'])) {
$idiomaSeleccionado = $_POST['lenguageselect'];
if (isset($_SESSION['name'])) {
$mensaje = $_SESSION['name']. " se a cambiado al idioma " . $idiomaSeleccionado;
} else {
$mensaje = "Un usuario se a cambiado al idioma " . $idiomaSeleccionado;
}
$fecha = date("Y-m-d H:i:s");
$archivo = basename(__FILE__);
$linea = "[$fecha] [$archivo] $mensaje" . PHP_EOL;
file_put_contents("admin/logs.txt", $linea, FILE_APPEND);
$_SESSION['selected_lang'] = $idiomaSeleccionado;
$_SESSION['lang_data'] = [];
$archivo = fopen('idiomas.txt', 'r');
$dentroIdioma = false;
while (($linea = fgets($archivo)) !== false) {
$linea = trim($linea);
if ($linea === '') continue;
if (strpos($linea, '[') === 0 && substr($linea, -1) === ']') {
$idiomaActual = substr($linea, 1, -1);
$dentroIdioma = ($idiomaActual === $idiomaSeleccionado);
continue;
}
if ($dentroIdioma && strpos($linea, '=') !== false) {
list($clave, $valor) = explode('=', $linea, 2);
$clave = trim($clave);
if (str_contains($valor, '|')) {
$valor = trim($valor, "\"|\t ");
$_SESSION['lang_data'][$clave] = array_map(
fn($v) => trim($v, '"'),
explode('|', $valor)
);
} else {
$valor = trim($valor, "\"\t ");
$_SESSION['lang_data'][$clave] = $valor;
}
}
}
fclose($archivo);
}
echo "<div class='maincontainer'>";
echo "<form method='post'>";
echo "<select name='lenguageselect' class='rightpositionlenguage' id='lenguageselect' onchange='this.form.submit()'>";
echo "<option value='' selected disabled hidden>".$_SESSION['selected_lang']."</option>";
$archivo = fopen('idiomas.txt', 'r');
if ($archivo) {
while (($linea = fgets($archivo)) !== false) {
$linea = trim($linea);
if ($linea === '') continue;
if (strpos($linea, '[') === 0 && substr($linea, -1) === ']') {
$idioma = substr($linea, 1, -1); // quita los corchetes
echo "<option value='".$idioma."'>".$idioma."</option>";
}
}
fclose($archivo);
}
echo "</select>";
echo "</form>";
echo "<form action='./play.php' method='post' class='datacontainer'>";
echo "<h1>CipherType</h1>";
echo "<div class='incontainer'>";
echo '<input type="text" id="inname" name="inname" placeholder="' . $_SESSION['lang_data']['TEXT_NAME_GAME'] . '">';
echo "<select name='indifficulty' id='indifficulty'>";
echo "<option value='sencillo'>" . $_SESSION['lang_data']['DIFFICULTY_SIMPLE'] . "</option>";
echo "<option value='normal'>" . $_SESSION['lang_data']['DIFFICULTY_NORMAL'] . "</option>";
echo "<option value='experto'>" . $_SESSION['lang_data']['DIFFICULTY_EXPERT'] . "</option>";
echo "</select>";
echo "";
echo "<button type='submit' id='buttonInitialitze' disabled>" . $_SESSION['lang_data']['TEXT_INITIALITZE'] . "</button>";
echo "<div id='checkboxWithExplicationButton'>";
echo "<p id='textPermaDeath'>permadeath</p>";
echo "<input type='checkbox' name='permadeath' id='checkbox'>";
echo "<div id='explicationButton'>?<p>".$_SESSION['lang_data']["TEXT_EXPLICATION_PERMADEATH"]."</p></div>";
echo "</div>";
echo "<p id='messageerror' class='error'></p>";
echo "<noscript>";
echo "<p class='error'>" . $_SESSION['lang_data']['TEXT_ERROR_JAVASCRIPT'] . "</p>";
echo "</noscript>";
echo "</div>";
echo "</form>";
echo "<div class='datacontainer'>";
echo "<h1>Descripción</h1>";
echo "<p>" . $_SESSION['lang_data']['DESCRIPTION_GAME'] . "</p>";
echo "</div>";
echo "</div>";
echo "<img class='mesa' src='media/mesamesa.jpg' alt='" . $_SESSION['lang_data']['ALT_MESA'] . "'>";
echo "<div class='machine'>";
echo "<img class='typingMachine' src='media/typingmachine.png' alt='" . $_SESSION['lang_data']['ALT_MACHINE'] . "'>";
echo "</div>";
}
?>
<script>
document.getElementById('buttonInitialitze').disabled = false;
const closeSession = document.getElementById("closeSession");
const destroySession = () => {
window.location = "/destroy_session.php";
}
const buttonInitialitzeGame = document.getElementById('buttonInitialitze');
document.querySelector("#indifficulty").disabled = false;
document.querySelector("#buttonInitialitze").disabled = false;
const input = document.getElementById('inname');
buttonInitialitzeGame.addEventListener("click", (event) => {
if (input.value.trim() === "") {
event.preventDefault();
const message = document.getElementById('messageerror');
message.textContent = "<?php echo $_SESSION['lang_data']['TEXT_ERROR_NAME'];?>";
}
});
const selectedLang = "<?php echo isset($_SESSION['selected_lang']) ? $_SESSION['selected_lang'] : ''; ?>";
document.addEventListener("keydown", (event) => {
if (event.target.nodeName === "INPUT") return;
if (selectedLang === "CASTELLANO") {
if (event.key.toLowerCase() === "i") {
buttonInitialitzeGame.classList.add("highlightButtonText");
setTimeout(() => {
buttonInitialitzeGame.click();
}, 1000);
} else if (event.key.toLowerCase() === "c") {
closeSession.classList.add("highlightButtonText");
setTimeout(() => {
closeSession.click();
}, 1000);
}
} else if (selectedLang === "CATALÁN"){
if (event.key.toLowerCase() === "i") {
buttonInitialitzeGame.classList.add("highlightButtonText");
setTimeout(() => {
buttonInitialitzeGame.click();
}, 1000);
} else if (event.key.toLowerCase() === "t") {
closeSession.classList.add("highlightButtonText");
setTimeout(() => {
closeSession.click();
}, 1000);
}
} else if (selectedLang === "ENGLISH"){
if (event.key.toLowerCase() === "i") {
buttonInitialitzeGame.classList.add("highlightButtonText");
setTimeout(() => {
buttonInitialitzeGame.click();
}, 1000);
} else if (event.key.toLowerCase() === "l") {
closeSession.classList.add("highlightButtonText");
setTimeout(() => {
closeSession.click();
}, 1000);
}
}
});
const valueName = "<?php
if (isset($_SESSION['name'])){
echo $_SESSION['name'];
} else{
echo '';
} ?>";
if (valueName !== ''){
input.value = valueName;
}
</script>
</body>
</html>