source: branches/version-2_5-dev/data/class/helper/SC_Helper_Mail.php @ 19749

Revision 19749, 9.4 KB checked in by Seasoft, 11 years ago (diff)

#858(SC_Helper_Mail#sfSendOrderMail LC_Page を使用しないように改訂)

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24/**
25 * メール関連 のヘルパークラス.
26 *
27 * @package Helper
28 * @author LOCKON CO.,LTD.
29 * @version $Id$
30 */
31class SC_Helper_Mail {
32
33    /** メールテンプレートのパス */
34    var $arrMAILTPLPATH;
35
36    /**
37     * コンストラクタ.
38     */
39    function SC_Helper_Mail() {
40        $masterData = new SC_DB_MasterData_Ex();
41        $this->arrMAILTPLPATH =  $masterData->getMasterData("mtb_mail_tpl_path");
42        $this->arrPref = $masterData->getMasterData("mtb_pref",
43                                 array("pref_id", "pref_name", "rank"));
44    }
45
46    /* DBに登録されたテンプレートメールの送信 */
47    function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "") {
48
49        $objQuery = new SC_Query();
50        // メールテンプレート情報の取得
51        $where = "template_id = ?";
52        $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
53        $objPage->tpl_header = $arrRet[0]['header'];
54        $objPage->tpl_footer = $arrRet[0]['footer'];
55        $tmp_subject = $arrRet[0]['subject'];
56
57        $objSiteInfo = new SC_SiteInfo();
58        $arrInfo = $objSiteInfo->data;
59
60        $objMailView = new SC_SiteView();
61        // メール本文の取得
62        $objMailView->assignobj($objPage);
63        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
64
65        // メール送信処理
66        $objSendMail = new SC_SendMail_Ex();
67        if ($from_address == "") $from_address = $arrInfo['email03'];
68        if ($from_name == "") $from_name = $arrInfo['shop_name'];
69        if ($reply_to == "") $reply_to = $arrInfo['email03'];
70        $error = $arrInfo['email04'];
71        $tosubject = $this->sfMakeSubject($tmp_subject);
72       
73        $objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error);
74        $objSendMail->setTo($to, $to_name);
75        $objSendMail->sendMail();    // メール送信
76    }
77
78    /* 受注完了メール送信 */
79    function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
80
81        $arrTplVar = new stdClass();
82        $objSiteInfo = new SC_SiteInfo();
83        $arrInfo = $objSiteInfo->data;
84        $arrTplVar->arrInfo = $arrInfo;
85
86        $objQuery = new SC_Query();
87
88        if($subject == "" && $header == "" && $footer == "") {
89            // メールテンプレート情報の取得
90            $where = "template_id = ?";
91            $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
92            $arrTplVar->tpl_header = $arrRet[0]['header'];
93            $arrTplVar->tpl_footer = $arrRet[0]['footer'];
94            $tmp_subject = $arrRet[0]['subject'];
95        } else {
96            $arrTplVar->tpl_header = $header;
97            $arrTplVar->tpl_footer = $footer;
98            $tmp_subject = $subject;
99        }
100
101        // 受注情報の取得
102        $where = "order_id = ?";
103        $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
104        $arrOrder = $arrRet[0];
105        $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
106
107        $arrTplVar->Message_tmp = $arrOrder['message'];
108
109        // 顧客情報の取得
110        $customer_id = $arrOrder['customer_id'];
111        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
112        $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : "";
113
114        $arrTplVar->arrCustomer = $arrCustomer;
115        $arrTplVar->arrOrder = $arrOrder;
116
117        //その他決済情報
118        if($arrOrder['memo02'] != "") {
119            $arrOther = unserialize($arrOrder['memo02']);
120
121            foreach($arrOther as $other_key => $other_val){
122                if(SC_Utils_Ex::sfTrim($other_val["value"]) == ""){
123                    $arrOther[$other_key]["value"] = "";
124                }
125            }
126
127            $arrTplVar->arrOther = $arrOther;
128        }
129
130        // 都道府県変換
131        $arrTplVar->arrOrder['deliv_pref'] = $this->arrPref[$arrTplVar->arrOrder['deliv_pref']];
132
133        $arrTplVar->arrOrderDetail = $arrOrderDetail;
134
135        $objCustomer = new SC_Customer();
136        $arrTplVar->tpl_user_point = $objCustomer->getValue('point');
137
138        $objMailView = new SC_SiteView();
139        // メール本文の取得
140        $objMailView->assignobj($arrTplVar);
141        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
142
143        // メール送信処理
144        $objSendMail = new SC_SendMail_Ex();
145        $bcc = $arrInfo['email01'];
146        $from = $arrInfo['email03'];
147        $error = $arrInfo['email04'];
148        $tosubject = $this->sfMakeSubject($tmp_subject);
149
150        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
151        $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様");
152
153
154        // 送信フラグ:trueの場合は、送信する。
155        if($send) {
156            if ($objSendMail->sendMail()) {
157                $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
158            }
159        }
160
161        return $objSendMail;
162    }
163
164    // テンプレートを使用したメールの送信
165    function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) {
166        $objMailView = new SC_SiteView();
167        $objSiteInfo = new SC_SiteInfo();
168        $arrInfo = $objSiteInfo->data;
169        // メール本文の取得
170        $objPage->tpl_shopname=$arrInfo['shop_name'];
171        $objPage->tpl_infoemail = $arrInfo['email02'];
172        $objMailView->assignobj($objPage);
173        $body = $objMailView->fetch($tplpath);
174        // メール送信処理
175        $objSendMail = new SC_SendMail_Ex();
176        $bcc = $arrInfo['email01'];
177        $from = $arrInfo['email03'];
178        $error = $arrInfo['email04'];
179        $tosubject = $this->sfMakeSubject($tmp_subject);
180       
181        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
182        $objSendMail->sendMail();
183    }
184
185    // 通常のメール送信
186    function sfSendMail($to, $tmp_subject, $body) {
187        $objSiteInfo = new SC_SiteInfo();
188        $arrInfo = $objSiteInfo->data;
189        // メール送信処理
190        $objSendMail = new SC_SendMail_Ex();
191        $bcc = $arrInfo['email01'];
192        $from = $arrInfo['email03'];
193        $error = $arrInfo['email04'];
194        $tosubject = $this->sfMakeSubject($tmp_subject);
195       
196        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
197        $objSendMail->sendMail();
198    }
199
200    //件名にテンプレートを用いる
201    function sfMakeSubject($subject) {
202        $objQuery = new SC_Query();
203        $objMailView = new SC_SiteView();
204        $objTplAssign = new stdClass;
205       
206        $arrInfo = $objQuery->select("*","dtb_baseinfo");
207        $arrInfo = $arrInfo[0];
208        $objTplAssign->tpl_shopname=$arrInfo['shop_name'];
209        $objTplAssign->tpl_infoemail=$subject; // 従来互換
210        $objTplAssign->tpl_mailtitle=$subject;
211        $objMailView->assignobj($objTplAssign);
212        $subject = $objMailView->fetch('mail_templates/mail_title.tpl');
213        return $subject;
214    }
215
216    // メール配信履歴への登録
217    function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
218        $sqlval['subject'] = $subject;
219        $sqlval['order_id'] = $order_id;
220        $sqlval['template_id'] = $template_id;
221        $sqlval['send_date'] = "Now()";
222        if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
223        if($_SESSION['member_id'] != "") {
224            $sqlval['creator_id'] = $_SESSION['member_id'];
225        } else {
226            $sqlval['creator_id'] = '0';
227        }
228        $sqlval['mail_body'] = $body;
229
230        $objQuery = new SC_Query();
231        $sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id");
232        $objQuery->insert("dtb_mail_history", $sqlval);
233    }
234
235    /* 会員登録があるかどうかのチェック(仮会員を含まない) */
236    function sfCheckCustomerMailMaga($email) {
237        $col = "email, mailmaga_flg, customer_id";
238        $from = "dtb_customer";
239        $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
240        $objQuery = new SC_Query();
241        $arrRet = $objQuery->select($col, $from, $where, array($email));
242        // 会員のメールアドレスが登録されている
243        if(!empty($arrRet[0]['customer_id'])) {
244            return true;
245        }
246        return false;
247    }
248}
249?>
Note: See TracBrowser for help on using the repository browser.