52 lines
1001 B
PHP
52 lines
1001 B
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../includes/config.php';
|
|
require_once __DIR__ . '/../includes/functions.php';
|
|
require_once __DIR__ . '/../includes/jsondb.php';
|
|
require_once __DIR__ . '/../includes/auth.php';
|
|
|
|
requireLogin();
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
$user = $_SESSION['user'];
|
|
|
|
$lang = $_GET['lang'] ?? '';
|
|
$list = $_GET['list'] ?? '';
|
|
|
|
$file = listPath($user, $lang, $list);
|
|
$data = JsonDB::read($file);
|
|
|
|
if (!isset($data['words'])) {
|
|
echo json_encode(['error' => 'no_list']);
|
|
exit;
|
|
}
|
|
|
|
$words = $data['words'];
|
|
$today = date('Y-m-d');
|
|
|
|
/**
|
|
* 1. eerst due words
|
|
*/
|
|
$due = array_filter($words, function ($w) use ($today) {
|
|
return !isset($w['nextReview']) || $w['nextReview'] <= $today;
|
|
});
|
|
|
|
/**
|
|
* 2. fallback als alles “not due”
|
|
*/
|
|
if (count($due) === 0) {
|
|
$due = $words;
|
|
}
|
|
|
|
/**
|
|
* 3. BELANGRIJK: shuffle zodat het niet altijd hetzelfde eerste item is
|
|
*/
|
|
$due = array_values($due);
|
|
shuffle($due);
|
|
|
|
$word = $due[0];
|
|
|
|
echo json_encode([
|
|
'word' => $word
|
|
]); |