source: branches/comu-ver2/data/class/pages/admin/system/LC_Page_Admin_System_Masterdata.php @ 18701

Revision 18701, 5.6 KB checked in by nanasess, 14 years ago (diff)

Copyright の更新(#601)

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