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

Revision 22498, 14.5 KB checked in by kim, 11 years ago (diff)

#2084 ID振り直し LC_Page_Admin_Products_UploadCSV_012からLC_Page_Admin_System_Parameterまで

  • 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-2012 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 = t('c_Member registration/editing_01');
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->arrForm['password02'] = DEFAULT_PASSWORD;
163                        $this->tpl_old_login_id    = $this->arrForm['login_id'];
164                        break;
165
166                    case 'new':
167                    default:
168                        $this->tpl_mode = $clean_mode_flg;
169                        $this->arrForm['authority'] = -1;
170                        break;
171                }
172                break;
173        }
174        $this->setTemplate($this->tpl_mainpage);
175
176    }
177
178    /**
179     * デストラクタ.
180     *
181     * @return void
182     */
183    function destroy() {
184        parent::destroy();
185    }
186
187    /**
188     * フォームパラメーター初期化
189     *
190     * @param object $objFormParam
191     * @param array  $arrParams $_POST値
192     * @param string $mode editの時は指定
193     * @return void
194     */
195    function initForm(&$objFormParam, &$arrParams, $mode = '') {
196
197        $objFormParam->addParam(t('PARAM_LABEL_MEMBER_ID'), 'member_id', INT_LEN, 'n', array('NUM_CHECK'));
198        $objFormParam->addParam(t('c_Name_01'), 'name', STEXT_LEN, 'KV', array('EXIST_CHECK', 'MAX_LENGTH_CHECK'));
199        $objFormParam->addParam(t('c_Affiliation_01'), 'department', STEXT_LEN, 'KV', array('MAX_LENGTH_CHECK'));
200        $objFormParam->addParam(t('c_Login ID_01'), 'login_id', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
201        $objFormParam->addParam(t('c_Login ID before change_01'), 'old_login_id', '' , '', array('ALNUM_CHECK'));
202        if ($mode == 'edit' && $arrParams['password'] == DEFAULT_PASSWORD) {
203            $objFormParam->addParam(t('c_Password_01'), 'password', '' , '', array('EXIST_CHECK'));
204            $objFormParam->addParam(t('c_Password (confirmation)_01'), 'password02', '' , '', array('EXIST_CHECK'));
205        } else {
206            $objFormParam->addParam(t('c_Password_01'), 'password', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
207            $objFormParam->addParam(t('c_Password (confirmation)_01'), 'password02', '' , '', array('EXIST_CHECK', 'ALNUM_CHECK'));
208        }
209        $objFormParam->addParam(t('c_Access_01'), 'authority', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
210        $objFormParam->addParam(t('c_Operating/Not operating_01'), 'work', INT_LEN, '', array('EXIST_CHECK', 'NUM_CHECK', 'MAX_LENGTH_CHECK'));
211        $objFormParam->addParam(t('c_Page_01'), '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(t('c_Password_01'), 'password', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
232            $objErr->doFunc(array(t('c_Login ID_01'), 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('NUM_RANGE_CHECK'));
233        } elseif ($mode == 'edit') {
234            $objErr->doFunc(array(t('c_Password_01'), 'password', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
235            $objErr->doFunc(array(t('c_Login ID_01'), 'login_id', ID_MIN_LEN, ID_MAX_LEN), array('SPTAB_CHECK' ,'NUM_RANGE_CHECK'));
236        }
237    $objErr->doFunc(array(t('c_Password_01'), t('c_Password (confirmation)_01'), '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'] = t('c_This name is already registered and cannot be used.<br>_01');
246            }
247            // ログインIDが登録済みでないか
248            if ($this->memberDataExists('login_id = ? AND del_flg = 0', $arrParams['login_id'])) {
249                $arrErr['login_id'] = t('c_This ID is already registered and cannot be used.<br>_01');
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'] = t('c_This ID is already registered and cannot be used.<br>_01');
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.