source: branches/version-2_12-multilang/data/class/pages/admin/system/LC_Page_Admin_System_Editdb.php @ 22496

Revision 22496, 7.6 KB checked in by m_uehara, 11 years ago (diff)

#2084 メッセージIDの振り直し

  • 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-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
25require_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 */
34class LC_Page_Admin_System_Editdb 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/editdb.tpl';
47        $this->tpl_subno    = 'editdb';
48        $this->tpl_mainno   = 'system';
49        $this->tpl_maintitle = t('c_System_01');
50        $this->tpl_subtitle = t('LC_Page_Admin_System_Editdb_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        $objFormParam = new SC_FormParam_Ex();
71
72        // パラメーターの初期化
73        $this->initForm($objFormParam, $_POST);
74
75        switch ($this->getMode()) {
76            case 'confirm' :
77                $message = $this->lfDoChange($objFormParam);
78                if (!is_array($message) && $message != '') {
79                    $this->tpl_onload = $message;
80                }
81                break;
82            default:
83                break;
84        }
85
86        //インデックスの現在値を取得
87        $this->arrForm = $this->lfGetIndexList();
88
89    }
90
91    /**
92     * デストラクタ.
93     *
94     * @return void
95     */
96    function destroy() {
97        parent::destroy();
98    }
99
100    /**
101     * フォームパラメーター初期化
102     *
103     * @param object $objFormParam
104     * @param array $arrParams $_POST値
105     * @return void
106     */
107    function initForm(&$objFormParam, &$arrParams) {
108
109        $objFormParam->addParam(t('c_mode_01'), 'mode', INT_LEN, 'n', array('ALPHA_CHECK', 'MAX_LENGTH_CHECK'));
110        $objFormParam->addParam(t('c_Table name_01'), 'table_name');
111        $objFormParam->addParam(t('c_Column name_01'), 'column_name');
112        $objFormParam->addParam(t('c_Index_01'), 'indexflag');
113        $objFormParam->addParam(t('c_Index (after change)_01'), 'indexflag_new');
114        $objFormParam->setParam($arrParams);
115
116    }
117
118    function lfDoChange(&$objFormParam) {
119        $objQuery =& SC_Query_Ex::getSingletonInstance();
120        $arrTarget = $this->lfGetTargetData($objFormParam);
121        $message = '';
122        if (is_array($arrTarget) && count($arrTarget) == 0) {
123            $message = "window.alert('" . t('c_There was no data subject to change._01') . "');";
124            return $message;
125        } elseif (!is_array($arrTarget) && $arrTarget != '') {
126            return $arrTarget; // window.alert が返ってきているはず。
127        }
128
129        // 変更対象の設定変更
130        foreach ($arrTarget as $item) {
131            $index_name = $item['table_name'] . '_' . $item['column_name'] . '_key';
132            $arrField = array('fields' => array($item['column_name'] => array()));
133            if ($item['indexflag_new'] == '1') {
134                $objQuery->createIndex($item['table_name'], $index_name, $arrField);
135            } else {
136                $objQuery->dropIndex($item['table_name'], $index_name);
137            }
138        }
139        $message = "window.alert('" . t('c_The index was successfully changed._01') . "');";
140        return $message;
141    }
142
143    function lfGetTargetData(&$objFormParam) {
144        $objQuery =& SC_Query_Ex::getSingletonInstance();
145        $arrIndexFlag    = $objFormParam->getValue('indexflag');
146        $arrIndexFlagNew = $objFormParam->getValue('indexflag_new');
147        $arrTableName    = $objFormParam->getValue('table_name');
148        $arrColumnName   = $objFormParam->getValue('column_name');
149        $arrTarget = array();
150        $message = '';
151
152        // 変更されている対象を走査
153        for ($i = 1; $i <= count($arrIndexFlag); $i++) {
154            //入力値チェック
155            $param = array('indexflag' => $arrIndexFlag[$i],
156                            'indexflag_new' => $arrIndexFlagNew[$i],
157                            'table_name' => $arrTableName[$i],
158                            'column_name' => $arrColumnName[$i]);
159            $objErr = new SC_CheckError_Ex($param);
160            $objErr->doFunc(array('インデックス(' . $i . ')', 'indexflag', INT_LEN), array('NUM_CHECK'));
161            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
162            $objErr->doFunc(array('インデックス変更後(' . $i . ')', 'indexflag_new', INT_LEN), array('NUM_CHECK'));
163            $objErr->doFunc(array('テーブル名(' . $i . ')', 'table_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
164            $objErr->doFunc(array('カラム名(' . $i . ')', 'column_name', STEXT_LEN), array('GRAPH_CHECK', 'EXIST_CHECK', 'MAX_LENGTH_CHECK'));
165            $arrErr = $objErr->arrErr;
166            if (count($arrErr) != 0) {
167                // 通常の送信ではエラーにならないはずです。
168                $message = "window.alert('" . t('c_Processing was suspended due to there being illegal data._01') . "');";
169                return $message;
170            }
171            if ($param['indexflag'] != $param['indexflag_new']) {
172                // 入力値がデータにある対象テーブルかのチェック
173                if ($objQuery->exists('dtb_index_list', 'table_name = ? and column_name = ?', array($param['table_name'], $param['column_name']))) {
174                    $arrTarget[] = $param;
175                }
176            }
177        }
178        return $arrTarget;
179    }
180
181    /**
182     * インデックス設定を行う一覧を返す関数
183     *
184     * @return void
185     */
186    function lfGetIndexList() {
187        // データベースからインデックス設定一覧を取得する
188        $objQuery =& SC_Query_Ex::getSingletonInstance();
189        $objQuery->setOrder('table_name, column_name');
190        $arrIndexList = $objQuery->select('table_name , column_name , recommend_flg, recommend_comment', 'dtb_index_list');
191
192        $table = '';
193        foreach ($arrIndexList as $key => $arrIndex) {
194            // テーブルに対するインデックス一覧を取得
195            if ($table !== $arrIndex['table_name']) {
196                $table = $arrIndex['table_name'];
197                $arrIndexes = $objQuery->listTableIndexes($table);
198            }
199            // インデックスが設定されているかを取得
200            $idx_name = $table . '_' . $arrIndex['column_name'] . '_key';
201            if (array_search($idx_name, $arrIndexes) === false) {
202                $arrIndexList[$key]['indexflag'] = '';
203            } else {
204                $arrIndexList[$key]['indexflag'] = '1';
205            }
206        }
207        return $arrIndexList;
208    }
209
210}
Note: See TracBrowser for help on using the repository browser.