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

Revision 22567, 9.7 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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