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

Revision 19966, 9.7 KB checked in by nanasess, 13 years ago (diff)

#748(モバイル/スマートフォンのデザイン管理)

  • テンプレート設定/追加を修正
  • Property svn:eol-style set to LF
  • 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 *
[18701]5 * Copyright(c) 2000-2010 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
24// {{{ requires
[19805]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");
[16677]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 */
[19661]36class LC_Page_Admin_Design_Up_Down extends LC_Page_Admin {
[16677]37
38    // }}}
39    // {{{ functions
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init() {
47        parent::init();
[19966]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);
[16677]56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
[18233]63    function process() {
[19661]64        $this->action();
65        $this->sendResponse();
66    }
67
68    /**
69     * Page のアクション.
70     *
[19713]71     * FIXME ロジックを見直し
72     *
[19661]73     * @return void
74     */
75    function action() {
76        // ログインチェック
[19966]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->lfGetMode()) {
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;
[16677]130    }
131
132    /**
133     * デストラクタ.
134     *
135     * @return void
136     */
137    function destroy() {
138        parent::destroy();
139    }
140
[19966]141    /**
142     * POSTされるmodeパラメータを取得する.
143     *
144     * @param void
145     * @return string modeパラメータ, 無ければnull
146     */
147    function lfGetMode(){
148        if (isset($_POST['mode'])) return $_POST['mode'];
149    }
150    /**
151     * SC_UploadFileクラスの初期化.
152     *
153     * @param object $objForm SC_FormParamのインスタンス
154     * @return object SC_UploadFileのインスタンス
155     */
156    function lfInitUploadFile($objForm) {
157        $pkg_dir = SMARTY_TEMPLATES_REALDIR . $objForm->getValue('template_code');
158        $objUpFile = new SC_UploadFile(TEMPLATE_TEMP_REALDIR, $pkg_dir);
159        $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
160
161        return $objUpFile;
162    }
163    /**
164     * SC_FormParamクラスの初期化.
165     *
166     * @param void
167     * @return object SC_FormParamのインスタンス
168     */
169    function lfInitUpload() {
170        $objForm = new SC_FormParam;
171
172        $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
173        $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, "KVa", array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
174        $objForm->setParam($_POST);
175
176        return $objForm;
177    }
178    /**
179     * uploadモードのパラメータ検証を行う.
180     *
181     * @param object $objForm SC_FormParamのインスタンス
182     * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す
183     */
184    function lfValidateUpload($objForm) {
185        $arrErr = $objForm->checkError();
186        if (!empty($arrErr)) {
187            return $arrErr;
188        }
189
190        $arrForm = $objForm->getHashArray();
191
192        // 同名のフォルダが存在する場合はエラー
193        if(file_exists(USER_TEMPLATE_REALDIR . $arrForm['template_code'])) {
194            $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
195        }
196
197        // 登録不可の文字列チェック
198        $arrIgnoreCode = array('admin',
199                               MOBILE_DEFAULT_TEMPLATE_NAME,
200                               SMARTPHONE_DEFAULT_TEMPLATE_NAME,
201                               DEFAULT_TEMPLATE_NAME);
202        if(in_array($arrForm['template_code'], $arrIgnoreCode)) {
203            $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>";
204        }
205
206        // DBにすでに登録されていないかチェック
207        $objQuery = new SC_Query();
208        $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));
209        if(!empty($ret)) {
210            $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
211        }
212
213        // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
214        $errFlag = true;
215        $array_ext = explode(".", $_FILES['template_file']['name']);
216        $ext = $array_ext[ count ( $array_ext ) - 1 ];
217        $ext = strtolower($ext);
218        // .tarチェック
219        if ($ext == 'tar') {
220            $errFlag = false;
221        }
222        $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
223        $ext = strtolower($ext);
224        // .tar.gzチェック
225        if ($ext== 'tar.gz') {
226            $errFlag = false;
227        }
228
229        if($errFlag) {
230            $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
231        }
232
233        return $arrErr;
234    }
235    /**
236     * DBおよびTPL_PKG_PATHにテンプレートパッケージを追加する.
237     *
238     * @param object $objForm SC_FormParamのインスタンス
239     * @param object $objUpFile SC_UploadFileのインスタンス
240     * @return void
241     */
242    function lfAddTemplates($objForm, $objUpFile, $device_type_id) {
243        $template_code = $objForm->getValue('template_code');
244        $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code;
245        $compile_dir  = DATA_REALDIR . "Smarty/templates_c/" . $template_code;
246        // フォルダ作成
247        if(!file_exists($template_dir)) {
248            mkdir($template_dir);
249        }
250        if(!file_exists($compile_dir)) {
251            mkdir($compile_dir);
252        }
253
254        // 一時フォルダから保存ディレクトリへ移動
255        $objUpFile->moveTempFile();
256
257        // 解凍
258        SC_Helper_FileManager::unpackFile($template_dir . "/" . $_FILES['template_file']['name']);
259        // ユーザデータの下のファイルをコピーする
260        $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
261        $to_dir = USER_REALDIR . "packages/" . $template_code . "/";
262        SC_Utils::sfMakeDir($to_dir);
[18233]263        SC_Utils::sfCopyDir($from_dir, $to_dir);
[19966]264
265        // DBにテンプレート情報を保存
266        $this->lfRegisterTemplates($objForm->getHashArray(), $device_type_id);
267    }
268
269    /**
270     * dtb_templatesへ入力内容を登録する.
271     *
272     * @param array $arrForm POSTされたパラメータ
273     * @return void
274     */
275    function lfRegisterTemplates($arrForm, $device_type_id) {
[18233]276        $objQuery = new SC_Query();
277        $sqlval = $arrForm;
[19966]278        $sqlval['device_type_id'] = $device_type_id;
[18233]279        $sqlval['create_date'] = "now()";
280        $sqlval['update_date'] = "now()";
281        $objQuery->insert('dtb_templates', $sqlval);
[19966]282    }
[16677]283}
284?>
Note: See TracBrowser for help on using the repository browser.