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