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