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

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

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

  • テンプレート設定/追加を修正
  • 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->lfGetMode()) {
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 lfGetMode(){
191        if (isset($_POST['mode'])) return $_POST['mode'];
192    }
193
194    function lfInitRegister() {
195        $objForm = new SC_FormParam();
196        $objForm->addParam(
197            'template_code', 'template_code', STEXT_LEN, '',
198            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
199        );
200        $objForm->setParam($_POST);
201
202        return $objForm;
203    }
204
205    function lfInitDelete() {
206        $objForm = new SC_FormParam();
207        $objForm->addParam(
208            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
209            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
210        );
211        $objForm->setParam($_POST);
212
213        return $objForm;
214    }
215
216    function lfInitDownload() {
217        $objForm = new SC_FormParam();
218        $objForm->addParam(
219            'template_code_temp', 'template_code_temp', STEXT_LEN, '',
220            array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")
221        );
222        $objForm->setParam($_POST);
223
224        return $objForm;
225    }
226
227    /**
228     * 使用するテンプレートをDBへ登録する
229     */
230    function lfRegisterTemplate($template_code, $device_type_id) {
231        $masterData = new SC_DB_MasterData_Ex();
232
233        $defineName = 'TEMPLATE_NAME';
234        switch ($device_type_id) {
235        case DEVICE_TYPE_MOBILE:
236            $defineName = 'MOBILE_' . $defineName;
237            break;
238
239        case DEVICE_TYPE_SMARTPHONE:
240            $defineName = 'SMARTPHONE_' . $defineName;
241            break;
242        case DEVICE_TYPE_PC:
243        default:
244        }
245
246        $data = array($defineName => var_export($template_code, TRUE));
247
248        // DBのデータを更新
249        $masterData->updateMasterData('mtb_constants', array(), $data);
250
251        // キャッシュを生成
252        $masterData->createCache('mtb_constants', array(), true, array('id', 'remarks'));
253    }
254   
255    /**
256     * ブロック位置の更新
257     */
258    function lfChangeBloc($template_code) {
259        $objQuery = new SC_Query();
260        /*
261         * FIXME 各端末に合わせて作成する必要あり
262         * $filepath = USER_TEMPLATE_REALDIR. $template_code. "/sql/update_bloc.sql";
263         */
264       
265        // ブロック位置更新SQLファイル有
266        if(file_exists($filepath)) {
267            if($fp = fopen($filepath, "r")) {
268                $sql = fread($fp, filesize($filepath));
269                fclose($fp);
270            }
271            // 改行、タブを1スペースに変換
272            $sql = preg_replace("/[\r\n\t]/", " " ,$sql);
273            $sql_split = split(";", $sql);
274            foreach($sql_split as $key => $val){
275                if (trim($val) != "") {
276                    $objQuery->query($val);
277                }
278            }
279        }
280    }
281
282    /**
283     * テンプレートパッケージの削除
284     */
285    function lfDeleteTemplate($template_code) {
286        // DB更新
287        $objQuery = new SC_Query();
288        $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code));
289        // テンプレート削除
290        $templates_dir = SMARTY_TEMPLATES_REALDIR. $template_code. "/";
291        SC_Utils_Ex::sfDelFile($templates_dir);
292        // コンパイル削除
293        $templates_c_dir = DATA_REALDIR. "Smarty/templates_c/". $template_code. "/";
294        SC_Utils_Ex::sfDelFile($templates_c_dir);
295        // ユーザーデータ削除
296        $user_dir = USER_TEMPLATE_REALDIR. $template_code. "/";
297        SC_Utils_Ex::sfDelFile($user_dir);
298    }
299
300    function lfGetAllTemplates($device_type_id) {
301        $objQuery = new SC_Query();
302        $arrRet = $objQuery->select('*', 'dtb_templates', "device_type_id = ?", array($device_type_id));
303        if (empty($arrRet)) return array();
304
305        return $arrRet;
306    }
307
308    /*
309     * 関数名:lfGetFileContents()
310     * 引数1 :ファイルパス
311     * 説明 :ファイル読込
312     * 戻り値:無し
313     */
314    function lfGetFileContents($read_file) {
315
316        if(file_exists($read_file)) {
317            $contents = file_get_contents($read_file);
318        } else {
319            $contents = "";
320        }
321
322        return $contents;
323    }
324
325    /**
326     * テンプレート名を返す.
327     */
328    function getTemplateName($device_type_id, $isDefault = false) {
329        switch ($device_type_id) {
330        case DEVICE_TYPE_MOBILE:
331            return $isDefault ? MOBILE_DEFAULT_TEMPLATE_NAME : MOBILE_TEMPLATE_NAME;
332            break;
333
334        case DEVICE_TYPE_SMARTPHONE:
335            return $isDefault ? SMARTPHONE_DEFAULT_TEMPLATE_NAME : SMARTPHONE_TEMPLATE_NAME;
336            break;
337
338        case DEVICE_TYPE_PC:
339        default:
340        }
341        return $isDefault ? DEFAULT_TEMPLATE_NAME : TEMPLATE_NAME;
342    }
343}
344?>
Note: See TracBrowser for help on using the repository browser.