1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 DATA_REALDIR. 'module/Tar.php'; |
---|
27 | require_once CLASS_EX_REALDIR . 'helper_extends/SC_Helper_FileManager_Ex.php'; |
---|
28 | |
---|
29 | /** |
---|
30 | * テンプレートアップロード のページクラス. |
---|
31 | * |
---|
32 | * @package Page |
---|
33 | * @author LOCKON CO.,LTD. |
---|
34 | * @version $Id$ |
---|
35 | */ |
---|
36 | class LC_Page_Admin_Design_Up_Down extends LC_Page_Admin_Ex { |
---|
37 | |
---|
38 | // }}} |
---|
39 | // {{{ functions |
---|
40 | |
---|
41 | /** |
---|
42 | * Page を初期化する. |
---|
43 | * |
---|
44 | * @return void |
---|
45 | */ |
---|
46 | function init() { |
---|
47 | parent::init(); |
---|
48 | $this->tpl_mainpage = 'design/up_down.tpl'; |
---|
49 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
50 | $this->tpl_subno = 'up_down'; |
---|
51 | $this->tpl_mainno = 'design'; |
---|
52 | $this->tpl_subtitle = 'テンプレート追加'; |
---|
53 | $this->arrErr = array(); |
---|
54 | $this->arrForm = array(); |
---|
55 | ini_set("max_execution_time", 300); |
---|
56 | } |
---|
57 | |
---|
58 | /** |
---|
59 | * Page のプロセス. |
---|
60 | * |
---|
61 | * @return void |
---|
62 | */ |
---|
63 | function process() { |
---|
64 | $this->action(); |
---|
65 | $this->sendResponse(); |
---|
66 | } |
---|
67 | |
---|
68 | /** |
---|
69 | * Page のアクション. |
---|
70 | * |
---|
71 | * FIXME ロジックを見直し |
---|
72 | * |
---|
73 | * @return void |
---|
74 | */ |
---|
75 | function action() { |
---|
76 | // 端末種別IDを取得 |
---|
77 | if (isset($_REQUEST['device_type_id']) |
---|
78 | && is_numeric($_REQUEST['device_type_id'])) { |
---|
79 | $device_type_id = $_REQUEST['device_type_id']; |
---|
80 | } else { |
---|
81 | $device_type_id = DEVICE_TYPE_PC; |
---|
82 | } |
---|
83 | |
---|
84 | switch($this->getMode()) { |
---|
85 | |
---|
86 | // ダウンロードボタン押下時の処理 |
---|
87 | case 'download': |
---|
88 | break; |
---|
89 | // アップロードボタン押下時の処理 |
---|
90 | case 'upload': |
---|
91 | // フォームパラメータ初期化 |
---|
92 | $objForm = $this->lfInitUpload(); |
---|
93 | // エラーチェック |
---|
94 | if ($arrErr = $this->lfValidateUpload($objForm)) { |
---|
95 | $this->arrErr = $arrErr; |
---|
96 | $this->arrForm = $objForm->getFormParamList(); |
---|
97 | break; |
---|
98 | } |
---|
99 | // アップロードファイル初期化 |
---|
100 | $objUpFile = $this->lfInitUploadFile($objForm); |
---|
101 | // 一時ファイルへ保存 |
---|
102 | $errMsg = $objUpFile->makeTempFile('template_file', false); |
---|
103 | // 書き込みエラーチェック |
---|
104 | if(isset($errMsg)) { |
---|
105 | $this->arrErr['template_file'] = $errMsg; |
---|
106 | $this->arrForm = $objForm->getFormParamList(); |
---|
107 | break; |
---|
108 | } |
---|
109 | $this->lfAddTemplates($objForm, $objUpFile, $device_type_id); |
---|
110 | $this->tpl_onload = "alert('テンプレートファイルをアップロードしました。');"; |
---|
111 | break; |
---|
112 | |
---|
113 | // 初回表示 |
---|
114 | default: |
---|
115 | break; |
---|
116 | } |
---|
117 | $this->device_type_id = $device_type_id; |
---|
118 | } |
---|
119 | |
---|
120 | /** |
---|
121 | * デストラクタ. |
---|
122 | * |
---|
123 | * @return void |
---|
124 | */ |
---|
125 | function destroy() { |
---|
126 | parent::destroy(); |
---|
127 | } |
---|
128 | |
---|
129 | /** |
---|
130 | * SC_UploadFileクラスの初期化. |
---|
131 | * |
---|
132 | * @param object $objForm SC_FormParamのインスタンス |
---|
133 | * @return object SC_UploadFileのインスタンス |
---|
134 | */ |
---|
135 | function lfInitUploadFile($objForm) { |
---|
136 | $pkg_dir = SMARTY_TEMPLATES_REALDIR . $objForm->getValue('template_code'); |
---|
137 | $objUpFile = new SC_UploadFile_Ex(TEMPLATE_TEMP_REALDIR, $pkg_dir); |
---|
138 | $objUpFile->addFile("テンプレートファイル", 'template_file', array(), TEMPLATE_SIZE, true, 0, 0, false); |
---|
139 | |
---|
140 | return $objUpFile; |
---|
141 | } |
---|
142 | /** |
---|
143 | * SC_FormParamクラスの初期化. |
---|
144 | * |
---|
145 | * @param void |
---|
146 | * @return object SC_FormParamのインスタンス |
---|
147 | */ |
---|
148 | function lfInitUpload() { |
---|
149 | $objForm = new SC_FormParam; |
---|
150 | |
---|
151 | $objForm->addParam("テンプレートコード", "template_code", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK", "ALNUM_CHECK")); |
---|
152 | $objForm->addParam("テンプレート名", "template_name", STEXT_LEN, 'KVa', array("EXIST_CHECK","SPTAB_CHECK","MAX_LENGTH_CHECK")); |
---|
153 | $objForm->setParam($_POST); |
---|
154 | |
---|
155 | return $objForm; |
---|
156 | } |
---|
157 | /** |
---|
158 | * uploadモードのパラメータ検証を行う. |
---|
159 | * |
---|
160 | * @param object $objForm SC_FormParamのインスタンス |
---|
161 | * @return array エラー情報を格納した連想配列, エラーが無ければ(多分)nullを返す |
---|
162 | */ |
---|
163 | function lfValidateUpload($objForm) { |
---|
164 | $arrErr = $objForm->checkError(); |
---|
165 | if (!empty($arrErr)) { |
---|
166 | return $arrErr; |
---|
167 | } |
---|
168 | |
---|
169 | $arrForm = $objForm->getHashArray(); |
---|
170 | |
---|
171 | // 同名のフォルダが存在する場合はエラー |
---|
172 | if(file_exists(USER_TEMPLATE_REALDIR . $arrForm['template_code'])) { |
---|
173 | $arrErr['template_code'] = "※ 同名のファイルがすでに存在します。<br/>"; |
---|
174 | } |
---|
175 | |
---|
176 | // 登録不可の文字列チェック |
---|
177 | $arrIgnoreCode = array('admin', |
---|
178 | MOBILE_DEFAULT_TEMPLATE_NAME, |
---|
179 | SMARTPHONE_DEFAULT_TEMPLATE_NAME, |
---|
180 | DEFAULT_TEMPLATE_NAME); |
---|
181 | if(in_array($arrForm['template_code'], $arrIgnoreCode)) { |
---|
182 | $arrErr['template_code'] = "※ このテンプレートコードは使用できません。<br/>"; |
---|
183 | } |
---|
184 | |
---|
185 | // DBにすでに登録されていないかチェック |
---|
186 | $objQuery = new SC_Query_Ex(); |
---|
187 | $ret = $objQuery->count("dtb_templates", "template_code = ?", array($arrForm['template_code'])); |
---|
188 | if(!empty($ret)) { |
---|
189 | $arrErr['template_code'] = "※ すでに登録されているテンプレートコードです。<br/>"; |
---|
190 | } |
---|
191 | |
---|
192 | // ファイルの拡張子チェック(.tar/tar.gzのみ許可) |
---|
193 | $errFlag = true; |
---|
194 | $array_ext = explode(".", $_FILES['template_file']['name']); |
---|
195 | $ext = $array_ext[ count ( $array_ext ) - 1 ]; |
---|
196 | $ext = strtolower($ext); |
---|
197 | // .tarチェック |
---|
198 | if ($ext == 'tar') { |
---|
199 | $errFlag = false; |
---|
200 | } |
---|
201 | $ext = $array_ext[ count ( $array_ext ) - 2 ].".".$ext; |
---|
202 | $ext = strtolower($ext); |
---|
203 | // .tar.gzチェック |
---|
204 | if ($ext== 'tar.gz') { |
---|
205 | $errFlag = false; |
---|
206 | } |
---|
207 | |
---|
208 | if($errFlag) { |
---|
209 | $arrErr['template_file'] = "※ アップロードするテンプレートファイルで許可されている形式は、tar/tar.gzです。<br />"; |
---|
210 | } |
---|
211 | |
---|
212 | return $arrErr; |
---|
213 | } |
---|
214 | /** |
---|
215 | * DBおよびファイルシステムにテンプレートパッケージを追加する. |
---|
216 | * |
---|
217 | * @param object $objForm SC_FormParamのインスタンス |
---|
218 | * @param object $objUpFile SC_UploadFileのインスタンス |
---|
219 | * @return void |
---|
220 | */ |
---|
221 | function lfAddTemplates($objForm, $objUpFile, $device_type_id) { |
---|
222 | $template_code = $objForm->getValue('template_code'); |
---|
223 | $template_dir = SMARTY_TEMPLATES_REALDIR . $template_code; |
---|
224 | $compile_dir = DATA_REALDIR . "Smarty/templates_c/" . $template_code; |
---|
225 | // フォルダ作成 |
---|
226 | if(!file_exists($template_dir)) { |
---|
227 | mkdir($template_dir); |
---|
228 | } |
---|
229 | if(!file_exists($compile_dir)) { |
---|
230 | mkdir($compile_dir); |
---|
231 | } |
---|
232 | |
---|
233 | // 一時フォルダから保存ディレクトリへ移動 |
---|
234 | $objUpFile->moveTempFile(); |
---|
235 | |
---|
236 | // 解凍 |
---|
237 | SC_Helper_FileManager_Ex::unpackFile($template_dir . "/" . $_FILES['template_file']['name']); |
---|
238 | // ユーザデータの下のファイルをコピーする |
---|
239 | $from_dir = SMARTY_TEMPLATES_REALDIR . $template_code . "/_packages/"; |
---|
240 | $to_dir = USER_REALDIR . "packages/" . $template_code . "/"; |
---|
241 | SC_Utils_Ex::sfMakeDir($to_dir); |
---|
242 | SC_Utils_Ex::sfCopyDir($from_dir, $to_dir); |
---|
243 | |
---|
244 | // DBにテンプレート情報を保存 |
---|
245 | $this->lfRegisterTemplates($objForm->getHashArray(), $device_type_id); |
---|
246 | } |
---|
247 | |
---|
248 | /** |
---|
249 | * dtb_templatesへ入力内容を登録する. |
---|
250 | * |
---|
251 | * @param array $arrForm POSTされたパラメータ |
---|
252 | * @return void |
---|
253 | */ |
---|
254 | function lfRegisterTemplates($arrForm, $device_type_id) { |
---|
255 | $objQuery = new SC_Query_Ex(); |
---|
256 | $sqlval = $arrForm; |
---|
257 | $sqlval['device_type_id'] = $device_type_id; |
---|
258 | $sqlval['create_date'] = "now()"; |
---|
259 | $sqlval['update_date'] = "now()"; |
---|
260 | $objQuery->insert('dtb_templates', $sqlval); |
---|
261 | } |
---|
262 | } |
---|
263 | ?> |
---|