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

Revision 19737, 17.0 KB checked in by nanasess, 13 years ago (diff)

#628(未使用処理・定義などの削除)

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