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

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