first commit 2
This commit is contained in:
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
$sub_menu = '710300';
|
||||
include_once('./_common.php');
|
||||
|
||||
auth_check_menu($auth, $sub_menu, "w");
|
||||
|
||||
$mode = isset($_POST['mode']) ? $_POST['mode'] : '';
|
||||
$st_id = isset($_POST['st_id']) ? (int)$_POST['st_id'] : 0;
|
||||
|
||||
if (!$mode) {
|
||||
alert('잘못된 접근입니다.');
|
||||
}
|
||||
|
||||
// 기본 정보
|
||||
$st_name = isset($_POST['st_name']) ? trim($_POST['st_name']) : '';
|
||||
$st_description = isset($_POST['st_description']) ? trim($_POST['st_description']) : '';
|
||||
$st_category = isset($_POST['st_category']) ? trim($_POST['st_category']) : '기타';
|
||||
$st_is_public = isset($_POST['st_is_public']) ? (int)$_POST['st_is_public'] : 1;
|
||||
|
||||
if (!$st_name) {
|
||||
alert('템플릿 이름을 입력해주세요.');
|
||||
}
|
||||
|
||||
// 질문 데이터
|
||||
$questions = isset($_POST['questions']) ? $_POST['questions'] : array();
|
||||
|
||||
if (empty($questions)) {
|
||||
alert('최소 1개 이상의 질문을 추가해주세요.');
|
||||
}
|
||||
|
||||
if ($mode == 'insert') {
|
||||
// 새 템플릿 생성
|
||||
$sql = "INSERT INTO survey_templates
|
||||
(st_name, st_description, st_category, st_is_public, st_created_by, st_created_at)
|
||||
VALUES
|
||||
('".sql_real_escape_string($st_name)."',
|
||||
'".sql_real_escape_string($st_description)."',
|
||||
'".sql_real_escape_string($st_category)."',
|
||||
'$st_is_public',
|
||||
'{$member['mb_id']}',
|
||||
NOW())";
|
||||
|
||||
sql_query($sql);
|
||||
$st_id = sql_insert_id();
|
||||
|
||||
if (!$st_id) {
|
||||
alert('템플릿 생성에 실패했습니다.');
|
||||
}
|
||||
|
||||
} else if ($mode == 'update') {
|
||||
// 기존 템플릿 수정
|
||||
if (!$st_id) {
|
||||
alert('템플릿 ID가 없습니다.');
|
||||
}
|
||||
|
||||
$sql = "UPDATE survey_templates SET
|
||||
st_name = '".sql_real_escape_string($st_name)."',
|
||||
st_description = '".sql_real_escape_string($st_description)."',
|
||||
st_category = '".sql_real_escape_string($st_category)."',
|
||||
st_is_public = '$st_is_public',
|
||||
st_updated_at = NOW()
|
||||
WHERE st_id = '$st_id'";
|
||||
|
||||
sql_query($sql);
|
||||
|
||||
// 기존 질문들 삭제
|
||||
sql_query("DELETE FROM survey_template_questions WHERE st_id = '$st_id'");
|
||||
}
|
||||
|
||||
// 질문들 저장
|
||||
foreach ($questions as $order => $question) {
|
||||
$stq_title = isset($question['stq_title']) ? trim($question['stq_title']) : '';
|
||||
$stq_description = isset($question['stq_description']) ? trim($question['stq_description']) : '';
|
||||
$stq_type = isset($question['stq_type']) ? trim($question['stq_type']) : 'text';
|
||||
$stq_required = isset($question['stq_required']) ? 1 : 0;
|
||||
$stq_options = '';
|
||||
|
||||
if (!$stq_title) {
|
||||
continue; // 제목이 없는 질문은 건너뛰기
|
||||
}
|
||||
|
||||
// 옵션 처리 (객관식 질문인 경우)
|
||||
if (in_array($stq_type, ['radio', 'checkbox', 'select']) && isset($question['options'])) {
|
||||
$options = array_filter($question['options'], function($option) {
|
||||
return trim($option) !== '';
|
||||
});
|
||||
|
||||
if (!empty($options)) {
|
||||
$stq_options = json_encode(array_values($options), JSON_UNESCAPED_UNICODE);
|
||||
}
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO survey_template_questions
|
||||
(st_id, stq_order, stq_type, stq_title, stq_description, stq_required, stq_options, stq_created_at)
|
||||
VALUES
|
||||
('$st_id',
|
||||
'".($order + 1)."',
|
||||
'".sql_real_escape_string($stq_type)."',
|
||||
'".sql_real_escape_string($stq_title)."',
|
||||
'".sql_real_escape_string($stq_description)."',
|
||||
'$stq_required',
|
||||
'".sql_real_escape_string($stq_options)."',
|
||||
NOW())";
|
||||
|
||||
sql_query($sql);
|
||||
}
|
||||
|
||||
$message = $mode == 'insert' ? '템플릿이 생성되었습니다.' : '템플릿이 수정되었습니다.';
|
||||
alert($message, 'template_list.php');
|
||||
?>
|
||||
Reference in New Issue
Block a user