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

Revision 20538, 13.4 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)
#628(未使用処理・定義などの削除)

  • 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-2010 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->httpCacheControl('nocache');
54    }
55
56    /**
57     * Page のプロセス.
58     *
59     * @return void
60     */
61    function process() {
62        $this->action();
63        $this->sendResponse();
64    }
65
66    /**
67     * Page のアクション.
68     *
69     * @return void
70     */
71    function action() {
72        // ページ送りの処理 $_REQUEST['pageno']が信頼しうる値かどうかチェックする。
73        $this->tpl_pageno = $this->lfCheckPageNo($_REQUEST['pageno']);
74
75        $objFormParam = new SC_FormParam_Ex();
76        $arrErr = array();
77        $arrForm = array();
78
79        switch($this->getMode()) {
80        case 'new':
81            // パラメータの初期化
82            $this->initForm($objFormParam, $_POST);
83
84            // エラーチェック
85            $arrErr = $this->validateData($objFormParam, $_POST, $this->getMode());
86            $this->arrForm = $objFormParam->getHashArray();
87
88            if(SC_Utils_Ex::isBlank($arrErr)) {
89
90                $this->insertMemberData($this->arrForm);
91                // 親ウィンドウを更新後、自ウィンドウを閉じる。
92                $url = ADMIN_SYSTEM_URLPATH . "?pageno=" . $this->arrForm['pageno'];
93                $this->tpl_onload = "fnUpdateParent('".$url."'); window.close();";
94
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                // エラー情報をセットする
104                $this->arrErr = $arrErr;
105            }
106            break;
107
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
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                // エラー情報をセットする
133                $this->arrErr = $arrErr;
134            }
135            break;
136
137        default:
138
139            // $_GET['id'](member_id)が登録済みのものかチェック。
140            // 登録されていない場合は不正なものとして、新規扱いとする。
141            $clean_id = "";
142            $clean_mode_flg = 'new';
143       
144            // idが0より大きい数字で整数の場合
145            if (isset($_GET['id']) && SC_Utils_Ex::sfIsInt($_GET['id']) && $_GET['id'] > 0) {
146                if ($this->memberDataExists('member_id = ? AND del_flg = 0', $_GET['id'])) {
147                    $clean_id = $_GET['id'];
148                    $clean_mode_flg = 'edit';
149                }
150            }
151
152            switch($clean_mode_flg) {
153            case 'edit':
154                $this->tpl_mode      = $clean_mode_flg;
155                $this->tpl_member_id = $clean_id;
156                $this->tpl_onfocus   = "fnClearText(this.name);";
157                $this->arrForm       = $this->getMemberData($clean_id);
158                $this->arrForm['password'] = 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     * @return void
177     */
178    function destroy() {
179        parent::destroy();
180    }
181
182
183    /**
184     * フォームパラメータ初期化
185     *
186     * @param object $objFormParam
187     * @param array  $arrParams $_POST値
188     * @param string $mode editの時は指定
189     * @return void
190     */
191    function initForm(&$objFormParam, &$arrParams, $mode = "") {
192
193        $objFormParam->addParam('メンバーID', 'member_id', INT_LEN, 'n', array('NUM_CHECK'));
194        $objFormParam->addParam('名前', 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
195        $objFormParam->addParam('所属', 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK'));
196        $objFormParam->addParam('ログインID', 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
197        $objFormParam->addParam('変更前ログインID', 'old_login_id', '' , '', array('ALNUM_CHECK'));
198        if ($mode == 'edit' && $arrParams['password'] == DEFAULT_PASSWORD) {
199            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK'));
200        } else {
201            $objFormParam->addParam('パスワード', 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
202        }
203        $objFormParam->addParam('権限', 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
204        $objFormParam->addParam('稼働/非稼働', 'work', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
205        $objFormParam->addParam('ページ', 'pageno', INT_LEN, 'n', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
206
207        $objFormParam->setParam($arrParams);
208        $objFormParam->convParam();
209
210    }
211
212
213
214    /**
215     * パラメータの妥当性検証を行う.
216     *
217     * @param void
218     * @return array エラー情報の連想配列
219     */
220    function validateData(&$objFormParam, &$arrParams, $mode) {
221        $arrErr = $objFormParam->checkError();
222        if (isset($arrErr) && count($arrErr) > 0) return $arrErr;
223
224        // ログインID・パスワードの文字数チェック
225        $objErr = new SC_CheckError_Ex();
226        if($mode == 'new') {
227            $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array("NUM_RANGE_CHECK"));
228            $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array("NUM_RANGE_CHECK"));
229        } elseif($mode == 'edit') {
230            $objErr->doFunc(array("パスワード", 'password', ID_MIN_LEN, ID_MAX_LEN), array("SPTAB_CHECK" ,"NUM_RANGE_CHECK"));
231            $objErr->doFunc(array("ログインID", 'login_id', ID_MIN_LEN, ID_MAX_LEN), array("SPTAB_CHECK" ,"NUM_RANGE_CHECK"));
232        }
233
234
235        $arrErr = $objErr->arrErr;
236
237        switch($mode) {
238        case 'new':
239            // 管理者名が登録済みでないか
240            if ($this->memberDataExists('name = ?', $arrParams['name'])) {
241                $arrErr['name'] = "既に登録されている名前なので利用できません。<br>";
242            }
243            // ログインIDが登録済みでないか
244            if ($this->memberDataExists('login_id = ?', $arrParams['login_id'])) {
245                $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>";
246            }
247            break;
248        case 'edit':
249            // ログインIDが変更されている場合はチェックする。
250            if ($arrParams['login_id'] != $arrParams['old_login_id']) {
251                // ログインIDが登録済みでないか
252                if ($this->memberDataExists('login_id = ?', $arrParams['login_id'])) {
253                    $arrErr['login_id'] = "既に登録されているIDなので利用できません。<br>";
254                }
255            }
256            break;
257        }
258
259        return $arrErr;
260    }
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        $table = 'dtb_member';
287
288        $objQuery =& SC_Query_Ex::getSingletonInstance();
289        $count = $objQuery->count($table, $where, array($val));
290
291        if ($count > 0) return true;
292        return false;
293    }
294
295    /**
296     * ページ番号が信頼しうる値かチェックする.
297     *
298     * @access private
299     * @param  integer $pageno ページの番号
300     * @return integer $clean_pageno チェック後のページの番号
301     */
302    function lfCheckPageNo($pageno) {
303
304        $clean_pageno = "";
305
306        // $pagenoが0以上の整数かチェック
307        if(SC_Utils_Ex::sfIsInt($pageno) && $pageno > 0) {
308            $clean_pageno = $pageno;
309        }
310
311        // 例外は全て1とする
312        else {
313            $clean_pageno = 1;
314        }
315
316        return $clean_pageno;
317    }
318
319    /**
320     * 入力された管理者データをInsertする.
321     *
322     * @param array 管理者データの連想配列
323     * @return void
324     */
325    function insertMemberData($arrMemberData) {
326        $objQuery =& SC_Query_Ex::getSingletonInstance();
327
328        // INSERTする値を作成する.
329        $salt                  = SC_Utils_Ex::sfGetRandomString(10);
330        $sqlVal = array();
331        $sqlVal['name']        = $arrMemberData['name'];
332        $sqlVal['department']  = $arrMemberData['department'];
333        $sqlVal['login_id']    = $arrMemberData['login_id'];
334        $sqlVal['password']    = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
335        $sqlVal['salt']        = $salt;
336        $sqlVal['authority']   = $arrMemberData['authority'];
337        $sqlVal['rank']        = $objQuery->max('rank', 'dtb_member') + 1;
338        $sqlVal['work']        = $arrMemberData['work'];
339        $sqlVal['del_flg']     = '0'; // 削除フラグをOFFに設定
340        $sqlVal['creator_id']  = $_SESSION['member_id'];
341        $sqlVal['create_date'] = 'NOW()';
342        $sqlVal['update_date'] = 'NOW()';
343
344        // INSERTの実行
345        $sqlVal['member_id'] = $objQuery->nextVal('dtb_member_member_id');
346        $objQuery->insert('dtb_member', $sqlVal);
347    }
348
349    /**
350     * 管理者データをUpdateする.
351     *
352     * @param array 管理者データの連想配列
353     * @return void
354     */
355    function updateMemberData($member_id, $arrMemberData) {
356        $objQuery =& SC_Query_Ex::getSingletonInstance();
357
358        // Updateする値を作成する.
359        $sqlVal = array();
360        $sqlVal['name']        = $arrMemberData['name'];
361        $sqlVal['department']  = $arrMemberData['department'];
362        $sqlVal['login_id']    = $arrMemberData['login_id'];
363        $sqlVal['authority']   = $arrMemberData['authority'];
364        $sqlVal['work']   = $arrMemberData['work'];
365        $sqlVal['update_date'] = 'NOW()';
366        if($arrMemberData['password'] != DEFAULT_PASSWORD) {
367            $salt = SC_Utils_Ex::sfGetRandomString(10);
368            $sqlVal['salt']     = $salt;
369            $sqlVal['password'] = SC_Utils_Ex::sfGetHashString($arrMemberData['password'], $salt);
370        }
371
372        $where = "member_id = ?";
373
374        // UPDATEの実行
375        $objQuery->update("dtb_member", $sqlVal, $where, array($member_id));
376    }
377}
378?>
Note: See TracBrowser for help on using the repository browser.