<?php
$cate_id = "STS_ORDER_PROD";
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']) {
    // 작업자 조회
    // 설비 조회
    // 양품 수량 조회
    // 불량 수량 조회
    // 과거 불량이력 조회
    // 설비 고장등록 조회

    // 가동 vs 비가동
    case "getWokerInfo":
      $sql = "USP_P_REG_PROD_WRK_S10";

      $params = array(
        'WRK_DT' => $_REQUEST["WRK_DT"] ?: "",
        'EMP_NO' => ""
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }

      break;

    case "getOperHst":
      $sql = "USP_P_REG_PROD_WRK_S20";

      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
        'EMP_NO' => $_REQUEST["EMP_NO"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }

      break;


    case "getRunInfo":

      $sql = "USP_P_REG_PROD_RUN_S10";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
        'EMP_NO' => $_REQUEST["EMP_NO"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;

    case "getFormData":
      //시작 시간 및 종료시간
      $timeSql = "USP_P_REG_PROD_RUN_S10";
      $timeParams = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
        'EMP_NO' => $_REQUEST["EMP_NO"] ?: "",
      );

      $timeRst = $baseObj->DB->exec($timeSql, $timeParams);

      $timeRows = array();
      if ($timeRst) {
        while ($row = $baseObj->DB->fetch_array($timeRst)) {
          $timeRows[] = $row;
        }
        $retval['time'] = $timeRows;
      }

      $sql = "USP_P_REG_PROD_POP_S10";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
        'OP_SEQ' => $_REQUEST["OP_SEQ"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }



      break;

    case "checkRunStatus":

      $sql = "USP_P_REG_PROD_RUN_S20";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
        'EMP_NO' => $_REQUEST["EMP_NO"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;


    case "putRunInfo":
      if (_notAuth("W")) {
        break;
      }

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

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

        if ($data['_STATUS_'] == 'U') {
          $sql = 'USP_P_REG_PROD_RUN_U10';

          $params = array(
            "FACLT_OPER_NO" => $data['FACLT_OPER_NO'] ?: "",
            "WO_NO" => $data['WO_NO'] ?: "",
            "WO_SEQ" => $data['WO_SEQ'] ?: "",
            "FACLT_CD" => $data['FACLT_CD'] ?: "",
            "RUNSTOP_GB" => $data['RUNSTOP_GB'] ?: "",
            "STOP_CD" => $data['STOP_CD'] ?: "",
            "OPER_ED_TM" => date('Y-m-d') . " " . $data['OPER_ED_TM'] ?: "",
            "EMP_NO" => $data['EMP_NO'] ?: "",

            "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)
          );
        } else {
          $sql = 'USP_P_REG_PROD_RUN_I10';

          $params = array(
            "FACLT_CD" => $data['FACLT_CD'] ?: "",
            "WO_NO" => $data['WO_NO'] ?: "",
            "WO_SEQ" => $data['WO_SEQ'] ?: "",
            "RUNSTOP_GB" => $data['RUNSTOP_GB'] ?: "",
            "OPER_ST_TM" => date('Y-m-d') . " " . $data['OPER_ST_TM'] ?: "",
            "EMP_NO" => $data['EMP_NO'] ?: "",

            "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)

          );
        }

        $rst = $baseObj->DB->exec($sql, $params);
      }

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



    // 설비 선택
    case "getFacilityInfo":

      $sql = "USP_P_REG_PROD_FACLT_S10";
      $params = array(
        'OP_CD' => $_REQUEST["OP_CD"] ?: "",
        'FACLT_CD' => ""
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;

    // 설비 고장 조회
    case "getFacilityHst":

      $sql = "USP_P_REG_PROD_FAC_HST_S10";
      $params = array(
        'FACLT_CD' => $_REQUEST["FACLT_CD"] ?: ""
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;

    // 설비 고장 등록
    case "putFacilityDef":
      if (_notAuth("W")) {
        break;
      }

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

      foreach ($_REQUEST['reqdata'] as $data) {
        $data = (array) $data;
        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";
        $sql = 'USP_P_REG_PROD_FAC_DEF_I10';

        $params = array(
          'FACLT_CD' => $data["FACLT_CD"] ?: "",
          'ERR_CD' => $data["ERR_CD"] ?: "",
          'CONTENT' => $data["CONTENT"] ?: "",
          'EMP_NO' => $data["EMP_NO"] ?: "",

          "RS_CODE" => array(&$_REQUEST['RS_CODE'], SQLSRV_PARAM_OUT),
          "RS_MSG" => array(&$_REQUEST['RS_MSG'], SQLSRV_PARAM_OUT)
        );
        $rst = $baseObj->DB->exec($sql, $params);
      }

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

    // 실적 조회
    case "getProd":

      $sql = "USP_P_REG_PROD_RSLT_S10";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;

    // 실적입력
    case "putProd":
      if (_notAuth("W")) {
        break;
      }

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

      foreach ($_REQUEST['reqdata'] as $data) {
        $data = (array) $data;
        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";
        $sql = 'USP_P_REG_PROD_RSLT_I10';

        $params = array(
          "WO_NO" => $data['WO_NO'] ?: "",
          "WO_SEQ" => $data['WO_SEQ'] ?: "",
          "OP_CD" => $data['OP_CD'] ?: "",
          "FACLT_CD" => $data['FACLT_CD'] ?: "",
          "PRD_QTY" => $data['PRD_QTY'] ?: "",
          "RSLT_GRP" => $data['RSLT_GRP'] ?: "",
          "WRK_DT" => $data['WRK_DT'] ?: "",
          "WRK_TM" => $data['WRK_DT'] . " " . $data['WRK_TM'] . ":00" ?: "",
          "EMP_NO" => $data['EMP_NO'] ?: "",
          "REMARK" => $data['REMARK'] ?: "",
          "RS_CODE" => array(&$_REQUEST['RS_CODE'], SQLSRV_PARAM_OUT),
          "RS_MSG" => array(&$_REQUEST['RS_MSG'], SQLSRV_PARAM_OUT)


        );
        $rst = $baseObj->DB->exec($sql, $params);
      }

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

    // 생산 실적 삭제
    case "delProd":
      if (_notAuth("W")) {
        break;
      }

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

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

        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";

        $sql = 'USP_P_REG_PROD_RSLT_D10';

        $params = array(
          "RSLT_NO" => $data['DEL_CD'] ?: "",

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


        );
        $rst = $baseObj->DB->exec($sql, $params);
      }

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



    // 불량 실적 조회
    case "getDef":

      $sql = "USP_P_REG_PROD_DEF_S10";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'WO_SEQ' => $_REQUEST["WO_SEQ"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;

    // 불량 실적 입력
    case "putDef":
      if (_notAuth("W")) {
        break;
      }

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

      foreach ($_REQUEST['reqdata'] as $data) {
        $data = (array) $data;
        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";
        $sql = 'USP_P_REG_PROD_DEF_I10';

        $params = array(
          "WO_NO" => $data['WO_NO'] ?: "",
          "WO_SEQ" => $data['WO_SEQ'] ?: "",
          "OP_CD" => $data['OP_CD'] ?: "",
          "FACLT_CD" => $data['FACLT_CD'] ?: NULL,
          "DEF_QTY" => $data['DEF_QTY'] ?: "",
          "DEF_CD" => $data['DEF_CD'] ?: "",
          "DEF_DT" => $data['DEF_DT'] ?: "",
          "DEF_TM" => $data['DEF_DT'] . " " . $data['DEF_TM'] . ":00" ?: "",
          "UNIT" => $data['UNIT'] ?: "",
          "DEF_CAUSE" => $data['DEF_CAUSE'] ?: "",
          "MAKE_USER_ID" => $data['EMP_NO'],
          "RS_CODE" => array(&$_REQUEST['RS_CODE'], SQLSRV_PARAM_OUT),
          "RS_MSG" => array(&$_REQUEST['RS_MSG'], SQLSRV_PARAM_OUT)


        );
        $rst = $baseObj->DB->exec($sql, $params);
      }

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


    // 불량 실적 삭제
    case "delDef":
      if (_notAuth("W")) {
        break;
      }

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

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

        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";

        $sql = 'USP_P_REG_PROD_DEF_D10';

        $params = array(
          "DEF_NO" => $data['DEL_CD'] ?: "",

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


        );
        $rst = $baseObj->DB->exec($sql, $params);
      }

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

    // 검사 실적 조회
    case "getInsp":

      $sql = "USP_Q_REG_INSP_QC_S50";
      $params = array(
        'WO_NO' => $_REQUEST["WO_NO"] ?: "",
        'OP_CD' => $_REQUEST["OP_CD"] ?: "",
        'OP_SEQ' => $_REQUEST["OP_SEQ"] ?: "",
      );

      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      } else {
        $retval['code'] = false;
      }
      break;
    // 검사 실적 등록
    case "putInsp":
      if (_notAuth("W"))
        break; /************ 권한체크*/
      $_REQUEST['RS_CODE'] = "";
      $_REQUEST['RS_MSG'] = "";
      $_REQUEST['reqdata'] = json_decode($_REQUEST['reqdata'], true);

      $rst2 = true;

      $_REQUEST['wholeData'] = json_decode($_REQUEST['wholeData'], true);


      foreach ($_REQUEST['wholeData'] as $whole) {

        $_REQUEST['RS_CODE'] = "";
        $_REQUEST['RS_MSG'] = "";
        if (isset($whole['INSP_RSLT_NO'])) {
          $sql = 'USP_Q_REG_INSP_QC_U20';

          $params = array(
            "INSP_RSLT_NO" => $whole['INSP_RSLT_NO']
            ,
            "WO_NO" => $whole['WO_NO']
            ,
            "WO_SEQ" => $whole['WO_SEQ']
            ,
            "OKNG_FLG" => $whole['OKNG_FLG']  // OKNG FLG 추가
            ,
            "INSP_SEQ" => $whole['INSP_SEQ']
            ,
            "INSP_ITEM" => $whole['INSP_ITEM']
            ,
            "INSP_TOOL" => $whole['INSP_TOOL']
            ,
            "INSP_EMP_NO" => $_REQUEST['EMP_NO'] ?? ""
            ,
            "REMARK"      => $whole['REMARK'] ?? ""
            ,
            "T1" => trim($whole['T1']) === "" ? null : $whole['T1']
            ,
            "T2" => trim($whole['T2']) === "" ? null : $whole['T2']
            ,
            "T3" => trim($whole['T3']) === "" ? null : $whole['T3']
            ,
            "T4" => trim($whole['T4']) === "" ? null : $whole['T4']
            ,
            "T5" => trim($whole['T5']) === "" ? null : $whole['T5']
            ,
            "T6" => trim($whole['T6']) === "" ? null : $whole['T6']
            ,
            "T7" => trim($whole['T7']) === "" ? null : $whole['T7']
            ,
            "T8" => trim($whole['T8']) === "" ? null : $whole['T8']
            ,
            "T9" => trim($whole['T9']) === "" ? null : $whole['T9']
            ,
            "T10" => trim($whole['T10']) === "" ? null : $whole['T10']
            ,
            "T11" => trim($whole['T11']) === "" ? null : $whole['T11']
            ,
            "T12" => trim($whole['T12']) === "" ? null : $whole['T12']
            ,
            "T13" => trim($whole['T13']) === "" ? null : $whole['T13']
            ,
            "T14" => trim($whole['T14']) === "" ? null : $whole['T14']
            ,
            "T15" => trim($whole['T15']) === "" ? null : $whole['T15']
            ,
            "T16" => trim($whole['T16']) === "" ? null : $whole['T16']
            ,
            "T17" => trim($whole['T17']) === "" ? null : $whole['T17']
            ,
            "T18" => trim($whole['T18']) === "" ? null : $whole['T18']
            ,
            "T19" => trim($whole['T19']) === "" ? null : $whole['T19']
            ,
            "T20" => trim($whole['T20']) === "" ? null : $whole['T20']
            ,
            "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)
          );
          $rst = $baseObj->DB->exec($sql, $params);

        } else {

          $sql = 'USP_Q_REG_INSP_QC_I20';
          $whole['INSP_RSLT_NO'] = "";
          $params = array(
            "WO_NO" => $whole['WO_NO']
            ,
            "WO_SEQ" => $whole['WO_SEQ']
            ,
            "OKNG_FLG" => $whole['OKNG_FLG']
            ,
            "INSP_SEQ" => $whole['INSP_SEQ']
            ,
            "INSP_ITEM" => $whole['INSP_ITEM']
            ,
            "INSP_TOOL" => $whole['INSP_TOOL']
            ,
            "INSP_EMP_NO" => $_REQUEST['EMP_NO'] ?? ""
            ,
            "REMARK"      => $whole['REMARK'] ?? ""
            ,
            "T1" => $whole['T1'] === "" ? null : $whole['T1']
            ,
            "T2" => $whole['T2'] === "" ? null : $whole['T2']
            ,
            "T3" => $whole['T3'] === "" ? null : $whole['T3']
            ,
            "T4" => $whole['T4'] === "" ? null : $whole['T4']
            ,
            "T5" => $whole['T5'] === "" ? null : $whole['T5']
            ,
            "T6" => $whole['T6'] === "" ? null : $whole['T6']
            ,
            "T7" => $whole['T7'] === "" ? null : $whole['T7']
            ,
            "T8" => $whole['T8'] === "" ? null : $whole['T8']
            ,
            "T9" => $whole['T9'] === "" ? null : $whole['T9']
            ,
            "T10" => $whole['T10'] === "" ? null : $whole['T10']
            ,
            "T11" => $whole['T11'] === "" ? null : $whole['T11']
            ,
            "T12" => $whole['T12'] === "" ? null : $whole['T12']
            ,
            "T13" => $whole['T13'] === "" ? null : $whole['T13']
            ,
            "T14" => $whole['T14'] === "" ? null : $whole['T14']
            ,
            "T15" => $whole['T15'] === "" ? null : $whole['T15']
            ,
            "T16" => $whole['T16'] === "" ? null : $whole['T16']
            ,
            "T17" => $whole['T17'] === "" ? null : $whole['T17']
            ,
            "T18" => $whole['T18'] === "" ? null : $whole['T18']
            ,
            "T19" => $whole['T19'] === "" ? null : $whole['T19']
            ,
            "T20" => $whole['T20'] === "" ? null : $whole['T20']
            ,
            "MAKE_USER_ID" => $GLOBALS['_Umem']['member_id']
            ,
            "INSP_RSLT_NO" => array(&$whole['INSP_RSLT_NO'], SQLSRV_PARAM_OUT)
            ,
            "RS_CODE" => array(&$_REQUEST['RS_CODE'], SQLSRV_PARAM_OUT)
            ,
            "RS_MSG" => array(&$_REQUEST['RS_MSG'], SQLSRV_PARAM_OUT)
          );

          $rst = $baseObj->DB->exec($sql, $params);
        }
      }


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

    case 'getRoutingList':
      $sql = "USP_B_ROUTING_S10";
      $params = array(
        "ITEM_CD" => $_REQUEST['ITEM_CD'] ?: "",
      );
      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        ;

        $retval['code'] = true;
        $retval['data'] = $rows;
        $retval['mesg'] = '정상 동작 되었습니다.';
      } else {
        $retval['code'] = false;
      }
      break;

    case 'getDefHst':
      $sql = "USP_P_REG_PROD_DEF_HST_S10";
      $params = array(
        "ITEM_CD" => $_REQUEST['ITEM_CD'],
        "OP_CD" => $_REQUEST['OP_CD']
      );
      $rst = $baseObj->DB->exec($sql, $params);

      $rows = array();
      if ($rst) {
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        }
        ;

        $retval['code'] = true;
        $retval['data'] = $rows;
        $retval['mesg'] = '정상 동작 되었습니다.';
      } else {
        $retval['code'] = false;
      }
      break;
  }
}

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