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

Revision 22857, 9.6 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

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