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

Revision 21689, 10.1 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 インスタンスを呼び出す処理を統一

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