380 lines
15 KiB
PHP
380 lines
15 KiB
PHP
<?php
|
|
$sub_menu = "800750";
|
|
include_once('./_common.php');
|
|
|
|
auth_check($auth[$sub_menu], 'r');
|
|
|
|
$g5['title'] = '알림 발송 테스트';
|
|
|
|
// NotificationHelper 로드
|
|
require_once G5_PATH . '/adm/order_manage/classes/NotificationHelper.class.php';
|
|
|
|
// 액션 처리
|
|
$action = isset($_REQUEST['action']) ? clean_xss_tags($_REQUEST['action']) : '';
|
|
|
|
if ($action && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
auth_check($auth[$sub_menu], 'w');
|
|
|
|
try {
|
|
if ($action === 'test_notification') {
|
|
$template_type = clean_xss_tags($_POST['template_type'] ?? '');
|
|
$template_key = clean_xss_tags($_POST['template_key'] ?? '');
|
|
$notification_type = clean_xss_tags($_POST['notification_type'] ?? '');
|
|
$test_recipient = clean_xss_tags($_POST['test_recipient'] ?? '');
|
|
|
|
if (!$template_key || !$notification_type || !$test_recipient) {
|
|
throw new Exception('필수 항목을 모두 입력해주세요.');
|
|
}
|
|
|
|
// 수신자 유효성 검증
|
|
if ($notification_type === 'email' && !filter_var($test_recipient, FILTER_VALIDATE_EMAIL)) {
|
|
throw new Exception('유효하지 않은 이메일 주소입니다.');
|
|
}
|
|
|
|
if ($notification_type === 'sms') {
|
|
$test_recipient = preg_replace('/[^0-9]/', '', $test_recipient);
|
|
if (!preg_match('/^01[0-9]{8,9}$/', $test_recipient)) {
|
|
throw new Exception('유효하지 않은 전화번호입니다.');
|
|
}
|
|
}
|
|
|
|
// 테스트 데이터 준비
|
|
$test_data = [
|
|
'customer_name' => '테스트 고객',
|
|
'customer_email' => $notification_type === 'email' ? $test_recipient : 'test@example.com',
|
|
'customer_phone' => $notification_type === 'sms' ? $test_recipient : '01012345678',
|
|
'estimate_id' => 'TEST-001',
|
|
'estimate_subject' => '테스트 견적 요청',
|
|
'total_amount' => '1,500,000',
|
|
'visit_fee' => '50,000',
|
|
'account_info' => '국민은행 123-456-789012 (주)창호전문',
|
|
'dealer_name' => '테스트 대리점',
|
|
'construction_date' => '2024-02-15',
|
|
'visit_datetime' => '2024-02-10 14:00',
|
|
'interim_payment_date' => '2024-02-13',
|
|
'days_remaining' => '2',
|
|
'bid_amount' => '1,200,000',
|
|
'selected_date' => date('Y-m-d H:i')
|
|
];
|
|
|
|
$notification_helper = new NotificationHelper();
|
|
|
|
// 알림 발송
|
|
if ($template_type === 'customer') {
|
|
$result = $notification_helper->sendCustomerNotification($template_key, $test_data);
|
|
} elseif ($template_type === 'dealer') {
|
|
$result = $notification_helper->sendDealerNotification($template_key, $test_data);
|
|
} else {
|
|
throw new Exception('유효하지 않은 템플릿 타입입니다.');
|
|
}
|
|
|
|
if ($result['success']) {
|
|
$message = '테스트 알림이 성공적으로 발송되었습니다.';
|
|
if (isset($result['debug_info'])) {
|
|
$message .= '\n\n디버그 정보: ' . $result['debug_info'];
|
|
}
|
|
alert($message);
|
|
} else {
|
|
throw new Exception('알림 발송 실패: ' . $result['message']);
|
|
}
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
alert('오류: ' . $e->getMessage());
|
|
}
|
|
|
|
goto_url('./notification_test.php');
|
|
exit;
|
|
}
|
|
|
|
// 템플릿 목록 조회
|
|
$email_templates = [];
|
|
$sms_templates = [];
|
|
|
|
$email_sql = "SELECT template_key, template_name FROM order_mail_templates ORDER BY template_key ASC";
|
|
$email_result = sql_query($email_sql);
|
|
while ($row = sql_fetch_array($email_result)) {
|
|
$email_templates[] = $row;
|
|
}
|
|
|
|
$sms_sql = "SELECT template_key, template_name FROM order_sms_templates ORDER BY template_key ASC";
|
|
$sms_result = sql_query($sms_sql);
|
|
while ($row = sql_fetch_array($sms_result)) {
|
|
$sms_templates[] = $row;
|
|
}
|
|
|
|
include_once(G5_ADMIN_PATH . '/admin.head.php');
|
|
?>
|
|
|
|
<div class="local_desc01 local_desc">
|
|
<p>
|
|
이메일 및 SMS 알림 템플릿의 실제 발송을 테스트할 수 있습니다.<br>
|
|
개발 단계에서는 알림창으로 표시되며, 운영 단계에서는 실제 발송됩니다.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- 알림 발송 테스트 -->
|
|
<div class="tbl_frm01 tbl_wrap">
|
|
<form name="ftest" method="post" onsubmit="return validateTestForm()">
|
|
<input type="hidden" name="action" value="test_notification">
|
|
|
|
<table>
|
|
<caption>알림 발송 테스트</caption>
|
|
<colgroup>
|
|
<col class="grid_4">
|
|
<col>
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row"><label for="template_type">템플릿 타입<strong class="sound_only">필수</strong></label></th>
|
|
<td>
|
|
<select name="template_type" id="template_type" class="frm_input"
|
|
onchange="updateTemplateList()" required>
|
|
<option value="">선택하세요</option>
|
|
<option value="customer">고객 알림</option>
|
|
<option value="dealer">대리점 알림</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><label for="template_key">템플릿<strong class="sound_only">필수</strong></label></th>
|
|
<td>
|
|
<select name="template_key" id="template_key" class="frm_input"
|
|
onchange="updateNotificationTypes()" required>
|
|
<option value="">먼저 템플릿 타입을 선택하세요</option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><label for="notification_type">발송 방식<strong class="sound_only">필수</strong></label>
|
|
</th>
|
|
<td>
|
|
<label><input type="radio" name="notification_type" value="email"
|
|
onchange="updateRecipientField()"> 이메일</label>
|
|
<label><input type="radio" name="notification_type" value="sms"
|
|
onchange="updateRecipientField()"> SMS</label>
|
|
<label><input type="radio" name="notification_type" value="both"
|
|
onchange="updateRecipientField()"> 둘 다</label>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><label for="test_recipient">테스트 수신자<strong class="sound_only">필수</strong></label>
|
|
</th>
|
|
<td>
|
|
<input type="text" name="test_recipient" id="test_recipient" class="frm_input" required>
|
|
<span class="frm_info" id="recipient_info">발송 방식을 먼저 선택하세요</span>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="btn_confirm01 btn_confirm">
|
|
<input type="submit" value="테스트 발송" class="btn_submit">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- 발송 모드 설정 -->
|
|
<div class="tbl_frm01 tbl_wrap" style="margin-top: 30px;">
|
|
<table>
|
|
<caption>발송 모드 설정</caption>
|
|
<colgroup>
|
|
<col class="grid_4">
|
|
<col>
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row">현재 모드</th>
|
|
<td>
|
|
<?php
|
|
// 개발/운영 모드 확인 (설정에서 가져오거나 기본값 사용)
|
|
$notification_mode = 'development'; // 실제로는 설정에서 가져와야 함
|
|
?>
|
|
<strong><?php echo $notification_mode === 'development' ? '개발 모드 (알림창 표시)' : '운영 모드 (실제 발송)'; ?></strong>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row">모드 설명</th>
|
|
<td>
|
|
<ul>
|
|
<li><strong>개발 모드:</strong> 실제 발송 대신 알림창으로 내용을 표시합니다.</li>
|
|
<li><strong>운영 모드:</strong> 실제 이메일/SMS를 발송합니다.</li>
|
|
</ul>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- 템플릿 변수 참조 -->
|
|
<div class="tbl_head01 tbl_wrap" style="margin-top: 30px;">
|
|
<table>
|
|
<caption>사용 가능한 템플릿 변수</caption>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">변수명</th>
|
|
<th scope="col">설명</th>
|
|
<th scope="col">예시값</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td><code>{customer_name}</code></td>
|
|
<td>고객명</td>
|
|
<td>홍길동</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{estimate_id}</code></td>
|
|
<td>견적 번호</td>
|
|
<td>12345</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{estimate_subject}</code></td>
|
|
<td>견적 제목</td>
|
|
<td>아파트 창호 교체 견적</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{total_amount}</code></td>
|
|
<td>총 금액</td>
|
|
<td>1,500,000</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{visit_fee}</code></td>
|
|
<td>방문 비용</td>
|
|
<td>50,000</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{dealer_name}</code></td>
|
|
<td>대리점명</td>
|
|
<td>김대리점</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{construction_date}</code></td>
|
|
<td>시공 예정일</td>
|
|
<td>2024-02-15</td>
|
|
</tr>
|
|
<tr>
|
|
<td><code>{account_info}</code></td>
|
|
<td>계좌 정보</td>
|
|
<td>국민은행 123-456-789012</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<script>
|
|
// 템플릿 데이터
|
|
const emailTemplates = <?php echo json_encode($email_templates); ?>;
|
|
const smsTemplates = <?php echo json_encode($sms_templates); ?>;
|
|
|
|
// 템플릿 타입 변경 시 템플릿 목록 업데이트
|
|
function updateTemplateList() {
|
|
const templateType = document.getElementById('template_type').value;
|
|
const templateSelect = document.getElementById('template_key');
|
|
|
|
// 기존 옵션 제거
|
|
templateSelect.innerHTML = '<option value="">템플릿을 선택하세요</option>';
|
|
|
|
if (templateType === 'customer' || templateType === 'dealer') {
|
|
// 이메일과 SMS 템플릿 모두 추가
|
|
emailTemplates.forEach(template => {
|
|
const option = document.createElement('option');
|
|
option.value = template.template_key;
|
|
option.textContent = `[이메일] ${template.template_name}`;
|
|
templateSelect.appendChild(option);
|
|
});
|
|
|
|
smsTemplates.forEach(template => {
|
|
const option = document.createElement('option');
|
|
option.value = template.template_key;
|
|
option.textContent = `[SMS] ${template.template_name}`;
|
|
templateSelect.appendChild(option);
|
|
});
|
|
}
|
|
|
|
// 발송 방식 초기화
|
|
document.querySelectorAll('input[name="notification_type"]').forEach(radio => {
|
|
radio.checked = false;
|
|
});
|
|
updateRecipientField();
|
|
}
|
|
|
|
// 템플릿 선택 시 발송 방식 업데이트
|
|
function updateNotificationTypes() {
|
|
const templateKey = document.getElementById('template_key').value;
|
|
|
|
if (templateKey) {
|
|
// 선택된 템플릿이 이메일인지 SMS인지 확인
|
|
const isEmailTemplate = emailTemplates.some(t => t.template_key === templateKey);
|
|
const isSmsTemplate = smsTemplates.some(t => t.template_key === templateKey);
|
|
|
|
// 해당하는 발송 방식만 활성화
|
|
document.querySelector('input[value="email"]').disabled = !isEmailTemplate;
|
|
document.querySelector('input[value="sms"]').disabled = !isSmsTemplate;
|
|
document.querySelector('input[value="both"]').disabled = !(isEmailTemplate && isSmsTemplate);
|
|
}
|
|
}
|
|
|
|
// 발송 방식 변경 시 수신자 필드 업데이트
|
|
function updateRecipientField() {
|
|
const notificationType = document.querySelector('input[name="notification_type"]:checked');
|
|
const recipientField = document.getElementById('test_recipient');
|
|
const recipientInfo = document.getElementById('recipient_info');
|
|
|
|
if (!notificationType) {
|
|
recipientField.placeholder = '';
|
|
recipientInfo.textContent = '발송 방식을 먼저 선택하세요';
|
|
return;
|
|
}
|
|
|
|
switch (notificationType.value) {
|
|
case 'email':
|
|
recipientField.placeholder = 'test@example.com';
|
|
recipientInfo.textContent = '테스트 이메일 주소를 입력하세요';
|
|
break;
|
|
case 'sms':
|
|
recipientField.placeholder = '01012345678';
|
|
recipientInfo.textContent = '테스트 전화번호를 입력하세요 (하이픈 없이)';
|
|
break;
|
|
case 'both':
|
|
recipientField.placeholder = 'test@example.com 또는 01012345678';
|
|
recipientInfo.textContent = '이메일 주소 또는 전화번호를 입력하세요';
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 폼 유효성 검사
|
|
function validateTestForm() {
|
|
const templateType = document.getElementById('template_type').value;
|
|
const templateKey = document.getElementById('template_key').value;
|
|
const notificationType = document.querySelector('input[name="notification_type"]:checked');
|
|
const testRecipient = document.getElementById('test_recipient').value.trim();
|
|
|
|
if (!templateType || !templateKey || !notificationType || !testRecipient) {
|
|
alert('모든 필수 항목을 입력해주세요.');
|
|
return false;
|
|
}
|
|
|
|
// 수신자 유효성 검증
|
|
if (notificationType.value === 'email' || notificationType.value === 'both') {
|
|
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(testRecipient)) {
|
|
alert('유효한 이메일 주소를 입력해주세요.');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (notificationType.value === 'sms') {
|
|
const phoneNumber = testRecipient.replace(/[^0-9]/g, '');
|
|
if (!/^01[0-9]{8,9}$/.test(phoneNumber)) {
|
|
alert('유효한 전화번호를 입력해주세요.');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return confirm('테스트 알림을 발송하시겠습니까?');
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
include_once(G5_ADMIN_PATH . '/admin.tail.php');
|
|
?>
|