// create second control, if need it
 $xt->assignbyref("Units_editcontrol1", $ctrlBlockArr['searchcontrol1']);
 // create search type select
 $xt->assign("searchtype_Units", $ctrlBlockArr['searchtype']);
 $isFieldNeedSecCtrl = $searchControlBuilder->isNeedSecondCtrl("Units");
 $ctrlInd = 0;
 if ($isFieldNeedSecCtrl) {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Units", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd, 1 => $ctrlInd + 1));
     $ctrlInd += 2;
 } else {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Units", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd));
     $ctrlInd++;
 }
 // search fields data
 if (GetLookupTable("PerUnit Price", $strTableName)) {
     $pageObject->settingsMap["globalSettings"]['shortTNames'][GetLookupTable("PerUnit Price", $strTableName)] = GetTableURL(GetLookupTable("PerUnit Price", $strTableName));
 }
 $pageObject->fillFieldToolTips("PerUnit Price");
 $srchFields = $pageObject->searchClauseObj->getSearchCtrlParams("PerUnit Price");
 $firstFieldParams = array();
 if (count($srchFields)) {
     $firstFieldParams = $srchFields[0];
 } else {
     $firstFieldParams['fName'] = "PerUnit Price";
     $firstFieldParams['eType'] = '';
     $firstFieldParams['value1'] = '';
     $firstFieldParams['opt'] = '';
     $firstFieldParams['value2'] = '';
     $firstFieldParams['not'] = false;
 }
 // create control
 // create second control, if need it
 $xt->assignbyref("Code_editcontrol1", $ctrlBlockArr['searchcontrol1']);
 // create search type select
 $xt->assign("searchtype_Code", $ctrlBlockArr['searchtype']);
 $isFieldNeedSecCtrl = $searchControlBuilder->isNeedSecondCtrl("Code");
 $ctrlInd = 0;
 if ($isFieldNeedSecCtrl) {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Code", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd, 1 => $ctrlInd + 1));
     $ctrlInd += 2;
 } else {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Code", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd));
     $ctrlInd++;
 }
 // search fields data
 if (GetLookupTable("Location", $strTableName)) {
     $pageObject->settingsMap["globalSettings"]['shortTNames'][GetLookupTable("Location", $strTableName)] = GetTableURL(GetLookupTable("Location", $strTableName));
 }
 $pageObject->fillFieldToolTips("Location");
 $srchFields = $pageObject->searchClauseObj->getSearchCtrlParams("Location");
 $firstFieldParams = array();
 if (count($srchFields)) {
     $firstFieldParams = $srchFields[0];
 } else {
     $firstFieldParams['fName'] = "Location";
     $firstFieldParams['eType'] = '';
     $firstFieldParams['value1'] = '';
     $firstFieldParams['opt'] = '';
     $firstFieldParams['value2'] = '';
     $firstFieldParams['not'] = false;
 }
 // create control
 // create second control, if need it
 $xt->assignbyref("IsSync_editcontrol1", $ctrlBlockArr['searchcontrol1']);
 // create search type select
 $xt->assign("searchtype_IsSync", $ctrlBlockArr['searchtype']);
 $isFieldNeedSecCtrl = $searchControlBuilder->isNeedSecondCtrl("IsSync");
 $ctrlInd = 0;
 if ($isFieldNeedSecCtrl) {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "IsSync", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd, 1 => $ctrlInd + 1));
     $ctrlInd += 2;
 } else {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "IsSync", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd));
     $ctrlInd++;
 }
 // search fields data
 if (GetLookupTable("Currunt Readings", $strTableName)) {
     $pageObject->settingsMap["globalSettings"]['shortTNames'][GetLookupTable("Currunt Readings", $strTableName)] = GetTableURL(GetLookupTable("Currunt Readings", $strTableName));
 }
 $pageObject->fillFieldToolTips("Currunt Readings");
 $srchFields = $pageObject->searchClauseObj->getSearchCtrlParams("Currunt Readings");
 $firstFieldParams = array();
 if (count($srchFields)) {
     $firstFieldParams = $srchFields[0];
 } else {
     $firstFieldParams['fName'] = "Currunt Readings";
     $firstFieldParams['eType'] = '';
     $firstFieldParams['value1'] = '';
     $firstFieldParams['opt'] = '';
     $firstFieldParams['value2'] = '';
     $firstFieldParams['not'] = false;
 }
 // create control
 /**
  * Fill field settings for current table 
  */
 function fillFieldSettings()
 {
     $arrFields = $this->getFieldsByPageType();
     foreach ($arrFields as $fName) {
         if (!array_key_exists($fName, $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'])) {
             $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName] = array();
         }
         $matchDK = false;
         if ($this->matchWithDetailKeys($fName)) {
             $matchDK = true;
         }
         foreach ($this->settingsMap["fieldSettings"] as $key => $val) {
             $fData = GetFieldData($this->tName, $fName, $key, $val['default']);
             if ($key != "validateAs") {
                 if ($key == "EditFormat") {
                     if ($matchDK) {
                         $fData = EDIT_FORMAT_READONLY;
                     }
                 } elseif ($key == "RTEType") {
                     if (UseRTEBasic($fName)) {
                         $fData = "RTE";
                     } elseif (UseRTEFCK($fName)) {
                         $fData = "RTECK";
                         if (!$this->isUseCK) {
                             $this->isUseCK = true;
                         }
                         $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName]['nWidth'] = GetNCols($fName);
                         $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName]['nHeight'] = GetNRows($fName);
                     } elseif (UseRTEInnova($fName)) {
                         $fData = "RTEINNOVA";
                     }
                 } elseif ($key == "autoCompleteFieldsAdd") {
                     $fData = GetFieldData($this->tName, $fName, "autoCompleteFields", $val['default']);
                 } elseif ($key == "autoCompleteFieldsEdit") {
                     if (GetFieldData($this->tName, $fName, 'autoCompleteFieldsOnEdit', false)) {
                         $fData = GetFieldData($this->tName, $fName, "autoCompleteFields", $val['default']);
                     } else {
                         $fData = array();
                     }
                 }
                 $isDefault = false;
                 if (is_array($fData)) {
                     $isDefault = !count($fData);
                 } else {
                     if (!is_array($val['default'])) {
                         $isDefault = $fData === $val['default'];
                     }
                 }
                 if (!$isDefault && !$matchDK) {
                     $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName][$val['jsName']] = $fData;
                 } else {
                     if ($matchDK && ($key == "EditFormat" || $key == "strName")) {
                         $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName][$val['jsName']] = $fData;
                     }
                 }
             } elseif (!$matchDK) {
                 $this->fillValidation($fData, $val, $this->jsSettings['tableSettings'][$this->tName]['fieldSettings'][$fName]);
             }
         }
         $this->jsSettings['tableSettings'][$this->tName]['isUseCK'] = $this->isUseCK;
         if (!empty($this->googleMapCfg) and $this->googleMapCfg['isUseGoogleMap']) {
             $this->jsSettings['tableSettings'][$this->tName]['isUseGoogleMap'] = true;
             $this->jsSettings['tableSettings'][$this->tName]['googleMapCfg'] = $this->googleMapCfg;
         }
         if (GetLookupTable($fName, $this->tName)) {
             $this->jsSettings['global']['shortTNames'][GetLookupTable($fName, $this->tName)] = GetTableURL(GetLookupTable($fName, $this->tName));
         }
         if (GetEditFormat($fName) == 'Time') {
             $this->fillTimePickSettings($fName);
         }
     }
     if ($this->pageType == PAGE_REGISTER) {
         $this->addConfirmToFieldSettings();
     }
 }
