/html/data/class/pages/admin/system/LC_Page_Admin_System_Masterdata.php

http://eccubeonazure.codeplex.com · PHP · 207 lines · 91 code · 25 blank · 91 comment · 14 complexity · 39b42099b3d3bcceb5d6a8c853100405 MD5 · raw file

  1. <?php
  2. /*
  3. * This file is part of EC-CUBE
  4. *
  5. * Copyright(c) 2000-2011 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. // {{{ requires
  24. require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
  25. /**
  26. * ????????? ???????.
  27. *
  28. * @package Page
  29. * @author LOCKON CO.,LTD.
  30. * @version $Id$
  31. */
  32. class LC_Page_Admin_System_Masterdata extends LC_Page_Admin_Ex {
  33. // }}}
  34. // {{{ functions
  35. /**
  36. * Page ??????.
  37. *
  38. * @return void
  39. */
  40. function init() {
  41. parent::init();
  42. $this->tpl_mainpage = 'system/masterdata.tpl';
  43. $this->tpl_subno = 'masterdata';
  44. $this->tpl_mainno = 'system';
  45. $this->tpl_maintitle = '??????';
  46. $this->tpl_subtitle = '?????????';
  47. }
  48. /**
  49. * Page ?????.
  50. *
  51. * @return void
  52. */
  53. function process() {
  54. $this->action();
  55. $this->sendResponse();
  56. }
  57. /**
  58. * Page ??????.
  59. *
  60. * @return void
  61. */
  62. function action() {
  63. $this->arrMasterDataName = $this->getMasterDataNames(array("mtb_pref",
  64. "mtb_zip",
  65. "mtb_constants"));
  66. $masterData = new SC_DB_MasterData_Ex();
  67. switch ($this->getMode()) {
  68. case 'edit':
  69. // POST ???????????
  70. $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
  71. $this->errorMessage = $this->checkUniqueID($_POST);
  72. if (empty($this->errorMessage)) {
  73. // ???????????????????
  74. $this->registMasterData($_POST, $masterData, $this->masterDataName);
  75. $this->tpl_onload = "window.alert('??????????????????');";
  76. }
  77. case 'show':
  78. // POST ???????????
  79. $this->masterDataName = $this->checkMasterDataName($_POST, $this->arrMasterDataName);
  80. // DB ????????????
  81. $this->arrMasterData =
  82. $masterData->getDbMasterData($this->masterDataName);
  83. break;
  84. default:
  85. }
  86. }
  87. /**
  88. * ??????.
  89. *
  90. * @return void
  91. */
  92. function destroy() {
  93. parent::destroy();
  94. }
  95. /**
  96. * ???????????????
  97. *
  98. * @access private
  99. * @param array $_POST?
  100. * @param array $arrMasterDataName ????????????????
  101. * @return string $master_data_name ???????????????????
  102. */
  103. function checkMasterDataName(&$arrParams, &$arrMasterDataName) {
  104. if (in_array($arrParams['master_data_name'], $arrMasterDataName)) {
  105. $master_data_name = $arrParams['master_data_name'];
  106. return $master_data_name;
  107. } else {
  108. SC_Utils_Ex::sfDispError("");
  109. }
  110. }
  111. /**
  112. * ????????????????.
  113. *
  114. * @access private
  115. * @param array $ignores ????????????????
  116. * @return array ???????????
  117. */
  118. function getMasterDataNames($ignores = array()) {
  119. $dbFactory = SC_DB_DBFactory_Ex::getInstance();
  120. $arrMasterDataName = $dbFactory->findTableNames("mtb_");
  121. $i = 0;
  122. foreach ($arrMasterDataName as $val) {
  123. foreach ($ignores as $ignore) {
  124. if ($val == $ignore) {
  125. unset($arrMasterDataName[$i]);
  126. }
  127. }
  128. $i++;
  129. }
  130. return $arrMasterDataName;
  131. }
  132. /**
  133. * ID ??????????????.
  134. *
  135. * ??????????????????????????.
  136. *
  137. * @access private
  138. * @return void|string ??????????????????????.
  139. */
  140. function checkUniqueID(&$arrParams) {
  141. $arrId = $arrParams['id'];
  142. for ($i = 0; $i < count($arrId); $i++) {
  143. $id = $arrId[$i];
  144. // ??????
  145. if ($arrId[$i] != "") {
  146. for ($j = $i + 1; $j < count($arrId); $j++) {
  147. if ($id == $arrId[$j]) {
  148. return $id . " ????????????????.";
  149. }
  150. }
  151. }
  152. }
  153. }
  154. /**
  155. * ??????????.
  156. *
  157. * @access private{
  158. * @param array $arrParams $_POST?
  159. * @param object $masterData SC_DB_MasterData_Ex()
  160. * @param string $master_data_name ??????????????????
  161. * @return void
  162. */
  163. function registMasterData($arrParams, &$masterData, $master_data_name) {
  164. $arrTmp = array();
  165. foreach ($arrParams['id'] as $key => $val) {
  166. // ID ????????????
  167. if ($val != "") {
  168. $arrTmp[$val] = $arrParams['name'][$key];
  169. }
  170. }
  171. // ??????????
  172. $masterData->objQuery =& SC_Query_Ex::getSingletonInstance();
  173. $masterData->objQuery->begin();
  174. $masterData->deleteMasterData($master_data_name, false);
  175. // TODO ????????????????????
  176. $masterData->registMasterData($master_data_name,
  177. array('id', 'name', 'rank'),
  178. $arrTmp, false);
  179. $masterData->objQuery->commit();
  180. }
  181. }
  182. ?>