source: branches/feature-module-update/data/class/pages/admin/basis/LC_Page_Admin_Basis_Delivery_Input.php @ 16582

Revision 16582, 8.2 KB checked in by nanasess, 17 years ago (diff)

ライセンス表記変更

  • 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    /* DBに登録する */
135    function lfRegistData() {
136        $arrRet = $this->objFormParam->getHashArray();
137        $objQuery = new SC_Query();
138        $objQuery->begin();
139
140        // 入力データを渡す。
141        $sqlval['name'] = $arrRet['name'];
142        $sqlval['service_name'] = $arrRet['service_name'];
143        $sqlval['confirm_url'] = $arrRet['confirm_url'];
144        $sqlval['creator_id'] = $_SESSION['member_id'];
145        $sqlval['update_date'] = 'Now()';
146
147        if($_POST['deliv_id'] != "") {
148            $deliv_id = $_POST['deliv_id'];
149            $where = "deliv_id = ?";
150            $objQuery->update("dtb_deliv", $sqlval, $where, array($deliv_id));
151            $objQuery->delete("dtb_delivfee", $where, array($deliv_id));
152            $objQuery->delete("dtb_delivtime", $where, array($deliv_id));
153        } else {
154            // 登録する配送業者IDの取得
155
156            if (DB_TYPE == "pgsql") {
157                $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id');
158                $sqlval['deliv_id'] = $deliv_id;
159            }
160
161            $sqlval['rank'] = $objQuery->max("dtb_deliv", "rank") + 1;
162            $sqlval['create_date'] = 'Now()';
163            // INSERTの実行
164            $objQuery->insert("dtb_deliv", $sqlval);
165
166            if (DB_TYPE == "mysql") {
167                $deliv_id = $objQuery->nextval('dtb_deliv', 'deliv_id');
168            }
169        }
170
171        $sqlval = array();
172        // 配送時間の設定
173        for($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
174            $keyname = "deliv_time$cnt";
175            if($arrRet[$keyname] != "") {
176                $sqlval['deliv_id'] = $deliv_id;
177                $sqlval['deliv_time'] = $arrRet[$keyname];
178                // INSERTの実行
179                $objQuery->insert("dtb_delivtime", $sqlval);
180            }
181        }
182
183        if(INPUT_DELIV_FEE) {
184            $sqlval = array();
185            // 配送料金の設定
186            for($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
187                $keyname = "fee$cnt";
188                if($arrRet[$keyname] != "") {
189                    $sqlval['deliv_id'] = $deliv_id;
190                    $sqlval['fee'] = $arrRet[$keyname];
191                    $sqlval['pref'] = $cnt;
192                    // INSERTの実行
193                    $objQuery->insert("dtb_delivfee", $sqlval);
194                }
195            }
196        }
197        $objQuery->commit();
198        return $deliv_id;
199    }
200
201    /* 配送業者情報の取得 */
202    function lfGetDelivData($deliv_id) {
203        $objQuery = new SC_Query();
204        // 配送業者一覧の取得
205        $col = "deliv_id, name, service_name, confirm_url";
206        $where = "deliv_id = ?";
207        $table = "dtb_deliv";
208        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
209        $this->objFormParam->setParam($arrRet[0]);
210        // 配送時間の取得
211        $col = "deliv_time";
212        $where = "deliv_id = ?  ORDER BY time_id";
213        $table = "dtb_delivtime";
214        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
215        $this->objFormParam->setParamList($arrRet, 'deliv_time');
216        // 配送料金の取得
217        $col = "fee";
218        $where = "deliv_id = ? ORDER BY pref";
219        $table = "dtb_delivfee";
220        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
221        $this->objFormParam->setParamList($arrRet, 'fee');
222    }
223
224    /* 入力内容のチェック */
225    function lfCheckError() {
226        // 入力データを渡す。
227        $arrRet =  $this->objFormParam->getHashArray();
228        $objErr = new SC_CheckError($arrRet);
229        $objErr->arrErr = $this->objFormParam->checkError();
230
231        if(!isset($objErr->arrErr['name']) && $_POST['deliv_id'] == "") {
232            // 既存チェック
233            $objDb = new SC_Helper_DB_Ex();
234            $ret = $objDb->sfIsRecord("dtb_deliv", "service_name", array($arrRet['service_name']));
235            if ($ret) {
236                $objErr->arrErr['name'] = "※ 同じ名称の組み合わせは登録できません。<br>";
237            }
238        }
239
240        return $objErr->arrErr;
241    }
242}
243?>
Note: See TracBrowser for help on using the repository browser.