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

Revision 22343, 9.6 KB checked in by m_uehara, 11 years ago (diff)

#2048 全角記号を半角記号に変更。

  • 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 
[15689]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.
[15689]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.
[15689]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15689]26
27/**
28 * CSS設定 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20345]34class LC_Page_Admin_Design_CSS extends LC_Page_Admin_Ex {
[15689]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;
[20538]48        $this->tpl_subno = 'css';
49        $this->tpl_mainno = 'design';
[22100]50        $this->tpl_maintitle = t('TPL_MAINTITLE_003');
51        $this->tpl_subtitle = t('LC_Page_Admin_Design_CSS_002');
[20560]52        $masterData = new SC_DB_MasterData_Ex();
53        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
[15689]54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
[19661]62        $this->action();
63        $this->sendResponse();
64    }
[15689]65
[19661]66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
[21591]72
[20860]73        $objLayout = new SC_Helper_PageLayout_Ex();
[15689]74
[20741]75        $objFormParam = new SC_FormParam_Ex();
[20860]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));
[20741]81
[17112]82        // CSSファイル名を取得
[20860]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);
[15689]86
[21514]87        $css_dir = $objLayout->getTemplatePath($this->device_type_id, true) . 'css/';
[20860]88        $css_path = $css_dir . $this->css_name . '.css';
[19725]89
[21441]90        switch ($this->getMode()) {
[17112]91            // データ更新処理
92            case 'confirm':
[20860]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'))) {
[22100]98                            $this->tpl_onload = "alert('" . t('ALERT_004') . "');";
[20860]99                        }
100                    }
101                }
[19725]102                break;
[17112]103            case 'delete':
[20860]104                if (!$is_error) {
105                    if ($this->doDelete($css_path)) {
[21527]106                        $arrPram = array(
107                            'device_type_id' => $this->device_type_id,
108                            'msg' => 'on',
109                        );
[21591]110
[21527]111                        SC_Response_Ex::reload($arrPram, true);
[20860]112                    }
113                }
[19725]114                break;
[17112]115            default:
[20860]116                if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
117                    // 完了メッセージ
[22100]118                    $this->tpl_onload = "alert('" . t('ALERT_004') . "');";
[20860]119                }
[19725]120                break;
[17112]121        }
122
[21806]123        if (!$is_error && $this->checkPath($this->css_name)) {
[20860]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        }
[22343]134        $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle;
[20860]135        $this->arrForm = $objFormParam->getFormParamList();
[21591]136
[15689]137    }
138
139    /**
140     * デストラクタ.
141     *
142     * @return void
143     */
144    function destroy() {
145        parent::destroy();
146    }
[17112]147
[20741]148    /**
[20970]149     * パラメーター情報の初期化
[20741]150     *
151     * @param object $objFormParam SC_FormParamインスタンス
152     * @return void
153     */
[20860]154    function lfInitParam(&$objFormParam) {
[22100]155        $objFormParam->addParam(t('PARAM_LABEL_DEVICE_TYPE_ID'), 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK'));
156        $objFormParam->addParam(t('PARAM_LABEL_CSS_FILE_NAME'), 'css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
157        $objFormParam->addParam(t('PARAM_LABEL_CSS_OLD_FILE_NAME'), 'old_css_name', STEXT_LEN, 'a', array('MAX_LENGTH_CHECK'));
158        $objFormParam->addParam(t('PARAM_LABEL_CSS_DATA'), 'css_data');
[20860]159
[20741]160    }
161
[20860]162    /**
163     * 登録を実行する.
164     *
165     * ファイルの作成に失敗した場合は, エラーメッセージを出力する.
166     *
167     * @param string $css_dir CSS ディレクトリ
168     * @param string $css_name CSSファイル名
169     * @param string $old_css_name 旧CSSファイル名
170     * @param string $css_path CSSファイルの絶対パス
171     * @param string $css_data 書き込みを行うデータ
172     * @return boolean 登録が成功した場合 true; 失敗した場合 false
173     */
174    function doRegister($css_dir, $css_name, $old_css_name, $css_path, $css_data) {
[17114]175        $objFileManager = new SC_Helper_FileManager_Ex();
176
[20860]177        if (!SC_Utils_Ex::isBlank($old_css_name)
178            && $old_css_name != $css_name) {
179            if (!unlink($css_dir . $old_css_name . '.css')) {
[22100]180                $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_003');
[20860]181                return false;
[17112]182            }
[20860]183        }
[17112]184
[20860]185        if (!SC_Helper_FileManager_Ex::sfWriteFile($css_path, $css_data)) {
[22100]186            $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_004');
[20860]187            return false;
[17112]188        }
[20860]189        return true;
[17112]190    }
191
[20860]192    /**
193     * 削除を実行する.
194     *
195     * @param string $css_path CSSファイルの絶対パス
196     * @return boolean 削除が成功した場合 true; 失敗した場合 false
197     */
198    function doDelete($css_path) {
199        if (!unlink($css_path)) {
[22100]200            $this->arrErr['err'] = t('LC_Page_Admin_Design_CSS_005');
[20860]201            return false;
[17112]202        }
[20860]203        return true;
[17112]204    }
205
206    /**
207     * CSSファイルのリストを取得.
208     *
209     * @param array $css_dir CSSディレクトリ
210     * @return array ファイルリスト
211     */
[20860]212    function getCSSList($css_dir) {
[17112]213        $objFileManager = new SC_Helper_FileManager_Ex();
214
215        $arrFileList = $objFileManager->sfGetFileList($css_dir);
[20860]216        foreach ($arrFileList as $val) {
[17112]217            if (!$val['is_dir']) {
218                $arrCSSList[] = array(
219                    'file_name' => $val['file_name'],
220                    'css_name'  => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']),
221                );
222            }
223        }
224        return $arrCSSList;
225    }
226
227    /**
[20860]228     * エラーチェックを行う.
[17112]229     *
[20860]230     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
231     * @return array エラーメッセージの配列
[17112]232     */
[20860]233    function lfCheckError(&$objFormParam, &$arrErr) {
234        $arrParams = $objFormParam->getHashArray();
235        $objErr = new SC_CheckError_Ex($arrParams);
236        $objErr->arrErr =& $arrErr;
[22100]237        $objErr->doFunc(array(t('PARAM_LABEL_CSS_FILE_NAME'), 'css_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD'));
[17112]238
[20860]239        $device_type_id = $objFormParam->getValue('device_type_id');
240        $css_name = $objFormParam->getValue('css_name');
241        $old_css_name = $objFormParam->getValue('old_css_name', $css_name);
[17112]242
[20860]243        $is_error = false;
244        // 重複チェック
[21441]245        if (!SC_Utils_Ex::isBlank(($objErr->arrErr['css_name']))) {
[20860]246            $arrCSSList = $this->getCSSList($this->getCSSDir());
247            foreach ($arrCSSList as $val) {
248                if ($val['css_name'] == $css_name) {
249                    if (SC_Utils_Ex::isBlank($old_css_name)
250                        || $old_css_name != $css_name) {
251                        $is_error = true;
[17112]252                    }
253                }
254            }
[20860]255            if ($is_error) {
[22100]256                $objErr->arrErr['css_name'] = t('LC_Page_Admin_Design_CSS_006');
[20860]257            }
[17112]258        }
259        return $objErr->arrErr;
260    }
[20860]261
262    /**
263     * CSSディレクトリを取得する.
264     *
265     * @param integer $device_type_id 端末種別ID
266     * @return string CSSディレクトリ
267     */
268    function getCSSDir($device_type_id) {
[21514]269        return SC_Helper_PageLayout_Ex::getTemplatePath($device_type_id, true) . 'css/';
[20860]270    }
[21829]271
[21806]272    /**
273     * 文字列に[./]表記がないかをチェックします
274     * @param string $str
275     * @return boolean
276     */
277    function checkPath($str) {
278        // 含む場合はfalse
279        if (preg_match('|\./|', $str)) {
280            return false;
281        }
282        return true;
283    }
[15689]284}
Note: See TracBrowser for help on using the repository browser.