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

Revision 20618, 10.3 KB checked in by kotani, 13 years ago (diff)

#920 (デザイン管理でプレビューを押すとシステムエラー)

  • PC以外のデバイスではプレビューできないようにした
  • レイアウト設定以外ではプレビューできないようにした
  • 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 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex {
35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'design/bloc.tpl';
47        $this->tpl_subnavi = 'design/subnavi.tpl';
48        $this->tpl_subno_edit = 'bloc';
49        $this->text_row = 13;
50        $this->tpl_subno = 'bloc';
51        $this->tpl_mainno = 'design';
52        $this->tpl_subtitle = 'ブロック設定';
53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
70     * FIXME テンプレートパスの取得方法を要修正
71     *
72     * @return void
73     */
74    function action() {
75        // ページIDを取得
76        if (isset($_REQUEST['bloc_id']) && is_numeric($_REQUEST['bloc_id'])) {
77            $bloc_id = $_REQUEST['bloc_id'];
78        } else {
79            $bloc_id = null;
80        }
81        $this->bloc_id = $bloc_id;
82
83        // 端末種別IDを取得
84        if (isset($_REQUEST['device_type_id'])
85            && is_numeric($_REQUEST['device_type_id'])) {
86            $device_type_id = $_REQUEST['device_type_id'];
87        } else {
88            $device_type_id = DEVICE_TYPE_PC;
89        }
90
91        $this->objLayout = new SC_Helper_PageLayout_Ex();
92        $package_path = $this->objLayout->getTemplatePath($device_type_id) . BLOC_DIR;
93
94        //サブタイトルの追加
95        $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id];
96
97        // ブロック一覧を取得
98        $this->arrBlocList = $this->lfgetBlocData("device_type_id = ?", array($device_type_id));
99
100        // bloc_id が指定されている場合にはブロックデータの取得
101        if ($bloc_id != '') {
102            $arrBlocData = $this->lfGetBlocData("bloc_id = ? AND device_type_id = ?",
103                                                array($bloc_id, $device_type_id));
104
105            $tplPath = $package_path . $arrBlocData[0]['filename'] . '.tpl';
106
107            // テンプレートファイルの読み込み
108            $arrBlocData[0]['tpl_data'] = file_get_contents($tplPath);
109            $this->arrBlocData = $arrBlocData[0];
110        }
111
112        // メッセージ表示
113        if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
114            // 完了メッセージ
115            $this->tpl_onload="alert('登録が完了しました。');";
116        }
117
118        switch($this->getMode()) {
119        case 'confirm':
120            // エラーチェック
121            $this->arrErr = $this->lfErrorCheck($_POST);
122
123            // エラーがなければ更新処理を行う
124            if (count($this->arrErr) == 0) {
125                // DBへデータを更新する
126                $this->lfEntryBlocData($_POST, $device_type_id);
127
128                // 旧ファイルの削除
129                if (file_exists($tplPath)) {
130                    unlink($tplPath);
131                }
132
133                // ファイル作成
134                $new_bloc_path = $package_path . $_POST['filename'] . ".tpl";
135                // ディレクトリの作成
136                SC_Utils_Ex::sfMakeDir($new_bloc_path);
137                $res = file_put_contents($new_bloc_path, $_POST['bloc_html']);
138                if ($res === false) {
139                    SC_Utils_Ex::sfDispException();
140                }
141
142                $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?",
143                                                    array($_POST['filename'], $device_type_id));
144
145                $bloc_id = $arrBlocData[0]['bloc_id'];
146                $arrQueryString = array(
147                    'bloc_id' => $bloc_id,
148                    'device_type_id' => $device_type_id,
149                    'msg' => 'on',
150                );
151                $this->objDisplay->reload($arrQueryString, true);
152                exit;
153            }else{
154                // エラーがあれば入力時のデータを表示する
155                $this->arrBlocData = $_POST;
156            }
157            break;
158        case 'delete':
159             // DBへデータを更新する
160            $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
161            $sql = "";                      // データ更新SQL生成用
162            $ret = "";                      // データ更新結果格納用
163            $arrDelData = array();          // 更新データ生成用
164
165            // 更新データ生成
166            $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
167
168            // bloc_id が空でない場合にはdeleteを実行
169            if ($_POST['bloc_id'] !== '') {
170                // SQL生成
171                $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ? AND device_type_id = ?";
172                // SQL実行
173                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
174
175                // ページに配置されているデータも削除する
176                $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ? AND device_type_id = ?";
177                // SQL実行
178                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
179
180                // ファイルの削除
181                if (file_exists($tplPath)) {
182                    unlink($tplPath);
183                }
184            }
185            $this->objDisplay->reload(array("device_type_id" => $device_type_id), true);
186            exit;
187            break;
188        default:
189            GC_Utils_Ex::gfPrintLog("MODEエラー:".$this->getMode());
190            break;
191        }
192        $this->device_type_id = $device_type_id;
193    }
194
195    /**
196     * デストラクタ.
197     *
198     * @return void
199     */
200    function destroy() {
201        parent::destroy();
202    }
203
204    /**
205     * ブロック情報を取得する.
206     *
207     * @param string $where Where句文
208     * @param array $arrVal Where句の絞込条件値
209     * @return array ブロック情報
210     */
211    function lfgetBlocData($where = '', $arrVal = array()){
212        $objQuery =& SC_Query_Ex::getSingletonInstance();
213        $objQuery->setOrder("bloc_id");
214        return $objQuery->select("*", "dtb_bloc", $where, $arrVal);
215    }
216
217    /**
218     * ブロック情報を更新する.
219     *
220     * @param array $arrData 更新データ
221     * @param integer $device_type_id 端末種別ID
222     * @return integer 更新結果
223     */
224    function lfEntryBlocData($arrData, $device_type_id){
225        $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
226        $sql = "";                      // データ更新SQL生成用
227        $ret = "";                      // データ更新結果格納用
228        $arrUpdData = array();          // 更新データ生成用
229        $arrChk = array();              // 排他チェック用
230
231        // 更新データ生成
232        $arrUpdData = array("bloc_name" => $arrData['bloc_name'],
233                            "tpl_path" => $arrData['filename'] . '.tpl',
234                            'filename' => $arrData['filename']);
235
236        // データが存在しているかチェックを行う
237        if($arrData['bloc_id'] !== ''){
238            $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?",
239                                           array($arrData['bloc_id'], $device_type_id));
240        }
241
242        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
243        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
244            // SQL生成
245            // FIXME device_type_id ごとの連番にする
246            $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id');
247            $arrUpdData['device_type_id'] = $device_type_id;
248            $arrUpdData['update_date'] = "now()";
249            $ret = $objQuery->insert('dtb_bloc', $arrUpdData);
250        } else {
251            $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?',
252                                     array($arrData['bloc_id'], $device_type_id));
253        }
254        return $ret;
255    }
256
257    /**
258     * 入力項目のエラーチェックを行う.
259     *
260     * @param array $arrData 入力データ
261     * @return array エラー情報
262     */
263    function lfErrorCheck($array) {
264        $objErr = new SC_CheckError_Ex($array);
265
266        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
267        $objErr->doFunc(array("ファイル名", 'filename', STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
268
269        // 同一のファイル名が存在している場合にはエラー
270        if(!isset($objErr->arrErr['filename']) && $array['filename'] !== ''){
271            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
272
273            if (count($arrChk[0]) >= 1 && $arrChk[0]['bloc_id'] != $array['bloc_id']) {
274                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
275            }
276        }
277
278        return $objErr->arrErr;
279    }
280}
281?>
Note: See TracBrowser for help on using the repository browser.