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

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