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

Revision 22818, 8.9 KB checked in by m_uehara, 11 years ago (diff)

#2236 2.12.3にて行われていた対応(r22231,r22241,r22282,r22348,r22374,r22376,r22440,r22545,r22546)を元に戻します

  • 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-2013 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        $post = $_POST;
74        //一括送信用の処理
75        if (array_key_exists('mail_order_id',$post) and $post['mode'] == 'mail_select'){
76            $post['order_id_array'] = implode(',',$post['mail_order_id']);
77        } else if(!array_key_exists('order_id_array',$post)){
78            $post['order_id_array'] = $post['order_id'];
79        }
80
81        //一括送信処理変数チェック(ここですべきかは課題)
82        if (preg_match("/^[0-9|\,]*$/",$post['order_id_array'])){
83            $this->order_id_array = $post['order_id_array'];
84        } else {
85            //エラーで元に戻す
86            SC_Response_Ex::sendRedirect(ADMIN_ORDER_URLPATH);
87            SC_Response_Ex::actionExit();
88        }
89
90        //メール本文の確認例は初めの1受注とする
91        if (!SC_Utils_Ex::isBlank($this->order_id_array)){
92            $order_id_array = split(',',$this->order_id_array);
93            $post['order_id'] = intval($order_id_array[0]);
94            $this->order_id_count = count($order_id_array);
95        }
96
97        // パラメーター管理クラス
98        $objFormParam = new SC_FormParam_Ex();
99        // パラメーター情報の初期化
100        $this->lfInitParam($objFormParam);
101
102        // POST値の取得
103        $objFormParam->setParam($post);
104        $objFormParam->convParam();
105        $this->tpl_order_id = $objFormParam->getValue('order_id');
106
107        // 検索パラメーターの引き継ぎ
108        $this->arrSearchHidden = $objFormParam->getSearchArray();
109
110        // 履歴を読み込むか
111        $load_history = SC_Utils_Ex::sfIsInt($this->tpl_order_id);
112
113        switch ($this->getMode()) {
114            case 'confirm':
115                $status = $this->confirm($objFormParam);
116                if ($status === true) {
117                    $load_history = false;
118                } else {
119                    $this->arrErr = $status;
120                }
121                break;
122
123            case 'send':
124                $sendStatus = $this->doSend($objFormParam);
125                if ($sendStatus === true) {
126                    SC_Response_Ex::sendRedirect(ADMIN_ORDER_URLPATH);
127                    SC_Response_Ex::actionExit();
128                }
129                $this->arrErr = $sendStatus;
130                break;
131
132            case 'change':
133                $objFormParam =  $this->changeData($objFormParam);
134                break;
135
136            case 'pre_edit':
137            case 'mail_select':
138            case 'return':
139            default:
140                break;
141        }
142
143        // 入力内容の引き継ぎ
144        $this->arrForm = $objFormParam->getFormParamList();
145
146        if ($load_history) {
147            $this->arrMailHistory = $this->getMailHistory($this->tpl_order_id);
148        }
149    }
150
151    /**
152     * 指定された注文番号のメール履歴を取得する。
153     * @var int order_id
154     */
155    function getMailHistory($order_id) {
156        $objQuery =& SC_Query_Ex::getSingletonInstance();
157        $col = 'send_date, subject, template_id, send_id';
158        $where = 'order_id = ?';
159        $objQuery->setOrder('send_date DESC');
160        return $objQuery->select($col, 'dtb_mail_history', $where, array($order_id));
161    }
162
163    /**
164     *
165     * メールを送る。
166     * @param SC_FormParam $objFormParam
167     */
168    function doSend(&$objFormParam) {
169        $arrErr = $objFormParam->checkerror();
170
171        // メールの送信
172        if (count($arrErr) == 0) {
173            // 注文受付メール(複数受注ID対応)
174            $order_id_array = explode(',',$this->order_id_array);
175            foreach ($order_id_array as $order_id){
176                $objMail = new SC_Helper_Mail_Ex();
177                $objSendMail = $objMail->sfSendOrderMail($order_id,
178                $objFormParam->getValue('template_id'),
179                $objFormParam->getValue('subject'),
180                $objFormParam->getValue('header'),
181                $objFormParam->getValue('footer'));
182            }
183            // TODO $SC_SendMail から送信がちゃんと出来たか確認できたら素敵。
184            return true;
185        }
186        return $arrErr;
187    }
188
189    /**
190     * 確認画面を表示する為の準備
191     * @param SC_FormParam $objFormParam
192     */
193    function confirm(&$objFormParam) {
194        $arrErr = $objFormParam->checkerror();
195        // メールの送信
196        if (count($arrErr) == 0) {
197            // 注文受付メール(送信なし)
198            $objMail = new SC_Helper_Mail_Ex();
199            $objSendMail = $objMail->sfSendOrderMail(
200                $objFormParam->getValue('order_id'),
201                $objFormParam->getValue('template_id'),
202                $objFormParam->getValue('subject'),
203                $objFormParam->getValue('header'),
204                $objFormParam->getValue('footer'), false);
205
206            $this->tpl_subject = $objFormParam->getValue('subject');
207            $this->tpl_body = mb_convert_encoding($objSendMail->body, CHAR_CODE, 'auto');
208            $this->tpl_to = $objSendMail->tpl_to;
209            $this->tpl_mainpage = 'order/mail_confirm.tpl';
210            return true;
211        }
212        return $arrErr;
213    }
214
215    /**
216     *
217     * テンプレートの文言をフォームに入れる。
218     * @param SC_FormParam $objFormParam
219     */
220    function changeData(&$objFormParam) {
221        $objQuery =& SC_Query_Ex::getSingletonInstance();
222
223        $template_id = $objFormParam->getValue('template_id');
224
225        // 未選択時
226        if (strlen($template_id) === 0) {
227            $mailTemplates = null;
228        }
229        // 有効選択時
230        elseif (SC_Utils_Ex::sfIsInt($template_id)) {
231            $where = 'template_id = ?';
232            $arrWhereVal = array($template_id);
233            $mailTemplates = $objQuery->getRow('subject, header, footer', 'dtb_mailtemplate', $where, $arrWhereVal);
234        }
235        // 不正選択時
236        else {
237            trigger_error('テンプレートの指定が不正。', E_USER_ERROR);
238        }
239
240        if (empty($mailTemplates)) {
241            foreach (array('subject','header','footer') as $key) {
242                $objFormParam->setValue($key, '');
243            }
244        } else {
245            $objFormParam->setParam($mailTemplates);
246        }
247
248        return $objFormParam;
249    }
250
251    /**
252     * デストラクタ.
253     *
254     * @return void
255     */
256    function destroy() {
257        parent::destroy();
258    }
259
260    /**
261     * パラメーター情報の初期化
262     * @param SC_FormParam $objFormParam
263     */
264    function lfInitParam(&$objFormParam) {
265        // 検索条件のパラメーターを初期化
266        parent::lfInitParam($objFormParam);
267        $objFormParam->addParam('テンプレート', 'template_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
268        $objFormParam->addParam('メールタイトル', 'subject', STEXT_LEN, 'KVa',  array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
269        $objFormParam->addParam('ヘッダー', 'header', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
270        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
271    }
272}
Note: See TracBrowser for help on using the repository browser.