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

Revision 20812, 10.7 KB checked in by kimoto, 13 years ago (diff)

デザイン管理>ブロック編集のtplのとり方がおかしいので修正

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