source: branches/version-2_5-dev/data/class/pages/admin/system/LC_Page_Admin_System_Masterdata.php @ 19803

Revision 19803, 5.7 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

  • 一斉置換前の現状記録のためのコミット

#628(未使用処理・定義などの削除)

  • 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_FILE_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_System_Masterdata 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 = 'system/masterdata.tpl';
47        $this->tpl_subnavi = 'system/subnavi.tpl';
48        $this->tpl_subno = 'masterdata';
49        $this->tpl_mainno = 'system';
50        $this->tpl_subtitle = 'マスタデータ管理';
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        SC_Utils_Ex::sfIsSuccess(new SC_Session);
70
71        $this->arrMasterDataName = $this->getMasterDataNames(array("mtb_pref",
72                                                                   "mtb_zip",
73                                                                   "mtb_constants"));
74        $masterData = new SC_DB_MasterData_Ex();
75
76        if (!isset($_POST["mode"])) $_POST["mode"] = "";
77
78        switch ($_POST["mode"]) {
79        case "edit":
80            // POST 文字列の妥当性チェック
81            $this->checkMasterDataName();
82            $this->errorMessage = $this->checkUniqueID();
83
84            if (empty($this->errorMessage)) {
85                // 取得したデータからマスタデータを生成
86                $arrData = array();
87                foreach ($_POST['id'] as $key => $val) {
88
89                    // ID が空のデータは生成しない
90                    if ($val != "") {
91                        $arrData[$val] = $_POST['name'][$key];
92                    }
93                }
94
95                // マスタデータを更新
96                $masterData->objQuery = new SC_Query();
97                $masterData->objQuery->begin();
98                $masterData->deleteMasterData($this->masterDataName, false);
99                // TODO カラム名はメタデータから取得した方が良い
100                $masterData->registMasterData($this->masterDataName,
101                                              array("id", "name", "rank"),
102                                              $arrData, false);
103                $masterData->objQuery->commit();
104                $this->tpl_onload = "window.alert('マスタデータの設定が完了しました。');";
105            }
106
107        case "show":
108            // POST 文字列の妥当性チェック
109            $this->checkMasterDataName();
110
111            // DB からマスタデータを取得
112            $this->arrMasterData =
113                $masterData->getDbMasterData($this->masterDataName);
114            break;
115
116        default:
117        }
118    }
119
120    /**
121     * デストラクタ.
122     *
123     * @return void
124     */
125    function destroy() {
126        parent::destroy();
127    }
128
129    /**
130     * マスタデータ名チェックを行う
131     *
132     * @access private
133     * @return void
134     */
135    function checkMasterDataName() {
136
137        if (in_array($_POST['master_data_name'], $this->arrMasterDataName)) {
138            $this->masterDataName = $_POST['master_data_name'];
139            return true;
140        } else {
141            SC_Utils_Ex::sfDispeError("");
142        }
143    }
144
145    /**
146     * マスタデータ名を配列で取得する.
147     *
148     * @access private
149     * @param array $ignores 取得しないマスタデータ名の配列
150     * @return array マスタデータ名の配列
151     */
152    function getMasterDataNames($ignores = array()) {
153        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
154        $arrMasterDataName = $dbFactory->findTableNames("mtb_");
155
156        $i = 0;
157        foreach ($arrMasterDataName as $val) {
158            foreach ($ignores as $ignore) {
159                if ($val == $ignore) {
160                    unset($arrMasterDataName[$i]);
161                }
162            }
163            $i++;
164        }
165        return $arrMasterDataName;
166    }
167
168    /**
169     * ID の値がユニークかチェックする.
170     *
171     * 重複した値が存在する場合はエラーメッセージを表示する.
172     *
173     * @access private
174     * @return void|string エラーが発生した場合はエラーメッセージを返す.
175     */
176    function checkUniqueID() {
177
178        $arrId = $_POST['id'];
179        for ($i = 0; $i < count($arrId); $i++) {
180
181            $id = $arrId[$i];
182            // 空の値は無視
183            if ($arrId[$i] != "") {
184                for ($j = $i + 1; $j < count($arrId); $j++) {
185                    if ($id == $arrId[$j]) {
186                        return $id . " が重複しているため登録できません.";
187                    }
188                }
189            }
190        }
191    }
192}
193?>
Note: See TracBrowser for help on using the repository browser.