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

Revision 21693, 6.7 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_Header 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/header.tpl';
47        $this->header_row = 13;
48        $this->footer_row = 13;
49        $this->tpl_subno = 'header';
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_Header_action_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->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
85
86        switch ($this->getMode()) {
87            // 登録
88            case 'regist':
89                $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr);
90                if (SC_Utils_Ex::isBlank($this->arrErr)) {
91                    if ($this->doRegister($objFormParam)) {
92                        $this->tpl_onload = "alert('登録が完了しました。');";
93                    }
94                }
95                break;
96
97            default:
98                break;
99        }
100
101        if (!$is_error) {
102            // テキストエリアに表示
103            $header_path = $this->getTemplatePath($this->device_type_id, 'header');
104            $footer_path = $this->getTemplatePath($this->device_type_id, 'footer');
105            if ($header_path === false || $footer_path === false) {
106                $this->arrErr['err'] = '※ ファイルの取得に失敗しました<br />';
107            } else {
108                $this->header_data = file_get_contents($header_path);
109                $this->footer_data = file_get_contents($footer_path);
110            }
111        } else {
112            // 画面にエラー表示しないため, ログ出力
113            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
114        }
115
116        //サブタイトルの追加
117        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
118
119        // フックポイント.
120        $objPlugin = SC_Helper_Plugin_Ex::getSingletonInstance($this->plugin_activate_flg);
121        $objPlugin->doAction('LC_Page_Admin_Design_Header_action_after', array($this));
122    }
123
124    /**
125     * デストラクタ.
126     *
127     * @return void
128     */
129    function destroy() {
130        parent::destroy();
131    }
132
133    /**
134     * パラメーター情報の初期化
135     *
136     * @param object $objFormParam SC_FormParamインスタンス
137     * @return void
138     */
139    function lfInitParam(&$objFormParam) {
140        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
141        $objFormParam->addParam('division', 'division', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
142        $objFormParam->addParam('ヘッダデータ', 'header');
143        $objFormParam->addParam('フッタデータ', 'footer');
144    }
145
146    /**
147     * エラーチェックを行う.
148     *
149     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
150     * @return array エラーメッセージの配列
151     */
152    function lfCheckError(&$objFormParam, &$arrErr) {
153        $arrParams = $objFormParam->getHashArray();
154        $objErr = new SC_CheckError_Ex($arrParams);
155        $objErr->arrErr =& $arrErr;
156        $objErr->doFunc(array('division', 'division', STEXT_LEN), array('EXIST_CHECK'));
157        return $objErr->arrErr;
158    }
159
160    /**
161     * 登録を実行する.
162     *
163     * ファイルの作成に失敗した場合は, エラーメッセージを出力する.
164     *
165     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
166     * @return integer|boolean 登録が成功した場合 true; 失敗した場合 false
167     */
168    function doRegister(&$objFormParam) {
169        $division = $objFormParam->getValue('division');
170        $contents = $objFormParam->getValue($division);
171        $tpl_path = $this->getTemplatePath($objFormParam->getValue('device_type_id'), $division);
172        if ($tpl_path === false
173            || !SC_Helper_FileManager_Ex::sfWriteFile($tpl_path, $contents)) {
174            $this->arrErr['err'] = '※ ファイルの書き込みに失敗しました<br />';
175            return false;
176        }
177        return true;
178    }
179
180    /**
181     * テンプレートパスを取得する.
182     *
183     * @param integer $device_type_id 端末種別ID
184     * @param string $division 'header' or 'footer'
185     * @return string|boolean 成功した場合, テンプレートのパス; 失敗した場合 false
186     */
187    function getTemplatePath($device_type_id, $division) {
188        $tpl_path = SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id) . '/' . $division . '.tpl';
189        if (file_exists($tpl_path)) {
190            return $tpl_path;
191        } else {
192            return false;
193        }
194    }
195}
Note: See TracBrowser for help on using the repository browser.