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

Revision 22100, 11.5 KB checked in by pineray, 11 years ago (diff)

#163 (テキスト出力多言語対応)

グローバル化に伴い、不要となった SC_I18n を削除.

  • 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
RevLine 
[15680]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[21867]5 * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved.
[15680]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15680]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15680]26
27/**
28 * デザイン管理 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20345]34class LC_Page_Admin_Design extends LC_Page_Admin_Ex {
[15680]35
[18212]36    // }}}
37    // {{{ functions
[15680]38
[18212]39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'design/index.tpl';
[20538]47        $this->tpl_subno = 'layout';
48        $this->tpl_mainno = 'design';
[22100]49        $this->tpl_maintitle = t('TPL_MAINTITLE_003');
50        $this->tpl_subtitle = t('LC_Page_Admin_Design_002');
[19713]51        $masterData = new SC_DB_MasterData_Ex();
[21481]52        $this->arrTarget = $masterData->getMasterData('mtb_target');
[20560]53        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
[18212]54    }
[15680]55
[18212]56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
[19661]62        $this->action();
63        $this->sendResponse();
64    }
[15680]65
[19661]66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
[21591]72
[18212]73        $objLayout = new SC_Helper_PageLayout_Ex();
[20830]74        $objFormParam = new SC_FormParam_Ex();
75        $this->lfInitParam($objFormParam, intval($_REQUEST['bloc_cnt']));
76        $objFormParam->setParam($_REQUEST);
[15680]77
[20830]78        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
79        $this->page_id = $objFormParam->getValue('page_id', 1);
[15680]80
[20041]81        switch ($this->getMode()) {
[21526]82            // 新規ブロック作成
83            case 'new_bloc':
[21592]84
[21526]85                SC_Response_Ex::sendRedirect('bloc.php', array('device_type_id' => $this->device_type_id));
[21743]86                SC_Response_Ex::actionExit();
[21526]87                break;
[16935]88
[21526]89            // 新規ページ作成
90            case 'new_page':
[21591]91
[21526]92                SC_Response_Ex::sendRedirect('main_edit.php', array('device_type_id' => $this->device_type_id));
[21743]93                SC_Response_Ex::actionExit();
[21526]94                break;
[15680]95
[21526]96            // プレビュー
97            case 'preview':
98                $this->placingBlocs($objFormParam, true);
99                $filename = $this->savePreviewData($this->page_id, $objLayout);
100                $_SESSION['preview'] = 'ON';
[21591]101
[21526]102                SC_Response_Ex::sendRedirectFromUrlPath('preview/' . DIR_INDEX_PATH, array('filename' => $filename));
[21743]103                SC_Response_Ex::actionExit();
[15680]104
[21526]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');
[21591]109
[21526]110                SC_Response_Ex::reload($arrQueryString, true);
[21743]111                SC_Response_Ex::actionExit();
[15680]112
[21526]113                break;
[15680]114
[21526]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);
[21591]120
[21526]121                    SC_Response_Ex::reload(array('device_type_id' => $this->device_type_id), true);
[21743]122                    SC_Response_Ex::actionExit();
[21526]123                }
124                break;
[19713]125
[21526]126            default:
127                // 完了メッセージ表示
128                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
[22100]129                    $this->tpl_onload="alert('" . t('ALERT_004') . "');";
[21526]130                }
131                break;
[18212]132        }
[15680]133
[20830]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        //サブタイトルを取得
[20911]141        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
[21591]142
[19661]143    }
[15680]144
[18212]145    /**
146     * デストラクタ.
147     *
148     * @return void
[18211]149     */
150    function destroy() {
151        parent::destroy();
152    }
[15680]153
[18211]154    /**
[20970]155     * フォームパラメーターの初期化を行う.
[18211]156     *
[20830]157     * @param SC_FormParam $objFormParam SC_FormParam インスタンス.
158     * @param integer $bloc_cnt ブロック数
159     * @return void
[18211]160     */
[20830]161    function lfInitParam(&$objFormParam, $bloc_cnt = 0) {
[22100]162        $objFormParam->addParam(t('PARAM_LABEL_PAGE_ID'), 'page_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
163        $objFormParam->addParam(t('PARAM_LABEL_DEVICE_TYPE_ID'), 'device_type_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
164        $objFormParam->addParam(t('PARAM_LABEL_BLOC_CNT'), 'bloc_cnt', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
[15680]165
[20830]166        for ($i = 1; $i <= $bloc_cnt; $i++) {
[22100]167            $objFormParam->addParam(t('PARAM_LABEL_BLOC_NAME'), 'name_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'GRAPH_CHECK'));
168            $objFormParam->addParam(t('PARAM_LABEL_BLOC_ID'), 'id_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
169            $objFormParam->addParam(t('PARAM_LABEL_TARGET_ID'), 'target_id_' . $i, STEXT_LEN, 'a', array('MAX_LENGTH_CHECK', 'ALNUM_CHECK'));
170            $objFormParam->addParam(t('PARAM_LABEL_TOP'), 'top_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
171            $objFormParam->addParam(t('PARAM_LABEL_FULL_PAGE'), 'anywhere_' . $i, INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
[18211]172        }
[20830]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);
[21441]189        foreach ($arrBlocPos as $arrBloc) {
[20830]190            $this->copyBloc($arrResults, $arrBloc, $i);
191            $i++;
192        }
193
194        // 未使用のブロックデータを追加
195        $arrBloc = $objLayout->getBlocs($device_type_id);
[21441]196        foreach ($arrBloc as $arrBloc) {
[20830]197            if (!$this->existsBloc($arrBloc, $arrResults)) {
198                $arrBloc['target_id'] = TARGET_ID_UNUSED;
199                $this->copyBloc($arrResults, $arrBloc, $i);
200                $i++;
[18211]201            }
202        }
[20830]203        return $arrResults;
204    }
[15680]205
[20830]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'];
[18211]220    }
[15680]221
[18211]222    /**
[20830]223     * ブロックIDがコピー先の配列に追加されているかのチェックを行う.
[18211]224     *
[20830]225     * @param array $arrBloc ブロックの配列
226     * @param array $arrToBlocs チェックを行うデータ配列
[18211]227     * @return bool 存在する場合 true
228     */
[20830]229    function existsBloc($arrBloc, $arrToBlocs) {
[21441]230        foreach ($arrToBlocs as $arrToBloc) {
[21442]231            if ($arrBloc['bloc_id'] === $arrToBloc['bloc_id']) {
[18211]232                return true;
233            }
234        }
235        return false;
236    }
[15829]237
[18211]238    /**
[20830]239     * プレビューするデータを DB に保存する.
[18211]240     *
[20830]241     * @param integer $page_id プレビューを行うページID
242     * @param SC_Helper_PageLayout $objLayout SC_Helper_PageLayout インスタンス
243     * @return string プレビューを行う tpl_mainpage ファイル名
[18211]244     */
[21479]245    function savePreviewData($page_id, &$objLayout) {
[20830]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'];
[18211]251    }
[16396]252
[18211]253    /**
[20830]254     * ブロックを配置する.
[18211]255     *
[20830]256     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
257     * @param boolean $is_preview プレビュー時の場合 true
[18211]258     * @return void
259     */
[20830]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();
[21514]266        $objQuery->delete('dtb_blocposition', 'page_id = ? AND device_type_id = ?',
[20830]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            }
[15680]280
[20830]281            // 他のページに anywhere が存在する場合は INSERT しない
282            $arrParams['anywhere'] = intval($objFormParam->getValue('anywhere_' . $i));
283            if ($arrParams['anywhere'] == 1) {
[21376]284                $exists = $objQuery->exists('dtb_blocposition', 'anywhere = 1 AND bloc_id = ? AND device_type_id = ?',
[21527]285                                            array($id, $device_type_id));
[21376]286                if ($exists) {
[20830]287                    continue;
288                }
289            }
[16935]290
[20830]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);
[21981]295
[21977]296            if ($arrParams['page_id'] == 0) {
297                $arrParams['anywhere'] = 0;
298            }
[21981]299
[21481]300            $objQuery->insert('dtb_blocposition', $arrParams);
[18211]301        }
[20830]302        $objQuery->commit();
[18211]303    }
[15680]304}
Note: See TracBrowser for help on using the repository browser.