99 lines
3.7 KiB
PHP
99 lines
3.7 KiB
PHP
<?php
|
|
// 1. 환경 설정 및 필수 파일 포함 (가장 먼저 실행)
|
|
$sub_menu = "600200"; // 메뉴 활성화를 위한 코드
|
|
include_once("./_common.php"); // 그누보드 관리자 공통 파일
|
|
require_once(__DIR__ . '/classes/TemplateManager.php'); // 템플릿 관리 클래스
|
|
|
|
// 2. 권한 확인
|
|
auth_check_menu($auth, $sub_menu, "r");
|
|
|
|
// 3. 객체 생성 및 변수 초기화
|
|
$templateManager = new TemplateManager();
|
|
$action = $_REQUEST['action'] ?? ''; // GET 또는 POST로 받은 action
|
|
$id = (int)($_REQUEST['id'] ?? 0); // GET 또는 POST로 받은 id
|
|
|
|
// 4. 요청 처리 (POST, GET)
|
|
|
|
// 4-1. POST 요청 처리 (생성, 수정)
|
|
if ($action && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
// 데이터 변경 작업이므로 쓰기(w) 권한을 확인합니다.
|
|
auth_check_menu($auth, $sub_menu, 'w');
|
|
// CSRF 토큰을 체크하여 유효한 요청인지 확인합니다.
|
|
check_admin_token();
|
|
|
|
try {
|
|
if ($action === 'create' || $action === 'update') {
|
|
// 템플릿 폼에서 넘어온 올바른 데이터를 받습니다.
|
|
$data = [
|
|
'id' => (int)($_POST['id'] ?? 0),
|
|
'code' => $_POST['code'] ?? '',
|
|
'title' => $_POST['title'] ?? '',
|
|
'content' => $_POST['content'] ?? '',
|
|
'header_html' => $_POST['header_html'] ?? '',
|
|
'footer_html' => $_POST['footer_html'] ?? '',
|
|
'is_use' => isset($_POST['is_use']) ? 1 : 0,
|
|
'variables' => $_POST['variables'] ?? [], // 변수 기본값 배열
|
|
];
|
|
|
|
// TemplateManager의 save() 메소드로 데이터를 저장합니다.
|
|
$templateManager->save($data);
|
|
alert('메일 템플릿이 성공적으로 저장되었습니다.', './template.php');
|
|
}
|
|
} catch (Exception $e) {
|
|
alert('작업 중 오류가 발생했습니다: ' . $e->getMessage());
|
|
}
|
|
|
|
goto_url('./template.php');
|
|
exit;
|
|
}
|
|
|
|
// 4-2. [개선] GET 요청 처리 (삭제)
|
|
if ($action === 'delete' && $id > 0) {
|
|
// 삭제(d) 권한을 확인하고, 토큰을 체크합니다. (CSRF 공격 방지)
|
|
auth_check_menu($auth, $sub_menu, 'd');
|
|
check_admin_token();
|
|
|
|
$templateManager->delete($id);
|
|
|
|
alert('선택한 템플릿을 삭제했습니다.', './template.php');
|
|
exit;
|
|
}
|
|
|
|
// 5. 뷰(View) 처리: action 값에 따라 다른 페이지를 보여줌
|
|
$g5['title'] = '메일 템플릿 관리';
|
|
|
|
// 5-1. 템플릿 생성 또는 수정 폼을 보여줘야 할 때
|
|
if ($action === 'create_form' || $action === 'edit_form') {
|
|
$template = null;
|
|
$template_vars = [];
|
|
|
|
if ($action === 'edit_form') {
|
|
if (!$id) {
|
|
alert('잘못된 접근입니다.');
|
|
}
|
|
$template = $templateManager->getById($id);
|
|
if (!$template) {
|
|
alert('존재하지 않는 템플릿입니다.');
|
|
}
|
|
// DB에서 이 템플릿의 변수와 기본값들을 가져옴
|
|
$template_vars = $templateManager->getVarsByTemplateId($id);
|
|
}
|
|
|
|
// [핵심 수정 1] DHTML 에디터 라이브러리 파일을 포함합니다.
|
|
// 이 파일에 editor_html(), get_editor_js() 함수가 정의되어 있습니다.
|
|
include_once(G5_EDITOR_LIB);
|
|
|
|
include_once(__DIR__ . '/templates/template_from.php');
|
|
exit;
|
|
}
|
|
|
|
// 5-2. 기본 동작: 템플릿 목록 페이지를 보여줌
|
|
include_once(G5_ADMIN_PATH . '/admin.head.php');
|
|
|
|
// [핵심 수정 2] getAll() 메소드는 이미 배열을 반환하므로, while 루프 없이 바로 변수에 할당합니다.
|
|
$template_list_data = $templateManager->getAll();
|
|
|
|
// template_list.php 파일을 불러와 목록을 표시합니다.
|
|
include(__DIR__ . '/templates/template_list.php');
|
|
|
|
include_once(G5_ADMIN_PATH . '/admin.tail.php'); |