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

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

#627(ソース整形・ソースコメントの改善)

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