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

Revision 20970, 11.9 KB checked in by Seasoft, 13 years ago (diff)

#1288 (「-er」カタカナ表記の統一)

  • 現状で混在が発生しているもののみ改修。
  • 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';
26require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php';
27
28/**
29 * ブロック編集 のページクラス.
30 *
31 * @package Page
32 * @author LOCKON CO.,LTD.
33 * @version $Id$
34 */
35class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex {
36
37    // }}}
38    // {{{ functions
39
40    /**
41     * Page を初期化する.
42     *
43     * @return void
44     */
45    function init() {
46        parent::init();
47        $this->tpl_mainpage = 'design/bloc.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_maintitle = 'デザイン管理';
53        $this->tpl_subtitle = 'ブロック設定';
54        $masterData = new SC_DB_MasterData_Ex();
55        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
56    }
57
58    /**
59     * Page のプロセス.
60     *
61     * @return void
62     */
63    function process() {
64        $this->action();
65        $this->sendResponse();
66    }
67
68    /**
69     * Page のアクション.
70     *
71     * @return void
72     */
73    function action() {
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                        SC_Response_Ex::reload(array('bloc_id' => $result,
95                                                     'device_type_id' => $this->device_type_id,
96                                                     'msg' => 'on'), true);
97                        exit;
98                    }
99                }
100            }
101            break;
102
103        // 削除
104        case 'delete':
105            if (!$is_error) {
106                if ($this->doDelete($objFormParam, $objLayout)) {
107                    SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id,
108                                                 'msg' => 'on'), true);
109                    exit;
110                }
111            }
112            break;
113
114        default:
115            if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
116                // 完了メッセージ
117                $this->tpl_onload = "alert('登録が完了しました。');";
118            }
119        }
120
121        if (!$is_error) {
122            // ブロック一覧を取得
123            $this->arrBlocList = $objLayout->getBlocs($this->device_type_id);
124            // bloc_id が指定されている場合にはブロックデータの取得
125            if (!SC_Utils_Ex::isBlank($this->bloc_id)) {
126                $arrBloc = $this->getBlocTemplate($this->device_type_id, $this->bloc_id, $objLayout);
127                $objFormParam->setParam($arrBloc);
128            }
129        } else {
130            // 画面にエラー表示しないため, ログ出力
131            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
132        }
133        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
134        $this->arrForm = $objFormParam->getFormParamList();
135    }
136
137    /**
138     * デストラクタ.
139     *
140     * @return void
141     */
142    function destroy() {
143        parent::destroy();
144    }
145
146    /**
147     * パラメーター情報の初期化
148     *
149     * @param object $objFormParam SC_FormParamインスタンス
150     * @return void
151     */
152    function lfInitParam(&$objFormParam) {
153        $objFormParam->addParam("ブロックID", "bloc_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
154        $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
155        $objFormParam->addParam("ブロック名", "bloc_name", STEXT_LEN, 'KVa', array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
156        $objFormParam->addParam("ファイル名", "filename", STEXT_LEN, 'a', array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
157        $objFormParam->addParam("ブロックデータ", "bloc_html");
158    }
159
160    /**
161     * ブロックのテンプレートを取得する.
162     *
163     * @param integer $device_type_id 端末種別ID
164     * @param integer $bloc_id ブロックID
165     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
166     * @return array ブロック情報の配列
167     */
168    function getBlocTemplate($device_type_id, $bloc_id, &$objLayout) {
169        $arrBloc = $objLayout->getBlocs($device_type_id, 'bloc_id = ?', array($bloc_id));
170        if (SC_Utils_Ex::isAbsoluteRealPath($arrBloc[0]['tpl_path'])) {
171            $tpl_path = $arrBloc[0]['tpl_path'];
172        } else {
173            $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . BLOC_DIR . $arrBloc[0]['tpl_path'];
174        }
175        if (file_exists($tpl_path)) {
176            $arrBloc[0]['bloc_html'] = file_get_contents($tpl_path);
177        }
178        return $arrBloc[0];
179    }
180
181    /**
182     * 登録を実行する.
183     *
184     * ファイルの作成に失敗した場合は, エラーメッセージを出力し,
185     * データベースをロールバックする.
186     *
187     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
188     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
189     * @return integer|boolean 登録が成功した場合, 登録したブロックID;
190     *                         失敗した場合 false
191     */
192    function doRegister(&$objFormParam, &$objLayout) {
193        $arrParams = $objFormParam->getHashArray();
194
195        $objQuery =& SC_Query_Ex::getSingletonInstance();
196        $objQuery->begin();
197
198        // blod_id が空の場合は新規登録
199        $is_new = SC_Utils_Ex::isBlank($arrParams['bloc_id']);
200        $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
201        // 既存データの重複チェック
202        if (!$is_new) {
203            $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ?', array($arrParams['bloc_id']));
204
205            // 既存のファイルが存在する場合は削除しておく
206            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
207            if (file_exists($exists_file)) {
208                unlink($exists_file);
209            }
210        }
211
212        $table = 'dtb_bloc';
213        $arrValues = $objQuery->extractOnlyColsOf($table, $arrParams);
214        $arrValues['tpl_path'] = $arrParams['filename'] . '.tpl';
215        $arrValues['update_date'] = 'now()';
216
217        // 新規登録
218        if ($is_new || SC_Utils_Ex::isBlank($arrExists)) {
219            $objQuery->setOrder('');
220            $arrValues['bloc_id'] = 1 + $objQuery->max('bloc_id', $table, 'device_type_id = ?',
221                                                       array($arrValues['device_type_id']));
222            $arrValues['create_date'] = 'now()';
223            $objQuery->insert($table, $arrValues);
224        }
225        // 更新
226        else {
227            $objQuery->update($table, $arrValues, 'bloc_id = ? AND device_type_id = ?',
228                              array($arrValues['bloc_id'], $arrValues['device_type_id']));
229        }
230
231        $bloc_path = $bloc_dir . $arrValues['tpl_path'];
232        if (!SC_Helper_FileManager_Ex::sfWriteFile($bloc_path, $arrParams['bloc_html'])) {
233            $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />';
234            $objQuery->rollback();
235            return false;
236        }
237
238        $objQuery->commit();
239        return $arrValues['bloc_id'];
240    }
241
242    /**
243     * 削除を実行する.
244     *
245     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
246     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
247     * @return boolean 登録が成功した場合 true; 失敗した場合 false
248     */
249    function doDelete(&$objFormParam, &$objLayout) {
250        $arrParams = $objFormParam->getHashArray();
251        $objQuery =& SC_Query_Ex::getSingletonInstance();
252        $objQuery->begin();
253
254        $arrExists = $objLayout->getBlocs($arrParams['device_type_id'], 'bloc_id = ? AND deletable_flg = 1',
255                                          array($arrParams['bloc_id']));
256        $is_error = false;
257        if (!SC_Utils_Ex::isBlank($arrExists)) {
258            $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?',
259                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
260            $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?',
261                              array($arrExists[0]['bloc_id'], $arrExists[0]['device_type_id']));
262
263            $bloc_dir = $objLayout->getTemplatePath($arrParams['device_type_id']) . BLOC_DIR;
264            $exists_file = $bloc_dir . $arrExists[0]['filename'] . '.tpl';
265
266            // ファイルの削除
267            if (file_exists($exists_file)) {
268                if (!unlink($exists_file)) {
269                    $is_error = true;
270                }
271            }
272        } else {
273            $is_error = true;
274        }
275
276        if ($is_error) {
277            $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />';
278            $objQuery->rollback();
279            return false;
280        }
281        $objQuery->commit();
282        return true;
283    }
284
285    /**
286     * エラーチェックを行う.
287     *
288     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
289     * @return array エラーメッセージの配列
290     */
291    function lfCheckError(&$objFormParam, &$arrErr, &$objLayout) {
292        $arrParams = $objFormParam->getHashArray();
293        $objErr = new SC_CheckError_Ex($arrParams);
294        $objErr->arrErr =& $arrErr;
295        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
296        $objErr->doFunc(array('ファイル名', 'filename', STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
297
298        $where = 'filename = ?';
299        $arrValues = array($arrParams['filename']);
300
301        // 変更の場合は自ブロックを除外
302        if (!SC_Utils_Ex::isBlank($arrParams['bloc_id'])) {
303            $where .= ' AND bloc_id <> ?';
304            $arrValues[] = $arrParams['bloc_id'];
305        }
306        $arrBloc = $objLayout->getBlocs($arrParams['device_type_id'], $where, $arrValues);
307        if (!SC_Utils_Ex::isBlank($arrBloc)) {
308            $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />';
309        }
310        return $objErr->arrErr;
311    }
312}
313?>
Note: See TracBrowser for help on using the repository browser.