source: branches/feature-module-update/data/class/helper/SC_Helper_Mail.php @ 16611

Revision 16611, 8.9 KB checked in by nanasess, 14 years ago (diff)

SC_Utils の呼び出し修正

  • 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-2007 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) {
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        $from = $arrInfo['email03'];
68        $error = $arrInfo['email04'];
69        $tosubject = $tmp_subject;
70        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error);
71        $objSendMail->setTo($to, $to_name);
72        $objSendMail->sendMail();    // メール送信
73    }
74
75    /* 受注完了メール送信 */
76    function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
77
78        $objPage = new LC_Page();
79        $objSiteInfo = new SC_SiteInfo();
80        $arrInfo = $objSiteInfo->data;
81        $objPage->arrInfo = $arrInfo;
82
83        $objQuery = new SC_Query();
84
85        if($subject == "" && $header == "" && $footer == "") {
86            // メールテンプレート情報の取得
87            $where = "template_id = ?";
88            $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array('1'));
89            $objPage->tpl_header = $arrRet[0]['header'];
90            $objPage->tpl_footer = $arrRet[0]['footer'];
91            $tmp_subject = $arrRet[0]['subject'];
92        } else {
93            $objPage->tpl_header = $header;
94            $objPage->tpl_footer = $footer;
95            $tmp_subject = $subject;
96        }
97
98        // 受注情報の取得
99        $where = "order_id = ?";
100        $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
101        $arrOrder = $arrRet[0];
102        $arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
103
104        $objPage->Message_tmp = $arrOrder['message'];
105
106        // 顧客情報の取得
107        $customer_id = $arrOrder['customer_id'];
108        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
109        $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : "";
110
111        $objPage->arrCustomer = $arrCustomer;
112        $objPage->arrOrder = $arrOrder;
113
114        //その他決済情報
115        if($arrOrder['memo02'] != "") {
116            $arrOther = unserialize($arrOrder['memo02']);
117
118            foreach($arrOther as $other_key => $other_val){
119                if(SC_Utils_Ex::sfTrim($other_val["value"]) == ""){
120                    $arrOther[$other_key]["value"] = "";
121                }
122            }
123
124            $objPage->arrOther = $arrOther;
125        }
126
127        // 都道府県変換
128        $objPage->arrOrder['deliv_pref'] = $this->arrPref[$objPage->arrOrder['deliv_pref']];
129
130        $objPage->arrOrderDetail = $arrOrderDetail;
131
132        $objCustomer = new SC_Customer();
133        $objPage->tpl_user_point = $objCustomer->getValue('point');
134
135        $objMailView = new SC_SiteView();
136        // メール本文の取得
137        $objMailView->assignobj($objPage);
138        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
139
140        // メール送信処理
141        $objSendMail = new SC_SendMail_Ex();
142        $bcc = $arrInfo['email01'];
143        $from = $arrInfo['email03'];
144        $error = $arrInfo['email04'];
145
146        $tosubject = $this->sfMakeSubject($objQuery, $objMailView,
147                                             $objPage, $tmp_subject);
148
149        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
150        $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様");
151
152
153        // 送信フラグ:trueの場合は、送信する。
154        if($send) {
155            if ($objSendMail->sendMail()) {
156                $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
157            }
158        }
159
160        return $objSendMail;
161    }
162
163    // テンプレートを使用したメールの送信
164    function sfSendTplMail($to, $subject, $tplpath, &$objPage) {
165        $objMailView = new SC_SiteView();
166        $objSiteInfo = new SC_SiteInfo();
167        $arrInfo = $objSiteInfo->data;
168        // メール本文の取得
169        $objPage->tpl_shopname=$arrInfo['shop_name'];
170        $objPage->tpl_infoemail = $arrInfo['email02'];
171        $objMailView->assignobj($objPage);
172        $body = $objMailView->fetch($tplpath);
173        // メール送信処理
174        $objSendMail = new SC_SendMail_Ex();
175        $to = mb_encode_mimeheader($to);
176        $bcc = $arrInfo['email01'];
177        $from = $arrInfo['email03'];
178        $error = $arrInfo['email04'];
179        $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
180        $objSendMail->sendMail();
181    }
182
183    // 通常のメール送信
184    function sfSendMail($to, $subject, $body) {
185        $objSiteInfo = new SC_SiteInfo();
186        $arrInfo = $objSiteInfo->data;
187        // メール送信処理
188        $objSendMail = new SC_SendMail_Ex();
189        $bcc = $arrInfo['email01'];
190        $from = $arrInfo['email03'];
191        $error = $arrInfo['email04'];
192        $objSendMail->setItem($to, $subject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
193        $objSendMail->sendMail();
194    }
195
196    //件名にテンプレートを用いる
197    function sfMakeSubject(&$objQuery, &$objMailView, &$objPage, $subject){
198
199        $arrInfo = $objQuery->select("*","dtb_baseinfo");
200        $arrInfo = $arrInfo[0];
201        $objPage->tpl_shopname=$arrInfo['shop_name'];
202        $objPage->tpl_infoemail=$subject;
203        $objMailView->assignobj($objPage);
204        $mailtitle = $objMailView->fetch('mail_templates/mail_title.tpl');
205        $ret = $mailtitle.$subject;
206        return $ret;
207    }
208
209    // メール配信履歴への登録
210    function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
211        $sqlval['subject'] = $subject;
212        $sqlval['order_id'] = $order_id;
213        $sqlval['template_id'] = $template_id;
214        $sqlval['send_date'] = "Now()";
215        if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
216        if($_SESSION['member_id'] != "") {
217            $sqlval['creator_id'] = $_SESSION['member_id'];
218        } else {
219            $sqlval['creator_id'] = '0';
220        }
221        $sqlval['mail_body'] = $body;
222
223        $objQuery = new SC_Query();
224        $objQuery->insert("dtb_mail_history", $sqlval);
225    }
226
227    /* 会員登録があるかどうかのチェック(仮会員を含まない) */
228    function sfCheckCustomerMailMaga($email) {
229        $col = "email, mailmaga_flg, customer_id";
230        $from = "dtb_customer";
231        $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
232        $objQuery = new SC_Query();
233        $arrRet = $objQuery->select($col, $from, $where, array($email));
234        // 会員のメールアドレスが登録されている
235        if(!empty($arrRet[0]['customer_id'])) {
236            return true;
237        }
238        return false;
239    }
240}
241?>
Note: See TracBrowser for help on using the repository browser.