<?php
require_once '../includes/auth.php';
require_once '../includes/config.php';

if (!isPenguji()) {
    die(json_encode(['success' => false, 'message' => 'Access denied']));
}

$station_id = $_POST['station_id'] ?? null;
$peserta_id = $_POST['peserta_id'] ?? null;
$ujian_id = $_POST['ujian_id'] ?? null;
$penguji_id = $_SESSION['user_id'];

if (!$station_id || !$peserta_id || !$ujian_id) {
    die(json_encode(['success' => false, 'message' => 'Missing parameters']));
}

$stmt = $pdo->prepare("
    SELECT global_performance 
    FROM penilaian_global 
    WHERE ujian_id = ? AND peserta_id = ? AND station_id = ? AND penguji_id = ?
");
$stmt->execute([$ujian_id, $peserta_id, $station_id, $penguji_id]);
$result = $stmt->fetch();

if ($result) {
    echo json_encode([
        'success' => true,
        'global_performance' => $result['global_performance']
    ]);
} else {
    echo json_encode([
        'success' => false,
        'global_performance' => null
    ]);
}
?>