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

Revision 20560, 9.2 KB checked in by t_yuo, 13 years ago (diff)

#948 (コンテンツ管理>CSV出力設定、デザイン管理 サブタイトルが欲しい)

  • デザイン管理に対応しました。
  • 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_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_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        $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        // 端末種別IDを取得
79        if (isset($_REQUEST['device_type_id'])
80            && is_numeric($_REQUEST['device_type_id'])) {
81            $device_type_id = $_REQUEST['device_type_id'];
82        } else {
83            $device_type_id = DEVICE_TYPE_PC;
84        }
85
86        //サブタイトルの追加
87        $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id];
88
89        switch($this->getMode()) {
90
91            // ダウンロードボタン押下時の処理
92        case 'download':
93            break;
94            // アップロードボタン押下時の処理
95        case 'upload':
96            // フォームパラメータ初期化
97            $objForm = $this->lfInitUpload();
98            // エラーチェック
99            if ($arrErr = $this->lfValidateUpload($objForm)) {
100                $this->arrErr  = $arrErr;
101                $this->arrForm = $objForm->getFormParamList();
102                break;
103            }
104            // アップロードファイル初期化
105            $objUpFile = $this->lfInitUploadFile($objForm);
106            // 一時ファイルへ保存
107            $errMsg = $objUpFile->makeTempFile('template_file', false);
108            // 書き込みエラーチェック
109            if(isset($errMsg)) {
110                $this->arrErr['template_file'] = $errMsg;
111                $this->arrForm = $objForm->getFormParamList();
112                break;
113            }
114            $this->lfAddTemplates($objForm, $objUpFile, $device_type_id);
115            $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');";
116            break;
117
118            // 初回表示
119        default:
120            break;
121        }
122        $this->device_type_id = $device_type_id;
123    }
124
125    /**
126     * デストラクタ.
127     *
128     * @return void
129     */
130    function destroy() {
131        parent::destroy();
132    }
133
134    /**
135     * SC_UploadFileクラスの初期化.
136     *
137     * @param object $objForm SC_FormParamのインスタンス
138     * @return object SC_UploadFileのインスタンス
139     */
140    function lfInitUploadFile($objForm) {
141        $pkg_dir = SMARTY_TEMPLATES_REALDIR . $objForm->getValue('template_code');
142        $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $pkg_dir);
143        $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false);
144
145        return $objUpFile;
146    }
147    /**
148     * SC_FormParamクラスの初期化.
149     *
150     * @param void
151     * @return object SC_FormParamのインスタンス
152     */
153    function lfInitUpload() {
154        $objForm = new SC_FormParam;
155
156        $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK"));
157        $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK"));
158        $objForm->setParam($_POST);
159
160        return $objForm;
161    }
162    /**
163     * uploadモードのパラメータ検証を行う.
164     *
165     * @param object $objForm SC_FormParamのインスタンス
166     * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す
167     */
168    function lfValidateUpload($objForm) {
169        $arrErr = $objForm->checkError();
170        if (!empty($arrErr)) {
171            return $arrErr;
172        }
173
174        $arrForm = $objForm->getHashArray();
175
176        // 同名のフォルダが存在する場合はエラー
177        if(file_exists(USER_TEMPLATE_REALDIR . $arrForm['template_code'])) {
178            $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>";
179        }
180
181        // 登録不可の文字列チェック
182        $arrIgnoreCode = array('admin',
183                               MOBILE_DEFAULT_TEMPLATE_NAME,
184                               SMARTPHONE_DEFAULT_TEMPLATE_NAME,
185                               DEFAULT_TEMPLATE_NAME);
186        if(in_array($arrForm['template_code'], $arrIgnoreCode)) {
187            $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>";
188        }
189
190        // DBにすでに登録されていないかチェック
191        $objQuery = new SC_Query_Ex();
192        $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code']));
193        if(!empty($ret)) {
194            $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>";
195        }
196
197        // ファイルの拡張子チェック(.tar/tar.gzのみ許可)
198        $errFlag = true;
199        $array_ext = explode(".", $_FILES['template_file']['name']);
200        $ext = $array_ext[ count ( $array_ext ) - 1 ];
201        $ext = strtolower($ext);
202        // .tarチェック
203        if ($ext == 'tar') {
204            $errFlag = false;
205        }
206        $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext;
207        $ext = strtolower($ext);
208        // .tar.gzチェック
209        if ($ext== 'tar.gz') {
210            $errFlag = false;
211        }
212
213        if($errFlag) {
214            $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />";
215        }
216
217        return $arrErr;
218    }
219    /**
220     * DBおよびファイルシステムにテンプレートパッケージを追加する.
221     *
222     * @param object $objForm SC_FormParamのインスタンス
223     * @param object $objUpFile SC_UploadFileのインスタンス
224     * @return void
225     */
226    function lfAddTemplates($objForm, $objUpFile, $device_type_id) {
227        $template_code = $objForm->getValue('template_code');
228        $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code;
229        $compile_dir  = DATA_REALDIR . "Smarty/templates_c/" . $template_code;
230        // フォルダ作成
231        if(!file_exists($template_dir)) {
232            mkdir($template_dir);
233        }
234        if(!file_exists($compile_dir)) {
235            mkdir($compile_dir);
236        }
237
238        // 一時フォルダから保存ディレクトリへ移動
239        $objUpFile->moveTempFile();
240
241        // 解凍
242        SC_Helper_FileManager_Ex::unpackFile($template_dir . "/" . $_FILES['template_file']['name']);
243        // ユーザデータの下のファイルをコピーする
244        $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
245        $to_dir = USER_REALDIR . "packages/" . $template_code . "/";
246        SC_Utils_Ex::sfMakeDir($to_dir);
247        SC_Utils_Ex::sfCopyDir($from_dir, $to_dir);
248
249        // DBにテンプレート情報を保存
250        $this->lfRegisterTemplates($objForm->getHashArray(), $device_type_id);
251    }
252
253    /**
254     * dtb_templatesへ入力内容を登録する.
255     *
256     * @param array $arrForm POSTされたパラメータ
257     * @return void
258     */
259    function lfRegisterTemplates($arrForm, $device_type_id) {
260        $objQuery = new SC_Query_Ex();
261        $sqlval = $arrForm;
262        $sqlval['device_type_id'] = $device_type_id;
263        $sqlval['create_date'] = "now()";
264        $sqlval['update_date'] = "now()";
265        $objQuery->insert('dtb_templates', $sqlval);
266    }
267}
268?>
Note: See TracBrowser for help on using the repository browser.