source: branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_Up_Down.php @ 19715

Revision 19715, 9.9 KB checked in by nanasess, 13 years ago (diff)

#382(管理画面XHTMLに変更)

  • UI を改善
  • Property svn:eol-style set to LF
  • 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-2010 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_PATH . "pages/admin/LC_Page_Admin.php");
26require_once(DATA_PATH. "module/Tar.php");
27require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php");
28
29/**
30 * テンプレートアップロード のページクラス.
31 *
32 * @package Page
33 * @author LOCKON CO.,LTD.
34 * @version $Id: LC_Page_Admin_Design_Up_Down.php 16582 2007-10-29 03:06:29Z nanasess $
35 */
36class LC_Page_Admin_Design_Up_Down extends LC_Page_Admin {
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_subnavi  = 'design/subnavi.tpl';
50        $this->tpl_subno    = 'up_down';
51        $this->tpl_mainno   = "design";
52        $this->tpl_subtitle = 'テンプレート追加';
53        $this->arrErr  = array();
54        $this->arrForm = array();
55        ini_set("max_execution_time", 300);
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            $objSession = new SC_Session();
78            SC_Utils::sfIsSuccess($objSession);
79            $this->now_template = $this->lfGetNowTemplate();
80           
81            // uniqidをテンプレートへ埋め込み
82            $this->uniqid = $objSession->getUniqId();
83           
84            switch($this->lfGetMode()) {
85           
86            // ダウンロードボタン押下時の処理
87            case 'download':
88                break;
89            // アップロードボタン押下時の処理
90            case 'upload':
91                // 画面遷移の正当性チェック
92                if (!SC_Utils::sfIsValidTransition($objSession)) {
93                    SC_Utils::sfDispError('');
94                }
95                // フォームパラメータ初期化
96                $objForm = $this->lfInitUpload();
97                // エラーチェック
98                if ($arrErr = $this->lfValidateUpload($objForm)) {
99                    $this->arrErr  = $arrErr;
100                    $this->arrForm = $objForm->getFormParamList();
101                    break;
102                }
103                // アップロードファイル初期化
104                $objUpFile = $this->lfInitUploadFile($objForm);
105                // 一時ファイルへ保存
106                $errMsg = $objUpFile->makeTempFile('template_file', false);
107                // 書き込みエラーチェック
108                if(isset($errMsg)) {
109                    $this->arrErr['template_file'] = $errMsg;
110                    $this->arrForm = $objForm->getFormParamList();
111                    break;
112                }
113                $this->lfAddTemplates($objForm, $objUpFile);
114                $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
115                break;
116           
117            // 初回表示
118            default:
119                break;
120            }
121    }
122
123    /**
124     * デストラクタ.
125     *
126     * @return void
127     */
128    function destroy() {
129        parent::destroy();
130    }
131
132    /**
133     * POSTされるmodeパラメータを取得する.
134     *
135     * @param void
136     * @return string modeパラメータ, 無ければnull
137     */
138    function lfGetMode(){
139        if (isset($_POST['mode'])) return $_POST['mode'];
140    }
141    /**
142     * SC_UploadFileクラスの初期化.
143     *
144     * @param object $objForm SC_FormParamのインスタンス
145     * @return object SC_UploadFileのインスタンス
146     */
147    function lfInitUploadFile($objForm) {
148        $pkg_dir = SMARTY_TEMPLATES_DIR . $objForm->getValue('template_code');
149        $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_DIR, $pkg_dir);
150        $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
151   
152        return $objUpFile;
153    }
154    /**
155     * SC_FormParamクラスの初期化.
156     *
157     * @param void
158     * @return object SC_FormParamのインスタンス
159     */
160    function lfInitUpload() {
161        $objForm = new SC_FormParam;
162   
163        $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
164        $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
165        $objForm->setParam($_POST);
166   
167        return $objForm;
168    }
169    /**
170     * uploadモードのパラメータ検証を行う.
171     *
172     * @param object $objForm SC_FormParamのインスタンス
173     * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す
174     */
175    function lfValidateUpload($objForm) {
176        $arrErr = $objForm->checkError();
177        if (!empty($arrErr)) {
178            return $arrErr;
179        }
180   
181        $arrForm = $objForm->getHashArray();
182   
183        // 同名のフォルダが存在する場合はエラー
184        if(file_exists(USER_TEMPLATE_PATH . $arrForm['template_code'])) {
185            $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
186        }
187   
188        // 登録不可の文字列チェック
189        $arrIgnoreCode = array(
190            'admin', 'mobile', 'default'
191        );
192        if(in_array($arrForm['template_code'], $arrIgnoreCode)) {
193            $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>";
194        }
195   
196        // DBにすでに登録されていないかチェック
197        $objQuery = new SC_Query();
198        $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));
199        if(!empty($ret)) {
200            $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
201        }
202   
203        // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
204        $errFlag = true;
205        $array_ext = explode(".", $_FILES['template_file']['name']);
206        $ext = $array_ext[ count ( $array_ext ) - 1 ];
207        $ext = strtolower($ext);
208        // .tarチェック
209        if ($ext == 'tar') {
210            $errFlag = false;
211        }
212        $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
213        $ext = strtolower($ext);
214        // .tar.gzチェック
215        if ($ext== 'tar.gz') {
216            $errFlag = false;
217        }
218   
219        if($errFlag) {
220            $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
221        }
222   
223        return $arrErr;
224    }
225    /**
226     * DBおよびTPL_PKG_PATHにテンプレートパッケージを追加する.
227     *
228     * @param object $objForm SC_FormParamのインスタンス
229     * @param object $objUpFile SC_UploadFileのインスタンス
230     * @return void
231     */
232    function lfAddTemplates($objForm, $objUpFile) {
233        $template_code = $objForm->getValue('template_code');
234        $template_dir = SMARTY_TEMPLATES_DIR . $template_code;
235        $compile_dir  = DATA_PATH . "Smarty/templates_c/" . $template_code;
236        // フォルダ作成
237        if(!file_exists($template_dir)) {
238            mkdir($template_dir);
239        }
240        if(!file_exists($compile_dir)) {
241            mkdir($compile_dir);
242        }
243               
244        // 一時フォルダから保存ディレクトリへ移動
245        $objUpFile->moveTempFile();
246       
247        // 解凍
248        SC_Helper_FileManager::unpackFile($template_dir . "/" . $_FILES['template_file']['name']);
249        // ユーザデータの下のファイルをコピーする
250        $from_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/";     
251        $to_dir = USER_PATH . "packages/" . $template_code . "/";
252        SC_Utils::sfMakeDir($to_dir);
253        SC_Utils::sfCopyDir($from_dir, $to_dir);
254       
255        // DBにテンプレート情報を保存
256        $this->lfRegisterTemplates($objForm->getHashArray());
257    }
258   
259    /**
260     * dtb_templatesへ入力内容を登録する.
261     *
262     * @param array $arrForm POSTされたパラメータ
263     * @return void
264     */
265    function lfRegisterTemplates($arrForm) {
266        $objQuery = new SC_Query();
267        $sqlval = $arrForm;
268        $sqlval['create_date'] = "now()";
269        $sqlval['update_date'] = "now()";
270        $objQuery->insert('dtb_templates', $sqlval);
271    }
272
273    /**
274     * デザイン管理で作成されたファイルをupload/temp_template/以下にコピーする
275     *
276     * @param string $to
277     * @return void
278     */
279    function lfCopyUserEdit($to) {
280        $arrDirs = array(
281            'css',
282            'include',
283            'templates'
284        );
285   
286        foreach ($arrDirs as $dir) {
287            $from = USER_PATH .  $dir;
288            SC_Utils::sfCopyDir($from, $to, '', true);
289        }
290    }
291    /**
292     * 現在選択しているテンプレートパッケージをupload/temp_template/以下にコピーする
293     *
294     * @param string $to 保存先パス
295     * @return void
296     */
297    function lfCopyTplPackage($to) {
298        $nowTpl = $this->lfGetNowTemplate();
299        if (!$nowTpl) return;
300   
301        $from = TPL_PKG_PATH . $nowTpl . '/';
302        SC_Utils::sfCopyDir($from, $to, '');
303    }
304    /**
305     * 現在適用しているテンプレートパッケージ名を取得する.
306     *
307     * @param void
308     * @return string テンプレートパッケージ名
309     */
310    function lfGetNowTemplate() {
311        $objQuery = new SC_Query();
312        $arrRet = $objQuery->select('top_tpl', 'dtb_baseinfo');
313        if (isset($arrRet[0]['top_tpl'])) {
314            return $arrRet[0]['top_tpl'];
315        }
316        return null;
317    }   
318}
319?>
Note: See TracBrowser for help on using the repository browser.