<?php
if( !$_REQUEST['mode'] ){
  $_RAW_TMP = file_get_contents("php://input");
  $_RAW = json_decode($_RAW_TMP, true);
  if( $_RAW['mode'] ){
    $_REQUEST = $_RAW;
  }
}

if( $_REQUEST['member_token'] ){
  $tkObj = new Token();
  $token_info = $tkObj->getFromToken($_REQUEST['member_token']);
  $token_stauts = $tkObj->statusToken($token_info);
  switch( $token_stauts ){
    case "E" : //토큰 연장
      $new_token = $tkObj->putToken($token_info['member_id'], $token_info['auth']);
    case "Y" : //토큰 유효
      $_SESSION['auth_mem_id'] = $token_info['member_id'];
      break;

      // 토큰 연장처리 되어 새로운 토큰($new_token) 이 발행되었는데도 갱신하지 않고,
      // 예전 토큰 그대로 사용하면 중복 인증요청으로 무효토큰 처리되니
      // 새로운 토큰이 발행되면 다음 요청시엔 꼭 새로운 토큰으로 교체하는 과정이 필요.
      // APP 에서 요청할때 응답이 필요한 요청이외의 단순 요청부분까지 응답을 필수 확인하여 $new_token 값이 있는지 점검후 교체하는 로직 필수!!

    case "F" : //토큰 비활성
      $tkObj->retireToken( $token_info['auth'] );
    case "N" : //토큰 무효
      unset($_SESSION['auth_mem_id']);
      break;
  }
}

$GLOBALS['week_word'] = Array(
  "eng" => Array(
    "sun",
    "mon",
    "the",
    "wed",
    "thu",
    "fri",
    "sat",
  ),
  "kor" => Array(
    "일",
    "월",
    "화",
    "수",
    "목",
    "금",
    "토",
  )
);
$GLOBALS['mon_word'] = Array(
  "eng" => Array(
    "jan",
    "feb",
    "mar",
    "apr",
    "may",
    "jun",
    "jul",
    "aug",
    "sep",
    "oct",
    "nov",
    "dec",
  ),
  "kor" => Array(
    "01월",
    "02월",
    "03월",
    "04월",
    "05월",
    "06월",
    "07월",
    "08월",
    "09월",
    "10월",
    "11월",
    "12월",
  )
);

$baseObj = new Member();
$GLOBALS['_Umem'] = $baseObj->loginCheck($_SESSION['auth_mem_id']);

$GLOBALS['_varsBaseCode'] = Array( //기본변수
  "line_num" => 20, //기본 라인수
  "page_num" => 5, //기본 페이지 출력수
  "id_len" => 6, //아이디 길이
  "pw_len" => 6, //비밀번호 길이
  "cate_depth" => 4, //카테고리 분류 최대 자리수. 4자리는 0001 ~ 9999 까지 레벨당 총 9999개 Child를 가지게 된다.
);

$GLOBALS['_varsMemStatus'] = Array( //회원상태
  1 => "활동중",
  2 => "승인대기",
  3 => "정지",
);

$GLOBALS['_varsLoginResult'] = Array( //로그인결과
  0 => "실패",
  1 => "성공",
);

$GLOBALS['_varsMenuArea'] = Array( //사용 페이지구분
  "service" => "사용자/실무자 화면",
  "partner" => "고객사 관리화면",
  "admin" => "관리자 화면"
);

$GLOBALS['_varsAuthArea'] = Array( //권한대상
  "G" => "그룹권한",
  "M" => "개별권한",
);

$GLOBALS['_varsAuthAdmin'] = Array( //관리자구분
  "SA" => "슈퍼관리자",
  "A" => "일반관리자",
);

$GLOBALS['_varsAuthMember'] = Array( //회원구분
  "SM" => "특별회원",
  "M"  => "일반회원",
  "Y"  => "게스트",
);

$GLOBALS['_varsCommonStatus'] = Array( //공통 상태허용
  "0" => "정지",
  "1" => "활동중",
);

$GLOBALS['_varsBoardEditor'] = Array( //웹에디터 선택
  "tinymce" => "웹에디터",
  "text" => "텍스트",
);

