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

Revision 18772, 8.0 KB checked in by nanasess, 14 years ago (diff)

r18700 の続き

  • SC_DbConn のインスタンスを直接使用している個所を SC_Query に変更(#565)
    • 削除予定の機能については未対応
  • 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:LC_Page_Admin_Products_ClassCategory.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Admin_Products_ClassCategory 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/classcategory.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        $objQuery = new SC_Query();
61        $objDb = new SC_Helper_DB_Ex();
62
63        // 認証可否の判定
64        $objSess = new SC_Session();
65        SC_Utils_Ex::sfIsSuccess($objSess);
66
67        $get_check = false;
68
69        // 規格IDのチェック
70        if(SC_Utils_Ex::sfIsInt($_GET['class_id'])) {
71            // 規格名の取得
72            $this->tpl_class_name = $objQuery->get("dtb_class", "name", "class_id = ?", array($_GET['class_id']));
73            if($this->tpl_class_name != "") {
74                // 規格IDの引き継ぎ
75                $this->arrHidden['class_id'] = $_GET['class_id'];
76                $get_check = true;
77            }
78        }
79
80        if(!$get_check) {
81            // 規格登録ページに飛ばす。
82            $this->sendRedirect($this->getLocation(URL_CLASS_REGIST));
83            exit;
84        }
85
86        if (!isset($_POST['mode'])) $_POST['mode'] = "";
87
88        if (isset($_POST['class_id'])) {
89            if (!SC_Utils_Ex::sfIsInt($_POST['class_id'])) {
90                SC_Utils_Ex::sfDispError("");
91            }
92        }
93
94        // 新規作成 or 編集
95        switch($_POST['mode']) {
96            // 登録ボタン押下
97        case 'edit':
98            // POST値の引き継ぎ
99            $this->arrForm = $_POST;
100            // 入力文字の変換
101            $_POST = $this->lfConvertParam($_POST);
102            // エラーチェック
103            $this->arrErr = $this->lfErrorCheck();
104            if(count($this->arrErr) <= 0) {
105                if($_POST['classcategory_id'] == "") {
106                    $this->lfInsertClass(); // DBへの書き込み
107                } else {
108                    $this->lfUpdateClass(); // DBへの書き込み
109                }
110                // 再表示
111                $this->reload($_GET['class_id']);
112                //sfReload("class_id=" . $_GET['class_id']);
113            } else {
114                // POSTデータを引き継ぐ
115                $this->tpl_classcategory_id = $_POST['classcategory_id'];
116            }
117            break;
118            // 削除
119        case 'delete':
120            // ランク付きレコードの削除
121            $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['class_id']);
122            $objDb->sfDeleteRankRecord("dtb_classcategory", "classcategory_id", $_POST['classcategory_id'], $where, true);
123            break;
124            // 編集前処理
125        case 'pre_edit':
126            // 編集項目をDBより取得する。
127            $where = "classcategory_id = ?";
128            $name = $objQuery->get("dtb_classcategory", "name", $where, array($_POST['classcategory_id']));
129            // 入力項目にカテゴリ名を入力する。
130            $this->arrForm['name'] = $name;
131            // POSTデータを引き継ぐ
132            $this->tpl_classcategory_id = $_POST['classcategory_id'];
133            break;
134        case 'down':
135            $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['class_id']);
136            $objDb->sfRankDown("dtb_classcategory", "classcategory_id", $_POST['classcategory_id'], $where);
137            break;
138        case 'up':
139            $where = "class_id = " . SC_Utils_Ex::sfQuoteSmart($_POST['class_id']);
140            $objDb->sfRankUp("dtb_classcategory", "classcategory_id", $_POST['classcategory_id'], $where);
141            break;
142        default:
143            break;
144        }
145
146        // 規格分類の読込
147        $where = "del_flg <> 1 AND class_id = ?";
148        $objQuery->setOrder("rank DESC");
149        $this->arrClassCat = $objQuery->select("name, classcategory_id", "dtb_classcategory", $where, array($_GET['class_id']));
150
151        $objView->assignobj($this);
152        $objView->display(MAIN_FRAME);
153
154    }
155
156    /**
157     * デストラクタ.
158     *
159     * @return void
160     */
161    function destroy() {
162        parent::destroy();
163    }
164
165    /* DBへの挿入 */
166    function lfInsertClass() {
167        $objQuery = new SC_Query();
168        $objQuery->begin();
169        // 親規格IDの存在チェック
170        $where = "del_flg <> 1 AND class_id = ?";
171        $ret =  $objQuery->get("dtb_class", "class_id", $where, array($_POST['class_id']));
172        if($ret != "") {
173            // INSERTする値を作成する。
174            $sqlval['name'] = $_POST['name'];
175            $sqlval['class_id'] = $_POST['class_id'];
176            $sqlval['creator_id'] = $_SESSION['member_id'];
177            $sqlval['rank'] = $objQuery->max("dtb_classcategory", "rank", $where, array($_POST['class_id'])) + 1;
178            $sqlval['create_date'] = "now()";
179            $sqlval['update_date'] = "now()";
180            // INSERTの実行
181            $ret = $objQuery->insert("dtb_classcategory", $sqlval);
182        }
183        $objQuery->commit();
184        return $ret;
185    }
186
187    /* DBへの更新 */
188    function lfUpdateClass() {
189        $objQuery = new SC_Query();
190        // UPDATEする値を作成する。
191        $sqlval['name'] = $_POST['name'];
192        $sqlval['update_date'] = "Now()";
193        $where = "classcategory_id = ?";
194        // UPDATEの実行
195        $ret = $objQuery->update("dtb_classcategory", $sqlval, $where, array($_POST['classcategory_id']));
196        return $ret;
197    }
198
199    /* 取得文字列の変換 */
200    function lfConvertParam($array) {
201        // 文字変換
202        $arrConvList['name'] = "KVa";
203
204        foreach ($arrConvList as $key => $val) {
205            // POSTされてきた値のみ変換する。
206            if(isset($array[$key])) {
207                $array[$key] = mb_convert_kana($array[$key] ,$val);
208            }
209        }
210        return $array;
211    }
212
213    /* 入力エラーチェック */
214    function lfErrorCheck() {
215        $objErr = new SC_CheckError();
216        $objErr->doFunc(array("分類名", "name", STEXT_LEN), array("EXIST_CHECK","MAX_LENGTH_CHECK"));
217        if(!isset($objErr->arrErr['name'])) {
218            $objQuery = new SC_Query();
219            $where = "class_id = ? AND name = ?";
220            $arrRet = $objQuery->select("classcategory_id, name", "dtb_classcategory", $where, array($_GET['class_id'], $_POST['name']));
221            // 編集中のレコード以外に同じ名称が存在する場合
222            if ($arrRet[0]['classcategory_id'] != $_POST['classcategory_id'] && $arrRet[0]['name'] == $_POST['name']) {
223                $objErr->arrErr['name'] = "※ 既に同じ内容の登録が存在します。<br>";
224            }
225        }
226        return $objErr->arrErr;
227    }
228}
229?>
Note: See TracBrowser for help on using the repository browser.