source: branches/version-2_12-multilang/data/class/pages/admin/design/LC_Page_Admin_Design.php @ 22503

Revision 22503, 11.4 KB checked in by m_uehara, 11 years ago (diff)

#2084 メッセージIDの振り直し

  • 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 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/index.tpl';
47        $this->tpl_subno = 'layout';
48        $this->tpl_mainno = 'design';
49        $this->tpl_maintitle = t('c_Design_01');
50        $this->tpl_subtitle = t('c_Layout settings_01');
51        $masterData = new SC_DB_MasterData_Ex();
52        $this->arrTarget = $masterData->getMasterData('mtb_target');
53        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
72
73        $objLayout = new SC_Helper_PageLayout_Ex();
74        $objFormParam = new SC_FormParam_Ex();
75        $this->lfInitParam($objFormParam, intval($_REQUEST['bloc_cnt']));
76        $objFormParam->setParam($_REQUEST);
77
78        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
79        $this->page_id = $objFormParam->getValue('page_id', 1);
80
81        switch ($this->getMode()) {
82            // 新規ブロック作成
83            case 'new_bloc':
84
85                SC_Response_Ex::sendRedirect('bloc.php', array('device_type_id' => $this->device_type_id));
86                SC_Response_Ex::actionExit();
87                break;
88
89            // 新規ページ作成
90            case 'new_page':
91
92                SC_Response_Ex::sendRedirect('main_edit.php', array('device_type_id' => $this->device_type_id));
93                SC_Response_Ex::actionExit();
94                break;
95
96            // プレビュー
97            case 'preview':
98                $this->placingBlocs($objFormParam, true);
99                $filename = $this->savePreviewData($this->page_id, $objLayout);
100                $_SESSION['preview'] = 'ON';
101
102                SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array('filename' => $filename));
103                SC_Response_Ex::actionExit();
104
105            // 編集実行
106            case 'confirm':
107                $this->placingBlocs($objFormParam);
108                $arrQueryString = array('device_type_id' => $this->device_type_id, 'page_id' => $this->page_id, 'msg' => 'on');
109
110                SC_Response_Ex::reload($arrQueryString, true);
111                SC_Response_Ex::actionExit();
112
113                break;
114
115            // データ削除処理
116            case 'delete':
117                //ベースデータでなければファイルを削除
118                if ($objLayout->isEditablePage($this->device_type_id, $this->page_id)) {
119                    $objLayout->lfDelPageData($this->page_id, $this->device_type_id);
120
121                    SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id), true);
122                    SC_Response_Ex::actionExit();
123                }
124                break;
125
126            default:
127                // 完了メッセージ表示
128                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
129                    $this->tpl_onload="alert('" . t('c_Registration is complete._01') . "');";
130                }
131                break;
132        }
133
134        $this->arrBlocs = $this->getLayout($this->device_type_id, $this->page_id, $objLayout);
135        $this->bloc_cnt = count($this->arrBlocs);
136        // 編集中のページ
137        $this->arrPageData = $objLayout->getPageProperties($this->device_type_id, $this->page_id);
138        // 編集可能ページ一覧
139        $this->arrEditPage = $objLayout->getPageProperties($this->device_type_id, null);
140        //サブタイトルを取得
141        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . ' > ' . $this->tpl_subtitle;
142
143    }
144
145    /**
146     * デストラクタ.
147     *
148     * @return void
149     */
150    function destroy() {
151        parent::destroy();
152    }
153
154    /**
155     * フォームパラメーターの初期化を行う.
156     *
157     * @param SC_FormParam $objFormParam SC_FormParam インスタンス.
158     * @param integer $bloc_cnt ブロック数
159     * @return void
160     */
161    function lfInitParam(&$objFormParam, $bloc_cnt = 0) {
162        $objFormParam->addParam(t('c_Page ID_01'), 'page_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
163        $objFormParam->addParam(t('c_Terminal type ID_01'), 'device_type_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
164        $objFormParam->addParam(t('c_Block number_01'), 'bloc_cnt', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
165
166        for ($i = 1; $i <= $bloc_cnt; $i++) {
167            $objFormParam->addParam(t('c_Block name_01'), 'name_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'GRAPH_CHECK'));
168            $objFormParam->addParam(t('c_Block ID_01'), 'id_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
169            $objFormParam->addParam(t('c_Target ID_01'), 'target_id_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'ALNUM_CHECK'));
170            $objFormParam->addParam(t('c_TOP coordinate_01'), 'top_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
171            $objFormParam->addParam(t('c_All pages_01'), 'anywhere_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
172        }
173    }
174
175    /**
176     * ブロックのレイアウト情報を取得する.
177     *
178     * @param integer $device_type_id 端末種別ID
179     * @param integer $page_id ページID
180     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
181     * @return array レイアウト情報の配列
182     */
183    function getLayout($device_type_id, $page_id, &$objLayout) {
184        $arrResults = array();
185        $i = 0;
186
187        // レイアウト済みのブロックデータを追加
188        $arrBlocPos = $objLayout->getBlocPositions($device_type_id, $page_id);
189        foreach ($arrBlocPos as $arrBloc) {
190            $this->copyBloc($arrResults, $arrBloc, $i);
191            $i++;
192        }
193
194        // 未使用のブロックデータを追加
195        $arrBloc = $objLayout->getBlocs($device_type_id);
196        foreach ($arrBloc as $arrBloc) {
197            if (!$this->existsBloc($arrBloc, $arrResults)) {
198                $arrBloc['target_id'] = TARGET_ID_UNUSED;
199                $this->copyBloc($arrResults, $arrBloc, $i);
200                $i++;
201            }
202        }
203        return $arrResults;
204    }
205
206    /**
207     * ブロック情報の配列をコピーする.
208     *
209     * @param array $arrDest コピー先ブロック情報
210     * @param array $arrFrom コピー元ブロック情報
211     * @param integer $cnt 配列番号
212     * @return void
213     */
214    function copyBloc(&$arrDest, $arrFrom, $cnt) {
215        $arrDest[$cnt]['target_id'] = $this->arrTarget[$arrFrom['target_id']];
216        $arrDest[$cnt]['bloc_id'] = $arrFrom['bloc_id'];
217        $arrDest[$cnt]['bloc_row'] = $arrFrom['bloc_row'];
218        $arrDest[$cnt]['anywhere'] = $arrFrom['anywhere'];
219        $arrDest[$cnt]['name'] = $arrFrom['bloc_name'];
220    }
221
222    /**
223     * ブロックIDがコピー先の配列に追加されているかのチェックを行う.
224     *
225     * @param array $arrBloc ブロックの配列
226     * @param array $arrToBlocs チェックを行うデータ配列
227     * @return bool 存在する場合 true
228     */
229    function existsBloc($arrBloc, $arrToBlocs) {
230        foreach ($arrToBlocs as $arrToBloc) {
231            if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id']) {
232                return true;
233            }
234        }
235        return false;
236    }
237
238    /**
239     * プレビューするデータを DB に保存する.
240     *
241     * @param integer $page_id プレビューを行うページID
242     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
243     * @return string プレビューを行う tpl_mainpage ファイル名
244     */
245    function savePreviewData($page_id, &$objLayout) {
246        $arrPageData = $objLayout->getPageProperties(DEVICE_TYPE_PC, $page_id);
247        $objQuery =& SC_Query_Ex::getSingletonInstance();
248        $arrPageData[0]['page_id'] = 0;
249        $objQuery->update('dtb_pagelayout', $arrPageData[0], 'page_id = 0 AND device_type_id = ?', array(DEVICE_TYPE_PC));
250        return $arrPageData[0]['filename'];
251    }
252
253    /**
254     * ブロックを配置する.
255     *
256     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
257     * @param boolean $is_preview プレビュー時の場合 true
258     * @return void
259     */
260    function placingBlocs(&$objFormParam, $is_preview = false) {
261        $page_id = $is_preview ? 0 : $objFormParam->getValue('page_id');
262        $device_type_id = $objFormParam->getValue('device_type_id');
263        $bloc_cnt = $objFormParam->getValue('bloc_cnt');
264        $objQuery =& SC_Query_Ex::getSingletonInstance();
265        $objQuery->begin();
266        $objQuery->delete('dtb_blocposition', 'page_id = ? AND device_type_id = ?',
267                          array($page_id, $device_type_id));
268        $arrTargetFlip = array_flip($this->arrTarget);
269        for ($i = 1; $i <= $bloc_cnt; $i++) {
270            // bloc_id が取得できない場合は INSERT しない
271            $id = $objFormParam->getValue('id_' . $i);
272            if (SC_Utils_Ex::isBlank($id)) {
273                continue;
274            }
275            // 未使用は INSERT しない
276            $arrParams['target_id']  = $arrTargetFlip[$objFormParam->getValue('target_id_' . $i)];
277            if ($arrParams['target_id'] == TARGET_ID_UNUSED) {
278                continue;
279            }
280
281            // 他のページに anywhere が存在する場合は INSERT しない
282            $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i));
283            if ($arrParams['anywhere'] == 1) {
284                $exists = $objQuery->exists('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?',
285                                            array($id, $device_type_id));
286                if ($exists) {
287                    continue;
288                }
289            }
290
291            $arrParams['device_type_id'] = $device_type_id;
292            $arrParams['page_id'] = $page_id;
293            $arrParams['bloc_id'] = $id;
294            $arrParams['bloc_row'] = $objFormParam->getValue('top_' . $i);
295
296            if ($arrParams['page_id'] == 0) {
297                $arrParams['anywhere'] = 0;
298            }
299
300            $objQuery->insert('dtb_blocposition', $arrParams);
301        }
302        $objQuery->commit();
303    }
304}
Note: See TracBrowser for help on using the repository browser.