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

Revision 22264, 14.4 KB checked in by undertree, 11 years ago (diff)

#1616(mtb_workが適切に利用されていない)
表記「稼動」「非稼動」をmtb_workから取得,表示するようにしました。

  • 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
75        // ページ送りの処理 $_REQUEST['pageno']が信頼しうる値かどうかチェックする。
76        $this->tpl_pageno = $this->lfCheckPageNo($_REQUEST['pageno']);
77
78        $objFormParam = new SC_FormParam_Ex();
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
198        $objFormParam->addParam('メンバーID', 'member_id', INT_LEN, 'n', array('NUM_CHECK'));
199        $objFormParam->addParam('名前', 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
200        $objFormParam->addParam('所属', 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK'));
201        $objFormParam->addParam('ログインID', 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
202        $objFormParam->addParam('変更前ログインID', 'old_login_id', '' , '', array('ALNUM_CHECK'));
203        if ($mode == 'edit' && $arrParams['password'] == DEFAULT_PASSWORD) {
204            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK'));
205            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK'));
206        } else {
207            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
208            $objFormParam->addParam('パスワード(確認)', 'password02', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
209        }
210        $objFormParam->addParam('権限', 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
211        $objFormParam->addParam('稼働/非稼働', 'work', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
212        $objFormParam->addParam('ページ', 'pageno', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
213
214        $objFormParam->setParam($arrParams);
215        $objFormParam->convParam();
216
217    }
218
219    /**
220     * パラメーターの妥当性検証を行う.
221     *
222     * @param void
223     * @return array エラー情報の連想配列
224     */
225    function validateData(&$objFormParam, &$arrParams, $mode) {
226        $arrErr = $objFormParam->checkError();
227        if (isset($arrErr) && count($arrErr) > 0) return $arrErr;
228
229        // ログインID・パスワードの文字数チェック
230        $objErr = new SC_CheckError_Ex();
231        if ($mode == 'new') {
232            $objErr->doFunc(array('パスワード', 'password', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
233            $objErr->doFunc(array('ログインID', 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
234        } elseif ($mode == 'edit') {
235            $objErr->doFunc(array('パスワード', 'password', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
236            $objErr->doFunc(array('ログインID', 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
237        }
238    $objErr->doFunc(array('パスワード', 'パスワード(確認)', 'password', 'password02') ,array('EQUAL_CHECK'));
239
240        $arrErr = $objErr->arrErr;
241
242        switch ($mode) {
243        case 'new':
244            // 管理者名が登録済みでないか
245            if ($this->memberDataExists('name = ? AND del_flg = 0', $arrParams['name'])) {
246                $arrErr['name'] = '既に登録されている名前なので利用できません。<br>';
247            }
248            // ログインIDが登録済みでないか
249            if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
250                $arrErr['login_id'] = '既に登録されているIDなので利用できません。<br>';
251            }
252            break;
253        case 'edit':
254            // ログインIDが変更されている場合はチェックする。
255            if ($arrParams['login_id'] != $arrParams['old_login_id']) {
256                // ログインIDが登録済みでないか
257                if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
258                    $arrErr['login_id'] = '既に登録されているIDなので利用できません。<br>';
259                }
260            }
261            break;
262        }
263
264        return $arrErr;
265    }
266
267    /**
268     * DBからmember_idに対応する管理者データを取得する
269     *
270     * @param integer $id メンバーID
271     * @return array 管理者データの連想配列, 無い場合は空の配列を返す
272     */
273    function getMemberData($id) {
274        $table   = 'dtb_member';
275        $columns = 'name,department,login_id,authority, work';
276        $where   = 'member_id = ?';
277
278        $objQuery =& SC_Query_Ex::getSingletonInstance();
279        return $objQuery->getRow($columns, $table, $where, array($id));
280    }
281
282    /**
283     *  値が登録済みかどうかを調べる
284     *
285     * @param string $where WHERE句
286     * @param string $val 検索したい値
287     * @return boolean 登録済みならtrue, 未登録ならfalse
288     */
289    function memberDataExists($where, $val) {
290        $objQuery =& SC_Query_Ex::getSingletonInstance();
291
292        $table = 'dtb_member';
293
294        $exists = $objQuery->exists($table, $where, array($val));
295        return $exists;
296    }
297
298    /**
299     * ページ番号が信頼しうる値かチェックする.
300     *
301     * @access private
302     * @param  integer $pageno ページの番号
303     * @return integer $clean_pageno チェック後のページの番号
304     */
305    function lfCheckPageNo($pageno) {
306
307        $clean_pageno = '';
308
309        // $pagenoが0以上の整数かチェック
310        if (SC_Utils_Ex::sfIsInt($pageno) && $pageno > 0) {
311            $clean_pageno = $pageno;
312        }
313
314        // 例外は全て1とする
315        else {
316            $clean_pageno = 1;
317        }
318
319        return $clean_pageno;
320    }
321
322    /**
323     * 入力された管理者データをInsertする.
324     *
325     * @param array 管理者データの連想配列
326     * @return void
327     */
328    function insertMemberData($arrMemberData) {
329        $objQuery =& SC_Query_Ex::getSingletonInstance();
330
331        // INSERTする値を作成する.
332        $salt                  = SC_Utils_Ex::sfGetRandomString(10);
333        $sqlVal = array();
334        $sqlVal['name']        = $arrMemberData['name'];
335        $sqlVal['department']  = $arrMemberData['department'];
336        $sqlVal['login_id']    = $arrMemberData['login_id'];
337        $sqlVal['password']    = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
338        $sqlVal['salt']        = $salt;
339        $sqlVal['authority']   = $arrMemberData['authority'];
340        $sqlVal['rank']        = $objQuery->max('rank', 'dtb_member') + 1;
341        $sqlVal['work']        = $arrMemberData['work'];
342        $sqlVal['del_flg']     = '0'; // 削除フラグをOFFに設定
343        $sqlVal['creator_id']  = $_SESSION['member_id'];
344        $sqlVal['create_date'] = 'CURRENT_TIMESTAMP';
345        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
346
347        // INSERTの実行
348        $sqlVal['member_id'] = $objQuery->nextVal('dtb_member_member_id');
349        $objQuery->insert('dtb_member', $sqlVal);
350    }
351
352    /**
353     * 管理者データをUpdateする.
354     *
355     * @param array 管理者データの連想配列
356     * @return void
357     */
358    function updateMemberData($member_id, $arrMemberData) {
359        $objQuery =& SC_Query_Ex::getSingletonInstance();
360
361        // Updateする値を作成する.
362        $sqlVal = array();
363        $sqlVal['name']        = $arrMemberData['name'];
364        $sqlVal['department']  = $arrMemberData['department'];
365        $sqlVal['login_id']    = $arrMemberData['login_id'];
366        $sqlVal['authority']   = $arrMemberData['authority'];
367        $sqlVal['work']   = $arrMemberData['work'];
368        $sqlVal['update_date'] = 'CURRENT_TIMESTAMP';
369        if ($arrMemberData['password'] != DEFAULT_PASSWORD) {
370            $salt = SC_Utils_Ex::sfGetRandomString(10);
371            $sqlVal['salt']     = $salt;
372            $sqlVal['password'] = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
373        }
374
375        $where = 'member_id = ?';
376
377        // UPDATEの実行
378        $objQuery->update('dtb_member', $sqlVal, $where, array($member_id));
379    }
380}
Note: See TracBrowser for help on using the repository browser.