From 85c9b633ec8ab97d863a6e3da2308218f3787818 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Wed, 14 Dec 2016 00:22:01 +0900 Subject: [PATCH] Implement SMS logging and viewing --- .../advanced_mailer.admin.controller.php | 39 ++++++++- .../advanced_mailer.admin.view.php | 84 +++++++++++++++++-- .../advanced_mailer.controller.php | 34 +++++--- modules/advanced_mailer/conf/module.xml | 2 + modules/advanced_mailer/lang/en.php | 1 + modules/advanced_mailer/lang/ko.php | 1 + .../{deleteLogs.xml => deleteMailLogs.xml} | 2 +- .../advanced_mailer/queries/deleteSMSLogs.xml | 9 ++ ...{getLogByType.xml => getMailLogByType.xml} | 2 +- .../queries/getSMSLogByType.xml | 17 ++++ .../{insertLog.xml => insertMailLog.xml} | 2 +- .../advanced_mailer/queries/insertSMSLog.xml | 15 ++++ modules/advanced_mailer/tpl/common.html | 4 +- .../tpl/{view_log.html => mail_log.html} | 0 .../tpl/{test.html => mail_test.html} | 2 +- modules/advanced_mailer/tpl/sms_log.html | 79 +++++++++++++++++ modules/advanced_mailer/tpl/sms_test.html | 45 ++++++++++ 17 files changed, 307 insertions(+), 31 deletions(-) rename modules/advanced_mailer/queries/{deleteLogs.xml => deleteMailLogs.xml} (85%) create mode 100644 modules/advanced_mailer/queries/deleteSMSLogs.xml rename modules/advanced_mailer/queries/{getLogByType.xml => getMailLogByType.xml} (91%) create mode 100644 modules/advanced_mailer/queries/getSMSLogByType.xml rename modules/advanced_mailer/queries/{insertLog.xml => insertMailLog.xml} (94%) create mode 100644 modules/advanced_mailer/queries/insertSMSLog.xml rename modules/advanced_mailer/tpl/{view_log.html => mail_log.html} (100%) rename modules/advanced_mailer/tpl/{test.html => mail_test.html} (98%) create mode 100644 modules/advanced_mailer/tpl/sms_log.html create mode 100644 modules/advanced_mailer/tpl/sms_test.html diff --git a/modules/advanced_mailer/advanced_mailer.admin.controller.php b/modules/advanced_mailer/advanced_mailer.admin.controller.php index 62ffbb92e..7489bb978 100644 --- a/modules/advanced_mailer/advanced_mailer.admin.controller.php +++ b/modules/advanced_mailer/advanced_mailer.admin.controller.php @@ -149,7 +149,7 @@ class Advanced_MailerAdminController extends Advanced_Mailer } /** - * Clear old sending log. + * Clear old mail sending log. */ public function procAdvanced_mailerAdminClearSentMail() { @@ -167,15 +167,46 @@ class Advanced_MailerAdminController extends Advanced_Mailer $obj = new stdClass(); $obj->status = $status; $obj->regdate = date('YmdHis', time() - ($clear_before_days * 86400) + zgap()); - $output = executeQuery('advanced_mailer.deleteLogs', $obj); + $output = executeQuery('advanced_mailer.deleteMailLogs', $obj); if ($status === 'success') { - $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminSentMail')); + $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminMailLog')); } else { - $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminErrors')); + $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminMailErrors')); + } + } + + /** + * Clear old SMS sending log. + */ + public function procAdvanced_mailerAdminClearSentSMS() + { + $status = Context::get('status'); + $clear_before_days = intval(Context::get('clear_before_days')); + if (!in_array($status, array('success', 'error'))) + { + return new Object(-1, 'msg_invalid_request'); + } + if ($clear_before_days < 0) + { + return new Object(-1, 'msg_invalid_request'); + } + + $obj = new stdClass(); + $obj->status = $status; + $obj->regdate = date('YmdHis', time() - ($clear_before_days * 86400) + zgap()); + $output = executeQuery('advanced_mailer.deleteSMSLogs', $obj); + + if ($status === 'success') + { + $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminSMSLog')); + } + else + { + $this->setRedirectUrl(getNotEncodedUrl('', 'module', 'admin', 'act', 'dispAdvanced_mailerAdminSMSErrors')); } } diff --git a/modules/advanced_mailer/advanced_mailer.admin.view.php b/modules/advanced_mailer/advanced_mailer.admin.view.php index b0092505e..5ef461bed 100644 --- a/modules/advanced_mailer/advanced_mailer.admin.view.php +++ b/modules/advanced_mailer/advanced_mailer.admin.view.php @@ -110,7 +110,7 @@ class Advanced_MailerAdminView extends Advanced_Mailer } /** - * Display the test send form. + * Display the mail test form. */ public function dispAdvanced_MailerAdminMailTest() { @@ -122,18 +122,18 @@ class Advanced_MailerAdminView extends Advanced_Mailer Context::set('sending_method', config('mail.type')); $this->setTemplatePath($this->module_path.'tpl'); - $this->setTemplateFile('test'); + $this->setTemplateFile('mail_test'); } /** - * Display the sent mail log. + * Display the mail log. */ public function dispAdvanced_MailerAdminMailLog() { $obj = new stdClass(); $obj->status = 'success'; $obj->page = $page = Context::get('page') ?: 1; - $maillog = executeQuery('advanced_mailer.getLogByType', $obj); + $maillog = executeQueryArray('advanced_mailer.getMailLogByType', $obj); $maillog = $maillog->toBool() ? $this->procMailLog($maillog->data) : array(); Context::set('advanced_mailer_log', $maillog); Context::set('advanced_mailer_status', 'success'); @@ -148,18 +148,18 @@ class Advanced_MailerAdminView extends Advanced_Mailer Context::set('sending_methods', $sending_methods); $this->setTemplatePath($this->module_path.'tpl'); - $this->setTemplateFile('view_log'); + $this->setTemplateFile('mail_log'); } /** - * Display the error log. + * Display the mail error log. */ public function dispAdvanced_MailerAdminMailErrors() { $obj = new stdClass(); $obj->status = 'error'; $obj->page = $page = Context::get('page') ?: 1; - $maillog = executeQuery('advanced_mailer.getLogByType', $obj); + $maillog = executeQueryArray('advanced_mailer.getMailLogByType', $obj); $maillog = $maillog->toBool() ? $this->procMailLog($maillog->data) : array(); Context::set('advanced_mailer_log', $maillog); Context::set('advanced_mailer_status', 'error'); @@ -174,7 +174,75 @@ class Advanced_MailerAdminView extends Advanced_Mailer Context::set('sending_methods', $sending_methods); $this->setTemplatePath($this->module_path.'tpl'); - $this->setTemplateFile('view_log'); + $this->setTemplateFile('mail_log'); + } + + /** + * Display the SMS test form. + */ + public function dispAdvanced_MailerAdminSMSTest() + { + $advanced_mailer_config = $this->getConfig(); + $sending_methods = Rhymix\Framework\Mail::getSupportedDrivers(); + + Context::set('advanced_mailer_config', $advanced_mailer_config); + Context::set('sending_methods', $sending_methods); + Context::set('sending_method', config('mail.type')); + + $this->setTemplatePath($this->module_path.'tpl'); + $this->setTemplateFile('sms_test'); + } + + /** + * Display the SMS log. + */ + public function dispAdvanced_MailerAdminSMSLog() + { + $obj = new stdClass(); + $obj->status = 'success'; + $obj->page = $page = Context::get('page') ?: 1; + $smslog = executeQueryArray('advanced_mailer.getSMSLogByType', $obj); + $smslog = $smslog->toBool() ? $smslog->data : array(); + Context::set('advanced_mailer_log', $smslog); + Context::set('advanced_mailer_status', 'success'); + + $paging = $this->procPaging('success', $page); + Context::set('total_count', $paging->total_count); + Context::set('total_page', $paging->total_page); + Context::set('page', $paging->page); + Context::set('page_navigation', $paging->page_navigation); + + $sending_methods = Rhymix\Framework\SMS::getSupportedDrivers(); + Context::set('sending_methods', $sending_methods); + + $this->setTemplatePath($this->module_path.'tpl'); + $this->setTemplateFile('sms_log'); + } + + /** + * Display the SMS error log. + */ + public function dispAdvanced_MailerAdminSMSErrors() + { + $obj = new stdClass(); + $obj->status = 'error'; + $obj->page = $page = Context::get('page') ?: 1; + $smslog = executeQueryArray('advanced_mailer.getSMSLogByType', $obj); + $smslog = $smslog->toBool() ? $smslog->data : array(); + Context::set('advanced_mailer_log', $smslog); + Context::set('advanced_mailer_status', 'error'); + + $paging = $this->procPaging('error', $page); + Context::set('total_count', $paging->total_count); + Context::set('total_page', $paging->total_page); + Context::set('page', $paging->page); + Context::set('page_navigation', $paging->page_navigation); + + $sending_methods = Rhymix\Framework\SMS::getSupportedDrivers(); + Context::set('sending_methods', $sending_methods); + + $this->setTemplatePath($this->module_path.'tpl'); + $this->setTemplateFile('sms_log'); } /** diff --git a/modules/advanced_mailer/advanced_mailer.controller.php b/modules/advanced_mailer/advanced_mailer.controller.php index 8ac3d558d..78bc8d219 100644 --- a/modules/advanced_mailer/advanced_mailer.controller.php +++ b/modules/advanced_mailer/advanced_mailer.controller.php @@ -58,7 +58,6 @@ class Advanced_MailerController extends Advanced_Mailer if (toBool($config->log_sent_mail) || (toBool($config->log_errors) && count($mail->errors))) { $obj = new \stdClass(); - $obj->mail_srl = getNextSequence(); $obj->mail_from = ''; $obj->mail_to = ''; @@ -99,9 +98,9 @@ class Advanced_MailerController extends Advanced_Mailer $obj->subject = $mail->message->getSubject(); $obj->calling_script = $mail->getCaller(); $obj->sending_method = strtolower(class_basename($mail->driver)); - $obj->status = !count($mail->errors) ? 'success' : 'error'; - $obj->errors = count($mail->errors) ? implode("\n", $mail->errors) : null; - $output = executeQuery('advanced_mailer.insertLog', $obj); + $obj->status = !count($mail->getErrors()) ? 'success' : 'error'; + $obj->errors = count($mail->getErrors()) ? implode("\n", $mail->getErrors()) : null; + $output = executeQuery('advanced_mailer.insertMailLog', $obj); if (!$output->toBool()) { return $output; @@ -155,18 +154,27 @@ class Advanced_MailerController extends Advanced_Mailer if (toBool($config->log_sent_sms) || (toBool($config->log_sms_errors) && count($sms->errors))) { - return new Object(); - $obj = new \stdClass(); - $obj->sms_srl = getNextSequence(); - $obj->sms_from = ''; - $obj->sms_to = ''; - $obj->content = $sms->getContent(); + $obj->sms_from = $sms->getFrom(); + $obj->sms_to = array(); + foreach ($sms->getRecipientsWithCountry() as $to) + { + if ($to->country) + { + $obj->sms_to[] = '+' . $to->country . '.' . $to->number; + } + else + { + $obj->sms_to[] = $to->number; + } + } + $obj->sms_to = implode(', ', $obj->sms_to); + $obj->content = trim($sms->getSubject() . "\n" . $sms->getBody()); $obj->calling_script = $sms->getCaller(); $obj->sending_method = strtolower(class_basename($sms->driver)); - $obj->status = !count($sms->errors) ? 'success' : 'error'; - $obj->errors = count($sms->errors) ? implode("\n", $sms->errors) : null; - $output = executeQuery('advanced_mailer.insertLog', $obj); + $obj->status = !count($sms->getErrors()) ? 'success' : 'error'; + $obj->errors = count($sms->getErrors()) ? implode("\n", $sms->getErrors()) : null; + $output = executeQuery('advanced_mailer.insertSMSLog', $obj); if (!$output->toBool()) { return $output; diff --git a/modules/advanced_mailer/conf/module.xml b/modules/advanced_mailer/conf/module.xml index 88ed22a98..2b341a7a8 100644 --- a/modules/advanced_mailer/conf/module.xml +++ b/modules/advanced_mailer/conf/module.xml @@ -16,7 +16,9 @@ + + diff --git a/modules/advanced_mailer/lang/en.php b/modules/advanced_mailer/lang/en.php index d557f0ceb..ee1fc6843 100644 --- a/modules/advanced_mailer/lang/en.php +++ b/modules/advanced_mailer/lang/en.php @@ -107,6 +107,7 @@ $lang->msg_advanced_mailer_log_is_empty = 'There are no entries to display.'; $lang->cmd_advanced_mailer_status_sender = 'Sender'; $lang->cmd_advanced_mailer_status_recipient = 'Recipient'; $lang->cmd_advanced_mailer_status_subject = 'Subject'; +$lang->cmd_advanced_mailer_status_content = 'Content'; $lang->cmd_advanced_mailer_status_sending_method = 'Method'; $lang->cmd_advanced_mailer_status_time = 'Time'; $lang->cmd_advanced_mailer_status = 'Status'; diff --git a/modules/advanced_mailer/lang/ko.php b/modules/advanced_mailer/lang/ko.php index 114eb4aec..cf6fd6ffa 100644 --- a/modules/advanced_mailer/lang/ko.php +++ b/modules/advanced_mailer/lang/ko.php @@ -107,6 +107,7 @@ $lang->msg_advanced_mailer_log_is_empty = '표시할 항목이 없습니다.'; $lang->cmd_advanced_mailer_status_sender = '보낸이'; $lang->cmd_advanced_mailer_status_recipient = '받는이'; $lang->cmd_advanced_mailer_status_subject = '제목'; +$lang->cmd_advanced_mailer_status_content = '내용'; $lang->cmd_advanced_mailer_status_sending_method = '발송 방법'; $lang->cmd_advanced_mailer_status_time = '발송 시간'; $lang->cmd_advanced_mailer_status = '상태'; diff --git a/modules/advanced_mailer/queries/deleteLogs.xml b/modules/advanced_mailer/queries/deleteMailLogs.xml similarity index 85% rename from modules/advanced_mailer/queries/deleteLogs.xml rename to modules/advanced_mailer/queries/deleteMailLogs.xml index 690e64ed8..d76928fff 100644 --- a/modules/advanced_mailer/queries/deleteLogs.xml +++ b/modules/advanced_mailer/queries/deleteMailLogs.xml @@ -1,4 +1,4 @@ - + diff --git a/modules/advanced_mailer/queries/deleteSMSLogs.xml b/modules/advanced_mailer/queries/deleteSMSLogs.xml new file mode 100644 index 000000000..21676d22b --- /dev/null +++ b/modules/advanced_mailer/queries/deleteSMSLogs.xml @@ -0,0 +1,9 @@ + + +
+ + + + + + diff --git a/modules/advanced_mailer/queries/getLogByType.xml b/modules/advanced_mailer/queries/getMailLogByType.xml similarity index 91% rename from modules/advanced_mailer/queries/getLogByType.xml rename to modules/advanced_mailer/queries/getMailLogByType.xml index 655b85e30..60285b793 100644 --- a/modules/advanced_mailer/queries/getLogByType.xml +++ b/modules/advanced_mailer/queries/getMailLogByType.xml @@ -1,4 +1,4 @@ - +
diff --git a/modules/advanced_mailer/queries/getSMSLogByType.xml b/modules/advanced_mailer/queries/getSMSLogByType.xml new file mode 100644 index 000000000..d7c4e36e7 --- /dev/null +++ b/modules/advanced_mailer/queries/getSMSLogByType.xml @@ -0,0 +1,17 @@ + + +
+ + + + + + + + + + + + + + diff --git a/modules/advanced_mailer/queries/insertLog.xml b/modules/advanced_mailer/queries/insertMailLog.xml similarity index 94% rename from modules/advanced_mailer/queries/insertLog.xml rename to modules/advanced_mailer/queries/insertMailLog.xml index 2f2580c34..006fbf166 100644 --- a/modules/advanced_mailer/queries/insertLog.xml +++ b/modules/advanced_mailer/queries/insertMailLog.xml @@ -1,4 +1,4 @@ - +
diff --git a/modules/advanced_mailer/queries/insertSMSLog.xml b/modules/advanced_mailer/queries/insertSMSLog.xml new file mode 100644 index 000000000..f1bb6460d --- /dev/null +++ b/modules/advanced_mailer/queries/insertSMSLog.xml @@ -0,0 +1,15 @@ + + +
+ + + + + + + + + + + + diff --git a/modules/advanced_mailer/tpl/common.html b/modules/advanced_mailer/tpl/common.html index 4b5c08526..29ecbd984 100644 --- a/modules/advanced_mailer/tpl/common.html +++ b/modules/advanced_mailer/tpl/common.html @@ -10,7 +10,7 @@
  • {$lang->cmd_advanced_mailer_mail_test}
  • {$lang->cmd_advanced_mailer_log_mail}
  • {$lang->cmd_advanced_mailer_log_mail_errors}
  • -
  • {$lang->cmd_advanced_mailer_sms_test}
  • -
  • {$lang->cmd_advanced_mailer_log_sms}
  • +
  • {$lang->cmd_advanced_mailer_sms_test}
  • +
  • {$lang->cmd_advanced_mailer_log_sms}
  • {$lang->cmd_advanced_mailer_log_sms_errors}
  • diff --git a/modules/advanced_mailer/tpl/view_log.html b/modules/advanced_mailer/tpl/mail_log.html similarity index 100% rename from modules/advanced_mailer/tpl/view_log.html rename to modules/advanced_mailer/tpl/mail_log.html diff --git a/modules/advanced_mailer/tpl/test.html b/modules/advanced_mailer/tpl/mail_test.html similarity index 98% rename from modules/advanced_mailer/tpl/test.html rename to modules/advanced_mailer/tpl/mail_test.html index 28f80d0c0..4234b9956 100644 --- a/modules/advanced_mailer/tpl/test.html +++ b/modules/advanced_mailer/tpl/mail_test.html @@ -4,7 +4,7 @@ - +
    diff --git a/modules/advanced_mailer/tpl/sms_log.html b/modules/advanced_mailer/tpl/sms_log.html new file mode 100644 index 000000000..964ee1093 --- /dev/null +++ b/modules/advanced_mailer/tpl/sms_log.html @@ -0,0 +1,79 @@ + + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + +
    + Total: {number_format($total_count)}, Page: {number_format($page)}/{number_format($total_page)} +
    {$lang->cmd_advanced_mailer_status_sender}{$lang->cmd_advanced_mailer_status_recipient}{$lang->cmd_advanced_mailer_status_content}{$lang->cmd_advanced_mailer_status_sending_method}{$lang->cmd_advanced_mailer_status_time}{$lang->cmd_advanced_mailer_status}
    + {htmlspecialchars($val->sms_from)} + + {htmlspecialchars($val->sms_to)} + {nl2br(htmlspecialchars($val->content))} + {@ if($val->sending_method === 'mail') $val->sending_method = 'mailfunction'} + {strval(isset($sending_methods[$val->sending_method]['name']) ? $sending_methods[$val->sending_method]['name'] : $val->sending_method)} + {(zdate($val->regdate, "Y-m-d\nH:i:s"))} + + {$lang->cmd_advanced_mailer_status_success} + + {$lang->cmd_advanced_mailer_status_error} +
    + {$lang->cmd_advanced_mailer_status_error_msg}:
    + {nl2br(htmlspecialchars(trim($val->errors)))}

    + {$lang->cmd_advanced_mailer_status_calling_script}:
    + {htmlspecialchars($val->calling_script)} +
    + +
    {$lang->msg_advanced_mailer_log_is_empty}
    + +
    + + + + +
    + + + + + +
    +
    diff --git a/modules/advanced_mailer/tpl/sms_test.html b/modules/advanced_mailer/tpl/sms_test.html new file mode 100644 index 000000000..4234b9956 --- /dev/null +++ b/modules/advanced_mailer/tpl/sms_test.html @@ -0,0 +1,45 @@ + + + + +
    + + + + +
    +

    {$XE_VALIDATOR_MESSAGE}

    +
    + +
    + +

    {$lang->cmd_advanced_mailer_mail_test}

    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    +
    +
    +
    + +
    + +
    + +
    + +