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

Revision 19670, 10.8 KB checked in by nanasess, 14 years ago (diff)

スマートフォン対応(#787)

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