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

Revision 21185, 13.5 KB checked in by shutta, 13 years ago (diff)

refs #800 (SQL標準関数を使用する)
CURRENT_TIMESTAMP を使用するように now() を置換。

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