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

Revision 20116, 10.3 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
RevLine 
[15618]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[18701]5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
[15618]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15618]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");
[19773]42        $this->arrPref = $masterData->getMasterData('mtb_pref');
[15618]43    }
44
45    /* DBに登録されたテンプレートメールの送信 */
[17375]46    function sfSendTemplateMail($to, $to_name, $template_id, &$objPage, $from_address = "", $from_name = "", $reply_to = "") {
[15618]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);
[15622]62        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
[15618]63
64        // メール送信処理
[16503]65        $objSendMail = new SC_SendMail_Ex();
[17375]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'];
[15618]69        $error = $arrInfo['email04'];
[17590]70        $tosubject = $this->sfMakeSubject($tmp_subject);
71       
[17375]72        $objSendMail->setItem('', $tosubject, $body, $from_address, $from_name, $reply_to, $error, $error);
[15618]73        $objSendMail->setTo($to, $to_name);
[16181]74        $objSendMail->sendMail();    // メール送信
[15618]75    }
76
77    /* 受注完了メール送信 */
78    function sfSendOrderMail($order_id, $template_id, $subject = "", $header = "", $footer = "", $send = true) {
79
[19749]80        $arrTplVar = new stdClass();
[15618]81        $objSiteInfo = new SC_SiteInfo();
82        $arrInfo = $objSiteInfo->data;
[19749]83        $arrTplVar->arrInfo = $arrInfo;
[15618]84
85        $objQuery = new SC_Query();
86
87        if($subject == "" && $header == "" && $footer == "") {
88            // メールテンプレート情報の取得
89            $where = "template_id = ?";
[17375]90            $arrRet = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($template_id));
[19749]91            $arrTplVar->tpl_header = $arrRet[0]['header'];
92            $arrTplVar->tpl_footer = $arrRet[0]['footer'];
[15618]93            $tmp_subject = $arrRet[0]['subject'];
94        } else {
[19749]95            $arrTplVar->tpl_header = $header;
96            $arrTplVar->tpl_footer = $footer;
[15618]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];
[19978]104        $arrTplVar->arrOrderDetail = $objQuery->select("*", "dtb_order_detail", $where, array($order_id));
[15618]105
[19978]106        $objProduct = new SC_Product();
107        $objQuery->setOrder('shipping_id');
108        $arrRet = $objQuery->select("*", "dtb_shipping", "order_id = ?", array($order_id));
109        foreach (array_keys($arrRet) as $key) {
110            $objQuery->setOrder('shipping_id');
111            $arrItems = $objQuery->select("*", "dtb_shipment_item", "order_id = ? AND shipping_id = ?",
112                                          array($order_id, $arrRet[$key]['shipping_id']));
113            foreach ($arrItems as $itemKey => $arrDetail) {
114                foreach ($arrDetail as $detailKey => $detailVal) {
115                    $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']][$detailKey] = $detailVal;
116                }
117
118                $arrRet[$key]['shipment_item'][$arrDetail['product_class_id']]['productsClass'] =& $objProduct->getDetailAndProductsClass($arrDetail['product_class_id']);
119            }
120        }
121        $arrTplVar->arrShipping = $arrRet;
122
[19749]123        $arrTplVar->Message_tmp = $arrOrder['message'];
[15618]124
125        // 顧客情報の取得
126        $customer_id = $arrOrder['customer_id'];
[19978]127        $objQuery->setOrder('customer_id');
[15618]128        $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id));
[16189]129        $arrCustomer = isset($arrRet[0]) ? $arrRet[0] : "";
[15618]130
[19749]131        $arrTplVar->arrCustomer = $arrCustomer;
132        $arrTplVar->arrOrder = $arrOrder;
[15618]133
134        //その他決済情報
135        if($arrOrder['memo02'] != "") {
136            $arrOther = unserialize($arrOrder['memo02']);
137
138            foreach($arrOther as $other_key => $other_val){
[16611]139                if(SC_Utils_Ex::sfTrim($other_val["value"]) == ""){
[15618]140                    $arrOther[$other_key]["value"] = "";
141                }
142            }
143
[19749]144            $arrTplVar->arrOther = $arrOther;
[15618]145        }
146
147        // 都道府県変換
[19978]148        $arrTplVar->arrPref = $this->arrPref;
[15618]149
150        $objCustomer = new SC_Customer();
[19749]151        $arrTplVar->tpl_user_point = $objCustomer->getValue('point');
[15618]152
[19897]153       if(Net_UserAgent_Mobile::isMobile() === true) {
154            $objMailView = new SC_MobileView();
155       } else {
156            $objMailView = new SC_SiteView();
157       }
[15618]158        // メール本文の取得
[19749]159        $objMailView->assignobj($arrTplVar);
[15622]160        $body = $objMailView->fetch($this->arrMAILTPLPATH[$template_id]);
[15618]161
162        // メール送信処理
[16503]163        $objSendMail = new SC_SendMail_Ex();
[15618]164        $bcc = $arrInfo['email01'];
165        $from = $arrInfo['email03'];
166        $error = $arrInfo['email04'];
[17590]167        $tosubject = $this->sfMakeSubject($tmp_subject);
[15618]168
169        $objSendMail->setItem('', $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
170        $objSendMail->setTo($arrOrder["order_email"], $arrOrder["order_name01"] . " ". $arrOrder["order_name02"] ." 様");
171
172
173        // 送信フラグ:trueの場合は、送信する。
174        if($send) {
175            if ($objSendMail->sendMail()) {
[15622]176                $this->sfSaveMailHistory($order_id, $template_id, $tosubject, $body);
[15618]177            }
178        }
179
180        return $objSendMail;
181    }
182
183    // テンプレートを使用したメールの送信
[17590]184    function sfSendTplMail($to, $tmp_subject, $tplpath, &$objPage) {
[15618]185        $objMailView = new SC_SiteView();
186        $objSiteInfo = new SC_SiteInfo();
187        $arrInfo = $objSiteInfo->data;
188        // メール本文の取得
189        $objPage->tpl_shopname=$arrInfo['shop_name'];
190        $objPage->tpl_infoemail = $arrInfo['email02'];
191        $objMailView->assignobj($objPage);
192        $body = $objMailView->fetch($tplpath);
193        // メール送信処理
[16503]194        $objSendMail = new SC_SendMail_Ex();
[15618]195        $bcc = $arrInfo['email01'];
196        $from = $arrInfo['email03'];
197        $error = $arrInfo['email04'];
[17590]198        $tosubject = $this->sfMakeSubject($tmp_subject);
199       
200        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
[15618]201        $objSendMail->sendMail();
202    }
203
204    // 通常のメール送信
[17590]205    function sfSendMail($to, $tmp_subject, $body) {
[15618]206        $objSiteInfo = new SC_SiteInfo();
207        $arrInfo = $objSiteInfo->data;
208        // メール送信処理
[16503]209        $objSendMail = new SC_SendMail_Ex();
[15618]210        $bcc = $arrInfo['email01'];
211        $from = $arrInfo['email03'];
212        $error = $arrInfo['email04'];
[17590]213        $tosubject = $this->sfMakeSubject($tmp_subject);
214       
215        $objSendMail->setItem($to, $tosubject, $body, $from, $arrInfo['shop_name'], $from, $error, $error, $bcc);
[15618]216        $objSendMail->sendMail();
217    }
218
219    //件名にテンプレートを用いる
[17590]220    function sfMakeSubject($subject) {
221        $objQuery = new SC_Query();
222        $objMailView = new SC_SiteView();
223        $objTplAssign = new stdClass;
224       
[15618]225        $arrInfo = $objQuery->select("*","dtb_baseinfo");
226        $arrInfo = $arrInfo[0];
[17590]227        $objTplAssign->tpl_shopname=$arrInfo['shop_name'];
228        $objTplAssign->tpl_infoemail=$subject; // 従来互換
229        $objTplAssign->tpl_mailtitle=$subject;
230        $objMailView->assignobj($objTplAssign);
231        $subject = $objMailView->fetch('mail_templates/mail_title.tpl');
232        return $subject;
[15618]233    }
234
235    // メール配信履歴への登録
236    function sfSaveMailHistory($order_id, $template_id, $subject, $body) {
237        $sqlval['subject'] = $subject;
238        $sqlval['order_id'] = $order_id;
239        $sqlval['template_id'] = $template_id;
240        $sqlval['send_date'] = "Now()";
[16588]241        if (!isset($_SESSION['member_id'])) $_SESSION['member_id'] = "";
[15618]242        if($_SESSION['member_id'] != "") {
243            $sqlval['creator_id'] = $_SESSION['member_id'];
244        } else {
245            $sqlval['creator_id'] = '0';
246        }
247        $sqlval['mail_body'] = $body;
248
249        $objQuery = new SC_Query();
[18788]250        $sqlval['send_id'] = $objQuery->nextVal("dtb_mail_history_send_id");
[15618]251        $objQuery->insert("dtb_mail_history", $sqlval);
252    }
253
[16588]254    /* 会員登録があるかどうかのチェック(仮会員を含まない) */
[15618]255    function sfCheckCustomerMailMaga($email) {
256        $col = "email, mailmaga_flg, customer_id";
257        $from = "dtb_customer";
[16588]258        $where = "(email = ? OR email_mobile = ?) AND status = 2 AND del_flg = 0";
[15618]259        $objQuery = new SC_Query();
260        $arrRet = $objQuery->select($col, $from, $where, array($email));
261        // 会員のメールアドレスが登録されている
[16182]262        if(!empty($arrRet[0]['customer_id'])) {
[15618]263            return true;
264        }
265        return false;
266    }
267}
268?>
Note: See TracBrowser for help on using the repository browser.