Files
2026-06-11 18:47:38 +09:00

157 lines
8.6 KiB
PHP

<?php
if (!defined('_GNUBOARD_')) exit;
// $template 변수가 존재하면 '수정', 없으면 '추가'로 제목 설정
$g5['title'] = isset($template) && $template['id'] ? '메일 템플릿 수정' : '메일 템플릿 추가';
// [수정] DHTML 에디터를 사용하므로 admin.head.php를 먼저 include 합니다.
include_once(G5_ADMIN_PATH.'/admin.head.php');
// [수정] '추가' 모드일 때 기본 레이아웃을 로드하고, '수정' 모드일 때는 DB 데이터를 사용합니다.
if (isset($template) && $template['id']) {
// 수정 모드
$row = $template;
} else {
// 추가 모드: 기본 레이아웃 파일을 불러와 기본값을 설정합니다.
// 파일 경로는 사용자가 지정한 'mail_layout' 디렉토리를 사용합니다.
include_once(__DIR__.'/mail_layout/mail_layout.php');
$row = [
'id' => 0,
'code' => '',
'title' => '',
'content' => '<p>이곳에 메일 본문 내용을 입력하세요.</p>',
'header_html' => $default_header_html ?? '',
'footer_html' => $default_footer_html ?? '',
'is_use' => 1,
];
}
?>
<!-- [삭제] Summernote 관련 CSS, JS 링크를 모두 제거합니다. -->
<style>
/* 템플릿 폼 레이아웃을 위한 CSS */
.template-container { display: flex; gap: 20px; margin-top: 20px; }
.template-editor { flex: 3; } /* 에디터 영역을 더 넓게 */
.template-vars { flex: 1; background: #f9f9f9; padding: 15px; border: 1px solid #ddd; border-radius: 4px; }
.template-vars h3 { margin-top: 0; padding-bottom: 10px; border-bottom: 1px solid #eee; }
.template-vars label { display: block; margin-top: 10px; font-weight: bold; }
/* [추가] 헤더/푸터 textarea 스타일 */
.template-layout-editor { margin-bottom: 20px; }
.template-layout-editor h3 { margin: 0 0 5px; font-size: 1.1em; }
.template-layout-editor textarea { width: 100%; height: 150px; padding: 10px; border: 1px solid #ccc; border-radius: 4px; font-family: consolas, monospace; font-size: 1em; }
</style>
<div class="local_desc01 local_desc">
<p>
메일 내용에 <code>{변수명}</code> 형식으로 입력하면 오른쪽에 해당 변수에 대한 테스트 및 기본값 입력 창이 자동으로 생성됩니다.<br>
이곳에 입력된 값은 템플릿과 함께 저장되며, 실제 발송 시 다른 값으로 치환되지 않았을 때의 기본값으로 사용될 수 있습니다.
</p>
</div>
<!-- [수정] onsubmit 이벤트를 추가하여 에디터 내용을 전송前に textarea에 반영합니다. -->
<form name="templateForm" id="templateForm" method="post" action="./template.php" onsubmit="return form_check(this);">
<input type="hidden" name="action" value="<?php echo $row['id'] ? 'update' : 'create'; ?>">
<input type="hidden" name="id" value="<?php echo (int)$row['id']; ?>">
<input type="hidden" name="token" value="">
<div class="tbl_frm01 tbl_wrap">
<table>
<caption><?php echo $g5['title']; ?></caption>
<colgroup>
<col class="grid_4">
<col>
</colgroup>
<tbody>
<tr>
<th scope="row"><label for="code">템플릿 코드</label></th>
<td>
<input type="text" name="code" id="code" required class="required frm_input" size="40" value="<?php echo get_text($row['code']); ?>">
<?php if ($row['id']): ?>
<span class="frm_info">이 코드는 템플릿을 식별하는 고유 값이므로 변경에 주의하세요.</span>
<?php else: ?>
<span class="frm_info">영문, 숫자, 언더바(_)만 사용 가능하며, 다른 템플릿과 중복될 수 없습니다. (예: `member_join`)</span>
<?php endif; ?>
</td>
</tr>
<tr>
<th scope="row"><label for="title">이메일 제목</label></th>
<td>
<input type="text" name="title" id="title" required class="required frm_input" size="80" value="<?php echo get_text($row['title']); ?>" placeholder="예: {쇼핑몰명} - {username}님의 주문이 완료되었습니다.">
</td>
</tr>
<tr>
<th scope="row"><label for="is_use">사용 여부</label></th>
<td><input type="checkbox" name="is_use" id="is_use" value="1" <?php echo $row['is_use'] ? 'checked' : ''; ?>></td>
</tr>
</tbody>
</table>
<!-- [추가] 헤더 HTML 입력 영역 -->
<div class="template-layout-editor">
<h3>헤더 HTML</h3>
<p class="frm_info">메일 본문 내용 위에 위치할 상단 레이아웃입니다. (로고, 인사말 등) 변수 감지 기능은 지원하지 않습니다.</p>
<?php echo editor_html('header_html', get_text(stripslashes(htmlspecialchars_decode($row['header_html'], 1)))); ?>
</div>
<div class="template-container">
<div class="template-editor">
<h3>이메일 내용 (HTML)</h3>
<!-- [수정] GnuBoard DHTML 에디터(SmartEditor2)로 변경 -->
<!-- 메일의 핵심 본문 영역입니다. -->
<?php echo editor_html('content', get_text(stripslashes(htmlspecialchars_decode($row['content'], 1)))); ?>
</div>
<div class="template-vars">
<h3><strong>변수 기본값 설정</strong></h3>
<p class="frm_info">'이메일 내용' 영역에서 감지된 변수 목록입니다.</p>
<div id="variableInputs">
<!-- 변수 감지 시 이곳에 입력 필드가 자동으로 생성됩니다. -->
</div>
</div>
</div>
<div class="btn_confirm01 btn_confirm">
<!-- <a href="./template.php" class="btn_cancel btn">목록</a>-->
<!-- [개선] 변수 새로고침 버튼 추가 -->
<button type="button" onclick="refreshVariables()" class="btn">변수 새로고침</button>
<!-- <button type="button" onclick="previewTemplate()" class="btn">미리보기</button>-->
<!-- <input type="submit" value="저장하기" class="btn_submit btn" accesskey="s">-->
</div>
<!-- [추가] 푸터 HTML 입력 영역 -->
<div class="template-layout-editor" style="margin-top: 20px;">
<h3>푸터 HTML</h3>
<p class="frm_info">메일 본문 내용 아래에 위치할 하단 레이아웃입니다. (회사 정보, 저작권 등) 변수 감지 기능은 지원하지 않습니다.</p>
<?php echo editor_html('footer_html', get_text(stripslashes(htmlspecialchars_decode($row['footer_html'], 1)))); ?>
</div>
</div>
<div class="btn_confirm01 btn_confirm">
<a href="./template.php" class="btn_cancel btn">목록</a>
<!-- [개선] 변수 새로고침 버튼 추가 -->
<button type="button" onclick="refreshVariables()" class="btn">변수 새로고침</button>
<button type="button" onclick="previewTemplate()" class="btn">미리보기</button>
<input type="submit" value="저장하기" class="btn_submit btn" accesskey="s">
</div>
</form>
<!-- PHP의 템플릿 변수 데이터를 JavaScript에서 사용할 수 있도록 변환 -->
<script>
const serverVars = <?php echo json_encode($template_vars ?? []); ?>;
</script>
<?php
// [수정] template_form.js 파일을 GnuBoard의 add_javascript 함수를 통해 로드합니다.
// 이렇게 하면 jQuery 라이브러리가 먼저 로드된 후 이 스크립트가 실행되어 'jQuery is not defined' 오류를 해결합니다.
// URL은 웹 경로로 지정해야 합니다.
add_javascript('<script src="'.G5_ADMIN_URL.'/mail_manage/assets/js/template.js"></script>', 1);
add_javascript('<script src="'.G5_ADMIN_URL.'/mail_manage/assets/js/template_form.js"></script>', 1);
// [수정] GnuBoard DHTML 에디터의 JS 파일을 로드합니다.
// 이 함수는 에디터를 활성화하는 필수 스크립트를 생성하며, 반드시 호출해야 합니다.
//echo get_editor_js('header_html');
//echo get_editor_js('content');
//echo get_editor_js('footer_html');
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>