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

Revision 21402, 9.8 KB checked in by Seasoft, 12 years ago (diff)

2.12系へマイルストーン変更となったチケット分を差し戻し
r21376 #1582,#1526,#1449 作業を簡単にするため、本来対象外のチケット(#1526,#1449)も含めた
r21375 #1581
r21374 #797
r21373 #1583,#1526 作業を簡単にするため、本来対象外のチケット(#1526)も含めた
r21372 #1576
r21371 #1581

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