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

Revision 21693, 13.1 KB checked in by h_yoshimoto, 12 years ago (diff)

#1692 フックポイント名を変更

  • 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_subno_edit = 'bloc';
48        $this->text_row = 13;
49        $this->tpl_subno = 'bloc';
50        $this->tpl_mainno = 'design';
51        $this->tpl_maintitle = 'デザイン管理';
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     * @return void
71     */
72    function action() {
73        // フックポイント.
74        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
75        $objPlugin->doAction('LC_Page_Admin_Design_Bloc_before', array($this));
76
77        $objFormParam = new SC_FormParam_Ex();
78        $this->lfInitParam($objFormParam);
79        $objFormParam->setParam($_REQUEST);
80        $objFormParam->convParam();
81        $this->arrErr = $objFormParam->checkError();
82        $is_error = (!SC_Utils_Ex::isBlank($this->arrErr));
83
84        $this->bloc_id = $objFormParam->getValue('bloc_id');
85        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
86
87        $objLayout = new SC_Helper_PageLayout_Ex();
88
89        switch ($this->getMode()) {
90            // 登録/更新
91            case 'confirm':
92                if (!$is_error) {
93                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objLayout);
94                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
95                        $result = $this->doRegister($objFormParam, $objLayout);
96                        if ($result !== false) {
97                            $arrPram = array(
98                                'bloc_id' => $result,
99                                'device_type_id' => $this->device_type_id,
100                                'msg' => 'on',
101                            );
102                            // フックポイント.
103                            $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
104                            $objPlugin->doAction('LC_Page_Admin_Design_Bloc_confirm', array($this));
105
106                            SC_Response_Ex::reload($arrPram, true);
107                            exit;
108                        }
109                    }
110                }
111                break;
112
113            // 削除
114            case 'delete':
115                if (!$is_error) {
116                    if ($this->doDelete($objFormParam, $objLayout)) {
117                        $arrPram = array(
118                            'device_type_id' => $this->device_type_id,
119                            'msg' => 'on',
120                        );
121                        // フックポイント.
122                        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
123                        $objPlugin->doAction('LC_Page_Admin_Design_Bloc_delete', array($this));
124
125                        SC_Response_Ex::reload($arrPram, true);
126                        exit;
127                    }
128                }
129                break;
130
131            default:
132                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
133                    // 完了メッセージ
134                    $this->tpl_onload = "alert('登録が完了しました。');";
135                }
136                break;
137        }
138
139        if (!$is_error) {
140            // ブロック一覧を取得
141            $this->arrBlocList = $objLayout->getBlocs($this->device_type_id);
142            // bloc_id が指定されている場合にはブロックデータの取得
143            if (!SC_Utils_Ex::isBlank($this->bloc_id)) {
144                $arrBloc = $this->getBlocTemplate($this->device_type_id, $this->bloc_id, $objLayout);
145                $objFormParam->setParam($arrBloc);
146            }
147        } else {
148            // 画面にエラー表示しないため, ログ出力
149            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
150        }
151        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
152        $this->arrForm = $objFormParam->getFormParamList();
153
154        // フックポイント.
155        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
156        $objPlugin->doAction('LC_Page_Admin_Design_Bloc_after', array($this));
157    }
158
159    /**
160     * デストラクタ.
161     *
162     * @return void
163     */
164    function destroy() {
165        parent::destroy();
166    }
167
168    /**
169     * パラメーター情報の初期化
170     *
171     * @param object $objFormParam SC_FormParamインスタンス
172     * @return void
173     */
174    function lfInitParam(&$objFormParam) {
175        $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
176        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
177        $objFormParam->addParam('ブロック名', 'bloc_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
178        $objFormParam->addParam('ファイル名', 'filename', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
179        $objFormParam->addParam('ブロックデータ', 'bloc_html');
180    }
181
182    /**
183     * ブロックのテンプレートを取得する.
184     *
185     * @param integer $device_type_id 端末種別ID
186     * @param integer $bloc_id ブロックID
187     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
188     * @return array ブロック情報の配列
189     */
190    function getBlocTemplate($device_type_id, $bloc_id, &$objLayout) {
191        $arrBloc = $objLayout->getBlocs($device_type_id, 'bloc_id = ?', array($bloc_id));
192        if (SC_Utils_Ex::isAbsoluteRealPath($arrBloc[0]['tpl_path'])) {
193            $tpl_path = $arrBloc[0]['tpl_path'];
194        } else {
195            $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . BLOC_DIR . $arrBloc[0]['tpl_path'];
196        }
197        if (file_exists($tpl_path)) {
198            $arrBloc[0]['bloc_html'] = file_get_contents($tpl_path);
199        }
200        return $arrBloc[0];
201    }
202
203    /**
204     * 登録を実行する.
205     *
206     * ファイルの作成に失敗した場合は, エラーメッセージを出力し,
207     * データベースをロールバックする.
208     *
209     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
210     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
211     * @return integer|boolean 登録が成功した場合, 登録したブロックID;
212     *                         失敗した場合 false
213     */
214    function doRegister(&$objFormParam, &$objLayout) {
215        $arrParams = $objFormParam->getHashArray();
216
217        $objQuery =& SC_Query_Ex::getSingletonInstance();
218        $objQuery->begin();
219
220        // blod_id が空の場合は新規登録
221        $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']);
222        $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
223        // 既存データの重複チェック
224        if (!$is_new) {
225            $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id']));
226
227            // 既存のファイルが存在する場合は削除しておく
228            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
229            if (file_exists($exists_file)) {
230                unlink($exists_file);
231            }
232        }
233
234        $table = 'dtb_bloc';
235        $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams);
236        $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl';
237        $arrValues['update_date'] = 'CURRENT_TIMESTAMP';
238
239        // 新規登録
240        if ($is_new || SC_Utils_Ex::isBlank($arrExists)) {
241            $objQuery->setOrder('');
242            $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?',
243                                                       array($arrValues['device_type_id']));
244            $arrValues['create_date'] = 'CURRENT_TIMESTAMP';
245            $objQuery->insert($table, $arrValues);
246        }
247        // 更新
248        else {
249            $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?',
250                              array($arrValues['bloc_id'], $arrValues['device_type_id']));
251        }
252
253        $bloc_path = $bloc_dir . $arrValues['tpl_path'];
254        if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $arrParams['bloc_html'])) {
255            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />';
256            $objQuery->rollback();
257            return false;
258        }
259
260        $objQuery->commit();
261        return $arrValues['bloc_id'];
262    }
263
264    /**
265     * 削除を実行する.
266     *
267     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
268     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
269     * @return boolean 登録が成功した場合 true; 失敗した場合 false
270     */
271    function doDelete(&$objFormParam, &$objLayout) {
272        $arrParams = $objFormParam->getHashArray();
273        $objQuery =& SC_Query_Ex::getSingletonInstance();
274        $objQuery->begin();
275
276        $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1',
277                                          array($arrParams['bloc_id']));
278        $is_error = false;
279        if (!SC_Utils_Ex::isBlank($arrExists)) {
280            $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?',
281                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
282            $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?',
283                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
284
285            $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
286            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
287
288            // ファイルの削除
289            if (file_exists($exists_file)) {
290                if (!unlink($exists_file)) {
291                    $is_error = true;
292                }
293            }
294        } else {
295            $is_error = true;
296        }
297
298        if ($is_error) {
299            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />';
300            $objQuery->rollback();
301            return false;
302        }
303        $objQuery->commit();
304        return true;
305    }
306
307    /**
308     * エラーチェックを行う.
309     *
310     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
311     * @return array エラーメッセージの配列
312     */
313    function lfCheckError(&$objFormParam, &$arrErr, &$objLayout) {
314        $arrParams = $objFormParam->getHashArray();
315        $objErr = new SC_CheckError_Ex($arrParams);
316        $objErr->arrErr =& $arrErr;
317        $objErr->doFunc(array('ブロック名', 'bloc_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
318        $objErr->doFunc(array('ファイル名', 'filename', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD'));
319
320        $where = 'filename = ?';
321        $arrValues = array($arrParams['filename']);
322
323        // 変更の場合は自ブロックを除外
324        if (!SC_Utils_Ex::isBlank($arrParams['bloc_id'])) {
325            $where .= ' AND bloc_id <> ?';
326            $arrValues[] = $arrParams['bloc_id'];
327        }
328        $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues);
329        if (!SC_Utils_Ex::isBlank($arrBloc)) {
330            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />';
331        }
332        return $objErr->arrErr;
333    }
334}
Note: See TracBrowser for help on using the repository browser.