Files
woordjes/api/next.php
T
2026-06-15 12:21:20 +02:00

45 lines
991 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/srs_queue.php';
require_once __DIR__ . '/../includes/auth.php';
requireLogin();
header('Content-Type: application/json; charset=utf-8');
$user = $_SESSION['user'];
$lang = $_GET['lang'] ?? '';
$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']);
exit;
}
$words = $data['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) {
$due = $words;
}
// pak altijd eerste uit gesorteerde set (stabiel gedrag)
$due = array_values($due);
$word = $due[0];
echo json_encode([
'word' => $word
]);