source: branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 20057

Revision 20057, 15.1 KB checked in by Seasoft, 13 years ago (diff)

#628(未使用処理・定義などの削除)

  • dtb_pagelayout.php_dir
  • dtb_pagelayout.tpl_dir
  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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
25require_once(CLASS_REALDIR . "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 */
35class 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; // FIXME $_REQUEST['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->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        switch ($this->getMode()) {
119        // 新規ブロック作成
120        case 'new_bloc':
121            SC_Response_Ex::sendRedirect('bloc.php', array("device_type_id" => $device_type_id));
122            exit;
123            break;
124
125        // 新規ページ作成
126        case 'new_page':
127            SC_Response_Ex::sendRedirect('main_edit.php', array("device_type_id" => $device_type_id));
128            exit;
129            break;
130
131        case 'confirm':
132        case 'preview':
133            //TODO 要リファクタリング(MODE if利用)
134            $page_id = $_POST['page_id'];
135            if ($this->getMode() == 'preview') {
136                $page_id = '0';
137            }
138
139            // 更新用にデータを整える
140            $arrUpdBlocData = array();
141
142            // delete実行
143            $arrRet = $objQuery->delete("dtb_blocposition",
144                                        "page_id = ? AND device_type_id = ?",
145                                        array($page_id, $device_type_id));
146
147            $arrTargetFlip = array_flip($this->arrTarget);
148
149            // POSTのデータを使いやすいように修正
150            for ($upd_cnt = 1; $upd_cnt <= $_POST['bloc_cnt']; $upd_cnt++) {
151                if (!isset($_POST['id_'.$upd_cnt])) {
152                    break;
153                }
154
155                // ブロック名称
156                $arrUpdBlocData[$upd_cnt]['name']       = $_POST['name_'.$upd_cnt];
157                // ブロックID
158                $arrUpdBlocData[$upd_cnt]['id']         = $_POST['id_'.$upd_cnt];
159                // ターゲットID
160                $arrUpdBlocData[$upd_cnt]['target_id']  = $arrTargetFlip[$_POST['target_id_'.$upd_cnt]];
161                // TOP座標
162                $arrUpdBlocData[$upd_cnt]['top']        = $_POST['top_'.$upd_cnt];
163                // 全ページ適用か
164                $arrUpdBlocData[$upd_cnt]['anywhere']   = $_POST['anywhere_'.$upd_cnt];
165                // 更新URL
166                $arrUpdBlocData[$upd_cnt]['update_url'] = $_SERVER['HTTP_REFERER'];
167            }
168
169
170            // ブロックの順序を取得し、更新を行う
171            foreach ($arrUpdBlocData as $key => $val) {
172                if ($arrUpdBlocData[$key]['target_id'] == TARGET_ID_UNUSED) {
173                    continue;
174                }
175
176                // ブロックの順序を取得
177                $arrUpdBlocData[$key]['bloc_row'] = $this->lfGetRowID($arrUpdBlocData, $val);
178
179                // insertデータ生成
180                $arrInsData = array('device_type_id' => $device_type_id,
181                                    'page_id' => $page_id,
182                                    'target_id' => $arrUpdBlocData[$key]['target_id'],
183                                    'bloc_id' => $arrUpdBlocData[$key]['id'],
184                                    'bloc_row' => $arrUpdBlocData[$key]['bloc_row'],
185                                    'anywhere' => $arrUpdBlocData[$key]['anywhere'] ? 1 : 0);
186                $count = $objQuery->getOne("SELECT COUNT(*) FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ? AND device_type_id = ?",
187                                           array($arrUpdBlocData[$key]['id'], $device_type_id));
188
189                if ($arrUpdBlocData[$key]['anywhere'] == 1) {
190                    $count = $objQuery->getOne("SELECT COUNT(*) FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ? AND device_type_id = ?",
191                                               array($arrUpdBlocData[$key]['id'], $device_type_id));
192                    if ($count != 0) {
193                        continue;
194                    }
195                } else {
196                    if ($count > 0) {
197                        $objQuery->query("DELETE FROM dtb_blocposition WHERE anywhere = 1 AND bloc_id = ? AND device_type_id = ?",
198                                         array($arrUpdBlocData[$key]['id'], $device_type_id));
199                    }
200                }
201                // SQL実行
202                $arrRet = $objQuery->insert("dtb_blocposition", $arrInsData);
203            }
204
205            // プレビュー処理 TODO 要リファクタリング(MODE if利用)
206            if ($this->getMode() == 'preview') {
207                $this->lfSetPreData($arrPageData, $objLayout);
208
209                $_SESSION['preview'] = "ON";
210
211                SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array("filename" => $arrPageData[0]["filename"]));
212                exit;
213
214            } else {
215                $arrQueryString = array("device_type_id" => $device_type_id, "page_id" => $page_id, "msg" => "on");
216                SC_Response_Ex::reload($arrQueryString, true);
217                exit;
218            }
219        break;
220
221        // データ削除処理
222        case 'delete':
223            //ベースデータでなければファイルを削除
224            if (!$objLayout->lfCheckBaseData($page_id, $device_type_id)) {
225                $objLayout->lfDelPageData($page_id, $device_type_id);
226                SC_Response_Ex::reload(array('device_type_id' => $device_type_id), true);
227                exit;
228            }
229        break;
230
231        default:
232        }
233
234        // ブロック情報を画面配置用に編集
235        $tpl_arrBloc = array();
236        $cnt = 0;
237        // 使用されているブロックデータを生成
238        foreach($arrBlocPos as $key => $val){
239            if ($val['page_id'] == $page_id) {
240                $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
241                $cnt++;
242            }
243        }
244        // 未使用のブロックデータを追加
245        foreach($arrBloc as $key => $val){
246            if (!$this->lfChkBloc($val, $tpl_arrBloc)) {
247                $val['target_id'] = TARGET_ID_UNUSED; // 未使用に追加する
248                $tpl_arrBloc = $this->lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt);
249                $cnt++;
250            }
251        }
252
253        $this->tpl_arrBloc = $tpl_arrBloc;
254        $this->bloc_cnt = count($tpl_arrBloc);
255        $this->page_id = $page_id;
256        $this->device_type_id = $device_type_id;
257
258        // ページ名称を取得
259        $arrPageData = $objLayout->lfGetPageData('page_id = ? AND device_type_id = ?', array($page_id, $device_type_id));
260        $this->arrPageData = $arrPageData[0];
261
262        global $GLOBAL_ERR;
263        $errCnt = 0;
264        if ($GLOBAL_ERR != "") {
265            $arrGlobalErr = explode("\n",$GLOBAL_ERR);
266            $errCnt = count($arrGlobalErr) - 8;
267            if ($errCnt < 0 ) {
268                $errCnt = 0;
269            }
270        }
271        $this->errCnt = $errCnt;
272    }
273
274    /**
275     * デストラクタ.
276     *
277     * @return void
278     */
279    function destroy() {
280        parent::destroy();
281    }
282
283    /**
284     * ブロック情報の配列を生成する.
285     *
286     * @param array $arrBloc Bloc情報
287     * @param array $tpl_arrBloc データをセットする配列
288     * @param array $val DBから取得したブロック情報
289     * @param integer $cnt 配列番号
290     * @return array データをセットした配列
291     */
292    function lfSetBlocData($arrBloc, $val, $tpl_arrBloc, $cnt) {
293
294        $tpl_arrBloc[$cnt]['target_id'] = $this->arrTarget[$val['target_id']];
295        $tpl_arrBloc[$cnt]['bloc_id'] = $val['bloc_id'];
296        $tpl_arrBloc[$cnt]['bloc_row'] =
297        isset($val['bloc_row']) ? $val['bloc_row'] : "";
298        $tpl_arrBloc[$cnt]['anywhere'] = $val['anywhere'];
299        if($val['anywhere'] == 1){
300            $tpl_arrBloc[$cnt]['anywhere_selected'] = 'checked="checked"';
301        }
302        foreach($arrBloc as $bloc_key => $bloc_val){
303            if ($bloc_val['bloc_id'] == $val['bloc_id']) {
304                $bloc_name = $bloc_val['bloc_name'];
305                break;
306            }
307        }
308        $tpl_arrBloc[$cnt]['name'] = $bloc_name;
309
310        return $tpl_arrBloc;
311    }
312
313    /**
314     * ブロックIDが配列に追加されているかのチェックを行う.
315     *
316     * @param array $arrBloc Bloc情報
317     * @param array $arrChkData チェックを行うデータ配列
318     * @return bool 存在する場合 true
319     */
320    function lfChkBloc($arrBloc, $arrChkData) {
321        foreach($arrChkData as $key => $val){
322            if ($val['bloc_id'] === $arrBloc['bloc_id'] ) {
323                // 配列に存在すればTrueを返す
324                return true;
325            }
326        }
327
328        // 配列に存在しなければFlaseを返す
329        return false;
330    }
331
332    /**
333     * ブロックIDが何番目に配置されているかを調べる.
334     *
335     * @param array $arrUpdData 更新情報
336     * @param array $arrObj チェックを行うデータ配列
337     * @return integer 順番
338     */
339    function lfGetRowID($arrUpdData, $arrObj){
340        $no = 0; // カウント用(同じデータが必ず1件あるので、初期値は0)
341
342        // 対象データが何番目に配置されているのかを取得する。
343        foreach ($arrUpdData as $key => $val) {
344            if ($val['target_id'] === $arrObj['target_id'] and $val['top'] <= $arrObj['top']){
345                $no++;
346            }
347        }
348        // 番号を返す
349        return $no;
350    }
351
352    /**
353     * プレビューするデータを DB に保存する.
354     *
355     * FIXME
356     *
357     * @param array $arrPageData ページ情報の配列
358     * @return void
359     */
360    function lfSetPreData($arrPageData, &$objLayout){
361        $objQuery = new SC_Query();     // DB操作オブジェクト
362        $sql = "";                      // データ更新SQL生成用
363        $ret = "";                      // データ更新結果格納用
364        $arrUpdData = array();          // 更新データ生成用
365        $filename = $arrPageData[0]['filename'];
366
367        $arrPreData = $objLayout->lfgetPageData(" page_id = ? " , array("0"));
368
369        // XXX tplファイルの削除
370        $del_tpl = USER_REALDIR . "templates/" . $filename . '.tpl';
371
372        if (file_exists($del_tpl)){
373            unlink($del_tpl);
374        }
375
376        // filename が空の場合にはMYページと判断
377        if($filename == ""){
378            $tplfile = TEMPLATE_REALDIR . "mypage/index";
379            $filename = 'mypage';
380        } else {
381            $tplfile = TEMPLATE_REALDIR . $filename;
382        }
383
384        // プレビュー用tplファイルのコピー
385        $copyTo = USER_REALDIR . "templates/preview/" . TEMPLATE_NAME . "/" . $filename . ".tpl";
386
387        if (!is_dir(dirname($copyTo))) {
388            mkdir(dirname($copyTo));
389        }
390
391        copy($tplfile . ".tpl", $copyTo);
392
393        // 更新データの取得
394        $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)" ;
395
396        $ret = $objQuery->getAll($sql, array($arrPageData[0]['page_id']));
397
398        // dbデータのコピー
399        $sql = " update dtb_pagelayout set ";
400        $sql .= "     page_name = ?";
401        $sql .= "     ,header_chk = ?";
402        $sql .= "     ,footer_chk = ?";
403        $sql .= "     ,url = ?";
404        $sql .= "     ,filename = ?";
405//      $sql .= "     ,anywhere = ?";
406        $sql .= " where page_id = 0";
407        var_dump($ret);
408                echo("####<br/>\n\n".__LINE__ ." in file:".__FILE__."<br/>\n\n ####");
409
410        $arrUpdData = array($ret[0]['page_id']
411        ,$ret[0]['page_id']
412        ,$ret[0]['page_id']
413        ,USER_DIR . "templates/" . TEMPLATE_NAME . "/"
414        ,$filename
415//      ,$ret[0]['anywhere']
416
417        );
418
419        $objQuery->query($sql,$arrUpdData);
420    }
421}
422?>
Note: See TracBrowser for help on using the repository browser.