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

Revision 19722, 11.5 KB checked in by nanasess, 13 years ago (diff)

#748(モバイル/スマートフォンのデザイン管理)

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