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

Revision 18820, 6.4 KB checked in by nanasess, 14 years ago (diff)

#781(規格のデータベースを木構造に)

  • 規格の無い商品が品切れになってしまう不具合修正
  • 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/LC_Page.php");
26
27/**
28 * 規格管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Products_Class extends LC_Page {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'products/class.tpl';
47        $this->tpl_subnavi = 'products/subnavi.tpl';
48        $this->tpl_subno = 'class';
49        $this->tpl_subtitle = '規格登録';
50        $this->tpl_mainno = 'products';
51    }
52
53    /**
54     * Page のプロセス.
55     *
56     * @return void
57     */
58    function process() {
59        $objView = new SC_AdminView();
60        $objSess = new SC_Session();
61        $objQuery = new SC_Query();
62        $objDb = new SC_Helper_DB_Ex();
63
64        // 認証可否の判定
65        SC_Utils_Ex::sfIsSuccess($objSess);
66
67        if (!isset($_POST['mode'])) $_POST['mode'] = "";
68
69        // 要求判定
70        switch($_POST['mode']) {
71            // 編集処理
72        case 'edit':
73            // POST値の引き継ぎ
74            $this->arrForm = $_POST;
75            // 入力文字の変換
76            $this->arrForm = $this->lfConvertParam($this->arrForm);
77            // エラーチェック
78            $this->arrErr = $this->lfErrorCheck();
79            if(count($this->arrErr) <= 0) {
80                if($_POST['class_id'] == "") {
81                    $this->lfInsertClass($this->arrForm); // 新規作成
82                } else {
83                    $this->lfUpdateClass($this->arrForm); // 既存編集
84                }
85                // 再表示
86                $this->reload();
87            } else {
88                // POSTデータを引き継ぐ
89                $this->tpl_class_id = $_POST['class_id'];
90            }
91            break;
92            // 削除
93        case 'delete':
94            $objDb->sfDeleteRankRecord("dtb_class", "class_id", $_POST['class_id'], "", true);
95            $objQuery = new SC_Query();
96            $objQuery->delete("dtb_classcategory", "class_id = ?", $_POST['class_id']);
97            // 再表示
98            $this->reload();
99            break;
100            // 編集前処理
101        case 'pre_edit':
102            // 編集項目をDBより取得する。
103            $where = "class_id = ?";
104            $class_name = $objQuery->get("dtb_class", "name", $where, array($_POST['class_id']));
105            // 入力項目にカテゴリ名を入力する。
106            $this->arrForm['name'] = $class_name;
107            // POSTデータを引き継ぐ
108            $this->tpl_class_id = $_POST['class_id'];
109            break;
110        case 'down':
111            $objDb->sfRankDown("dtb_class", "class_id", $_POST['class_id']);
112            // 再表示
113            $this->reload();
114            break;
115        case 'up':
116            $objDb->sfRankUp("dtb_class", "class_id", $_POST['class_id']);
117            // 再表示
118            $this->reload();
119            break;
120        default:
121            break;
122        }
123
124        // 規格の読込
125        $where = "del_flg <> 1";
126        $objQuery->setOrder("rank DESC");
127        $this->arrClass = $objQuery->select("name, class_id", "dtb_class", $where);
128        $this->arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount();
129
130        $objView->assignobj($this);
131        $objView->display(MAIN_FRAME);
132    }
133
134    /**
135     * デストラクタ.
136     *
137     * @return void
138     */
139    function destroy() {
140        parent::destroy();
141    }
142
143    /* DBへの挿入 */
144    function lfInsertClass($arrData) {
145        $objQuery = new SC_Query();
146        // INSERTする値を作成する。
147        $sqlval['name'] = $arrData['name'];
148        $sqlval['creator_id'] = $_SESSION['member_id'];
149        $sqlval['rank'] = $objQuery->max("dtb_class", "rank") + 1;
150        $sqlval['create_date'] = "now()";
151        $sqlval['update_date'] = "now()";
152        // INSERTの実行
153        $sqlval['class_id'] = $objQuery->nextVal('dtb_class_class_id');
154        $ret = $objQuery->insert("dtb_class", $sqlval);
155
156        return $ret;
157    }
158
159    /* DBへの更新 */
160    function lfUpdateClass($arrData) {
161        $objQuery = new SC_Query();
162        // UPDATEする値を作成する。
163        $sqlval['name'] = $arrData['name'];
164        $sqlval['update_date'] = "Now()";
165        $where = "class_id = ?";
166        // UPDATEの実行
167        $ret = $objQuery->update("dtb_class", $sqlval, $where, array($arrData['class_id']));
168        return $ret;
169    }
170
171    /* 取得文字列の変換 */
172    function lfConvertParam($array) {
173        // 文字変換
174        $arrConvList['name'] = "KVa";
175
176        foreach ($arrConvList as $key => $val) {
177            // POSTされてきた値のみ変換する。
178            if(isset($array[$key])) {
179                $array[$key] = mb_convert_kana($array[$key] ,$val);
180            }
181        }
182        return $array;
183    }
184
185    /* 入力エラーチェック */
186    function lfErrorCheck() {
187        $objErr = new SC_CheckError();
188        $objErr->doFunc(array("規格名", "name", STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
189
190        if(!isset($objErr->arrErr['name'])) {
191            $objQuery = new SC_Query();
192            $arrRet = $objQuery->select("class_id, name", "dtb_class", "del_flg = 0 AND name = ?", array($_POST['name']));
193            // 編集中のレコード以外に同じ名称が存在する場合
194            if ($arrRet[0]['class_id'] != $_POST['class_id'] && $arrRet[0]['name'] == $_POST['name']) {
195                $objErr->arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br>";
196            }
197        }
198        return $objErr->arrErr;
199    }
200}
201?>
Note: See TracBrowser for help on using the repository browser.