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

Revision 19661, 11.1 KB checked in by nanasess, 13 years ago (diff)

source:branches/camp/camp-2_5-E のマージ

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