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