Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_System_Masterdata.php

Documentation is available at LC_Page_Admin_System_Masterdata.php

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

Documentation generated on Fri, 24 Feb 2012 13:59:11 +0900 by Seasoft