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