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_PATH . "pages/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * メイン編集 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Design_MainEdit extends LC_Page_Admin { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'design/main_edit.tpl'; |
---|
47 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
48 | $this->user_URL = USER_URL; |
---|
49 | $this->text_row = 13; |
---|
50 | $this->tpl_subno = "main_edit"; |
---|
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 | * @return void |
---|
69 | */ |
---|
70 | function action() { |
---|
71 | $objView = new SC_AdminView(); |
---|
72 | $this->objLayout = new SC_Helper_PageLayout_Ex(); |
---|
73 | |
---|
74 | // 認証可否の判定 |
---|
75 | $objSess = new SC_Session(); |
---|
76 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
77 | |
---|
78 | // ページIDを取得 |
---|
79 | if (isset($_REQUEST['page_id']) && is_numeric($_REQUEST['page_id'])) { |
---|
80 | $page_id = $_REQUEST['page_id']; |
---|
81 | } else { |
---|
82 | $page_id = 1; |
---|
83 | } |
---|
84 | |
---|
85 | $this->page_id = $page_id; |
---|
86 | |
---|
87 | // 端末種別IDを取得 |
---|
88 | if (isset($_REQUEST['device_type_id']) |
---|
89 | && is_numeric($_REQUEST['device_type_id'])) { |
---|
90 | $device_type_id = $_REQUEST['device_type_id']; |
---|
91 | } else { |
---|
92 | $device_type_id = DEVICE_TYPE_PC; |
---|
93 | } |
---|
94 | |
---|
95 | // ページ一覧を取得 |
---|
96 | $this->arrPageList = $this->objLayout->lfgetPageData("page_id <> 0 AND device_type_id = ?", |
---|
97 | array($device_type_id)); |
---|
98 | |
---|
99 | // メッセージ表示 |
---|
100 | if (isset($_GET['msg']) && $_GET['msg'] == "on"){ |
---|
101 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
102 | } |
---|
103 | |
---|
104 | // page_id が指定されている場合にはテンプレートデータの取得 |
---|
105 | if (is_numeric($page_id) and $page_id != '') { |
---|
106 | $this->lfGetPageData($page_id, $objView); |
---|
107 | } |
---|
108 | |
---|
109 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
110 | |
---|
111 | switch ($_POST['mode']) { |
---|
112 | case 'preview': |
---|
113 | $this->lfPreviewPageData($page_id); |
---|
114 | exit; |
---|
115 | break; |
---|
116 | |
---|
117 | case 'delete': |
---|
118 | if (!$this->objLayout->lfCheckBaseData($page_id)) { |
---|
119 | $this->lfDeletePageData($page_id); |
---|
120 | exit; |
---|
121 | } |
---|
122 | break; |
---|
123 | |
---|
124 | case 'confirm': |
---|
125 | $this->lfConfirmPageData($page_id); |
---|
126 | default: |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * デストラクタ. |
---|
132 | * |
---|
133 | * @return void |
---|
134 | */ |
---|
135 | function destroy() { |
---|
136 | parent::destroy(); |
---|
137 | } |
---|
138 | |
---|
139 | /** |
---|
140 | * ページデータを取得する. |
---|
141 | * |
---|
142 | * @param integer $page_id ページID |
---|
143 | * @param integer $device_type_id 端末種別ID |
---|
144 | * @param object $objView ビューオブジェクト |
---|
145 | * @return void |
---|
146 | */ |
---|
147 | function lfGetPageData($page_id, $device_type_id, $objView){ |
---|
148 | $arrPageData = $this->objLayout->lfGetPageData("page_id = ? AND device_type_id = ?", |
---|
149 | array($page_id, $device_type_id)); |
---|
150 | |
---|
151 | if (strlen($arrPageData[0]['filename']) == 0) { |
---|
152 | $this->arrErr['page_id_err'] = "※ 指定されたページは編集できません。"; |
---|
153 | // 画面の表示 |
---|
154 | $objView->assignobj($this); |
---|
155 | $objView->display(MAIN_FRAME); |
---|
156 | exit; |
---|
157 | } |
---|
158 | |
---|
159 | // FIXME |
---|
160 | // テンプレートファイルが存在していれば読み込む |
---|
161 | $tpl_file = USER_TEMPLATE_PATH . "/" . TEMPLATE_NAME . "/" . $arrPageData[0]['filename'] . ".tpl"; |
---|
162 | if (file_exists($tpl_file)){ |
---|
163 | $arrPageData[0]['tpl_data'] = file_get_contents($tpl_file); |
---|
164 | // 存在してなければ, 指定されたテンプレートのファイルを読み込む |
---|
165 | } else { |
---|
166 | $arrPageData[0]['tpl_data'] = file_get_contents(TEMPLATE_DIR . $arrPageData[0]['filename'] . ".tpl"); |
---|
167 | } |
---|
168 | |
---|
169 | // チェックボックスの値変更 |
---|
170 | $arrPageData[0]['header_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['header_chk'], true); |
---|
171 | $arrPageData[0]['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['footer_chk'], true); |
---|
172 | |
---|
173 | // ディレクトリを画面表示用に編集 |
---|
174 | $arrPageData[0]['directory'] = str_replace(USER_DIR, '', $arrPageData[0]['php_dir']); |
---|
175 | |
---|
176 | $this->arrPageData = $arrPageData[0]; |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * プレビュー画面を表示する. |
---|
181 | * |
---|
182 | * @param integer $page_id ページID |
---|
183 | * @param integer $device_type_id 端末種別ID |
---|
184 | * @return void |
---|
185 | */ |
---|
186 | function lfPreviewPageData($page_id, $device_type_id) { |
---|
187 | |
---|
188 | $page_id_old = $page_id; |
---|
189 | // プレビューの場合ページIDを0にセットする。 |
---|
190 | $page_id = "0"; |
---|
191 | $url = basename($_POST['url']); |
---|
192 | |
---|
193 | $tmpPost = $_POST; |
---|
194 | $tmpPost['page_id'] = $page_id; |
---|
195 | $tmpPost['url'] = $url; |
---|
196 | $tmpPost['tpl_dir'] = USER_PATH . "templates/preview/"; |
---|
197 | |
---|
198 | $arrPreData = $this->objLayout->lfGetPageData("page_id = ? AND device_type_id = ?", |
---|
199 | array($page_id, $device_type_id)); |
---|
200 | |
---|
201 | // tplファイルの削除 (XXX: 処理の意図が不明。存在していると都合が悪いファイル?) |
---|
202 | $del_tpl = USER_PATH . "templates/" . $arrPreData[0]['filename'] . '.tpl'; |
---|
203 | if (file_exists($del_tpl)){ |
---|
204 | unlink($del_tpl); |
---|
205 | } |
---|
206 | |
---|
207 | // DBへデータを更新する |
---|
208 | $this->lfEntryPageData($tmpPost); |
---|
209 | |
---|
210 | // TPLファイル作成 |
---|
211 | $preview_tpl = USER_PATH . "templates/preview/" . TEMPLATE_NAME . "/" . $url . '.tpl'; |
---|
212 | $this->lfCreateFile($preview_tpl, $_POST['tpl_data']); |
---|
213 | |
---|
214 | // blocposition を削除 |
---|
215 | $objQuery = new SC_Query(); // DB操作オブジェクト |
---|
216 | $sql = 'delete from dtb_blocposition where page_id = 0'; |
---|
217 | $ret = $objQuery->query($sql); |
---|
218 | |
---|
219 | if ($page_id_old != "") { |
---|
220 | // 登録データを取得 |
---|
221 | $sql = "SELECT 0, target_id, bloc_id, bloc_row FROM dtb_blocposition WHERE page_id = ?"; |
---|
222 | $ret = $objQuery->getAll($sql,array($page_id_old)); |
---|
223 | |
---|
224 | if (count($ret) > 0) { |
---|
225 | |
---|
226 | // blocposition を複製 |
---|
227 | $sql = " insert into dtb_blocposition ("; |
---|
228 | $sql .= " page_id,"; |
---|
229 | $sql .= " target_id,"; |
---|
230 | $sql .= " bloc_id,"; |
---|
231 | $sql .= " bloc_row"; |
---|
232 | $sql .= " )values(?, ?, ?, ?)"; |
---|
233 | |
---|
234 | // 取得件数文INSERT実行 |
---|
235 | foreach($ret as $key => $val){ |
---|
236 | $ret = $objQuery->query($sql,$val); |
---|
237 | } |
---|
238 | } |
---|
239 | } |
---|
240 | $_SESSION['preview'] = "ON"; |
---|
241 | $this->objDisplay->redirect($this->getLocation(URL_DIR . "preview/" . DIR_INDEX_URL, array("filename" => $arrPageData[0]["filename"]))); |
---|
242 | |
---|
243 | } |
---|
244 | |
---|
245 | /** |
---|
246 | * データ登録処理. |
---|
247 | * |
---|
248 | * @param integer $page_id ページID |
---|
249 | * @param integer $device_type_id 端末種別ID |
---|
250 | * @return void |
---|
251 | */ |
---|
252 | function lfConfirmPageData($page_id, $device_type_id) { |
---|
253 | // エラーチェック |
---|
254 | $this->arrErr = $this->lfErrorCheck($_POST); |
---|
255 | |
---|
256 | // エラーがなければ更新処理を行う |
---|
257 | if (count($this->arrErr) == 0) { |
---|
258 | // DBへデータを更新する |
---|
259 | $this->lfEntryPageData($_POST); |
---|
260 | |
---|
261 | // ベースデータでなければファイルを削除し、PHPファイルを作成する |
---|
262 | if (!$this->objLayout->lfCheckBaseData($page_id, $device_type_id)) { |
---|
263 | // PHPファイル作成 |
---|
264 | $this->lfCreatePHPFile($_POST['url']); |
---|
265 | } |
---|
266 | |
---|
267 | // FIXME |
---|
268 | // TPLファイル作成 |
---|
269 | $cre_tpl = USER_TEMPLATE_PATH . "/" . TEMPLATE_NAME . "/" . basename($_POST['url']) . '.tpl'; |
---|
270 | $this->lfCreateFile($cre_tpl, $_POST['tpl_data']); |
---|
271 | |
---|
272 | // 新規作成の場合、 |
---|
273 | if ($page_id == '') { |
---|
274 | // ページIDを取得する |
---|
275 | $arrPageData = $this->objLayout->lfGetPageData("url = ? AND page_id <> 0" , array(USER_DIR . $_POST['url'] . '.php')); |
---|
276 | $page_id = $arrPageData[0]['page_id']; |
---|
277 | } |
---|
278 | $this->objDisplay->redirect($this->getLocation("./main_edit.php", |
---|
279 | array("page_id" => $page_id, |
---|
280 | "device_type_id" => $device_type_id, |
---|
281 | "msg" => "on"))); |
---|
282 | exit; |
---|
283 | } else { |
---|
284 | // エラーがあれば入力時のデータを表示する |
---|
285 | $this->arrPageData = $_POST; |
---|
286 | $this->arrPageData['header_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['header_chk']), true); |
---|
287 | $this->arrPageData['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['footer_chk']), true); |
---|
288 | $this->arrPageData['directory'] = ''; |
---|
289 | $this->arrPageData['filename'] = $_POST['url']; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | /** |
---|
294 | * ブロック情報を更新する. |
---|
295 | * |
---|
296 | * @param array $arrData 更新データ |
---|
297 | * @return void |
---|
298 | */ |
---|
299 | function lfEntryPageData($arrData, $device_type_id){ |
---|
300 | $objQuery = new SC_Query(); |
---|
301 | $arrChk = array(); // 排他チェック用 |
---|
302 | |
---|
303 | // 更新データの変換 |
---|
304 | $sqlval = $this->lfGetUpdData($arrData); |
---|
305 | |
---|
306 | // データが存在しているかチェックを行う |
---|
307 | if($arrData['page_id'] !== ''){ |
---|
308 | $arrChk = $this->objLayout->lfgetPageData("page_id = ? AND device_type_id = ?", |
---|
309 | array($arrData['page_id'], $device_type_id)); |
---|
310 | } |
---|
311 | |
---|
312 | // page_id が空 若しくは データが存在していない場合にはINSERTを行う |
---|
313 | if ($arrData['page_id'] === '' or !isset($arrChk[0])) { |
---|
314 | // FIXME device_type_id ごとの連番にする |
---|
315 | $sqlval['page_id'] = $objQuery->nextVal('dtb_pagelayout_page_id'); |
---|
316 | $sqlval['device_type_id'] = $device_type_id; |
---|
317 | $sqlval['create_date'] = 'now()'; |
---|
318 | $objQuery->insert('dtb_pagelayout', $sqlval); |
---|
319 | } |
---|
320 | // データが存在してる場合にはアップデートを行う |
---|
321 | else { |
---|
322 | $objQuery->update('dtb_pagelayout', $sqlval, 'page_id = ? AND device_type_id = ?', |
---|
323 | array($arrData['page_id'], $device_type_id)); |
---|
324 | } |
---|
325 | } |
---|
326 | |
---|
327 | /** |
---|
328 | * DBへ更新を行うデータを生成する. |
---|
329 | * |
---|
330 | * @param array $arrData 更新データ |
---|
331 | * @return array 更新データ |
---|
332 | */ |
---|
333 | function lfGetUpdData($arrData){ |
---|
334 | $arrUpdData = array( |
---|
335 | 'header_chk' => SC_Utils_Ex::sfChangeCheckBox($arrData['header_chk']), // ヘッダー使用 |
---|
336 | 'footer_chk' => SC_Utils_Ex::sfChangeCheckBox($arrData['footer_chk']), // フッター使用 |
---|
337 | 'update_url' => $_SERVER['HTTP_REFERER'], // 更新URL |
---|
338 | 'update_date' => 'now()', |
---|
339 | ); |
---|
340 | |
---|
341 | // ベースデータの場合には変更しない。 |
---|
342 | if (!$this->objLayout->lfCheckBaseData($arrData['page_id'])) { |
---|
343 | $arrUpdData['page_name'] = $arrData['page_name'] ; |
---|
344 | $arrUpdData['url'] = USER_DIR . $arrData['url'] . '.php'; |
---|
345 | $arrUpdData['php_dir'] = dirname($arrUpdData['url']); |
---|
346 | if ($arrUpdData['php_dir'] == '.') { |
---|
347 | $arrUpdData['php_dir'] = ''; |
---|
348 | } else { |
---|
349 | $arrUpdData['php_dir'] .= '/'; |
---|
350 | } |
---|
351 | $arrUpdData['tpl_dir'] = substr(TPL_DIR, strlen(URL_DIR)); |
---|
352 | $arrUpdData['filename'] = basename($arrData['url']); // 拡張子を付加しない |
---|
353 | } |
---|
354 | |
---|
355 | return $arrUpdData; |
---|
356 | } |
---|
357 | |
---|
358 | /** |
---|
359 | * ページデータを削除する. |
---|
360 | * |
---|
361 | * @param integer $page_id ページID |
---|
362 | * @return void |
---|
363 | */ |
---|
364 | function lfDeletePageData($page_id, $device_type_id){ |
---|
365 | $this->objLayout->lfDelPageData($page_id, $device_type_id); |
---|
366 | $this->objDisplay->redirect($this->getLocation("./main_edit.php", |
---|
367 | array("device_type_id" => $device_type_id))); |
---|
368 | } |
---|
369 | |
---|
370 | /** |
---|
371 | * 入力項目のエラーチェックを行う. |
---|
372 | * |
---|
373 | * @param array $arrData 入力データ |
---|
374 | * @return array エラー情報 |
---|
375 | */ |
---|
376 | function lfErrorCheck($array) { |
---|
377 | $objErr = new SC_CheckError($array); |
---|
378 | $objErr->doFunc(array("名称", "page_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
379 | $objErr->doFunc(array("URL", "url", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
380 | |
---|
381 | // URLチェック |
---|
382 | $okUrl = true; |
---|
383 | foreach (explode('/', $array['url']) as $url_part) { |
---|
384 | if (!ereg( '^[a-zA-Z0-9:_~\.-]+$', $url_part)) { |
---|
385 | $okUrl = false; |
---|
386 | } |
---|
387 | if ($url_part == '.' || $url_part == '..') { |
---|
388 | $okUrl = false; |
---|
389 | } |
---|
390 | } |
---|
391 | if (!$okUrl) { |
---|
392 | $objErr->arrErr['url'] = "※ URLを正しく入力してください。<br />"; |
---|
393 | } |
---|
394 | |
---|
395 | // 同一のURLが存在している場合にはエラー |
---|
396 | $params = array(); |
---|
397 | |
---|
398 | $sqlWhere = 'url = ?'; |
---|
399 | $params[] = USER_DIR . $array['url'] . '.php'; |
---|
400 | |
---|
401 | // プレビュー用のレコードは除外 |
---|
402 | $sqlWhere .= ' AND page_id <> 0'; |
---|
403 | |
---|
404 | // 変更の場合、自身のレコードは除外 |
---|
405 | if (strlen($array['page_id']) != 0) { |
---|
406 | $sqlWhere .= ' AND page_id <> ?'; |
---|
407 | $params[] = $array['page_id']; |
---|
408 | } |
---|
409 | |
---|
410 | $arrChk = $this->objLayout->lfgetPageData($sqlWhere , $params); |
---|
411 | |
---|
412 | if (count($arrChk) >= 1) { |
---|
413 | $objErr->arrErr['url'] = '※ 同じURLのデータが存在しています。別のURLを付けてください。<br />'; |
---|
414 | } |
---|
415 | |
---|
416 | return $objErr->arrErr; |
---|
417 | } |
---|
418 | |
---|
419 | /** |
---|
420 | * ファイルを作成する. |
---|
421 | * |
---|
422 | * @param string $path テンプレートファイルのパス |
---|
423 | * @param string $data テンプレートの内容 |
---|
424 | * @return void |
---|
425 | */ |
---|
426 | function lfCreateFile($path, $data){ |
---|
427 | |
---|
428 | // ディレクトリが存在していなければ作成する |
---|
429 | if (!is_dir(dirname($path))) { |
---|
430 | mkdir(dirname($path)); |
---|
431 | } |
---|
432 | |
---|
433 | // ファイル作成 |
---|
434 | $fp = fopen($path,"w"); |
---|
435 | fwrite($fp, $data); // FIXME いきなり POST はちょっと... |
---|
436 | fclose($fp); |
---|
437 | } |
---|
438 | |
---|
439 | /** |
---|
440 | * PHPファイルを作成する. |
---|
441 | * |
---|
442 | * @param string $path PHPファイルのパス |
---|
443 | * @return void |
---|
444 | */ |
---|
445 | function lfCreatePHPFile($url){ |
---|
446 | |
---|
447 | $path = USER_PATH . $url . ".php"; |
---|
448 | |
---|
449 | // カスタマイズを考慮し、上書きしない。(#831) |
---|
450 | if (file_exists($path)) { |
---|
451 | return; |
---|
452 | } |
---|
453 | |
---|
454 | // php保存先ディレクトリが存在していなければ作成する |
---|
455 | if (!is_dir(dirname($path))) { |
---|
456 | mkdir(dirname($path)); |
---|
457 | } |
---|
458 | |
---|
459 | // ベースとなるPHPファイルの読み込み |
---|
460 | if (file_exists(USER_DEF_PHP)){ |
---|
461 | $php_data = file_get_contents(USER_DEF_PHP); |
---|
462 | } |
---|
463 | |
---|
464 | // require.phpの場所を書き換える |
---|
465 | $php_data = str_replace("###require###", str_repeat('../', substr_count($url, '/')) . '../require.php', $php_data); |
---|
466 | |
---|
467 | // phpファイルの作成 |
---|
468 | $fp = fopen($path,"w"); |
---|
469 | fwrite($fp, $php_data); |
---|
470 | fclose($fp); |
---|
471 | } |
---|
472 | |
---|
473 | } |
---|
474 | ?> |
---|