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

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

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

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