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

Revision 21820, 8.8 KB checked in by adachi, 12 years ago (diff)

#1797 #1798 メールテンプレートでfilterが動作するように修正

  • 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        //一括送信用の処理
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 ($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        switch ($this->getMode()) {
111            case 'pre_edit':
112            case 'mail_select':
113                break;
114            case 'return':
115                break;
116            case 'send':
117                $sendStatus = $this->doSend($objFormParam);
118                if ($sendStatus === true) {
119
120                    SC_Response_Ex::sendRedirect(ADMIN_ORDER_URLPATH);
121                    SC_Response_Ex::actionExit();
122                } else {
123                    $this->arrErr = $sendStatus;
124                }
125            case 'confirm':
126                $status = $this->confirm($objFormParam);
127                if ($status === true) {
128                    $this->arrHidden = $objFormParam->getHashArray();
129
130                    return ;
131                } else {
132                    $this->arrErr = $status;
133                }
134                break;
135            case 'change':
136                $objFormParam =  $this->changeData($objFormParam);
137                break;
138        }
139
140        if (SC_Utils_Ex::sfIsInt($objFormParam->getValue('order_id'))) {
141            $this->arrMailHistory = $this->getMailHistory($objFormParam->getValue('order_id'));
142        }
143
144        $this->arrForm = $objFormParam->getFormParamList();
145
146    }
147
148    /**
149     * 指定された注文番号のメール履歴を取得する。
150     * @var int order_id
151     */
152    function getMailHistory($order_id) {
153        $objQuery =& SC_Query_Ex::getSingletonInstance();
154        $col = 'send_date, subject, template_id, send_id';
155        $where = 'order_id = ?';
156        $objQuery->setOrder('send_date DESC');
157        return $objQuery->select($col, 'dtb_mail_history', $where, array($order_id));
158    }
159
160    /**
161     *
162     * メールを送る。
163     * @param SC_FormParam $objFormParam
164     */
165    function doSend(&$objFormParam) {
166        $arrErr = $objFormParam->checkerror();
167
168        // メールの送信
169        if (count($arrErr) == 0) {
170            // 注文受付メール(複数受注ID対応)
171            $order_id_array = explode(',',$this->order_id_array);
172            foreach ($order_id_array as $order_id){
173                $objMail = new SC_Helper_Mail_Ex();
174                $objMail->setPage($this);
175                $objSendMail = $objMail->sfSendOrderMail($order_id,
176                $objFormParam->getValue('template_id'),
177                $objFormParam->getValue('subject'),
178                $objFormParam->getValue('header'),
179                $objFormParam->getValue('footer'));
180            }
181            // TODO $SC_SendMail から送信がちゃんと出来たか確認できたら素敵。
182            return true;
183        }
184        return $arrErr;
185    }
186
187    /**
188     * 確認画面を表示する為の準備
189     * @param SC_FormParam $objFormParam
190     */
191    function confirm(&$objFormParam) {
192        $arrErr = $objFormParam->checkerror();
193        // メールの送信
194        if (count($arrErr) == 0) {
195            // 注文受付メール(送信なし)
196            $objMail = new SC_Helper_Mail_Ex();
197            $objMail->setPage($this);
198            $objSendMail = $objMail->sfSendOrderMail(
199                $objFormParam->getValue('order_id'),
200                $objFormParam->getValue('template_id'),
201                $objFormParam->getValue('subject'),
202                $objFormParam->getValue('header'),
203                $objFormParam->getValue('footer'), false);
204
205            $this->tpl_subject = $objFormParam->getValue('subject');
206            $this->tpl_body = mb_convert_encoding($objSendMail->body, CHAR_CODE, 'auto');
207            $this->tpl_to = $objSendMail->tpl_to;
208            $this->tpl_mainpage = 'order/mail_confirm.tpl';
209            return true;
210        }
211        return $arrErr;
212    }
213
214    /**
215     *
216     * テンプレートの文言をフォームに入れる。
217     * @param SC_FormParam $objFormParam
218     */
219    function changeData(&$objFormParam) {
220        if (SC_Utils_Ex::sfIsInt($objFormParam->getValue('template_id'))) {
221            $objQuery =& SC_Query_Ex::getSingletonInstance();
222            $where = 'template_id = ?';
223            $mailTemplates = $objQuery->select('subject, header, footer', 'dtb_mailtemplate', $where, array($objFormParam->getValue('template_id')));
224            if (!is_null($mailTemplates)) {
225                foreach (array('subject','header','footer') as $key) {
226                    $objFormParam->setValue($key,$mailTemplates[$key]);
227                }
228            }
229            $objFormParam->setParam($mailTemplates[0]);
230        } else {
231            foreach (array('subject','header','footer') as $key) {
232                $objFormParam->setValue($key,'');
233            }
234        }
235        return $objFormParam;
236    }
237
238    /**
239     * デストラクタ.
240     *
241     * @return void
242     */
243    function destroy() {
244        parent::destroy();
245    }
246
247    /**
248     * パラメーター情報の初期化
249     * @param SC_FormParam $objFormParam
250     */
251    function lfInitParam(&$objFormParam) {
252        // 検索条件のパラメーターを初期化
253        parent::lfInitParam($objFormParam);
254        $objFormParam->addParam('テンプレート', 'template_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
255        $objFormParam->addParam('メールタイトル', 'subject', STEXT_LEN, 'KVa',  array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
256        $objFormParam->addParam('ヘッダー', 'header', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
257        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
258    }
259}
Note: See TracBrowser for help on using the repository browser.