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

Revision 23124, 8.7 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

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