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

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

#627(ソース整形・ソースコメントの改善)

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