1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2007 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_PATH . "pages/LC_Page.php"); |
---|
26 | require_once(DATA_PATH . "module/Tar.php"); |
---|
27 | require_once(CLASS_EX_PATH . "helper_extends/SC_Helper_FileManager_Ex.php"); |
---|
28 | |
---|
29 | /** |
---|
30 | * テンプレート設定 のページクラス. |
---|
31 | * |
---|
32 | * @package Page |
---|
33 | * @author LOCKON CO.,LTD. |
---|
34 | * @version $Id$ |
---|
35 | */ |
---|
36 | class LC_Page_Admin_Design_Template extends LC_Page { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /** テンプレートデータ種別 */ |
---|
42 | var $arrSubnavi = array( |
---|
43 | 'title' => array( |
---|
44 | 1 => 'top', |
---|
45 | 2 => 'product', |
---|
46 | 3 => 'detail', |
---|
47 | 4 => 'mypage' |
---|
48 | ), |
---|
49 | 'name' =>array( |
---|
50 | 1 => 'TOPページ', |
---|
51 | 2 => '商品一覧ページ', |
---|
52 | 3 => '商品詳細ページ', |
---|
53 | 4 => 'MYページ' |
---|
54 | ) |
---|
55 | ); |
---|
56 | |
---|
57 | /** |
---|
58 | * Page を初期化する. |
---|
59 | * |
---|
60 | * @return void |
---|
61 | */ |
---|
62 | function init() { |
---|
63 | parent::init(); |
---|
64 | $this->tpl_mainpage = 'design/template.tpl'; |
---|
65 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
66 | $this->tpl_subno = 'template'; |
---|
67 | $this->tpl_mainno = "design"; |
---|
68 | $this->tpl_subtitle = 'テンプレート設定'; |
---|
69 | $this->arrErr = array(); |
---|
70 | $this->arrForm = array(); |
---|
71 | $this->tpl_select = DEFAULT_TEMPLATE_NAME; |
---|
72 | ini_set("max_execution_time", 300); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * Page のプロセス. |
---|
77 | * |
---|
78 | * @return void |
---|
79 | */ |
---|
80 | function process() { |
---|
81 | // 認証可否の判定 |
---|
82 | $objSession = new SC_Session(); |
---|
83 | SC_Utils::sfIsSuccess($objSession); |
---|
84 | |
---|
85 | // uniqidをテンプレートへ埋め込み |
---|
86 | $this->uniqid = $objSession->getUniqId(); |
---|
87 | |
---|
88 | $objView = new SC_AdminView(); |
---|
89 | |
---|
90 | switch($this->lfGetMode()) { |
---|
91 | |
---|
92 | // 登録ボタン押下時 |
---|
93 | case 'register': |
---|
94 | // 画面遷移の正当性チェック |
---|
95 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
96 | sfDispError(''); |
---|
97 | } |
---|
98 | // パラメータ検証 |
---|
99 | $objForm = $this->lfInitRegister(); |
---|
100 | if ($objForm->checkError()) { |
---|
101 | SC_Utils_Ex::sfDispError(''); |
---|
102 | } |
---|
103 | |
---|
104 | $template_code = $objForm->getValue('template_code'); |
---|
105 | $this->tpl_select = $template_code; |
---|
106 | |
---|
107 | if($template_code == "") { |
---|
108 | $template_code = "default"; |
---|
109 | } |
---|
110 | |
---|
111 | // DBへ使用するテンプレートを登録 |
---|
112 | $this->lfRegisterTemplate($template_code); |
---|
113 | |
---|
114 | // XXX コンパイルファイルのクリア処理を行う |
---|
115 | $objView->_smarty->clear_compiled_tpl(); |
---|
116 | |
---|
117 | // ブロック位置を更新 |
---|
118 | $this->lfChangeBloc($template_code); |
---|
119 | |
---|
120 | // 完了メッセージ |
---|
121 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
122 | break; |
---|
123 | |
---|
124 | // 削除ボタン押下時 |
---|
125 | case 'delete': |
---|
126 | // 画面遷移の正当性チェック |
---|
127 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
128 | SC_Utils::sfDispError(''); |
---|
129 | } |
---|
130 | // パラメータ検証 |
---|
131 | $objForm = $this->lfInitDelete(); |
---|
132 | if ($objForm->checkError()) { |
---|
133 | SC_Utils::sfDispError(''); |
---|
134 | } |
---|
135 | |
---|
136 | $template_code = $objForm->getValue('template_code_temp'); |
---|
137 | if ($template_code == $this->lfGetNowTemplate()) { |
---|
138 | $this->tpl_onload = "alert('選択中のテンプレートは削除出来ません');"; |
---|
139 | break; |
---|
140 | } |
---|
141 | |
---|
142 | $this->lfDeleteTemplate($template_code); |
---|
143 | break; |
---|
144 | |
---|
145 | // downloadボタン押下時 |
---|
146 | case 'download': |
---|
147 | // 画面遷移の正当性チェック |
---|
148 | if (!SC_Utils::sfIsValidTransition($objSession)) { |
---|
149 | SC_Utils::sfDispError(''); |
---|
150 | } |
---|
151 | // パラメータ検証 |
---|
152 | $objForm = $this->lfInitDownload(); |
---|
153 | $template_code = $objForm->getValue('template_code_temp'); |
---|
154 | // ユーザデータの下のファイルも保存する。 |
---|
155 | $from_dir = USER_TEMPLATE_PATH . $template_code . "/"; |
---|
156 | $to_dir = SMARTY_TEMPLATES_DIR . $template_code . "/_packages/"; |
---|
157 | SC_Utils::sfMakeDir($to_dir); |
---|
158 | SC_Utils::sfCopyDir($from_dir, $to_dir); |
---|
159 | SC_Helper_FileManager::downloadArchiveFiles(SMARTY_TEMPLATES_DIR . $template_code); |
---|
160 | break; |
---|
161 | |
---|
162 | // プレビューボタン押下時 |
---|
163 | case 'preview': |
---|
164 | break; |
---|
165 | |
---|
166 | default: |
---|
167 | break; |
---|
168 | } |
---|
169 | |
---|
170 | // defaultパラメータのセット |
---|
171 | $this->templates = $this->lfGetAllTemplates(); |
---|
172 | $this->now_template = $this->lfGetNowtemplate(); |
---|
173 | |
---|
174 | // 画面の表示 |
---|
175 | $objView->assignobj($this); |
---|
176 | $objView->display(MAIN_FRAME); |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * デストラクタ. |
---|
181 | * |
---|
182 | * @return void |
---|
183 | */ |
---|
184 | function destroy() { |
---|
185 | parent::destroy(); |
---|
186 | } |
---|
187 | |
---|
188 | function lfGetMode(){ |
---|
189 | if (isset($_POST['mode'])) return $_POST['mode']; |
---|
190 | } |
---|
191 | |
---|
192 | function lfInitRegister() { |
---|
193 | $objForm = new SC_FormParam(); |
---|
194 | $objForm->addParam( |
---|
195 | 'template_code', 'template_code', STEXT_LEN, '', |
---|
196 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
197 | ); |
---|
198 | $objForm->setParam($_POST); |
---|
199 | |
---|
200 | return $objForm; |
---|
201 | } |
---|
202 | |
---|
203 | function lfInitDelete() { |
---|
204 | $objForm = new SC_FormParam(); |
---|
205 | $objForm->addParam( |
---|
206 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
207 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
208 | ); |
---|
209 | $objForm->setParam($_POST); |
---|
210 | |
---|
211 | return $objForm; |
---|
212 | } |
---|
213 | |
---|
214 | function lfInitDownload() { |
---|
215 | $objForm = new SC_FormParam(); |
---|
216 | $objForm->addParam( |
---|
217 | 'template_code_temp', 'template_code_temp', STEXT_LEN, '', |
---|
218 | array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK") |
---|
219 | ); |
---|
220 | $objForm->setParam($_POST); |
---|
221 | |
---|
222 | return $objForm; |
---|
223 | } |
---|
224 | |
---|
225 | /** |
---|
226 | * 現在適用しているテンプレートパッケージ名を取得する. |
---|
227 | * |
---|
228 | * @param void |
---|
229 | * @return string テンプレートパッケージ名 |
---|
230 | */ |
---|
231 | function lfGetNowTemplate() { |
---|
232 | $objQuery = new SC_Query(); |
---|
233 | $arrRet = $objQuery->select('top_tpl', 'dtb_baseinfo'); |
---|
234 | if (isset($arrRet[0]['top_tpl'])) { |
---|
235 | return $arrRet[0]['top_tpl']; |
---|
236 | } |
---|
237 | return null; |
---|
238 | } |
---|
239 | |
---|
240 | /** |
---|
241 | * 使用するテンプレートをDBへ登録する |
---|
242 | */ |
---|
243 | function lfRegisterTemplate($template_code) { |
---|
244 | $objQuery = new SC_Query(); |
---|
245 | $sqlval['name'] = "\"" . $template_code . "\""; |
---|
246 | $objQuery->update("mtb_constants", $sqlval, "id = ?", array('DEFAULT_TEMPLATE_NAME')); |
---|
247 | // キャッシュを生成 |
---|
248 | $masterData = new SC_DB_MasterData_Ex(); |
---|
249 | // 更新したデータを取得 |
---|
250 | $mtb_constants = $masterData->getDBMasterData("mtb_constants"); |
---|
251 | $masterData->clearCache("mtb_constants"); |
---|
252 | $masterData->createCache("mtb_constants", $mtb_constants, true, |
---|
253 | array("id", "remarks", "rank")); |
---|
254 | } |
---|
255 | |
---|
256 | /** |
---|
257 | * ブロック位置の更新 |
---|
258 | */ |
---|
259 | function lfChangeBloc($template_code) { |
---|
260 | $objQuery = new SC_Query(); |
---|
261 | $filepath = USER_TEMPLATE_PATH. $template_code. "/sql/update_bloc.sql"; |
---|
262 | |
---|
263 | // ブロック位置更新SQLファイル有 |
---|
264 | if(file_exists($filepath)) { |
---|
265 | if($fp = fopen($filepath, "r")) { |
---|
266 | $sql = fread($fp, filesize($filepath)); |
---|
267 | fclose($fp); |
---|
268 | } |
---|
269 | // 改行、タブを1スペースに変換 |
---|
270 | $sql = preg_replace("/[\r\n\t]/", " " ,$sql); |
---|
271 | $sql_split = split(";", $sql); |
---|
272 | foreach($sql_split as $key => $val){ |
---|
273 | if (trim($val) != "") { |
---|
274 | $objQuery->query($val); |
---|
275 | } |
---|
276 | } |
---|
277 | } |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
281 | * テンプレートパッケージの削除 |
---|
282 | */ |
---|
283 | function lfDeleteTemplate($template_code) { |
---|
284 | // DB更新 |
---|
285 | $objQuery = new SC_Query(); |
---|
286 | $objQuery->delete('dtb_templates', 'template_code = ?', array($template_code)); |
---|
287 | // テンプレート削除 |
---|
288 | $templates_dir = SMARTY_TEMPLATES_DIR. $template_code. "/"; |
---|
289 | SC_Utils_Ex::sfDelFile($templates_dir); |
---|
290 | // ユーザーデータ削除 |
---|
291 | $user_dir = USER_TEMPLATE_PATH. $template_code. "/"; |
---|
292 | SC_Utils_Ex::sfDelFile($user_dir); |
---|
293 | } |
---|
294 | |
---|
295 | function lfGetAllTemplates() { |
---|
296 | $objQuery = new SC_Query(); |
---|
297 | $arrRet = $objQuery->select('*', 'dtb_templates'); |
---|
298 | if (empty($arrRet)) return array(); |
---|
299 | |
---|
300 | return $arrRet; |
---|
301 | } |
---|
302 | } |
---|
303 | ?> |
---|