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

Revision 20560, 11.1 KB checked in by t_yuo, 13 years ago (diff)

#948 (コンテンツ管理>CSV出力設定、デザイン管理 サブタイトルが欲しい)

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