source: branches/comu-ver2/data/class/pages/admin/basis/LC_Page_Admin_Basis_Delivery_Input.php @ 18701

Revision 18701, 10.9 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

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