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

Revision 23126, 6.3 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
25
26/**
27 * マスターデータ管理 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Admin_System_Masterdata extends LC_Page_Admin_Ex
34{
35    /**
36     * Page を初期化する.
37     *
38     * @return void
39     */
40    public function init()
41    {
42        parent::init();
43        $this->tpl_mainpage = 'system/masterdata.tpl';
44        $this->tpl_subno = 'masterdata';
45        $this->tpl_mainno = 'system';
46        $this->tpl_maintitle = 'システム設定';
47        $this->tpl_subtitle = 'マスターデータ管理';
48    }
49
50    /**
51     * Page のプロセス.
52     *
53     * @return void
54     */
55    public function process()
56    {
57        $this->action();
58        $this->sendResponse();
59    }
60
61    /**
62     * Page のアクション.
63     *
64     * @return void
65     */
66    public function action()
67    {
68        $this->arrMasterDataName = $this->getMasterDataNames(array('mtb_pref', 'mtb_zip', 'mtb_constants'));
69        $masterData = new SC_DB_MasterData_Ex();
70
71        switch ($this->getMode()) {
72            case 'edit':
73                // POST 文字列の妥当性チェック
74                $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
75                $this->errorMessage = $this->checkUniqueID($_POST);
76
77                if (empty($this->errorMessage)) {
78                    // 取得したデータからマスターデータを生成
79                    $this->registMasterData($_POST, $masterData, $this->masterDataName);
80                    $this->tpl_onload = "window.alert('マスターデータの設定が完了しました。');";
81                }
82                // FIXME break 入れ忘れと思われる。そうでないなら、要コメント。
83
84            case 'show':
85                // POST 文字列の妥当性チェック
86                $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
87
88                // DB からマスターデータを取得
89                $this->arrMasterData =
90                    $masterData->getDbMasterData($this->masterDataName);
91                break;
92
93            default:
94                break;
95        }
96
97    }
98
99    /**
100     * マスターデータ名チェックを行う
101     *
102     * @access private
103     * @param  array  $_POST値
104     * @param  array  $arrMasterDataName マスターデータテーブル名のリスト
105     * @return string $master_data_name 選択しているマスターデータのテーブル名
106     */
107    public function checkMasterDataName(&$arrParams, &$arrMasterDataName)
108    {
109        if (in_array($arrParams['master_data_name'], $arrMasterDataName)) {
110            $master_data_name = $arrParams['master_data_name'];
111
112            return $master_data_name;
113        } else {
114            SC_Utils_Ex::sfDispError('');
115        }
116
117    }
118
119    /**
120     * マスターデータ名を配列で取得する.
121     *
122     * @access private
123     * @param  array $ignores 取得しないマスターデータ名の配列
124     * @return array マスターデータ名の配列
125     */
126    public function getMasterDataNames($ignores = array())
127    {
128        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
129        $arrMasterDataName = $dbFactory->findTableNames('mtb_');
130
131        $i = 0;
132        foreach ($arrMasterDataName as $val) {
133            foreach ($ignores as $ignore) {
134                if ($val == $ignore) {
135                    unset($arrMasterDataName[$i]);
136                }
137            }
138            $i++;
139        }
140
141        return $arrMasterDataName;
142    }
143
144    /**
145     * ID の値がユニークかチェックする.
146     *
147     * 重複した値が存在する場合はエラーメッセージを表示する.
148     *
149     * @access private
150     * @return void|string エラーが発生した場合はエラーメッセージを返す.
151     */
152    public function checkUniqueID(&$arrParams)
153    {
154        $arrId = $arrParams['id'];
155        for ($i = 0; $i < count($arrId); $i++) {
156            $id = $arrId[$i];
157            // 空の値は無視
158            if ($arrId[$i] != '') {
159                for ($j = $i + 1; $j < count($arrId); $j++) {
160                    if ($id == $arrId[$j]) {
161                        return $id . ' が重複しているため登録できません.';
162                    }
163                }
164            }
165        }
166    }
167
168    /**
169     * マスターデータの登録.
170     *
171     * @access private{
172     * @param  array  $arrParams        $_POST値
173     * @param  object $masterData       SC_DB_MasterData_Ex()
174     * @param  string $master_data_name 登録対象のマスターデータのテーブル名
175     * @return void
176     */
177    public function registMasterData($arrParams, &$masterData, $master_data_name)
178    {
179        $arrTmp = array();
180        foreach ($arrParams['id'] as $key => $val) {
181            // ID が空のデータは生成しない
182            if ($val != '') {
183                $arrTmp[$val] = $arrParams['name'][$key];
184            }
185        }
186
187        // マスターデータを更新
188        $masterData->objQuery =& SC_Query_Ex::getSingletonInstance();
189        $masterData->objQuery->begin();
190        $masterData->deleteMasterData($master_data_name, false);
191        // TODO カラム名はメタデータから取得した方が良い
192        $masterData->registMasterData($master_data_name, array('id', 'name', 'rank'), $arrTmp, false);
193        $masterData->objQuery->commit();
194    }
195}
Note: See TracBrowser for help on using the repository browser.