(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');