source: branches/feature-module-update/data/class/pages/admin/design/LC_Page_Admin_Design_Bloc.php @ 16582

Revision 16582, 11.4 KB checked in by nanasess, 17 years ago (diff)

ライセンス表記変更

  • Property svn:keywords set to "Id Revision Date"
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 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/LC_Page.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 {
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        $objView = new SC_AdminView();
62        $this->objLayout = new SC_Helper_PageLayout_Ex();
63
64        // 認証可否の判定
65        $objSess = new SC_Session();
66        SC_Utils_Ex::sfIsSuccess($objSess);
67
68        // ブロック一覧を取得
69        $this->arrBlocList = $this->lfgetBlocData();
70
71        // ブロックIDを取得
72        if (isset($_POST['bloc_id'])) {
73            $bloc_id = $_POST['bloc_id'];
74        }else if (isset($_GET['bloc_id'])) {
75            $bloc_id = $_GET['bloc_id'];
76        }else{
77            $bloc_id = '';
78        }
79        $this->bloc_id = $bloc_id;
80
81        // bloc_id が指定されている場合にはブロックデータの取得
82        if ($bloc_id != '') {
83            $arrBlocData = $this->lfgetBlocData(" bloc_id = ? " , array($bloc_id));
84
85            // ユーザー作成ブロックが存在する場合
86            if (is_file(USER_PATH . $arrBlocData[0]['tpl_path'])) {
87                $arrBlocData[0]['tpl_path'] = USER_PATH
88                    . $arrBlocData[0]['tpl_path'];
89
90            // 存在しない場合は指定テンプレートのブロックを取得
91            } else {
92                $arrBlocData[0]['tpl_path'] = TEMPLATE_DIR
93                    . $arrBlocData[0]['tpl_path'];
94            }
95
96            // テンプレートファイルの読み込み
97            $arrBlocData[0]['tpl_data'] = file_get_contents($arrBlocData[0]['tpl_path']);
98            $this->arrBlocData = $arrBlocData[0];
99        }
100
101        // メッセージ表示
102        if (isset($_GET['msg']) && $_GET['msg'] == "on") {
103            // 完了メッセージ
104            $this->tpl_onload="alert('登録が完了しました。');";
105        }
106
107        if (!isset($_POST['mode'])) $_POST['mode'] = "";
108
109        // プレビュー表示
110        if ($_POST['mode'] == "preview") {
111            // プレビューファイル作成
112            $prev_path = USER_INC_PATH . 'preview/bloc_preview.tpl';
113            // TODO 一応, is_write 等でチェックすべき?
114            $fp = fopen($prev_path,"w");
115            fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと...
116            fclose($fp);
117
118            // プレビューデータ表示
119            $this->preview = "on";
120            $this->arrBlocData['tpl_data'] = $_POST['bloc_html'];
121            $this->arrBlocData['tpl_path'] = $prev_path;
122            $this->arrBlocData['bloc_name'] = $_POST['bloc_name'];
123            $this->arrBlocData['filename'] = $_POST['filename'];
124            $this->text_row = $_POST['html_area_row'];
125        }else{
126            $this->preview = "off";
127        }
128
129        // データ登録処理
130        if ($_POST['mode'] == 'confirm') {
131
132            // エラーチェック
133            $this->arrErr = $this->lfErrorCheck($_POST);
134
135            // エラーがなければ更新処理を行う
136            if (count($this->arrErr) == 0) {
137                // DBへデータを更新する
138                $this->lfEntryBlocData($_POST);
139
140                // ファイルの削除
141                //$del_file=BLOC_PATH . $arrBlocData[0]['filename']. '.tpl';
142                $del_file = USER_PATH . $arrBlocData[0]['tpl_path'];
143                if (file_exists($del_file)) {
144                    unlink($del_file);
145                }
146
147                // ファイル作成
148                $fp = fopen(USER_PATH . BLOC_DIR . $_POST['filename'] . '.tpl',"w");
149                fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと...
150                fclose($fp);
151
152                $arrBlocData = $this->lfgetBlocData(" filename = ? " , array($_POST['filename']));
153
154                $bloc_id = $arrBlocData[0]['bloc_id'];
155                $this->sendRedirect($this->getLocation("./bloc.php",
156                                            array("bloc_id" => $bloc_id,
157                                                  "msg" => "on")));
158            }else{
159                // エラーがあれば入力時のデータを表示する
160                $this->arrBlocData = $_POST;
161            }
162        }
163
164        // データ削除処理
165        if ($_POST['mode'] == 'delete') {
166
167            // DBへデータを更新する
168            $objDBConn = new SC_DbConn;     // DB操作オブジェクト
169            $sql = "";                      // データ更新SQL生成用
170            $ret = "";                      // データ更新結果格納用
171            $arrDelData = array();          // 更新データ生成用
172
173            // 更新データ生成
174            $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
175
176            // bloc_id が空でない場合にはdeleteを実行
177            if ($_POST['bloc_id'] !== '') {
178                // SQL生成
179                $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ?";
180                // SQL実行
181                $ret = $objDBConn->query($sql,array($_POST['bloc_id']));
182
183                // ページに配置されているデータも削除する
184                $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ?";
185                // SQL実行
186                $ret = $objDBConn->query($sql,array($_POST['bloc_id']));
187
188                // ファイルの削除
189                $del_file = BLOC_PATH . $arrBlocData[0]['filename']. '.tpl';
190                if(file_exists($del_file)){
191                    unlink($del_file);
192                }
193            }
194            $this->sendRedirect($this->getLocation("./bloc.php"));
195        }
196
197        // 画面の表示
198        $objView->assignobj($this);
199        $objView->display(MAIN_FRAME);
200    }
201
202    /**
203     * デストラクタ.
204     *
205     * @return void
206     */
207    function destroy() {
208        parent::destroy();
209    }
210
211    /**
212     * ブロック情報を取得する.
213     *
214     * @param string $where Where句文
215     * @param array $arrVal Where句の絞込条件値
216     * @return array ブロック情報
217     */
218    function lfgetBlocData($where = '', $arrVal = ''){
219        $objDBConn = new SC_DbConn;     // DB操作オブジェクト
220        $sql = "";                      // データ取得SQL生成用
221        $arrRet = array();              // データ取得用
222
223        // SQL生成
224        $sql = " SELECT ";
225        $sql .= "   bloc_id";
226        $sql .= "   ,bloc_name";
227        $sql .= "   ,tpl_path";
228        $sql .= "   ,filename";
229        $sql .= "   ,create_date";
230        $sql .= "   ,update_date";
231        $sql .= "   ,php_path";
232        $sql .= "   ,del_flg";
233        $sql .= " FROM ";
234        $sql .= "   dtb_bloc";
235
236        // where句の指定があれば追加
237        if ($where != '') {
238            $sql .= " WHERE " . $where;
239        }
240
241        $sql .= " ORDER BY  bloc_id";
242
243        $arrRet = $objDBConn->getAll($sql, $arrVal);
244
245        return $arrRet;
246    }
247
248    /**
249     * ブロック情報を更新する.
250     *
251     * @param array $arrData 更新データ
252     * @return integer 更新結果
253     */
254    function lfEntryBlocData($arrData){
255        $objDBConn = new SC_DbConn;     // DB操作オブジェクト
256        $sql = "";                      // データ更新SQL生成用
257        $ret = "";                      // データ更新結果格納用
258        $arrUpdData = array();          // 更新データ生成用
259        $arrChk = array();              // 排他チェック用
260
261        // 更新データ生成
262        $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
263
264        // データが存在しているかチェックを行う
265        if($arrData['bloc_id'] !== ''){
266            $arrChk = $this->lfgetBlocData("bloc_id = ?", array($arrData['bloc_id']));
267        }
268
269        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
270        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
271            // SQL生成
272            $sql = " INSERT INTO dtb_bloc";
273            $sql .= " ( ";
274            $sql .= "     bloc_name ";      // ブロック名称
275            $sql .= "     ,tpl_path ";      // テンプレート保存先
276            $sql .= "     ,filename ";      // ファイル名称
277            $sql .= "     ,create_date ";   // 作成日
278            $sql .= "     ,update_date ";   // 更新日
279            $sql .= " ) VALUES ( ?,?,?,now(),now() )";
280            $sql .= " ";
281        }else{
282            // データが存在してる場合にはアップデートを行う
283            // SQL生成
284            $sql = " UPDATE dtb_bloc";
285            $sql .= " SET";
286            $sql .= "     bloc_name = ? ";  // ブロック名称
287            $sql .= "     ,tpl_path = ? ";  // テンプレート保存先
288            $sql .= "     ,filename = ? ";  // テンプレートファイル名
289            $sql .= "     ,update_date = now()";
290            $sql .= " WHERE bloc_id = ?";
291            $sql .= " ";
292
293            // 更新データにブロックIDを追加
294            array_push($arrUpdData, $arrData['bloc_id']);
295        }
296
297        // SQL実行
298        $ret = $objDBConn->query($sql,$arrUpdData);
299
300        return $ret;
301
302    }
303
304    /**
305     * 入力項目のエラーチェックを行う.
306     *
307     * @param array $arrData 入力データ
308     * @return array エラー情報
309     */
310    function lfErrorCheck($array) {
311        $objErr = new SC_CheckError($array);
312
313        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
314        $objErr->doFunc(array("ファイル名", "filename", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK"));
315
316        // 同一のファイル名が存在している場合にはエラー
317        if(!isset($objErr->arrErr['filename']) and $array['filename'] !== ''){
318            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
319
320            if (count($arrChk[0]) >= 1 and $arrChk[0]['bloc_id'] != $array['bloc_id']) {
321                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
322            }
323        }
324
325        return $objErr->arrErr;
326    }
327}
328?>
Note: See TracBrowser for help on using the repository browser.