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_REALDIR . "pages/admin/LC_Page_Admin.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * システム管理 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class LC_Page_Admin_System_Input extends LC_Page_Admin { |
---|
35 | |
---|
36 | // }}} |
---|
37 | // {{{ functions |
---|
38 | |
---|
39 | /** |
---|
40 | * Page を初期化する. |
---|
41 | * |
---|
42 | * @return void |
---|
43 | */ |
---|
44 | function init() { |
---|
45 | parent::init(); |
---|
46 | |
---|
47 | $this->tpl_mainpage = 'system/input.tpl'; |
---|
48 | |
---|
49 | // ページ送り用ナンバーの取得 |
---|
50 | $this->tpl_pageno = isset($_REQUEST['pageno']) ? $_REQUEST['pageno'] : 1; |
---|
51 | |
---|
52 | // マスタ-データから権限配列を取得 |
---|
53 | $masterData = new SC_DB_MasterData_Ex(); |
---|
54 | $this->arrAUTHORITY = $masterData->getMasterData('mtb_authority'); |
---|
55 | |
---|
56 | $this->httpCacheControl('nocache'); |
---|
57 | } |
---|
58 | |
---|
59 | /** |
---|
60 | * Page のプロセス. |
---|
61 | * |
---|
62 | * @return void |
---|
63 | */ |
---|
64 | function process() { |
---|
65 | $this->action(); |
---|
66 | $this->sendResponse(); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * Page のアクション. |
---|
71 | * |
---|
72 | * @return void |
---|
73 | */ |
---|
74 | function action() { |
---|
75 | // ログインチェック |
---|
76 | SC_Utils::sfIsSuccess(new SC_Session()); |
---|
77 | |
---|
78 | // トランザクショントークンの取得 |
---|
79 | $this->transactionid = SC_Helper_Session_Ex::getToken(); |
---|
80 | |
---|
81 | switch($this->getMode()) { |
---|
82 | case 'new': |
---|
83 | $this->execNewMode(); |
---|
84 | break; |
---|
85 | |
---|
86 | case 'edit': |
---|
87 | $this->execEditMode(); |
---|
88 | break; |
---|
89 | |
---|
90 | case 'parent_reload': |
---|
91 | $this->execParentReloadMode(); |
---|
92 | // defaultアクションも実行させるためbreakしない |
---|
93 | |
---|
94 | default: |
---|
95 | $this->execDefaultMode(); |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | /** |
---|
101 | * デストラクタ. |
---|
102 | * |
---|
103 | * @return void |
---|
104 | */ |
---|
105 | function destroy() { |
---|
106 | parent::destroy(); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * switchアクション振り分け用パラメータを取得する. |
---|
111 | * |
---|
112 | * @param void |
---|
113 | * @return string モード名 |
---|
114 | */ |
---|
115 | function getMode() { |
---|
116 | $mode = ''; |
---|
117 | if ($_SERVER['REQUEST_METHOD'] == 'GET') { |
---|
118 | if(isset($_GET['mode'])) $mode = $_GET['mode']; |
---|
119 | } elseif ($_SERVER['REQUEST_METHOD'] == 'POST') { |
---|
120 | if(isset($_POST['mode'])) $mode = $_POST['mode']; |
---|
121 | } |
---|
122 | return $mode; |
---|
123 | } |
---|
124 | |
---|
125 | /** |
---|
126 | * newアクションの実行 |
---|
127 | * メンバーデータの新規登録を行う. |
---|
128 | * |
---|
129 | * @param void |
---|
130 | * @return void |
---|
131 | */ |
---|
132 | function execNewMode() { |
---|
133 | if (SC_Helper_Session_Ex::isValidToken() !== true) { |
---|
134 | SC_Utils::sfDispError(''); |
---|
135 | } |
---|
136 | |
---|
137 | $this->initNewMode(); |
---|
138 | |
---|
139 | $arrErr = $this->validateNewMode(); |
---|
140 | |
---|
141 | if (count($arrErr) > 0) { |
---|
142 | // 入力された値を保持する |
---|
143 | $this->tpl_mode = $_POST['mode']; |
---|
144 | $this->tpl_member_id = $_POST['member_id']; |
---|
145 | $this->tpl_old_login_id = $_POST['old_login_id']; |
---|
146 | $this->arrForm = $this->objForm->getHashArray(); |
---|
147 | // パスワードは保持しない |
---|
148 | $this->arrForm['password'] = ''; |
---|
149 | // エラー情報をセットする |
---|
150 | $this->arrErr = $arrErr; |
---|
151 | // トランザクショントークンの取得 |
---|
152 | $this->transactionid = SC_Helper_Session_Ex::getToken(); |
---|
153 | return; |
---|
154 | } |
---|
155 | |
---|
156 | $this->insertMemberData($this->objForm->getHashArray()); |
---|
157 | $this->objDisplay->reload(array('mode' => 'parent_reload')); |
---|
158 | } |
---|
159 | |
---|
160 | /** |
---|
161 | * newアクションの初期化. |
---|
162 | * SC_FormParamのインスタンスをメンバ変数にセットする. |
---|
163 | * |
---|
164 | * @param void |
---|
165 | * @return void |
---|
166 | */ |
---|
167 | function initNewMode($mode = "") { |
---|
168 | $objForm = new SC_FormParam(); |
---|
169 | |
---|
170 | $objForm->addParam('名前', 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK')); |
---|
171 | $objForm->addParam('所属', 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK')); |
---|
172 | $objForm->addParam('ログインID', 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK')); |
---|
173 | if ($mode == "edit" && $_POST['password'] == DUMMY_PASS) { |
---|
174 | $objForm->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK')); |
---|
175 | } else { |
---|
176 | $objForm->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK')); |
---|
177 | } |
---|
178 | $objForm->addParam('権限', 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK')); |
---|
179 | |
---|
180 | $objForm->setParam($_POST); |
---|
181 | $objForm->convParam(); |
---|
182 | |
---|
183 | $this->objForm = $objForm; |
---|
184 | } |
---|
185 | |
---|
186 | /** |
---|
187 | * newアクションのパラメータ検証を行う. |
---|
188 | * |
---|
189 | * @param void |
---|
190 | * @return array エラー情報の連想配列 |
---|
191 | */ |
---|
192 | function validateNewMode() { |
---|
193 | $arrErr = $this->objForm->checkError(); |
---|
194 | if (isset($arrErr) && count($arrErr) > 0) return $arrErr; |
---|
195 | |
---|
196 | // ログインID・パスワードの文字数チェック |
---|
197 | $objErr = new SC_CheckError(); |
---|
198 | $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array("NUM_RANGE_CHECK")); |
---|
199 | $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array("NUM_RANGE_CHECK")); |
---|
200 | |
---|
201 | $arrErr = $objErr->arrErr; |
---|
202 | |
---|
203 | // 管理者名が登録済みでないか |
---|
204 | if ($this->memberDataExists('name = ?', $_POST['name'])) { |
---|
205 | $arrErr['name'] = "既に登録されている名前なので利用できません。<br>"; |
---|
206 | } |
---|
207 | // ログインIDが登録済みでないか |
---|
208 | if ($this->memberDataExists('login_id = ?', $_POST['login_id'])) { |
---|
209 | $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>"; |
---|
210 | } |
---|
211 | |
---|
212 | return $arrErr; |
---|
213 | } |
---|
214 | |
---|
215 | /** |
---|
216 | * editアクションの実行 |
---|
217 | * メンバーデータの更新を行う. |
---|
218 | * |
---|
219 | * @param void |
---|
220 | * @return void |
---|
221 | */ |
---|
222 | function execEditMode() { |
---|
223 | if (SC_Helper_Session_Ex::isValidToken() !== true) { |
---|
224 | SC_Utils::sfDispError(''); |
---|
225 | } |
---|
226 | |
---|
227 | $this->initNewMode("edit"); |
---|
228 | |
---|
229 | $arrErr = $this->validateEditMode(); |
---|
230 | |
---|
231 | if (count($arrErr) > 0) { |
---|
232 | // 入力された値を保持する |
---|
233 | $this->tpl_mode = $_POST['mode']; |
---|
234 | $this->tpl_member_id = $_POST['member_id']; |
---|
235 | $this->tpl_old_login_id = $_POST['old_login_id']; |
---|
236 | $this->arrForm = $this->objForm->getHashArray(); |
---|
237 | // パスワードは保持しない |
---|
238 | $this->arrForm['password'] = ''; |
---|
239 | // エラー情報をセットする |
---|
240 | $this->arrErr = $arrErr; |
---|
241 | // トランザクショントークンの取得 |
---|
242 | $this->transactionid = SC_Helper_Session_Ex::getToken(); |
---|
243 | return; |
---|
244 | } |
---|
245 | |
---|
246 | $this->updateMemberData($_POST['member_id'], $this->objForm->getHashArray()); |
---|
247 | // 親ウィンドウを更新後、自ウィンドウを閉じる。 |
---|
248 | $url = ADMIN_SYSTEM_URL_PATH . "?pageno=" . $_POST['pageno']; |
---|
249 | $this->tpl_onload = "fnUpdateParent('".$url."'); window.close();"; |
---|
250 | } |
---|
251 | |
---|
252 | /** |
---|
253 | * editアクションのパラメータ検証を行う. |
---|
254 | * |
---|
255 | * @param void |
---|
256 | * @return array エラー情報の連想配列 |
---|
257 | */ |
---|
258 | function validateEditMode() { |
---|
259 | $arrErr = $this->objForm->checkError(); |
---|
260 | if (isset($arrErr) && count($arrErr) > 0) return $arrErr; |
---|
261 | |
---|
262 | // ログインID・パスワードの文字数チェック |
---|
263 | $objErr = new SC_CheckError(); |
---|
264 | $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array("SPTAB_CHECK" ,"NUM_RANGE_CHECK")); |
---|
265 | $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array("SPTAB_CHECK" ,"NUM_RANGE_CHECK")); |
---|
266 | |
---|
267 | $arrErr = $objErr->arrErr; |
---|
268 | |
---|
269 | // ログインIDが変更されている場合はチェックする。 |
---|
270 | if ($_POST['login_id'] != $_POST['old_login_id']) { |
---|
271 | // ログインIDが登録済みでないか |
---|
272 | if ($this->memberDataExists('login_id = ?', $_POST['login_id'])) { |
---|
273 | $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>"; |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | return $arrErr; |
---|
278 | } |
---|
279 | |
---|
280 | /** |
---|
281 | * parent_reloadアクションを実行する. |
---|
282 | * テンプレートに親windowをリロードするjavascriptをセットする. |
---|
283 | * |
---|
284 | * @param void |
---|
285 | * @return void |
---|
286 | */ |
---|
287 | function execParentReloadMode() { |
---|
288 | $url = ADMIN_SYSTEM_URL_PATH; |
---|
289 | $this->tpl_onload = "fnUpdateParent('$url')"; |
---|
290 | } |
---|
291 | |
---|
292 | /** |
---|
293 | * defaultアクションを実行する. |
---|
294 | * 初回表示時に実行される. |
---|
295 | * $GET['id']が渡された場合、編集モードとして表示, |
---|
296 | * 無い場合は新規登録モードとして表示する. |
---|
297 | * |
---|
298 | * @param void |
---|
299 | * @return void |
---|
300 | */ |
---|
301 | function execDefaultMode() { |
---|
302 | // $_GET['id']があれば編集モードで表示する |
---|
303 | if (isset($_GET['id']) && SC_Utils::sfIsInt($_GET['id'])) { |
---|
304 | $this->tpl_mode = 'edit'; |
---|
305 | $this->tpl_member_id = $_GET['id']; |
---|
306 | $this->tpl_onfocus = "fnClearText(this.name);"; |
---|
307 | $this->arrForm = $this->getMemberData($_GET['id']); |
---|
308 | $this->arrForm['password'] = DUMMY_PASS; |
---|
309 | $this->tpl_old_login_id = $this->arrForm['login_id']; |
---|
310 | // 新規作成モードで表示 |
---|
311 | } else { |
---|
312 | $this->tpl_mode = "new"; |
---|
313 | $this->arrForm['authority'] = -1; |
---|
314 | } |
---|
315 | } |
---|
316 | |
---|
317 | /** |
---|
318 | * DBからmember_idに対応する管理者データを取得する |
---|
319 | * |
---|
320 | * @param integer $id メンバーID |
---|
321 | * @return array 管理者データの連想配列, 無い場合は空の配列を返す |
---|
322 | */ |
---|
323 | function getMemberData($id) { |
---|
324 | $table = 'dtb_member'; |
---|
325 | $columns = 'name,department,login_id,authority'; |
---|
326 | $where = 'member_id = ?'; |
---|
327 | |
---|
328 | $objQuery = new SC_Query(); |
---|
329 | $arrRet = $objQuery->select($columns, $table, $where, array($id)); |
---|
330 | |
---|
331 | if (is_null($arrRet)) return array(); |
---|
332 | |
---|
333 | return $arrRet[0]; |
---|
334 | } |
---|
335 | |
---|
336 | /** |
---|
337 | * 値が登録済みかどうかを調べる |
---|
338 | * |
---|
339 | * @param string $where WHERE句 |
---|
340 | * @param string $val 検索したい値 |
---|
341 | * @return boolean 登録済みならtrue, 未登録ならfalse |
---|
342 | */ |
---|
343 | function memberDataExists($where, $val) { |
---|
344 | $table = 'dtb_member'; |
---|
345 | |
---|
346 | $objQuery = new SC_Query(); |
---|
347 | $count = $objQuery->count($table, $where, array($val)); |
---|
348 | |
---|
349 | if ($count > 0) return true; |
---|
350 | return false; |
---|
351 | } |
---|
352 | |
---|
353 | /** |
---|
354 | * 入力された管理者データをInsertする. |
---|
355 | * |
---|
356 | * @param array 管理者データの連想配列 |
---|
357 | * @return void |
---|
358 | */ |
---|
359 | function insertMemberData($arrMemberData) { |
---|
360 | $objQuery = new SC_Query(); |
---|
361 | |
---|
362 | // INSERTする値を作成する. |
---|
363 | $sqlVal = array(); |
---|
364 | $sqlVal['name'] = $arrMemberData['name']; |
---|
365 | $sqlVal['department'] = $arrMemberData['department']; |
---|
366 | $sqlVal['login_id'] = $arrMemberData['login_id']; |
---|
367 | $sqlVal['password'] = sha1($arrMemberData['password'] . ':' . AUTH_MAGIC); |
---|
368 | $sqlVal['authority'] = $arrMemberData['authority']; |
---|
369 | $sqlVal['rank'] = $objQuery->max('rank', 'dtb_member') + 1; |
---|
370 | $sqlVal['work'] = '1'; // 稼働に設定 |
---|
371 | $sqlVal['del_flg'] = '0'; // 削除フラグをOFFに設定 |
---|
372 | $sqlVal['creator_id'] = $_SESSION['member_id']; |
---|
373 | $sqlVal['create_date'] = 'NOW()'; |
---|
374 | $sqlVal['update_date'] = 'NOW()'; |
---|
375 | |
---|
376 | // INSERTの実行 |
---|
377 | $sqlval['member_id'] = $objQuery->nextVal('dtb_member_member_id'); |
---|
378 | $objQuery->insert('dtb_member', $sqlVal); |
---|
379 | } |
---|
380 | |
---|
381 | /** |
---|
382 | * 管理者データをUpdateする. |
---|
383 | * |
---|
384 | * @param array 管理者データの連想配列 |
---|
385 | * @return void |
---|
386 | */ |
---|
387 | function updateMemberData($member_id, $arrMemberData) { |
---|
388 | $objQuery = new SC_Query(); |
---|
389 | |
---|
390 | // Updateする値を作成する. |
---|
391 | $sqlVal = array(); |
---|
392 | $sqlVal['name'] = $arrMemberData['name']; |
---|
393 | $sqlVal['department'] = $arrMemberData['department']; |
---|
394 | $sqlVal['login_id'] = $arrMemberData['login_id']; |
---|
395 | $sqlVal['authority'] = $arrMemberData['authority']; |
---|
396 | $sqlVal['update_date'] = 'NOW()'; |
---|
397 | if($arrMemberData['password'] != DUMMY_PASS) { |
---|
398 | $sqlVal['password'] = sha1($arrMemberData['password'] . ":" . AUTH_MAGIC); |
---|
399 | } |
---|
400 | |
---|
401 | $where = "member_id = ?"; |
---|
402 | |
---|
403 | // UPDATEの実行 |
---|
404 | $objQuery->update("dtb_member", $sqlVal, $where, array($member_id)); |
---|
405 | } |
---|
406 | } |
---|
407 | ?> |
---|