source: branches/version-2_12-dev/data/class/pages/admin/basis/LC_Page_Admin_Basis_DeliveryInput.php @ 21693

Revision 21693, 12.6 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

  • 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-2011 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_DeliveryInput 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_subno = 'delivery';
47        $this->tpl_mainno = 'basis';
48        $masterData = new SC_DB_MasterData_Ex();
49        $this->arrPref = $masterData->getMasterData('mtb_pref');
50        $this->arrProductType = $masterData->getMasterData('mtb_product_type');
51        $this->arrPayments = SC_Helper_DB_Ex::sfGetIDValueList('dtb_payment', 'payment_id', 'payment_method');
52        $this->tpl_maintitle = '基本情報管理';
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        // フックポイント.
74        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
75        $objPlugin->doAction('LC_Page_Admin_Basis_DeliveryInput_action_before', array($this));
76
77        $this->lfInitParam($this->mode, $objFormParam);
78        $objFormParam->setParam($_POST);
79
80        // 入力値の変換
81        $objFormParam->convParam();
82        $this->arrErr = $this->lfCheckError($objFormParam);
83
84        switch ($this->mode) {
85            case 'edit':
86                if (count($this->arrErr) == 0) {
87                    $objFormParam->setValue('deliv_id', $this->lfRegistData($objFormParam->getHashArray(), $_SESSION['member_id']));
88                    $this->tpl_onload = "window.alert('配送方法設定が完了しました。');";
89                }
90                break;
91            case 'pre_edit':
92                if (count($this->arrErr) > 0) {
93                    trigger_error('', E_USER_ERROR);
94                }
95                $this->lfGetDelivData($objFormParam);
96                break;
97            default:
98                break;
99        }
100
101        $this->arrForm = $objFormParam->getFormParamList();
102
103        // フックポイント.
104        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
105        $objPlugin->doAction('LC_Page_Admin_Basis_DeliveryInput_action_after', array($this));
106    }
107
108    /**
109     * デストラクタ.
110     *
111     * @return void
112     */
113    function destroy() {
114        parent::destroy();
115    }
116
117    /* パラメーター情報の初期化 */
118    function lfInitParam($mode, &$objFormParam) {
119        $objFormParam = new SC_FormParam_Ex();
120
121        switch ($mode) {
122            case 'edit':
123                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
124                $objFormParam->addParam('配送業者名', 'name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
125                $objFormParam->addParam('名称', 'service_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
126                $objFormParam->addParam('説明', 'remark', LLTEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
127                $objFormParam->addParam('伝票No.確認URL', 'confirm_url', URL_LEN, 'n', array('URL_CHECK', 'MAX_LENGTH_CHECK'), 'http://');
128                $objFormParam->addParam('取扱商品種別', 'product_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
129                $objFormParam->addParam('取扱支払方法', 'payment_ids', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
130
131                for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
132                    $objFormParam->addParam("お届け時間$cnt", "deliv_time$cnt", STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
133                }
134
135                if (INPUT_DELIV_FEE) {
136                    for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
137                        $objFormParam->addParam("配送料金$cnt", "fee$cnt", PRICE_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
138                    }
139                }
140                break;
141
142            case 'pre_edit':
143                $objFormParam->addParam('配送業者ID', 'deliv_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
144                break;
145
146            default:
147                break;
148        }
149    }
150
151    /**
152     * 配送情報を登録する
153     *
154     * @return $deliv_id
155     */
156    function lfRegistData($arrRet, $member_id) {
157        $objQuery =& SC_Query_Ex::getSingletonInstance();
158        $objQuery->begin();
159
160        // 入力データを渡す。
161        $sqlval['name'] = $arrRet['name'];
162        $sqlval['service_name'] = $arrRet['service_name'];
163        $sqlval['remark'] = $arrRet['remark'];
164        $sqlval['confirm_url'] = $arrRet['confirm_url'];
165        $sqlval['product_type_id'] = $arrRet['product_type_id'];
166        $sqlval['creator_id'] = $member_id;
167        $sqlval['update_date'] = 'CURRENT_TIMESTAMP';
168
169        // deliv_id が決まっていた場合
170        if ($arrRet['deliv_id'] != '') {
171            $deliv_id = $arrRet['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                $arrWhereVal = array($deliv_id, $cnt);
182                // 既存データの有無を確認
183                $curData = $objQuery->select('*', $table, $where, $arrWhereVal);
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, $arrWhereVal);
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, $arrWhereVal);
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 fee_id = ?', array($deliv_id, $cnt));
212                    }
213                }
214            }
215        } else {
216            // 登録する配送業者IDの取得
217            $deliv_id = $objQuery->nextVal('dtb_deliv_deliv_id');
218            $sqlval['deliv_id'] = $deliv_id;
219            $sqlval['rank'] = $objQuery->max('rank', 'dtb_deliv') + 1;
220            $sqlval['create_date'] = 'CURRENT_TIMESTAMP';
221            // INSERTの実行
222            $objQuery->insert('dtb_deliv', $sqlval);
223
224            $sqlval = array();
225            // お届け時間の設定
226            for ($cnt = 1; $cnt <= DELIVTIME_MAX; $cnt++) {
227                $keyname = "deliv_time$cnt";
228                if ($arrRet[$keyname] != '') {
229                    $sqlval['deliv_id'] = $deliv_id;
230                    $sqlval['time_id'] = $cnt;
231                    $sqlval['deliv_time'] = $arrRet[$keyname];
232                    // INSERTの実行
233                    $objQuery->insert('dtb_delivtime', $sqlval);
234                }
235            }
236
237            if (INPUT_DELIV_FEE) {
238                $sqlval = array();
239                // 配送料金の設定
240                for ($cnt = 1; $cnt <= DELIVFEE_MAX; $cnt++) {
241                    $keyname = "fee$cnt";
242                    if ($arrRet[$keyname] != '') {
243                        $sqlval['deliv_id'] = $deliv_id;
244                        $sqlval['fee'] = $arrRet[$keyname];
245                        $sqlval['pref'] = $cnt;
246                        // INSERTの実行
247                        $sqlval['fee_id'] = $cnt;
248                        $objQuery->insert('dtb_delivfee', $sqlval);
249                    }
250                }
251            }
252        }
253
254        $objQuery->delete('dtb_payment_options', 'deliv_id = ?', array($arrRet['deliv_id']));
255        $sqlval = array();
256        $i = 1;
257        foreach ($arrRet['payment_ids'] as $val) {
258            $sqlval['deliv_id'] = $deliv_id;
259            $sqlval['payment_id'] = $val;
260            $sqlval['rank'] = $i;
261            $objQuery->insert('dtb_payment_options', $sqlval);
262            $i++;
263        }
264        $objQuery->commit();
265        return $deliv_id;
266    }
267
268    /* 配送業者情報の取得 */
269    function lfGetDelivData(&$objFormParam) {
270        $objQuery =& SC_Query_Ex::getSingletonInstance();
271
272        $deliv_id = $objFormParam->getValue('deliv_id');
273
274        // パラメーター情報の初期化
275        $this->lfInitParam('edit', $objFormParam);
276
277        // 配送業者一覧の取得
278        $col = 'deliv_id, name, service_name, remark, confirm_url, product_type_id';
279        $where = 'deliv_id = ?';
280        $table = 'dtb_deliv';
281        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
282        $objFormParam->setParam($arrRet[0]);
283        // お届け時間の取得
284        $col = 'deliv_time';
285        $where = 'deliv_id = ?  ORDER BY time_id';
286        $table = 'dtb_delivtime';
287        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
288        $objFormParam->setParamList($arrRet, 'deliv_time');
289        // 配送料金の取得
290        $col = 'fee';
291        $where = 'deliv_id = ? ORDER BY pref';
292        $table = 'dtb_delivfee';
293        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
294        $objFormParam->setParamList($arrRet, 'fee');
295        // 支払方法
296        $col = 'payment_id';
297        $where = 'deliv_id = ? ORDER BY rank';
298        $table = 'dtb_payment_options';
299        $arrRet = $objQuery->select($col, $table, $where, array($deliv_id));
300        $arrPaymentIds = array();
301        foreach ($arrRet as $val) {
302            $arrPaymentIds[] = $val['payment_id'];
303        }
304        $objFormParam->setValue('payment_ids', $arrPaymentIds);
305    }
306
307    /* 入力内容のチェック */
308    function lfCheckError(&$objFormParam) {
309        // 入力データを渡す。
310        $arrRet =  $objFormParam->getHashArray();
311        $objErr = new SC_CheckError_Ex($arrRet);
312        $objErr->arrErr = $objFormParam->checkError();
313
314        if (!isset($objErr->arrErr['name'])) {
315            // 既存チェック
316            $objDb = new SC_Helper_DB_Ex();
317            if ($arrRet['deliv_id'] == '') {
318                $ret = $objDb->sfIsRecord('dtb_deliv', 'service_name', array($arrRet['service_name']));
319            } else {
320                $objQuery = new SC_Query_Ex();
321                $ret = (($objQuery->count('dtb_deliv', 'deliv_id != ? AND service_name = ? ', array($arrRet['deliv_id'], $arrRet['service_name'])) > 0)? true : false);
322            }
323            if ($ret) {
324                $objErr->arrErr['service_name'] = '※ 同じ名称の組み合わせは登録できません。<br>';
325            }
326        }
327
328        return $objErr->arrErr;
329    }
330}
Note: See TracBrowser for help on using the repository browser.