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