先に作成した管理画面でのお問合わせ機能だけだと閲覧のみなので、管理画面からメールを返信できるようにカスタマイズする.
※これが大変だったんだった。 サイトどおりにやってもうまくいかない。ホント。
デフォルトでは「order_id」が「NOT_NULL」すなわち、お買い物データがないものは、エラーとなってしまいますので、この制限をはずします。 また、送信先のメールアドレスを保存するために、「email」カラムを「text」型で追加します。
管理画面から、
システム設定>マスタデータ管理>mtb_mail_template
と進んで、
ID:5 値:お問合わせ返信
を追加する。
も同様に、
ID:5 値:mail_tenplates/contact_re_mail.tpl
を追加。
/html/admin/customer/mail.php /html/admin/customer/mail_confirm.php /html/admin/customer/mail_view.php /data/Smarty/templates/default/admin/customer/mail.tpl /data/Smarty/templates/default/admin/customer/mail_confirm.tpl /data/Smarty/templates/default/admin/customer/mail_view.tpl /data/Smarty/templates/default/mail_template/contact_re_mail.tpl /data/class/pages/admin/customer/LC_Page_Admin_Contact_Mail.php /data/class/pages/admin/customer/LC_Page_Admin_Contact_MailView.php
クラスの編集 /data/class/helper/SC_Helper_Mail.php
以下のメソッドを追加
- /***
- * 2009.04.27 追加
- * @author i-enter y-nakajima
- * 返信メール送信メソッド
- * @param $contact_id, $template_id, $subject = "", $header = "", $footer = "", $send = true
- **/
- function sfSendContactMail($contact_id, $template_id, $subject = "", $header = "", $footer = "", $send_flg = true) {
- $objPage = new LC_Page();
- $objSiteInfo = new SC_SiteInfo();
- $arrInfo = $objSiteInfo->data;
- $objPage->arrInfo = $arrInfo;
-
- $objQuery = new SC_Query();
-
- if($subject == "" && $header == "" && $footer == ""){
-
- // メールテンプレート情報の取得
- $where = "template_id = ?";
- $objPage->tpl_header = $arrRet[0]['header'];
- $objPage->tpl_footer = $arrRet[0]['footer'];
- $tmp_subject = $arrRet[0]['subject'];
-
- } else {
- $objPage->tpl_header = $header;
- $objPage->tpl_footer = $footer;
- $tmp_subject = $subject;
- }
-
- // 問い合わせ情報の取得
- $where = "contact_id = ?";
-
- $objPage->arrContact = $arrRet[0];
-
- $objMailView = new SC_SiteView();
- // メール本文の取得
- $objMailView->assignobj($objPage);
- $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
-
- // メール送信処理
- $objSendMail = new SC_SendMail_Ex();
- $bcc = $arrInfo['email01'];
- $from = $arrInfo['email03'];
- $error = $arrInfo['email04'];
-
- $tosubject = $this->sfMakeSubject($objQuery, $objMailView, $objPage, $tmp_subject);
-
- $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
- $objSendMail->setTo($arrRet[0]['email'] , $arrRet[0]['name'] . ' ' . $arrRet[0]['name_f'] . ' 様');
-
- // 送信フラグ:trueの場合はTXTメール送信を実行する
- if($send_flg){
- if($objSendMail->sendMail()){
- $this->sfSaveMailHistory2($arrRet[0]['email'], $template_id, $tosubject, $body);
- }
- }
-
- return $objSendMail;
- }
-
- /***
- * 2009.04.27 追加
- * @author i-enter y-nakajima
- * メール配信履歴への登録
- * @param $email, $template_id, $subject, $body
- **/
- function sfSaveMailHistory2($email, $template_id, $subject, $body) {
- $sqlval['subject'] = $subject;
- $sqlval['email'] = $email;
- $sqlval['template_id'] = $template_id;
- $sqlval['send_date'] = "Now()";
-
- if($_SESSION['member_id'] != "") {
- $sqlval['creator_id'] = $_SESSION['member_id'];
- } else {
- $sqlval['creator_id'] = '0';
- }
- $sqlval['mail_body'] = $body;
-
- $objQuery = new SC_Query();
- $objQuery->insert("dtb_mail_history", $sqlval);
- }
次に以下のファイルを編集。
/data/class/pages/admin/customer/LC_Page_Admin_Contact_Mail.php
<?php
require_once(CLASS_PATH . "pages/LC_Page.php");
/**
* お問い合わせメール管理 のページクラス.
*/
class LC_Page_Admin_Contact_Mail extends LC_Page {
/**
* Page を初期化する.
*
* @return void
*/
function init() {
parent::init();
$this->tpl_mainpage = 'customer/mail.tpl';
$this->tpl_subnavi = 'customer/subnavi.tpl';
$this->tpl_mainno = 'customer';
$this->tpl_subno = 'contact';
$this->tpl_subtitle = 'お問合わせ返信';
$masterData = new SC_DB_MasterData_Ex();
$this->arrMAILTEMPLATE = $masterData->getMasterData("mtb_mail_template");
}
/**
* Page のプロセス.
*
* @return void
*/
function process() {
$objView = new SC_AdminView();
$objSess = new SC_Session();
SC_Utils_Ex::sfIsSuccess($objSess);
if(SC_Utils_Ex::sfIsInt($_GET['contact_id'])){
$this->tpl_contact_id = $_GET['contact_id'];
}elseif(SC_Utils_Ex::sfIsInt($_POST['contact_id'])){
$this->tpl_contact_id = $_POST['contact_id'];
}
// パラメータ管理クラス
$objFormParam = new SC_FormParam();
// パラメータ情報の初期化
$this->lfInitParam($objFormParam);
$objMail = new SC_Helper_Mail_Ex();
switch($_POST['mode']) {
case 'pre_edit':
break;
case 'return':
// POST値の取得
$objFormParam->setParam($_POST);
break;
case 'send':
// POST値の取得
$objFormParam->setParam($_POST);
// 入力値の変換
$objFormParam->convParam();
$this->arrErr = $objFormParam->checkError();
// メールの送信
if (count($this->arrErr) == 0) {
// 問合せ返信メール
$objSendMail = $objMail->sfSendContactMail($this->tpl_contact_id, $_POST['template_id'], $_POST['subject'], $_POST['header'], $_POST['footer']);
}
$this->sendRedirect($this->getLocation("./contact.php"), true);
exit;
break;
case 'confirm':
// POST値の取得
$objFormParam->setParam($_POST);
// 入力値の変換
$objFormParam->convParam();
// 入力値の引き継ぎ
$this->arrHidden = $objFormParam->getHashArray();
$this->arrErr = $objFormParam->checkError();
// メールの送信
if (count($this->arrErr) == 0) {
// 問合せ返信メール(送信なし)
$objSendMail = $objMail->sfSendContactMail($this->tpl_contact_id, $_POST['template_id'], $_POST['subject'], $_POST['header'], $_POST['footer'], false);
// 確認ページの表示
$this->tpl_subject = $_POST['subject'];
$this->tpl_body = mb_convert_encoding( $objSendMail->body, CHAR_CODE, "auto" );
$this->tpl_to = $objSendMail->arrRecip["To"];
$this->tpl_mainpage = 'customer/mail_confirm.tpl';
$this->arrHidden['contact_id'] = $this->tpl_contact_id;
$objView->assignobj($this);
$objView->display(MAIN_FRAME);
exit;
}
break;
case 'change':
// POST値の取得
$objFormParam->setValue('template_id', $_POST['template_id']);
if(SC_Utils_Ex::sfIsInt($_POST['template_id'])) {
$objQuery = new SC_Query();
$where = "template_id = ?";
$arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($_POST['template_id']));
$objFormParam->setParam($arrRet[0]);
}
break;
}
$objQuery = new SC_Query();
$where = "contact_id = ?";
$arrRet = $objQuery->select("*", "dtb_contact", $where, array($this->tpl_contact_id));
$col = "send_date, subject, template_id, send_id";
$where = "email = ?";
$objQuery->setorder("send_date DESC");
$this->arrMailHistory = $objQuery->select($col, "dtb_mail_history", $where, array($arrRet[0]['email']));
$this->arrForm = $objFormParam->getFormParamList();
$objView->assignobj($this);
$objView->display(MAIN_FRAME);
}
/**
* デストラクタ.
*
* @return void
*/
function destroy() {
parent::destroy();
}
/* パラメータ情報の初期化 */
function lfInitParam(&$objFormParam) {
$objFormParam->addParam("テンプレート", "template_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
$objFormParam->addParam("メールタイトル", "subject", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
$objFormParam->addParam("ヘッダー", "header", LTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
$objFormParam->addParam("フッター", "footer", LTEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK"));
}
}
?>
次はこれをorderのをコピーして編集。 /data/class/pages/admin/customer/LC_Page_Admin_Contact_MailView.php
- <?php
- require_once(CLASS_PATH . "pages/LC_Page.php");
-
- /**
- * お問合わせメール確認 のページクラス.
- */
- class LC_Page_Admin_Contact_MailView extends LC_Page {
-
- /**
- * Page を初期化する.
- *
- * @return void
- */
- function init() {
- parent::init();
- $this->tpl_mainpage = 'customer/mail_view.tpl';
- }
-
- /**
- * Page のプロセス.
- *
- * @return void
- */
- function process() {
- $objView = new SC_AdminView();
- $objSess = new SC_Session();
-
- // 認証可否の判定
- SC_Utils_Ex::sfIsSuccess($objSess);
-
- if(SC_Utils_Ex::sfIsInt($_GET['send_id'])) {
- $objQuery = new SC_Query();
- $col = "subject, mail_body";
- $where = "send_id = ?";
- $this->tpl_subject = $arrRet[0]['subject'];
- $this->tpl_body = $arrRet[0]['mail_body'];
- }
-
- $objView->assignobj($this);
- $objView->display($this->tpl_mainpage);
- }
-
- /**
- * デストラクタ.
- *
- * @return void
- */
- function destroy() {
- parent::destroy();
- }
- }
- ?>
/data/Smarty/templates/default/adin/customer/mail.tpl の以下を変更
Line 28
28. <input type="hidden" name="order_id" value="<!--{$tpl_order_id}-->">
↓↓↓↓
28. <input type="hidden" name="order_id" value="<!--{$tpl_contact_id}-->">
Line142
142. <input type="button" name="back" value="検索結果へ戻る" onclick="fnChangeAction('<!--{$smarty.const.URL_SEARCH_ORDER}-->'); fnModeSubmit('search','',''); return false;" />
↓↓↓↓
142. <input type="button" name="back" value="検索結果へ戻る" onclick="fnChangeAction('contact.php'); fnModeSubmit('','',''); return false;" />
/data/Smarty/templates/default/adin/customer/contact_re_mail.tpl を新規作成。
- お問合せ内容が挿入されます。
- <!--{$tpl_header}-->
-
- ----------------------------------------------
-
- ■お問合せ日時:<!--{$arrContact.create_date}-->
-
- ■お問い合わせ内容
- <!--{$arrContact.message}-->
-
- ----------------------------------------------
-
- <!--{$tpl_footer}-->
カスタマイズ結果はこんな感じです。