<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");

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

$num = isset($_POST['num']) ? $_POST['num'] : '';
$tablename = isset($_POST['tablename']) ? $_POST['tablename'] : '';
$lotDone = isset($_POST['lotDone']) ? $_POST['lotDone'] : '';

// 데이터베이스 연결
$pdo = db_connect();

$response = ['success' => false];

if ($num && $tablename && $lotDone) {
    try {
        $pdo->beginTransaction();
        $sql = "UPDATE $DB.$tablename SET lotDone = ? WHERE num = ? LIMIT 1";
        $stmh = $pdo->prepare($sql);
        $stmh->bindValue(1, $lotDone, PDO::PARAM_STR);
        $stmh->bindValue(2, $num, PDO::PARAM_INT);
        $stmh->execute();
        $pdo->commit();

        $response['success'] = true;
    } catch (PDOException $Exception) {
        $pdo->rollBack();
        $response['error'] = $Exception->getMessage();
    }
} else {
    $response['error'] = '잘못된 요청입니다.';
}

// JSON 응답 반환
echo json_encode($response, JSON_UNESCAPED_UNICODE);
?>
