Files
sam-kd/holiday/process.php
hskwon aca1767eb9 초기 커밋: 5130 레거시 시스템
- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경
- DB 연결 하드코딩 → .env 기반으로 변경
- MySQL strict mode DATE 오류 수정
2025-12-10 20:14:31 +09:00

93 lines
3.0 KiB
PHP

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
$tablename = 'holiday';
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
header("Content-Type: application/json"); // Use JSON content type
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
$pdo = db_connect();
include "_request.php";
// 검색 태그 생성 (등록일자와 코멘트를 조합)
$searchtag = $registedate . ' ' . $comment;
if ($mode == "update") {
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "&#10";
try {
$pdo->beginTransaction();
$sql = "UPDATE " . $DB . "." . $tablename . " SET ";
$sql .= "registedate = ?, startdate = ?, enddate = ?, periodcheck = ?, comment = ?, searchtag = ?, update_log = ? ";
$sql .= "WHERE num = ? LIMIT 1"; // Update only one record matching the 'num'
$stmh = $pdo->prepare($sql);
$stmh->bindValue(1, $registedate, PDO::PARAM_STR);
$stmh->bindValue(2, $startdate, PDO::PARAM_STR);
$stmh->bindValue(3, $enddate, PDO::PARAM_STR);
$stmh->bindValue(4, $periodcheck, PDO::PARAM_INT);
$stmh->bindValue(5, $comment, PDO::PARAM_STR);
$stmh->bindValue(6, $searchtag, PDO::PARAM_STR);
$stmh->bindValue(7, $update_log, PDO::PARAM_STR);
$stmh->bindValue(8, $num, PDO::PARAM_INT);
$stmh->execute();
$pdo->commit();
} catch (PDOException $Exception) {
$pdo->rollBack();
print "오류: " . $Exception->getMessage();
}
}
if ($mode == "insert" || $mode == '' || $mode == null) {
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "&#10";
try {
$pdo->beginTransaction();
$sql = "INSERT INTO " . $DB . "." . $tablename . " (";
$sql .= "registedate, startdate, enddate, periodcheck, comment, searchtag, update_log ";
$sql .= ") VALUES (?, ?, ?, ?, ?, ?, ?)";
$stmh = $pdo->prepare($sql);
$stmh->bindValue(1, $registedate, PDO::PARAM_STR);
$stmh->bindValue(2, $startdate, PDO::PARAM_STR);
$stmh->bindValue(3, $enddate, PDO::PARAM_STR);
$stmh->bindValue(4, $periodcheck, PDO::PARAM_INT);
$stmh->bindValue(5, $comment, PDO::PARAM_STR);
$stmh->bindValue(6, $searchtag, PDO::PARAM_STR);
$stmh->bindValue(7, $update_log, PDO::PARAM_STR);
$stmh->execute();
$pdo->commit();
} catch (PDOException $Exception) {
$pdo->rollBack();
print "오류: " . $Exception->getMessage();
}
}
if ($mode == "delete") { // Data deletion
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();
print "오류: ".$ex->getMessage();
}
}
$data = [
'num' => $num,
'mode' => $mode
];
echo json_encode($data, JSON_UNESCAPED_UNICODE);
?>