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

Revision 20560, 16.4 KB checked in by t_yuo, 13 years ago (diff)

#948 (コンテンツ管理>CSV出力設定、デザイン管理 サブタイトルが欲しい)

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