- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
164 lines
6.8 KiB
PHP
164 lines
6.8 KiB
PHP
<?php
|
|
// /guiderail/process.php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
|
|
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : 'guiderail';
|
|
$selectWork = isset($_REQUEST['selectWork']) ? $_REQUEST['selectWork'] : '';
|
|
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
|
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
|
|
|
|
header("Content-Type: application/json");
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
// 전개도 데이터 처리인 경우
|
|
if ($selectWork == 'unfold') {
|
|
$bending_components = isset($_REQUEST['bending_components']) ? $_REQUEST['bending_components'] : '';
|
|
$material_summary = isset($_REQUEST['material_summary']) ? $_REQUEST['material_summary'] : '';
|
|
} else {
|
|
// 기존 코드
|
|
include "_request.php"; // num, registration_date, ..., bending_components 변수 할당
|
|
}
|
|
|
|
if ($selectWork == 'unfold') {
|
|
try {
|
|
$pdo->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);
|
|
?>
|