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 | |
---|
27 | /** |
---|
28 | * メイン編集 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_Design_MainEdit 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/main_edit.tpl'; |
---|
47 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
48 | $this->text_row = 13; |
---|
49 | $this->tpl_subno = "main_edit"; |
---|
50 | $this->tpl_mainno = 'design'; |
---|
51 | $this->tpl_subtitle = 'ページ詳細設定'; |
---|
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 | $objView = new SC_AdminView_Ex(); |
---|
73 | $this->objLayout = new SC_Helper_PageLayout_Ex(); |
---|
74 | |
---|
75 | // ページIDを取得 |
---|
76 | if (isset($_REQUEST['page_id']) && is_numeric($_REQUEST['page_id'])) { |
---|
77 | $page_id = $_REQUEST['page_id']; |
---|
78 | } |
---|
79 | |
---|
80 | $this->page_id = $page_id; |
---|
81 | |
---|
82 | // 端末種別IDを取得 |
---|
83 | if (isset($_REQUEST['device_type_id']) |
---|
84 | && is_numeric($_REQUEST['device_type_id'])) { |
---|
85 | $device_type_id = $_REQUEST['device_type_id']; |
---|
86 | } else { |
---|
87 | $device_type_id = DEVICE_TYPE_PC; |
---|
88 | } |
---|
89 | |
---|
90 | //サブタイトルの追加 |
---|
91 | $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id]; |
---|
92 | |
---|
93 | // ページ一覧を取得 |
---|
94 | $this->arrPageList = $this->objLayout->lfGetPageData("page_id <> 0 AND device_type_id = ?", |
---|
95 | array($device_type_id)); |
---|
96 | |
---|
97 | // メッセージ表示 |
---|
98 | if (isset($_GET['msg']) && $_GET['msg'] == 'on'){ |
---|
99 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
100 | } |
---|
101 | |
---|
102 | // page_id が指定されている場合にはテンプレートデータの取得 |
---|
103 | if (is_numeric($page_id) && $page_id != '') { |
---|
104 | $this->arrPageData = $this->lfGetPageData($page_id, $device_type_id, $objView); |
---|
105 | } |
---|
106 | |
---|
107 | switch ($this->getMode()) { |
---|
108 | case 'delete': |
---|
109 | if (!$this->objLayout->lfCheckBaseData($page_id, $device_type_id)) { |
---|
110 | $this->lfDeletePageData($page_id, $device_type_id); |
---|
111 | exit; |
---|
112 | } |
---|
113 | break; |
---|
114 | |
---|
115 | case 'confirm': |
---|
116 | $this->lfConfirmPageData($page_id, $device_type_id); |
---|
117 | default: |
---|
118 | } |
---|
119 | $this->device_type_id = $device_type_id; |
---|
120 | } |
---|
121 | |
---|
122 | /** |
---|
123 | * デストラクタ. |
---|
124 | * |
---|
125 | * @return void |
---|
126 | */ |
---|
127 | function destroy() { |
---|
128 | parent::destroy(); |
---|
129 | } |
---|
130 | |
---|
131 | /** |
---|
132 | * ページデータを取得する. |
---|
133 | * |
---|
134 | * @param integer $page_id ページID |
---|
135 | * @param integer $device_type_id 端末種別ID |
---|
136 | * @param object $objView ビューオブジェクト |
---|
137 | * @return void |
---|
138 | */ |
---|
139 | function lfGetPageData($page_id, $device_type_id, $objView){ |
---|
140 | $arrPageData = $this->objLayout->lfGetPageData("page_id = ? AND device_type_id = ?", |
---|
141 | array($page_id, $device_type_id)); |
---|
142 | |
---|
143 | if (strlen($arrPageData[0]['filename']) == 0) { |
---|
144 | $this->arrErr['page_id_err'] = "※ 指定されたページは編集できません。"; |
---|
145 | // 画面の表示 |
---|
146 | $objView->assignobj($this); |
---|
147 | $objView->display(MAIN_FRAME); |
---|
148 | exit; |
---|
149 | } |
---|
150 | |
---|
151 | // テンプレートを読み込む |
---|
152 | $templatePath = $this->objLayout->getTemplatePath($device_type_id); |
---|
153 | $arrPageData[0]['tpl_data'] = file_get_contents($templatePath . $arrPageData[0]['filename'] . ".tpl"); |
---|
154 | |
---|
155 | // チェックボックスの値変更 |
---|
156 | $arrPageData[0]['header_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['header_chk'], true); |
---|
157 | $arrPageData[0]['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox($arrPageData[0]['footer_chk'], true); |
---|
158 | |
---|
159 | // ディレクトリを画面表示用に編集 |
---|
160 | $arrPageData[0]['filename'] = preg_replace('|^' . preg_quote(USER_DIR) . '|', '', $arrPageData[0]['filename']); |
---|
161 | |
---|
162 | return $arrPageData[0]; |
---|
163 | } |
---|
164 | |
---|
165 | /** |
---|
166 | * データ登録処理. |
---|
167 | * |
---|
168 | * @param integer $page_id ページID |
---|
169 | * @param integer $device_type_id 端末種別ID |
---|
170 | * @return void |
---|
171 | */ |
---|
172 | function lfConfirmPageData($page_id, $device_type_id) { |
---|
173 | // エラーチェック |
---|
174 | $this->arrErr = $this->lfErrorCheck($_POST, $device_type_id); |
---|
175 | |
---|
176 | // エラーがなければ更新処理を行う |
---|
177 | if (count($this->arrErr) == 0) { |
---|
178 | // DBへデータを更新する |
---|
179 | $arrTmp = $this->lfEntryPageData( |
---|
180 | $device_type_id, |
---|
181 | $page_id, |
---|
182 | $_POST['page_name'], |
---|
183 | USER_DIR . $_POST['url'], |
---|
184 | $_POST['header_chk'], |
---|
185 | $_POST['footer_chk'] |
---|
186 | ); |
---|
187 | $page_id = $arrTmp['page_id']; |
---|
188 | |
---|
189 | $arrTmp = $this->objLayout->lfGetPageData('page_id = ? AND device_type_id = ?', array($page_id, $device_type_id)); |
---|
190 | $arrData = $arrTmp[0]; |
---|
191 | |
---|
192 | // ベースデータでなければファイルを削除し、PHPファイルを作成する |
---|
193 | if (!$this->objLayout->lfCheckBaseData($arrData['page_id'], $device_type_id)) { |
---|
194 | // PHPファイル作成 |
---|
195 | $this->lfCreatePHPFile($_POST['url'], $device_type_id); |
---|
196 | } |
---|
197 | |
---|
198 | // TPLファイル作成 |
---|
199 | $cre_tpl = $this->objLayout->getTemplatePath($device_type_id) . $arrData['filename'] . '.tpl'; |
---|
200 | $this->lfCreateFile($cre_tpl, $_POST['tpl_data']); |
---|
201 | |
---|
202 | $arrQueryString = array( |
---|
203 | "page_id" => $arrData['page_id'], |
---|
204 | "device_type_id" => $device_type_id, |
---|
205 | 'msg' => 'on', |
---|
206 | ); |
---|
207 | $this->objDisplay->reload($arrQueryString, true); |
---|
208 | exit; |
---|
209 | } else { |
---|
210 | // エラーがあれば入力時のデータを表示する |
---|
211 | $this->arrPageData = $_POST; |
---|
212 | $this->arrPageData['header_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['header_chk']), true); |
---|
213 | $this->arrPageData['footer_chk'] = SC_Utils_Ex::sfChangeCheckBox(SC_Utils_Ex::sfChangeCheckBox($_POST['footer_chk']), true); |
---|
214 | $this->arrPageData['directory'] = ''; |
---|
215 | $this->arrPageData['filename'] = $_POST['url']; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | /** |
---|
220 | * ブロック情報を更新する. |
---|
221 | * |
---|
222 | * @param integer $device_type_id |
---|
223 | * @param integer $page_id |
---|
224 | * @param string $page_name |
---|
225 | * @param string $filename |
---|
226 | * @param integer $header_chk |
---|
227 | * @param integer $footer_chk |
---|
228 | * @return array 実際に使用した更新データ |
---|
229 | */ |
---|
230 | function lfEntryPageData($device_type_id, $page_id, $page_name, $filename, $header_chk, $footer_chk) { |
---|
231 | $objQuery = new SC_Query_Ex(); |
---|
232 | $arrChk = array(); // 排他チェック用 |
---|
233 | |
---|
234 | // 更新用データの変換 |
---|
235 | $sqlval = $this->lfGetUpdData($device_type_id, $page_id, $page_name, $filename, $header_chk, $footer_chk); |
---|
236 | |
---|
237 | // データが存在しているかチェックを行う |
---|
238 | if ($page_id !== ''){ |
---|
239 | $arrChk = $this->objLayout->lfGetPageData("page_id = ? AND device_type_id = ?", |
---|
240 | array($page_id, $device_type_id)); |
---|
241 | } |
---|
242 | |
---|
243 | // page_id が空 若しくは データが存在していない場合にはINSERTを行う |
---|
244 | if ($page_id === '' || !isset($arrChk[0])) { |
---|
245 | // FIXME device_type_id ごとの連番にする |
---|
246 | $sqlval['page_id'] = $objQuery->nextVal('dtb_pagelayout_page_id'); |
---|
247 | $sqlval['device_type_id'] = $device_type_id; |
---|
248 | $sqlval['create_date'] = 'now()'; |
---|
249 | $objQuery->insert('dtb_pagelayout', $sqlval); |
---|
250 | } |
---|
251 | // データが存在してる場合にはアップデートを行う |
---|
252 | else { |
---|
253 | $objQuery->update('dtb_pagelayout', $sqlval, 'page_id = ? AND device_type_id = ?', |
---|
254 | array($page_id, $device_type_id)); |
---|
255 | // 戻り値用 |
---|
256 | $sqlval['page_id'] = $page_id; |
---|
257 | } |
---|
258 | return $sqlval; |
---|
259 | } |
---|
260 | |
---|
261 | /** |
---|
262 | * DBへ更新を行うデータを生成する. |
---|
263 | * |
---|
264 | * @param integer $device_type_id |
---|
265 | * @param integer $page_id |
---|
266 | * @param string $page_name |
---|
267 | * @param string $filename |
---|
268 | * @param integer $header_chk |
---|
269 | * @param integer $footer_chk |
---|
270 | * @return array 更新データ |
---|
271 | */ |
---|
272 | function lfGetUpdData($device_type_id, $page_id, $page_name, $filename, $header_chk, $footer_chk) { |
---|
273 | $arrUpdData = array( |
---|
274 | 'header_chk' => SC_Utils_Ex::sfChangeCheckBox($header_chk), // ヘッダー使用 |
---|
275 | 'footer_chk' => SC_Utils_Ex::sfChangeCheckBox($footer_chk), // フッター使用 |
---|
276 | 'update_url' => $_SERVER['HTTP_REFERER'], // 更新URL |
---|
277 | 'update_date' => 'now()', |
---|
278 | ); |
---|
279 | |
---|
280 | // ベースデータの場合には変更しない。 |
---|
281 | if (!$this->objLayout->lfCheckBaseData($page_id, $device_type_id)) { |
---|
282 | $arrUpdData['page_name'] = $page_name; |
---|
283 | $arrUpdData['url'] = $filename . '.php'; |
---|
284 | $arrUpdData['filename'] = $filename; // 拡張子を付加しない |
---|
285 | } |
---|
286 | |
---|
287 | return $arrUpdData; |
---|
288 | } |
---|
289 | |
---|
290 | /** |
---|
291 | * ページデータを削除する. |
---|
292 | * |
---|
293 | * @param integer $page_id ページID |
---|
294 | * @return void |
---|
295 | */ |
---|
296 | function lfDeletePageData($page_id, $device_type_id){ |
---|
297 | $this->objLayout->lfDelPageData($page_id, $device_type_id); |
---|
298 | $this->objDisplay->reload(array("device_type_id" => $device_type_id), true); |
---|
299 | } |
---|
300 | |
---|
301 | /** |
---|
302 | * 入力項目のエラーチェックを行う. |
---|
303 | * |
---|
304 | * @param array $arrData 入力データ |
---|
305 | * @param integer $device_type_id 端末種別ID |
---|
306 | * @return array エラー情報 |
---|
307 | */ |
---|
308 | function lfErrorCheck($array, $device_type_id) { |
---|
309 | $objErr = new SC_CheckError_Ex($array); |
---|
310 | $objErr->doFunc(array("名称", "page_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
311 | $objErr->doFunc(array('URL', 'url', STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
312 | |
---|
313 | // URLチェック |
---|
314 | $okUrl = true; |
---|
315 | foreach (explode('/', $array['url']) as $url_part) { |
---|
316 | if (!ereg( '^[a-zA-Z0-9:_~\.-]+$', $url_part)) { |
---|
317 | $okUrl = false; |
---|
318 | } |
---|
319 | if ($url_part == '.' || $url_part == '..') { |
---|
320 | $okUrl = false; |
---|
321 | } |
---|
322 | } |
---|
323 | if (!$okUrl) { |
---|
324 | $objErr->arrErr['url'] = "※ URLを正しく入力してください。<br />"; |
---|
325 | } |
---|
326 | |
---|
327 | // 同一のURLが存在している場合にはエラー |
---|
328 | $params = array(); |
---|
329 | |
---|
330 | $sqlWhere = 'url = ?'; |
---|
331 | $params[] = $this->objLayout->getUserDir($device_type_id) . $array['url'] . '.php'; |
---|
332 | |
---|
333 | // プレビュー用のレコードは除外 |
---|
334 | $sqlWhere .= ' AND page_id <> 0'; |
---|
335 | |
---|
336 | // 変更の場合、自身のレコードは除外 |
---|
337 | if (strlen($array['page_id']) != 0) { |
---|
338 | $sqlWhere .= ' AND page_id <> ?'; |
---|
339 | $params[] = $array['page_id']; |
---|
340 | } |
---|
341 | |
---|
342 | $arrChk = $this->objLayout->lfgetPageData($sqlWhere , $params); |
---|
343 | |
---|
344 | if (count($arrChk) >= 1) { |
---|
345 | $objErr->arrErr['url'] = '※ 同じURLのデータが存在しています。別のURLを付けてください。<br />'; |
---|
346 | } |
---|
347 | |
---|
348 | return $objErr->arrErr; |
---|
349 | } |
---|
350 | |
---|
351 | /** |
---|
352 | * ファイルを作成する. |
---|
353 | * |
---|
354 | * @param string $path テンプレートファイルのパス |
---|
355 | * @param string $data テンプレートの内容 |
---|
356 | * @return void |
---|
357 | */ |
---|
358 | function lfCreateFile($path, $data){ |
---|
359 | |
---|
360 | // ディレクトリが存在していなければ作成する |
---|
361 | if (!is_dir(dirname($path))) { |
---|
362 | mkdir(dirname($path), 0777, true); // FIXME (PHP4) |
---|
363 | } |
---|
364 | |
---|
365 | // ファイル作成 |
---|
366 | $fp = fopen($path,'w'); |
---|
367 | if ($fp === false) { |
---|
368 | SC_Utils_Ex::sfDispException(); |
---|
369 | } |
---|
370 | $ret = fwrite($fp, $data); |
---|
371 | if ($ret === false) { |
---|
372 | SC_Utils_Ex::sfDispException(); |
---|
373 | } |
---|
374 | fclose($fp); |
---|
375 | } |
---|
376 | |
---|
377 | /** |
---|
378 | * PHPファイルを作成する. |
---|
379 | * |
---|
380 | * @param string $path PHPファイルのパス |
---|
381 | * @return void |
---|
382 | */ |
---|
383 | function lfCreatePHPFile($url, $device_type_id){ |
---|
384 | |
---|
385 | $path = USER_REALDIR . $url . ".php"; |
---|
386 | |
---|
387 | // カスタマイズを考慮し、上書きしない。(#831) |
---|
388 | if (file_exists($path)) { |
---|
389 | return; |
---|
390 | } |
---|
391 | |
---|
392 | // php保存先ディレクトリが存在していなければ作成する |
---|
393 | if (!is_dir(dirname($path))) { |
---|
394 | mkdir(dirname($path), 0777, true); // FIXME (PHP4) |
---|
395 | } |
---|
396 | |
---|
397 | // ベースとなるPHPファイルの読み込み |
---|
398 | if (file_exists(USER_DEF_PHP_REALFILE)){ |
---|
399 | $php_data = file_get_contents(USER_DEF_PHP_REALFILE); |
---|
400 | } |
---|
401 | |
---|
402 | // require.phpの場所を書き換える |
---|
403 | $defaultStrings = "exit; // Don't rewrite. This line is rewritten by EC-CUBE."; |
---|
404 | $replaceStrings = "require_once '" . str_repeat('../', substr_count($url, '/')) . "../require.php';"; |
---|
405 | $php_data = str_replace($defaultStrings, $replaceStrings, $php_data); |
---|
406 | |
---|
407 | // phpファイルの作成 |
---|
408 | $fp = fopen($path,'w'); |
---|
409 | fwrite($fp, $php_data); |
---|
410 | fclose($fp); |
---|
411 | } |
---|
412 | |
---|
413 | } |
---|
414 | ?> |
---|