source: branches/version-2_13-dev/data/class/pages/admin/products/LC_Page_Admin_Products_Maker.php @ 23297

Revision 23297, 6.4 KB checked in by undertree, 10 years ago (diff)

#2457 メーカー登録後、新規登録画面に移行しない の対応

  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * メーカー登録 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_Products_Maker extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'products/maker.tpl';
44        $this->tpl_subno = 'maker';
45        $this->tpl_maintitle = '商品管理';
46        $this->tpl_subtitle = 'メーカー登録';
47        $this->tpl_mainno = 'products';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    public function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    public function action()
67    {
68        $objMaker = new SC_Helper_Maker_Ex();
69        $objFormParam = new SC_FormParam_Ex();
70
71        // パラメーター情報の初期化
72        $this->lfInitParam($objFormParam);
73
74        // POST値をセット
75        $objFormParam->setParam($_POST);
76
77        // POST値の入力文字変換
78        $objFormParam->convParam();
79
80        //maker_idを変数にセット
81        $maker_id = $objFormParam->getValue('maker_id');
82
83        // モードによる処理切り替え
84        switch ($this->getMode()) {
85            // 編集処理
86            case 'edit':
87                // エラーチェック
88                $this->arrErr = $this->lfCheckError($objFormParam, $objMaker);
89                if (!SC_Utils_Ex::isBlank($this->arrErr['maker_id'])) {
90                    trigger_error('', E_USER_ERROR);
91
92                    return;
93                }
94
95                if (count($this->arrErr) <= 0) {
96                    // POST値の引き継ぎ
97                    $arrParam = $objFormParam->getHashArray();
98                    // 登録実行
99                    $res_maker_id = $this->doRegist($maker_id, $arrParam, $objMaker);
100                    if ($res_maker_id !== FALSE) {
101                        // 完了メッセージ
102                        $this->tpl_onload = "alert('登録が完了しました。');";
103                    }
104                }
105                SC_Response_Ex::reload();
106                break;
107
108            // 編集前処理
109            case 'pre_edit':
110                $maker = $objMaker->getMaker($maker_id);
111                $objFormParam->setParam($maker);
112
113                // POSTデータを引き継ぐ
114                $this->tpl_maker_id = $maker_id;
115                break;
116
117            // メーカー順変更
118            case 'up':
119                $objMaker->rankUp($maker_id);
120
121                // リロード
122                SC_Response_Ex::reload();
123                break;
124
125            case 'down':
126                $objMaker->rankDown($maker_id);
127
128                // リロード
129                SC_Response_Ex::reload();
130                break;
131
132            // 削除
133            case 'delete':
134                $objMaker->delete($maker_id);
135
136                // リロード
137                SC_Response_Ex::reload();
138                break;
139
140            default:
141                break;
142        }
143
144        $this->arrForm = $objFormParam->getFormParamList();
145
146        // メーカー情報読み込み
147        $this->arrMaker = $objMaker->getList();
148    }
149
150    /**
151     * パラメーター情報の初期化を行う.
152     *
153     * @param  SC_FormParam $objFormParam SC_FormParam インスタンス
154     * @return void
155     */
156    public function lfInitParam(&$objFormParam)
157    {
158        $objFormParam->addParam('メーカーID', 'maker_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
159        $objFormParam->addParam('メーカー名', 'name', SMTEXT_LEN, 'KVa', array('EXIST_CHECK','SPTAB_CHECK','MAX_LENGTH_CHECK'));
160    }
161
162    /**
163     * 登録処理を実行.
164     *
165     * @param  integer  $maker_id
166     * @param  array    $sqlval
167     * @param  object   $objMaker
168     * @return multiple
169     */
170    public function doRegist($maker_id, $sqlval, SC_Helper_Maker_Ex $objMaker)
171    {
172        $sqlval['maker_id'] = $maker_id;
173        $sqlval['creator_id'] = $_SESSION['member_id'];
174
175        return $objMaker->saveMaker($sqlval);
176    }
177
178    /**
179     * 入力エラーチェック.
180     *
181     * @return array $objErr->arrErr エラー内容
182     */
183    public function lfCheckError(&$objFormParam, SC_Helper_Maker_Ex &$objMaker)
184    {
185        $arrErr = $objFormParam->checkError();
186        $arrForm = $objFormParam->getHashArray();
187
188        // maker_id の正当性チェック
189        if (!empty($arrForm['maker_id'])) {
190            if (!SC_Utils_Ex::sfIsInt($arrForm['maker_id'])
191                || SC_Utils_Ex::sfIsZeroFilling($arrForm['maker_id'])
192                || !$objMaker->getMaker($arrForm['maker_id'])
193            ) {
194                // maker_idが指定されていて、且つその値が不正と思われる場合はエラー
195                $arrErr['maker_id'] = '※ メーカーIDが不正です<br />';
196            }
197        }
198        if (!isset($arrErr['name'])) {
199            $arrMaker = $objMaker->getByName($arrForm['name']);
200
201            // 編集中のレコード以外に同じ名称が存在する場合
202            if (
203                    !SC_Utils_Ex::isBlank($arrMaker)
204                    && $arrMaker['maker_id'] != $arrForm['maker_id']
205                    && $arrMaker['name'] == $arrForm['name']
206                ) {
207                $arrErr['name'] = '※ 既に同じ内容の登録が存在します。<br />';
208            }
209        }
210
211        return $arrErr;
212    }
213}
Note: See TracBrowser for help on using the repository browser.