source: branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_DeliveryInput.php @ 21750

Revision 21750, 12.2 KB checked in by shutta, 12 years ago (diff)

#1579 SC_Query::getSingletonInstance()への置き換え

  • 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-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
25require_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 */
34class LC_Page_Admin_Basis_DeliveryInput extends LC_Page_Admin_Ex {
35    // }}}
36    // {{{ functions
37
38    /**
39     * Page を初期化する.
40     *
41     * @return void
42     */
43    function init() {
44        parent::init();
45        $this->tpl_mainpage = 'basis/delivery_input.tpl';
46        $this->tpl_subno = 'delivery';
47        $this->tpl_mainno = 'basis';
48        $masterData = new SC_DB_MasterData_Ex();
49        $this->arrPref = $masterData->getMasterData('mtb_pref');
50        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
51        $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method');
52        $this->tpl_maintitle = '基本情報管理';
53        $this->tpl_subtitle = '配送方法設定';
54        $this->mode = $this->getMode();
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->lfInitParam($this->mode, $objFormParam);
75        $objFormParam->setParam($_POST);
76
77        // 入力値の変換
78        $objFormParam->convParam();
79        $this->arrErr = $this->lfCheckError($objFormParam);
80
81        switch ($this->mode) {
82            case 'edit':
83                if (count($this->arrErr) == 0) {
84                    $objFormParam->setValue('deliv_id', $this->lfRegistData($objFormParam->getHashArray(), $_SESSION['member_id']));
85                    $this->tpl_onload = "window.alert('配送方法設定が完了しました。');";
86                }
87                break;
88            case 'pre_edit':
89                if (count($this->arrErr) > 0) {
90                    trigger_error('', E_USER_ERROR);
91                }
92                $this->lfGetDelivData($objFormParam);
93                break;
94            default:
95                break;
96        }
97
98        $this->arrForm = $objFormParam->getFormParamList();
99
100    }
101
102    /**
103     * デストラクタ.
104     *
105     * @return void
106     */
107    function destroy() {
108        parent::destroy();
109    }
110
111    /* パラメーター情報の初期化 */
112    function lfInitParam($mode, &$objFormParam) {
113        $objFormParam = new SC_FormParam_Ex();
114
115        switch ($mode) {
116            case 'edit':
117                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
118                $objFormParam->addParam('配送業者名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
119                $objFormParam->addParam('名称', 'service_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
120                $objFormParam->addParam('説明', 'remark', LLTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
121                $objFormParam->addParam('伝票No.確認URL', 'confirm_url', URL_LEN, 'n', array('URL_CHECK', 'MAX_LENGTH_CHECK'), 'http://');
122                $objFormParam->addParam('取扱商品種別', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
123                $objFormParam->addParam('取扱支払方法', 'payment_ids', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
124
125                for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
126                    $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
127                }
128
129                if (INPUT_DELIV_FEE) {
130                    for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
131                        $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
132                    }
133                }
134                break;
135
136            case 'pre_edit':
137                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
138                break;
139
140            default:
141                break;
142        }
143    }
144
145    /**
146     * 配送情報を登録する
147     *
148     * @return $deliv_id
149     */
150    function lfRegistData($arrRet, $member_id) {
151        $objQuery =& SC_Query_Ex::getSingletonInstance();
152        $objQuery->begin();
153
154        // 入力データを渡す。
155        $sqlval['name'] = $arrRet['name'];
156        $sqlval['service_name'] = $arrRet['service_name'];
157        $sqlval['remark'] = $arrRet['remark'];
158        $sqlval['confirm_url'] = $arrRet['confirm_url'];
159        $sqlval['product_type_id'] = $arrRet['product_type_id'];
160        $sqlval['creator_id'] = $member_id;
161        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
162
163        // deliv_id が決まっていた場合
164        if ($arrRet['deliv_id'] != '') {
165            $deliv_id = $arrRet['deliv_id'];
166            $where = 'deliv_id = ?';
167            $objQuery->update('dtb_deliv', $sqlval, $where, array($deliv_id));
168
169            // お届け時間の登録
170            $table = 'dtb_delivtime';
171            $where = 'deliv_id = ? AND time_id = ?';
172            for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
173                $sqlval = array();
174                $keyname = 'deliv_time'.$cnt;
175                $arrWhereVal = array($deliv_id, $cnt);
176                // 既存データの有無を確認
177                $curData = $objQuery->select('*', $table, $where, $arrWhereVal);
178
179                if (strcmp($arrRet[$keyname], '') != 0) {
180                    $sqlval['deliv_time'] = $arrRet[$keyname];
181
182                    // 入力が空ではなく、DBに情報があれば更新
183                    if (count($curData)) {
184                        $objQuery->update($table, $sqlval, $where, $arrWhereVal);
185                    }
186                    // DBに情報がなければ登録
187                    else {
188                        $sqlval['deliv_id'] = $deliv_id;
189                        $sqlval['time_id'] = $cnt;
190                        $objQuery->insert($table, $sqlval);
191                    }
192                }
193                // 入力が空で、DBに情報がある場合は削除
194                else if (count($curData)) {
195                    $objQuery->delete($table, $where, $arrWhereVal);
196                }
197            }
198
199            // 配送料の登録
200            if (INPUT_DELIV_FEE) {
201                for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
202                    $keyname = 'fee'.$cnt;
203                    if (strcmp($arrRet[$keyname], '') != 0) {
204                        $sqlval = array('fee' => $arrRet[$keyname]);
205                        $objQuery->update('dtb_delivfee', $sqlval, 'deliv_id = ? AND fee_id = ?', array($deliv_id, $cnt));
206                    }
207                }
208            }
209        } else {
210            // 登録する配送業者IDの取得
211            $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
212            $sqlval['deliv_id'] = $deliv_id;
213            $sqlval['rank'] = $objQuery->max('rank', 'dtb_deliv') + 1;
214            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
215            // INSERTの実行
216            $objQuery->insert('dtb_deliv', $sqlval);
217
218            $sqlval = array();
219            // お届け時間の設定
220            for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
221                $keyname = "deliv_time$cnt";
222                if ($arrRet[$keyname] != '') {
223                    $sqlval['deliv_id'] = $deliv_id;
224                    $sqlval['time_id'] = $cnt;
225                    $sqlval['deliv_time'] = $arrRet[$keyname];
226                    // INSERTの実行
227                    $objQuery->insert('dtb_delivtime', $sqlval);
228                }
229            }
230
231            if (INPUT_DELIV_FEE) {
232                $sqlval = array();
233                // 配送料金の設定
234                for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
235                    $keyname = "fee$cnt";
236                    if ($arrRet[$keyname] != '') {
237                        $sqlval['deliv_id'] = $deliv_id;
238                        $sqlval['fee'] = $arrRet[$keyname];
239                        $sqlval['pref'] = $cnt;
240                        // INSERTの実行
241                        $sqlval['fee_id'] = $cnt;
242                        $objQuery->insert('dtb_delivfee', $sqlval);
243                    }
244                }
245            }
246        }
247
248        $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($arrRet['deliv_id']));
249        $sqlval = array();
250        $i = 1;
251        foreach ($arrRet['payment_ids'] as $val) {
252            $sqlval['deliv_id'] = $deliv_id;
253            $sqlval['payment_id'] = $val;
254            $sqlval['rank'] = $i;
255            $objQuery->insert('dtb_payment_options', $sqlval);
256            $i++;
257        }
258        $objQuery->commit();
259        return $deliv_id;
260    }
261
262    /* 配送業者情報の取得 */
263    function lfGetDelivData(&$objFormParam) {
264        $objQuery =& SC_Query_Ex::getSingletonInstance();
265
266        $deliv_id = $objFormParam->getValue('deliv_id');
267
268        // パラメーター情報の初期化
269        $this->lfInitParam('edit', $objFormParam);
270
271        // 配送業者一覧の取得
272        $col = 'deliv_id, name, service_name, remark, confirm_url, product_type_id';
273        $where = 'deliv_id = ?';
274        $table = 'dtb_deliv';
275        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
276        $objFormParam->setParam($arrRet[0]);
277        // お届け時間の取得
278        $col = 'deliv_time';
279        $where = 'deliv_id = ?  ORDER BY time_id';
280        $table = 'dtb_delivtime';
281        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
282        $objFormParam->setParamList($arrRet, 'deliv_time');
283        // 配送料金の取得
284        $col = 'fee';
285        $where = 'deliv_id = ? ORDER BY pref';
286        $table = 'dtb_delivfee';
287        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
288        $objFormParam->setParamList($arrRet, 'fee');
289        // 支払方法
290        $col = 'payment_id';
291        $where = 'deliv_id = ? ORDER BY rank';
292        $table = 'dtb_payment_options';
293        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
294        $arrPaymentIds = array();
295        foreach ($arrRet as $val) {
296            $arrPaymentIds[] = $val['payment_id'];
297        }
298        $objFormParam->setValue('payment_ids', $arrPaymentIds);
299    }
300
301    /* 入力内容のチェック */
302    function lfCheckError(&$objFormParam) {
303        // 入力データを渡す。
304        $arrRet =  $objFormParam->getHashArray();
305        $objErr = new SC_CheckError_Ex($arrRet);
306        $objErr->arrErr = $objFormParam->checkError();
307
308        if (!isset($objErr->arrErr['name'])) {
309            // 既存チェック
310            $objDb = new SC_Helper_DB_Ex();
311            if ($arrRet['deliv_id'] == '') {
312                $ret = $objDb->sfIsRecord('dtb_deliv', 'service_name', array($arrRet['service_name']));
313            } else {
314                $objQuery =& SC_Query_Ex::getSingletonInstance();
315                $ret = (($objQuery->count('dtb_deliv', 'deliv_id != ? AND service_name = ? ', array($arrRet['deliv_id'], $arrRet['service_name'])) > 0)? true : false);
316            }
317            if ($ret) {
318                $objErr->arrErr['service_name'] = '※ 同じ名称の組み合わせは登録できません。<br>';
319            }
320        }
321
322        return $objErr->arrErr;
323    }
324}
Note: See TracBrowser for help on using the repository browser.