source: branches/version-2_5-dev/data/class/pages/admin/design/LC_Page_Admin_Design_MainEdit.php @ 20116

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