91 lines
3.3 KiB
PHP
91 lines
3.3 KiB
PHP
<?php
|
|
if (!defined('_GNUBOARD_')) exit;
|
|
|
|
class NotificationManager
|
|
{
|
|
/**
|
|
* 템플릿 키를 기반으로 알림을 발송합니다.
|
|
* @param string $template_key 템플릿 키 (e.g., 'reservation_confirmed')
|
|
* @param array $data 치환될 데이터 배열 (e.g., ['customer_name' => '홍길동'])
|
|
* @return bool 성공 여부
|
|
*/
|
|
public function sendNotification($template_key, $data)
|
|
{
|
|
$success = true;
|
|
|
|
// 1. 이메일 템플릿 조회 및 발송
|
|
$email_sql = "SELECT * FROM consultant_mail_templates WHERE template_key = '" . sql_real_escape_string($template_key) . "' AND is_active = 1";
|
|
$email_template = sql_fetch($email_sql);
|
|
|
|
if ($email_template) {
|
|
$subject = $this->replaceVariables($email_template['template_subject'], $data);
|
|
$content = $this->replaceVariables($email_template['template_content'], $data);
|
|
|
|
if (!$this->sendEmail($data['customer_email'], $data['customer_name'], $subject, $content)) {
|
|
$success = false;
|
|
}
|
|
}
|
|
|
|
// 2. SMS 템플릿 조회 및 발송
|
|
$sms_sql = "SELECT * FROM consultant_sms_templates WHERE template_key = '" . sql_real_escape_string($template_key) . "' AND is_active = 1";
|
|
$sms_template = sql_fetch($sms_sql);
|
|
|
|
if ($sms_template) {
|
|
$content = $this->replaceVariables($sms_template['template_content'], $data);
|
|
|
|
if (!$this->sendSms($data['customer_phone'], $content)) {
|
|
$success = false;
|
|
}
|
|
}
|
|
|
|
return $success;
|
|
}
|
|
|
|
/**
|
|
* 변수를 실제 값으로 치환합니다.
|
|
*/
|
|
private function replaceVariables($text, $data)
|
|
{
|
|
foreach ($data as $key => $value) {
|
|
$text = str_replace('{' . $key . '}', $value, $text);
|
|
}
|
|
return $text;
|
|
}
|
|
|
|
/**
|
|
* 💡 [연동] mail_manage 시스템을 사용하여 메일을 발송합니다.
|
|
*/
|
|
private function sendEmail($to_email, $to_name, $subject, $content)
|
|
{
|
|
// mail_manage의 라이브러리 포함
|
|
if (file_exists(G5_ADMIN_PATH . '/mail_manage/mailer.lib.php')) {
|
|
include_once(G5_ADMIN_PATH . '/mail_manage/mailer.lib.php');
|
|
|
|
// mailer() 함수 호출 (mail_manage의 함수명에 따라 수정 필요)
|
|
// mailer($from_name, $from_email, $to_email, $subject, $content, 1);
|
|
consultant_log("[Email Sent] To: {$to_email}, Subject: {$subject}");
|
|
return true;
|
|
}
|
|
consultant_log("[Email Error] mail_manage/mailer.lib.php not found.", 'error');
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* 💡 [연동] sms_admin 시스템을 사용하여 문자를 발송합니다.
|
|
*/
|
|
private function sendSms($to_phone, $content)
|
|
{
|
|
// sms_admin의 라이브러리 포함
|
|
if (file_exists(G5_ADMIN_PATH . '/sms_admin/sms.lib.php')) {
|
|
include_once(G5_ADMIN_PATH . '/sms_admin/sms.lib.php');
|
|
|
|
// sms_send() 함수 호출 (sms_admin의 함수명에 따라 수정 필요)
|
|
// $result = sms_send($to_phone, $content);
|
|
consultant_log("[SMS Sent] To: {$to_phone}, Content: {$content}");
|
|
return true;
|
|
}
|
|
consultant_log("[SMS Error] sms_admin/sms.lib.php not found.", 'error');
|
|
return false;
|
|
}
|
|
}
|