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

Revision 20116, 9.4 KB checked in by nanasess, 13 years ago (diff)
  • svn properties を再設定
  • 再設定用のスクリプト追加
  • 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-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_REALDIR . "pages/admin/LC_Page_Admin.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_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
80        // 端末種別IDを取得
81        if (isset($_REQUEST['device_type_id'])
82            && is_numeric($_REQUEST['device_type_id'])) {
83            $device_type_id = $_REQUEST['device_type_id'];
84        } else {
85            $device_type_id = DEVICE_TYPE_PC;
86        }
87
88
89        // uniqidをテンプレートへ埋め込み
90        $this->uniqid = $objSession->getUniqId();
91
92        switch($this->getMode()) {
93
94            // ダウンロードボタン押下時の処理
95        case 'download':
96            break;
97            // アップロードボタン押下時の処理
98        case 'upload':
99            // 画面遷移の正当性チェック
100            if (!SC_Utils::sfIsValidTransition($objSession)) {
101                SC_Utils::sfDispError('');
102            }
103            // フォームパラメータ初期化
104            $objForm = $this->lfInitUpload();
105            // エラーチェック
106            if ($arrErr = $this->lfValidateUpload($objForm)) {
107                $this->arrErr  = $arrErr;
108                $this->arrForm = $objForm->getFormParamList();
109                break;
110            }
111            // アップロードファイル初期化
112            $objUpFile = $this->lfInitUploadFile($objForm);
113            // 一時ファイルへ保存
114            $errMsg = $objUpFile->makeTempFile('template_file', false);
115            // 書き込みエラーチェック
116            if(isset($errMsg)) {
117                $this->arrErr['template_file'] = $errMsg;
118                $this->arrForm = $objForm->getFormParamList();
119                break;
120            }
121            $this->lfAddTemplates($objForm, $objUpFile, $device_type_id);
122            $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
123            break;
124
125            // 初回表示
126        default:
127            break;
128        }
129        $this->device_type_id = $device_type_id;
130    }
131
132    /**
133     * デストラクタ.
134     *
135     * @return void
136     */
137    function destroy() {
138        parent::destroy();
139    }
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_REALDIR . $objForm->getValue('template_code');
149        $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_REALDIR, $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_REALDIR . $arrForm['template_code'])) {
185            $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
186        }
187
188        // 登録不可の文字列チェック
189        $arrIgnoreCode = array('admin',
190                               MOBILE_DEFAULT_TEMPLATE_NAME,
191                               SMARTPHONE_DEFAULT_TEMPLATE_NAME,
192                               DEFAULT_TEMPLATE_NAME);
193        if(in_array($arrForm['template_code'], $arrIgnoreCode)) {
194            $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>";
195        }
196
197        // DBにすでに登録されていないかチェック
198        $objQuery = new SC_Query();
199        $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));
200        if(!empty($ret)) {
201            $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
202        }
203
204        // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
205        $errFlag = true;
206        $array_ext = explode(".", $_FILES['template_file']['name']);
207        $ext = $array_ext[ count ( $array_ext ) - 1 ];
208        $ext = strtolower($ext);
209        // .tarチェック
210        if ($ext == 'tar') {
211            $errFlag = false;
212        }
213        $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
214        $ext = strtolower($ext);
215        // .tar.gzチェック
216        if ($ext== 'tar.gz') {
217            $errFlag = false;
218        }
219
220        if($errFlag) {
221            $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
222        }
223
224        return $arrErr;
225    }
226    /**
227     * DBおよびファイルシステムにテンプレートパッケージを追加する.
228     *
229     * @param object $objForm SC_FormParamのインスタンス
230     * @param object $objUpFile SC_UploadFileのインスタンス
231     * @return void
232     */
233    function lfAddTemplates($objForm, $objUpFile, $device_type_id) {
234        $template_code = $objForm->getValue('template_code');
235        $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code;
236        $compile_dir  = DATA_REALDIR . "Smarty/templates_c/" . $template_code;
237        // フォルダ作成
238        if(!file_exists($template_dir)) {
239            mkdir($template_dir);
240        }
241        if(!file_exists($compile_dir)) {
242            mkdir($compile_dir);
243        }
244
245        // 一時フォルダから保存ディレクトリへ移動
246        $objUpFile->moveTempFile();
247
248        // 解凍
249        SC_Helper_FileManager::unpackFile($template_dir . "/" . $_FILES['template_file']['name']);
250        // ユーザデータの下のファイルをコピーする
251        $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
252        $to_dir = USER_REALDIR . "packages/" . $template_code . "/";
253        SC_Utils::sfMakeDir($to_dir);
254        SC_Utils::sfCopyDir($from_dir, $to_dir);
255
256        // DBにテンプレート情報を保存
257        $this->lfRegisterTemplates($objForm->getHashArray(), $device_type_id);
258    }
259
260    /**
261     * dtb_templatesへ入力内容を登録する.
262     *
263     * @param array $arrForm POSTされたパラメータ
264     * @return void
265     */
266    function lfRegisterTemplates($arrForm, $device_type_id) {
267        $objQuery = new SC_Query();
268        $sqlval = $arrForm;
269        $sqlval['device_type_id'] = $device_type_id;
270        $sqlval['create_date'] = "now()";
271        $sqlval['update_date'] = "now()";
272        $objQuery->insert('dtb_templates', $sqlval);
273    }
274}
275?>
Note: See TracBrowser for help on using the repository browser.