source: branches/version-2_13-dev/data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php @ 22887

Revision 22887, 9.7 KB checked in by dkazuto, 11 years ago (diff)

#2112 テンプレート追加画面のテンプレートコードのエラーメッセージについて

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