source: branches/feature-module-update/data/class/pages/admin/basis/LC_Page_Admin_Basis_Masterdata.php @ 16582

Revision 16582, 5.5 KB checked in by nanasess, 16 years ago (diff)

ライセンス表記変更

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