107 lines
1.8 KiB
PHP
107 lines
1.8 KiB
PHP
<?php
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/auth.php';
|
|
|
|
requireLogin();
|
|
|
|
$lang = $_GET['lang'] ?? '';
|
|
$list = $_GET['list'] ?? '';
|
|
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Oefenen</title>
|
|
<link rel="stylesheet" href="assets/css/style.css">
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container">
|
|
|
|
<div class="card">
|
|
|
|
<h1>Oefenen</h1>
|
|
|
|
<p>
|
|
Vertaal:
|
|
<strong id="question">...</strong>
|
|
</p>
|
|
|
|
<input id="answer" autocomplete="off">
|
|
|
|
<button onclick="check()">Controleer</button>
|
|
|
|
<p id="result"></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
let currentWord = null;
|
|
|
|
async function loadWord() {
|
|
|
|
const res = await fetch(
|
|
"api/next.php?lang=<?= $lang ?>&list=<?= $list ?>"
|
|
);
|
|
|
|
const data = await res.json();
|
|
|
|
if (!data.word) {
|
|
document.getElementById('question').innerText =
|
|
"Geen woordenlijst gevonden";
|
|
return;
|
|
}
|
|
|
|
currentWord = data.word;
|
|
|
|
document.getElementById('question').innerText =
|
|
currentWord.question;
|
|
|
|
document.getElementById('answer').value = '';
|
|
document.getElementById('result').innerText = '';
|
|
}
|
|
|
|
async function check() {
|
|
|
|
const answer =
|
|
document.getElementById('answer').value;
|
|
|
|
const res = await fetch('api/answer.php', {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
lang: "<?= $lang ?>",
|
|
list: "<?= $list ?>",
|
|
wordId: currentWord.id,
|
|
answer: answer
|
|
})
|
|
});
|
|
|
|
const data = await res.json();
|
|
|
|
const result = document.getElementById('result');
|
|
|
|
if (data.correct) {
|
|
result.innerText = "Goed";
|
|
result.style.color = "green";
|
|
} else {
|
|
result.innerText = "Fout";
|
|
result.style.color = "red";
|
|
}
|
|
|
|
setTimeout(loadWord, 700);
|
|
}
|
|
|
|
loadWord();
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|