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

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