source: branches/version-2_12-multilang/data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php @ 22505

Revision 22505, 9.5 KB checked in by kim, 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_Design_UpDown 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 = 'design/up_down.tpl';
47        $this->tpl_subno    = 'up_down';
48        $this->tpl_mainno   = 'design';
49        $this->tpl_maintitle = t('c_Design_01');
50        $this->tpl_subtitle = t('c_Template addition_01');
51        $this->arrErr  = array();
52        $this->arrForm = array();
53        ini_set('max_execution_time', 300);
54        $masterData = new SC_DB_MasterData_Ex();
55        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
63    function process() {
64        $this->action();
65        $this->sendResponse();
66    }
67
68    /**
69     * Page のアクション.
70     *
71     * FIXME ロジックを見直し
72     *
73     * @return void
74     */
75    function action() {
76
77        $objFormParam = new SC_FormParam_Ex();
78        $this->lfInitParam($objFormParam);
79        $objFormParam->setParam($_REQUEST);
80        $objFormParam->convParam();
81
82        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
83
84        switch ($this->getMode()) {
85            // アップロードボタン押下時の処理
86            case 'upload':
87                $objUpFile = $this->lfInitUploadFile($objFormParam);
88                $this->arrErr = $this->lfCheckError($objFormParam, $objUpFile);
89                if (SC_Utils_Ex::isBlank($this->arrErr)) {
90                    if ($this->doUpload($objFormParam, $objUpFile)) {
91                        $this->tpl_onload = "alert('" . t('c_The template file was uploaded._01') . "');";
92                        $objFormParam->setValue('template_name', '');
93                        $objFormParam->setValue('template_code', '');
94                    }
95                }
96                break;
97
98            default:
99                break;
100        }
101        //サブタイトルの追加
102        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . ' > ' . $this->tpl_subtitle;
103        $this->arrForm = $objFormParam->getFormParamList();
104
105    }
106
107    /**
108     * デストラクタ.
109     *
110     * @return void
111     */
112    function destroy() {
113        parent::destroy();
114    }
115
116    /**
117     * SC_UploadFileクラスの初期化.
118     *
119     * @param object $objForm SC_FormParamのインスタンス
120     * @return object SC_UploadFileのインスタンス
121     */
122    function lfInitUploadFile($objForm) {
123        $pkg_dir = SMARTY_TEMPLATES_REALDIR . $objForm->getValue('template_code');
124        $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $pkg_dir);
125        $objUpFile->addFile(t('c_Template file_01'), 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
126        return $objUpFile;
127    }
128
129    /**
130     * SC_FormParamクラスの初期化.
131     *
132     * @param SC_FormParam $objFormParam SC_FormParamのインスタンス
133     * @return void
134     */
135    function lfInitParam(&$objFormParam) {
136        $objFormParam->addParam(t('c_Template code_01'), 'template_code', STEXT_LEN, 'a', array('EXIST_CHECK', 'SPTAB_CHECK','MAX_LENGTH_CHECK', 'ALNUM_CHECK'));
137        $objFormParam->addParam(t('c_Template name_01'), 'template_name', STEXT_LEN, 'KVa', array('EXIST_CHECK', 'SPTAB_CHECK','MAX_LENGTH_CHECK'));
138        $objFormParam->addParam(t('c_Terminal type ID_01'), 'device_type_id', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
139    }
140
141    /**
142     * uploadモードのパラメーター検証を行う.
143     *
144     * @param object $objFormParam SC_FormParamのインスタンス
145     * @param object $objUpFile SC_UploadFileのインスタンス
146     * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す
147     */
148    function lfCheckError(&$objFormParam, &$objUpFile) {
149        $arrErr = $objFormParam->checkError();
150        $template_code = $objFormParam->getValue('template_code');
151
152        // 同名のフォルダが存在する場合はエラー
153        if (file_exists(USER_TEMPLATE_REALDIR . $template_code)) {
154            $arrErr['template_code'] = t('c_* A file with the same name already exists.<br/>_01');
155        }
156
157        // 登録不可の文字列チェック
158        $arrIgnoreCode = array('admin',
159                               MOBILE_DEFAULT_TEMPLATE_NAME,
160                               SMARTPHONE_DEFAULT_TEMPLATE_NAME,
161                               DEFAULT_TEMPLATE_NAME);
162        if (in_array($template_code, $arrIgnoreCode)) {
163            $arrErr['template_code'] = t('c_* This template code cannot be used.<br/>_01');
164        }
165
166        // DBにすでに登録されていないかチェック
167        $objQuery =& SC_Query_Ex::getSingletonInstance();
168        $exists = $objQuery->exists('dtb_templates', 'template_code = ?', array($template_code));
169        if ($exists) {
170            $arrErr['template_code'] = t('c_* This template code is already registered.<br/>_01');
171        }
172
173        /*
174         * ファイル形式チェック
175         * ファイルが壊れていることも考慮して, 展開可能かチェックする.
176         */
177        $tar = new Archive_Tar($_FILES['template_file']['tmp_name'], true);
178        $arrArchive = $tar->listContent();
179        if (!is_array($arrArchive)) {
180            $arrErr['template_file'] = t('c_* The template file could not be decompressed. The permissible formats are tar/tar.gz.<br />_01');
181        } else {
182            $make_temp_error = $objUpFile->makeTempFile('template_file', false);
183            if (!SC_Utils_Ex::isBlank($make_temp_error)) {
184                $arrErr['template_file'] = $make_temp_error;
185            }
186        }
187        return $arrErr;
188    }
189
190    /**
191     * DBおよびファイルシステムにテンプレートパッケージを追加する.
192     *
193     * エラーが発生した場合は, エラーを出力し, false を返す.
194     *
195     * @param object $objFormParam SC_FormParamのインスタンス
196     * @param object $objUpFile SC_UploadFileのインスタンス
197     * @return boolean 成功した場合 true; 失敗した場合 false
198     */
199    function doUpload($objFormParam, $objUpFile) {
200        $template_code = $objFormParam->getValue('template_code');
201        $template_name = $objFormParam->getValue('template_name');
202        $device_type_id = $objFormParam->getValue('device_type_id');
203
204        $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code;
205        $compile_dir  = DATA_REALDIR . 'Smarty/templates_c/' . $template_code;
206
207        $objQuery =& SC_Query_Ex::getSingletonInstance();
208        $objQuery->begin();
209
210        $arrValues = array(
211            'template_code' => $template_code,
212            'device_type_id' => $device_type_id,
213            'template_name' => $template_name,
214            'create_date' => 'CURRENT_TIMESTAMP',
215            'update_date' => 'CURRENT_TIMESTAMP',
216        );
217        $objQuery->insert('dtb_templates', $arrValues);
218
219        $is_error = false;
220        // フォルダ作成
221        if (!file_exists($template_dir)) {
222            if (!mkdir($template_dir)) {
223                $this->arrErr['err'] = t('c_* The template folder could not be created.<br/>_01');
224                $objQuery->rollback();
225                return false;
226            }
227        }
228        if (!file_exists($compile_dir)) {
229            if (!mkdir($compile_dir)) {
230                $this->arrErr['err'] = t('c_* Smarty compile folder could not be created.<br/>_01');
231                $objQuery->rollback();
232                return false;
233            }
234        }
235
236        // 一時フォルダから保存ディレクトリへ移動
237        $objUpFile->moveTempFile();
238
239        // 解凍
240        if (!SC_Helper_FileManager_Ex::unpackFile($template_dir . '/' . $_FILES['template_file']['name'])) {
241            $this->arrErr['err'] = t('c_* Decompression of the template file failed.<br/>_01');
242            $objQuery->rollback();
243            return false;
244        }
245        // ユーザデータの下のファイルをコピーする
246        $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . '/_packages/';
247        $to_dir = USER_REALDIR . 'packages/' . $template_code . '/';
248        if (!SC_Utils_Ex::recursiveMkdir($to_dir)) {
249            $this->arrErr['err'] = t('c_* T_ARG1 creation failed.<br/>_01', array('T_ARG1' => $to_dir));
250           
251            $objQuery->rollback();
252            return false;
253        }
254        SC_Utils_Ex::sfCopyDir($from_dir, $to_dir);
255
256        $objQuery->commit();
257        return true;
258    }
259}
Note: See TracBrowser for help on using the repository browser.