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

Revision 21693, 14.7 KB checked in by h_yoshimoto, 12 years ago (diff)

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