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

Revision 20041, 10.6 KB checked in by eccuore, 13 years ago (diff)

#642(共通ロジックの機能向上) mode 取得用の関数を利用するように修正(switchリファクタリングは未対応)

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