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

Revision 20693, 10.5 KB checked in by kotani, 13 years ago (diff)

#994 (デザイン管理>ブロック設定での不具合)

  • 削除できない不具合改修
  • 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() {
[20693]75        $objFormParam = new SC_FormParam_Ex();
76        $this->lfInitParam($objFormParam, $_REQUEST);
77
78       // ページIDを取得
79        $bloc_id = $objFormParam->getValue('bloc_id');
[15687]80        $this->bloc_id = $bloc_id;
81
[19713]82        // 端末種別IDを取得
[20693]83        $device_type_id = $objFormParam->getValue('device_type_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//        }
[19713]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 'confirm':
120            // エラーチェック
121            $this->arrErr = $this->lfErrorCheck($_POST);
122
123            // エラーがなければ更新処理を行う
124            if (count($this->arrErr) == 0) {
125                // DBへデータを更新する
[19725]126                $this->lfEntryBlocData($_POST, $device_type_id);
[18233]127
128                // 旧ファイルの削除
[19795]129                if (file_exists($tplPath)) {
130                    unlink($tplPath);
[18233]131                }
[19713]132
[18233]133                // ファイル作成
[19795]134                $new_bloc_path = $package_path . $_POST['filename'] . ".tpl";
[19713]135                // ディレクトリの作成
[20484]136                SC_Utils_Ex::sfMakeDir($new_bloc_path);
[20629]137                $fp = fopen($new_bloc_path,"w");
138                if (!$fp) {
[19795]139                    SC_Utils_Ex::sfDispException();
140                }
[20629]141                fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと...
142                fclose($fp);
[18233]143
[19713]144                $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?",
145                                                    array($_POST['filename'], $device_type_id));
[18233]146
147                $bloc_id = $arrBlocData[0]['bloc_id'];
[19832]148                $arrQueryString = array(
149                    'bloc_id' => $bloc_id,
150                    'device_type_id' => $device_type_id,
151                    'msg' => 'on',
152                );
153                $this->objDisplay->reload($arrQueryString, true);
[18233]154                exit;
155            }else{
156                // エラーがあれば入力時のデータを表示する
157                $this->arrBlocData = $_POST;
158            }
[19713]159            break;
[18233]160        case 'delete':
[19713]161             // DBへデータを更新する
[20693]162            $objQuery =& SC_Query_Ex::getSingletonInstance();
[18233]163            $sql = "";                      // データ更新SQL生成用
164            $ret = "";                      // データ更新結果格納用
165
166            // bloc_id が空でない場合にはdeleteを実行
[20693]167            if ($bloc_id !== '') {
168                $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', array($bloc_id, $device_type_id));
[18233]169
170                // ページに配置されているデータも削除する
[20693]171                $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', array($bloc_id, $device_type_id));
[18233]172
173                // ファイルの削除
[19795]174                if (file_exists($tplPath)) {
175                    unlink($tplPath);
[18233]176                }
177            }
[19832]178            $this->objDisplay->reload(array("device_type_id" => $device_type_id), true);
[18233]179            exit;
[19713]180            break;
[18233]181        default:
[20484]182            GC_Utils_Ex::gfPrintLog("MODEエラー:".$this->getMode());
[19713]183            break;
184        }
[19722]185        $this->device_type_id = $device_type_id;
[15687]186    }
187
188    /**
189     * デストラクタ.
190     *
191     * @return void
192     */
193    function destroy() {
194        parent::destroy();
195    }
196
197    /**
[20693]198     * パラメータ情報の初期化
199     *
200     * @param object $objFormParam SC_FormParamインスタンス
201     * @param array $arrPost $_POSTデータ
202     * @return void
203     */
204    function lfInitParam(&$objFormParam, $arrPost) {
205        $objFormParam->addParam("ブロックID", "bloc_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"));
206        $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), DEVICE_TYPE_PC);
207        $objFormParam->setParam($arrPost);
208        $objFormParam->convParam();
209    }
210
211    /**
[15687]212     * ブロック情報を取得する.
213     *
214     * @param string $where Where句文
215     * @param array $arrVal Where句の絞込条件値
216     * @return array ブロック情報
217     */
[19713]218    function lfgetBlocData($where = '', $arrVal = array()){
[20507]219        $objQuery =& SC_Query_Ex::getSingletonInstance();
[19713]220        $objQuery->setOrder("bloc_id");
221        return $objQuery->select("*", "dtb_bloc", $where, $arrVal);
[15687]222    }
223
224    /**
225     * ブロック情報を更新する.
226     *
227     * @param array $arrData 更新データ
[19725]228     * @param integer $device_type_id 端末種別ID
[15687]229     * @return integer 更新結果
230     */
[19725]231    function lfEntryBlocData($arrData, $device_type_id){
[20693]232        $objQuery =& SC_Query_Ex::getSingletonInstance();
[19713]233        $sql = "";                      // データ更新SQL生成用
234        $ret = "";                      // データ更新結果格納用
235        $arrUpdData = array();          // 更新データ生成用
236        $arrChk = array();              // 排他チェック用
[15687]237
238        // 更新データ生成
[19725]239        $arrUpdData = array("bloc_name" => $arrData['bloc_name'],
[19795]240                            "tpl_path" => $arrData['filename'] . '.tpl',
[20538]241                            'filename' => $arrData['filename']);
[15687]242
243        // データが存在しているかチェックを行う
244        if($arrData['bloc_id'] !== ''){
[19713]245            $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?",
[19725]246                                           array($arrData['bloc_id'], $device_type_id));
[15687]247        }
248
249        // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う
250        if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) {
251            // SQL生成
[19713]252            // FIXME device_type_id ごとの連番にする
[18978]253            $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id');
[19725]254            $arrUpdData['device_type_id'] = $device_type_id;
[19832]255            $arrUpdData['update_date'] = "now()";
[18978]256            $ret = $objQuery->insert('dtb_bloc', $arrUpdData);
257        } else {
[19713]258            $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?',
[19725]259                                     array($arrData['bloc_id'], $device_type_id));
[15687]260        }
261        return $ret;
262    }
263
264    /**
265     * 入力項目のエラーチェックを行う.
266     *
267     * @param array $arrData 入力データ
268     * @return array エラー情報
269     */
270    function lfErrorCheck($array) {
[20503]271        $objErr = new SC_CheckError_Ex($array);
[15687]272
273        $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
[20538]274        $objErr->doFunc(array("ファイル名", 'filename', STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD"));
[15687]275
276        // 同一のファイル名が存在している場合にはエラー
[20454]277        if(!isset($objErr->arrErr['filename']) && $array['filename'] !== ''){
[15687]278            $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename']));
279
[20454]280            if (count($arrChk[0]) >= 1 && $arrChk[0]['bloc_id'] != $array['bloc_id']) {
[15687]281                $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。';
282            }
283        }
284
285        return $objErr->arrErr;
286    }
287}
288?>
Note: See TracBrowser for help on using the repository browser.