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

Revision 21743, 14.3 KB checked in by AMUAMU, 12 years ago (diff)

#1754 (exit;を個別の処理でしない) #1692 (プラグイン機能) 各ファイルでフックポイントの呼出を書かないで、自動的にフックポイントを呼び出すように修正。

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