source: branches/version-2_13-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_PaymentInput.php @ 23606

Revision 23606, 11.1 KB checked in by kimoto, 10 years ago (diff)

#2448 typo修正・ソース整形・ソースコメントの改善 for 2.13.3

 https://scrutinizer-ci.com/g/nobuhiko/EC-CUBE/inspections/e0f27994-b3c7-4fc6-ad70-55d3cd63769b/patches

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2014 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * 支払方法設定 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Basis_PaymentInput extends LC_Page_Admin_Ex
34{
35    /** SC_UploadFile インスタンス */
36    public $objUpFile;
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    public function init()
44    {
45        parent::init();
46        $this->tpl_mainpage = 'basis/payment_input.tpl';
47        $this->tpl_mainno = 'basis';
48        $this->tpl_subno = 'payment';
49        $this->tpl_maintitle = '基本情報管理';
50        $this->tpl_subtitle = '支払方法設定';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    public function process()
59    {
60        $this->action();
61        $this->sendResponse();
62    }
63
64    /**
65     * Page のアクション.
66     *
67     * @return void
68     */
69    public function action()
70    {
71        $objPayment = new SC_Helper_Payment_Ex();
72        $objFormParam = new SC_FormParam_Ex();
73        $mode = $this->getMode();
74        $this->lfInitParam($mode, $objFormParam);
75
76        // ファイル管理クラス
77        $this->objUpFile = new SC_UploadFile_Ex(IMAGE_TEMP_REALDIR, IMAGE_SAVE_REALDIR);
78        // ファイル情報の初期化
79        $this->objUpFile = $this->lfInitFile();
80        // Hiddenからのデータを引き継ぐ
81        $this->objUpFile->setHiddenFileList($_POST);
82
83        switch ($mode) {
84            case 'edit':
85                $objFormParam->setParam($_REQUEST);
86                $objFormParam->convParam();
87                $post = $objFormParam->getHashArray();
88                $this->arrErr = $this->lfCheckError($post, $objFormParam, $objPayment);
89                $this->charge_flg = $post['charge_flg'];
90                if (count($this->arrErr) == 0) {
91                    $this->lfRegistData($objFormParam, $objPayment, $_SESSION['member_id'], $post['payment_id']);
92                    $this->objUpFile->moveTempFile();
93                    $this->tpl_onload = "location.href = './payment.php'; return;";
94                }
95                $this->tpl_payment_id = $post['payment_id'];
96                break;
97            // 画像のアップロード
98            case 'upload_image':
99                $objFormParam->setParam($_REQUEST);
100                $objFormParam->convParam();
101                $post = $objFormParam->getHashArray();
102                // ファイル存在チェック
103                $this->arrErr = $this->objUpFile->checkExists($post['image_key']);
104                // 画像保存処理
105                $this->arrErr[$post['image_key']] = $this->objUpFile->makeTempFile($post['image_key']);
106                $this->tpl_payment_id = $post['payment_id'];
107                break;
108            // 画像の削除
109            case 'delete_image':
110                $objFormParam->setParam($_REQUEST);
111                $objFormParam->convParam();
112                $this->arrErr = $objFormParam->checkError();
113                $post = $objFormParam->getHashArray();
114                if (count($this->arrErr) == 0) {
115                    $this->objUpFile->deleteFile($post['image_key']);
116                }
117                $this->tpl_payment_id = $post['payment_id'];
118                break;
119
120            case 'pre_edit':
121                $objFormParam->setParam($_REQUEST);
122                $objFormParam->convParam();
123                $this->arrErr = $objFormParam->checkError();
124                $post = $objFormParam->getHashArray();
125                if (count($this->arrErr) == 0) {
126                    $arrRet = $objPayment->get($post['payment_id']);
127
128                    $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
129                    $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
130                    $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
131                    $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
132                    $objFormParam->addParam('固定', 'fix');
133                    $objFormParam->setParam($arrRet);
134
135                    $this->charge_flg = $arrRet['charge_flg'];
136                    $this->objUpFile->setDBFileList($arrRet);
137                }
138                $this->tpl_payment_id = $post['payment_id'];
139                break;
140            default:
141                break;
142        }
143
144        $this->arrForm = $objFormParam->getFormParamList();
145
146        // FORM表示用配列を渡す。
147        $this->arrFile = $this->objUpFile->getFormFileList(IMAGE_TEMP_URLPATH, IMAGE_SAVE_URLPATH);
148        // HIDDEN用に配列を渡す。
149        $this->arrHidden = array_merge((array) $this->arrHidden, (array) $this->objUpFile->getHiddenFileList());
150    }
151
152    /* ファイル情報の初期化 */
153    public function lfInitFile()
154    {
155        $this->objUpFile->addFile('ロゴ画像', 'payment_image', array('gif','jpeg','jpg','png'), IMAGE_SIZE, false, CLASS_IMAGE_WIDTH, CLASS_IMAGE_HEIGHT);
156
157        return $this->objUpFile;
158    }
159
160    /* パラメーター情報の初期化 */
161
162    /**
163     * @param string|null $mode
164     * @param SC_FormParam_Ex $objFormParam
165     */
166    public function lfInitParam($mode, &$objFormParam)
167    {
168        switch ($mode) {
169            case 'edit':
170                $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
171                $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
172                $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
173                $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
174                $objFormParam->addParam('固定', 'fix');
175                $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
176                $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
177
178                break;
179            case 'upload_image':
180            case 'delete_image':
181                $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
182                $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
183                $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
184                $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
185                $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
186                $objFormParam->addParam('固定', 'fix');
187                $objFormParam->addParam('画像キー', 'image_key', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
188
189                break;
190            case 'pre_edit':
191                $objFormParam->addParam('支払いID', 'payment_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
192                $objFormParam->addParam('課金フラグ', 'charge_flg', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
193                break;
194
195            default:
196                $objFormParam->addParam('支払方法', 'payment_method', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
197                $objFormParam->addParam('手数料', 'charge', PRICE_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
198                $objFormParam->addParam('利用条件(~円以上)', 'rule_max', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
199                $objFormParam->addParam('利用条件(~円以下)', 'upper_rule', PRICE_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
200                $objFormParam->addParam('固定', 'fix');
201
202                break;
203        }
204    }
205
206    /* DBへデータを登録する */
207
208    /**
209     * @param SC_FormParam_Ex $objFormParam
210     */
211    public function lfRegistData(&$objFormParam, SC_Helper_Payment_Ex $objPayment, $member_id, $payment_id = '')
212    {
213        $sqlval = array_merge($objFormParam->getHashArray(), $this->objUpFile->getDBFileList());
214        $sqlval['payment_id'] = $payment_id;
215        $sqlval['creator_id'] = $member_id;
216
217        if ($sqlval['fix'] != '1') {
218            $sqlval['fix'] = 2; // 自由設定
219        }
220
221        $objPayment->save($sqlval);
222    }
223
224    /* 利用条件の数値チェック */
225
226    /* 入力内容のチェック */
227
228    /**
229     * @param SC_FormParam_Ex $objFormParam
230     */
231    public 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}
Note: See TracBrowser for help on using the repository browser.