public function aryCheckFunctionList()
 {
     $this->m_aryCanUseFunction = array();
     foreach ($this->m_aryFunctionList as $key => $value) {
         //set error code
         $nErrorCode = 0;
         $result = array();
         //always add current alarm
         if ($key == "cncCurtAlm") {
             $tmpAry = array();
             $tmpAry["funName"] = $key;
             $tmpAry["funDetail"] = $this->m_aryFunctionList[$key];
             array_push($this->m_aryCanUseFunction, $tmpAry);
             continue;
         }
         if (is_array($value[$this->listItemName['DBAPI']])) {
             //means it needs more than one dbapi
             foreach ($value[$this->listItemName['DBAPI']] as $dbKey) {
                 $nErrorCode = GetDBData($dbKey, $this->m_nCNCID, array(), $result);
                 if ($nErrorCode !== 0) {
                     break;
                 }
             }
         } else {
             //means it needs one dbapi
             $nErrorCode = GetDBData($key, $this->m_nCNCID, array(), $result);
         }
         if ($nErrorCode !== 0) {
             continue;
         }
         $tmpAry = array();
         $tmpAry["funName"] = $key;
         $tmpAry["funDetail"] = $this->m_aryFunctionList[$key];
         array_push($this->m_aryCanUseFunction, $tmpAry);
     }
     return $this->m_aryCanUseFunction;
 }
