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

Revision 18820, 10.7 KB checked in by nanasess, 14 years ago (diff)

#781(規格のデータベースを木構造に)

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