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