$GLOBALS['_varsPagingList'] = Array("5"=>5,"10"=>10,"20"=>20,"50"=>50,"100"=>100,"200"=>200,"500"=>500,"1000"=>1000,"2000"=>2000,"5000"=>5000,"10000"=>10000);

/* 디폴트 값을 기준정보 관리와 매칭 시켜야 한다. */
//$GLOBALS['_varsBaseCode']      = array_merge_static($GLOBALS['_varsBaseCode'], $baseObj->getBaseCodeVars("cm_var","cm_var"));
//$GLOBALS['_varsMemStatus']     = $baseObj->getBaseCodeVars("mem_status","mem_status") ?: $GLOBALS['_varsMemStatus'];
//$GLOBALS['_varsLoginResult']   = $baseObj->getBaseCodeVars("login_result","login_result") ?: $GLOBALS['_varsLoginResult'];
//$GLOBALS['_varsMenuArea']      = $baseObj->getBaseCodeVars("menu_area","menu_area") ?: $GLOBALS['_varsMenuArea'];
//$GLOBALS['_varsAuthArea']      = $baseObj->getBaseCodeVars("auth_area","auth_area") ?: $GLOBALS['_varsAuthArea'];
//$GLOBALS['_varsAuthAdmin']     = $baseObj->getBaseCodeVars("auth_admin","auth_admin") ?: $GLOBALS['_varsAuthAdmin'];
//$GLOBALS['_varsAuthMember']    = $baseObj->getBaseCodeVars("auth_member","auth_member") ?: $GLOBALS['_varsAuthMember'];
//$GLOBALS['_varsCommonStatus']  = $baseObj->getBaseCodeVars("common_status","common_status") ?: $GLOBALS['_varsCommonStatus'];
//$GLOBALS['_varsBoardEditor']   = $baseObj->getBaseCodeVars("board_editor","board_editor") ?: $GLOBALS['_varsBoardEditor'];
//$GLOBALS['_varsPosition']      = $baseObj->getBaseCodeVars("position","position") ?: $GLOBALS['_varsPosition'];
//$GLOBALS['_varsJobrole']       = $baseObj->getBaseCodeVars("JOB_ROLE","JOB_ROLE") ?: $GLOBALS['_varsJobrole'];
//$GLOBALS['_varsJobfunc']       = $baseObj->getBaseCodeVars("JOB_FUNC","JOB_FUNC") ?: $GLOBALS['_varsJobfunc'];
//$GLOBALS['_varsEmptype']       = $baseObj->getBaseCodeVars("EMP_TYPE","EMP_TYPE") ?: $GLOBALS['_varsEmptype'];
//$GLOBALS['_varsNations']       = $baseObj->getBaseCodeVars("nation_code","nation_code") ?: $GLOBALS['_varsNations'];
//$GLOBALS['_varsCurrency']      = $baseObj->getBaseCodeVars("currency","currency") ?: $GLOBALS['_varsCurrency'];
//$GLOBALS['_varsCurrencyExp']   = $baseObj->getBaseCodeVarsExp("currency","currency") ?: $GLOBALS['_varsCurrency'];
//$GLOBALS['_WH_TYPE']           = $baseObj->getBaseCodeVars("WH_TYPE","WH_TYPE") ?: $GLOBALS['_WH_TYPE'];
//$GLOBALS['_ITEM_GRP']          = $baseObj->getBaseCodeVars("ITEM_GRP","ITEM_GRP") ?: $GLOBALS['_ITEM_GRP'];
//$GLOBALS['_SHAPE_GRP']         = $baseObj->getBaseGroupVars("SHAPE_TYPE") ?: $GLOBALS['_SHAPE_TYPE'];
//$GLOBALS['_SHAPE_TYPE']        = $baseObj->getBaseCodeVars("SHAPE_TYPE") ?: $GLOBALS['_SHAPE_TYPE'];
//$GLOBALS['_ITEM_ACCNT']        = $baseObj->getBaseCodeVars("ITEM_ACCNT","ITEM_ACCNT") ?: $GLOBALS['_ITEM_ACCNT'];
//$GLOBALS['_LOCATION_TYPE']     = $baseObj->getBaseCodeVars("LOCATION_TYPE","LOCATION_TYPE") ?: $GLOBALS['_LOCATION_TYPE'];
//$GLOBALS['_OP_GRP']            = $baseObj->getBaseCodeVars("OP_GRP","OP_GRP") ?: $GLOBALS['_OP_GRP'];
//$GLOBALS['_ITEM_SPEC']         = $baseObj->getBaseCodeVars("ITEM_SPEC","ITEM_SPEC") ?: $GLOBALS['_ITEM_SPEC'];
//$GLOBALS['_INSP_ITEM']         = $baseObj->getBaseCodeVars("INSP_ITEM","INSP_ITEM") ?: $GLOBALS['_INSP_ITEM'];
//$GLOBALS['_SALES_GRP']         = $baseObj->getBaseCodeVars("SALES_GRP","SALES_GRP") ?: $GLOBALS['_SALES_GRP'];
//$GLOBALS['_DEAL_TYPE']         = $baseObj->getBaseCodeVars("DEAL_TYPE","DEAL_TYPE") ?: $GLOBALS['_DEAL_TYPE'];
//$GLOBALS['_PAY_METH']          = $baseObj->getBaseCodeVars("PAY_METH","PAY_METH") ?: $GLOBALS['_PAY_METH'];
//$GLOBALS['_UNIT']              = $baseObj->getBaseCodeVars("UNIT","UNIT") ?: $GLOBALS['_UNIT'];
//$GLOBALS['_SHIFT_ID']          = $baseObj->getBaseCodeVars("SHIFT_ID","SHIFT_ID") ?: $GLOBALS['_SHIFT_ID'];
//$GLOBALS['_SHIFT_TYPE']        = $baseObj->getBaseCodeVars("SHIFT_TYPE","SHIFT_TYPE") ?: $GLOBALS['_SHIFT_TYPE'];
//$GLOBALS['_TM_TYPE']           = $baseObj->getBaseCodeVars("TM_TYPE","TM_TYPE") ?: $GLOBALS['_TM_TYPE'];
//$GLOBALS['_FACLT_TYPE']        = $baseObj->getBaseCodeVars("FACLT_TYPE","FACLT_TYPE") ?: $GLOBALS['_FACLT_TYPE'];
//$GLOBALS['_FACLT_TYPE_EXP']    = $baseObj->getBaseCodeVarsExp("FACLT_TYPE","FACLT_TYPE") ?: $GLOBALS['_FACLT_TYPE'];
//$GLOBALS['_IN_TYPE']           = $baseObj->getBaseCodeVars("IN_TYPE","IN_TYPE") ?: $GLOBALS['_IN_TYPE'];
//$GLOBALS['_EXPEN_TYPE']        = $baseObj->getBaseCodeVars("EXPEN_TYPE","EXPEN_TYPE") ?: $GLOBALS['_EXPEN_TYPE'];
//$GLOBALS['_OP_PART']           = $baseObj->getBaseCodeVars("OP_PART","OP_PART") ?: $GLOBALS['_OP_PART'];
//$GLOBALS['_RUNSTOP_GB']        = $baseObj->getBaseCodeVars("RUNSTOP_GB","RUNSTOP_GB") ?: $GLOBALS['_RUNSTOP_GB'];
//$GLOBALS['_ITEN_STATUS']       = $baseObj->getBaseCodeVars("ITEN_STATUS","ITEN_STATUS") ?: $GLOBALS['_ITEN_STATUS'];
//$GLOBALS['_PROD_STATUS']       = $baseObj->getBaseCodeVars("PROD_STATUS","PROD_STATUS") ?: $GLOBALS['_PROD_STATUS'];
//$GLOBALS['_FOUND_TYPE']        = $baseObj->getBaseCodeVars("FOUND_TYPE","FOUND_TYPE") ?: $GLOBALS['_FOUND_TYPE'];
//$GLOBALS['_JUDG_CD']           = $baseObj->getBaseCodeVars("JUDG_CD","JUDG_CD") ?: $GLOBALS['_JUDG_CD'];
//$GLOBALS['_LOAD_TYPE']         = $baseObj->getBaseCodeVars("LOAD_TYPE","LOAD_TYPE") ?: $GLOBALS['_LOAD_TYPE'];
//$GLOBALS['_REQ_INSP_ITEM']     = $baseObj->getBaseCodeVars("REQ_INSP_ITEM","REQ_INSP_ITEM") ?: $GLOBALS['_REQ_INSP_ITEM'];

