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

Revision 22567, 14.5 KB checked in by shutta, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.12.4)
Zend Framework PHP 標準コーディング規約のコーディングスタイルへ準拠。
classおよびfunctionの開始波括弧「{」のスタイルを修正。

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