beginTransaction(); $sql = "UPDATE {$DB}.{$tablename} SET bending_components = :bending_components, material_summary = :material_summary WHERE num = :num LIMIT 1"; $stmh = $pdo->prepare($sql); // 파라미터 바인딩 $stmh->bindValue(':bending_components', $bending_components); // 스냅샷 JSON 저장 $stmh->bindValue(':material_summary', $material_summary); // 자재요약 JSON 저장 $stmh->bindValue(':num', $num, PDO::PARAM_INT); $stmh->execute(); $pdo->commit(); } catch (PDOException $Exception) { $pdo->rollBack(); echo json_encode(['error' => $Exception->getMessage()]); exit; } } else { // --- [수정] --- if ($mode == "modify") { $update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . (isset($update_log) ? $update_log : '') . " "; try { $pdo->beginTransaction(); $sql = "UPDATE {$DB}.{$tablename} SET registration_date = :registration_date, check_type = :check_type, author = :author, remark = :remark, update_log = :update_log, model_name = :model_name, rail_width = :rail_width, rail_length = :rail_length, finishing_type = :finishing_type, bending_components = :bending_components, firstitem = :firstitem, search_keyword = :search_keyword, model_UA = :model_UA, material_summary = :material_summary WHERE num = :num LIMIT 1"; $stmh = $pdo->prepare($sql); // 파라미터 바인딩 $stmh->bindValue(':registration_date', $registration_date); $stmh->bindValue(':check_type', $check_type); $stmh->bindValue(':author', $author); $stmh->bindValue(':remark', $remark); $stmh->bindValue(':update_log', $update_log); $stmh->bindValue(':model_name', $model_name); $stmh->bindValue(':rail_width', $rail_width); $stmh->bindValue(':rail_length', $rail_length); $stmh->bindValue(':finishing_type', $finishing_type); $stmh->bindValue(':bending_components', $bending_components); // 스냅샷 JSON 저장 $stmh->bindValue(':firstitem', $firstitem); $stmh->bindValue(':search_keyword', $search_keyword); $stmh->bindValue(':model_UA', $model_UA); $stmh->bindValue(':material_summary', $material_summary); // 자재요약 JSON 저장 $stmh->bindValue(':num', $num, PDO::PARAM_INT); $stmh->execute(); $pdo->commit(); } catch (PDOException $Exception) { $pdo->rollBack(); echo json_encode(['error' => $Exception->getMessage()]); exit; } } else if ($mode == "insert" || $mode == "copy") { $update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . (isset($update_log) ? $update_log : '') . " "; try { $pdo->beginTransaction(); $sql = "INSERT INTO {$DB}.{$tablename} ( registration_date, check_type, author, remark, update_log, model_name, rail_width, rail_length, finishing_type, bending_components, firstitem, search_keyword, model_UA, material_summary ) VALUES ( :registration_date, :check_type, :author, :remark, :update_log, :model_name, :rail_width, :rail_length, :finishing_type, :bending_components, :firstitem, :search_keyword, :model_UA, :material_summary )"; $stmh = $pdo->prepare($sql); $stmh->bindValue(':registration_date', $registration_date); $stmh->bindValue(':check_type', $check_type); $stmh->bindValue(':author', $author); $stmh->bindValue(':remark', $remark); $stmh->bindValue(':update_log', $update_log); $stmh->bindValue(':model_name', $model_name); $stmh->bindValue(':rail_width', $rail_width); $stmh->bindValue(':rail_length', $rail_length); $stmh->bindValue(':finishing_type', $finishing_type); $stmh->bindValue(':bending_components', $bending_components); // 스냅샷 JSON 저장 $stmh->bindValue(':firstitem', $firstitem); $stmh->bindValue(':search_keyword', $search_keyword); $stmh->bindValue(':model_UA', $model_UA); $stmh->bindValue(':material_summary', $material_summary); // 자재요약 JSON 저장 $stmh->execute(); $num = $pdo->lastInsertId(); $pdo->commit(); } catch (PDOException $Exception) { $pdo->rollBack(); echo json_encode(['error' => $Exception->getMessage()]); exit; } } // (삭제 로직은 동일) else if ($mode == "delete") { try { $pdo->beginTransaction(); $sql = "UPDATE {$DB}.{$tablename} SET is_deleted=1 WHERE num = ?"; $stmh = $pdo->prepare($sql); $stmh->bindValue(1, $num, PDO::PARAM_INT); $stmh->execute(); $pdo->commit(); } catch (PDOException $ex) { $pdo->rollBack(); echo json_encode(['error' => $ex->getMessage()]); exit; } } } // 최종 성공 응답 $data = [ 'num' => $num, 'mode' => $mode ]; echo json_encode($data, JSON_UNESCAPED_UNICODE); ?>