<?php
/*
* @Overview 부서 등록
* @History 2024-03-25 / 최승연 / 최초작성
*/

$cate_id = "BASE_EMPLOYEE"; //현재 메뉴 ID 필수!!!
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
include_once _SVC_INC_PATH_ ."/auth_check.php";
include_once _HOME_INC_PATH_ ."/ajax_init.php";


if(!_notAuth("R")) {


  switch($_REQUEST['mode']) {

    // 사원정보
    case 'getWorkerList':
      $squl = "USP_B_EMPLOYEE_S10";
      $params = Array(
        "EMP_NO"      => $_REQUEST['EMP_NO']?:"",
        "P_EMP_NM"    => $_REQUEST['EMP_NM']?:"",
        "P_DEPT_CD"   => $_REQUEST['DEPT_CD']?:"",
        "P_DEPT_NM"   => $_REQUEST['DEPT_NM']?:"",
        "RET_FLG"     => $_REQUEST['RET_FLG']?:""
      );
      $rst = $baseObj->DB->exec($squl,$params);

      $rows = array();
      if( $rst ){
        $retval['code'] = true;
        while( $row = $baseObj->DB->fetch_array($rst) ){
          $rows[] = $row;
        };
        $retval['data'] = $rows;
        $retval['msg'] = '정상 동작 되었습니다.';
      }else{
        $retval['code'] = false;
      }



      break;
      
    case 'putWorker':
//      if( !_notAuth("W") ) break;

      $_REQUEST["reqdata"] = json_decode( $_REQUEST['reqdata'] );
      $rst = true;

      foreach( $_REQUEST['reqdata'] as $data ){
        $data =(array)$data;

        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";
        $params = Array(
          "EMP_NO"			  => $data['EMP_NO']?:"",
          "EMP_NM"			  => $data['EMP_NM']?:"",
          "EMP_SHORT_NM"  => $data['EMP_SHORT_NM']?:"",
          "DEPT_CD"       => $data['DEPT_CD']?:"",
          "JOB_POS"	      => $data['JOB_POS'],
          "JOB_ROLE"      => $data['JOB_ROLE'],
          // 현장직
          "JOB_FUNC"       => $data['JOB_FUNC']?:"N",
          
          "OS_FLG"		    => $data['OS_FLG']?:"N",
          "OS_BP_CD"      => $data['OS_BP_CD'],

          "MAKE_USER_ID" => $GLOBALS['_Umem']['member_id'],

          "RS_CODE"		    => array(&$_REQUEST['RS_CODE'], SQLSRV_PARAM_OUT),
          "RS_MSG"			  => array(&$_REQUEST['RS_MSG'], SQLSRV_PARAM_OUT)
        );

        if($data['_STATUS_']=='D'){
          $sql = "USP_B_EMPLOYEE_D10";
  
          $params = Array(
            "EMP_NO"		 => $data['EMP_NO'],
          );

        }else{
          
          // 길이 제한
          if(strlen($data['EMP_NO']) > 20){$retval['mesg'] = cUtil\Mlang::getText("사번은 20자 내로 작성해주세요."); $rst=false; break;}
          if(mb_strlen($data['EMP_NM']) > 50){$retval['mesg'] = cUtil\Mlang::getText("성명은 50자 내로 작성해주세요."); $rst=false; break;}
          if(mb_strlen($data['EMP_SHORT_NM']) > 50){$retval['mesg'] = cUtil\Mlang::getText("영문명은 50자 내로 작성해주세요."); $rst=false; break;}

          switch($data['_STATUS_']) {
            case 'I':
              $sql = "USP_B_EMPLOYEE_I10";
            break;
  
            case 'U':
              $sql = "USP_B_EMPLOYEE_U10";
            break;
          };
        }
        $rst = $baseObj->DB->exec($sql, $params);
        
      }


      if($rst && !$_REQUEST['RS_CODE']){
        $retval['code'] = true;
      }else{
        $retval['code'] = false;
        $retval['mesg'] = $_REQUEST['RS_MSG'];
      }
      break;
      

  }
}

if (!$_REQUEST['no_echo']) {
  echo json_encode($retval);
}