114 lines
1.9 KiB
PHP
114 lines
1.9 KiB
PHP
<?php
|
|
|
|
require_once 'includes/config.php';
|
|
require_once 'includes/auth.php';
|
|
require_once 'includes/functions.php';
|
|
require_once 'includes/jsondb.php';
|
|
|
|
requireLogin();
|
|
|
|
$user = $_SESSION['user'];
|
|
|
|
$lang = $_GET['lang'];
|
|
$list = $_GET['list'];
|
|
|
|
$file = listPath($user, $lang, $list);
|
|
|
|
$data = JsonDB::read($file);
|
|
|
|
if (!$data) {
|
|
die('Geen lijst');
|
|
}
|
|
|
|
// kies woord
|
|
require_once 'includes/srs_queue.php';
|
|
|
|
$words = $data['words'];
|
|
|
|
$words = sortDueWords($words);
|
|
|
|
$today = date('Y-m-d');
|
|
|
|
$due = array_filter($words, function ($w) use ($today) {
|
|
return !isset($w['nextReview']) || $w['nextReview'] <= $today;
|
|
});
|
|
|
|
if (count($due) > 0) {
|
|
$word = array_values($due)[0];
|
|
} else {
|
|
$word = $words[0];
|
|
}
|
|
?>
|
|
|
|
<!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><?= htmlspecialchars($word['question']) ?></strong>
|
|
</p>
|
|
|
|
<input id="answer" placeholder="jouw antwoord">
|
|
|
|
<button onclick="check()">
|
|
Controleer
|
|
</button>
|
|
|
|
<p id="result"></p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
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: <?= (int)$word['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(() => location.reload(), 800);
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|