1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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/LC_Page_Admin_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_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_subnavi = 'order/subnavi.tpl'; |
---|
48 | $this->tpl_mainno = 'order'; |
---|
49 | $this->tpl_subno = 'index'; |
---|
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 | $this->arrSearchHidden = SC_Utils_Ex::sfFilterKey($_POST,"^search_"); |
---|
75 | // パラメータ管理クラス |
---|
76 | $objFormParam = new SC_FormParam_Ex(); |
---|
77 | // パラメータ情報の初期化 |
---|
78 | $this->lfInitParam($objFormParam); |
---|
79 | // POST値の取得 |
---|
80 | $objFormParam->setParam($_POST); |
---|
81 | $objFormParam->convParam(); |
---|
82 | $this->tpl_order_id = $objFormParam->getValue('order_id'); |
---|
83 | |
---|
84 | switch($this->getMode()) { |
---|
85 | case 'pre_edit': |
---|
86 | break; |
---|
87 | case 'return': |
---|
88 | break; |
---|
89 | case 'send': |
---|
90 | $sendStatus = $this->doSend($objFormParam); |
---|
91 | if($sendStatus === true){ |
---|
92 | SC_Response_Ex::sendRedirect(ADMIN_ORDER_URLPATH); |
---|
93 | exit; |
---|
94 | }else{ |
---|
95 | $this->arrErr = $sendStatus; |
---|
96 | } |
---|
97 | case 'confirm': |
---|
98 | $status = $this->confirm($objFormParam); |
---|
99 | if($status === true){ |
---|
100 | $this->arrHidden = $objFormParam->getHashArray(); |
---|
101 | return ; |
---|
102 | }else{ |
---|
103 | $this->arrErr = $status; |
---|
104 | } |
---|
105 | break; |
---|
106 | case 'change': |
---|
107 | $objFormParam = $this->changeData($objFormParam); |
---|
108 | break; |
---|
109 | } |
---|
110 | |
---|
111 | if(SC_Utils_Ex::sfIsInt($objFormParam->getValue('order_id'))) { |
---|
112 | $this->arrMailHistory = $this->getMailHistory($objFormParam->getValue('order_id')); |
---|
113 | } |
---|
114 | |
---|
115 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
116 | } |
---|
117 | |
---|
118 | /** |
---|
119 | * 指定された注文番号のメール履歴を取得する。 |
---|
120 | * @var int order_id |
---|
121 | */ |
---|
122 | function getMailHistory($order_id){ |
---|
123 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
124 | $col = "send_date, subject, template_id, send_id"; |
---|
125 | $where = "order_id = ?"; |
---|
126 | $objQuery->setOrder("send_date DESC"); |
---|
127 | return $objQuery->select($col, "dtb_mail_history", $where, array($order_id)); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * |
---|
132 | * メールを送る。 |
---|
133 | * @param SC_FormParam $objFormParam |
---|
134 | */ |
---|
135 | function doSend(&$objFormParam){ |
---|
136 | $arrErr = $objFormParam->checkerror(); |
---|
137 | |
---|
138 | // メールの送信 |
---|
139 | if (count($arrErr) == 0) { |
---|
140 | // 注文受付メール |
---|
141 | $objMail = new SC_Helper_Mail_Ex(); |
---|
142 | $objSendMail = $objMail->sfSendOrderMail($objFormParam->getValue('order_id'), |
---|
143 | $objFormParam->getValue('template_id'), |
---|
144 | $objFormParam->getValue('subject'), |
---|
145 | $objFormParam->getValue('header'), |
---|
146 | $objFormParam->getValue('footer')); |
---|
147 | // TODO $SC_SendMail から送信がちゃんと出来たか確認できたら素敵。 |
---|
148 | return true; |
---|
149 | } |
---|
150 | return $arrErr; |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * 確認画面を表示する為の準備 |
---|
155 | * @param SC_FormParam $objFormParam |
---|
156 | */ |
---|
157 | function confirm(&$objFormParam){ |
---|
158 | $arrErr = $objFormParam->checkerror(); |
---|
159 | // メールの送信 |
---|
160 | if (count($arrErr) == 0) { |
---|
161 | // 注文受付メール(送信なし) |
---|
162 | $objMail = new SC_Helper_Mail_Ex(); |
---|
163 | $objSendMail = $objMail->sfSendOrderMail( |
---|
164 | $objFormParam->getValue('order_id'), |
---|
165 | $objFormParam->getValue('template_id'), |
---|
166 | $objFormParam->getValue('subject'), |
---|
167 | $objFormParam->getValue('header'), |
---|
168 | $objFormParam->getValue('footer'), false); |
---|
169 | |
---|
170 | $this->tpl_subject = $objFormParam->getValue('subject'); |
---|
171 | $this->tpl_body = mb_convert_encoding( $objSendMail->body, CHAR_CODE, 'auto' ); |
---|
172 | $this->tpl_to = $objSendMail->tpl_to; |
---|
173 | $this->tpl_mainpage = 'order/mail_confirm.tpl'; |
---|
174 | return true; |
---|
175 | } |
---|
176 | return $arrErr; |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * |
---|
181 | * テンプレートの文言をフォームに入れる。 |
---|
182 | * @param SC_FormParam $objFormParam |
---|
183 | */ |
---|
184 | function changeData(&$objFormParam){ |
---|
185 | if(SC_Utils_Ex::sfIsInt($objFormParam->getValue('template_id'))) { |
---|
186 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
187 | $where = "template_id = ?"; |
---|
188 | $mailTemplates = $objQuery->select("subject, header, footer", "dtb_mailtemplate", $where, array($objFormParam->getValue('template_id'))); |
---|
189 | if(!is_null($mailTemplates )){ |
---|
190 | foreach(array('subject','header','footer') as $key){ |
---|
191 | $objFormParam->setValue($key,$mailTemplates[$key]); |
---|
192 | } |
---|
193 | } |
---|
194 | $objFormParam->setParam($mailTemplates[0]); |
---|
195 | }else{ |
---|
196 | foreach(array('subject','header','footer') as $key){ |
---|
197 | $objFormParam->setValue($key,""); |
---|
198 | } |
---|
199 | } |
---|
200 | return $objFormParam; |
---|
201 | } |
---|
202 | |
---|
203 | /** |
---|
204 | * デストラクタ. |
---|
205 | * |
---|
206 | * @return void |
---|
207 | */ |
---|
208 | function destroy() { |
---|
209 | parent::destroy(); |
---|
210 | } |
---|
211 | |
---|
212 | /** |
---|
213 | * パラメータ情報の初期化 |
---|
214 | * @param SC_FormParam $objFormParam |
---|
215 | */ |
---|
216 | function lfInitParam(&$objFormParam) { |
---|
217 | $objFormParam->addParam("オーダーID", "order_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
218 | $objFormParam->addParam("テンプレート", "template_id", INT_LEN, 'n', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
219 | $objFormParam->addParam("メールタイトル", 'subject', STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
220 | $objFormParam->addParam("ヘッダー", 'header', LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
221 | $objFormParam->addParam("フッター", 'footer', LTEXT_LEN, 'KVa', array("MAX_LENGTH_CHECK", "SPTAB_CHECK")); |
---|
222 | } |
---|
223 | } |
---|
224 | ?> |
---|