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

Revision 20560, 10.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_Template 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/template.tpl';
49        $this->tpl_subnavi  = 'design/subnavi.tpl';
50        $this->tpl_subno    = 'template';
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        $this->tpl_select = $this->getTemplateName($device_type_id);
90
91        $objView = new SC_AdminView_Ex();
92
93        switch($this->getMode()) {
94
95            // 登録ボタン押下時
96        case 'register':
97            // パラメータ検証
98            $objForm = $this->lfInitRegister();
99            if ($objForm->checkError()) {
100                SC_Utils_Ex::sfDispError('');
101            }
102
103            $template_code = $objForm->getValue('template_code');
104            $this->tpl_select = $template_code;
105
106            if($template_code == "") {
107                $template_code = $this->getTemplateName($device_type_id, true);
108            }
109
110            // DBへ使用するテンプレートを登録
111            $this->lfRegisterTemplate($template_code);
112
113            // XXX コンパイルファイルのクリア処理を行う
114            $objView->_smarty->clear_compiled_tpl();
115
116            // ブロック位置を更新
117            $this->lfChangeBloc($template_code);
118
119            // 完了メッセージ
120            $this->tpl_onload="alert('登録が完了しました。');";
121            break;
122
123            // 削除ボタン押下時
124        case 'delete':
125            // パラメータ検証
126            $objForm = $this->lfInitDelete();
127            if ($objForm->checkError()) {
128                SC_Utils_Ex::sfDispError('');
129            }
130
131            //現在使用中のテンプレートとデフォルトのテンプレートは削除できないようにする
132            $template_code = $objForm->getValue('template_code_temp');
133            if ($template_code == $this->getTemplateName($device_type_id)
134                || $template_code == $this->getTemplateName($device_type_id, true)) {
135                $this->tpl_onload = "alert('デフォルトテンプレートと、選択中のテンプレートは削除出来ません');";
136                break;
137            }
138            $this->lfDeleteTemplate($template_code);
139            break;
140
141            // downloadボタン押下時
142        case 'download':
143            // パラメータ検証
144            $objForm = $this->lfInitDownload();
145            $template_code = $objForm->getValue('template_code_temp');
146            // ユーザデータの下のファイルも保存する。
147            $from_dir = USER_TEMPLATE_REALDIR . $template_code . "/";
148            $to_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/";
149            SC_Utils_Ex::sfMakeDir($to_dir);
150            SC_Utils_Ex::sfCopyDir($from_dir, $to_dir);
151            SC_Helper_FileManager_Ex::downloadArchiveFiles(SMARTY_TEMPLATES_REALDIR . $template_code);
152            break;
153
154            // プレビューボタン押下時
155        case 'preview':
156            break;
157
158        default:
159            break;
160        }
161
162        $this->templates = $this->lfGetAllTemplates($device_type_id);
163        $this->now_template = TEMPLATE_NAME;
164        $this->device_type_id = $device_type_id;
165    }
166
167    /**
168     * デストラクタ.
169     *
170     * @return void
171     */
172    function destroy() {
173        parent::destroy();
174    }
175
176    function lfInitRegister() {
177        $objForm = new SC_FormParam_Ex();
178        $objForm->addParam(
179            'template_code', 'template_code', STEXT_LEN, '',
180            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
181        );
182        $objForm->setParam($_POST);
183
184        return $objForm;
185    }
186
187    function lfInitDelete() {
188        $objForm = new SC_FormParam_Ex();
189        $objForm->addParam(
190            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
191            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
192        );
193        $objForm->setParam($_POST);
194
195        return $objForm;
196    }
197
198    function lfInitDownload() {
199        $objForm = new SC_FormParam_Ex();
200        $objForm->addParam(
201            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
202            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
203        );
204        $objForm->setParam($_POST);
205
206        return $objForm;
207    }
208
209    /**
210     * 使用するテンプレートをDBへ登録する
211     */
212    function lfRegisterTemplate($template_code, $device_type_id) {
213        $masterData = new SC_DB_MasterData_Ex();
214
215        $defineName = 'TEMPLATE_NAME';
216        switch ($device_type_id) {
217        case DEVICE_TYPE_MOBILE:
218            $defineName = 'MOBILE_' . $defineName;
219            break;
220
221        case DEVICE_TYPE_SMARTPHONE:
222            $defineName = 'SMARTPHONE_' . $defineName;
223            break;
224        case DEVICE_TYPE_PC:
225        default:
226        }
227
228        $data = array($defineName => var_export($template_code, TRUE));
229
230        // DBのデータを更新
231        $masterData->updateMasterData('mtb_constants', array(), $data);
232
233        // キャッシュを生成
234        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
235    }
236
237    /**
238     * ブロック位置の更新
239     */
240    function lfChangeBloc($template_code) {
241        $objQuery = new SC_Query_Ex();
242        /*
243         * FIXME 各端末に合わせて作成する必要あり
244         * $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql";
245         */
246
247        // ブロック位置更新SQLファイル有
248        if(file_exists($filepath)) {
249            if($fp = fopen($filepath, 'r')) {
250                $sql = fread($fp, filesize($filepath));
251                fclose($fp);
252            }
253            // 改行、タブを1スペースに変換
254            $sql = preg_replace("/[\r\n\t]/", " " ,$sql);
255            $sql_split = explode(";", $sql);
256            foreach($sql_split as $key => $val){
257                if (trim($val) != "") {
258                    $objQuery->query($val);
259                }
260            }
261        }
262    }
263
264    /**
265     * テンプレートパッケージの削除
266     */
267    function lfDeleteTemplate($template_code) {
268        // DB更新
269        $objQuery = new SC_Query_Ex();
270        $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code));
271        // テンプレート削除
272        $templates_dir = SMARTY_TEMPLATES_REALDIR. $template_code. "/";
273        SC_Utils_Ex::sfDelFile($templates_dir);
274        // コンパイル削除
275        $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/";
276        SC_Utils_Ex::sfDelFile($templates_c_dir);
277        // ユーザーデータ削除
278        $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/";
279        SC_Utils_Ex::sfDelFile($user_dir);
280    }
281
282    function lfGetAllTemplates($device_type_id) {
283        $objQuery = new SC_Query_Ex();
284        $arrRet = $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id));
285        if (empty($arrRet)) return array();
286
287        return $arrRet;
288    }
289
290    /*
291     * 関数名:lfGetFileContents()
292     * 引数1 :ファイルパス
293     * 説明 :ファイル読込
294     * 戻り値:無し
295     */
296    function lfGetFileContents($read_file) {
297
298        if(file_exists($read_file)) {
299            $contents = file_get_contents($read_file);
300        } else {
301            $contents = "";
302        }
303
304        return $contents;
305    }
306
307    /**
308     * テンプレート名を返す.
309     */
310    function getTemplateName($device_type_id, $isDefault = false) {
311        switch ($device_type_id) {
312        case DEVICE_TYPE_MOBILE:
313            return $isDefault ? MOBILE_DEFAULT_TEMPLATE_NAME : MOBILE_TEMPLATE_NAME;
314            break;
315
316        case DEVICE_TYPE_SMARTPHONE:
317            return $isDefault ? SMARTPHONE_DEFAULT_TEMPLATE_NAME : SMARTPHONE_TEMPLATE_NAME;
318            break;
319
320        case DEVICE_TYPE_PC:
321        default:
322        }
323        return $isDefault ? DEFAULT_TEMPLATE_NAME : TEMPLATE_NAME;
324    }
325}
326?>
Note: See TracBrowser for help on using the repository browser.