source: branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 16582

Revision 16582, 16.5 KB checked in by nanasess, 16 years ago (diff)

ライセンス表記変更

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