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

Revision 20560, 11.1 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
RevLine 
[15687]1<?php
2/*
[16582]3 * This file is part of EC-CUBE
4 *
[18701]5 * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved.
[15687]6 *
7 * http://www.lockon.co.jp/
[16582]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.
[15687]22 */
23
24// {{{ requires
[20534]25require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
[15687]26
27/**
28 * ブロック編集 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
33 */
[20345]34class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex {
[15687]35
36    // }}}
37    // {{{ functions
38
39    /**
40     * Page を初期化する.
41     *
42     * @return void
43     */
44    function init() {
45        parent::init();
46        $this->tpl_mainpage = 'design/bloc.tpl';
47        $this->tpl_subnavi = 'design/subnavi.tpl';
48        $this->tpl_subno_edit = 'bloc';
49        $this->text_row = 13;
[20538]50        $this->tpl_subno = 'bloc';
51        $this->tpl_mainno = 'design';
[19719]52        $this->tpl_subtitle = 'ブロック設定';
[20560]53        $masterData = new SC_DB_MasterData_Ex();
54        $this->arrDeviceType = $masterData->getMasterData('mtb_device_type');
[15687]55    }
56
57    /**
58     * Page のプロセス.
59     *
60     * @return void
61     */
62    function process() {
[19661]63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
[19713]70     * FIXME テンプレートパスの取得方法を要修正
71     *
[19661]72     * @return void
73     */
74    function action() {
[19713]75        // ページIDを取得
76        if (isset($_REQUEST['bloc_id']) && is_numeric($_REQUEST['bloc_id'])) {
77            $bloc_id = $_REQUEST['bloc_id'];
78        } else {
[19795]79            $bloc_id = null;
[15687]80        }
81        $this->bloc_id = $bloc_id;
82
[19713]83        // 端末種別IDを取得
84        if (isset($_REQUEST['device_type_id'])
85            && is_numeric($_REQUEST['device_type_id'])) {
86            $device_type_id = $_REQUEST['device_type_id'];
87        } else {
88            $device_type_id = DEVICE_TYPE_PC;
89        }
90
[19725]91        $this->objLayout = new SC_Helper_PageLayout_Ex();
[19795]92        $package_path = $this->objLayout->getTemplatePath($device_type_id) . BLOC_DIR;
[19725]93
[20560]94        //サブタイトルの追加
95        $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id];
96
[19713]97        // ブロック一覧を取得
98        $this->arrBlocList = $this->lfgetBlocData("device_type_id = ?", array($device_type_id));
99
[15687]100        // bloc_id が指定されている場合にはブロックデータの取得
101        if ($bloc_id != '') {
[19713]102            $arrBlocData = $this->lfGetBlocData("bloc_id = ? AND device_type_id = ?",
103                                                array($bloc_id, $device_type_id));
[15687]104
[19795]105            $tplPath = $package_path . $arrBlocData[0]['filename'] . '.tpl';
[16275]106
[15687]107            // テンプレートファイルの読み込み
[19795]108            $arrBlocData[0]['tpl_data'] = file_get_contents($tplPath);
[15687]109            $this->arrBlocData = $arrBlocData[0];
110        }
111
112        // メッセージ表示
[20538]113        if (isset($_GET['msg']) && $_GET['msg'] == 'on') {
[15687]114            // 完了メッセージ
115            $this->tpl_onload="alert('登録が完了しました。');";
116        }
117
[20041]118        switch($this->getMode()) {
[18233]119        case 'preview':
120            // プレビューファイル作成
[19807]121            $prev_path = USER_INC_REALDIR . 'preview/bloc_preview.tpl';
[19713]122            // ディレクトリの作成
[20484]123            SC_Utils_Ex::sfMakeDir($prev_path);
[19981]124            $res = file_put_contents($prev_path, $_POST['bloc_html']);
[19795]125            if ($res === false) {
126                SC_Utils_Ex::sfDispException();
127            }
[18233]128
129            // プレビューデータ表示
[20538]130            $this->preview = 'on';
[18233]131            $this->arrBlocData['tpl_data'] = $_POST['bloc_html'];
132            $this->arrBlocData['tpl_path'] = $prev_path;
133            $this->arrBlocData['bloc_name'] = $_POST['bloc_name'];
134            $this->arrBlocData['filename'] = $_POST['filename'];
135            $this->text_row = $_POST['html_area_row'];
[19713]136            break;
[18233]137        case 'confirm':
[20538]138            $this->preview = 'off';
[18233]139            // エラーチェック
140            $this->arrErr = $this->lfErrorCheck($_POST);
141
142            // エラーがなければ更新処理を行う
143            if (count($this->arrErr) == 0) {
144                // DBへデータを更新する
[19725]145                $this->lfEntryBlocData($_POST, $device_type_id);
[18233]146
147                // 旧ファイルの削除
[19795]148                if (file_exists($tplPath)) {
149                    unlink($tplPath);
[18233]150                }
[19713]151
[18233]152                // ファイル作成
[19795]153                $new_bloc_path = $package_path . $_POST['filename'] . ".tpl";
[19713]154                // ディレクトリの作成
[20484]155                SC_Utils_Ex::sfMakeDir($new_bloc_path);
[19795]156                $res = file_put_contents($new_bloc_path, $_POST['bloc_html']);
157                if ($res === false) {
158                    SC_Utils_Ex::sfDispException();
159                }
[18233]160
[19713]161                $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?",
162                                                    array($_POST['filename'], $device_type_id));
[18233]163
164                $bloc_id = $arrBlocData[0]['bloc_id'];
[19832]165                $arrQueryString = array(
166                    'bloc_id' => $bloc_id,
167                    'device_type_id' => $device_type_id,
168                    'msg' => 'on',
169                );
170                $this->objDisplay->reload($arrQueryString, true);
[18233]171                exit;
172            }else{
173                // エラーがあれば入力時のデータを表示する
174                $this->arrBlocData = $_POST;
175            }
[19713]176            break;
[18233]177        case 'delete':
[20538]178            $this->preview = 'off';
[19713]179             // DBへデータを更新する
[20507]180            $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
[18233]181            $sql = "";                      // データ更新SQL生成用
182            $ret = "";                      // データ更新結果格納用
183            $arrDelData = array();          // 更新データ生成用
184
185            // 更新データ生成
186            $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']);
187
188            // bloc_id が空でない場合にはdeleteを実行
189            if ($_POST['bloc_id'] !== '') {
190                // SQL生成
[19713]191                $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ? AND device_type_id = ?";
[18233]192                // SQL実行
[19713]193                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
[18233]194
195                // ページに配置されているデータも削除する
[19713]196                $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ? AND device_type_id = ?";
[18233]197                // SQL実行
[19713]198                $ret = $objQuery->query($sql,array($_POST['bloc_id'], $device_type_id));
[18233]199
200                // ファイルの削除
[19795]201                if (file_exists($tplPath)) {
202                    unlink($tplPath);
[18233]203                }
204            }
[19832]205            $this->objDisplay->reload(array("device_type_id" => $device_type_id), true);
[18233]206            exit;
[19713]207            break;
[18233]208        default:
[20484]209            GC_Utils_Ex::gfPrintLog("MODEエラー:".$this->getMode());
[19713]210            break;
211        }
[19722]212        $this->device_type_id = $device_type_id;
[15687]213    }
214
215    /**
216     * デストラクタ.
217     *
218     * @return void
219     */
220    function destroy() {
221        parent::destroy();
222    }
223
224    /**
225     * ブロック情報を取得する.
226     *
227     * @param string $where Where句文
228     * @param array $arrVal Where句の絞込条件値
229     * @return array ブロック情報
230     */
[19713]231    function lfgetBlocData($where = '', $arrVal = array()){
[20507]232        $objQuery =& SC_Query_Ex::getSingletonInstance();
[19713]233        $objQuery->setOrder("bloc_id");
234        return $objQuery->select("*", "dtb_bloc", $where, $arrVal);
[15687]235    }
236
237    /**
238     * ブロック情報を更新する.
239     *
240     * @param array $arrData 更新データ
[19725]241     * @param integer $device_type_id 端末種別ID
[15687]242     * @return integer 更新結果
243     */
[19725]244    function lfEntryBlocData($arrData, $device_type_id){
[20507]245        $objQuery = new SC_Query_Ex();     // DB操作オブジェクト
[19713]246        $sql = "";                      // データ更新SQL生成用
247        $ret = "";                      // データ更新結果格納用
248        $arrUpdData = array();          // 更新データ生成用
249        $arrChk = array();              // 排他チェック用
[15687]250
251        // 更新データ生成
[19725]252        $arrUpdData = array("bloc_name" => $arrData['bloc_name'],
[19795]253                            "tpl_path" => $arrData['filename'] . '.tpl',
[20538]254                            'filename' => $arrData['filename']);
[15687]255
256        // データが存在しているかチェックを行う
257        if($arrData['bloc_id'] !== ''){
[19713]258            $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?",
[19725]259                                           array($arrData['bloc_id'], $device_type_id));
[15687]260        }
261
262        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
263        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
264            // SQL生成
[19713]265            // FIXME device_type_id ごとの連番にする
[18978]266            $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id');
[19725]267            $arrUpdData['device_type_id'] = $device_type_id;
[19832]268            $arrUpdData['update_date'] = "now()";
[18978]269            $ret = $objQuery->insert('dtb_bloc', $arrUpdData);
270        } else {
[19713]271            $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?',
[19725]272                                     array($arrData['bloc_id'], $device_type_id));
[15687]273        }
274        return $ret;
275    }
276
277    /**
278     * 入力項目のエラーチェックを行う.
279     *
280     * @param array $arrData 入力データ
281     * @return array エラー情報
282     */
283    function lfErrorCheck($array) {
[20503]284        $objErr = new SC_CheckError_Ex($array);
[15687]285
286        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
[20538]287        $objErr->doFunc(array("ファイル名", 'filename', STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
[15687]288
289        // 同一のファイル名が存在している場合にはエラー
[20454]290        if(!isset($objErr->arrErr['filename']) && $array['filename'] !== ''){
[15687]291            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
292
[20454]293            if (count($arrChk[0]) >= 1 && $arrChk[0]['bloc_id'] != $array['bloc_id']) {
[15687]294                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
295            }
296        }
297
298        return $objErr->arrErr;
299    }
300}
301?>
Note: See TracBrowser for help on using the repository browser.