function buildLookupSQL($field, $table, $parentVal, $childVal = "", $doCategoryFilter = true, $doValueFilter = false, $addCategoryField = false, $doWhereFilter = true, $oneRecordMode = false)
{
    global $strTableName;
    if (!strlen($table)) {
        $table = $strTableName;
    }
    //	read settings
    $nLookupType = GetFieldData($table, $field, "LookupType", LT_LISTOFVALUES);
    if ($nLookupType != LT_LOOKUPTABLE) {
        return "";
    }
    $bUnique = GetFieldData($table, $field, "LookupUnique", false);
    $strLookupWhere = LookupWhere($field, $table);
    $strOrderBy = GetFieldData($table, $field, "LookupOrderBy", "");
    $bDesc = GetFieldData($table, $field, "LookupDesc", false);
    $strCategoryFilter = GetFieldData($table, $field, "CategoryFilter", "");
    if ($doCategoryFilter) {
        $parentVal = make_db_value(CategoryControl($field, $table), $parentVal);
    }
    if ($doValueFilter) {
        $childVal = make_db_value($field, $childVal);
    }
    //	build SQL string
    $LookupSQL = "SELECT ";
    if ($oneRecordMode) {
        $LookupSQL .= "top 1 ";
    }
    if ($bUnique) {
        $LookupSQL .= "DISTINCT ";
    }
    $LookupSQL .= GetLWLinkField($field, $table);
    $LookupSQL .= "," . GetLWDisplayField($field, $table);
    if ($addCategoryField && strlen($strCategoryFilter)) {
        $LookupSQL .= "," . AddFieldWrappers($strCategoryFilter);
    }
    $LookupSQL .= " FROM " . AddTableWrappers(GetLookupTable($field, $table));
    //	build Where clause
    $categoryWhere = "";
    $childWhere = "";
    if (UseCategory($field, $table) && $doCategoryFilter) {
        $condition = "=" . $parentVal;
        if ($childVal === "null") {
            $condition = " is null";
        }
        $categoryWhere = AddFieldWrappers($strCategoryFilter) . $condition;
    }
    if ($doValueFilter) {
        $condition = "=" . $childVal;
        if ($childVal === "null") {
            $condition = " is null";
        }
        $childWhere = AddFieldWrappers(GetLWLinkField($field, $table)) . $condition;
    }
    $strWhere = "";
    if ($doWhereFilter && strlen($strLookupWhere)) {
        $strWhere = "(" . $strLookupWhere . ")";
    }
    if (strlen($categoryWhere)) {
        if (strlen($strWhere)) {
            $strWhere .= " AND ";
        }
        $strWhere .= $categoryWhere;
    }
    if (strlen($childWhere)) {
        if (strlen($strWhere)) {
            $strWhere .= " AND ";
        }
        $strWhere .= $childWhere;
    }
    if (strlen($strWhere)) {
        $LookupSQL .= " WHERE " . $strWhere;
    }
    //	order by clause
    if (strlen($strOrderBy)) {
        $LookupSQL .= " ORDER BY " . AddTableWrappers(GetLookupTable($field, $table)) . "." . AddFieldWrappers($strOrderBy);
        if ($bDesc) {
            $LookupSQL .= " DESC";
        }
    }
    return $LookupSQL;
}
 // create second control, if need it
 $xt->assignbyref("Location_editcontrol1", $ctrlBlockArr['searchcontrol1']);
 // create search type select
 $xt->assign("searchtype_Location", $ctrlBlockArr['searchtype']);
 $isFieldNeedSecCtrl = $searchControlBuilder->isNeedSecondCtrl("Location");
 $ctrlInd = 0;
 if ($isFieldNeedSecCtrl) {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Location", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd, 1 => $ctrlInd + 1));
     $ctrlInd += 2;
 } else {
     $pageObject->controlsMap["search"]["searchBlocks"][] = array('fName' => "Location", 'recId' => $id, 'ctrlsMap' => array(0 => $ctrlInd));
     $ctrlInd++;
 }
 // search fields data
 if (GetLookupTable("Customer Type", $strTableName)) {
     $pageObject->settingsMap["globalSettings"]['shortTNames'][GetLookupTable("Customer Type", $strTableName)] = GetTableURL(GetLookupTable("Customer Type", $strTableName));
 }
 $pageObject->fillFieldToolTips("Customer Type");
 $srchFields = $pageObject->searchClauseObj->getSearchCtrlParams("Customer Type");
 $firstFieldParams = array();
 if (count($srchFields)) {
     $firstFieldParams = $srchFields[0];
 } else {
     $firstFieldParams['fName'] = "Customer Type";
     $firstFieldParams['eType'] = '';
     $firstFieldParams['value1'] = '';
     $firstFieldParams['opt'] = '';
     $firstFieldParams['value2'] = '';
     $firstFieldParams['not'] = false;
 }
 // create control