source: branches/version-2_5-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_Delivery_Input.php @ 19732

Revision 19732, 11.0 KB checked in by Seasoft, 13 years ago (diff)

#855(SC_Query の #select, #getRow, #getCol, #get, #min, #max の引数順を統一する)

  • SC_Query#max を改訂
  • SC_Query#min を改訂
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-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
25require_once(CLASS_PATH . "pages/admin/LC_Page_Admin.php");
26
27/**
28 * 配送業者設定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Basis_Delivery_Input extends LC_Page_Admin {
35
36    // {{{ properties
37
38    /** フォームパラメータの配列 */
39    var $objFormParam;
40
41    // }}}
42    // {{{ functions
43
44    /**
45     * Page を初期化する.
46     *
47     * @return void
48     */
49    function init() {
50        parent::init();
51        $this->tpl_mainpage = 'basis/delivery_input.tpl';
52        $this->tpl_subnavi = 'basis/subnavi.tpl';
53        $this->tpl_subno = 'delivery';
54        $this->tpl_mainno = 'basis';
55        $masterData = new SC_DB_MasterData_Ex();
56        $this->arrPref = $masterData->getMasterData("mtb_pref", array("pref_id", "pref_name", "rank"));
57        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
58        $this->tpl_subtitle = '配送業者設定';
59        $this->mode = isset($_POST['mode']) ? $_POST['mode'] : '';
60    }
61
62    /**
63     * Page のプロセス.
64     *
65     * @return void
66     */
67    function process() {
68        $this->action();
69        $this->sendResponse();
70    }
71
72    /**
73     * Page のアクション.
74     *
75     * @return void
76     */
77    function action() {
78        $objSess = new SC_Session();
79
80        // 認証可否の判定
81        SC_Utils_Ex::sfIsSuccess($objSess);
82
83        // パラメータ管理クラス
84        $this->objFormParam = new SC_FormParam();
85        // パラメータ情報の初期化
86        $this->lfInitParam();
87        // POST値をパラメータとする
88        $this->objFormParam->setParam($_POST);
89        // 入力値の変換
90        $this->objFormParam->convParam();
91        $this->arrErr = $this->lfCheckError();
92
93        switch ($this->mode) {
94            case 'edit':
95                if (count($this->arrErr) == 0) {
96                    $this->objFormParam->setValue('deliv_id', $this->lfRegistData());
97                    $this->tpl_onload = "window.alert('配送業者設定が完了しました。');";
98                }
99                break;
100            case 'pre_edit':
101                if (count($this->arrErr) > 0) {
102                    SC_Utils_Ex::sfDispException();
103                }
104                $this->lfGetDelivData($this->objFormParam->getValue('deliv_id'));
105                break;
106            default:
107                break;
108        }
109
110        $this->arrForm = $this->objFormParam->getFormParamList();
111    }
112
113    /**
114     * デストラクタ.
115     *
116     * @return void
117     */
118    function destroy() {
119        parent::destroy();
120    }
121
122    /* パラメータ情報の初期化 */
123    function lfInitParam($mode = null) {
124
125        if (is_null($mode)) $mode = $this->mode;
126
127        $this->objFormParam->initParam();
128
129        switch ($mode) {
130            case 'edit':
131                $this->objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
132                $this->objFormParam->addParam("配送業者名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
133                $this->objFormParam->addParam("名称", "service_name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
134                $this->objFormParam->addParam("伝票No.確認URL", "confirm_url", STEXT_LEN, "n", array("URL_CHECK", "MAX_LENGTH_CHECK"), "http://");
135                $this->objFormParam->addParam("取扱商品種別", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
136
137                for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
138                    $this->objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
139                }
140
141                if(INPUT_DELIV_FEE) {
142                    for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
143                        $this->objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
144                    }
145                }
146                break;
147
148            case 'pre_edit':
149                $this->objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
150                break;
151
152            default:
153                break;
154        }
155    }
156
157    /**
158     * 配送情報を登録する
159     *
160     * @return $deliv_id
161     */
162    function lfRegistData() {
163        $arrRet = $this->objFormParam->getHashArray();
164        $objQuery = new SC_Query();
165        $objQuery->begin();
166
167        // 入力データを渡す。
168        $sqlval['name'] = $arrRet['name'];
169        $sqlval['service_name'] = $arrRet['service_name'];
170        $sqlval['confirm_url'] = $arrRet['confirm_url'];
171        $sqlval['product_type_id'] = $arrRet['product_type_id'];
172        $sqlval['creator_id'] = $_SESSION['member_id'];
173        $sqlval['update_date'] = 'Now()';
174
175
176        // deliv_id が決まっていた場合
177        if($_POST['deliv_id'] != "") {
178            $deliv_id = $_POST['deliv_id'];
179            $where = "deliv_id = ?";
180            $objQuery->update("dtb_deliv", $sqlval, $where, array($deliv_id));
181
182            // お届け時間の登録
183            $table = "dtb_delivtime";
184            $where = "deliv_id = ? AND time_id = ?";
185            for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
186                $sqlval = array();
187                $keyname = "deliv_time".$cnt;
188                $arrval = array($deliv_id, $cnt);
189                // 既存データの有無を確認
190                $curData = $objQuery->select("*", $table, $where, $arrval);
191
192                if(strcmp($arrRet[$keyname], "") != 0) {
193                    $sqlval['deliv_time'] = $arrRet[$keyname];
194
195                    // 入力が空ではなく、DBに情報があれば更新
196                    if(count($curData)) {
197                        $objQuery->update($table, $sqlval, $where, $arrval);
198                    }
199                    // DBに情報がなければ登録
200                    else {
201                        $sqlval['deliv_id'] = $deliv_id;
202                        $sqlval['time_id'] = $cnt;
203                        $objQuery->insert($table, $sqlval);
204                    }
205                }
206                // 入力が空で、DBに情報がある場合は削除
207                else if(count($curData)) {
208                    $objQuery->delete($table, $where, $arrval);
209                }
210            }
211
212            // 配送料の登録
213            if(INPUT_DELIV_FEE) {
214                for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
215                    $keyname = "fee".$cnt;
216                    if(strcmp($arrRet[$keyname], "") != 0) {
217                        $sqlval = array('fee' => $arrRet[$keyname]);
218                        $objQuery->update("dtb_delivfee", $sqlval, "deliv_id = ? AND fee_id = ?", array($deliv_id, $cnt));
219                    }
220                }
221            }
222        }
223        else {
224            // 登録する配送業者IDの取得
225            $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
226            $sqlval['deliv_id'] = $deliv_id;
227            $sqlval['rank'] = $objQuery->max("rank", "dtb_deliv") + 1;
228            $sqlval['create_date'] = 'Now()';
229            // INSERTの実行
230            $objQuery->insert("dtb_deliv", $sqlval);
231
232            $sqlval = array();
233            // お届け時間の設定
234            for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
235                $keyname = "deliv_time$cnt";
236                if($arrRet[$keyname] != "") {
237                    $sqlval['deliv_id'] = $deliv_id;
238                    $sqlval['time_id'] = $cnt;
239                    $sqlval['deliv_time'] = $arrRet[$keyname];
240                    // INSERTの実行
241                    $objQuery->insert("dtb_delivtime", $sqlval);
242                }
243            }
244
245            if(INPUT_DELIV_FEE) {
246                $sqlval = array();
247                // 配送料金の設定
248                for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
249                    $keyname = "fee$cnt";
250                    if($arrRet[$keyname] != "") {
251                        $sqlval['deliv_id'] = $deliv_id;
252                        $sqlval['fee'] = $arrRet[$keyname];
253                        $sqlval['pref'] = $cnt;
254                        // INSERTの実行
255                        $sqlval['fee_id'] = $cnt;
256                        $objQuery->insert("dtb_delivfee", $sqlval);
257                    }
258                }
259            }
260        }
261        $objQuery->commit();
262        return $deliv_id;
263    }
264
265    /* 配送業者情報の取得 */
266    function lfGetDelivData($deliv_id) {
267        $objQuery = new SC_Query();
268
269        // パラメータ情報の初期化
270        $this->lfInitParam('edit');
271
272        // 配送業者一覧の取得
273        $col = "deliv_id, name, service_name, confirm_url, product_type_id";
274        $where = "deliv_id = ?";
275        $table = "dtb_deliv";
276        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
277        $this->objFormParam->setParam($arrRet[0]);
278        // お届け時間の取得
279        $col = "deliv_time";
280        $where = "deliv_id = ?  ORDER BY time_id";
281        $table = "dtb_delivtime";
282        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
283        $this->objFormParam->setParamList($arrRet, 'deliv_time');
284        // 配送料金の取得
285        $col = "fee";
286        $where = "deliv_id = ? ORDER BY pref";
287        $table = "dtb_delivfee";
288        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
289        $this->objFormParam->setParamList($arrRet, 'fee');
290    }
291
292    /* 入力内容のチェック */
293    function lfCheckError() {
294        // 入力データを渡す。
295        $arrRet =  $this->objFormParam->getHashArray();
296        $objErr = new SC_CheckError($arrRet);
297        $objErr->arrErr = $this->objFormParam->checkError();
298
299        if(!isset($objErr->arrErr['name']) && $_POST['deliv_id'] == "") {
300            // 既存チェック
301            $objDb = new SC_Helper_DB_Ex();
302            $ret = $objDb->sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name']));
303            if ($ret) {
304                $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>";
305            }
306        }
307
308        return $objErr->arrErr;
309    }
310}
311?>
Note: See TracBrowser for help on using the repository browser.