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

Revision 21867, 12.2 KB checked in by nakanishi, 12 years ago (diff)

#1831 Copyright Update

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