source: tmp/version-2_5-test/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 18609

Revision 18609, 18.6 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

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