230 lines
13 KiB
PHP
230 lines
13 KiB
PHP
<?php
|
|
$sub_menu = '710300';
|
|
include_once('./_common.php');
|
|
|
|
auth_check_menu($auth, $sub_menu, "w");
|
|
|
|
$st_id = isset($_GET['st_id']) ? (int)$_GET['st_id'] : 0;
|
|
$is_edit = $st_id > 0;
|
|
|
|
$template = [
|
|
'st_name' => '',
|
|
'st_description' => '',
|
|
'st_category' => '고객서비스',
|
|
'st_is_public' => 1
|
|
];
|
|
|
|
$questions = [];
|
|
|
|
if ($is_edit) {
|
|
$template = sql_fetch("SELECT * FROM survey_templates WHERE st_id = '$st_id'");
|
|
if (!$template) {
|
|
alert('존재하지 않는 템플릿입니다.', 'template_list.php');
|
|
}
|
|
|
|
// 템플릿 질문들 가져오기
|
|
$question_sql = "SELECT * FROM survey_template_questions WHERE st_id = '$st_id' ORDER BY stq_order ASC";
|
|
$question_result = sql_query($question_sql);
|
|
while ($question = sql_fetch_array($question_result)) {
|
|
$questions[] = $question;
|
|
}
|
|
|
|
$g5['title'] = '템플릿 수정';
|
|
} else {
|
|
$g5['title'] = '새 템플릿 만들기';
|
|
}
|
|
|
|
include_once(G5_ADMIN_PATH.'/admin.head.php');
|
|
?>
|
|
|
|
<!-- CSS는 template_form.css 파일에서 자동 로드됩니다 -->
|
|
|
|
<div class="template-form-container">
|
|
<div class="form-header">
|
|
<h1><i class="fa fa-magic"></i> <?php echo $is_edit ? '템플릿 수정' : '새 템플릿 만들기'; ?></h1>
|
|
<p>설문 템플릿을 만들어 다른 사용자들과 공유하세요</p>
|
|
</div>
|
|
|
|
<div class="form-content">
|
|
<form name="templateForm" method="post" action="template_form_update.php">
|
|
<?php if ($is_edit): ?>
|
|
<input type="hidden" name="st_id" value="<?php echo $st_id; ?>">
|
|
<input type="hidden" name="mode" value="update">
|
|
<?php else: ?>
|
|
<input type="hidden" name="mode" value="insert">
|
|
<?php endif; ?>
|
|
|
|
<div class="form-section">
|
|
<h2 class="section-title">
|
|
<i class="fa fa-info-circle"></i> 기본 정보
|
|
</h2>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label required">템플릿 이름</label>
|
|
<input type="text" name="st_name" class="form-control"
|
|
value="<?php echo htmlspecialchars($template['st_name']); ?>"
|
|
placeholder="템플릿 이름을 입력하세요" required>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">템플릿 설명</label>
|
|
<textarea name="st_description" class="form-control" rows="3"
|
|
placeholder="템플릿에 대한 설명을 입력하세요"><?php echo htmlspecialchars($template['st_description']); ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label class="form-label required">카테고리</label>
|
|
<select name="st_category" class="form-control form-select" required>
|
|
<option value="고객서비스"<?php echo $template['st_category'] == '고객서비스' ? ' selected' : ''; ?>>고객서비스</option>
|
|
<option value="마케팅"<?php echo $template['st_category'] == '마케팅' ? ' selected' : ''; ?>>마케팅</option>
|
|
<option value="제품개발"<?php echo $template['st_category'] == '제품개발' ? ' selected' : ''; ?>>제품개발</option>
|
|
<option value="인사관리"<?php echo $template['st_category'] == '인사관리' ? ' selected' : ''; ?>>인사관리</option>
|
|
<option value="기타"<?php echo $template['st_category'] == '기타' ? ' selected' : ''; ?>>기타</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">공개 설정</label>
|
|
<select name="st_is_public" class="form-control form-select">
|
|
<option value="1"<?php echo $template['st_is_public'] == 1 ? ' selected' : ''; ?>>공개</option>
|
|
<option value="0"<?php echo $template['st_is_public'] == 0 ? ' selected' : ''; ?>>비공개</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-section">
|
|
<h2 class="section-title">
|
|
<i class="fa fa-question-circle"></i> 질문 구성
|
|
</h2>
|
|
|
|
<div class="questions-container" id="questionsContainer">
|
|
<?php if (count($questions) > 0): ?>
|
|
<?php foreach ($questions as $index => $question): ?>
|
|
<div class="question-item" data-index="<?php echo $index; ?>">
|
|
<div class="question-header">
|
|
<div class="question-number"><?php echo $index + 1; ?></div>
|
|
<div class="question-title-text">질문 <?php echo $index + 1; ?></div>
|
|
<div class="question-actions">
|
|
<button type="button" class="btn-sm btn-secondary" onclick="moveQuestion(<?php echo $index; ?>, 'up')">
|
|
<i class="fa fa-arrow-up"></i>
|
|
</button>
|
|
<button type="button" class="btn-sm btn-secondary" onclick="moveQuestion(<?php echo $index; ?>, 'down')">
|
|
<i class="fa fa-arrow-down"></i>
|
|
</button>
|
|
<button type="button" class="btn-sm btn-danger" onclick="removeQuestion(<?php echo $index; ?>)">
|
|
<i class="fa fa-trash"></i>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
|
|
<input type="hidden" name="questions[<?php echo $index; ?>][stq_id]" value="<?php echo $question['stq_id']; ?>">
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label class="form-label">질문 제목</label>
|
|
<input type="text" name="questions[<?php echo $index; ?>][stq_title]" class="form-control"
|
|
value="<?php echo htmlspecialchars($question['stq_title']); ?>"
|
|
placeholder="질문을 입력하세요" required>
|
|
</div>
|
|
|
|
<div class="form-group question-type-group">
|
|
<label class="form-label">질문 유형</label>
|
|
<select name="questions[<?php echo $index; ?>][stq_type]" class="form-control form-select question-type-select"
|
|
onchange="toggleOptions(<?php echo $index; ?>)">
|
|
<option value="text"<?php echo $question['stq_type'] == 'text' ? ' selected' : ''; ?>>단답형</option>
|
|
<option value="textarea"<?php echo $question['stq_type'] == 'textarea' ? ' selected' : ''; ?>>장문형</option>
|
|
<option value="radio"<?php echo $question['stq_type'] == 'radio' ? ' selected' : ''; ?>>객관식(단일)</option>
|
|
<option value="checkbox"<?php echo $question['stq_type'] == 'checkbox' ? ' selected' : ''; ?>>객관식(다중)</option>
|
|
<option value="select"<?php echo $question['stq_type'] == 'select' ? ' selected' : ''; ?>>드롭다운</option>
|
|
<option value="rating"<?php echo $question['stq_type'] == 'rating' ? ' selected' : ''; ?>>평점</option>
|
|
<option value="date"<?php echo $question['stq_type'] == 'date' ? ' selected' : ''; ?>>날짜</option>
|
|
<option value="email"<?php echo $question['stq_type'] == 'email' ? ' selected' : ''; ?>>이메일</option>
|
|
<option value="number"<?php echo $question['stq_type'] == 'number' ? ' selected' : ''; ?>>숫자</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label class="form-label">질문 설명 (선택사항)</label>
|
|
<textarea name="questions[<?php echo $index; ?>][stq_description]" class="form-control" rows="2"
|
|
placeholder="질문에 대한 추가 설명"><?php echo htmlspecialchars($question['stq_description']); ?></textarea>
|
|
</div>
|
|
|
|
<div class="form-row">
|
|
<div class="form-group">
|
|
<label>
|
|
<input type="checkbox" name="questions[<?php echo $index; ?>][stq_required]" value="1"
|
|
<?php echo $question['stq_required'] ? 'checked' : ''; ?>>
|
|
필수 질문
|
|
</label>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (in_array($question['stq_type'], ['radio', 'checkbox', 'select'])): ?>
|
|
<div class="options-container" id="optionsContainer<?php echo $index; ?>">
|
|
<label class="form-label">선택 옵션</label>
|
|
<?php
|
|
$options = json_decode($question['stq_options'], true);
|
|
if (is_array($options)):
|
|
foreach ($options as $opt_index => $option):
|
|
?>
|
|
<div class="option-item">
|
|
<input type="text" name="questions[<?php echo $index; ?>][options][]"
|
|
class="form-control option-input"
|
|
value="<?php echo htmlspecialchars($option); ?>"
|
|
placeholder="옵션을 입력하세요">
|
|
<button type="button" class="btn-sm btn-danger" onclick="removeOption(this)">
|
|
<i class="fa fa-times"></i>
|
|
</button>
|
|
</div>
|
|
<?php
|
|
endforeach;
|
|
endif;
|
|
?>
|
|
<button type="button" class="btn-add-option" onclick="addOption(<?php echo $index; ?>)">
|
|
<i class="fa fa-plus"></i> 옵션 추가
|
|
</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php else: ?>
|
|
<div class="empty-questions" id="emptyQuestions">
|
|
<i class="fa fa-question-circle"></i>
|
|
<h3>질문을 추가해주세요</h3>
|
|
<p>아래 버튼을 클릭하여 첫 번째 질문을 만들어보세요.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<button type="button" class="btn-add-question" onclick="addQuestion()">
|
|
<i class="fa fa-plus"></i> 질문 추가
|
|
</button>
|
|
</div>
|
|
|
|
<div class="form-actions">
|
|
<button type="submit" class="btn-primary">
|
|
<i class="fa fa-save"></i> <?php echo $is_edit ? '템플릿 수정' : '템플릿 저장'; ?>
|
|
</button>
|
|
<a href="template_list.php" class="btn-primary btn-outline">
|
|
<i class="fa fa-times"></i> 취소
|
|
</a>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- JavaScript는 template_form.js 파일에서 자동 로드됩니다 -->
|
|
<script>
|
|
// 페이지별 초기 데이터 설정
|
|
window.templateFormData = {
|
|
questionIndex: <?php echo count($questions); ?>,
|
|
isEdit: <?php echo $is_edit ? 'true' : 'false'; ?>
|
|
};
|
|
</script>
|
|
|
|
<?php
|
|
include_once(G5_ADMIN_PATH.'/admin.tail.php');
|
|
?>
|