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

Revision 23066, 14.4 KB checked in by pineray, 11 years ago (diff)

#2342 JavaScript?のグローバルな宣言を減らす
eccubeオブジェクト内の階層を減らす.

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