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

Revision 21743, 9.3 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #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 * CSS設定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
34class LC_Page_Admin_Design_CSS 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/css.tpl';
47        $this->area_row = 30;
48        $this->tpl_subno = 'css';
49        $this->tpl_mainno = 'design';
50        $this->tpl_maintitle = 'デザイン管理';
51        $this->tpl_subtitle = 'CSS設定';
52        $masterData = new SC_DB_MasterData_Ex();
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
75        $objFormParam = new SC_FormParam_Ex();
76        $this->lfInitParam($objFormParam);
77        $objFormParam->setParam($_REQUEST);
78        $objFormParam->convParam();
79        $this->arrErr = $objFormParam->checkError();
80        $is_error = (!SC_Utils_Ex::isBlank($this->arrErr));
81
82        // CSSファイル名を取得
83        $this->css_name = $objFormParam->getValue('css_name');
84        $this->old_css_name = $objFormParam->getValue('old_css_name', $this->css_name);
85        $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC);
86
87        $css_dir = $objLayout->getTemplatePath($this->device_type_id, true) . 'css/';
88        $css_path = $css_dir . $this->css_name . '.css';
89
90        switch ($this->getMode()) {
91            // データ更新処理
92            case 'confirm':
93                if (!$is_error) {
94                    $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr);
95                    if (SC_Utils_Ex::isBlank($this->arrErr)) {
96                        if ($this->doRegister($css_dir, $this->css_name, $this->old_css_name, $css_path,
97                                              $objFormParam->getValue('css_data'))) {
98                            $this->tpl_onload = "alert('登録が完了しました。');";
99                        }
100                    }
101                }
102                break;
103            case 'delete':
104                if (!$is_error) {
105                    if ($this->doDelete($css_path)) {
106                        $arrPram = array(
107                            'device_type_id' => $this->device_type_id,
108                            'msg' => 'on',
109                        );
110
111                        SC_Response_Ex::reload($arrPram, true);
112                    }
113                }
114                break;
115            default:
116                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
117                    // 完了メッセージ
118                    $this->tpl_onload = "alert('登録が完了しました。');";
119                }
120                break;
121        }
122
123        if (!$is_error) {
124            // CSSファイルの読み込み
125            if (!SC_Utils_Ex::isBlank($this->css_name)) {
126                $objFormParam->setValue('css_data', file_get_contents($css_path));
127            }
128            // ファイルリストを取得
129            $this->arrCSSList = $this->getCSSList($css_dir);
130        } else {
131            // 画面にエラー表示しないため, ログ出力
132            GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true));
133
134        }
135        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
136        $this->arrForm = $objFormParam->getFormParamList();
137
138    }
139
140    /**
141     * デストラクタ.
142     *
143     * @return void
144     */
145    function destroy() {
146        parent::destroy();
147    }
148
149    /**
150     * パラメーター情報の初期化
151     *
152     * @param object $objFormParam SC_FormParamインスタンス
153     * @return void
154     */
155    function lfInitParam(&$objFormParam) {
156        $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
157        $objFormParam->addParam('CSSファイル名', 'css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
158        $objFormParam->addParam('旧CSSファイル名', 'old_css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
159        $objFormParam->addParam('CSSデータ', 'css_data');
160
161    }
162
163    /**
164     * 登録を実行する.
165     *
166     * ファイルの作成に失敗した場合は, エラーメッセージを出力する.
167     *
168     * @param string $css_dir CSS ディレクトリ
169     * @param string $css_name CSSファイル名
170     * @param string $old_css_name 旧CSSファイル名
171     * @param string $css_path CSSファイルの絶対パス
172     * @param string $css_data 書き込みを行うデータ
173     * @return boolean 登録が成功した場合 true; 失敗した場合 false
174     */
175    function doRegister($css_dir, $css_name, $old_css_name, $css_path, $css_data) {
176        $objFileManager = new SC_Helper_FileManager_Ex();
177
178        if (!SC_Utils_Ex::isBlank($old_css_name)
179            && $old_css_name != $css_name) {
180            if (!unlink($css_dir . $old_css_name . '.css')) {
181                $this->arrErr['err'] = '※ 旧ファイルの削除に失敗しました<br />';
182                return false;
183            }
184        }
185
186        if (!SC_Helper_FileManager_Ex::sfWriteFile($css_path, $css_data)) {
187            $this->arrErr['err'] = '※ CSSの書き込みに失敗しました<br />';
188            return false;
189        }
190        return true;
191    }
192
193    /**
194     * 削除を実行する.
195     *
196     * @param string $css_path CSSファイルの絶対パス
197     * @return boolean 削除が成功した場合 true; 失敗した場合 false
198     */
199    function doDelete($css_path) {
200        if (!unlink($css_path)) {
201            $this->arrErr['err'] = '※ CSSの削除に失敗しました<br />';
202            return false;
203        }
204        return true;
205    }
206
207    /**
208     * CSSファイルのリストを取得.
209     *
210     * @param array $css_dir CSSディレクトリ
211     * @return array ファイルリスト
212     */
213    function getCSSList($css_dir) {
214        $objFileManager = new SC_Helper_FileManager_Ex();
215
216        $arrFileList = $objFileManager->sfGetFileList($css_dir);
217        foreach ($arrFileList as $val) {
218            if (!$val['is_dir']) {
219                $arrCSSList[] = array(
220                    'file_name' => $val['file_name'],
221                    'css_name'  => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']),
222                );
223            }
224        }
225        return $arrCSSList;
226    }
227
228    /**
229     * エラーチェックを行う.
230     *
231     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
232     * @return array エラーメッセージの配列
233     */
234    function lfCheckError(&$objFormParam, &$arrErr) {
235        $arrParams = $objFormParam->getHashArray();
236        $objErr = new SC_CheckError_Ex($arrParams);
237        $objErr->arrErr =& $arrErr;
238        $objErr->doFunc(array('CSSファイル名', 'css_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD'));
239
240        $device_type_id = $objFormParam->getValue('device_type_id');
241        $css_name = $objFormParam->getValue('css_name');
242        $old_css_name = $objFormParam->getValue('old_css_name', $css_name);
243
244        $is_error = false;
245        // 重複チェック
246        if (!SC_Utils_Ex::isBlank(($objErr->arrErr['css_name']))) {
247            $arrCSSList = $this->getCSSList($this->getCSSDir());
248            foreach ($arrCSSList as $val) {
249                if ($val['css_name'] == $css_name) {
250                    if (SC_Utils_Ex::isBlank($old_css_name)
251                        || $old_css_name != $css_name) {
252                        $is_error = true;
253                    }
254                }
255            }
256            if ($is_error) {
257                $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />';
258            }
259        }
260        return $objErr->arrErr;
261    }
262
263    /**
264     * CSSディレクトリを取得する.
265     *
266     * @param integer $device_type_id 端末種別ID
267     * @return string CSSディレクトリ
268     */
269    function getCSSDir($device_type_id) {
270        return SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id, true) . 'css/';
271    }
272}
Note: See TracBrowser for help on using the repository browser.