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/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * デザイン管理 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Design extends LC_Page { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | $this->tpl_mainpage = 'design/index.tpl'; |
---|
47 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
48 | $this->tpl_subno = "layout"; |
---|
49 | $this->tpl_mainno = "design"; |
---|
50 | $this->tpl_subtitle = 'レイアウト設定'; |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Page のプロセス. |
---|
55 | * |
---|
56 | * @return void |
---|
57 | */ |
---|
58 | function process() { |
---|
59 | |
---|
60 | $objView = new SC_AdminView(); |
---|
61 | $objSess = new SC_Session(); |
---|
62 | $objLayout = new SC_Helper_PageLayout_Ex(); |
---|
63 | |
---|
64 | // 認証可否の判定 |
---|
65 | $objSess = new SC_Session(); |
---|
66 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
67 | |
---|
68 | // ページIDを取得 |
---|
69 | if (isset($_GET['page_id'])) { |
---|
70 | $page_id = $_GET['page_id']; |
---|
71 | }else if (isset($_POST['page_id'])){ |
---|
72 | $page_id = $_POST['page_id']; |
---|
73 | }else{ |
---|
74 | $page_id = 1; |
---|
75 | } |
---|
76 | |
---|
77 | // 編集可能ページを取得 |
---|
78 | $this->arrEditPage = $objLayout->lfgetPageData(); |
---|
79 | |
---|
80 | // ブロック配置用データを取得 |
---|
81 | $sel = ", pos.target_id, pos.bloc_id, pos.bloc_row "; |
---|
82 | $from = ", dtb_blocposition AS pos"; |
---|
83 | $where = " where "; |
---|
84 | $where .= " lay.page_id = ? AND "; |
---|
85 | $where .= "lay.page_id = pos.page_id AND exists (select bloc_id from dtb_bloc as blc where pos.bloc_id = blc.bloc_id) ORDER BY lay.page_id,pos.target_id, pos.bloc_row, pos.bloc_id "; |
---|
86 | $arrData = array($page_id); |
---|
87 | $arrBlocPos = $this->lfgetLayoutData($sel, $from, $where, $arrData ); |
---|
88 | |
---|
89 | // データの存在チェックを行う |
---|
90 | $arrPageData = $objLayout->lfgetPageData("page_id = ?", array($page_id)); |
---|
91 | if (count($arrPageData) <= 0) { |
---|
92 | $exists_page = 0; |
---|
93 | }else{ |
---|
94 | $exists_page = 1; |
---|
95 | } |
---|
96 | $this->exists_page = $exists_page; |
---|
97 | |
---|
98 | // メッセージ表示 |
---|
99 | if (isset($_GET['msg']) && $_GET['msg'] == "on") { |
---|
100 | $this->complate_msg="alert('登録が完了しました。');"; |
---|
101 | } |
---|
102 | |
---|
103 | // ブロックを取得 |
---|
104 | $arrBloc = $this->lfgetBlocData(); |
---|
105 | |
---|
106 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
107 | |
---|
108 | // 新規ブロック作成 |
---|
109 | if ($_POST['mode'] == 'new_bloc') { |
---|
110 | $this->sendRedirect($this->getLocation("./bloc.php")); |
---|
111 | exit; |
---|
112 | } |
---|
113 | |
---|
114 | // 新規ページ作成 |
---|
115 | if ($_POST['mode'] == 'new_page') { |
---|
116 | $this->sendRedirect($this->getLocation("./main_edit.php")); |
---|
117 | exit; |
---|
118 | } |
---|
119 | |
---|
120 | // データ登録処理 |
---|
121 | if ($_POST['mode'] == 'confirm' or $_POST['mode'] == 'preview') { |
---|
122 | $page_id = $_POST['page_id']; |
---|
123 | if ($_POST['mode'] == 'preview') { |
---|
124 | $page_id = '0'; |
---|
125 | } |
---|
126 | $masterData = new SC_DB_MasterData_Ex(); |
---|
127 | $arrTarget = $masterData->getMasterData("mtb_target"); |
---|
128 | |
---|
129 | // 更新用にデータを整える |
---|
130 | $arrUpdBlocData = array(); |
---|
131 | $arrTargetFlip = array_flip($arrTarget); |
---|
132 | |
---|
133 | $upd_cnt = 1; |
---|
134 | $arrUpdData[$upd_cnt]['page_id'] = $page_id; |
---|
135 | |
---|
136 | // POSTのデータを使いやすいように修正 |
---|
137 | for($upd_cnt = 1; $upd_cnt <= $_POST['bloc_cnt']; $upd_cnt++){ |
---|
138 | if (!isset($_POST['id_'.$upd_cnt])) { |
---|
139 | break; |
---|
140 | } |
---|
141 | $arrUpdBlocData[$upd_cnt]['name'] = $_POST['name_'.$upd_cnt]; // ブロック名称 |
---|
142 | $arrUpdBlocData[$upd_cnt]['id'] = $_POST['id_'.$upd_cnt]; // ブロックID |
---|
143 | $arrUpdBlocData[$upd_cnt]['target_id'] = $arrTargetFlip[$_POST['target_id_'.$upd_cnt]]; // ターゲットID |
---|
144 | $arrUpdBlocData[$upd_cnt]['top'] = $_POST['top_'.$upd_cnt]; // TOP座標 |
---|
145 | $arrUpdBlocData[$upd_cnt]['update_url'] = $_SERVER['HTTP_REFERER']; // 更新URL |
---|
146 | } |
---|
147 | |
---|
148 | // データの更新を行う |
---|
149 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
150 | $arrRet = array(); // データ取得用 |
---|
151 | |
---|
152 | // delete実行 |
---|
153 | $del_sql = ""; |
---|
154 | $del_sql .= "DELETE FROM dtb_blocposition WHERE page_id = ? "; |
---|
155 | $arrRet = $objDBConn->query($del_sql,array($page_id)); |
---|
156 | |
---|
157 | // ブロックの順序を取得し、更新を行う |
---|
158 | foreach($arrUpdBlocData as $key => $val){ |
---|
159 | // ブロックの順序を取得 |
---|
160 | $bloc_row = $this->lfGetRowID($arrUpdBlocData, $val); |
---|
161 | $arrUpdBlocData[$key]['bloc_row'] = $bloc_row; |
---|
162 | $arrUpdBlocData[$key]['page_id'] = $page_id; // ページID |
---|
163 | |
---|
164 | /* |
---|
165 | ターゲットID 1:レフトナビ 2:ライトナビ 3:イン画面上部 4:メイン画面下部 5:欄外 |
---|
166 | */ |
---|
167 | if ($arrUpdBlocData[$key]['target_id'] == 5) { |
---|
168 | $arrUpdBlocData[$key]['bloc_row'] = "0"; |
---|
169 | } |
---|
170 | |
---|
171 | // insert文生成 |
---|
172 | $ins_sql = ""; |
---|
173 | $ins_sql .= "INSERT INTO dtb_blocposition "; |
---|
174 | $ins_sql .= " values ( "; |
---|
175 | $ins_sql .= " ? "; // ページID |
---|
176 | $ins_sql .= " ,? "; // ターゲットID |
---|
177 | $ins_sql .= " ,? "; // ブロックID |
---|
178 | $ins_sql .= " ,? "; // ブロックの並び順序 |
---|
179 | $ins_sql .= " ,(SELECT filename FROM dtb_bloc WHERE bloc_id = ?) "; // ファイル名称 |
---|
180 | $ins_sql .= " ) "; |
---|
181 | |
---|
182 | // insertデータ生成 |
---|
183 | $arrInsData = array($page_id, |
---|
184 | $arrUpdBlocData[$key]['target_id'], |
---|
185 | $arrUpdBlocData[$key]['id'], |
---|
186 | $arrUpdBlocData[$key]['bloc_row'], |
---|
187 | $arrUpdBlocData[$key]['id'] |
---|
188 | ); |
---|
189 | // SQL実行 |
---|
190 | $arrRet = $objDBConn->query($ins_sql,$arrInsData); |
---|
191 | } |
---|
192 | |
---|
193 | // プレビュー処理 |
---|
194 | if ($_POST['mode'] == 'preview') { |
---|
195 | if ($page_id === "") { |
---|
196 | $this->sendRedirect($this->getLocation("./index.php")); |
---|
197 | exit; |
---|
198 | } |
---|
199 | $this->lfSetPreData($arrPageData, $objLayout); |
---|
200 | |
---|
201 | $_SESSION['preview'] = "ON"; |
---|
202 | |
---|
203 | $this->sendRedirect($this->getLocation(URL_DIR . "preview/index.php", array("filename" => $arrPageData[0]["filename"]))); |
---|
204 | exit; |
---|
205 | |
---|
206 | }else{ |
---|
207 | $this->sendRedirect($this->getLocation("./index.php", |
---|
208 | array("page_id" => $page_id, |
---|
209 | "msg" => "on"))); |
---|
210 | exit; |
---|
211 | |
---|
212 | } |
---|
213 | } |
---|
214 | |
---|
215 | // データ削除処理 ベースデータでなければファイルを削除 |
---|
216 | if ($_POST['mode'] == 'delete' and !$objLayout->lfCheckBaseData($page_id)) { |
---|
217 | $objLayout->lfDelPageData($page_id); |
---|
218 | $this->sendRedirect($this->getLocation("./index.php")); |
---|
219 | exit; |
---|
220 | } |
---|
221 | |
---|
222 | // ブロック情報を画面配置用に編集 |
---|
223 | $tpl_arrBloc = array(); |
---|
224 | $cnt = 0; |
---|
225 | // 使用されているブロックデータを生成 |
---|
226 | foreach($arrBlocPos as $key => $val){ |
---|
227 | if ($val['page_id'] == $page_id) { |
---|
228 | $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt); |
---|
229 | $cnt++; |
---|
230 | } |
---|
231 | } |
---|
232 | |
---|
233 | // 未使用のブロックデータを追加 |
---|
234 | foreach($arrBloc as $key => $val){ |
---|
235 | if (!$this->lfChkBloc($val, $tpl_arrBloc)) { |
---|
236 | $val['target_id'] = 5; // 未使用に追加する |
---|
237 | $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt); |
---|
238 | $cnt++; |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | $this->tpl_arrBloc = $tpl_arrBloc; |
---|
243 | $this->bloc_cnt = count($tpl_arrBloc); |
---|
244 | $this->page_id = $page_id; |
---|
245 | |
---|
246 | // ページ名称を取得 |
---|
247 | $arrPageData = $objLayout->lfgetPageData(' page_id = ?', array($page_id)); |
---|
248 | $this->arrPageData = $arrPageData[0]; |
---|
249 | |
---|
250 | global $GLOBAL_ERR; |
---|
251 | $errCnt = 0; |
---|
252 | if ($GLOBAL_ERR != "") { |
---|
253 | $arrGlobalErr = explode("\n",$GLOBAL_ERR); |
---|
254 | $errCnt = count($arrGlobalErr) - 8; |
---|
255 | if ($errCnt < 0 ) { |
---|
256 | $errCnt = 0; |
---|
257 | } |
---|
258 | } |
---|
259 | $this->errCnt = $errCnt; |
---|
260 | |
---|
261 | // 画面の表示 |
---|
262 | $objView->assignobj($this); |
---|
263 | $objView->display(MAIN_FRAME); |
---|
264 | |
---|
265 | } |
---|
266 | /** |
---|
267 | * デストラクタ. |
---|
268 | * |
---|
269 | * @return void |
---|
270 | */ |
---|
271 | function destroy() { |
---|
272 | parent::destroy(); |
---|
273 | } |
---|
274 | |
---|
275 | /** |
---|
276 | * 編集可能なページ情報を取得する. |
---|
277 | * |
---|
278 | * @param string $sel Select句文 |
---|
279 | * @param string $where Where句文 |
---|
280 | * @param array $arrVa Where句の絞込条件値 |
---|
281 | * @return array ページレイアウト情報の配列 |
---|
282 | */ |
---|
283 | function lfgetLayoutData($sel = '' , $from = '', $where = '', $arrVal = ''){ |
---|
284 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
285 | $sql = ""; // データ取得SQL生成用 |
---|
286 | $arrRet = array(); // データ取得用 |
---|
287 | |
---|
288 | // SQL生成 |
---|
289 | |
---|
290 | $sql = ""; |
---|
291 | $sql .= " select "; |
---|
292 | $sql .= " lay.page_id "; |
---|
293 | $sql .= " ,lay.page_name "; |
---|
294 | $sql .= " ,lay.url "; |
---|
295 | $sql .= " ,lay.author "; |
---|
296 | $sql .= " ,lay.description "; |
---|
297 | $sql .= " ,lay.keyword "; |
---|
298 | $sql .= " ,lay.update_url "; |
---|
299 | $sql .= " ,lay.create_date "; |
---|
300 | $sql .= " ,lay.update_date "; |
---|
301 | |
---|
302 | // Select句の指定があれば追加 |
---|
303 | if ($sel != '') { |
---|
304 | $sql .= $sel; |
---|
305 | } |
---|
306 | |
---|
307 | $sql .= " from dtb_pagelayout AS lay "; |
---|
308 | // From句の指定があれば追加 |
---|
309 | if ($from != '') { |
---|
310 | $sql .= $from; |
---|
311 | } |
---|
312 | |
---|
313 | // where句の指定があれば追加 |
---|
314 | if ($where != '') { |
---|
315 | $sql .= $where; |
---|
316 | }else{ |
---|
317 | $sql .= " ORDER BY lay.page_id "; |
---|
318 | } |
---|
319 | |
---|
320 | $arrRet = $objDBConn->getAll($sql, $arrVal); |
---|
321 | |
---|
322 | return $arrRet; |
---|
323 | } |
---|
324 | |
---|
325 | /** |
---|
326 | * ブロック情報を取得する. |
---|
327 | * |
---|
328 | * @param string $where Where句文 |
---|
329 | * @param array $arrVal Where句の絞込条件値 |
---|
330 | * @return array ブロック情報の配列 |
---|
331 | */ |
---|
332 | function lfgetBlocData($where = '', $arrVal = ''){ |
---|
333 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
334 | $sql = ""; // データ取得SQL生成用 |
---|
335 | $arrRet = array(); // データ取得用 |
---|
336 | |
---|
337 | // SQL生成 |
---|
338 | $sql = ""; |
---|
339 | $sql .= " SELECT "; |
---|
340 | $sql .= " bloc_id"; |
---|
341 | $sql .= " ,bloc_name"; |
---|
342 | $sql .= " ,tpl_path"; |
---|
343 | $sql .= " ,filename"; |
---|
344 | $sql .= " ,update_date"; |
---|
345 | $sql .= " FROM "; |
---|
346 | $sql .= " dtb_bloc"; |
---|
347 | |
---|
348 | // where句の指定があれば追加 |
---|
349 | if ($where != '') { |
---|
350 | $sql .= " WHERE " . $where; |
---|
351 | } |
---|
352 | |
---|
353 | $sql .= " ORDER BY bloc_id"; |
---|
354 | |
---|
355 | $arrRet = $objDBConn->getAll($sql, $arrVal); |
---|
356 | |
---|
357 | return $arrRet; |
---|
358 | } |
---|
359 | |
---|
360 | /** |
---|
361 | * ブロック情報の配列を生成する. |
---|
362 | * |
---|
363 | * @param array $arrBloc Bloc情報 |
---|
364 | * @param array $tpl_arrBloc データをセットする配列 |
---|
365 | * @param integer $cnt 配列番号 |
---|
366 | * @return array データをセットした配列 |
---|
367 | */ |
---|
368 | function lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt) { |
---|
369 | $masterData = new SC_DB_MasterData_Ex(); |
---|
370 | $arrTarget = $masterData->getMasterData("mtb_target"); |
---|
371 | |
---|
372 | $tpl_arrBloc[$cnt]['target_id'] = $arrTarget[$val['target_id']]; |
---|
373 | $tpl_arrBloc[$cnt]['bloc_id'] = $val['bloc_id']; |
---|
374 | $tpl_arrBloc[$cnt]['bloc_row'] = |
---|
375 | isset($val['bloc_row']) ? $val['bloc_row'] : ""; |
---|
376 | |
---|
377 | foreach($arrBloc as $bloc_key => $bloc_val){ |
---|
378 | if ($bloc_val['bloc_id'] == $val['bloc_id']) { |
---|
379 | $bloc_name = $bloc_val['bloc_name']; |
---|
380 | break; |
---|
381 | } |
---|
382 | } |
---|
383 | $tpl_arrBloc[$cnt]['name'] = $bloc_name; |
---|
384 | |
---|
385 | return $tpl_arrBloc; |
---|
386 | } |
---|
387 | |
---|
388 | /** |
---|
389 | * ブロックIDが配列に追加されているかのチェックを行う. |
---|
390 | * |
---|
391 | * @param array $arrBloc Bloc情報 |
---|
392 | * @param array $arrChkData チェックを行うデータ配列 |
---|
393 | * @return bool 存在する場合 true |
---|
394 | */ |
---|
395 | function lfChkBloc($arrBloc, $arrChkData) { |
---|
396 | foreach($arrChkData as $key => $val){ |
---|
397 | if ($val['bloc_id'] === $arrBloc['bloc_id'] ) { |
---|
398 | // 配列に存在すればTrueを返す |
---|
399 | return true; |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | // 配列に存在しなければFlaseを返す |
---|
404 | return false; |
---|
405 | } |
---|
406 | |
---|
407 | /** |
---|
408 | * ブロックIDが何番目に配置されているかを調べる. |
---|
409 | * |
---|
410 | * @param array $arrUpdData 更新情報 |
---|
411 | * @param array $arrObj チェックを行うデータ配列 |
---|
412 | * @return integer 順番 |
---|
413 | */ |
---|
414 | function lfGetRowID($arrUpdData, $arrObj){ |
---|
415 | $no = 0; // カウント用(同じデータが必ず1件あるので、初期値は0) |
---|
416 | |
---|
417 | // 対象データが何番目に配置されているのかを取得する。 |
---|
418 | foreach ($arrUpdData as $key => $val) { |
---|
419 | if ($val['target_id'] === $arrObj['target_id'] and $val['top'] <= $arrObj['top']){ |
---|
420 | $no++; |
---|
421 | } |
---|
422 | } |
---|
423 | // 番号を返す |
---|
424 | return $no; |
---|
425 | } |
---|
426 | |
---|
427 | /** |
---|
428 | * プレビューするデータを DB に保存する. |
---|
429 | * |
---|
430 | * @param array $arrPageData ページ情報の配列 |
---|
431 | * @return void |
---|
432 | */ |
---|
433 | function lfSetPreData($arrPageData, &$objLayout){ |
---|
434 | $objDBConn = new SC_DbConn; // DB操作オブジェクト |
---|
435 | $sql = ""; // データ更新SQL生成用 |
---|
436 | $ret = ""; // データ更新結果格納用 |
---|
437 | $arrUpdData = array(); // 更新データ生成用 |
---|
438 | $filename = $arrPageData[0]['filename']; |
---|
439 | |
---|
440 | $arrPreData = $objLayout->lfgetPageData(" page_id = ? " , array("0")); |
---|
441 | |
---|
442 | // XXX tplファイルの削除 |
---|
443 | $del_tpl = USER_PATH . "templates/" . $filename . '.tpl'; |
---|
444 | |
---|
445 | if (file_exists($del_tpl)){ |
---|
446 | unlink($del_tpl); |
---|
447 | } |
---|
448 | |
---|
449 | $tplfile = TEMPLATE_DIR . $filename; |
---|
450 | |
---|
451 | // filename が空の場合にはMYページと判断 |
---|
452 | if($filename == ""){ |
---|
453 | $tplfile = TEMPLATE_DIR . "mypage/index"; |
---|
454 | $filename = 'mypage'; |
---|
455 | } |
---|
456 | |
---|
457 | // プレビュー用tplファイルのコピー |
---|
458 | $copyTo = USER_PATH . "templates/preview/" . TEMPLATE_NAME . "/" . $filename . ".tpl"; |
---|
459 | |
---|
460 | if (!is_dir(dirname($copyTo))) { |
---|
461 | mkdir(dirname($copyTo)); |
---|
462 | } |
---|
463 | |
---|
464 | copy($tplfile . ".tpl", $copyTo); |
---|
465 | |
---|
466 | // 更新データの取得 |
---|
467 | $sql = "select page_name, header_chk, footer_chk from dtb_pagelayout where page_id = ?"; |
---|
468 | $ret = $objDBConn->getAll($sql, array($arrPageData[0]['page_id'])); |
---|
469 | |
---|
470 | // dbデータのコピー |
---|
471 | $sql = " update dtb_pagelayout set "; |
---|
472 | $sql .= " page_name = ?"; |
---|
473 | $sql .= " ,header_chk = ?"; |
---|
474 | $sql .= " ,footer_chk = ?"; |
---|
475 | $sql .= " ,url = ?"; |
---|
476 | $sql .= " ,tpl_dir = ?"; |
---|
477 | $sql .= " ,filename = ?"; |
---|
478 | $sql .= " where page_id = 0"; |
---|
479 | |
---|
480 | $arrUpdData = array($ret[0]['page_id'] |
---|
481 | ,$ret[0]['page_id'] |
---|
482 | ,$ret[0]['page_id'] |
---|
483 | ,USER_DIR . "templates/" . TEMPLATE_NAME . "/" |
---|
484 | ,USER_DIR . "templates/" . TEMPLATE_NAME . "/" |
---|
485 | ,$filename |
---|
486 | ); |
---|
487 | |
---|
488 | $objDBConn->query($sql,$arrUpdData); |
---|
489 | } |
---|
490 | } |
---|
491 | ?> |
---|