source: branches/version-2_4/data/class/pages/admin/system/LC_Page_Admin_System_Masterdata.php @ 18734

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