$GLOBALS['_ALL_BASE'] = $baseObj->getBaseCodeVarsAll("","") ?: "";

$GLOBALS['_varsBaseCode']      = array_merge_static($GLOBALS['_varsBaseCode'], $GLOBALS['_ALL_BASE']['CODE']['cm_var']);
$GLOBALS['_SHAPE_GRP']         = $baseObj->getBaseGroupVars("SHAPE_TYPE") ?: $GLOBALS['_SHAPE_TYPE'];
$GLOBALS['_varsMemStatus']     = $GLOBALS['_ALL_BASE']['CODE']['mem_status'] ?: $GLOBALS['_varsMemStatus'];
$GLOBALS['_varsLoginResult']   = $GLOBALS['_ALL_BASE']['CODE']['login_result'] ?: $GLOBALS['_varsLoginResult'];
$GLOBALS['_varsMenuArea']      = $GLOBALS['_ALL_BASE']['CODE']['menu_area'] ?: $GLOBALS['_varsMenuArea'];
$GLOBALS['_varsAuthArea']      = $GLOBALS['_ALL_BASE']['CODE']['auth_area'] ?: $GLOBALS['_varsAuthArea'];
$GLOBALS['_varsAuthAdmin']     = $GLOBALS['_ALL_BASE']['CODE']['auth_admin'] ?: $GLOBALS['_varsAuthAdmin'];
$GLOBALS['_varsAuthMember']    = $GLOBALS['_ALL_BASE']['CODE']['auth_member'] ?: $GLOBALS['_varsAuthMember'];
$GLOBALS['_varsCommonStatus']  = $GLOBALS['_ALL_BASE']['CODE']['common_status'] ?: $GLOBALS['_varsCommonStatus'];
// $GLOBALS['_varsBoardEditor']   = $GLOBALS['_ALL_BASE']['CODE']['board_editor'] ?: $GLOBALS['_varsBoardEditor'];
$GLOBALS['_varsPosition']      = $GLOBALS['_ALL_BASE']['CODE']['position'] ?: $GLOBALS['_varsPosition'];
$GLOBALS['_varsJobrole']       = $GLOBALS['_ALL_BASE']['CODE']['JOB_ROLE'] ?: $GLOBALS['_varsJobrole'];
$GLOBALS['_varsJobfunc']       = $GLOBALS['_ALL_BASE']['CODE']['JOB_FUNC'] ?: $GLOBALS['_varsJobfunc'];
$GLOBALS['_varsEmptype']       = $GLOBALS['_ALL_BASE']['CODE']['EMP_TYPE'] ?: $GLOBALS['_varsEmptype'];
$GLOBALS['_varsNations']       = $GLOBALS['_ALL_BASE']['CODE']['nation_code'] ?: $GLOBALS['_varsNations'];
$GLOBALS['_varsCurrency']      = $GLOBALS['_ALL_BASE']['CODE']['currency'] ?: $GLOBALS['_varsCurrency'];
$GLOBALS['_varsCurrencyExp']   = $GLOBALS['_ALL_BASE']['CODEEXP']['currency'] ?: $GLOBALS['_varsCurrency'];
$GLOBALS['_WH_TYPE']           = $GLOBALS['_ALL_BASE']['CODE']['WH_TYPE'] ?: $GLOBALS['_WH_TYPE'];
$GLOBALS['_ITEM_GRP']          = $GLOBALS['_ALL_BASE']['CODE']['ITEM_GRP'] ?: $GLOBALS['_ITEM_GRP'];
$GLOBALS['_SHAPE_TYPE']        = $GLOBALS['_ALL_BASE']['CODE']['SHAPE_TYPE'] ?: $GLOBALS['_SHAPE_TYPE'];
$GLOBALS['_ITEM_ACCNT']        = $GLOBALS['_ALL_BASE']['CODE']['ITEM_ACCNT'] ?: $GLOBALS['_ITEM_ACCNT'];
$GLOBALS['_LOCATION_TYPE']     = $GLOBALS['_ALL_BASE']['CODE']['LOCATION_TYPE'] ?: $GLOBALS['_LOCATION_TYPE'];
$GLOBALS['_OP_GRP']            = $GLOBALS['_ALL_BASE']['CODE']['OP_GRP'] ?: $GLOBALS['_OP_GRP'];
$GLOBALS['_ITEM_SPEC']         = $GLOBALS['_ALL_BASE']['CODE']['ITEM_SPEC'] ?: $GLOBALS['_ITEM_SPEC'];
$GLOBALS['_INSP_ITEM']         = $GLOBALS['_ALL_BASE']['CODE']['INSP_ITEM'] ?: $GLOBALS['_INSP_ITEM'];
$GLOBALS['_SALES_GRP']         = $GLOBALS['_ALL_BASE']['CODE']['SALES_GRP'] ?: $GLOBALS['_SALES_GRP'];
$GLOBALS['_DEAL_TYPE']         = $GLOBALS['_ALL_BASE']['CODE']['DEAL_TYPE'] ?: $GLOBALS['_DEAL_TYPE'];
$GLOBALS['_PAY_METH']          = $GLOBALS['_ALL_BASE']['CODE']['PAY_METH'] ?: $GLOBALS['_PAY_METH'];
$GLOBALS['_UNIT']              = $GLOBALS['_ALL_BASE']['CODE']['UNIT'] ?: $GLOBALS['_UNIT'];
$GLOBALS['_SHIFT_ID']          = $GLOBALS['_ALL_BASE']['CODE']['SHIFT_ID'] ?: $GLOBALS['_SHIFT_ID'];
$GLOBALS['_SHIFT_TYPE']        = $GLOBALS['_ALL_BASE']['CODE']['SHIFT_TYPE'] ?: $GLOBALS['_SHIFT_TYPE'];
$GLOBALS['_TM_TYPE']           = $GLOBALS['_ALL_BASE']['CODE']['TM_TYPE'] ?: $GLOBALS['_TM_TYPE'];
$GLOBALS['_FACLT_TYPE']        = $GLOBALS['_ALL_BASE']['CODE']['FACLT_TYPE'] ?: $GLOBALS['_FACLT_TYPE'];
$GLOBALS['_FACLT_TYPE_EXP']    = $GLOBALS['_ALL_BASE']['CODEEXP']['FACLT_TYPE'] ?: $GLOBALS['_FACLT_TYPE'];
$GLOBALS['_IN_TYPE']           = $GLOBALS['_ALL_BASE']['CODE']['IN_TYPE'] ?: $GLOBALS['_IN_TYPE'];
$GLOBALS['_EXPEN_TYPE']        = $GLOBALS['_ALL_BASE']['CODE']['EXPEN_TYPE'] ?: $GLOBALS['_EXPEN_TYPE'];
$GLOBALS['_OP_PART']           = $GLOBALS['_ALL_BASE']['CODE']['OP_PART'] ?: $GLOBALS['_OP_PART'];
$GLOBALS['_RUNSTOP_GB']        = $GLOBALS['_ALL_BASE']['CODE']['RUNSTOP_GB'] ?: $GLOBALS['_RUNSTOP_GB'];
$GLOBALS['_ITEN_STATUS']       = $GLOBALS['_ALL_BASE']['CODE']['ITEN_STATUS'] ?: $GLOBALS['_ITEN_STATUS'];
$GLOBALS['_PROD_STATUS']       = $GLOBALS['_ALL_BASE']['CODE']['PROD_STATUS'] ?: $GLOBALS['_PROD_STATUS'];
$GLOBALS['_FOUND_TYPE']        = $GLOBALS['_ALL_BASE']['CODE']['FOUND_TYPE'] ?: $GLOBALS['_FOUND_TYPE'];
$GLOBALS['_JUDG_CD']           = $GLOBALS['_ALL_BASE']['CODE']['JUDG_CD'] ?: $GLOBALS['_JUDG_CD'];
$GLOBALS['_LOAD_TYPE']         = $GLOBALS['_ALL_BASE']['CODE']['LOAD_TYPE'] ?: $GLOBALS['_LOAD_TYPE'];
$GLOBALS['_REQ_INSP_ITEM']     = $GLOBALS['_ALL_BASE']['CODE']['REQ_INSP_ITEM'] ?: $GLOBALS['_REQ_INSP_ITEM'];
$GLOBALS['_SAMP_CUSTOM']       = $GLOBALS['_ALL_BASE']['CODE']['SAMP_CUSTOM'] ?: $GLOBALS['_SAMP_CUSTOM'];
$GLOBALS['_TLColor']           = $GLOBALS['_ALL_BASE']['CODEEXP']['TLColor'] ?: $GLOBALS['_TLColor'];
$GLOBALS['_IO_TYPE_FIN']       = $GLOBALS['_ALL_BASE']['CODE']['IO_TYPE_FIN'] ?: $GLOBALS['_IO_TYPE_FIN'];
$GLOBALS['_NCR_CD']            = $GLOBALS['_ALL_BASE']['CODE']['NCR_CD'] ?: $GLOBALS['_NCR_CD'];
$GLOBALS['_TASK_TYPE']         = $GLOBALS['_ALL_BASE']['CODE']['TASK_TYPE'] ?: $GLOBALS['_TASK_TYPE'];
$GLOBALS['_STOP_CD']           = $GLOBALS['_ALL_BASE']['CODE']['STOP_CD'] ?: $GLOBALS['_STOP_CD'];
$GLOBALS['_DEF_CD']            = $GLOBALS['_ALL_BASE']['CODE']['DEF_CD'] ?: $GLOBALS['_DEF_CD'];
$GLOBALS['_RSLT_GRP']          = $GLOBALS['_ALL_BASE']['CODE']['RSLT_GRP'] ?: $GLOBALS['_RSLT_GRP'];
$GLOBALS['_ORD_TYPE']          = $GLOBALS['_ALL_BASE']['CODE']['ORD_TYPE'] ?: $GLOBALS['_ORD_TYPE'];
$GLOBALS['_WO_STATUS']         = $GLOBALS['_ALL_BASE']['CODE']['WO_STATUS'] ?: $GLOBALS['_WO_STATUS'];
$GLOBALS['_INSP_TOOL']         = $GLOBALS['_ALL_BASE']['CODE']['INSP_TOOL'] ?: $GLOBALS['_INSP_TOOL'];

$GLOBALS['_INSP_METH']         = $GLOBALS['_ALL_BASE']['CODE']['INSP_METH'] ?: $GLOBALS['_INSP_METH'];
//$GLOBALS['_WRK_TEAM']         = $GLOBALS['_ALL_BASE']['CODE']['WRK_TEAM'] ?: $GLOBALS['_WRK_TEAM'];
$GLOBALS['_FACLT_GRP']         = $GLOBALS['_ALL_BASE']['CODE']['FACLT_GRP'] ?: $GLOBALS['_FACLT_GRP'];
$GLOBALS['_OP_STATUS']         = $GLOBALS['_ALL_BASE']['CODE']['OP_STATUS'] ?: $GLOBALS['_OP_STATUS'];

// sort($GLOBALS['_varsNations']);
// ksort($GLOBALS['_varsCurrency']);
//ksort($GLOBALS['_varsCurrencyExp']);
//$GLOBALS['_OP_STATUS'] = Array(
//  "PRE" => Array(NULL,"","S"), //S확정
//  "PLAN" => Array("P","I"),    //P계획, I지시
//  "WORK" => Array("W","F",),   //W작업, F완료
//);


$cmv_obj = new Common_vars(); //공통변수 클래스