- URL 하드코딩 → .env APP_URL 기반 동적 URL로 변경 - DB 연결 하드코딩 → .env 기반으로 변경 - MySQL strict mode DATE 오류 수정
55 lines
2.2 KiB
PHP
55 lines
2.2 KiB
PHP
<?php
|
|
include $_SERVER['DOCUMENT_ROOT'] . '/session.php';
|
|
header("Content-Type: application/json"); // JSON 응답을 위해 설정
|
|
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . "/lib/mydb.php");
|
|
$pdo = db_connect();
|
|
|
|
try {
|
|
// POST 데이터에서 author_list와 기타 정보를 가져옴
|
|
$authorList = isset($_POST['author_list']) ? json_decode($_POST['author_list'], true) : [];
|
|
$currentYear = $_POST['current_year'] ?? "";
|
|
|
|
if (empty($authorList)) {
|
|
echo json_encode(["status" => "error", "message" => "등록할 직원 정보가 없습니다."]);
|
|
exit;
|
|
}
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
$sql = "INSERT INTO {$DB}.almember (name, company, part, dateofentry, referencedate, availableday, service_based, initial_less_than_one_year)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
|
$stmh = $pdo->prepare($sql);
|
|
|
|
foreach ($authorList as $author) {
|
|
$name = $author['name'] ?? "";
|
|
$company = $author['company'] ?? "";
|
|
$part = $author['part'] ?? "";
|
|
$dateofentry = $author['dateofentry'] ?? '' ;
|
|
$availableday = $author['availableday'] ?? '' ;
|
|
$service_based = $author['service_based'] ?? '' ;
|
|
$initial_less_than_one_year = $author['initial_less_than_one_year'] ?? '' ;
|
|
|
|
|
|
// 각 직원의 데이터를 삽입
|
|
$stmh->bindValue(1, $name, PDO::PARAM_STR);
|
|
$stmh->bindValue(2, $company, PDO::PARAM_STR);
|
|
$stmh->bindValue(3, $part, PDO::PARAM_STR);
|
|
$stmh->bindValue(4, $dateofentry, PDO::PARAM_STR); // 입사일
|
|
$stmh->bindValue(5, $currentYear, PDO::PARAM_STR); // 해당 연도
|
|
$stmh->bindValue(6, $availableday, PDO::PARAM_INT); // 계산된 연차 발생일수
|
|
$stmh->bindValue(7, $service_based, PDO::PARAM_INT);
|
|
$stmh->bindValue(8, $initial_less_than_one_year, PDO::PARAM_INT);
|
|
$stmh->execute();
|
|
}
|
|
|
|
$pdo->commit();
|
|
|
|
echo json_encode(["status" => "success", "message" => "대량 등록이 성공적으로 완료되었습니다."]);
|
|
} catch (PDOException $e) {
|
|
$pdo->rollBack();
|
|
echo json_encode(["status" => "error", "message" => "DB 오류: " . $e->getMessage()]);
|
|
exit;
|
|
}
|
|
?>
|