- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
100 lines
3.5 KiB
PHP
100 lines
3.5 KiB
PHP
<?php
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/session.php");
|
|
|
|
$tablename = isset($_REQUEST['tablename']) ? $_REQUEST['tablename'] : 'todos';
|
|
$mode = isset($_REQUEST['mode']) ? $_REQUEST['mode'] : '';
|
|
$num = isset($_REQUEST['num']) ? $_REQUEST['num'] : '';
|
|
|
|
header("Content-Type: application/json"); // Use JSON content type
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
include $_SERVER['DOCUMENT_ROOT'] . "/todo/_request.php"; // Ensure this file properly sets all needed variables
|
|
|
|
if ($mode == "update") {
|
|
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
|
try {
|
|
$pdo->beginTransaction();
|
|
$sql = "UPDATE " . $DB . "." . $tablename . " SET
|
|
orderdate = ?, towhom = ?, reply = ?, deadline = ?, work_status = ?, title = ?,
|
|
first_writer = ?, update_log = ?, searchtag = ?
|
|
WHERE num = ? LIMIT 1";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
|
|
$stmh->bindValue(1, $orderdate, PDO::PARAM_STR);
|
|
$stmh->bindValue(2, $towhom, PDO::PARAM_STR);
|
|
$stmh->bindValue(3, $reply, PDO::PARAM_STR);
|
|
$stmh->bindValue(4, $deadline, PDO::PARAM_STR);
|
|
$stmh->bindValue(5, $work_status, PDO::PARAM_STR);
|
|
$stmh->bindValue(6, $title, PDO::PARAM_STR);
|
|
$stmh->bindValue(7, $first_writer, PDO::PARAM_STR);
|
|
$stmh->bindValue(8, $update_log, PDO::PARAM_STR);
|
|
$stmh->bindValue(9, $searchtag, PDO::PARAM_STR);
|
|
$stmh->bindValue(10, $num, PDO::PARAM_INT);
|
|
|
|
$stmh->execute();
|
|
$pdo->commit();
|
|
} catch (PDOException $Exception) {
|
|
$pdo->rollBack();
|
|
echo json_encode(["error" => $Exception->getMessage()], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
if ($mode == "insert" || $mode == '' || $mode == null) {
|
|
$update_log = date("Y-m-d H:i:s") . " - " . $_SESSION["name"] . " " . $update_log . "
";
|
|
try {
|
|
$pdo->beginTransaction();
|
|
$sql = "INSERT INTO " . $DB . "." . $tablename . " (
|
|
orderdate, towhom, reply, deadline, work_status, title,
|
|
first_writer, update_log, searchtag
|
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
$stmh = $pdo->prepare($sql);
|
|
|
|
$stmh->bindValue(1, $orderdate, PDO::PARAM_STR);
|
|
$stmh->bindValue(2, $towhom, PDO::PARAM_STR);
|
|
$stmh->bindValue(3, $reply, PDO::PARAM_STR);
|
|
$stmh->bindValue(4, $deadline, PDO::PARAM_STR);
|
|
$stmh->bindValue(5, $work_status, PDO::PARAM_STR);
|
|
$stmh->bindValue(6, $title, PDO::PARAM_STR);
|
|
$stmh->bindValue(7, $first_writer, PDO::PARAM_STR);
|
|
$stmh->bindValue(8, $update_log, PDO::PARAM_STR);
|
|
$stmh->bindValue(9, $searchtag, PDO::PARAM_STR);
|
|
|
|
$stmh->execute();
|
|
$pdo->commit();
|
|
} catch (PDOException $Exception) {
|
|
$pdo->rollBack();
|
|
echo json_encode(["error" => $Exception->getMessage()], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
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()], JSON_UNESCAPED_UNICODE);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$data = [
|
|
'num' => $num,
|
|
'title' => $title,
|
|
'orderdate' => $orderdate,
|
|
'mode' => $mode
|
|
];
|
|
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
?>
|