1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2011 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 |
---|
25 | require_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 | */ |
---|
34 | class LC_Page_Admin_Design_Bloc 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/bloc.tpl'; |
---|
47 | $this->tpl_subnavi = 'design/subnavi.tpl'; |
---|
48 | $this->tpl_subno_edit = 'bloc'; |
---|
49 | $this->text_row = 13; |
---|
50 | $this->tpl_subno = 'bloc'; |
---|
51 | $this->tpl_mainno = 'design'; |
---|
52 | $this->tpl_subtitle = 'ブロック設定'; |
---|
53 | $masterData = new SC_DB_MasterData_Ex(); |
---|
54 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * Page のプロセス. |
---|
59 | * |
---|
60 | * @return void |
---|
61 | */ |
---|
62 | function process() { |
---|
63 | $this->action(); |
---|
64 | $this->sendResponse(); |
---|
65 | } |
---|
66 | |
---|
67 | /** |
---|
68 | * Page のアクション. |
---|
69 | * |
---|
70 | * FIXME テンプレートパスの取得方法を要修正 |
---|
71 | * |
---|
72 | * @return void |
---|
73 | */ |
---|
74 | function action() { |
---|
75 | $objFormParam = new SC_FormParam_Ex(); |
---|
76 | $this->lfInitParam($objFormParam, $_REQUEST); |
---|
77 | |
---|
78 | // ページIDを取得 |
---|
79 | $bloc_id = $objFormParam->getValue('bloc_id'); |
---|
80 | $this->bloc_id = $bloc_id; |
---|
81 | |
---|
82 | // 端末種別IDを取得 |
---|
83 | $device_type_id = $objFormParam->getValue('device_type_id'); |
---|
84 | |
---|
85 | $this->objLayout = new SC_Helper_PageLayout_Ex(); |
---|
86 | $package_path = $this->objLayout->getTemplatePath($device_type_id) . BLOC_DIR; |
---|
87 | |
---|
88 | //サブタイトルの追加 |
---|
89 | $this->tpl_subtitle .= ' - ' . $this->arrDeviceType[$device_type_id]; |
---|
90 | |
---|
91 | // ブロック一覧を取得 |
---|
92 | $this->arrBlocList = $this->lfgetBlocData("device_type_id = ?", array($device_type_id)); |
---|
93 | |
---|
94 | // bloc_id が指定されている場合にはブロックデータの取得 |
---|
95 | if ($bloc_id != '') { |
---|
96 | $arrBlocData = $this->lfGetBlocData("bloc_id = ? AND device_type_id = ?", |
---|
97 | array($bloc_id, $device_type_id)); |
---|
98 | |
---|
99 | $tplPath = $package_path . $arrBlocData[0]['filename'] . '.tpl'; |
---|
100 | |
---|
101 | // テンプレートファイルの読み込み |
---|
102 | $arrBlocData[0]['tpl_data'] = file_get_contents($tplPath); |
---|
103 | $this->arrBlocData = $arrBlocData[0]; |
---|
104 | } |
---|
105 | |
---|
106 | // メッセージ表示 |
---|
107 | if (isset($_GET['msg']) && $_GET['msg'] == 'on') { |
---|
108 | // 完了メッセージ |
---|
109 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
110 | } |
---|
111 | |
---|
112 | switch($this->getMode()) { |
---|
113 | case 'confirm': |
---|
114 | // エラーチェック |
---|
115 | $this->arrErr = $this->lfErrorCheck($_POST); |
---|
116 | |
---|
117 | // エラーがなければ更新処理を行う |
---|
118 | if (count($this->arrErr) == 0) { |
---|
119 | // DBへデータを更新する |
---|
120 | $this->lfEntryBlocData($_POST, $device_type_id); |
---|
121 | |
---|
122 | // 旧ファイルの削除 |
---|
123 | if (file_exists($tplPath)) { |
---|
124 | unlink($tplPath); |
---|
125 | } |
---|
126 | |
---|
127 | // ファイル作成 |
---|
128 | $new_bloc_path = $package_path . $_POST['filename'] . ".tpl"; |
---|
129 | // ディレクトリの作成 |
---|
130 | SC_Utils_Ex::sfMakeDir($new_bloc_path); |
---|
131 | $fp = fopen($new_bloc_path,"w"); |
---|
132 | if (!$fp) { |
---|
133 | SC_Utils_Ex::sfDispException(); |
---|
134 | } |
---|
135 | fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと... |
---|
136 | fclose($fp); |
---|
137 | |
---|
138 | $arrBlocData = $this->lfGetBlocData("filename = ? AND device_type_id = ?", |
---|
139 | array($_POST['filename'], $device_type_id)); |
---|
140 | |
---|
141 | $bloc_id = $arrBlocData[0]['bloc_id']; |
---|
142 | $arrQueryString = array( |
---|
143 | 'bloc_id' => $bloc_id, |
---|
144 | 'device_type_id' => $device_type_id, |
---|
145 | 'msg' => 'on', |
---|
146 | ); |
---|
147 | $this->objDisplay->reload($arrQueryString, true); |
---|
148 | exit; |
---|
149 | }else{ |
---|
150 | // エラーがあれば入力時のデータを表示する |
---|
151 | $this->arrBlocData = $_POST; |
---|
152 | } |
---|
153 | break; |
---|
154 | case 'delete': |
---|
155 | // DBへデータを更新する |
---|
156 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
157 | $sql = ""; // データ更新SQL生成用 |
---|
158 | $ret = ""; // データ更新結果格納用 |
---|
159 | |
---|
160 | // bloc_id が空でない場合にはdeleteを実行 |
---|
161 | if ($bloc_id !== '') { |
---|
162 | $objQuery->delete('dtb_bloc', 'bloc_id = ? AND device_type_id = ?', array($bloc_id, $device_type_id)); |
---|
163 | |
---|
164 | // ページに配置されているデータも削除する |
---|
165 | $objQuery->delete('dtb_blocposition', 'bloc_id = ? AND device_type_id = ?', array($bloc_id, $device_type_id)); |
---|
166 | |
---|
167 | // ファイルの削除 |
---|
168 | if (file_exists($tplPath)) { |
---|
169 | unlink($tplPath); |
---|
170 | } |
---|
171 | } |
---|
172 | $this->objDisplay->reload(array("device_type_id" => $device_type_id), true); |
---|
173 | exit; |
---|
174 | break; |
---|
175 | default: |
---|
176 | GC_Utils_Ex::gfPrintLog("MODEエラー:".$this->getMode()); |
---|
177 | break; |
---|
178 | } |
---|
179 | $this->device_type_id = $device_type_id; |
---|
180 | } |
---|
181 | |
---|
182 | /** |
---|
183 | * デストラクタ. |
---|
184 | * |
---|
185 | * @return void |
---|
186 | */ |
---|
187 | function destroy() { |
---|
188 | parent::destroy(); |
---|
189 | } |
---|
190 | |
---|
191 | /** |
---|
192 | * パラメータ情報の初期化 |
---|
193 | * |
---|
194 | * @param object $objFormParam SC_FormParamインスタンス |
---|
195 | * @param array $arrPost $_POSTデータ |
---|
196 | * @return void |
---|
197 | */ |
---|
198 | function lfInitParam(&$objFormParam, $arrPost) { |
---|
199 | $objFormParam->addParam("ブロックID", "bloc_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK")); |
---|
200 | $objFormParam->addParam("端末種別ID", "device_type_id", INT_LEN, 'n', array("NUM_CHECK", "MAX_LENGTH_CHECK"), DEVICE_TYPE_PC); |
---|
201 | $objFormParam->setParam($arrPost); |
---|
202 | $objFormParam->convParam(); |
---|
203 | } |
---|
204 | |
---|
205 | /** |
---|
206 | * ブロック情報を取得する. |
---|
207 | * |
---|
208 | * @param string $where Where句文 |
---|
209 | * @param array $arrVal Where句の絞込条件値 |
---|
210 | * @return array ブロック情報 |
---|
211 | */ |
---|
212 | function lfgetBlocData($where = '', $arrVal = array()){ |
---|
213 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
214 | $objQuery->setOrder("bloc_id"); |
---|
215 | return $objQuery->select("*", "dtb_bloc", $where, $arrVal); |
---|
216 | } |
---|
217 | |
---|
218 | /** |
---|
219 | * ブロック情報を更新する. |
---|
220 | * |
---|
221 | * @param array $arrData 更新データ |
---|
222 | * @param integer $device_type_id 端末種別ID |
---|
223 | * @return integer 更新結果 |
---|
224 | */ |
---|
225 | function lfEntryBlocData($arrData, $device_type_id){ |
---|
226 | $objQuery =& SC_Query_Ex::getSingletonInstance(); |
---|
227 | $sql = ""; // データ更新SQL生成用 |
---|
228 | $ret = ""; // データ更新結果格納用 |
---|
229 | $arrUpdData = array(); // 更新データ生成用 |
---|
230 | $arrChk = array(); // 排他チェック用 |
---|
231 | |
---|
232 | // 更新データ生成 |
---|
233 | $arrUpdData = array("bloc_name" => $arrData['bloc_name'], |
---|
234 | "tpl_path" => $arrData['filename'] . '.tpl', |
---|
235 | 'filename' => $arrData['filename']); |
---|
236 | |
---|
237 | // データが存在しているかチェックを行う |
---|
238 | if($arrData['bloc_id'] !== ''){ |
---|
239 | $arrChk = $this->lfgetBlocData("bloc_id = ? AND device_type_id = ?", |
---|
240 | array($arrData['bloc_id'], $device_type_id)); |
---|
241 | } |
---|
242 | |
---|
243 | // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う |
---|
244 | if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) { |
---|
245 | // SQL生成 |
---|
246 | // FIXME device_type_id ごとの連番にする |
---|
247 | $arrUpdData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id'); |
---|
248 | $arrUpdData['device_type_id'] = $device_type_id; |
---|
249 | $arrUpdData['update_date'] = "now()"; |
---|
250 | $ret = $objQuery->insert('dtb_bloc', $arrUpdData); |
---|
251 | } else { |
---|
252 | $ret = $objQuery->update('dtb_bloc', $arrUpdData, 'bloc_id = ? AND device_type_id = ?', |
---|
253 | array($arrData['bloc_id'], $device_type_id)); |
---|
254 | } |
---|
255 | return $ret; |
---|
256 | } |
---|
257 | |
---|
258 | /** |
---|
259 | * 入力項目のエラーチェックを行う. |
---|
260 | * |
---|
261 | * @param array $arrData 入力データ |
---|
262 | * @return array エラー情報 |
---|
263 | */ |
---|
264 | function lfErrorCheck($array) { |
---|
265 | $objErr = new SC_CheckError_Ex($array); |
---|
266 | |
---|
267 | $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
268 | $objErr->doFunc(array("ファイル名", 'filename', STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK_BY_NOUPLOAD")); |
---|
269 | |
---|
270 | // 同一のファイル名が存在している場合にはエラー |
---|
271 | if(!isset($objErr->arrErr['filename']) && $array['filename'] !== ''){ |
---|
272 | $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename'])); |
---|
273 | |
---|
274 | if (count($arrChk[0]) >= 1 && $arrChk[0]['bloc_id'] != $array['bloc_id']) { |
---|
275 | $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。'; |
---|
276 | } |
---|
277 | } |
---|
278 | |
---|
279 | return $objErr->arrErr; |
---|
280 | } |
---|
281 | } |
---|
282 | ?> |
---|