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 |
---|
25 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
26 | require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php'; |
---|
27 | |
---|
28 | /** |
---|
29 | * CSS設定 のページクラス. |
---|
30 | * |
---|
31 | * @package Page |
---|
32 | * @author LOCKON CO.,LTD. |
---|
33 | * @version $Id$ |
---|
34 | */ |
---|
35 | class LC_Page_Admin_Design_CSS extends LC_Page_Admin_Ex { |
---|
36 | |
---|
37 | // }}} |
---|
38 | // {{{ functions |
---|
39 | |
---|
40 | /** |
---|
41 | * Page を初期化する. |
---|
42 | * |
---|
43 | * @return void |
---|
44 | */ |
---|
45 | function init() { |
---|
46 | parent::init(); |
---|
47 | $this->tpl_mainpage = 'design/css.tpl'; |
---|
48 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
49 | $this->area_row = 30; |
---|
50 | $this->tpl_subno = 'css'; |
---|
51 | $this->tpl_mainno = 'design'; |
---|
52 | $this->tpl_subtitle = 'CSS設定'; |
---|
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 | * FIXME css ファイルの取得方法を要修正 |
---|
71 | * |
---|
72 | * @return void |
---|
73 | */ |
---|
74 | function action() { |
---|
75 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
76 | $this->objLayout = new SC_Helper_PageLayout_Ex(); |
---|
77 | |
---|
78 | $objFormParam = new SC_FormParam_Ex(); |
---|
79 | $this->lfInitParam($objFormParam, $_REQUEST); |
---|
80 | |
---|
81 | // CSSファイル名を取得 |
---|
82 | $css_name = $objFormParam->getValue('css_name'); |
---|
83 | $this->css_name = $css_name; |
---|
84 | $old_css_name = $objFormParam->getValue('old_css_name'); |
---|
85 | if ($old_css_name == "" && $css_name != "") { |
---|
86 | $old_css_name = $css_name; |
---|
87 | } |
---|
88 | $this->old_css_name = $old_css_name; |
---|
89 | |
---|
90 | // 端末種別IDを取得 |
---|
91 | $device_type_id = $objFormParam->getValue('device_type_id'); |
---|
92 | |
---|
93 | //サブタイトルの追加 |
---|
94 | $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id]; |
---|
95 | |
---|
96 | $css_dir = $this->objLayout->getTemplatePath($device_type_id, true) . "css/"; |
---|
97 | $css_path = $css_dir . $css_name . '.css'; |
---|
98 | |
---|
99 | // CSSファイルの読み込み |
---|
100 | if($css_name != ''){ |
---|
101 | $css_data = $objFileManager->sfReadFile($css_path); |
---|
102 | } |
---|
103 | // テキストエリアに表示 |
---|
104 | $this->css_data = $css_data; |
---|
105 | |
---|
106 | switch($this->getMode()) { |
---|
107 | // データ更新処理 |
---|
108 | case 'confirm': |
---|
109 | $this->lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path); |
---|
110 | break; |
---|
111 | case 'delete': |
---|
112 | $this->lfExecuteDelete($css_path, $device_type_id); |
---|
113 | break; |
---|
114 | default: |
---|
115 | break; |
---|
116 | } |
---|
117 | |
---|
118 | // ファイルリストを取得 |
---|
119 | $this->arrCSSList = $this->lfGetCSSList($css_dir); |
---|
120 | $this->device_type_id = $device_type_id; |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * デストラクタ. |
---|
125 | * |
---|
126 | * @return void |
---|
127 | */ |
---|
128 | function destroy() { |
---|
129 | parent::destroy(); |
---|
130 | } |
---|
131 | |
---|
132 | |
---|
133 | /** |
---|
134 | * パラメータ情報の初期化 |
---|
135 | * |
---|
136 | * @param object $objFormParam SC_FormParamインスタンス |
---|
137 | * @param array $arrPost $_POSTデータ |
---|
138 | * @return void |
---|
139 | */ |
---|
140 | function lfInitParam(&$objFormParam, $arrPost) { |
---|
141 | $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), DEVICE_TYPE_PC); |
---|
142 | $objFormParam->addParam("CSSファイル名", "css_name", MTEXT_LEN, 'a', array("MAX_LENGTH_CHECK")); |
---|
143 | $objFormParam->addParam("旧CSSファイル名", "old_css_name", MTEXT_LEN, 'a', array("MAX_LENGTH_CHECK")); |
---|
144 | $objFormParam->setParam($arrPost); |
---|
145 | $objFormParam->convParam(); |
---|
146 | } |
---|
147 | |
---|
148 | function lfExecuteConfirm($css_dir, $css_name, $old_css_name, $css_path) { |
---|
149 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
150 | |
---|
151 | // エラーチェック |
---|
152 | $this->arrErr = $this->lfErrorCheck($_POST, $css_dir); |
---|
153 | |
---|
154 | // エラーがなければ更新処理を行う |
---|
155 | if (count($this->arrErr) == 0) { |
---|
156 | // 旧ファイルの削除 |
---|
157 | if ($old_css_name != '' && $old_css_name != $css_name) { |
---|
158 | $objFileManager->sfDeleteDir($css_dir . $old_css_name . '.css'); |
---|
159 | } |
---|
160 | // プレビュー用テンプレートに書き込み |
---|
161 | $objFileManager->sfWriteFile($css_path, $_POST['css']); |
---|
162 | |
---|
163 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
164 | $this->old_css_name = $css_name; |
---|
165 | } |
---|
166 | $this->css_data = $_POST['css']; |
---|
167 | } |
---|
168 | |
---|
169 | function lfExecuteDelete($css_path, $device_type_id) { |
---|
170 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
171 | |
---|
172 | // css_name が空でない場合にはdeleteを実行 |
---|
173 | if ($_POST['css_name'] !== '') { |
---|
174 | $objFileManager->sfDeleteDir($css_path); |
---|
175 | } |
---|
176 | $this->objDisplay->reload(array('device_type_id' => $device_type_id), true); |
---|
177 | } |
---|
178 | |
---|
179 | /** |
---|
180 | * CSSファイルのリストを取得. |
---|
181 | * |
---|
182 | * @param array $css_dir CSSディレクトリ |
---|
183 | * @return array ファイルリスト |
---|
184 | */ |
---|
185 | function lfGetCSSList($css_dir) { |
---|
186 | $objFileManager = new SC_Helper_FileManager_Ex(); |
---|
187 | |
---|
188 | $arrFileList = $objFileManager->sfGetFileList($css_dir); |
---|
189 | foreach ($arrFileList as $key => $val) { |
---|
190 | if (!$val['is_dir']) { |
---|
191 | $arrCSSList[] = array( |
---|
192 | 'file_name' => $val['file_name'], |
---|
193 | 'css_name' => preg_replace('/(.+)\.(.+?)$/','$1',$val['file_name']), |
---|
194 | ); |
---|
195 | } |
---|
196 | } |
---|
197 | return $arrCSSList; |
---|
198 | } |
---|
199 | |
---|
200 | /** |
---|
201 | * 入力項目のエラーチェックを行う. |
---|
202 | * |
---|
203 | * @param array $arrData 入力データ |
---|
204 | * @param array $css_dir CSSディレクトリ |
---|
205 | * @return array エラー情報 |
---|
206 | */ |
---|
207 | function lfErrorCheck($array, $css_dir) { |
---|
208 | $objErr = new SC_CheckError_Ex($array); |
---|
209 | |
---|
210 | $objErr->doFunc(array("CSSファイル名", "css_name", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK")); |
---|
211 | |
---|
212 | // 入力文字が英数字,"_","-"以外ならエラーを返す |
---|
213 | if(!isset($objErr->arrErr['css_name'])){ |
---|
214 | if(!ereg("^[a-zA-Z0-9_\.-]+$", $array['css_name'])) { |
---|
215 | $objErr->arrErr['css_name'] = '※ CSSファイル名は英数字と"_"および"-"だけを入力してください。<br />'; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | // 同一のファイル名が存在している場合にはエラー |
---|
220 | if(!isset($objErr->arrErr['css_name'])){ |
---|
221 | $arrCSSList = $this->lfGetCSSList($css_dir); |
---|
222 | foreach ($arrCSSList as $key => $val) { |
---|
223 | if ($val['css_name'] == $array['css_name']) { |
---|
224 | if ($array['old_css_name'] == '' || $array['old_css_name'] != $array['css_name']) { |
---|
225 | $errFlg = TRUE; |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | if ($errFlg) $objErr->arrErr['css_name'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。<br />'; |
---|
230 | } |
---|
231 | |
---|
232 | return $objErr->arrErr; |
---|
233 | } |
---|
234 | } |
---|
235 | ?> |
---|