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 |
---|
25 | require_once(CLASS_PATH . "pages/LC_Page.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 { |
---|
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 | } |
---|
54 | |
---|
55 | /** |
---|
56 | * Page のプロセス. |
---|
57 | * |
---|
58 | * @return void |
---|
59 | */ |
---|
60 | function process() { |
---|
61 | $objView = new SC_AdminView(); |
---|
62 | $this->objLayout = new SC_Helper_PageLayout_Ex(); |
---|
63 | $package_path = USER_TEMPLATE_PATH . "/" . TEMPLATE_NAME . "/"; |
---|
64 | |
---|
65 | // 認証可否の判定 |
---|
66 | $objSess = new SC_Session(); |
---|
67 | SC_Utils_Ex::sfIsSuccess($objSess); |
---|
68 | |
---|
69 | // ブロック一覧を取得 |
---|
70 | $this->arrBlocList = $this->lfgetBlocData(); |
---|
71 | |
---|
72 | // ブロックIDを取得 |
---|
73 | if (isset($_POST['bloc_id'])) { |
---|
74 | $bloc_id = $_POST['bloc_id']; |
---|
75 | }else if (isset($_GET['bloc_id'])) { |
---|
76 | $bloc_id = $_GET['bloc_id']; |
---|
77 | }else{ |
---|
78 | $bloc_id = ''; |
---|
79 | } |
---|
80 | $this->bloc_id = $bloc_id; |
---|
81 | |
---|
82 | // bloc_id が指定されている場合にはブロックデータの取得 |
---|
83 | if ($bloc_id != '') { |
---|
84 | $arrBlocData = $this->lfgetBlocData(" bloc_id = ? " , array($bloc_id)); |
---|
85 | |
---|
86 | // ユーザー作成ブロックが存在する場合 |
---|
87 | if (is_file($package_path . $arrBlocData[0]['tpl_path'])) { |
---|
88 | $arrBlocData[0]['tpl_path'] = $package_path . $arrBlocData[0]['tpl_path']; |
---|
89 | |
---|
90 | // 存在しない場合は指定テンプレートのブロックを取得 |
---|
91 | } else { |
---|
92 | $arrBlocData[0]['tpl_path'] = TEMPLATE_DIR . $arrBlocData[0]['tpl_path']; |
---|
93 | } |
---|
94 | |
---|
95 | // テンプレートファイルの読み込み |
---|
96 | $arrBlocData[0]['tpl_data'] = file_get_contents($arrBlocData[0]['tpl_path']); |
---|
97 | $this->arrBlocData = $arrBlocData[0]; |
---|
98 | } |
---|
99 | |
---|
100 | // メッセージ表示 |
---|
101 | if (isset($_GET['msg']) && $_GET['msg'] == "on") { |
---|
102 | // 完了メッセージ |
---|
103 | $this->tpl_onload="alert('登録が完了しました。');"; |
---|
104 | } |
---|
105 | |
---|
106 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
107 | |
---|
108 | switch($_POST['mode']) { |
---|
109 | case 'preview': |
---|
110 | // プレビューファイル作成 |
---|
111 | $prev_path = USER_INC_PATH . 'preview/bloc_preview.tpl'; |
---|
112 | // ディレクトリの作成 |
---|
113 | SC_Utils::sfMakeDir($prev_path); |
---|
114 | $fp = fopen($prev_path,"w"); |
---|
115 | fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと... |
---|
116 | fclose($fp); |
---|
117 | |
---|
118 | // プレビューデータ表示 |
---|
119 | $this->preview = "on"; |
---|
120 | $this->arrBlocData['tpl_data'] = $_POST['bloc_html']; |
---|
121 | $this->arrBlocData['tpl_path'] = $prev_path; |
---|
122 | $this->arrBlocData['bloc_name'] = $_POST['bloc_name']; |
---|
123 | $this->arrBlocData['filename'] = $_POST['filename']; |
---|
124 | $this->text_row = $_POST['html_area_row']; |
---|
125 | break; |
---|
126 | case 'confirm': |
---|
127 | $this->preview = "off"; |
---|
128 | // エラーチェック |
---|
129 | $this->arrErr = $this->lfErrorCheck($_POST); |
---|
130 | |
---|
131 | // エラーがなければ更新処理を行う |
---|
132 | if (count($this->arrErr) == 0) { |
---|
133 | // DBへデータを更新する |
---|
134 | $this->lfEntryBlocData($_POST); |
---|
135 | |
---|
136 | // 旧ファイルの削除 |
---|
137 | $old_bloc_path = $package_path . $arrBlocData[0]['tpl_path']; |
---|
138 | if (file_exists($old_bloc_path)) { |
---|
139 | unlink($old_bloc_path); |
---|
140 | } |
---|
141 | |
---|
142 | // ファイル作成 |
---|
143 | $new_bloc_path = $package_path . BLOC_DIR . $_POST['filename'] . ".tpl"; |
---|
144 | // ディレクトリの作成 |
---|
145 | SC_Utils::sfMakeDir($new_bloc_path); |
---|
146 | $fp = fopen($new_bloc_path,"w"); |
---|
147 | fwrite($fp, $_POST['bloc_html']); // FIXME いきなり POST はちょっと... |
---|
148 | fclose($fp); |
---|
149 | |
---|
150 | $arrBlocData = $this->lfgetBlocData(" filename = ? " , array($_POST['filename'])); |
---|
151 | |
---|
152 | $bloc_id = $arrBlocData[0]['bloc_id']; |
---|
153 | $this->sendRedirect($this->getLocation("./bloc.php", |
---|
154 | array("bloc_id" => $bloc_id, |
---|
155 | "msg" => "on"))); |
---|
156 | exit; |
---|
157 | }else{ |
---|
158 | // エラーがあれば入力時のデータを表示する |
---|
159 | $this->arrBlocData = $_POST; |
---|
160 | } |
---|
161 | break; |
---|
162 | case 'delete': |
---|
163 | $this->preview = "off"; |
---|
164 | // DBへデータを更新する |
---|
165 | $objQuery = new SC_Query(); // DB操作オブジェクト |
---|
166 | $sql = ""; // データ更新SQL生成用 |
---|
167 | $ret = ""; // データ更新結果格納用 |
---|
168 | $arrDelData = array(); // 更新データ生成用 |
---|
169 | |
---|
170 | // 更新データ生成 |
---|
171 | $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']); |
---|
172 | |
---|
173 | // bloc_id が空でない場合にはdeleteを実行 |
---|
174 | if ($_POST['bloc_id'] !== '') { |
---|
175 | // SQL生成 |
---|
176 | $sql = " DELETE FROM dtb_bloc WHERE bloc_id = ?"; |
---|
177 | // SQL実行 |
---|
178 | $ret = $objQuery->query($sql,array($_POST['bloc_id'])); |
---|
179 | |
---|
180 | // ページに配置されているデータも削除する |
---|
181 | $sql = "DELETE FROM dtb_blocposition WHERE bloc_id = ?"; |
---|
182 | // SQL実行 |
---|
183 | $ret = $objQuery->query($sql,array($_POST['bloc_id'])); |
---|
184 | |
---|
185 | // ファイルの削除 |
---|
186 | $del_file = $package_path . BLOC_DIR . $arrBlocData[0]['filename']. '.tpl'; |
---|
187 | if(file_exists($del_file)){ |
---|
188 | unlink($del_file); |
---|
189 | } |
---|
190 | } |
---|
191 | $this->sendRedirect($this->getLocation("./bloc.php")); |
---|
192 | exit; |
---|
193 | break; |
---|
194 | default: |
---|
195 | if(isset($_POST['mode'])) { |
---|
196 | GC_Utils::gfPrintLog("MODEエラー:".$_POST['mode']); |
---|
197 | } |
---|
198 | break; |
---|
199 | } |
---|
200 | |
---|
201 | // 画面の表示 |
---|
202 | $objView->assignobj($this); |
---|
203 | $objView->display(MAIN_FRAME); |
---|
204 | } |
---|
205 | |
---|
206 | /** |
---|
207 | * デストラクタ. |
---|
208 | * |
---|
209 | * @return void |
---|
210 | */ |
---|
211 | function destroy() { |
---|
212 | parent::destroy(); |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * ブロック情報を取得する. |
---|
217 | * |
---|
218 | * @param string $where Where句文 |
---|
219 | * @param array $arrVal Where句の絞込条件値 |
---|
220 | * @return array ブロック情報 |
---|
221 | */ |
---|
222 | function lfgetBlocData($where = '', $arrVal = ''){ |
---|
223 | $objQuery = new SC_Query(); // DB操作オブジェクト |
---|
224 | $sql = ""; // データ取得SQL生成用 |
---|
225 | $arrRet = array(); // データ取得用 |
---|
226 | |
---|
227 | // SQL生成 |
---|
228 | $sql = " SELECT "; |
---|
229 | $sql .= " bloc_id"; |
---|
230 | $sql .= " ,bloc_name"; |
---|
231 | $sql .= " ,tpl_path"; |
---|
232 | $sql .= " ,filename"; |
---|
233 | $sql .= " ,create_date"; |
---|
234 | $sql .= " ,update_date"; |
---|
235 | $sql .= " ,php_path"; |
---|
236 | $sql .= " ,del_flg"; |
---|
237 | $sql .= " FROM "; |
---|
238 | $sql .= " dtb_bloc"; |
---|
239 | |
---|
240 | // where句の指定があれば追加 |
---|
241 | if ($where != '') { |
---|
242 | $sql .= " WHERE " . $where; |
---|
243 | } |
---|
244 | |
---|
245 | $sql .= " ORDER BY bloc_id"; |
---|
246 | |
---|
247 | $arrRet = $objQuery->getAll($sql, $arrVal); |
---|
248 | |
---|
249 | return $arrRet; |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * ブロック情報を更新する. |
---|
254 | * |
---|
255 | * @param array $arrData 更新データ |
---|
256 | * @return integer 更新結果 |
---|
257 | */ |
---|
258 | function lfEntryBlocData($arrData){ |
---|
259 | $objQuery = new SC_Query(); // DB操作オブジェクト |
---|
260 | $sql = ""; // データ更新SQL生成用 |
---|
261 | $ret = ""; // データ更新結果格納用 |
---|
262 | $arrUpdData = array(); // 更新データ生成用 |
---|
263 | $arrChk = array(); // 排他チェック用 |
---|
264 | |
---|
265 | // 更新データ生成 |
---|
266 | $arrUpdData = array($arrData['bloc_name'], BLOC_DIR . $arrData['filename'] . '.tpl', $arrData['filename']); |
---|
267 | |
---|
268 | // データが存在しているかチェックを行う |
---|
269 | if($arrData['bloc_id'] !== ''){ |
---|
270 | $arrChk = $this->lfgetBlocData("bloc_id = ?", array($arrData['bloc_id'])); |
---|
271 | } |
---|
272 | |
---|
273 | // bloc_id が空 若しくは データが存在していない場合にはINSERTを行う |
---|
274 | if ($arrData['bloc_id'] === '' or !isset($arrChk[0])) { |
---|
275 | // SQL生成 |
---|
276 | $arrData['bloc_id'] = $objQuery->nextVal('dtb_bloc_bloc_id'); |
---|
277 | $sql = " INSERT INTO dtb_bloc"; |
---|
278 | $sql .= " ( "; |
---|
279 | $sql .= " bloc_id "; // ブロックID |
---|
280 | $sql .= " ,bloc_name "; // ブロック名称 |
---|
281 | $sql .= " ,tpl_path "; // テンプレート保存先 |
---|
282 | $sql .= " ,filename "; // ファイル名称 |
---|
283 | $sql .= " ,create_date "; // 作成日 |
---|
284 | $sql .= " ,update_date "; // 更新日 |
---|
285 | $sql .= " ) VALUES (?, ?,?,?,now(),now() )"; |
---|
286 | $sql .= " "; |
---|
287 | }else{ |
---|
288 | // データが存在してる場合にはアップデートを行う |
---|
289 | // SQL生成 |
---|
290 | $sql = " UPDATE dtb_bloc"; |
---|
291 | $sql .= " SET"; |
---|
292 | $sql .= " bloc_name = ? "; // ブロック名称 |
---|
293 | $sql .= " ,tpl_path = ? "; // テンプレート保存先 |
---|
294 | $sql .= " ,filename = ? "; // テンプレートファイル名 |
---|
295 | $sql .= " ,update_date = now()"; |
---|
296 | $sql .= " WHERE bloc_id = ?"; |
---|
297 | $sql .= " "; |
---|
298 | |
---|
299 | // 更新データにブロックIDを追加 |
---|
300 | array_push($arrUpdData, $arrData['bloc_id']); |
---|
301 | } |
---|
302 | |
---|
303 | // SQL実行 |
---|
304 | $ret = $objQuery->query($sql,$arrUpdData); |
---|
305 | |
---|
306 | return $ret; |
---|
307 | |
---|
308 | } |
---|
309 | |
---|
310 | /** |
---|
311 | * 入力項目のエラーチェックを行う. |
---|
312 | * |
---|
313 | * @param array $arrData 入力データ |
---|
314 | * @return array エラー情報 |
---|
315 | */ |
---|
316 | function lfErrorCheck($array) { |
---|
317 | $objErr = new SC_CheckError($array); |
---|
318 | |
---|
319 | $objErr->doFunc(array("ブロック名", "bloc_name", STEXT_LEN), array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
320 | $objErr->doFunc(array("ファイル名", "filename", STEXT_LEN), array("EXIST_CHECK", "NO_SPTAB", "MAX_LENGTH_CHECK","FILE_NAME_CHECK")); |
---|
321 | |
---|
322 | // 同一のファイル名が存在している場合にはエラー |
---|
323 | if(!isset($objErr->arrErr['filename']) and $array['filename'] !== ''){ |
---|
324 | $arrChk = $this->lfgetBlocData("filename = ?", array($array['filename'])); |
---|
325 | |
---|
326 | if (count($arrChk[0]) >= 1 and $arrChk[0]['bloc_id'] != $array['bloc_id']) { |
---|
327 | $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別の名称を付けてください。'; |
---|
328 | } |
---|
329 | } |
---|
330 | |
---|
331 | return $objErr->arrErr; |
---|
332 | } |
---|
333 | } |
---|
334 | ?> |
---|