source: branches/version-2_12-dev/data/class/pages/admin/system/LC_Page_Admin_System_Input.php @ 21511

Revision 21511, 13.9 KB checked in by pingpong, 12 years ago (diff)

#1494 管理機能でもパスワードの確認入力を行う

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
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
25require_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 */
34class LC_Page_Admin_System_Input 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
47        $this->tpl_mainpage = 'system/input.tpl';
48
49        // マスターデータから権限配列を取得
50        $masterData = new SC_DB_MasterData_Ex();
51        $this->arrAUTHORITY = $masterData->getMasterData('mtb_authority');
52
53        $this->tpl_subtitle = 'メンバー登録/編集';
54        $this->httpCacheControl('nocache');
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     * @return void
71     */
72    function action() {
73        // ページ送りの処理 $_REQUEST['pageno']が信頼しうる値かどうかチェックする。
74        $this->tpl_pageno = $this->lfCheckPageNo($_REQUEST['pageno']);
75
76        $objFormParam = new SC_FormParam_Ex();
77        $arrErr = array();
78        $arrForm = array();
79
80        switch ($this->getMode()) {
81        case 'new':
82            // パラメーターの初期化
83            $this->initForm($objFormParam, $_POST);
84
85            // エラーチェック
86            $arrErr = $this->validateData($objFormParam, $_POST, $this->getMode());
87            $this->arrForm = $objFormParam->getHashArray();
88
89            if (SC_Utils_Ex::isBlank($arrErr)) {
90
91                $this->insertMemberData($this->arrForm);
92                // 親ウィンドウを更新後、自ウィンドウを閉じる。
93                $url = ADMIN_SYSTEM_URLPATH . "?pageno=" . $this->arrForm['pageno'];
94                $this->tpl_onload = "fnUpdateParent('".$url."'); window.close();";
95
96            } else {
97                // 入力された値を保持する
98                $this->tpl_mode      = $this->getMode();
99                $this->tpl_member_id = '';
100                $this->tpl_old_login_id = '';
101
102                // パスワードは保持しない
103                $this->arrForm['password'] = '';
104                $this->arrForm['password02'] = '';
105                // エラー情報をセットする
106                $this->arrErr = $arrErr;
107            }
108            break;
109
110        case 'edit':
111            // パラメーターの初期化
112            $this->initForm($objFormParam, $_POST, $this->getMode());
113
114            // エラーチェック
115            $arrErr = $this->validateData($objFormParam, $_POST, $this->getMode());
116            $this->arrForm = $objFormParam->getHashArray();
117
118            if (SC_Utils_Ex::isBlank($arrErr)) {
119
120                $this->updateMemberData($this->arrForm['member_id'], $this->arrForm);
121                // 親ウィンドウを更新後、自ウィンドウを閉じる。
122                $url = ADMIN_SYSTEM_URLPATH . "?pageno=" . $this->arrForm['pageno'];
123                $this->tpl_onload = "fnUpdateParent('".$url."'); window.close();";
124
125            } else {
126                // 入力された値を保持する
127                $this->tpl_mode      = $this->getMode();
128                $this->tpl_member_id = $this->arrForm['member_id'];
129                $this->tpl_old_login_id = $this->arrForm['old_login_id'];
130
131                // パスワードは保持しない
132                $this->arrForm['password'] = '';
133                $this->arrForm['password02'] = '';
134                // エラー情報をセットする
135                $this->arrErr = $arrErr;
136            }
137            break;
138
139        default:
140
141            // $_GET['id'](member_id)が登録済みのものかチェック。
142            // 登録されていない場合は不正なものとして、新規扱いとする。
143            $clean_id = "";
144            $clean_mode_flg = 'new';
145
146            // idが0より大きい数字で整数の場合
147            if (isset($_GET['id']) && SC_Utils_Ex::sfIsInt($_GET['id']) && $_GET['id'] > 0) {
148                if ($this->memberDataExists('member_id = ? AND del_flg = 0', $_GET['id'])) {
149                    $clean_id = $_GET['id'];
150                    $clean_mode_flg = 'edit';
151                }
152            }
153
154            switch ($clean_mode_flg) {
155            case 'edit':
156                $this->tpl_mode      = $clean_mode_flg;
157                $this->tpl_member_id = $clean_id;
158                $this->tpl_onfocus   = "fnClearText(this.name);";
159                $this->arrForm       = $this->getMemberData($clean_id);
160                $this->arrForm['password'] = DEFAULT_PASSWORD;
161                $this->tpl_old_login_id    = $this->arrForm['login_id'];
162                break;
163
164            case 'new':
165            default:
166                $this->tpl_mode = $clean_mode_flg;
167                $this->arrForm['authority'] = -1;
168                break;
169            }
170            break;
171        }
172        $this->setTemplate($this->tpl_mainpage);
173    }
174
175    /**
176     * デストラクタ.
177     *
178     * @return void
179     */
180    function destroy() {
181        parent::destroy();
182    }
183
184    /**
185     * フォームパラメーター初期化
186     *
187     * @param object $objFormParam
188     * @param array  $arrParams $_POST値
189     * @param string $mode editの時は指定
190     * @return void
191     */
192    function initForm(&$objFormParam, &$arrParams, $mode = "") {
193
194        $objFormParam->addParam('メンバーID', 'member_id', INT_LEN, 'n', array('NUM_CHECK'));
195        $objFormParam->addParam('名前', 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
196        $objFormParam->addParam('所属', 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK'));
197        $objFormParam->addParam('ログインID', 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
198        $objFormParam->addParam('変更前ログインID', 'old_login_id', '' , '', array('ALNUM_CHECK'));
199        if ($mode == 'edit' && $arrParams['password'] == DEFAULT_PASSWORD) {
200            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK'));
201            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK'));
202        } else {
203            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
204            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
205        }
206        $objFormParam->addParam('権限', 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
207        $objFormParam->addParam('稼働/非稼働', 'work', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
208        $objFormParam->addParam('ページ', 'pageno', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
209
210        $objFormParam->setParam($arrParams);
211        $objFormParam->convParam();
212
213    }
214
215    /**
216     * パラメーターの妥当性検証を行う.
217     *
218     * @param void
219     * @return array エラー情報の連想配列
220     */
221    function validateData(&$objFormParam, &$arrParams, $mode) {
222        $arrErr = $objFormParam->checkError();
223        if (isset($arrErr) && count($arrErr) > 0) return $arrErr;
224
225        // ログインID・パスワードの文字数チェック
226        $objErr = new SC_CheckError_Ex();
227        if ($mode == 'new') {
228            $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
229            $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
230        } elseif ($mode == 'edit') {
231            $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
232            $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
233        }
234    $objErr->doFunc(array('パスワード', 'パスワード(確認)', 'password', 'password02') ,array('EQUAL_CHECK'));
235
236        $arrErr = $objErr->arrErr;
237
238        switch ($mode) {
239        case 'new':
240            // 管理者名が登録済みでないか
241            if ($this->memberDataExists('name = ? AND del_flg = 0', $arrParams['name'])) {
242                $arrErr['name'] = "既に登録されている名前なので利用できません。<br>";
243            }
244            // ログインIDが登録済みでないか
245            if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
246                $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>";
247            }
248            break;
249        case 'edit':
250            // ログインIDが変更されている場合はチェックする。
251            if ($arrParams['login_id'] != $arrParams['old_login_id']) {
252                // ログインIDが登録済みでないか
253                if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
254                    $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>";
255                }
256            }
257            break;
258        }
259
260        return $arrErr;
261    }
262
263    /**
264     * DBからmember_idに対応する管理者データを取得する
265     *
266     * @param integer $id メンバーID
267     * @return array 管理者データの連想配列, 無い場合は空の配列を返す
268     */
269    function getMemberData($id) {
270        $table   = 'dtb_member';
271        $columns = 'name,department,login_id,authority, work';
272        $where   = 'member_id = ?';
273
274        $objQuery =& SC_Query_Ex::getSingletonInstance();
275        return $objQuery->getRow($columns, $table, $where, array($id));
276    }
277
278    /**
279     *  値が登録済みかどうかを調べる
280     *
281     * @param string $where WHERE句
282     * @param string $val 検索したい値
283     * @return boolean 登録済みならtrue, 未登録ならfalse
284     */
285    function memberDataExists($where, $val) {
286        $objQuery =& SC_Query_Ex::getSingletonInstance();
287
288        $table = 'dtb_member';
289
290        $exists = $objQuery->exists($table, $where, array($val));
291        return $exists;
292    }
293
294    /**
295     * ページ番号が信頼しうる値かチェックする.
296     *
297     * @access private
298     * @param  integer $pageno ページの番号
299     * @return integer $clean_pageno チェック後のページの番号
300     */
301    function lfCheckPageNo($pageno) {
302
303        $clean_pageno = "";
304
305        // $pagenoが0以上の整数かチェック
306        if (SC_Utils_Ex::sfIsInt($pageno) && $pageno > 0) {
307            $clean_pageno = $pageno;
308        }
309
310        // 例外は全て1とする
311        else {
312            $clean_pageno = 1;
313        }
314
315        return $clean_pageno;
316    }
317
318    /**
319     * 入力された管理者データをInsertする.
320     *
321     * @param array 管理者データの連想配列
322     * @return void
323     */
324    function insertMemberData($arrMemberData) {
325        $objQuery =& SC_Query_Ex::getSingletonInstance();
326
327        // INSERTする値を作成する.
328        $salt                  = SC_Utils_Ex::sfGetRandomString(10);
329        $sqlVal = array();
330        $sqlVal['name']        = $arrMemberData['name'];
331        $sqlVal['department']  = $arrMemberData['department'];
332        $sqlVal['login_id']    = $arrMemberData['login_id'];
333        $sqlVal['password']    = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
334        $sqlVal['salt']        = $salt;
335        $sqlVal['authority']   = $arrMemberData['authority'];
336        $sqlVal['rank']        = $objQuery->max('rank', 'dtb_member') + 1;
337        $sqlVal['work']        = $arrMemberData['work'];
338        $sqlVal['del_flg']     = '0'; // 削除フラグをOFFに設定
339        $sqlVal['creator_id']  = $_SESSION['member_id'];
340        $sqlVal['create_date'] = 'CURRENT_TIMESTAMP';
341        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
342
343        // INSERTの実行
344        $sqlVal['member_id'] = $objQuery->nextVal('dtb_member_member_id');
345        $objQuery->insert('dtb_member', $sqlVal);
346    }
347
348    /**
349     * 管理者データをUpdateする.
350     *
351     * @param array 管理者データの連想配列
352     * @return void
353     */
354    function updateMemberData($member_id, $arrMemberData) {
355        $objQuery =& SC_Query_Ex::getSingletonInstance();
356
357        // Updateする値を作成する.
358        $sqlVal = array();
359        $sqlVal['name']        = $arrMemberData['name'];
360        $sqlVal['department']  = $arrMemberData['department'];
361        $sqlVal['login_id']    = $arrMemberData['login_id'];
362        $sqlVal['authority']   = $arrMemberData['authority'];
363        $sqlVal['work']   = $arrMemberData['work'];
364        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
365        if ($arrMemberData['password'] != DEFAULT_PASSWORD) {
366            $salt = SC_Utils_Ex::sfGetRandomString(10);
367            $sqlVal['salt']     = $salt;
368            $sqlVal['password'] = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
369        }
370
371        $where = "member_id = ?";
372
373        // UPDATEの実行
374        $objQuery->update('dtb_member', $sqlVal, $where, array($member_id));
375    }
376}
Note: See TracBrowser for help on using the repository browser.