Files
dnssash/adm/order_manage/sms_template_form.php
2026-06-11 18:47:38 +09:00

146 lines
4.8 KiB
PHP

<?php
$sub_menu = "800600";
include_once("./_common.php");
auth_check_menu($auth, $sub_menu, "r");
$id = (int) $_GET['id'];
$template = sql_fetch("SELECT * FROM order_sms_templates WHERE id = {$id}");
if (!$template) {
alert('템플릿을 찾을 수 없습니다.', './sms_templates.php');
}
$g5['title'] = "SMS 템플릿 수정";
include_once(G5_ADMIN_PATH . '/admin.head.php');
$variables = json_decode($template['variables'], true);
?>
<div class="local_ov01 local_ov">
SMS 템플릿 수정 - <?php echo htmlspecialchars($template['template_name']); ?>
</div>
<form name="templateForm" method="post" action="sms_template_update.php">
<input type="hidden" name="id" value="<?php echo $template['id']; ?>">
<div class="tbl_frm01 tbl_wrap">
<table>
<caption>SMS 템플릿 수정</caption>
<colgroup>
<col class="grid_4">
<col>
</colgroup>
<tbody>
<tr>
<th scope="row">템플릿명</th>
<td>
<input type="text" name="template_name"
value="<?php echo htmlspecialchars($template['template_name']); ?>" class="frm_input"
style="width:100%;" required>
</td>
</tr>
<tr>
<th scope="row">SMS 내용</th>
<td>
<textarea name="content" id="sms_content" class="frm_input" style="width:100%; height:150px;"
onkeyup="checkSMSLength();"
required><?php echo htmlspecialchars($template['content']); ?></textarea>
<div id="sms_length_info">
<span id="current_length">0</span> / 80 바이트
(<span id="current_chars">0</span> / 40 글자)
<span id="length_warning" style="color: red; display: none;">SMS 길이 초과!</span>
</div>
<div class="frm_info">한글 1글자 = 2바이트, 영문/숫자 1글자 = 1바이트</div>
</td>
</tr>
<tr>
<th scope="row">사용 가능한 변수</th>
<td>
<?php if (is_array($variables)) { ?>
<?php foreach ($variables as $var) { ?>
<span class="variable-tag"
onclick="insertVariable('{<?php echo $var; ?>}')">{<?php echo $var; ?>}</span>
<?php } ?>
<?php } ?>
<div class="frm_info">변수를 클릭하면 SMS 내용에 삽입됩니다.</div>
</td>
</tr>
</tbody>
</table>
</div>
<div class="btn_confirm01 btn_confirm">
<input type="submit" value="저장" class="btn_submit">
<a href="sms_templates.php" class="btn btn_02">목록</a>
</div>
</form>
<style>
.variable-tag {
display: inline-block;
background: #e8f5e8;
color: #2e7d32;
padding: 2px 8px;
margin: 2px;
border-radius: 12px;
font-size: 12px;
font-family: monospace;
cursor: pointer;
}
.variable-tag:hover {
background: #c8e6c9;
}
#sms_length_info {
margin-top: 5px;
font-size: 12px;
color: #666;
}
</style>
<script>
function checkSMSLength() {
const content = document.getElementById('sms_content').value;
let byteLength = 0;
for (let i = 0; i < content.length; i++) {
const char = content.charAt(i);
byteLength += (escape(char).length > 4) ? 2 : 1;
}
document.getElementById('current_length').textContent = byteLength;
document.getElementById('current_chars').textContent = content.length;
const warning = document.getElementById('length_warning');
if (byteLength > 80) {
warning.style.display = 'inline';
} else {
warning.style.display = 'none';
}
}
function insertVariable(variable) {
const textarea = document.getElementById('sms_content');
const cursorPos = textarea.selectionStart;
const textBefore = textarea.value.substring(0, cursorPos);
const textAfter = textarea.value.substring(cursorPos);
textarea.value = textBefore + variable + textAfter;
textarea.focus();
textarea.setSelectionRange(cursorPos + variable.length, cursorPos + variable.length);
checkSMSLength();
}
// 페이지 로드 시 길이 체크
document.addEventListener('DOMContentLoaded', function () {
checkSMSLength();
});
</script>
<?php
include_once(G5_ADMIN_PATH . '/admin.tail.php');
?>