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

Revision 22856, 14.5 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。もう少し整えたいが、一旦現状コミット。
  • 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 = "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                    $this->updateMemberData($this->arrForm['member_id'], $this->arrForm);
120                    // 親ウィンドウを更新後、自ウィンドウを閉じる。
121                    $url = ADMIN_SYSTEM_URLPATH . '?pageno=' . $this->arrForm['pageno'];
122                    $this->tpl_onload = "fnUpdateParent('".$url."'); window.close();";
123
124                } else {
125                    // 入力された値を保持する
126                    $this->tpl_mode      = $this->getMode();
127                    $this->tpl_member_id = $this->arrForm['member_id'];
128                    $this->tpl_old_login_id = $this->arrForm['old_login_id'];
129
130                    // パスワードは保持しない
131                    $this->arrForm['password'] = '';
132                    $this->arrForm['password02'] = '';
133                    // エラー情報をセットする
134                    $this->arrErr = $arrErr;
135                }
136                break;
137
138            default:
139
140                // $_GET['id'](member_id)が登録済みのものかチェック。
141                // 登録されていない場合は不正なものとして、新規扱いとする。
142                $clean_id = '';
143                $clean_mode_flg = 'new';
144
145                // idが0より大きい数字で整数の場合
146                if (isset($_GET['id']) && SC_Utils_Ex::sfIsInt($_GET['id']) && $_GET['id'] > 0) {
147                    if ($this->memberDataExists('member_id = ? AND del_flg = 0', $_GET['id'])) {
148                        $clean_id = $_GET['id'];
149                        $clean_mode_flg = 'edit';
150                    }
151                }
152
153                switch ($clean_mode_flg) {
154                    case 'edit':
155                        $this->tpl_mode      = $clean_mode_flg;
156                        $this->tpl_member_id = $clean_id;
157                        $this->tpl_onfocus   = 'fnClearText(this.name);';
158                        $this->arrForm       = $this->getMemberData($clean_id);
159                        $this->arrForm['password'] = DEFAULT_PASSWORD;
160                        $this->arrForm['password02'] = 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     *
179     * @return void
180     */
181    function destroy()
182    {
183        parent::destroy();
184    }
185
186    /**
187     * フォームパラメーター初期化
188     *
189     * @param object $objFormParam
190     * @param array  $arrParams $_POST値
191     * @param string $mode editの時は指定
192     * @return void
193     */
194    function initForm(&$objFormParam, &$arrParams, $mode = '')
195    {
196        $objFormParam->addParam('メンバーID', 'member_id', INT_LEN, 'n', array('NUM_CHECK'));
197        $objFormParam->addParam('名前', 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
198        $objFormParam->addParam('所属', 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK'));
199        $objFormParam->addParam('ログインID', 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
200        $objFormParam->addParam('変更前ログインID', 'old_login_id', '' , '', array('ALNUM_CHECK'));
201        if ($mode == 'edit' && $arrParams['password'] == DEFAULT_PASSWORD) {
202            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK'));
203            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK'));
204        } else {
205            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
206            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
207        }
208        $objFormParam->addParam('権限', 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
209        $objFormParam->addParam('稼働/非稼働', 'work', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
210        $objFormParam->addParam('ページ', 'pageno', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
211
212        $objFormParam->setParam($arrParams);
213        $objFormParam->convParam();
214
215    }
216
217    /**
218     * パラメーターの妥当性検証を行う.
219     *
220     * @param void
221     * @return array エラー情報の連想配列
222     */
223    function validateData(&$objFormParam, &$arrParams, $mode)
224    {
225        $arrErr = $objFormParam->checkError();
226        if (isset($arrErr) && count($arrErr) > 0) return $arrErr;
227
228        // ログインID・パスワードの文字数チェック
229        $objErr = new SC_CheckError_Ex();
230        if ($mode == 'new') {
231            $objErr->doFunc(array('パスワード', 'password', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
232            $objErr->doFunc(array('ログインID', 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
233        } elseif ($mode == 'edit') {
234            $objErr->doFunc(array('パスワード', 'password', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
235            $objErr->doFunc(array('ログインID', 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
236        }
237        $objErr->doFunc(array('パスワード', 'パスワード(確認)', 'password', 'password02') ,array('EQUAL_CHECK'));
238
239        $arrErr = $objErr->arrErr;
240
241        switch ($mode) {
242            case 'new':
243                // 管理者名が登録済みでないか
244                if ($this->memberDataExists('name = ? AND del_flg = 0', $arrParams['name'])) {
245                    $arrErr['name'] = '既に登録されている名前なので利用できません。<br>';
246                }
247                // ログインIDが登録済みでないか
248                if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
249                    $arrErr['login_id'] = '既に登録されているIDなので利用できません。<br>';
250                }
251                break;
252            case 'edit':
253                // ログインIDが変更されている場合はチェックする。
254                if ($arrParams['login_id'] != $arrParams['old_login_id']) {
255                    // ログインIDが登録済みでないか
256                    if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
257                        $arrErr['login_id'] = '既に登録されているIDなので利用できません。<br>';
258                    }
259                }
260                break;
261        }
262
263        return $arrErr;
264    }
265
266    /**
267     * DBからmember_idに対応する管理者データを取得する
268     *
269     * @param integer $id メンバーID
270     * @return array 管理者データの連想配列, 無い場合は空の配列を返す
271     */
272    function getMemberData($id)
273    {
274        $table   = 'dtb_member';
275        $columns = 'name,department,login_id,authority, work';
276        $where   = 'member_id = ?';
277
278        $objQuery =& SC_Query_Ex::getSingletonInstance();
279
280        return $objQuery->getRow($columns, $table, $where, array($id));
281    }
282
283    /**
284     *  値が登録済みかどうかを調べる
285     *
286     * @param string $where WHERE句
287     * @param string $val 検索したい値
288     * @return boolean 登録済みならtrue, 未登録ならfalse
289     */
290    function memberDataExists($where, $val)
291    {
292        $objQuery =& SC_Query_Ex::getSingletonInstance();
293
294        $table = 'dtb_member';
295
296        $exists = $objQuery->exists($table, $where, array($val));
297
298        return $exists;
299    }
300
301    /**
302     * ページ番号が信頼しうる値かチェックする.
303     *
304     * @access private
305     * @param  integer $pageno ページの番号
306     * @return integer $clean_pageno チェック後のページの番号
307     */
308    function lfCheckPageNo($pageno)
309    {
310        $clean_pageno = '';
311
312        // $pagenoが0以上の整数かチェック
313        if (SC_Utils_Ex::sfIsInt($pageno) && $pageno > 0) {
314            $clean_pageno = $pageno;
315        }
316
317        // 例外は全て1とする
318        else {
319            $clean_pageno = 1;
320        }
321
322        return $clean_pageno;
323    }
324
325    /**
326     * 入力された管理者データをInsertする.
327     *
328     * @param array 管理者データの連想配列
329     * @return void
330     */
331    function insertMemberData($arrMemberData)
332    {
333        $objQuery =& SC_Query_Ex::getSingletonInstance();
334
335        // INSERTする値を作成する.
336        $salt                  = SC_Utils_Ex::sfGetRandomString(10);
337        $sqlVal = array();
338        $sqlVal['name']        = $arrMemberData['name'];
339        $sqlVal['department']  = $arrMemberData['department'];
340        $sqlVal['login_id']    = $arrMemberData['login_id'];
341        $sqlVal['password']    = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
342        $sqlVal['salt']        = $salt;
343        $sqlVal['authority']   = $arrMemberData['authority'];
344        $sqlVal['rank']        = $objQuery->max('rank', 'dtb_member') + 1;
345        $sqlVal['work']        = $arrMemberData['work'];
346        $sqlVal['del_flg']     = '0'; // 削除フラグをOFFに設定
347        $sqlVal['creator_id']  = $_SESSION['member_id'];
348        $sqlVal['create_date'] = 'CURRENT_TIMESTAMP';
349        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
350
351        // INSERTの実行
352        $sqlVal['member_id'] = $objQuery->nextVal('dtb_member_member_id');
353        $objQuery->insert('dtb_member', $sqlVal);
354    }
355
356    /**
357     * 管理者データをUpdateする.
358     *
359     * @param array 管理者データの連想配列
360     * @return void
361     */
362    function updateMemberData($member_id, $arrMemberData)
363    {
364        $objQuery =& SC_Query_Ex::getSingletonInstance();
365
366        // Updateする値を作成する.
367        $sqlVal = array();
368        $sqlVal['name']        = $arrMemberData['name'];
369        $sqlVal['department']  = $arrMemberData['department'];
370        $sqlVal['login_id']    = $arrMemberData['login_id'];
371        $sqlVal['authority']   = $arrMemberData['authority'];
372        $sqlVal['work']   = $arrMemberData['work'];
373        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
374        if ($arrMemberData['password'] != DEFAULT_PASSWORD) {
375            $salt = SC_Utils_Ex::sfGetRandomString(10);
376            $sqlVal['salt']     = $salt;
377            $sqlVal['password'] = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
378        }
379
380        $where = 'member_id = ?';
381
382        // UPDATEの実行
383        $objQuery->update('dtb_member', $sqlVal, $where, array($member_id));
384    }
385}
Note: See TracBrowser for help on using the repository browser.