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/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 | $objFormParam = new SC_FormParam_Ex(); |
---|
75 | $mode = $this->getMode(); |
---|
76 | $this->lfInitParam($mode, $objFormParam); |
---|
77 | |
---|
78 | // ファイル管理クラス |
---|
79 | $this->objUpFile = new SC_UploadFile(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR); |
---|
80 | // ファイル情報の初期化 |
---|
81 | $this->objUpFile = $this->lfInitFile(); |
---|
82 | // Hiddenからのデータを引き継ぐ |
---|
83 | $this->objUpFile->setHiddenFileList($_POST); |
---|
84 | |
---|
85 | switch($mode) { |
---|
86 | case 'edit': |
---|
87 | $objFormParam->setParam($_REQUEST); |
---|
88 | $objFormParam->convParam(); |
---|
89 | $this->arrErr = $objFormParam->checkError(); |
---|
90 | $post = $objFormParam->getHashArray(); |
---|
91 | $this->charge_flg = $post["charge_flg"]; |
---|
92 | if(count($this->arrErr) == 0) { |
---|
93 | $this->lfRegistData($post['payment_id'], $_SESSION['member_id'], $objFormParam); |
---|
94 | $this->objUpFile->moveTempFile(); |
---|
95 | $this->tpl_onload = "location.href = './payment.php'; return;"; |
---|
96 | } |
---|
97 | $this->tpl_payment_id = $post['payment_id']; |
---|
98 | break; |
---|
99 | // 画像のアップロード |
---|
100 | case 'upload_image': |
---|
101 | $objFormParam->setParam($_REQUEST); |
---|
102 | $objFormParam->convParam(); |
---|
103 | $post = $objFormParam->getHashArray(); |
---|
104 | // ファイル存在チェック |
---|
105 | $this->arrErr = $this->objUpFile->checkEXISTS($post['image_key']); |
---|
106 | // 画像保存処理 |
---|
107 | $this->arrErr[$post['image_key']] = $this->objUpFile->makeTempFile($post['image_key']); |
---|
108 | $this->tpl_payment_id = $post['payment_id']; |
---|
109 | break; |
---|
110 | // 画像の削除 |
---|
111 | case 'delete_image': |
---|
112 | $objFormParam->setParam($_REQUEST); |
---|
113 | $objFormParam->convParam(); |
---|
114 | $this->arrErr = $objFormParam->checkError(); |
---|
115 | $post = $objFormParam->getHashArray(); |
---|
116 | if(count($this->arrErr) == 0) { |
---|
117 | $this->objUpFile->deleteFile($post['image_key']); |
---|
118 | } |
---|
119 | $this->tpl_payment_id = $post['payment_id']; |
---|
120 | break; |
---|
121 | |
---|
122 | case 'pre_edit': |
---|
123 | $objFormParam->setParam($_REQUEST); |
---|
124 | $objFormParam->convParam(); |
---|
125 | $this->arrErr = $objFormParam->checkError(); |
---|
126 | $post = $objFormParam->getHashArray(); |
---|
127 | if(count($this->arrErr) == 0) { |
---|
128 | $arrRet = $this->lfGetData($post['payment_id']); |
---|
129 | |
---|
130 | $objFormParam->addParam("支払方法", "payment_method", STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
131 | $objFormParam->addParam("手数料", 'charge', PRICE_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
132 | $objFormParam->addParam("利用条件(~円以上)", 'rule', PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
133 | $objFormParam->addParam("利用条件(~円以下)", "upper_rule", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
134 | $objFormParam->addParam("固定", 'fix'); |
---|
135 | $objFormParam->setParam($arrRet); |
---|
136 | |
---|
137 | $this->charge_flg = $arrRet["charge_flg"]; |
---|
138 | $this->objUpFile->setDBFileList($arrRet); |
---|
139 | } |
---|
140 | $this->tpl_payment_id = $post['payment_id']; |
---|
141 | break; |
---|
142 | default: |
---|
143 | break; |
---|
144 | } |
---|
145 | |
---|
146 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
147 | |
---|
148 | // FORM表示用配列を渡す。 |
---|
149 | $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH); |
---|
150 | // HIDDEN用に配列を渡す。 |
---|
151 | $this->arrHidden = array_merge((array)$this->arrHidden, (array)$this->objUpFile->getHiddenFileList()); |
---|
152 | } |
---|
153 | |
---|
154 | /** |
---|
155 | * デストラクタ. |
---|
156 | * |
---|
157 | * @return void |
---|
158 | */ |
---|
159 | function destroy() { |
---|
160 | parent::destroy(); |
---|
161 | } |
---|
162 | |
---|
163 | /* ファイル情報の初期化 */ |
---|
164 | function lfInitFile() { |
---|
165 | $this->objUpFile->addFile("ロゴ画像", 'payment_image', array('gif'), IMAGE_SIZE, false, CLASS_IMAGE_WIDTH, CLASS_IMAGE_HEIGHT); |
---|
166 | return $this->objUpFile; |
---|
167 | } |
---|
168 | |
---|
169 | /* パラメータ情報の初期化 */ |
---|
170 | function lfInitParam($mode, &$objFormParam) { |
---|
171 | |
---|
172 | switch ($mode) { |
---|
173 | case 'edit': |
---|
174 | $objFormParam->addParam("支払方法", "payment_method", STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
175 | $objFormParam->addParam("手数料", 'charge', PRICE_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
176 | $objFormParam->addParam("利用条件(~円以上)", 'rule', PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
177 | $objFormParam->addParam("利用条件(~円以下)", "upper_rule", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
178 | $objFormParam->addParam("固定", 'fix'); |
---|
179 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
180 | $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
181 | |
---|
182 | break; |
---|
183 | case "upload_image": |
---|
184 | case "delete_image": |
---|
185 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
186 | $objFormParam->addParam("支払方法", "payment_method", STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
187 | $objFormParam->addParam("手数料", 'charge', PRICE_LEN, 'n', array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
188 | $objFormParam->addParam("利用条件(~円以上)", 'rule', PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
189 | $objFormParam->addParam("利用条件(~円以下)", "upper_rule", PRICE_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
190 | $objFormParam->addParam("固定", 'fix'); |
---|
191 | $objFormParam->addParam("画像キー", "image_key", STEXT_LEN, 'KVa', array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
192 | |
---|
193 | break; |
---|
194 | case "pre_edit": |
---|
195 | $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
196 | $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
197 | break; |
---|
198 | |
---|
199 | default: |
---|
200 | $objFormParam->addParam("支払方法", "payment_method", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK")); |
---|
201 | $objFormParam->addParam("手数料", "charge", PRICE_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
202 | $objFormParam->addParam("利用条件(~円以上)", "rule", PRICE_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
203 | $objFormParam->addParam("利用条件(~円以下)", "upper_rule", PRICE_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
204 | $objFormParam->addParam("固定", "fix"); |
---|
205 | |
---|
206 | break; |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | /* DBからデータを読み込む */ |
---|
211 | function lfGetData($payment_id) { |
---|
212 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
213 | $where = "payment_id = ?"; |
---|
214 | $arrRet = $objQuery->select("*", "dtb_payment", $where, array($payment_id)); |
---|
215 | return $arrRet[0]; |
---|
216 | } |
---|
217 | |
---|
218 | /* DBへデータを登録する */ |
---|
219 | function lfRegistData($payment_id = "", $member_id, &$objFormParam) { |
---|
220 | |
---|
221 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
222 | $sqlval = $objFormParam->getHashArray(); |
---|
223 | $arrRet = $this->objUpFile->getDBFileList(); // ファイル名の取得 |
---|
224 | $sqlval = array_merge($sqlval, $arrRet); |
---|
225 | $sqlval['update_date'] = 'Now()'; |
---|
226 | |
---|
227 | if($sqlval['fix'] != '1') { |
---|
228 | $sqlval['fix'] = 2; // 自由設定 |
---|
229 | } |
---|
230 | |
---|
231 | // 新規登録 |
---|
232 | if($payment_id == "") { |
---|
233 | // INSERTの実行 |
---|
234 | $sqlval['creator_id'] = $member_id; |
---|
235 | $sqlval['rank'] = $objQuery->max('rank', "dtb_payment") + 1; |
---|
236 | $sqlval['create_date'] = 'Now()'; |
---|
237 | $sqlval['payment_id'] = $objQuery->nextVal('dtb_payment_payment_id'); |
---|
238 | $objQuery->insert("dtb_payment", $sqlval); |
---|
239 | // 既存編集 |
---|
240 | } else { |
---|
241 | $where = "payment_id = ?"; |
---|
242 | $objQuery->update("dtb_payment", $sqlval, $where, array($payment_id)); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | /* 利用条件の数値チェック */ |
---|
247 | |
---|
248 | /* 入力内容のチェック */ |
---|
249 | function lfCheckError($post) { |
---|
250 | |
---|
251 | // DBのデータを取得 |
---|
252 | $arrPaymentData = $this->lfGetData($post['payment_id']); |
---|
253 | |
---|
254 | // 手数料を設定できない場合には、手数料を0にする |
---|
255 | if($arrPaymentData["charge_flg"] == 2) $this->objFormParam->setValue('charge', "0"); |
---|
256 | |
---|
257 | // 入力データを渡す。 |
---|
258 | $arrRet = $this->objFormParam->getHashArray(); |
---|
259 | $objErr = new SC_CheckError_Ex($arrRet); |
---|
260 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
261 | |
---|
262 | // 利用条件(下限)チェック |
---|
263 | if($arrRet['rule'] < $arrPaymentData["rule_min"] and $arrPaymentData["rule_min"] != ""){ |
---|
264 | $objErr->arrErr['rule'] = "利用条件(下限)は" . $arrPaymentData["rule_min"] ."円以上にしてください。<br>"; |
---|
265 | } |
---|
266 | |
---|
267 | // 利用条件(上限)チェック |
---|
268 | if($arrRet["upper_rule"] > $arrPaymentData["upper_rule_max"] and $arrPaymentData["upper_rule_max"] != ""){ |
---|
269 | $objErr->arrErr["upper_rule"] = "利用条件(上限)は" . $arrPaymentData["upper_rule_max"] ."円以下にしてください。<br>"; |
---|
270 | } |
---|
271 | |
---|
272 | // 利用条件チェック |
---|
273 | $objErr->doFunc(array("利用条件(~円以上)", "利用条件(~円以下)", 'rule', "upper_rule"), array("GREATER_CHECK")); |
---|
274 | |
---|
275 | return $objErr->arrErr; |
---|
276 | } |
---|
277 | } |
---|
278 | ?> |
---|