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

Revision 20538, 15.0 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

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