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

Revision 19732, 6.6 KB checked in by Seasoft, 13 years ago (diff)

#855(SC_Query の #select, #getRow, #getCol, #get, #min, #max の引数順を統一する)

  • SC_Query#max を改訂
  • SC_Query#min を改訂
  • 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/admin/LC_Page_Admin.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_Admin {
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        $this->action();
60        $this->sendResponse();
61    }
62
63    /**
64     * Page のアクション.
65     *
66     * @return void
67     */
68    function action() {
69        $objSess = new SC_Session();
70        $objQuery = new SC_Query();
71        $objDb = new SC_Helper_DB_Ex();
72
73        // 認証可否の判定
74        SC_Utils_Ex::sfIsSuccess($objSess);
75
76        if (!isset($_POST['mode'])) $_POST['mode'] = "";
77
78        // 要求判定
79        switch($_POST['mode']) {
80            // 編集処理
81        case 'edit':
82            // POST値の引き継ぎ
83            $this->arrForm = $_POST;
84            // 入力文字の変換
85            $this->arrForm = $this->lfConvertParam($this->arrForm);
86            // エラーチェック
87            $this->arrErr = $this->lfErrorCheck();
88            if(count($this->arrErr) <= 0) {
89                if($_POST['class_id'] == "") {
90                    $this->lfInsertClass($this->arrForm); // 新規作成
91                } else {
92                    $this->lfUpdateClass($this->arrForm); // 既存編集
93                }
94                // 再表示
95                $this->objDisplay->reload();
96            } else {
97                // POSTデータを引き継ぐ
98                $this->tpl_class_id = $_POST['class_id'];
99            }
100            break;
101            // 削除
102        case 'delete':
103            $objDb->sfDeleteRankRecord("dtb_class", "class_id", $_POST['class_id'], "", true);
104            $objQuery = new SC_Query();
105            $objQuery->delete("dtb_classcategory", "class_id = ?", $_POST['class_id']);
106            // 再表示
107            $this->objDisplay->reload();
108            break;
109            // 編集前処理
110        case 'pre_edit':
111            // 編集項目をDBより取得する。
112            $where = "class_id = ?";
113            $class_name = $objQuery->get("name", "dtb_class", $where, array($_POST['class_id']));
114            // 入力項目にカテゴリ名を入力する。
115            $this->arrForm['name'] = $class_name;
116            // POSTデータを引き継ぐ
117            $this->tpl_class_id = $_POST['class_id'];
118            break;
119        case 'down':
120            $objDb->sfRankDown("dtb_class", "class_id", $_POST['class_id']);
121            // 再表示
122            $this->objDisplay->reload();
123            break;
124        case 'up':
125            $objDb->sfRankUp("dtb_class", "class_id", $_POST['class_id']);
126            // 再表示
127            $this->objDisplay->reload();
128            break;
129        default:
130            break;
131        }
132
133        // 規格の読込
134        $where = "del_flg <> 1";
135        $objQuery->setOrder("rank DESC");
136        $this->arrClass = $objQuery->select("name, class_id", "dtb_class", $where);
137        $this->arrClassCatCount = SC_Utils_Ex::sfGetClassCatCount();
138    }
139
140    /**
141     * デストラクタ.
142     *
143     * @return void
144     */
145    function destroy() {
146        parent::destroy();
147    }
148
149    /* DBへの挿入 */
150    function lfInsertClass($arrData) {
151        $objQuery = new SC_Query();
152        // INSERTする値を作成する。
153        $sqlval['name'] = $arrData['name'];
154        $sqlval['creator_id'] = $_SESSION['member_id'];
155        $sqlval['rank'] = $objQuery->max("rank", "dtb_class") + 1;
156        $sqlval['create_date'] = "now()";
157        $sqlval['update_date'] = "now()";
158        // INSERTの実行
159        $sqlval['class_id'] = $objQuery->nextVal('dtb_class_class_id');
160        $ret = $objQuery->insert("dtb_class", $sqlval);
161
162        return $ret;
163    }
164
165    /* DBへの更新 */
166    function lfUpdateClass($arrData) {
167        $objQuery = new SC_Query();
168        // UPDATEする値を作成する。
169        $sqlval['name'] = $arrData['name'];
170        $sqlval['update_date'] = "Now()";
171        $where = "class_id = ?";
172        // UPDATEの実行
173        $ret = $objQuery->update("dtb_class", $sqlval, $where, array($arrData['class_id']));
174        return $ret;
175    }
176
177    /* 取得文字列の変換 */
178    function lfConvertParam($array) {
179        // 文字変換
180        $arrConvList['name'] = "KVa";
181
182        foreach ($arrConvList as $key => $val) {
183            // POSTされてきた値のみ変換する。
184            if(isset($array[$key])) {
185                $array[$key] = mb_convert_kana($array[$key] ,$val);
186            }
187        }
188        return $array;
189    }
190
191    /* 入力エラーチェック */
192    function lfErrorCheck() {
193        $objErr = new SC_CheckError();
194        $objErr->doFunc(array("規格名", "name", STEXT_LEN), array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
195
196        if(!isset($objErr->arrErr['name'])) {
197            $objQuery = new SC_Query();
198            $arrRet = $objQuery->select("class_id, name", "dtb_class", "del_flg = 0 AND name = ?", array($_POST['name']));
199            // 編集中のレコード以外に同じ名称が存在する場合
200            if ($arrRet[0]['class_id'] != $_POST['class_id'] && $arrRet[0]['name'] == $_POST['name']) {
201                $objErr->arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br>";
202            }
203        }
204        return $objErr->arrErr;
205    }
206}
207?>
Note: See TracBrowser for help on using the repository browser.