示例#2
0
function systemData($methodName, $param, &$resultAry)
{
    $ErrorCode = array("NoUser" => -4, "errorPwd" => -3, "NoData" => -2, "ServerBusy" => -1, "Success" => 0, "NeedDoSome" => 1);
    //module to connect to database
    $RemoteAjax = new RemoteModule();
    //init
    $errorCode = $ErrorCode['Success'];
    $resultAry = '';
    switch ($methodName) {
        case "login":
            //catch user info to compare
            $tmpResultAry = array();
            $tmpErrorCode = systemData("catchUserInfo", $param, $tmpResultAry);
            if ($tmpErrorCode != $ErrorCode['Success']) {
                $errorCode = $tmpErrorCode;
                unset($tmpResultAry);
                unset($tmpErrorCode);
                break;
            }
            $user = $param['user'];
            $pwd = $param['pwd'];
            $DBUser = $tmpResultAry['user'];
            $DBPwd = $tmpResultAry['pwd'];
            //compare user and password
            if ($pwd != $DBPwd) {
                //md5($pwd) != $DBPwd ){
                $errorCode = $ErrorCode['errorPwd'];
                unset($tmpResultAry);
                unset($tmpErrorCode);
                break;
            }
            $companyID = $tmpResultAry['company_id'];
            //user correct, start to get factory and group
            $tmpResultAry = array();
            $tmpErrorCode = GetDBData("myFIDnGID", $companyID, $param, $tmpResultAry);
            if ($tmpErrorCode != $ErrorCode['Success']) {
                $errorCode = $tmpErrorCode;
                unset($tmpResultAry);
                unset($tmpErrorCode);
                break;
            }
            //all success, start to save in SESSION
            //save user info, include name, mode
            $userMode = $param['userMode'] == 1 ? "Management" : "Operation";
            $tmpParam['object'] = "user";
            $tmpParam['value'] = array("name" => $DBUser, "mode" => $userMode);
            $tmpResultAry = array();
            $tmpErrorCode = systemData("saveSESSION", $tmpParam, $tmpResultAry);
            //save company info, include fid,gid
            $fidList = array();
            $gidList = array();
            foreach ($tmpResultAry as $key => $value) {
                //input fid
                if (!in_array($value['fid'], $fidList) == true) {
                    array_push($fidList, $value['fid']);
                }
                //input gid
                if (!in_array($value['gid'], $gidList) == true) {
                    array_push($gidList, $value['gid']);
                }
            }
            $tmpParam['object'] = "companyInfo";
            $tmpParam['value'] = array("fid" => $fidList, "gid" => $gidList);
            $tmpResultAry = array();
            $tmpErrorCode = systemData("saveSESSION", $tmpParam, $tmpResultAry);
            break;
        case "logout":
            break;
        case "catchUserInfo":
            $user = $param['user'];
            $pwd = $param['pwd'];
            $sqlTmp = "SELECT * FROM company WHERE user='******';";
            $RemoteAjax->SQLQuery('catchUserInfo', $sqlTmp);
            if (!empty($RemoteAjax->resultArray['catchUserInfo']) == true) {
                $resultAry = $RemoteAjax->resultArray['catchUserInfo'][0];
            } else {
                $errorCode = $ErrorCode['NoUser'];
            }
            unset($sqlTmp);
            unset($RemoteAjax->resultArray['catchUserInfo']);
            break;
        case "saveSESSION":
            $object = $param['object'];
            foreach ($param['value'] as $key => $value) {
                $_SESSION[$object][$key] = $value;
            }
            break;
    }
    unset($RemoteAjax);
    return $errorCode;
}
示例#3
0
        unset($sqlTmp);
        unset($RemoteAjax->resultArray['changePwd']);
        unset($resultAry);
        break;
    case "DoubleCheckPwd":
        $isSamePwd = false;
        if (md5($post['pwd']) == $_SESSION['RemoteViewer']['user']['pwd']) {
            $isSamePwd = true;
        }
        $resultAry = array("result" => "success", "isSamePwd" => $isSamePwd);
        print_r(json_encode($resultAry));
        break;
    case "GetComapnyLogo":
        $nCompanyID = $_SESSION['RemoteViewer']['companyInfo']['company_id'];
        $companyLogo = array();
        $nErrorCode = GetDBData('GetCompanyLogo', $nCompanyID, array(), $companyLogo);
        $resultAry = array("result" => "success", "data" => $companyLogo);
        print_r(json_encode($resultAry));
        break;
    case "initAuthority":
        $param = array("comapny_name" => $post['companyName']);
        $aryComapnyInfo = array();
        $nErrorCode = GetDBData('initAuthority', 0, $param, $aryComapnyInfo);
        $resultAry = array("result" => "success", "data" => $aryComapnyInfo);
        print_r(json_encode($resultAry));
        break;
    case "GetSession":
        $resultAry = array("result" => "success", "data" => $_SESSION);
        echo json_encode($resultAry);
        break;
}
示例#4
0
function DeleteOldUniID()
{
    $result = array();
    GetDBData('DeleteAllOldCmdByWid', 0, array(), $result);
}
示例#5
0
        }
        $cncObj['cncIndex'] = $post['cncIndex'];
        $cncObj['dataCluster'] = $post['dataCluster'];
        $result = array("result" => "success", "data" => $cncObj);
        print_r(json_encode($result));
        break;
    case "GetInfo":
        $nCNCID = $post['cncID'];
        $result = array();
        $nErrorCode = GetDBData('cncInfo', $nCNCID, array(), $result);
        print_r(json_encode($result));
        break;
    case "GetCncAgentVersion":
        $nCNCID = $post['cncID'];
        $aryCncAgentVersion = array();
        $nErrorCode = GetDBData('cncAgentVersion', $nCNCID, array(), $aryCncAgentVersion);
        $result = array("result" => "success", "data" => $aryCncAgentVersion);
        print_r(json_encode($result));
        break;
}
function GetDiagnosisValue($szCustomizedComponent)
{
    //init
    $diagnosisType = array("R");
    $returnAry = array();
    //start
    $splitValue = split("[(,)]", $szCustomizedComponent);
    for ($i = 0; $i < count($diagnosisType); $i++) {
        if (strrpos($splitValue[1], $diagnosisType[$i]) !== false) {
            $subSplitValue = split($diagnosisType[$i], $splitValue[1]);
            $returnAry['type'] = TranslateDiagnosisType($diagnosisType[$i]);
示例#6
0
        header('Expires: 0');
        header('Cache-Control: must-revalidate');
        header('Pragma: public');
        //print file content
        echo fread($tmpfile, strlen($fileAry['file']));
        // this removes the file
        fclose($tmpfile);
        break;
    case "UploadNcFile":
        $timeObj = new DateTime();
        $currenttime = $timeObj->format('Y-m-d H:i:s');
        //upload file
        $fileConecnt = file_get_contents($_FILES['file']['tmp_name']);
        $param = array("name" => $_FILES['file']['name'], "file" => addslashes($fileConecnt), "size" => $_FILES['file']['size'], "upload_time" => $currenttime);
        $nCNCID = $request['nItemID'];
        $result = array();
        $nErrorCode = GetDBData('UploadNcFile', $nCNCID, $param, $result);
        //remove unless param, and sent param back
        unset($param['file']);
        $result = array("result" => "success", "data" => $param);
        print_r(json_encode($result));
        break;
    case "UploadCompanyLogo":
        $param = array('logoImage' => $request['file']);
        $nCompanyID = $_SESSION['RemoteViewer']['companyInfo']['company_id'];
        $result = array();
        $nErrorCode = GetDBData('UploadCompanyLogo', $nCompanyID, $param, $result);
        $result = array("result" => "success", "data" => $param['logoImage']);
        print_r(json_encode($result));
        break;
}
示例#7
0
        $nGID = $post['g_id'];
        $ipcamArray = array();
        $nErrorCode = GetDBData('GetAllIpcam', $nGID, array(), $ipcamArray);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $ipcamArray);
        print_r(json_encode($result));
        break;
    case "IPCamUpdate":
        $nIPCAMID = $post['ipcam_id'];
        $param = array("ipcam_name" => $post['name'], "ipcam_rtsp_url" => $post['rtsp_url']);
        $nErrorCode = GetDBData('IPCamUpdate', $nIPCAMID, $param, $groupArray);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $groupArray);
        print_r(json_encode($result));
        break;
    case "IPCamDelete":
        $nIPCAMID = $post['ipcam_id'];
        $nErrorCode = GetDBData('IPCamDelete', $nIPCAMID, array(), $ipcamArray);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $ipcamArray);
        print_r(json_encode($result));
        break;
    case "GetIPCamInfo":
        $nCID = $post['g_id'];
        $ipcamArray = array();
        $nErrorCode = GetDBData('GetAllIpcam', $nCID, array(), $ipcamArray);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $ipcamArray);
        print_r(json_encode($result));
        break;
}
        $nCID = $_SESSION['RemoteViewer']['companyInfo']['company_id'];
        $param = array("device" => $post['layoutDevice'], "layoutName" => $post['layoutName'], "layoutFile" => $post['b64Layout']);
        $nErrorCode = GetDBData('SaveLayout', $nCID, $param, $tmpAry);
        $result = array("result" => "success");
        print_r(json_encode($result));
        break;
    case "deleteLayout":
        $tmpAry = array();
        $nCID = $_SESSION['RemoteViewer']['companyInfo']['company_id'];
        $param = array("device" => $post['device'], "layoutName" => $post['layoutName']);
        $nErrorCode = GetDBData('DeleteLayout', $nCID, $param, $tmpAry);
        $result = array("result" => "success", "data" => $tmpAry);
        print_r(json_encode($result));
        break;
    case "saveLayoutComponentNickname":
        $tmpAry = array();
        $nCID = $_SESSION['RemoteViewer']['companyInfo']['company_id'];
        $param = array("nicknames" => $post['b64Nicknames']);
        $nErrorCode = GetDBData('SaveDashboardItemsNicknames', $nCID, $param, $tmpAry);
        $result = array("result" => "success", "data" => $tmpAry);
        print_r(json_encode($result));
        break;
    case "initCNCListFromFactory":
        //my layout
        $CNCList = array();
        $nFactoryID = isset($post['nFID']) ? $post['nFID'] : $_SESSION['RemoteViewer']['companyInfo']['fid'][0];
        $nErrorCode = GetDBData('CncListFromF', $nFactoryID, array(), $CNCList);
        $result = array("result" => "success", "data" => $CNCList);
        print_r(json_encode($result));
        break;
}
示例#9
0
function GetDBData($szDBAPIName, $nCategoryID, $aryParam, &$aryResultAry)
{
    require "DBSchema.php";
    $ErrorCode = array("Empty" => -4, "ZeroData" => -3, "NoData" => -2, "ServerBusy" => -1, "Success" => 0, "NeedDoSome" => 1);
    //init
    $errorCode = $ErrorCode['Success'];
    $aryResultAry = '';
    switch ($szDBAPIName) {
        //sys_related
        case "myFIDnGID":
            $companyID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['NAME']} as fName, {$FACTORY['ID']} as fid, {$GROUP['NAME']} as gName, {$GROUP['ID']} as gid FROM {$FACTORY['TABLE']} LEFT JOIN {$GROUP['TABLE']} ON {$FACTORY['ID']}={$GROUP['FACTORYID']} WHERE {$FACTORY['COMPANYID']}={$companyID} GROUP BY {$GROUP['ID']};";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            /*else{
            			$aryResultAry = $aryResultAry[0];
            		}*/
            break;
        case "DownloadAgentFile":
            $sqlTmp = "SELECT {$AGENTVERSION['AGENTFILE']} as file, {$AGENTVERSION['DESCRIPTION']} as description FROM {$AGENTVERSION['TABLE']} WHERE {$AGENTVERSION['AGENTVERSION']}='{$aryParam['param1']}' AND {$AGENTVERSION['APIVERSION']}='{$aryParam['param2']}';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
            //sys_command
        //sys_command
        case "DeleteAllOldCmdByWid":
            if (empty($_SESSION['companyInfo']['oldWid']) == true) {
                break;
            }
            foreach ($_SESSION['companyInfo']['oldWid'] as $key => $value) {
                $result = array();
                GetDBData("DeleteOldCmdByWid", 0, array("oldUniID" => $value), $result);
                GetDBData("DeleteOldCNCVerByWid", 0, array("oldUniID" => $value), $result);
            }
            break;
        case "DeleteOldCmdByWid":
            //$nCNCID = $nCategoryID;
            $sqlTmp = "DELETE FROM {$CNCCOMMAND['TABLE']} WHERE {$CNCCOMMAND['WID']}='{$aryParam['oldUniID']}'";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            $aryResultAry = $sqlTmp;
            break;
        case "DeleteOldCNCVerByWid":
            $sqlTmp = "DELETE FROM {$CNCVARIABLE['TABLE']} WHERE {$CNCVARIABLE['WID']}='{$aryParam['oldUniID']}'";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            $aryResultAry = $sqlTmp;
            break;
        case "Command":
            $nCNCID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$CNCCOMMAND['TABLE']} ( {$CNCCOMMAND['WID']}, {$CNCCOMMAND['CNCID']}, {$CNCCOMMAND['COMMAND']}, {$CNCCOMMAND['PARAMETER1']}, {$CNCCOMMAND['PARAMETER2']}, {$CNCCOMMAND['WEBTIME']} ) VALUES ( '{$aryParam['uniID']}', '{$nCNCID}', '{$aryParam['command']}', '{$aryParam['cmdParam'][0]}', '{$aryParam['cmdParam'][1]}', '{$aryParam['webTime']}' )";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            //$aryResultAry = $sqlTmp;
            break;
        case "GetCommandResult":
            $sqlTmp = "SELECT {$CNCCOMMANDRESULT['PARAMETER1']} as param1, {$CNCCOMMANDRESULT['PARAMETER2']} as param2, {$CNCCOMMANDRESULT['AGENTTIME']} as agent_time FROM {$CNCCOMMANDRESULT['TABLE']} WHERE {$CNCCOMMANDRESULT['WID']}='{$aryParam['uniID']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
        case "GetCNCVar":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCVARIABLE['NO']} as no, {$CNCVARIABLE['VALUE']} as value, {$CNCVARIABLE['AGENTTIME']} as agent_time FROM {$CNCVARIABLE['TABLE']} WHERE {$CNCVARIABLE['CNCID']}='{$nCNCID}' AND {$CNCVARIABLE['WID']}='{$aryParam['uniID']}' AND {$CNCVARIABLE['TYPE']}='{$aryParam['type']}' AND ({$CNCVARIABLE['NO']} >= {$aryParam['start']}) AND ({$CNCVARIABLE['NO']} <= {$aryParam['end']})";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "GetCNCNcFileList":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCNCDIR['NCNAMELIST']} as name, {$CNCNCDIR['NCSIZELIST']} as size, {$CNCNCDIR['NCDATELIST']} as date FROM {$CNCNCDIR['TABLE']} WHERE {$CNCNCDIR['CNCID']}='{$nCNCID}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
        case "UploadNcFile":
            $nCNCID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$CNCNCFILES['TABLE']} ( {$CNCNCFILES['CNCID']}, {$CNCNCFILES['NAME']}, {$CNCNCFILES['FILE']}, {$CNCNCFILES['FILEUPLOADTIME']} ) VALUES ( '{$nCNCID}', '{$aryParam['name']}', '{$aryParam['file']}', '{$aryParam['upload_time']}') ON DUPLICATE KEY UPDATE {$CNCNCFILES['FILE']}='{$aryParam['file']}', {$CNCNCFILES['FILEUPLOADTIME']}='{$aryParam['upload_time']}'";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "DownloadNcFile":
            $nCNCID = $aryParam['param1'];
            $sqlTmp = "SELECT {$CNCNCFILES['NAME']} as name, {$CNCNCFILES['FILE']} as file, {$CNCNCFILES['FILEUPLOADTIME']} as upload_time FROM {$CNCNCFILES['TABLE']} WHERE {$CNCNCFILES['CNCID']}='{$nCNCID}' AND {$CNCNCFILES['NAME']}='{$aryParam['param2']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
        case "DownloadLadFile":
            $nCNCID = $aryParam['param1'];
            $sqlTmp = "SELECT {$CNCLADFILES['NAME']} as name, {$CNCLADFILES['FILE']} as file, {$CNCLADFILES['FILEUPLOADTIME']} as upload_time FROM {$CNCLADFILES['TABLE']} WHERE {$CNCLADFILES['CNCID']}='{$nCNCID}' AND {$CNCLADFILES['NAME']}='{$aryParam['param2']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
        case "GetOffsetData":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCOFFSET['NO']} as no, {$CNCOFFSET['VALUE']} as value FROM {$CNCOFFSET['TABLE']} WHERE {$CNCOFFSET['CNCID']}={$nCNCID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "WriteOffsetData":
            $nCNCID = $nCategoryID;
            $sqlTmp = "UPDATE {$CNCOFFSET['TABLE']} SET {$CNCOFFSET['VALUE']}='{$aryParam['value']}', {$CNCOFFSET['UPDATETIME']}='{$aryParam['update_time']}' WHERE {$CNCOFFSET['CNCID']}='{$nCNCID}' AND {$CNCOFFSET['NO']}='{$aryParam['no']}'";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "GetDebugLog":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$AGENTDEBUGINFO['LOG']} as log FROM {$AGENTDEBUGINFO['TABLE']} WHERE {$AGENTDEBUGINFO['CNCID']}={$nCNCID} AND {$AGENTDEBUGINFO['TIMESTAMP']}='{$aryParam['szTime']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['log'];
            }
            break;
            //company
        //company
        case "initAuthority":
            $sqlTmp = "SELECT {$COMPANY['IMG']} as img, {$COMPANY['SMALLLOGO']} as small_logo FROM {$COMPANY['TABLE']} WHERE {$COMPANY['NAME']}='{$aryParam['comapny_name']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
        case "GetAllFactoryInfo":
            $nCID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['ALL']} FROM {$FACTORY['TABLE']} WHERE {$FACTORY['COMPANYID']}='{$nCID}';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "UploadCompanyLogo":
            $nCID = $nCategoryID;
            $sqlTmp = "UPDATE {$COMPANY['TABLE']} SET {$COMPANY['SMALLLOGO']}='{$aryParam['logoImage']}' WHERE {$COMPANY['ID']}='{$nCID}'";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "GetCompanyLogo":
            $nCID = $nCategoryID;
            $sqlTmp = "SELECT {$COMPANY['SMALLLOGO']} as small_logo FROM {$COMPANY['TABLE']} WHERE {$COMPANY['ID']}={$nCID};";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['small_logo'];
            }
            break;
            //company_user & authority
            //factory
        //company_user & authority
        //factory
        case "fID":
            $nFID = $nCategoryID;
            $aryResultAry = $nFID;
            break;
        case "fName":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['NAME']} as name FROM {$FACTORY['TABLE']} WHERE {$FACTORY['ID']}={$nFID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['name'];
            }
            break;
        case "fTotalCNC":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT COUNT({$CNCSTATUS['CNCID']}) as fTotalCNC FROM {$CNC['TABLE']} LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNC['ID']} WHERE {$CNC['GROUPID']} IN (SELECT {$GROUP['ID']} FROM {$GROUP['TABLE']} WHERE {$GROUP['FACTORYID']}={$nFID}) AND {$CNCSTATUS['CNCID']} != 'null'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['fTotalCNC'];
            }
            break;
        case "fOOE":
            $nFID = $nCategoryID;
            //Cuz excepted worktime is not exist here
            /*$aryTmparyResult = array();
            		$nTmpErrorCode = GetDBData( "factoryExceptRecordTime", $nFID, array(), $aryTmparyResult );
            		if( $nTmpErrorCode !== $ErrorCode['Success'] ){
            			//means user doesn't set this
            			$errorCode = $nTmpErrorCode;
            			unset( $aryTmparyResult );
            			unset( $nTmpErrorCode );
            			break;
            		}
            		$F_exceptRecord = $aryTmparyResult;*/
            $F_exceptRecord = 86400;
            //get all cnc in this factory, to count all record time
            $aryTmparyResult = array();
            $nTmpErrorCode = GetDBData("CncListFromF", $nFID, array(), $aryTmparyResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                //means user doesn't set this
                $errorCode = $nTmpErrorCode;
                unset($aryTmparyResult);
                unset($nTmpErrorCode);
                break;
            }
            $cncList = $aryTmparyResult;
            $summaryRecord = 0;
            foreach ($cncList as $cncKey => $cncValue) {
                $aryTmparyResult = array();
                $nTmpErrorCode = GetDBData("cncLastWorkTime", $cncValue['cnc_id'], array(), $aryTmparyResult);
                if ($nTmpErrorCode !== $ErrorCode['Success']) {
                    //means user doesn't set this
                    $errorCode = $nTmpErrorCode;
                    unset($aryTmparyResult);
                    unset($nTmpErrorCode);
                    break;
                }
                $cncPreWorkTime = $aryTmparyResult;
                $summaryRecord = $cncPreWorkTime + $summaryRecord;
            }
            if ($errorCode === 0) {
                $avgPreWorkTime = $summaryRecord / sizeof($cncList);
                $aryResultAry = $avgPreWorkTime / $F_exceptRecord * 100;
            }
            unset($F_exceptRecord);
            unset($cncList);
            unset($summaryRecord);
            break;
        case "fStatusOfCnc":
            $nFID = $nCategoryID;
            //check offline cnc first
            $aryTmparyResult = array();
            $nTmpErrorCode = GetDBData("fAEGNTOFFOfCnc", $nFID, array(), $aryTmparyResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                unset($aryTmparyResult);
                unset($nTmpErrorCode);
                break;
            }
            //sql to get cnc status
            $sqlTmp = "SELECT {$CNCSTATUS['ALL']} FROM {$CNC['TABLE']} LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNC['ID']} WHERE {$CNC['GROUPID']} IN (SELECT {$GROUP['ID']} FROM {$GROUP['TABLE']} WHERE {$GROUP['FACTORYID']}={$nFID}) AND {$CNCSTATUS['CNCID']} != 'null';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "fAEGNTOFFOfCnc":
            $nFID = $nCategoryID;
            //sql to get time diff over 5 minutes
            $sqlTmp = "SELECT {$CNCSTATUS['ALL']} FROM cnc LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNC['ID']} LEFT JOIN {$CNCTIME['TABLE']} ON {$CNCTIME['CNCID']}={$CNC['ID']} WHERE {$CNC['GROUPID']} IN (SELECT {$GROUP['ID']} FROM {$GROUP['TABLE']} WHERE {$GROUP['FACTORYID']}={$nFID}) AND timestampdiff( minute, {$CNCTIME['AGENTTIME']}, now() ) > 5 AND {$CNCSTATUS['STATUS']} != 'AGENTOFF';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == true) {
                foreach ($aryResultAry as $key => $value) {
                    //update status into offline
                    $sql_updateToOffline = "UPDATE {$CNCSTATUS['TABLE']} SET {$CNCSTATUS['STATUS']} = 'AGENTOFF'  WHERE {$CNCSTATUS['CNCID']}={$value['cnc_id']}";
                    DoNonQueryComd($sql_updateToOffline);
                }
            }
            break;
        case "CncListFromF":
            $nFID = $nCategoryID;
            //sql to get cnc list from {$FACTORY['TABLE']}
            $sqlTmp = "SELECT {$CNC['ID']}, {$CNC['NAME']}  FROM {$GROUP['TABLE']} LEFT JOIN {$CNC['TABLE']} ON {$CNC['GROUPID']}={$GROUP['ID']} WHERE {$GROUP['FACTORYID']}={$nFID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "factoryExceptRecordTime":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['EXPEXTWORKTIME']} as expected_work_time FROM {$FACTORY['TABLE']} WHERE {$FACTORY['ID']}={$nFID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } elseif ($aryResultAry[0]['expected_work_time'] <= 0) {
                $aryResultAry = 0;
                $errorCode = $szDBAPIName . $ErrorCode['Empty'];
            } else {
                $aryResultAry = $aryResultAry[0]['expected_work_time'];
            }
            break;
            //factory shift schedule
        //factory shift schedule
        case "SaveShiftSchedule":
            $nFID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$FACTORYSHIFTSCHEDULE['TABLE']} ( {$FACTORYSHIFTSCHEDULE['FACTORYID']}, {$FACTORYSHIFTSCHEDULE['SCHEDULETIME']}, {$FACTORYSHIFTSCHEDULE['SHIFTSCHEDULE']}, {$FACTORYSHIFTSCHEDULE['UPDATETIME']}) VALUES ( '{$nFID}', '{$aryParam['scheduleTime']}', '{$aryParam['shiftSchedule']}', CURRENT_TIMESTAMP ) ON DUPLICATE KEY UPDATE {$FACTORYSHIFTSCHEDULE['SCHEDULETIME']}='{$aryParam['scheduleTime']}', {$FACTORYSHIFTSCHEDULE['SHIFTSCHEDULE']}='{$aryParam['shiftSchedule']}', {$FACTORYSHIFTSCHEDULE['UPDATETIME']}=CURRENT_TIMESTAMP";
            $aryResultAry = $sqlTmp;
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "GetShiftSchedule":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORYSHIFTSCHEDULE['SCHEDULETIME']} as shiftTime, {$FACTORYSHIFTSCHEDULE['SHIFTSCHEDULE']} as shiftS FROM {$FACTORYSHIFTSCHEDULE['TABLE']} WHERE {$FACTORYSHIFTSCHEDULE['FACTORYID']}='{$nFID}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['ServerBusy'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
            //IPCam
        //IPCam
        case "GetAllGroup":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT {$GROUP['ALL']} FROM {$GROUP['TABLE']} WHERE {$GROUP['FACTORYID']}={$nFID};";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "IPCamUpload":
            $nGID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$IPCAM['TABLE']} ( {$IPCAM['IPCAMNAME']}, {$IPCAM['GROUPID']}, {$IPCAM['IPCAMRTSP']} ) VALUES ('{$aryParam['ipcam_name']}', '{$nGID}', '{$aryParam['ipcam_rtsp_url']}')";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            $aryResultAry = mysql_insert_id();
            break;
        case "GetAllIpcam":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT {$IPCAM['ALL']} FROM {$IPCAM['TABLE']} WHERE {$IPCAM['GROUPID']}={$nGID};";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "IPCamUpdate":
            $nIPCamID = $nCategoryID;
            $sqlTmp = "UPDATE {$IPCAM['TABLE']} SET {$IPCAM['IPCAMNAME']} = '{$aryParam['ipcam_name']}', {$IPCAM['IPCAMRTSP']} = '{$aryParam['ipcam_rtsp_url']}' WHERE {$IPCAM['IPCAMID']}={$nIPCamID};";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "IPCamDelete":
            $nIPCamID = $nCategoryID;
            $sqlTmp = "DELETE FROM {$IPCAM['TABLE']} WHERE {$IPCAM['IPCAMID']}={$nIPCamID};";
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
            //group
        //group
        case "Group_fID":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT {$GROUP['FACTORYID']} as fID FROM {$GROUP['TABLE']} WHERE {$GROUP['ID']}={$nGID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['ServerBusy'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['fID'];
            }
            break;
        case "FnG_info":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['ID']} as fID, {$FACTORY['NAME']} as fName, {$GROUP['NAME']} as gName, {$CNC['ID']} as cncList FROM {$GROUP['TABLE']} LEFT JOIN {$FACTORY['TABLE']} ON {$GROUP['FACTORYID']}={$FACTORY['ID']} LEFT JOIN {$CNC['TABLE']} ON {$CNC['GROUPID']}={$GROUP['ID']} WHERE {$GROUP['ID']}={$nGID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['ServerBusy'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "gID":
            $nGID = $nCategoryID;
            $aryResultAry = $nGID;
            break;
        case "gName":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT {$GROUP['NAME']} as gName FROM {$GROUP['TABLE']} WHERE {$GROUP['ID']}={$nGID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['ServerBusy'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['gName'];
            }
            break;
        case "gTotalCNC":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT COUNT({$CNC['ID']}) as gTotalCNC FROM {$CNC['TABLE']} LEFT JOIN {$GROUP['TABLE']} ON {$CNC['GROUPID']} = {$GROUP['ID']} LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNC['ID']} = {$CNCSTATUS['CNCID']} WHERE {$GROUP['ID']}={$nGID} AND {$CNCSTATUS['CNCID']} != 'null' ;";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['gTotalCNC'];
            }
            break;
        case "gOOE":
            $nGID = $nCategoryID;
            //excepted time is not exist here
            /*$aryTmpResult = array();
            		$nTmpErrorCode = GetDBData( "GroupExceptRecordTime", $nGID, array(), $aryTmpResult );
            		if( $nTmpErrorCode !== $ErrorCode['Success'] ){
            			//means user doesn't set this
            			$errorCode = $nTmpErrorCode;
            			unset( $aryTmpResult );
            			unset( $nTmpErrorCode );
            			break;
            		}
            		$exceptRecord = $aryTmpResult;*/
            $exceptRecord = 86400;
            //get all cnc in this factory, to count all record time
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("CncListFromG", $nGID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                //means user doesn't set this
                $errorCode = $nTmpErrorCode;
                unset($aryTmpResult);
                unset($nTmpErrorCode);
                break;
            }
            $cncList = $aryTmpResult;
            $summaryRecord = 0;
            foreach ($cncList as $cncKey => $cncValue) {
                $aryTmpResult = array();
                $nTmpErrorCode = GetDBData("cncLastWorkTime", $cncValue['cnc_id'], array(), $aryTmpResult);
                if ($nTmpErrorCode !== $ErrorCode['Success']) {
                    //means user doesn't set this
                    $errorCode = $nTmpErrorCode;
                    unset($aryTmpResult);
                    unset($nTmpErrorCode);
                    break;
                }
                $cncPreWorkTime = $aryTmpResult;
                $summaryRecord = $cncPreWorkTime + $summaryRecord;
            }
            if ($errorCode === 0) {
                $avgPreWorkTime = $summaryRecord / sizeof($cncList);
                $aryResultAry = $avgPreWorkTime / $exceptRecord * 100;
            }
            unset($exceptRecord);
            unset($cncList);
            unset($summaryRecord);
            break;
        case "gIPCAM":
            $nGID = $nCategoryID;
            $aryResultAry = false;
            break;
        case "gStatusOfCnc":
            $nGID = $nCategoryID;
            //check offline cnc first
            $aryTmparyResult = array();
            $nTmpErrorCode = GetDBData("gAGENTOFFOfCnc", $nGID, array(), $aryTmparyResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                unset($aryTmparyResult);
                unset($nTmpErrorCode);
                break;
            }
            //sql to get cnc status
            $sqlTmp = "SELECT {$CNCSTATUS['ALL']}, {$CNC['NAME']} as cncName FROM {$CNC['TABLE']} LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNC['ID']} WHERE {$CNC['GROUPID']} = {$nGID} AND {$CNCSTATUS['CNCID']} != 'null';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "gAGENTOFFOfCnc":
            $nGID = $nCategoryID;
            //sql to get time diff over 5 minutes
            $sqlTmp = "SELECT {$CNCSTATUS['ALL']} FROM {$CNC['TABLE']} LEFT JOIN {$CNCSTATUS['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNC['ID']} LEFT JOIN {$CNCTIME['TABLE']} ON {$CNCTIME['CNCID']}={$CNC['ID']} WHERE {$CNC['GROUPID']}={$nGID} AND timestampdiff( minute, {$CNCTIME['AGENTTIME']}, now() ) > 5 AND {$CNCSTATUS['STATUS']} != 'AGENTOFF';";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == true) {
                foreach ($aryResultAry as $key => $value) {
                    //update status into offline
                    $sql_updateToOffline = "UPDATE {$CNCSTATUS['TABLE']} SET {$CNCSTATUS['STATUS']} = 'OFFLINE'  WHERE {$CNCSTATUS['CNCID']}={$value['cnc_id']}";
                    DoNonQueryComd($sql_updateToOffline);
                }
            }
            break;
        case "GroupExceptRecordTime":
            $nGID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['EXPEXTWORKTIME']} as expected_work_time FROM {$GROUP['TABLE']} LEFT JOIN {$FACTORY['TABLE']} ON {$GROUP['FACTORYID']}={$FACTORY['ID']} WHERE {$GROUP['ID']}={$nGID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['expected_work_time'];
            }
            break;
        case "CncListFromG":
            $nGID = $nCategoryID;
            //sql to get cnc list from {$FACTORY['TABLE']}
            $sqlTmp = "SELECT {$CNC['ID']} as cnc_id FROM {$GROUP['TABLE']} LEFT JOIN {$CNC['TABLE']} ON {$CNC['GROUPID']}={$GROUP['ID']} WHERE {$GROUP['ID']}={$nGID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
            //cnc routine
            //cnc table
        //cnc routine
        //cnc table
        case "cncID":
            $nCncID = $nCategoryID;
            $aryResultAry = $nCncID;
            break;
        case "cncIP":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['IP']} as IP FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['IP'];
            }
            break;
        case "cncMachine":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['MACHINE']} as Machine FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['Machine'];
            }
            break;
        case "cncMachineType":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['MACHINETYPE']} as MachineType FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['MachineType'];
            }
            break;
        case "cncVersion":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['VERSION']} as Version FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['Version'];
            }
            break;
        case "cncSerialNo":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['SERIALNO']} as SerialNo FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['SerialNo'];
            }
            break;
        case "cncGetGroupID":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['GROUPID']} as nGID FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['nGID'];
            }
            break;
        case "cncGetGroupName":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$GROUP['NAME']} as szGName FROM {$CNC['TABLE']} LEFT JOIN {$GROUP['TABLE']} ON {$GROUP['ID']}={$CNC['GROUPID']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['szGName'];
            }
            break;
        case "cncGetFactoryID":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$GROUP['FACTORYID']} as nFID FROM {$CNC['TABLE']} LEFT JOIN {$GROUP['TABLE']} ON {$GROUP['ID']}={$CNC['GROUPID']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['nFID'];
            }
            break;
        case "cncGetFactoryName":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['NAME']} as szFName FROM {$GROUP['TABLE']} LEFT JOIN {$FACTORY['TABLE']} ON {$FACTORY['ID']}={$GROUP['FACTORYID']} WHERE {$GROUP['ID']} = (SELECT {$CNC['GROUPID']} FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}) ";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['szFName'];
            }
            break;
        case "cncName":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['NAME']} FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['name'];
            }
            break;
        case "cncPic":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNC['IMG']} as img FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = base64_encode($aryResultAry[0]['img']);
            }
            break;
            //end cnc table
            //cnc status table
        //end cnc table
        //cnc status table
        case "cncStatus":
            $nCncID = $nCategoryID;
            //get offline cnc first
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("AGENTOFFCnc", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                unset($aryTmpResult);
                unset($nTmpErrorCode);
                break;
            }
            //sql to get status
            $sqlTmp = "SELECT CASE {$CNCSTATUS['STATUS']} WHEN 'AGENTOFF' THEN 'AGENTOFF' WHEN 'OFFLINE' THEN 'OFFLINE' ELSE (CASE {$CNCSTATUS['ALARM']} WHEN 'ALARM' THEN 'ALARM' ELSE {$CNCSTATUS['STATUS']} END) END as Status FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['Status'];
            }
            break;
        case "cncMode":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['MODE']} as mode FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['mode'];
            }
            break;
        case "cncAlarm":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['ALARM']} as alarm FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['alarm'];
            }
            break;
        case "cncEMG":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['EMG']} as emg FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['emg'];
            }
            break;
        case "AGENTOFFCnc":
            $nCncID = $nCategoryID;
            //sql to get offline cnc, differ 5 minutes
            $sqlTmp = "SELECT {$CNCSTATUS['ALL']} FROM {$CNCSTATUS['TABLE']} LEFT JOIN {$CNCTIME['TABLE']} ON {$CNCSTATUS['CNCID']}={$CNCTIME['CNCID']} WHERE {$CNCSTATUS['STATUS']} != 'AGENTOFF' AND {$CNCSTATUS['CNCID']}={$nCncID} AND timestampdiff( minute, {$CNCTIME['AGENTTIME']}, now() ) > 5;";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == true) {
                foreach ($aryResultAry as $subKey => $subValue) {
                    //update status into offline
                    $sql_updateToOffline = "UPDATE {$CNCSTATUS['TABLE']} SET {$CNCSTATUS['STATUS']} = 'AGENTOFF'  WHERE {$CNCSTATUS['CNCID']}={$subValue['cnc_id']}";
                    DoNonQueryComd($sql_updateToOffline, $szDBAPIName);
                }
            }
            break;
        case "cncMainProg":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['MAINPROG']} as main_prog FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['main_prog'];
            }
            break;
        case "cncCurProg":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['CURPROG']} as cruProg FROM {$CNCSTATUS['TABLE']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['cruProg'];
            }
            break;
            //end status table
            //record table
        //end status table
        //record table
        case "cncPowerOnTime":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['POWERONTIME']} as powerOnTime FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['powerOnTime'];
            }
            break;
        case "cncCycleTime":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['CYCLETIME']} as cycleTime FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['cycleTime'];
            }
            break;
        case "cncTotalCycleTime":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['TOTALCYCLETIME']} as totalCycleTime FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['totalCycleTime'];
            }
            break;
        case "cncPartCount":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['PARTCOUNT']} as partCount FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['partCount'];
            }
            break;
        case "cncRequirePartCount":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['REQUIRECOUNT']} as requirePartCount FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['requirePartCount'];
            }
            break;
        case "cncTotalCount":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCRECORD['TOTALCOUNT']} as totalCount FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['totalCount'];
            }
            break;
        case "cncLastWorkTime":
            $nCncID = $nCategoryID;
            //sql to get record
            $sqlTmp = "SELECT {$CNCRECORD['LASTWORKTIME']} as lastwork_time FROM {$CNCRECORD['TABLE']} WHERE timestampdiff( second, {$CNCRECORD['WORKFILEUPDATETIME']}, now() ) < 86400 AND {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                //means cncLastWorkTime have no data, need to explore record file
                $aryTmparyResult = array();
                $nTmpErrorCode = GetDBData("cncWorkFile", $nCncID, array(), $aryTmparyResult);
                if ($nTmpErrorCode !== $ErrorCode['Success']) {
                    $errorCode = $nTmpErrorCode;
                    unset($aryTmparyResult);
                    unset($nTmpErrorCode);
                    break;
                }
                $recordPlaintext = $aryTmparyResult;
                $recordAry = analyzRecord($recordPlaintext);
                $lastwork_time = findLastRecordTime($recordAry, 1);
                //write this time into db
                $today = new DateTime();
                $todateDateTime = $today->setTime(0, 0, 0);
                $sql_updatelastwork_time = "UPDATE {$CNCRECORD['TABLE']} SET {$CNCRECORD['LASTWORKTIME']}='{$lastwork_time}', {$CNCRECORD['WORKFILEUPDATETIME']}='{$todateDateTime->format('Y-m-d H:i:s')}' WHERE {$CNCRECORD['CNCID']}={$nCncID}";
                DoNonQueryComd($sql_updatelastwork_time, $szDBAPIName);
                $aryResultAry = $lastwork_time;
            } else {
                $aryResultAry = $aryResultAry[0]['lastwork_time'];
            }
            break;
        case "cncWorkFile":
            $nCncID = $nCategoryID;
            //sql to get record file
            $sqlTmp = "SELECT {$CNCRECORD['WORKFILE']} as workfile FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } elseif ($aryResultAry[0]['workfile'] === "") {
                $aryResultAry = "";
                $errorCode = $szDBAPIName . $ErrorCode['Empty'];
            } else {
                $aryResultAry = $aryResultAry[0]['workfile'];
            }
            break;
            //end record table
            //time table
        //end record table
        //time table
        case "cncTimeStatus":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMESTATUS']} as tmieStatus FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['tmieStatus'];
            }
            break;
        case "cncTimeStart":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMESTART']} as timeStart FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['timeStart'];
            }
            break;
        case "cncTimeExpire":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMEEXPIRE']} as timeExpire FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['timeExpire'];
            }
            break;
        case "cncTimeRemain":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMEREMAIN']} as timeRemain FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['timeRemain'];
            }
            break;
        case "cncTimeCurrent":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMECURRENT']} as timeCurrent FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['timeCurrent'];
            }
            break;
        case "cncTimeOfOpening":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['TIMEOFOPENING']} as TimeOfOpening FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } elseif ($aryResultAry[0]['TimeOfOpening'] == 0) {
                $aryResultAry = 0;
                $errorCode = $szDBAPIName . $ErrorCode['ZeroData'];
            } else {
                $aryResultAry = $aryResultAry[0]['TimeOfOpening'];
            }
            break;
        case "cncRestDay":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT  CASE {$CNCTIME['TIMESTATUS']} WHEN 'DT_NoTimeLimit' THEN 'NoLimit' ELSE {$CNCTIME['TIMEREMAIN']} END as RestDay FROM {$CNCTIME['TABLE']}  WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['RestDay'];
            }
            break;
        case "cncProcess":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT ROUND(( {$CNCRECORD['PARTCOUNT']}/{$CNCRECORD['REQUIRECOUNT']})*100, 2) as cncProcess FROM {$CNCRECORD['TABLE']} WHERE {$CNCRECORD['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $tmpProcess = $aryResultAry[0]['cncProcess'];
                if ($tmpProcess > 100) {
                    $tmpProcess = 100;
                }
                if ($tmpProcess == 0) {
                    $aryResultAry = "0%";
                }
                $aryResultAry = $tmpProcess . "%";
            }
            break;
        case "cncPartProcess":
            $nCncID = $nCategoryID;
            $tmparyResultAry = array();
            $tmpErrorCode = GetDBData("cncPartCount", $nCncID, array(), $tmparyResultAry);
            if ($tmpErrorCode !== $ErrorCode['Success']) {
                //means user doesn't set this
                $errorCode = $tmpErrorCode;
                unset($tmparyResultAry);
                unset($tmpErrorCode);
                break;
            }
            $nPartCount = $tmparyResultAry;
            $tmparyResultAry = array();
            $tmpErrorCode = GetDBData("cncRequirePartCount", $nCncID, array(), $tmparyResultAry);
            if ($tmpErrorCode !== $ErrorCode['Success']) {
                //means user doesn't set this
                $errorCode = $tmpErrorCode;
                unset($tmparyResultAry);
                unset($tmpErrorCode);
                break;
            }
            $nRequirePartCount = $tmparyResultAry;
            $aryResultAry = $nPartCount . "/" . $nRequirePartCount;
            break;
        case "cncRestTime":
            //TODO:Rest Time to Process
            $nCncID = $nCategoryID;
            $aryResultAry = "35mins";
            break;
        case "cncUpdateTime":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCTIME['AGENTTIME']} as update_time FROM {$CNCTIME['TABLE']} WHERE {$CNCTIME['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['update_time'];
            }
            break;
            //end time table
        //end time table
        case "cncInfo":
            $nCncID = $nCategoryID;
            //machine as Machine, machine_type as MachineType, version as Version, serial_no as SerialNo
            //ip as IP, machine as Machine, machine_type as MachineType, version as Version, serial_no as SerialNo, RESTDAY
            $cncInfoList = "{$CNC['IP']} as IP, {$CNC['MACHINE']} as Machine, {$CNC['MACHINETYPE']} as MachineType, {$CNC['VERSION']} as Version, {$CNC['SERIALNO']} as SerialNo";
            $sqlTmp = "SELECT " . $cncInfoList . " FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            //get restTime
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncRestDay", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                //unset( $aryTmpResult );
                unset($nTmpErrorCode);
            }
            $aryResultAry['RestDay'] = $aryTmpResult;
            break;
        case "cncOOE":
            $nCncID = $nCategoryID;
            //excepted time is not exist here
            /*$tmparyResultAry = array();
            		$tmpErrorCode = GetDBData( "cncExceptRecordTime", $nCncID, array(), $tmparyResultAry );
            		if( $tmpErrorCode !== $ErrorCode['Success'] ){
            			//means user doesn't set this
            			$errorCode = $tmpErrorCode;
            			unset( $tmparyResultAry );
            			unset( $tmpErrorCode );
            			break;
            		}
            		$exceptRecord = $tmparyResultAry;*/
            $exceptRecord = 86400;
            $tmparyResultAry = array();
            $tmpErrorCode = GetDBData("cncLastWorkTime", $nCncID, array(), $tmparyResultAry);
            if ($tmpErrorCode !== $ErrorCode['Success']) {
                //means user doesn't set this
                $errorCode = $tmpErrorCode;
                unset($tmparyResultAry);
                unset($tmpErrorCode);
                break;
            }
            $cncPreWorkTime = $tmparyResultAry;
            if ($errorCode === 0) {
                $aryResultAry = $cncPreWorkTime / $exceptRecord * 100;
            }
            unset($exceptRecord);
            unset($summaryRecord);
            break;
        case "cncHisOOE":
            $nCncID = $nCategoryID;
            //get opentime
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncTimeOfOpening", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                //unset( $aryTmpResult );
                unset($nTmpErrorCode);
            }
            $aryResultAry['OOE']['TimeOfOpening'] = $aryTmpResult;
            //get total cyctime
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncTotalCycleTime", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                //unset( $aryTmpResult );
                unset($nTmpErrorCode);
            }
            $aryResultAry['OOE']['totalCycTime'] = $aryTmpResult;
            //open the record file
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncWorkFile", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                //unset( $aryTmpResult );
                unset($nTmpErrorCode);
            }
            $aryResultAry['OOE']['hisRecordFile'] = $aryTmpResult;
            //get factory set worktime
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncExceptRecordTime", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                unset($aryTmpResult);
                unset($nTmpErrorCode);
                break;
            }
            $aryResultAry['OOE']['expectedWorkTime'] = $aryTmpResult;
            break;
        case "cncCurtAlm":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCALARM['ALL']} FROM {$CNCALARM['TABLE']} WHERE {$CNCALARM['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "cncHisAlm":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCALARMHISTORY['ALARMHISFILE']} FROM {$CNCALARMHISTORY['TABLE']} WHERE {$CNCALARMHISTORY['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['alarm_history'];
            }
            break;
        case "cncHisAlarm":
            $nCncID = $nCategoryID;
            if ($aryParam['unit'] == "curtAlm") {
                //get current alarm
                $aryTmpResult = array();
                $nTmpErrorCode = GetDBData("cncCurtAlm", $nCncID, array(), $aryTmpResult);
                if ($nTmpErrorCode !== $ErrorCode['Success']) {
                    $errorCode = $nTmpErrorCode;
                    //unset( $aryTmpResult );
                    unset($nTmpErrorCode);
                }
                $aryResultAry['curtAlm'] = $aryTmpResult;
            }
            //get history alm
            $aryTmpResult = array();
            $nTmpErrorCode = GetDBData("cncHisAlm", $nCncID, array(), $aryTmpResult);
            if ($nTmpErrorCode !== $ErrorCode['Success']) {
                $errorCode = $nTmpErrorCode;
                //unset( $aryTmpResult );
                unset($nTmpErrorCode);
            }
            $aryResultAry['hisAlm'] = $aryTmpResult;
            break;
        case "cncHisRecord":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCSTATUS['MAINPROG']} as MainProg, {$CNCRECORD['ALL']} FROM {$CNCSTATUS['TABLE']} LEFT JOIN {$CNCRECORD['TABLE']} ON {$CNCRECORD['CNCID']}={$CNCSTATUS['CNCID']} WHERE {$CNCSTATUS['CNCID']}={$nCncID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry['Record'] = $aryResultAry[0];
            }
            break;
        case "cncExceptRecordTime":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORY['EXPEXTWORKTIME']} as expected_work_time FROM {$GROUP['TABLE']} LEFT JOIN {$FACTORY['TABLE']} ON {$GROUP['FACTORYID']}={$FACTORY['ID']} WHERE {$GROUP['ID']}= (SELECT {$CNC['GROUPID']} FROM {$CNC['TABLE']} WHERE {$CNC['ID']}={$nCncID});";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } elseif ($aryResultAry[0]['expected_work_time'] <= 0) {
                $aryResultAry = 0;
                $errorCode = $szDBAPIName . $ErrorCode['ZeroData'];
            } else {
                $aryResultAry = $aryResultAry[0]['expected_work_time'];
            }
            break;
            //cnc_agent_version
        //cnc_agent_version
        case "cncAgentVersion":
            $nCncID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCAGENTVERSION['AGENTVERSION']} as agent_version, {$CNCAGENTVERSION['APIVERSION']} as api_version FROM {$CNCAGENTVERSION['TABLE']} WHERE {$CNCAGENTVERSION['CNCID']}= {$nCncID};";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0];
            }
            break;
            //end cnc_agent_version
            //layout
        //end cnc_agent_version
        //layout
        case "GetDefaultLayout":
            $sqlTmp = "SELECT {$SYSDEFAULTLAYOUT['NAME']} as name, {$SYSDEFAULTLAYOUT['FILE']} as file FROM {$SYSDEFAULTLAYOUT['TABLE']} WHERE {$SYSDEFAULTLAYOUT['DEVICE']}='{$aryParam['device']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "GetMyLayout":
            $nCID = $nCategoryID;
            $sqlTmp = "SELECT {$COMPANYLAYOUT['ALL']} FROM {$COMPANYLAYOUT['TABLE']} WHERE {$COMPANYLAYOUT['COMPANYID']}={$nCID} AND {$COMPANYLAYOUT['LAYOUTDEVICE']}='{$aryParam['device']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            break;
        case "SaveLayout":
            $nCID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$COMPANYLAYOUT['TABLE']} ( {$COMPANYLAYOUT['COMPANYID']}, {$COMPANYLAYOUT['LAYOUTDEVICE']}, {$COMPANYLAYOUT['LAYOUTNAME']}, {$COMPANYLAYOUT['LAYOUTFILE']}, {$COMPANYLAYOUT['UPDATETIME']}) VALUES ( '{$nCID}', '{$aryParam['device']}', '{$aryParam['layoutName']}', '{$aryParam['layoutFile']}', CURRENT_TIMESTAMP ) ON DUPLICATE KEY UPDATE {$COMPANYLAYOUT['LAYOUTFILE']}='{$aryParam['layoutFile']}', {$COMPANYLAYOUT['UPDATETIME']}=CURRENT_TIMESTAMP";
            $aryResultAry = $sqlTmp;
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "GetLayoutComponentFromRoutine":
            $nCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCROUTINE['ROUTINE']} as routine, {$CNCROUTINE['NAME']} as name FROM {$CNCROUTINE['TABLE']} WHERE {$CNCROUTINE['COMPANYID']}='{$nCID}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            }
            break;
        case "DeleteLayout":
            $nCID = $nCategoryID;
            $sqlTmp = "DELETE FROM {$COMPANYLAYOUT['TABLE']} WHERE {$COMPANYLAYOUT['LAYOUTNAME']}='{$aryParam['layoutName']}' AND {$COMPANYLAYOUT['COMPANYID']}='{$nCID}' AND {$COMPANYLAYOUT['LAYOUTDEVICE']}='{$aryParam['device']}'";
            $aryResultAry = $sqlTmp;
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
        case "GetDashboardItemsNicknames":
            $nCID = $nCategoryID;
            $sqlTmp = "SELECT {$COMPANYDASHBOARDITEMNAMES['ITEMNAMES']} as itemNames FROM {$COMPANYDASHBOARDITEMNAMES['TABLE']} WHERE {$COMPANYDASHBOARDITEMNAMES['COMPANYID']}='{$nCID}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['itemNames'];
            }
            break;
        case "SaveDashboardItemsNicknames":
            $nCID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$COMPANYDASHBOARDITEMNAMES['TABLE']} ( {$COMPANYDASHBOARDITEMNAMES['COMPANYID']}, {$COMPANYDASHBOARDITEMNAMES['ITEMNAMES']}, {$COMPANYDASHBOARDITEMNAMES['UPDATETIME']}) VALUES ( '{$nCID}', '{$aryParam['nicknames']}', CURRENT_TIMESTAMP ) ON DUPLICATE KEY UPDATE {$COMPANYDASHBOARDITEMNAMES['ITEMNAMES']}='{$aryParam['nicknames']}', {$COMPANYDASHBOARDITEMNAMES['UPDATETIME']}=CURRENT_TIMESTAMP";
            $aryResultAry = $sqlTmp;
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
            //slider setting
        //slider setting
        case "GetSliderSetting":
            $nFID = $nCategoryID;
            $sqlTmp = "SELECT {$FACTORYSLIDERSETTING['SLIDERSETTING']} as sliderSetting FROM {$FACTORYSLIDERSETTING['TABLE']} WHERE {$FACTORYSLIDERSETTING['FACTORYID']}={$nFID}";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['sliderSetting'];
            }
            break;
        case "SaveSliderSetting":
            $nFID = $nCategoryID;
            $sqlTmp = "INSERT INTO {$FACTORYSLIDERSETTING['TABLE']} ( {$FACTORYSLIDERSETTING['FACTORYID']}, {$FACTORYSLIDERSETTING['SLIDERSETTING']}, {$FACTORYSLIDERSETTING['UPDATETIME']}) VALUES ( '{$nFID}', '{$aryParam['sliderSetting']}', CURRENT_TIMESTAMP ) ON DUPLICATE KEY UPDATE {$FACTORYSLIDERSETTING['SLIDERSETTING']}='{$aryParam['sliderSetting']}', {$FACTORYSLIDERSETTING['UPDATETIME']}=CURRENT_TIMESTAMP";
            $aryResultAry = $sqlTmp;
            DoNonQueryComd($sqlTmp, $szDBAPIName);
            break;
            //customization diagnosis value
        //customization diagnosis value
        case "GetCustomerDiagnosisValue":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCVARIABLE['VALUE']} as value, {$CNCVARIABLE['AGENTTIME']} as agent_time FROM {$CNCVARIABLE['TABLE']} WHERE {$CNCVARIABLE['CNCID']}='{$nCNCID}' AND {$CNCVARIABLE['WID']}='0' AND {$CNCVARIABLE['TYPE']}='{$aryParam['type']}' AND {$CNCVARIABLE['NO']}='{$aryParam['no']}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['value'];
            }
            break;
        case "GetParamSchema":
            $nCNCID = $nCategoryID;
            $sqlTmp = "SELECT {$CNCPARAMSCHEMA['PARAMSCHEMA']} as ParamSchema FROM {$CNCPARAMSCHEMA['TABLE']} WHERE {$CNCPARAMSCHEMA['CNCID']}='{$nCNCID}'";
            $isSuccess = isDoSQLCmd($sqlTmp, $szDBAPIName, $aryResultAry);
            if ($isSuccess == false) {
                $errorCode = $szDBAPIName . $ErrorCode['NoData'];
                $errorCode = $nCategoryID . $errorCode;
            } else {
                $aryResultAry = $aryResultAry[0]['ParamSchema'];
            }
            break;
    }
    unset($sqlTmp);
    return $errorCode;
}
示例#10
0
    case "TranslateDataSource":
        $nCNCID = $post['cncID'];
        $funObj = new FunctionObj($nCNCID);
        $dataSource = array();
        if (!empty($post['dataSource']) == true) {
            foreach ($post['dataSource'] as $key => $value) {
                $szApiName = $funObj->GetDBAPIFromTWName($value);
                array_push($dataSource, $szApiName);
            }
        }
        $result = array("result" => "success", "data" => $dataSource, "rawData" => $post['dataSource'], "cnc_id" => $post['cncID']);
        print_r(json_encode($result));
        break;
    case "GetRecordStr":
        $recordAry = array();
        foreach ($post['cncs'] as $key) {
            $cncName = array();
            $workFile = array();
            $nCNCID = $key;
            $nErrorCode = GetDBData('cncName', $nCNCID, array(), $cncName);
            $nErrorCode = GetDBData('cncWorkFile', $nCNCID, array(), $workFile);
            if ($cncName == "") {
                $recordAry[$key] = $workFile;
                continue;
            }
            $recordAry[$cncName] = $workFile;
        }
        $result = array("result" => "success", "data" => $recordAry);
        print_r(json_encode($result));
        break;
}
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $factoryArray);
        print_r(json_encode($result));
        break;
    case "initCNCListFromFactory":
        //my layout
        $CNCList = array();
        $nFactoryID = $post['nFID'];
        $nErrorCode = GetDBData('CncListFromF', $nFactoryID, array(), $CNCList);
        $result = array("result" => "success", "data" => $CNCList);
        print_r(json_encode($result));
        break;
    case "loadSliderSetting":
        $nFID = $post['nFID'];
        $b64SliderSetting = array();
        $nErrorCode = GetDBData('GetSliderSetting', $nFID, array(), $b64SliderSetting);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success", "data" => $b64SliderSetting);
        print_r(json_encode($result));
        break;
    case "saveSliderSetting":
        $param = array("sliderSetting" => $post['b64SliderSetting']);
        //my layout
        $tmpArray = array();
        $nFID = $post['nFID'];
        $nErrorCode = GetDBData('SaveSliderSetting', $nFID, $param, $tmpArray);
        //ErrorLog( $nErrorCode );
        $result = array("result" => "success");
        print_r(json_encode($result));
        break;
}
示例#12
0
} else {
    echo "not defined";
    exit;
}
$method = $post['method'];
switch ($method) {
    case "SaveSchedule":
        $param = array("scheduleTime" => $post['B64_scheduleTime'], "shiftSchedule" => $post['B64_schedule']);
        $nFID = $post['fid'];
        $aryResult = array();
        $nErrorCode = GetDBData('SaveShiftSchedule', $nFID, $param, $aryResult);
        ErrorLog($nErrorCode);
        $result = array("result" => "success", "data" => $aryResult);
        print_r(json_encode($result));
        break;
    case "LoadSchedule":
        $fid = isset($post['fid']) == true ? $post['fid'] : 0;
        //get fid from cncid
        if ($fid === 0) {
            $nCNCID = $post['cncid'];
            $result_fid = array();
            $nErrorCode = GetDBData('cncGetFactoryID', $nCNCID, array(), $result_fid);
            $fid = $result_fid;
        }
        $nFID = $fid;
        $aryResult = array();
        $nErrorCode = GetDBData('GetShiftSchedule', $nFID, array(), $aryResult);
        $result = array("result" => "success", "data" => $aryResult);
        print_r(json_encode($result));
        break;
}