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

Revision 19897, 9.5 KB checked in by kotani, 16 years ago (diff)

#880(mobile/sphoneディレクトリを削除)に対応。まずmobileのみ意図通りの動作になるように一部コミット(shopping/入力内容確認ページ)

  • 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    }
44
45    /* DBに登録されたテンプレートメールの送信 */
46    function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "") {
47
48        $objQuery = new SC_Query();
49        // メールテンプレート情報の取得
50        $where = "template_id = ?";
51        $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
52        $objPage->tpl_header = $arrRet[0]['header'];
53        $objPage->tpl_footer = $arrRet[0]['footer'];
54        $tmp_subject = $arrRet[0]['subject'];
55
56        $objSiteInfo = new SC_SiteInfo();
57        $arrInfo = $objSiteInfo->data;
58
59        $objMailView = new SC_SiteView();
60        // メール本文の取得
61        $objMailView->assignobj($objPage);
62        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
63
64        // メール送信処理
65        $objSendMail = new SC_SendMail_Ex();
66        if ($from_address == "") $from_address = $arrInfo['email03'];
67        if ($from_name == "") $from_name = $arrInfo['shop_name'];
68        if ($reply_to == "") $reply_to = $arrInfo['email03'];
69        $error = $arrInfo['email04'];
70        $tosubject = $this->sfMakeSubject($tmp_subject);
71       
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        $arrTplVar = new stdClass();
81        $objSiteInfo = new SC_SiteInfo();
82        $arrInfo = $objSiteInfo->data;
83        $arrTplVar->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            $arrTplVar->tpl_header = $arrRet[0]['header'];
92            $arrTplVar->tpl_footer = $arrRet[0]['footer'];
93            $tmp_subject = $arrRet[0]['subject'];
94        } else {
95            $arrTplVar->tpl_header = $header;
96            $arrTplVar->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        $arrTplVar->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        $arrTplVar->arrCustomer = $arrCustomer;
114        $arrTplVar->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            $arrTplVar->arrOther = $arrOther;
127        }
128
129        // 都道府県変換
130        $arrTplVar->arrOrder['deliv_pref_name'] = $this->arrPref[$arrTplVar->arrOrder['deliv_pref']];
131        $arrTplVar->arrOrder['order_pref_name'] = $this->arrPref[$arrTplVar->arrOrder['order_pref']];
132
133        $arrTplVar->arrOrderDetail = $arrOrderDetail;
134
135        $objCustomer = new SC_Customer();
136        $arrTplVar->tpl_user_point = $objCustomer->getValue('point');
137
138       if(Net_UserAgent_Mobile::isMobile() === true) {
139            $objMailView = new SC_MobileView();
140       } else {
141            $objMailView = new SC_SiteView();
142       }
143        // メール本文の取得
144        $objMailView->assignobj($arrTplVar);
145        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
146
147        // メール送信処理
148        $objSendMail = new SC_SendMail_Ex();
149        $bcc = $arrInfo['email01'];
150        $from = $arrInfo['email03'];
151        $error = $arrInfo['email04'];
152        $tosubject = $this->sfMakeSubject($tmp_subject);
153
154        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
155        $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様");
156
157
158        // 送信フラグ:trueの場合は、送信する。
159        if($send) {
160            if ($objSendMail->sendMail()) {
161                $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
162            }
163        }
164
165        return $objSendMail;
166    }
167
168    // テンプレートを使用したメールの送信
169    function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) {
170        $objMailView = new SC_SiteView();
171        $objSiteInfo = new SC_SiteInfo();
172        $arrInfo = $objSiteInfo->data;
173        // メール本文の取得
174        $objPage->tpl_shopname=$arrInfo['shop_name'];
175        $objPage->tpl_infoemail = $arrInfo['email02'];
176        $objMailView->assignobj($objPage);
177        $body = $objMailView->fetch($tplpath);
178        // メール送信処理
179        $objSendMail = new SC_SendMail_Ex();
180        $bcc = $arrInfo['email01'];
181        $from = $arrInfo['email03'];
182        $error = $arrInfo['email04'];
183        $tosubject = $this->sfMakeSubject($tmp_subject);
184       
185        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
186        $objSendMail->sendMail();
187    }
188
189    // 通常のメール送信
190    function sfSendMail($to, $tmp_subject, $body) {
191        $objSiteInfo = new SC_SiteInfo();
192        $arrInfo = $objSiteInfo->data;
193        // メール送信処理
194        $objSendMail = new SC_SendMail_Ex();
195        $bcc = $arrInfo['email01'];
196        $from = $arrInfo['email03'];
197        $error = $arrInfo['email04'];
198        $tosubject = $this->sfMakeSubject($tmp_subject);
199       
200        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
201        $objSendMail->sendMail();
202    }
203
204    //件名にテンプレートを用いる
205    function sfMakeSubject($subject) {
206        $objQuery = new SC_Query();
207        $objMailView = new SC_SiteView();
208        $objTplAssign = new stdClass;
209       
210        $arrInfo = $objQuery->select("*","dtb_baseinfo");
211        $arrInfo = $arrInfo[0];
212        $objTplAssign->tpl_shopname=$arrInfo['shop_name'];
213        $objTplAssign->tpl_infoemail=$subject; // 従来互換
214        $objTplAssign->tpl_mailtitle=$subject;
215        $objMailView->assignobj($objTplAssign);
216        $subject = $objMailView->fetch('mail_templates/mail_title.tpl');
217        return $subject;
218    }
219
220    // メール配信履歴への登録
221    function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
222        $sqlval['subject'] = $subject;
223        $sqlval['order_id'] = $order_id;
224        $sqlval['template_id'] = $template_id;
225        $sqlval['send_date'] = "Now()";
226        if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
227        if($_SESSION['member_id'] != "") {
228            $sqlval['creator_id'] = $_SESSION['member_id'];
229        } else {
230            $sqlval['creator_id'] = '0';
231        }
232        $sqlval['mail_body'] = $body;
233
234        $objQuery = new SC_Query();
235        $sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id");
236        $objQuery->insert("dtb_mail_history", $sqlval);
237    }
238
239    /* 会員登録があるかどうかのチェック(仮会員を含まない) */
240    function sfCheckCustomerMailMaga($email) {
241        $col = "email, mailmaga_flg, customer_id";
242        $from = "dtb_customer";
243        $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
244        $objQuery = new SC_Query();
245        $arrRet = $objQuery->select($col, $from, $where, array($email));
246        // 会員のメールアドレスが登録されている
247        if(!empty($arrRet[0]['customer_id'])) {
248            return true;
249        }
250        return false;
251    }
252}
253?>
Note: See TracBrowser for help on using the repository browser.