diff --git a/api/next.php b/api/next.php index 4067fd6..96f8fe9 100644 --- a/api/next.php +++ b/api/next.php @@ -3,12 +3,11 @@ require_once __DIR__ . '/../includes/config.php'; require_once __DIR__ . '/../includes/functions.php'; require_once __DIR__ . '/../includes/jsondb.php'; -require_once __DIR__ . '/../includes/srs_queue.php'; require_once __DIR__ . '/../includes/auth.php'; requireLogin(); -header('Content-Type: application/json; charset=utf-8'); +header('Content-Type: application/json'); $user = $_SESSION['user']; @@ -18,25 +17,33 @@ $list = $_GET['list'] ?? ''; $file = listPath($user, $lang, $list); $data = JsonDB::read($file); -if (!isset($data['words']) || !is_array($data['words'])) { - echo json_encode(['error' => 'list_not_found']); +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; } -// pak altijd eerste uit gesorteerde set (stabiel gedrag) +/** + * 3. BELANGRIJK: shuffle zodat het niet altijd hetzelfde eerste item is + */ $due = array_values($due); +shuffle($due); $word = $due[0];