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

Revision 20538, 9.9 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

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