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

Revision 20507, 11.8 KB checked in by shutta, 13 years ago (diff)

SC_Queryクラスのclass_extends対応

  • 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_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_Delivery_Input 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_subnavi = 'basis/subnavi.tpl';
47        $this->tpl_subno = 'delivery';
48        $this->tpl_mainno = 'basis';
49        $masterData = new SC_DB_MasterData_Ex();
50        $this->arrPref = $masterData->getMasterData('mtb_pref');
51        $this->arrProductType = $masterData->getMasterData("mtb_product_type");
52        $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
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        $objFormParam = new SC_FormParam_Ex();
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                    SC_Utils_Ex::sfDispException();
91                }
92                $this->lfGetDelivData($objFormParam);
93                break;
94            default:
95                break;
96        }
97
98        $this->arrForm = $objFormParam->getFormParamList();
99    }
100
101    /**
102     * デストラクタ.
103     *
104     * @return void
105     */
106    function destroy() {
107        parent::destroy();
108    }
109
110    /* パラメータ情報の初期化 */
111    function lfInitParam($mode, &$objFormParam) {
112        $objFormParam->initParam();
113
114        switch ($mode) {
115            case 'edit':
116                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
117                $objFormParam->addParam("配送業者名", "name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
118                $objFormParam->addParam("名称", "service_name", STEXT_LEN, "KVa", array("EXIST_CHECK", "MAX_LENGTH_CHECK"));
119                $objFormParam->addParam("説明", "remark", LLTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
120                $objFormParam->addParam("伝票No.確認URL", "confirm_url", STEXT_LEN, "n", array("URL_CHECK", "MAX_LENGTH_CHECK"), "http://");
121                $objFormParam->addParam("取扱商品種別", "product_type_id", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
122                $objFormParam->addParam("取扱支払方法", "payment_ids", INT_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "MAX_LENGTH_CHECK"));
123
124                for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
125                    $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
126                }
127
128                if(INPUT_DELIV_FEE) {
129                    for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
130                        $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
131                    }
132                }
133                break;
134
135            case 'pre_edit':
136                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
137                break;
138
139            default:
140                break;
141        }
142    }
143
144    /**
145     * 配送情報を登録する
146     *
147     * @return $deliv_id
148     */
149    function lfRegistData($arrRet, $member_id) {
150        $objQuery =& SC_Query_Ex::getSingletonInstance();
151        $objQuery->begin();
152
153        // 入力データを渡す。
154        $sqlval['name'] = $arrRet['name'];
155        $sqlval['service_name'] = $arrRet['service_name'];
156        $sqlval['remark'] = $arrRet['remark'];
157        $sqlval['confirm_url'] = $arrRet['confirm_url'];
158        $sqlval['product_type_id'] = $arrRet['product_type_id'];
159        $sqlval['creator_id'] = $member_id;
160        $sqlval['update_date'] = 'Now()';
161
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                $arrval = array($deliv_id, $cnt);
176                // 既存データの有無を確認
177                $curData = $objQuery->select("*", $table, $where, $arrval);
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, $arrval);
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, $arrval);
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        }
210        else {
211            // 登録する配送業者IDの取得
212            $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
213            $sqlval['deliv_id'] = $deliv_id;
214            $sqlval['rank'] = $objQuery->max("rank", "dtb_deliv") + 1;
215            $sqlval['create_date'] = 'Now()';
216            // INSERTの実行
217            $objQuery->insert("dtb_deliv", $sqlval);
218
219            $sqlval = array();
220            // お届け時間の設定
221            for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
222                $keyname = "deliv_time$cnt";
223                if($arrRet[$keyname] != "") {
224                    $sqlval['deliv_id'] = $deliv_id;
225                    $sqlval['time_id'] = $cnt;
226                    $sqlval['deliv_time'] = $arrRet[$keyname];
227                    // INSERTの実行
228                    $objQuery->insert("dtb_delivtime", $sqlval);
229                }
230            }
231
232            if(INPUT_DELIV_FEE) {
233                $sqlval = array();
234                // 配送料金の設定
235                for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
236                    $keyname = "fee$cnt";
237                    if($arrRet[$keyname] != "") {
238                        $sqlval['deliv_id'] = $deliv_id;
239                        $sqlval['fee'] = $arrRet[$keyname];
240                        $sqlval['pref'] = $cnt;
241                        // INSERTの実行
242                        $sqlval['fee_id'] = $cnt;
243                        $objQuery->insert("dtb_delivfee", $sqlval);
244                    }
245                }
246            }
247        }
248
249        $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($arrRet['deliv_id']));
250        $sqlval = array();
251        $i = 1;
252        foreach ($arrRet['payment_ids'] as $val) {
253            $sqlval['deliv_id'] = $deliv_id;
254            $sqlval['payment_id'] = $val;
255            $sqlval['rank'] = $i;
256            $objQuery->insert('dtb_payment_options', $sqlval);
257            $i++;
258        }
259        $objQuery->commit();
260        return $deliv_id;
261    }
262
263    /* 配送業者情報の取得 */
264    function lfGetDelivData(&$objFormParam) {
265        $objQuery =& SC_Query_Ex::getSingletonInstance();
266
267        $deliv_id = $objFormParam->getValue('deliv_id');
268
269        // パラメータ情報の初期化
270        $this->lfInitParam('edit', $objFormParam);
271
272        // 配送業者一覧の取得
273        $col = "deliv_id, name, service_name, remark, confirm_url, product_type_id";
274        $where = "deliv_id = ?";
275        $table = "dtb_deliv";
276        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
277        $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        $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        $objFormParam->setParamList($arrRet, 'fee');
290        // 支払方法
291        $col = 'payment_id';
292        $where = 'deliv_id = ? ORDER BY rank';
293        $table = 'dtb_payment_options';
294        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
295        $arrPaymentIds = array();
296        foreach ($arrRet as $val) {
297            $arrPaymentIds[] = $val['payment_id'];
298        }
299        $objFormParam->setValue('payment_ids', $arrPaymentIds);
300    }
301
302    /* 入力内容のチェック */
303    function lfCheckError(&$objFormParam) {
304        // 入力データを渡す。
305        $arrRet =  $objFormParam->getHashArray();
306        $objErr = new SC_CheckError_Ex($arrRet);
307        $objErr->arrErr = $objFormParam->checkError();
308
309        if(!isset($objErr->arrErr['name']) && $arrRet['deliv_id'] == "") {
310            // 既存チェック
311            $objDb = new SC_Helper_DB_Ex();
312            $ret = $objDb->sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name']));
313            if ($ret) {
314                $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>";
315            }
316        }
317
318        return $objErr->arrErr;
319    }
320}
321?>
Note: See TracBrowser for help on using the repository browser.