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

Revision 19795, 11.2 KB checked in by Seasoft, 13 years ago (diff)

#825(ページクラスとテンプレートのファイル名を一致させる)
#748(モバイル/スマートフォンのデザイン管理機能)

  • 新規ブロックを登録できない不具合を改修
  • 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 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Design_Bloc extends LC_Page_Admin {
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    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process() {
61        $this->action();
62        $this->sendResponse();
63    }
64
65    /**
66     * Page のアクション.
67     *
68     * FIXME テンプレートパスの取得方法を要修正
69     *
70     * @return void
71     */
72    function action() {
73
74        // 認証可否の判定
75        $objSess = new SC_Session();
76        SC_Utils_Ex::sfIsSuccess($objSess);
77
78        // ページIDを取得
79        if (isset($_REQUEST['bloc_id']) && is_numeric($_REQUEST['bloc_id'])) {
80            $bloc_id = $_REQUEST['bloc_id'];
81        } else {
82            $bloc_id = null;
83        }
84        $this->bloc_id = $bloc_id;
85
86        // 端末種別IDを取得
87        if (isset($_REQUEST['device_type_id'])
88            && is_numeric($_REQUEST['device_type_id'])) {
89            $device_type_id = $_REQUEST['device_type_id'];
90        } else {
91            $device_type_id = DEVICE_TYPE_PC;
92        }
93
94        $this->objLayout = new SC_Helper_PageLayout_Ex();
95        $package_path = $this->objLayout->getTemplatePath($device_type_id) . BLOC_DIR;
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        if (!isset($_POST['mode'])) $_POST['mode'] = "";
119
120        switch($_POST['mode']) {
121        case 'preview':
122            // プレビューファイル作成
123            $prev_path = USER_INC_PATH . 'preview/bloc_preview.tpl';
124            // ディレクトリの作成
125            SC_Utils::sfMakeDir($prev_path);
126            $res = file_put_contents($new_bloc_path, $_POST['bloc_html']);
127            if ($res === false) {
128                SC_Utils_Ex::sfDispException();
129            }
130
131            // プレビューデータ表示
132            $this->preview = "on";
133            $this->arrBlocData['tpl_data'] = $_POST['bloc_html'];
134            $this->arrBlocData['tpl_path'] = $prev_path;
135            $this->arrBlocData['bloc_name'] = $_POST['bloc_name'];
136            $this->arrBlocData['filename'] = $_POST['filename'];
137            $this->text_row = $_POST['html_area_row'];
138            break;
139        case 'confirm':
140            $this->preview = "off";
141            // エラーチェック
142            $this->arrErr = $this->lfErrorCheck($_POST);
143
144            // エラーがなければ更新処理を行う
145            if (count($this->arrErr) == 0) {
146                // DBへデータを更新する
147                $this->lfEntryBlocData($_POST, $device_type_id);
148
149                // 旧ファイルの削除
150                if (file_exists($tplPath)) {
151                    unlink($tplPath);
152                }
153
154                // ファイル作成
155                $new_bloc_path = $package_path . $_POST['filename'] . ".tpl";
156                // ディレクトリの作成
157                SC_Utils::sfMakeDir($new_bloc_path);
158                $res = file_put_contents($new_bloc_path, $_POST['bloc_html']);
159                if ($res === false) {
160                    SC_Utils_Ex::sfDispException();
161                }
162
163                $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?",
164                                                    array($_POST['filename'], $device_type_id));
165
166                $bloc_id = $arrBlocData[0]['bloc_id'];
167                $this->objDisplay->redirect($this->getLocation("./bloc.php",
168                                            array("bloc_id" => $bloc_id,
169                                                  "device_type_id" => $device_type_id,
170                                                  "msg" => "on")));
171                exit;
172            }else{
173                // エラーがあれば入力時のデータを表示する
174                $this->arrBlocData = $_POST;
175            }
176            break;
177        case 'delete':
178            $this->preview = "off";
179             // DBへデータを更新する
180            $objQuery = new SC_Query();     // DB操作オブジェクト
181            $sql = "";                      // データ更新SQL生成用
182            $ret = "";                      // データ更新結果格納用
183            $arrDelData = array();          // 更新データ生成用
184
185            // 更新データ生成
186            $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
187
188            // bloc_id が空でない場合にはdeleteを実行
189            if ($_POST['bloc_id'] !== '') {
190                // SQL生成
191                $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ? AND device_type_id = ?";
192                // SQL実行
193                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
194
195                // ページに配置されているデータも削除する
196                $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ? AND device_type_id = ?";
197                // SQL実行
198                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
199
200                // ファイルの削除
201                if (file_exists($tplPath)) {
202                    unlink($tplPath);
203                }
204            }
205            $this->objDisplay->redirect($this->getLocation("./bloc.php",
206                                                           array("device_type_id" => $device_type_id)));
207            exit;
208            break;
209        default:
210            if(isset($_POST['mode'])) {
211               GC_Utils::gfPrintLog("MODEエラー:".$_POST['mode']);
212            }
213            break;
214        }
215        $this->device_type_id = $device_type_id;
216    }
217
218    /**
219     * デストラクタ.
220     *
221     * @return void
222     */
223    function destroy() {
224        parent::destroy();
225    }
226
227    /**
228     * ブロック情報を取得する.
229     *
230     * @param string $where Where句文
231     * @param array $arrVal Where句の絞込条件値
232     * @return array ブロック情報
233     */
234    function lfgetBlocData($where = '', $arrVal = array()){
235        $objQuery =& SC_Query::getSingletonInstance();
236        $objQuery->setOrder("bloc_id");
237        return $objQuery->select("*", "dtb_bloc", $where, $arrVal);
238    }
239
240    /**
241     * ブロック情報を更新する.
242     *
243     * @param array $arrData 更新データ
244     * @param integer $device_type_id 端末種別ID
245     * @return integer 更新結果
246     */
247    function lfEntryBlocData($arrData, $device_type_id){
248        $objQuery = new SC_Query();     // DB操作オブジェクト
249        $sql = "";                      // データ更新SQL生成用
250        $ret = "";                      // データ更新結果格納用
251        $arrUpdData = array();          // 更新データ生成用
252        $arrChk = array();              // 排他チェック用
253
254        // 更新データ生成
255        $arrUpdData = array("bloc_name" => $arrData['bloc_name'],
256                            "tpl_path" => $arrData['filename'] . '.tpl',
257                            "filename" => $arrData['filename']);
258
259        // データが存在しているかチェックを行う
260        if($arrData['bloc_id'] !== ''){
261            $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?",
262                                           array($arrData['bloc_id'], $device_type_id));
263        }
264
265        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
266        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
267            // SQL生成
268            // FIXME device_type_id ごとの連番にする
269            $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id');
270            $arrUpdData['device_type_id'] = $device_type_id;
271            $arrUpdData['create_date'] = "now()";
272            $ret = $objQuery->insert('dtb_bloc', $arrUpdData);
273        } else {
274            $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?',
275                                     array($arrData['bloc_id'], $device_type_id));
276        }
277        return $ret;
278    }
279
280    /**
281     * 入力項目のエラーチェックを行う.
282     *
283     * @param array $arrData 入力データ
284     * @return array エラー情報
285     */
286    function lfErrorCheck($array) {
287        $objErr = new SC_CheckError($array);
288
289        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
290        $objErr->doFunc(array("ファイル名", "filename", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK"));
291
292        // 同一のファイル名が存在している場合にはエラー
293        if(!isset($objErr->arrErr['filename']) and $array['filename'] !== ''){
294            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
295
296            if (count($arrChk[0]) >= 1 and $arrChk[0]['bloc_id'] != $array['bloc_id']) {
297                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
298            }
299        }
300
301        return $objErr->arrErr;
302    }
303}
304?>
Note: See TracBrowser for help on using the repository browser.