Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
/**
* API Endpoint: Haal sessie statistieken op
* GET parameters:
* - session_id: Unieke sessie ID
*/
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
require_once 'config.php';
try {
$session_id = isset($_GET['session_id']) ? $_GET['session_id'] : null;
if (!$session_id) {
throw new Exception('Session ID required');
}
$pdo = getDbConnection();
// Haal sessie statistieken op
$stmt = $pdo->prepare("
SELECT
COUNT(*) as total_attempts,
SUM(correct) as total_correct,
SUM(attempts) as total_tries,
SUM(is_mastered) as mastered_words,
ROUND((SUM(correct) / COUNT(*)) * 100, 2) as success_rate
FROM user_progress
WHERE session_id = :session_id
");
$stmt->execute([':session_id' => $session_id]);
$stats = $stmt->fetch();
// Haal recente pogingen op
$stmt = $pdo->prepare("
SELECT up.*, w.english_word, w.dutch_translation, c.category_name
FROM user_progress up
JOIN words w ON up.word_id = w.word_id
JOIN categories c ON w.category_id = c.category_id
WHERE up.session_id = :session_id
ORDER BY up.last_attempt DESC
LIMIT 10
");
$stmt->execute([':session_id' => $session_id]);
$recent = $stmt->fetchAll();
echo json_encode([
'success' => true,
'stats' => $stats,
'recent_words' => $recent
]);
} catch (Exception $e) {
http_response_code(400);
echo json_encode([
'success' => false,
'error' => $e->getMessage()
]);
}