Page
[ class tree: Page ] [ index: Page ] [ all elements ]

Source for file LC_Page_Admin_System_Input.php

Documentation is available at LC_Page_Admin_System_Input.php

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

Documentation generated on Fri, 24 Feb 2012 14:01:49 +0900 by Seasoft