source: branches/comu-ver2/data/class/helper/SC_Helper_Mail.php @ 17375

Revision 17375, 9.1 KB checked in by pineray, 18 years ago (diff)

メールテンプレート周り

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