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

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