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/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_Basis_PaymentInput extends LC_Page_Admin_Ex { |
---|
35 | |
---|
36 | // {{{ properties |
---|
37 | |
---|
38 | /** SC_UploadFile インスタンス */ |
---|
39 | var $objUpFile; |
---|
40 | |
---|
41 | // }}} |
---|
42 | // {{{ functions |
---|
43 | |
---|
44 | /** |
---|
45 | * Page を初期化する. |
---|
46 | * |
---|
47 | * @return void |
---|
48 | */ |
---|
49 | function init() { |
---|
50 | parent::init(); |
---|
51 | $this->tpl_mainpage = 'basis/payment_input.tpl'; |
---|
52 | $this->tpl_mainno = 'basis'; |
---|
53 | $this->tpl_subno = 'payment'; |
---|
54 | $this->tpl_maintitle = '基本情報管理'; |
---|
55 | $this->tpl_subtitle = '支払方法設定'; |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * Page のプロセス. |
---|
60 | * |
---|
61 | * @return void |
---|
62 | */ |
---|
63 | function process() { |
---|
64 | $this->action(); |
---|
65 | $this->sendResponse(); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * Page のアクション. |
---|
70 | * |
---|
71 | * @return void |
---|
72 | */ |
---|
73 | function action() { |
---|
74 | |
---|
75 | $objPayment = new SC_Helper_Payment_Ex(); |
---|
76 | $objFormParam = new SC_FormParam_Ex(); |
---|
77 | $mode = $this->getMode(); |
---|
78 | $this->lfInitParam($mode, $objFormParam); |
---|
79 | |
---|
80 | // ファイル管理クラス |
---|
81 | $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
82 | // ファイル情報の初期化 |
---|
83 | $this->objUpFile = $this->lfInitFile(); |
---|
84 | // Hiddenからのデータを引き継ぐ |
---|
85 | $this->objUpFile->setHiddenFileList($_POST); |
---|
86 | |
---|
87 | switch ($mode) { |
---|
88 | case 'edit': |
---|
89 | $objFormParam->setParam($_REQUEST); |
---|
90 | $objFormParam->convParam(); |
---|
91 | $post = $objFormParam->getHashArray(); |
---|
92 | $this->arrErr = $this->lfCheckError($post, $objFormParam, $objPayment); |
---|
93 | $this->charge_flg = $post['charge_flg']; |
---|
94 | if (count($this->arrErr) == 0) { |
---|
95 | $this->lfRegistData($objFormParam, $objPayment, $_SESSION['member_id'], $post['payment_id']); |
---|
96 | $this->objUpFile->moveTempFile(); |
---|
97 | $this->tpl_onload = "location.href = './payment.php'; return;"; |
---|
98 | } |
---|
99 | $this->tpl_payment_id = $post['payment_id']; |
---|
100 | break; |
---|
101 | // 画像のアップロード |
---|
102 | case 'upload_image': |
---|
103 | $objFormParam->setParam($_REQUEST); |
---|
104 | $objFormParam->convParam(); |
---|
105 | $post = $objFormParam->getHashArray(); |
---|
106 | // ファイル存在チェック |
---|
107 | $this->arrErr = $this->objUpFile->checkExists($post['image_key']); |
---|
108 | // 画像保存処理 |
---|
109 | $this->arrErr[$post['image_key']] = $this->objUpFile->makeTempFile($post['image_key']); |
---|
110 | $this->tpl_payment_id = $post['payment_id']; |
---|
111 | break; |
---|
112 | // 画像の削除 |
---|
113 | case 'delete_image': |
---|
114 | $objFormParam->setParam($_REQUEST); |
---|
115 | $objFormParam->convParam(); |
---|
116 | $this->arrErr = $objFormParam->checkError(); |
---|
117 | $post = $objFormParam->getHashArray(); |
---|
118 | if (count($this->arrErr) == 0) { |
---|
119 | $this->objUpFile->deleteFile($post['image_key']); |
---|
120 | } |
---|
121 | $this->tpl_payment_id = $post['payment_id']; |
---|
122 | break; |
---|
123 | |
---|
124 | case 'pre_edit': |
---|
125 | $objFormParam->setParam($_REQUEST); |
---|
126 | $objFormParam->convParam(); |
---|
127 | $this->arrErr = $objFormParam->checkError(); |
---|
128 | $post = $objFormParam->getHashArray(); |
---|
129 | if (count($this->arrErr) == 0) { |
---|
130 | $arrRet = $objPayment->get($post['payment_id']); |
---|
131 | |
---|
132 | $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
133 | $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
134 | $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
135 | $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
136 | $objFormParam->addParam('固定', 'fix'); |
---|
137 | $objFormParam->setParam($arrRet); |
---|
138 | |
---|
139 | $this->charge_flg = $arrRet['charge_flg']; |
---|
140 | $this->objUpFile->setDBFileList($arrRet); |
---|
141 | } |
---|
142 | $this->tpl_payment_id = $post['payment_id']; |
---|
143 | break; |
---|
144 | default: |
---|
145 | break; |
---|
146 | } |
---|
147 | |
---|
148 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
149 | |
---|
150 | // FORM表示用配列を渡す。 |
---|
151 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
152 | // HIDDEN用に配列を渡す。 |
---|
153 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList()); |
---|
154 | |
---|
155 | } |
---|
156 | |
---|
157 | /** |
---|
158 | * デストラクタ. |
---|
159 | * |
---|
160 | * @return void |
---|
161 | */ |
---|
162 | function destroy() { |
---|
163 | parent::destroy(); |
---|
164 | } |
---|
165 | |
---|
166 | /* ファイル情報の初期化 */ |
---|
167 | function lfInitFile() { |
---|
168 | $this->objUpFile->addFile('ロゴ画像', 'payment_image', array('gif','jpeg','jpg','png'), IMAGE_SIZE, false, CLASS_IMAGE_WIDTH, CLASS_IMAGE_HEIGHT); |
---|
169 | return $this->objUpFile; |
---|
170 | } |
---|
171 | |
---|
172 | /* パラメーター情報の初期化 */ |
---|
173 | function lfInitParam($mode, &$objFormParam) { |
---|
174 | |
---|
175 | switch ($mode) { |
---|
176 | case 'edit': |
---|
177 | $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
178 | $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
179 | $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
180 | $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
181 | $objFormParam->addParam('固定', 'fix'); |
---|
182 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
183 | $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
184 | |
---|
185 | break; |
---|
186 | case 'upload_image': |
---|
187 | case 'delete_image': |
---|
188 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
189 | $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
190 | $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
191 | $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
192 | $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
193 | $objFormParam->addParam('固定', 'fix'); |
---|
194 | $objFormParam->addParam('画像キー', 'image_key', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
195 | |
---|
196 | break; |
---|
197 | case 'pre_edit': |
---|
198 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
199 | $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
200 | break; |
---|
201 | |
---|
202 | default: |
---|
203 | $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
204 | $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
205 | $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
206 | $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
207 | $objFormParam->addParam('固定', 'fix'); |
---|
208 | |
---|
209 | break; |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | /* DBへデータを登録する */ |
---|
214 | function lfRegistData(&$objFormParam, SC_Helper_Payment_Ex $objPayment, $member_id, $payment_id = '') { |
---|
215 | |
---|
216 | $sqlval = array_merge($objFormParam->getHashArray(), $this->objUpFile->getDBFileList()); |
---|
217 | $sqlval['update_date'] = 'CURRENT_TIMESTAMP'; |
---|
218 | $sqlval['payment_id'] = $payment_id; |
---|
219 | $sqlval['creator_id'] = $member_id; |
---|
220 | |
---|
221 | if ($sqlval['fix'] != '1') { |
---|
222 | $sqlval['fix'] = 2; // 自由設定 |
---|
223 | } |
---|
224 | |
---|
225 | $objPayment->save($sqlval); |
---|
226 | } |
---|
227 | |
---|
228 | /* 利用条件の数値チェック */ |
---|
229 | |
---|
230 | /* 入力内容のチェック */ |
---|
231 | function lfCheckError($post, $objFormParam, SC_Helper_Payment_Ex $objPayment) { |
---|
232 | |
---|
233 | // DBのデータを取得 |
---|
234 | $arrPaymentData = $objPayment->get($post['payment_id']); |
---|
235 | |
---|
236 | // 手数料を設定できない場合には、手数料を0にする |
---|
237 | if ($arrPaymentData['charge_flg'] == 2) { |
---|
238 | $objFormParam->setValue('charge', '0'); |
---|
239 | } |
---|
240 | |
---|
241 | // 入力データを渡す。 |
---|
242 | $arrRet = $objFormParam->getHashArray(); |
---|
243 | $objErr = new SC_CheckError_Ex($arrRet); |
---|
244 | $objErr->arrErr = $objFormParam->checkError(); |
---|
245 | |
---|
246 | // 利用条件(下限)チェック |
---|
247 | if ($arrRet['rule_max'] < $arrPaymentData['rule_min'] and $arrPaymentData['rule_min'] != '') { |
---|
248 | $objErr->arrErr['rule'] = '利用条件(下限)は' . $arrPaymentData['rule_min'] .'円以上にしてください。<br>'; |
---|
249 | } |
---|
250 | |
---|
251 | // 利用条件(上限)チェック |
---|
252 | if ($arrRet['upper_rule'] > $arrPaymentData['upper_rule_max'] and $arrPaymentData['upper_rule_max'] != '') { |
---|
253 | $objErr->arrErr['upper_rule'] = '利用条件(上限)は' . $arrPaymentData['upper_rule_max'] .'円以下にしてください。<br>'; |
---|
254 | } |
---|
255 | |
---|
256 | // 利用条件チェック |
---|
257 | $objErr->doFunc(array('利用条件(~円以上)', '利用条件(~円以下)', 'rule_max', 'upper_rule'), array('GREATER_CHECK')); |
---|
258 | |
---|
259 | return $objErr->arrErr; |
---|
260 | } |
---|
261 | } |
---|