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

Revision 20538, 10.9 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 * @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    }
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        // ページIDを取得
74        if (isset($_REQUEST['bloc_id']) && is_numeric($_REQUEST['bloc_id'])) {
75            $bloc_id = $_REQUEST['bloc_id'];
76        } else {
77            $bloc_id = null;
78        }
79        $this->bloc_id = $bloc_id;
80
81        // 端末種別IDを取得
82        if (isset($_REQUEST['device_type_id'])
83            && is_numeric($_REQUEST['device_type_id'])) {
84            $device_type_id = $_REQUEST['device_type_id'];
85        } else {
86            $device_type_id = DEVICE_TYPE_PC;
87        }
88
89        $this->objLayout = new SC_Helper_PageLayout_Ex();
90        $package_path = $this->objLayout->getTemplatePath($device_type_id) . BLOC_DIR;
91
92        // ブロック一覧を取得
93        $this->arrBlocList = $this->lfgetBlocData("device_type_id = ?", array($device_type_id));
94
95        // bloc_id が指定されている場合にはブロックデータの取得
96        if ($bloc_id != '') {
97            $arrBlocData = $this->lfGetBlocData("bloc_id = ? AND device_type_id = ?",
98                                                array($bloc_id, $device_type_id));
99
100            $tplPath = $package_path . $arrBlocData[0]['filename'] . '.tpl';
101
102            // テンプレートファイルの読み込み
103            $arrBlocData[0]['tpl_data'] = file_get_contents($tplPath);
104            $this->arrBlocData = $arrBlocData[0];
105        }
106
107        // メッセージ表示
108        if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
109            // 完了メッセージ
110            $this->tpl_onload="alert('登録が完了しました。');";
111        }
112
113        switch($this->getMode()) {
114        case 'preview':
115            // プレビューファイル作成
116            $prev_path = USER_INC_REALDIR . 'preview/bloc_preview.tpl';
117            // ディレクトリの作成
118            SC_Utils_Ex::sfMakeDir($prev_path);
119            $res = file_put_contents($prev_path, $_POST['bloc_html']);
120            if ($res === false) {
121                SC_Utils_Ex::sfDispException();
122            }
123
124            // プレビューデータ表示
125            $this->preview = 'on';
126            $this->arrBlocData['tpl_data'] = $_POST['bloc_html'];
127            $this->arrBlocData['tpl_path'] = $prev_path;
128            $this->arrBlocData['bloc_name'] = $_POST['bloc_name'];
129            $this->arrBlocData['filename'] = $_POST['filename'];
130            $this->text_row = $_POST['html_area_row'];
131            break;
132        case 'confirm':
133            $this->preview = 'off';
134            // エラーチェック
135            $this->arrErr = $this->lfErrorCheck($_POST);
136
137            // エラーがなければ更新処理を行う
138            if (count($this->arrErr) == 0) {
139                // DBへデータを更新する
140                $this->lfEntryBlocData($_POST, $device_type_id);
141
142                // 旧ファイルの削除
143                if (file_exists($tplPath)) {
144                    unlink($tplPath);
145                }
146
147                // ファイル作成
148                $new_bloc_path = $package_path . $_POST['filename'] . ".tpl";
149                // ディレクトリの作成
150                SC_Utils_Ex::sfMakeDir($new_bloc_path);
151                $res = file_put_contents($new_bloc_path, $_POST['bloc_html']);
152                if ($res === false) {
153                    SC_Utils_Ex::sfDispException();
154                }
155
156                $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?",
157                                                    array($_POST['filename'], $device_type_id));
158
159                $bloc_id = $arrBlocData[0]['bloc_id'];
160                $arrQueryString = array(
161                    'bloc_id' => $bloc_id,
162                    'device_type_id' => $device_type_id,
163                    'msg' => 'on',
164                );
165                $this->objDisplay->reload($arrQueryString, true);
166                exit;
167            }else{
168                // エラーがあれば入力時のデータを表示する
169                $this->arrBlocData = $_POST;
170            }
171            break;
172        case 'delete':
173            $this->preview = 'off';
174             // DBへデータを更新する
175            $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
176            $sql = "";                      // データ更新SQL生成用
177            $ret = "";                      // データ更新結果格納用
178            $arrDelData = array();          // 更新データ生成用
179
180            // 更新データ生成
181            $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
182
183            // bloc_id が空でない場合にはdeleteを実行
184            if ($_POST['bloc_id'] !== '') {
185                // SQL生成
186                $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ? AND device_type_id = ?";
187                // SQL実行
188                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
189
190                // ページに配置されているデータも削除する
191                $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ? AND device_type_id = ?";
192                // SQL実行
193                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
194
195                // ファイルの削除
196                if (file_exists($tplPath)) {
197                    unlink($tplPath);
198                }
199            }
200            $this->objDisplay->reload(array("device_type_id" => $device_type_id), true);
201            exit;
202            break;
203        default:
204            GC_Utils_Ex::gfPrintLog("MODEエラー:".$this->getMode());
205            break;
206        }
207        $this->device_type_id = $device_type_id;
208    }
209
210    /**
211     * デストラクタ.
212     *
213     * @return void
214     */
215    function destroy() {
216        parent::destroy();
217    }
218
219    /**
220     * ブロック情報を取得する.
221     *
222     * @param string $where Where句文
223     * @param array $arrVal Where句の絞込条件値
224     * @return array ブロック情報
225     */
226    function lfgetBlocData($where = '', $arrVal = array()){
227        $objQuery =& SC_Query_Ex::getSingletonInstance();
228        $objQuery->setOrder("bloc_id");
229        return $objQuery->select("*", "dtb_bloc", $where, $arrVal);
230    }
231
232    /**
233     * ブロック情報を更新する.
234     *
235     * @param array $arrData 更新データ
236     * @param integer $device_type_id 端末種別ID
237     * @return integer 更新結果
238     */
239    function lfEntryBlocData($arrData, $device_type_id){
240        $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
241        $sql = "";                      // データ更新SQL生成用
242        $ret = "";                      // データ更新結果格納用
243        $arrUpdData = array();          // 更新データ生成用
244        $arrChk = array();              // 排他チェック用
245
246        // 更新データ生成
247        $arrUpdData = array("bloc_name" => $arrData['bloc_name'],
248                            "tpl_path" => $arrData['filename'] . '.tpl',
249                            'filename' => $arrData['filename']);
250
251        // データが存在しているかチェックを行う
252        if($arrData['bloc_id'] !== ''){
253            $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?",
254                                           array($arrData['bloc_id'], $device_type_id));
255        }
256
257        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
258        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
259            // SQL生成
260            // FIXME device_type_id ごとの連番にする
261            $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id');
262            $arrUpdData['device_type_id'] = $device_type_id;
263            $arrUpdData['update_date'] = "now()";
264            $ret = $objQuery->insert('dtb_bloc', $arrUpdData);
265        } else {
266            $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?',
267                                     array($arrData['bloc_id'], $device_type_id));
268        }
269        return $ret;
270    }
271
272    /**
273     * 入力項目のエラーチェックを行う.
274     *
275     * @param array $arrData 入力データ
276     * @return array エラー情報
277     */
278    function lfErrorCheck($array) {
279        $objErr = new SC_CheckError_Ex($array);
280
281        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
282        $objErr->doFunc(array("ファイル名", 'filename', STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
283
284        // 同一のファイル名が存在している場合にはエラー
285        if(!isset($objErr->arrErr['filename']) && $array['filename'] !== ''){
286            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
287
288            if (count($arrChk[0]) >= 1 && $arrChk[0]['bloc_id'] != $array['bloc_id']) {
289                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
290            }
291        }
292
293        return $objErr->arrErr;
294    }
295}
296?>
Note: See TracBrowser for help on using the repository browser.