source: branches/version-2_12-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Mail.php @ 21591

Revision 21591, 8.4 KB checked in by h_yoshimoto, 12 years ago (diff)

#1686 管理画面にフックポイントを配置

  • 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
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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// {{{ requires
25require_once CLASS_EX_REALDIR . 'page_extends/admin/order/LC_Page_Admin_Order_Ex.php';
26
27/**
28 * 受注メール管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Order_Mail extends LC_Page_Admin_Order_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'order/mail.tpl';
47        $this->tpl_mainno = 'order';
48        $this->tpl_subno = 'index';
49        $this->tpl_maintitle = '受注管理';
50        $this->tpl_subtitle = '受注管理';
51
52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrMAILTEMPLATE = $masterData->getMasterData('mtb_mail_template');
54        $this->httpCacheControl('nocache');
55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
70     * @return void
71     */
72    function action() {
73        // フックポイント.
74        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
75        $objPlugin->doAction('lc_page_admin_order_mail_action_start', array($this));
76
77        // パラメーター管理クラス
78        $objFormParam = new SC_FormParam_Ex();
79        // パラメーター情報の初期化
80        $this->lfInitParam($objFormParam);
81
82        // POST値の取得
83        $objFormParam->setParam($_POST);
84        $objFormParam->convParam();
85        $this->tpl_order_id = $objFormParam->getValue('order_id');
86
87        // 検索パラメーターの引き継ぎ
88        $this->arrSearchHidden = $objFormParam->getSearchArray();
89
90        switch ($this->getMode()) {
91            case 'pre_edit':
92                break;
93            case 'return':
94                break;
95            case 'send':
96                $sendStatus = $this->doSend($objFormParam);
97                if ($sendStatus === true) {
98                    // フックポイント.
99                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
100                    $objPlugin->doAction('lc_page_admin_order_mail_action_send', array($this));
101
102                    SC_Response_Ex::sendRedirect(ADMIN_ORDER_URLPATH);
103                    exit;
104                } else {
105                    $this->arrErr = $sendStatus;
106                }
107            case 'confirm':
108                $status = $this->confirm($objFormParam);
109                if ($status === true) {
110                    $this->arrHidden = $objFormParam->getHashArray();
111
112                    // フックポイント.
113                    $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
114                    $objPlugin->doAction('lc_page_admin_order_mail_action_confirm', array($this));
115
116                    return ;
117                } else {
118                    $this->arrErr = $status;
119                }
120                break;
121            case 'change':
122                $objFormParam =  $this->changeData($objFormParam);
123                break;
124        }
125
126        if (SC_Utils_Ex::sfIsInt($objFormParam->getValue('order_id'))) {
127            $this->arrMailHistory = $this->getMailHistory($objFormParam->getValue('order_id'));
128        }
129
130        $this->arrForm = $objFormParam->getFormParamList();
131
132        // フックポイント.
133        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance();
134        $objPlugin->doAction('lc_page_admin_order_mail_action_end', array($this));
135    }
136
137    /**
138     * 指定された注文番号のメール履歴を取得する。
139     * @var int order_id
140     */
141    function getMailHistory($order_id) {
142        $objQuery =& SC_Query_Ex::getSingletonInstance();
143        $col = 'send_date, subject, template_id, send_id';
144        $where = 'order_id = ?';
145        $objQuery->setOrder('send_date DESC');
146        return $objQuery->select($col, 'dtb_mail_history', $where, array($order_id));
147    }
148
149    /**
150     *
151     * メールを送る。
152     * @param SC_FormParam $objFormParam
153     */
154    function doSend(&$objFormParam) {
155        $arrErr = $objFormParam->checkerror();
156
157        // メールの送信
158        if (count($arrErr) == 0) {
159            // 注文受付メール
160            $objMail = new SC_Helper_Mail_Ex();
161            $objSendMail = $objMail->sfSendOrderMail($objFormParam->getValue('order_id'),
162            $objFormParam->getValue('template_id'),
163            $objFormParam->getValue('subject'),
164            $objFormParam->getValue('header'),
165            $objFormParam->getValue('footer'));
166            // TODO $SC_SendMail から送信がちゃんと出来たか確認できたら素敵。
167            return true;
168        }
169        return $arrErr;
170    }
171
172    /**
173     * 確認画面を表示する為の準備
174     * @param SC_FormParam $objFormParam
175     */
176    function confirm(&$objFormParam) {
177        $arrErr = $objFormParam->checkerror();
178        // メールの送信
179        if (count($arrErr) == 0) {
180            // 注文受付メール(送信なし)
181            $objMail = new SC_Helper_Mail_Ex();
182            $objSendMail = $objMail->sfSendOrderMail(
183            $objFormParam->getValue('order_id'),
184            $objFormParam->getValue('template_id'),
185            $objFormParam->getValue('subject'),
186            $objFormParam->getValue('header'),
187            $objFormParam->getValue('footer'), false);
188
189            $this->tpl_subject = $objFormParam->getValue('subject');
190            $this->tpl_body = mb_convert_encoding($objSendMail->body, CHAR_CODE, 'auto');
191            $this->tpl_to = $objSendMail->tpl_to;
192            $this->tpl_mainpage = 'order/mail_confirm.tpl';
193            return true;
194        }
195        return $arrErr;
196    }
197
198    /**
199     *
200     * テンプレートの文言をフォームに入れる。
201     * @param SC_FormParam $objFormParam
202     */
203    function changeData(&$objFormParam) {
204        if (SC_Utils_Ex::sfIsInt($objFormParam->getValue('template_id'))) {
205            $objQuery =& SC_Query_Ex::getSingletonInstance();
206            $where = 'template_id = ?';
207            $mailTemplates = $objQuery->select('subject, header, footer', 'dtb_mailtemplate', $where, array($objFormParam->getValue('template_id')));
208            if (!is_null($mailTemplates)) {
209                foreach (array('subject','header','footer') as $key) {
210                    $objFormParam->setValue($key,$mailTemplates[$key]);
211                }
212            }
213            $objFormParam->setParam($mailTemplates[0]);
214        } else {
215            foreach (array('subject','header','footer') as $key) {
216                $objFormParam->setValue($key,'');
217            }
218        }
219        return $objFormParam;
220    }
221
222    /**
223     * デストラクタ.
224     *
225     * @return void
226     */
227    function destroy() {
228        parent::destroy();
229    }
230
231    /**
232     * パラメーター情報の初期化
233     * @param SC_FormParam $objFormParam
234     */
235    function lfInitParam(&$objFormParam) {
236        // 検索条件のパラメーターを初期化
237        parent::lfInitParam($objFormParam);
238
239        $objFormParam->addParam('オーダーID', 'order_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
240        $objFormParam->addParam('テンプレート', 'template_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
241        $objFormParam->addParam('メールタイトル', 'subject', STEXT_LEN, 'KVa',  array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
242        $objFormParam->addParam('ヘッダー', 'header', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
243        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
244    }
245}
Note: See TracBrowser for help on using the repository browser.