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

Revision 20534, 8.9 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

  • 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-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_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_Products_Maker extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/maker.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_subno = 'maker';
49        $this->tpl_subtitle = 'メーカー登録';
50        $this->tpl_mainno = 'products';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
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        // 変換後のPOST値を取得
81        $this->arrForm  = $objFormParam->getHashArray();
82
83
84        // モードによる処理切り替え
85        switch($this->getMode()) {
86
87        // 編集処理
88        case 'edit':
89        // 入力文字の変換
90
91            // エラーチェック
92            $this->arrErr = $this->lfErrorCheck($this->arrForm);
93            if(count($this->arrErr) <= 0) {
94                if($this->arrForm['maker_id'] == "") {
95                    // メーカー情報新規登録
96                    $this->lfInsert($this->arrForm);
97                } else {
98                    // メーカー情報編集
99                    $this->lfUpdate($this->arrForm);
100                }
101                // 再表示
102                $this->objDisplay->reload();
103            } else {
104                // POSTデータを引き継ぐ
105                $this->tpl_maker_id = $this->arrForm['maker_id'];
106            }
107            break;
108
109        // 編集前処理
110        case 'pre_edit':
111            $this->arrForm = $this->lfPreEdit($this->arrForm, $this->arrForm['maker_id']);
112            $this->tpl_maker_id = $this->arrForm['maker_id'];
113            break;
114
115        // メーカー順変更
116        case 'up':
117        case 'down':
118            $this->lfRankChange($this->arrForm['maker_id'], $this->getMode());
119            // リロード
120            SC_Response_Ex::reload();
121            break;
122
123        // 削除
124        case 'delete':
125            $this->lfDelete($this->arrForm['maker_id']);
126            // リロード
127            SC_Response_Ex::reload();
128            break;
129
130        default:
131            break;
132        }
133
134        // メーカー情報読み込み
135        $this->arrMaker = $this->lfDisp();
136
137    }
138
139    /**
140     * デストラクタ.
141     *
142     * @return void
143     */
144    function destroy() {
145        parent::destroy();
146    }
147
148    /**
149     * パラメータ情報の初期化を行う.
150     *
151     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
152     * @return void
153     */
154    function lfInitParam(&$objFormParam) {
155        $objFormParam->addParam("メーカーID", "maker_id", INT_LEN, "n", array("NUM_CHECK", "MAX_LENGTH_CHECK"));
156        $objFormParam->addParam("メーカー名", "name", SMTEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
157    }
158
159    /**
160     * メーカー情報表示.
161     *
162     * @return array $arrMaker メーカー情報
163     */
164    function lfDisp() {
165        $objQuery =& SC_Query_Ex::getSingletonInstance();
166
167        // 削除されていないメーカー情報を表示する
168        $where = "del_flg = 0";
169        $objQuery->setOrder("rank DESC");
170        $arrMaker = array();
171        $arrMaker = $objQuery->select("maker_id, name", "dtb_maker", $where);
172        return $arrMaker;
173    }
174
175    /**
176     * メーカー情報新規登録.
177     *
178     * @param array $arrForm メーカー情報
179     * @return void
180     */
181    function lfInsert(&$arrForm) {
182        $objQuery =& SC_Query_Ex::getSingletonInstance();
183
184        // INSERTする値を作成する
185        $sqlval['name'] = $arrForm['name'];
186        $sqlval['rank'] = $objQuery->max("rank", "dtb_maker") + 1;
187        $sqlval['creator_id'] = $_SESSION['member_id'];
188        $sqlval['update_date'] = "Now()";
189        $sqlval['create_date'] = "Now()";
190        $sqlval['maker_id'] = $objQuery->nextVal('dtb_maker_maker_id');
191
192        // INSERTの実行
193        $objQuery->insert("dtb_maker", $sqlval);
194    }
195
196    /**
197     * メーカー情報更新.
198     *
199     * @param array $arrForm メーカー情報
200     * @return void
201     */
202    function lfUpdate(&$arrForm) {
203        $objQuery =& SC_Query_Ex::getSingletonInstance();
204
205        // UPDATEする値を作成する
206        $sqlval['name'] = $arrForm['name'];
207        $sqlval['update_date'] = "Now()";
208        $where = "maker_id = ?";
209
210        // UPDATEの実行
211        $objQuery->update("dtb_maker", $sqlval, $where, array($arrForm['maker_id']));
212    }
213
214    /**
215     * メーカー情報削除.
216     *
217     * @param integer $maker_id メーカーID
218     * @return void
219     */
220    function lfDelete($maker_id) {
221        $objDb = new SC_Helper_DB_Ex();
222        $objDb->sfDeleteRankRecord("dtb_maker", "maker_id", $maker_id, "", true);
223    }
224
225    /**
226     * メーカー情報順番変更.
227     *
228     * @param  integer $maker_id メーカーID
229     * @param  string  $mode up か down のモードを示す文字列
230     * @return void
231     */
232    function lfRankChange($maker_id, $mode) {
233        $objDb = new SC_Helper_DB_Ex();
234       
235        switch($mode) {
236        case 'up':
237            $objDb->sfRankUp("dtb_maker", "maker_id", $maker_id);
238            break;
239
240        case 'down':
241            $objDb->sfRankDown("dtb_maker", "maker_id", $maker_id);
242            break;
243
244        default:
245            break;
246        }
247    }
248
249
250    /**
251     * メーカー情報編集前処理.
252     *
253     * @param array   $arrForm メーカー情報
254     * @param integer $maker_id メーカーID
255     * @return array  $arrForm メーカー名を追加
256     */
257    function lfPreEdit(&$arrForm, $maker_id) {
258        $objQuery =& SC_Query_Ex::getSingletonInstance();
259
260        // 編集項目を取得する
261        $where = "maker_id = ?";
262        $arrMaker = array();
263        $arrMaker = $objQuery->select("name", "dtb_maker", $where, array($maker_id));
264        $arrForm['name'] = $arrMaker[0]['name'];
265
266        return $arrForm;
267    }
268
269    /**
270     * 入力エラーチェック.
271     *
272     * @param  array $arrForm メーカー情報
273     * @return array $objErr->arrErr エラー内容
274     */
275    function lfErrorCheck(&$arrForm) {
276        $objErr = new SC_CheckError_Ex($arrForm);
277        $objErr->doFunc(array("メーカー名", "name", SMTEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
278
279        // maker_id の正当性チェック
280        if(!empty($arrForm['maker_id'])) {
281            $objDb = new SC_Helper_DB_Ex();
282            if(!SC_Utils_Ex::sfIsInt($arrForm['maker_id'])
283              || SC_Utils_Ex::sfIsZeroFilling($arrForm['maker_id'])
284              || !$objDb->sfIsRecord('dtb_maker', 'maker_id', array($arrForm['maker_id']))) {
285
286              // maker_idが指定されていて、且つその値が不正と思われる場合はエラー
287              $objErr->arrErr['maker_id'] = "※ メーカーIDが不正です<br />";
288            }
289        }
290        if(!isset($objErr->arrErr['name'])) {
291            $objQuery =& SC_Query_Ex::getSingletonInstance();
292            $arrMaker = array();
293            $arrMaker = $objQuery->select("maker_id, name", "dtb_maker", "del_flg = 0 AND name = ?", array($arrForm['name']));
294
295            // 編集中のレコード以外に同じ名称が存在する場合
296            if ($arrMaker[0]['maker_id'] != $arrForm['maker_id'] && $arrMaker[0]['name'] == $arrForm['name']) {
297                $objErr->arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br />";
298            }
299        }
300
301        return $objErr->arrErr;
302    }
303}
304?>
Note: See TracBrowser for help on using the repository browser.