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

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