91 lines
4.3 KiB
PHP
91 lines
4.3 KiB
PHP
<?php
|
|
// 💡 [수정] 관리자 인증을 건너뛰기 위해 `_common.php` 대신 `common.php`를 직접 포함합니다.
|
|
// 이렇게 하면 일반 사용자가 로그인 없이도 이 파일에 접근하여 문의를 저장할 수 있습니다.
|
|
include_once(__DIR__ . '/_common.php');
|
|
|
|
// `_common.php`에 정의된 테이블 상수를 여기서 직접 정의합니다.
|
|
$g5['contact_inquiry_table'] = G5_TABLE_PREFIX . 'contact_inquiry';
|
|
|
|
$response = [
|
|
'success' => false,
|
|
'message' => '알 수 없는 오류가 발생했습니다.'
|
|
];
|
|
|
|
try {
|
|
// POST 데이터가 없으면 오류 처리
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
throw new Exception('잘못된 요청 방식입니다.');
|
|
}
|
|
|
|
$contact_subject = isset($_POST['contact_subject']) ? trim($_POST['contact_subject']) : '';
|
|
$contact_name = isset($_POST['contact_name']) ? trim($_POST['contact_name']) : '';
|
|
$contact_hp = isset($_POST['contact_hp']) ? trim($_POST['contact_hp']) : '';
|
|
$contact_zip = isset($_POST['contact_zip']) ? trim($_POST['contact_zip']) : '';
|
|
$contact_addr1 = isset($_POST['contact_addr1']) ? trim($_POST['contact_addr1']) : '';
|
|
$contact_addr2 = isset($_POST['contact_addr2']) ? trim($_POST['contact_addr2']) : '';
|
|
$contact_message = isset($_POST['contact_message']) ? trim($_POST['contact_message']) : '';
|
|
|
|
if (empty($contact_name) || empty($contact_hp) || empty($contact_message)) {
|
|
throw new Exception('필수 입력 항목이 누락되었습니다.');
|
|
}
|
|
|
|
// SQL Injection 방지를 위해 escaping
|
|
$contact_subject = sql_real_escape_string($contact_subject);
|
|
$contact_name = sql_real_escape_string($contact_name);
|
|
$contact_hp = sql_real_escape_string($contact_hp);
|
|
$contact_zip = sql_real_escape_string($contact_zip);
|
|
$contact_addr1 = sql_real_escape_string($contact_addr1);
|
|
$contact_addr2 = sql_real_escape_string($contact_addr2);
|
|
$contact_message = sql_real_escape_string($contact_message);
|
|
|
|
$sql = " INSERT INTO {$g5['contact_inquiry_table']}
|
|
SET contact_subject = '{$contact_subject}',
|
|
contact_name = '{$contact_name}',
|
|
contact_hp = '{$contact_hp}',
|
|
contact_zip = '{$contact_zip}',
|
|
contact_addr1 = '{$contact_addr1}',
|
|
contact_addr2 = '{$contact_addr2}',
|
|
contact_message = '{$contact_message}',
|
|
created_at = '" . G5_TIME_YMDHIS . "',
|
|
status = 'new' ";
|
|
|
|
// 테이블 존재 여부 확인 (테이블이 없어서 에러나는 경우 방지)
|
|
$table_check = sql_query(" DESCRIBE {$g5['contact_inquiry_table']} ", false);
|
|
if (!$table_check) {
|
|
// 테이블이 없으면 자동 생성 시도
|
|
$create_sql = "
|
|
CREATE TABLE IF NOT EXISTS `{$g5['contact_inquiry_table']}` (
|
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
|
`contact_subject` varchar(255) NOT NULL DEFAULT '' COMMENT '문의 항목 (주거형태 등)',
|
|
`contact_name` varchar(255) NOT NULL DEFAULT '' COMMENT '이름',
|
|
`contact_hp` varchar(255) NOT NULL DEFAULT '' COMMENT '연락처',
|
|
`contact_zip` varchar(10) NOT NULL DEFAULT '' COMMENT '우편번호',
|
|
`contact_addr1` varchar(255) NOT NULL DEFAULT '' COMMENT '기본 주소',
|
|
`contact_addr2` varchar(255) NOT NULL DEFAULT '' COMMENT '상세 주소',
|
|
`contact_message` text NOT NULL COMMENT '문의 내용',
|
|
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '작성일',
|
|
`status` varchar(20) NOT NULL DEFAULT 'new' COMMENT '상태 (new, read, done)',
|
|
PRIMARY KEY (`id`)
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='상담 문의 내역';
|
|
";
|
|
sql_query($create_sql);
|
|
}
|
|
|
|
if (sql_query($sql)) {
|
|
$response['success'] = true;
|
|
$response['message'] = '상담 신청이 성공적으로 저장되었습니다.';
|
|
} else {
|
|
throw new Exception('데이터베이스 저장 중 오류가 발생했습니다.');
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
// 버퍼 비우기 (혹시 모를 공백이나 경고 메시지 제거)
|
|
ob_clean();
|
|
|
|
header('Content-Type: application/json');
|
|
echo json_encode($response);
|
|
exit;
|
|
?>
|