1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2013 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 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * ブロック編集 のページクラス. |
---|
28 | * |
---|
29 | * @package Page |
---|
30 | * @author LOCKON CO.,LTD. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | class LC_Page_Admin_Design_Bloc extends LC_Page_Admin_Ex |
---|
34 | { |
---|
35 | /** |
---|
36 | * Page を初期化する. |
---|
37 | * |
---|
38 | * @return void |
---|
39 | */ |
---|
40 | public function init() |
---|
41 | { |
---|
42 | parent::init(); |
---|
43 | $this->tpl_mainpage = 'design/bloc.tpl'; |
---|
44 | $this->tpl_subno_edit = 'bloc'; |
---|
45 | $this->text_row = 13; |
---|
46 | $this->tpl_subno = 'bloc'; |
---|
47 | $this->tpl_mainno = 'design'; |
---|
48 | $this->tpl_maintitle = 'デザイン管理'; |
---|
49 | $this->tpl_subtitle = 'ブロック設定'; |
---|
50 | $masterData = new SC_DB_MasterData_Ex(); |
---|
51 | $this->arrDeviceType = $masterData->getMasterData('mtb_device_type'); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * Page のプロセス. |
---|
56 | * |
---|
57 | * @return void |
---|
58 | */ |
---|
59 | public function process() |
---|
60 | { |
---|
61 | $this->action(); |
---|
62 | $this->sendResponse(); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * Page のアクション. |
---|
67 | * |
---|
68 | * @return void |
---|
69 | */ |
---|
70 | public function action() |
---|
71 | { |
---|
72 | $objFormParam = new SC_FormParam_Ex(); |
---|
73 | $this->lfInitParam($objFormParam); |
---|
74 | $objFormParam->setParam($_REQUEST); |
---|
75 | $objFormParam->convParam(); |
---|
76 | $this->arrErr = $objFormParam->checkError(); |
---|
77 | $is_error = (!SC_Utils_Ex::isBlank($this->arrErr)); |
---|
78 | |
---|
79 | $this->bloc_id = $objFormParam->getValue('bloc_id'); |
---|
80 | $this->device_type_id = $objFormParam->getValue('device_type_id', DEVICE_TYPE_PC); |
---|
81 | |
---|
82 | $objBloc = new SC_Helper_Bloc_Ex($this->device_type_id); |
---|
83 | |
---|
84 | switch ($this->getMode()) { |
---|
85 | // 登録/更新 |
---|
86 | case 'confirm': |
---|
87 | if (!$is_error) { |
---|
88 | $this->arrErr = $this->lfCheckError($objFormParam, $this->arrErr, $objBloc); |
---|
89 | if (SC_Utils_Ex::isBlank($this->arrErr)) { |
---|
90 | $result = $this->doRegister($objFormParam, $objBloc); |
---|
91 | if ($result !== false) { |
---|
92 | $arrPram = array( |
---|
93 | 'bloc_id' => $result, |
---|
94 | 'device_type_id' => $this->device_type_id, |
---|
95 | 'msg' => 'on', |
---|
96 | ); |
---|
97 | |
---|
98 | SC_Response_Ex::reload($arrPram, true); |
---|
99 | SC_Response_Ex::actionExit(); |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | break; |
---|
104 | |
---|
105 | // 削除 |
---|
106 | case 'delete': |
---|
107 | if (!$is_error) { |
---|
108 | if ($this->doDelete($objFormParam, $objBloc)) { |
---|
109 | $arrPram = array( |
---|
110 | 'device_type_id' => $this->device_type_id, |
---|
111 | 'msg' => 'on', |
---|
112 | ); |
---|
113 | |
---|
114 | SC_Response_Ex::reload($arrPram, true); |
---|
115 | SC_Response_Ex::actionExit(); |
---|
116 | } |
---|
117 | } |
---|
118 | break; |
---|
119 | |
---|
120 | default: |
---|
121 | if (isset($_GET['msg']) && $_GET['msg'] == 'on') { |
---|
122 | // 完了メッセージ |
---|
123 | $this->tpl_onload = "alert('登録が完了しました。');"; |
---|
124 | } |
---|
125 | break; |
---|
126 | } |
---|
127 | |
---|
128 | if (!$is_error) { |
---|
129 | // ブロック一覧を取得 |
---|
130 | $this->arrBlocList = $objBloc->getList(); |
---|
131 | // bloc_id が指定されている場合にはブロックデータの取得 |
---|
132 | if (!SC_Utils_Ex::isBlank($this->bloc_id)) { |
---|
133 | $arrBloc = $this->getBlocTemplate($this->bloc_id, $objBloc); |
---|
134 | $objFormParam->setParam($arrBloc); |
---|
135 | } |
---|
136 | } else { |
---|
137 | // 画面にエラー表示しないため, ログ出力 |
---|
138 | GC_Utils_Ex::gfPrintLog('Error: ' . print_r($this->arrErr, true)); |
---|
139 | } |
---|
140 | $this->tpl_subtitle = $this->arrDeviceType[$this->device_type_id] . '>' . $this->tpl_subtitle; |
---|
141 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * パラメーター情報の初期化 |
---|
146 | * |
---|
147 | * @param object $objFormParam SC_FormParamインスタンス |
---|
148 | * @return void |
---|
149 | */ |
---|
150 | public function lfInitParam(&$objFormParam) |
---|
151 | { |
---|
152 | $objFormParam->addParam('ブロックID', 'bloc_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
153 | $objFormParam->addParam('端末種別ID', 'device_type_id', INT_LEN, 'n', array('NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
154 | $objFormParam->addParam('ブロック名', 'bloc_name', STEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
155 | $objFormParam->addParam('ファイル名', 'filename', STEXT_LEN, 'a', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
156 | $objFormParam->addParam('ブロックデータ', 'bloc_html'); |
---|
157 | } |
---|
158 | |
---|
159 | /** |
---|
160 | * ブロックのテンプレートを取得する. |
---|
161 | * |
---|
162 | * @param integer $bloc_id ブロックID |
---|
163 | * @param SC_Helper_Bloc_Ex $objBloc SC_Helper_Bloc_Ex インスタンス |
---|
164 | * @return array ブロック情報の配列 |
---|
165 | */ |
---|
166 | public function getBlocTemplate($bloc_id, SC_Helper_Bloc_Ex &$objBloc) |
---|
167 | { |
---|
168 | $arrBloc = $objBloc->getBloc($bloc_id); |
---|
169 | |
---|
170 | return $arrBloc; |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * 登録を実行する. |
---|
175 | * |
---|
176 | * ファイルの作成に失敗した場合は, エラーメッセージを出力し, |
---|
177 | * データベースをロールバックする. |
---|
178 | * |
---|
179 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
180 | * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス |
---|
181 | * @return integer|boolean 登録が成功した場合, 登録したブロックID; |
---|
182 | * 失敗した場合 false |
---|
183 | */ |
---|
184 | public function doRegister(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) |
---|
185 | { |
---|
186 | $arrParams = $objFormParam->getHashArray(); |
---|
187 | $result = $objBloc->save($arrParams); |
---|
188 | |
---|
189 | if (!$result) { |
---|
190 | $this->arrErr['err'] = '※ ブロックの書き込みに失敗しました<br />'; |
---|
191 | } |
---|
192 | |
---|
193 | return $result; |
---|
194 | } |
---|
195 | |
---|
196 | /** |
---|
197 | * 削除を実行する. |
---|
198 | * |
---|
199 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
200 | * @param SC_Helper_Bloc $objBloc SC_Helper_Bloc インスタンス |
---|
201 | * @return boolean 登録が成功した場合 true; 失敗した場合 false |
---|
202 | */ |
---|
203 | public function doDelete(&$objFormParam, SC_Helper_Bloc_Ex &$objBloc) |
---|
204 | { |
---|
205 | $arrParams = $objFormParam->getHashArray(); |
---|
206 | $result = $objBloc->delete($arrParams['bloc_id']); |
---|
207 | |
---|
208 | if (!$result) { |
---|
209 | $this->arrErr['err'] = '※ ブロックの削除に失敗しました<br />'; |
---|
210 | } |
---|
211 | |
---|
212 | return $result; |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * エラーチェックを行う. |
---|
217 | * |
---|
218 | * @param SC_FormParam $objFormParam SC_FormParam インスタンス |
---|
219 | * @return array エラーメッセージの配列 |
---|
220 | */ |
---|
221 | public function lfCheckError(&$objFormParam, &$arrErr, SC_Helper_Bloc_Ex &$objBloc) |
---|
222 | { |
---|
223 | $arrParams = $objFormParam->getHashArray(); |
---|
224 | $objErr = new SC_CheckError_Ex($arrParams); |
---|
225 | $objErr->arrErr =& $arrErr; |
---|
226 | $objErr->doFunc(array('ブロック名', 'bloc_name', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK')); |
---|
227 | $objErr->doFunc(array('ファイル名', 'filename', STEXT_LEN), array('EXIST_CHECK', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK','FILE_NAME_CHECK_BY_NOUPLOAD')); |
---|
228 | |
---|
229 | $where = 'filename = ?'; |
---|
230 | $arrValues = array($arrParams['filename']); |
---|
231 | |
---|
232 | // 変更の場合は自ブロックを除外 |
---|
233 | if (!SC_Utils_Ex::isBlank($arrParams['bloc_id'])) { |
---|
234 | $where .= ' AND bloc_id <> ?'; |
---|
235 | $arrValues[] = $arrParams['bloc_id']; |
---|
236 | } |
---|
237 | $arrBloc = $objBloc->getWhere($where, $arrValues); |
---|
238 | if (!SC_Utils_Ex::isBlank($arrBloc)) { |
---|
239 | $objErr->arrErr['filename'] = '※ 同じファイル名のデータが存在しています。別のファイル名を入力してください。<br />'; |
---|
240 | } |
---|
241 | |
---|
242 | return $objErr->arrErr; |
---|
243 | } |
---|
244 | } |
---|