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 |
---|
25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | |
---|
27 | /** |
---|
28 | * ヘッダ, フッタ編集 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Design_Header extends LC_Page_Admin_Ex { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'design/header.tpl'; |
---|
47 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
48 | $this->header_row = 13; |
---|
49 | $this->footer_row = 13; |
---|
50 | $this->tpl_subno = 'header'; |
---|
51 | $this->tpl_mainno = 'design'; |
---|
52 | $this->tpl_subtitle = 'ヘッダー/フッター設定'; |
---|
53 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Page のプロセス. |
---|
57 | * |
---|
58 | * @return void |
---|
59 | */ |
---|
60 | function process() { |
---|
61 | $this->action(); |
---|
62 | $this->sendResponse(); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Page のアクション. |
---|
67 | * |
---|
68 | * FIXME テンプレートの取得方法を要修正 |
---|
69 | * |
---|
70 | * @return void |
---|
71 | */ |
---|
72 | function action() { |
---|
73 | // 端末種別IDを取得 |
---|
74 | if (isset($_REQUEST['device_type_id']) |
---|
75 | && is_numeric($_REQUEST['device_type_id'])) { |
---|
76 | $device_type_id = $_REQUEST['device_type_id']; |
---|
77 | } else { |
---|
78 | $device_type_id = DEVICE_TYPE_PC; |
---|
79 | } |
---|
80 | $this->device_type_id = $device_type_id; |
---|
81 | |
---|
82 | // テンプレートのパス |
---|
83 | $template_path = $this->lfGetTemplatePath($device_type_id); |
---|
84 | $preview_template_path = $this->lfGetPreviewTemplatePath(); |
---|
85 | |
---|
86 | // データ更新処理 |
---|
87 | if (isset($_POST['division']) && $_POST['division'] != '') { |
---|
88 | $division = $_POST['division']; |
---|
89 | $content = $_POST[$division]; // TODO no checked? |
---|
90 | // プレビュー用のテンプレートに書き込む |
---|
91 | $preview_template = $preview_template_path.'/'.$division.'.tpl'; |
---|
92 | $this->lfUpdateTemplate($preview_template, $content); |
---|
93 | |
---|
94 | switch ($this->getMode()) { |
---|
95 | case 'regist': |
---|
96 | // 正規のテンプレートに書き込む |
---|
97 | $template = $template_path . '/' . $division . '.tpl'; |
---|
98 | $this->lfUpdateTemplate($template, $content); |
---|
99 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
100 | break; |
---|
101 | case 'preview': |
---|
102 | if ($division == 'header') $this->header_prev = 'on'; |
---|
103 | if ($division == 'footer') $this->footer_prev = 'on'; |
---|
104 | $this->header_row = isset($_POST['header_row']) ? $_POST['header_row'] : $this->header_row; |
---|
105 | $this->footer_row = isset($_POST['footer_row']) ? $_POST['footer_row'] : $this->footer_row; |
---|
106 | break; |
---|
107 | default: |
---|
108 | // なにもしない |
---|
109 | break; |
---|
110 | } |
---|
111 | }else{ |
---|
112 | // postでデータが渡されなければ新規読み込みと判断をし、 |
---|
113 | // プレビュー用テンプレートに正規のテンプレートをロードする |
---|
114 | $templates = array( |
---|
115 | 'header.tpl', |
---|
116 | 'footer.tpl' |
---|
117 | ); |
---|
118 | $this->lfLoadPreviewTemplates($preview_template_path, $template_path, $templates); |
---|
119 | } |
---|
120 | |
---|
121 | // テキストエリアに表示 |
---|
122 | $this->header_data = file_get_contents($preview_template_path . '/header.tpl'); |
---|
123 | $this->footer_data = file_get_contents($preview_template_path . '/footer.tpl'); |
---|
124 | |
---|
125 | // ブラウザタイプ |
---|
126 | $this->browser_type = isset($_POST['browser_type']) ? $_POST['browser_type'] : ""; |
---|
127 | } |
---|
128 | |
---|
129 | protected function lfLoadPreviewTemplates($preview_template_path, $template_path, $templates) { |
---|
130 | if (!is_dir($preview_template_path)) { |
---|
131 | mkdir($preview_template_path); |
---|
132 | } |
---|
133 | foreach($templates as $template) { |
---|
134 | $source = $template_path . '/' . $template; |
---|
135 | $dest = $preview_template_path . '/' . $template; |
---|
136 | copy($source, $dest); |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | protected function lfUpdateTemplate($template, $content) { |
---|
141 | $fp = fopen($template,'w'); |
---|
142 | fwrite($fp, $content); |
---|
143 | fclose($fp); |
---|
144 | } |
---|
145 | |
---|
146 | protected function lfGetTemplatePath($device_type_id) { |
---|
147 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
148 | return $objLayout->getTemplatePath($device_type_id); |
---|
149 | } |
---|
150 | |
---|
151 | protected function lfGetPreviewTemplatePath() { |
---|
152 | return USER_INC_REALDIR . 'preview'; |
---|
153 | } |
---|
154 | |
---|
155 | /** |
---|
156 | * デストラクタ. |
---|
157 | * |
---|
158 | * @return void |
---|
159 | */ |
---|
160 | function destroy() { |
---|
161 | parent::destroy(); |
---|
162 | } |
---|
163 | } |
---|