source: branches/version-2_13_0/data/class/pages/admin/design/LC_Page_Admin_Design_UpDown.php @ 23126

Revision 23126, 9.6 KB checked in by m_uehara, 11 years ago (diff)

#2348 r23116 - r23125 をマージ

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