<?php
include($_SERVER['DOCUMENT_ROOT'] . '/includes/include_all.inc.php');

header('Content-Type: application/json');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $caseId = $_POST['caseId'];
    $caseGrade = $_POST['caseGrade'];
    $caseScore = $_POST['caseScore'];
    $userData = $_POST['userData'];
    $instructorNotes = $_POST['instructorNotes'];

    $stmt = $pdo->prepare("UPDATE wp_groupusers_data SET case_grade = ?, case_score = ?, user_data = ?, instructor_notes = ? WHERE id = ?");
    $result = $stmt->execute([$caseGrade, $caseScore, $userData, $instructorNotes, $caseId]);

    if ($result) {
        echo json_encode(['success' => true]);
    } else {
        echo json_encode(['success' => false, 'error' => 'Failed to update case']);
    }
} else {
    echo json_encode(['success' => false, 'error' => 'Invalid request method']);
}