1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 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 |
---|
25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * マスターデータ管理 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_System_Masterdata extends LC_Page_Admin_Ex { |
---|
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_subno = 'masterdata'; |
---|
48 | $this->tpl_mainno = 'system'; |
---|
49 | $this->tpl_maintitle = t('TPL_MAINTITLE_009'); |
---|
50 | $this->tpl_subtitle = t('LC_Page_Admin_System_Masterdata_001'); |
---|
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 | |
---|
70 | $this->arrMasterDataName = $this->getMasterDataNames(array('mtb_pref', 'mtb_zip', 'mtb_constants')); |
---|
71 | $masterData = new SC_DB_MasterData_Ex(); |
---|
72 | |
---|
73 | switch ($this->getMode()) { |
---|
74 | case 'edit': |
---|
75 | // POST 文字列の妥当性チェック |
---|
76 | $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName); |
---|
77 | $this->errorMessage = $this->checkUniqueID($_POST); |
---|
78 | |
---|
79 | if (empty($this->errorMessage)) { |
---|
80 | // 取得したデータからマスターデータを生成 |
---|
81 | $this->registMasterData($_POST, $masterData, $this->masterDataName); |
---|
82 | $this->tpl_onload = "window.alert('" . t('ALERT_028') . "');"; |
---|
83 | } |
---|
84 | // FIXME break 入れ忘れと思われる。そうでないなら、要コメント。 |
---|
85 | |
---|
86 | case 'show': |
---|
87 | // POST 文字列の妥当性チェック |
---|
88 | $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName); |
---|
89 | |
---|
90 | // DB からマスターデータを取得 |
---|
91 | $this->arrMasterData = |
---|
92 | $masterData->getDbMasterData($this->masterDataName); |
---|
93 | break; |
---|
94 | |
---|
95 | default: |
---|
96 | break; |
---|
97 | } |
---|
98 | |
---|
99 | } |
---|
100 | |
---|
101 | /** |
---|
102 | * デストラクタ. |
---|
103 | * |
---|
104 | * @return void |
---|
105 | */ |
---|
106 | function destroy() { |
---|
107 | parent::destroy(); |
---|
108 | } |
---|
109 | |
---|
110 | /** |
---|
111 | * マスターデータ名チェックを行う |
---|
112 | * |
---|
113 | * @access private |
---|
114 | * @param array $_POST値 |
---|
115 | * @param array $arrMasterDataName マスターデータテーブル名のリスト |
---|
116 | * @return string $master_data_name 選択しているマスターデータのテーブル名 |
---|
117 | */ |
---|
118 | function checkMasterDataName(&$arrParams, &$arrMasterDataName) { |
---|
119 | |
---|
120 | if (in_array($arrParams['master_data_name'], $arrMasterDataName)) { |
---|
121 | $master_data_name = $arrParams['master_data_name']; |
---|
122 | return $master_data_name; |
---|
123 | } else { |
---|
124 | SC_Utils_Ex::sfDispError(''); |
---|
125 | } |
---|
126 | |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * マスターデータ名を配列で取得する. |
---|
131 | * |
---|
132 | * @access private |
---|
133 | * @param array $ignores 取得しないマスターデータ名の配列 |
---|
134 | * @return array マスターデータ名の配列 |
---|
135 | */ |
---|
136 | function getMasterDataNames($ignores = array()) { |
---|
137 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
138 | $arrMasterDataName = $dbFactory->findTableNames('mtb_'); |
---|
139 | |
---|
140 | $i = 0; |
---|
141 | foreach ($arrMasterDataName as $val) { |
---|
142 | foreach ($ignores as $ignore) { |
---|
143 | if ($val == $ignore) { |
---|
144 | unset($arrMasterDataName[$i]); |
---|
145 | } |
---|
146 | } |
---|
147 | $i++; |
---|
148 | } |
---|
149 | return $arrMasterDataName; |
---|
150 | } |
---|
151 | |
---|
152 | /** |
---|
153 | * ID の値がユニークかチェックする. |
---|
154 | * |
---|
155 | * 重複した値が存在する場合はエラーメッセージを表示する. |
---|
156 | * |
---|
157 | * @access private |
---|
158 | * @return void|string エラーが発生した場合はエラーメッセージを返す. |
---|
159 | */ |
---|
160 | function checkUniqueID(&$arrParams) { |
---|
161 | |
---|
162 | $arrId = $arrParams['id']; |
---|
163 | for ($i = 0; $i < count($arrId); $i++) { |
---|
164 | |
---|
165 | $id = $arrId[$i]; |
---|
166 | // 空の値は無視 |
---|
167 | if ($arrId[$i] != '') { |
---|
168 | for ($j = $i + 1; $j < count($arrId); $j++) { |
---|
169 | if ($id == $arrId[$j]) { |
---|
170 | return t('LC_Page_Admin_System_Masterdata_002', array('T_ARG1' => $id)); |
---|
171 | |
---|
172 | } |
---|
173 | } |
---|
174 | } |
---|
175 | } |
---|
176 | } |
---|
177 | |
---|
178 | /** |
---|
179 | * マスターデータの登録. |
---|
180 | * |
---|
181 | * @access private{ |
---|
182 | * @param array $arrParams $_POST値 |
---|
183 | * @param object $masterData SC_DB_MasterData_Ex() |
---|
184 | * @param string $master_data_name 登録対象のマスターデータのテーブル名 |
---|
185 | * @return void |
---|
186 | */ |
---|
187 | function registMasterData($arrParams, &$masterData, $master_data_name) { |
---|
188 | |
---|
189 | $arrTmp = array(); |
---|
190 | foreach ($arrParams['id'] as $key => $val) { |
---|
191 | |
---|
192 | // ID が空のデータは生成しない |
---|
193 | if ($val != '') { |
---|
194 | $arrTmp[$val] = $arrParams['name'][$key]; |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | // マスターデータを更新 |
---|
199 | $masterData->objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
200 | $masterData->objQuery->begin(); |
---|
201 | $masterData->deleteMasterData($master_data_name, false); |
---|
202 | // TODO カラム名はメタデータから取得した方が良い |
---|
203 | $masterData->registMasterData($master_data_name, array('id', 'name', 'rank'), $arrTmp, false); |
---|
204 | $masterData->objQuery->commit(); |
---|
205 | |
---|
206 | } |
---|
207 | } |
---|