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

Revision 21743, 8.7 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

  • 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                $objSendMail = $objMail->sfSendOrderMail($order_id,
175                $objFormParam->getValue('template_id'),
176                $objFormParam->getValue('subject'),
177                $objFormParam->getValue('header'),
178                $objFormParam->getValue('footer'));
179            }
180            // TODO $SC_SendMail から送信がちゃんと出来たか確認できたら素敵。
181            return true;
182        }
183        return $arrErr;
184    }
185
186    /**
187     * 確認画面を表示する為の準備
188     * @param SC_FormParam $objFormParam
189     */
190    function confirm(&$objFormParam) {
191        $arrErr = $objFormParam->checkerror();
192        // メールの送信
193        if (count($arrErr) == 0) {
194            // 注文受付メール(送信なし)
195            $objMail = new SC_Helper_Mail_Ex();
196            $objSendMail = $objMail->sfSendOrderMail(
197            $objFormParam->getValue('order_id'),
198            $objFormParam->getValue('template_id'),
199            $objFormParam->getValue('subject'),
200            $objFormParam->getValue('header'),
201            $objFormParam->getValue('footer'), false);
202
203            $this->tpl_subject = $objFormParam->getValue('subject');
204            $this->tpl_body = mb_convert_encoding($objSendMail->body, CHAR_CODE, 'auto');
205            $this->tpl_to = $objSendMail->tpl_to;
206            $this->tpl_mainpage = 'order/mail_confirm.tpl';
207            return true;
208        }
209        return $arrErr;
210    }
211
212    /**
213     *
214     * テンプレートの文言をフォームに入れる。
215     * @param SC_FormParam $objFormParam
216     */
217    function changeData(&$objFormParam) {
218        if (SC_Utils_Ex::sfIsInt($objFormParam->getValue('template_id'))) {
219            $objQuery =& SC_Query_Ex::getSingletonInstance();
220            $where = 'template_id = ?';
221            $mailTemplates = $objQuery->select('subject, header, footer', 'dtb_mailtemplate', $where, array($objFormParam->getValue('template_id')));
222            if (!is_null($mailTemplates)) {
223                foreach (array('subject','header','footer') as $key) {
224                    $objFormParam->setValue($key,$mailTemplates[$key]);
225                }
226            }
227            $objFormParam->setParam($mailTemplates[0]);
228        } else {
229            foreach (array('subject','header','footer') as $key) {
230                $objFormParam->setValue($key,'');
231            }
232        }
233        return $objFormParam;
234    }
235
236    /**
237     * デストラクタ.
238     *
239     * @return void
240     */
241    function destroy() {
242        parent::destroy();
243    }
244
245    /**
246     * パラメーター情報の初期化
247     * @param SC_FormParam $objFormParam
248     */
249    function lfInitParam(&$objFormParam) {
250        // 検索条件のパラメーターを初期化
251        parent::lfInitParam($objFormParam);
252        $objFormParam->addParam('テンプレート', 'template_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
253        $objFormParam->addParam('メールタイトル', 'subject', STEXT_LEN, 'KVa',  array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
254        $objFormParam->addParam('ヘッダー', 'header', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
255        $objFormParam->addParam('フッター', 'footer', LTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK', 'SPTAB_CHECK'));
256    }
257}
Note: See TracBrowser for help on using the repository browser.