/**
  * Static function for create list page
  * Read params from setting 
  * Create object of class in accordance with mode displaying page 
  */
 function &createListPage($table, $options)
 {
     global $bSubqueriesSupported, $strTableName, $conn, $locale_info, $isGroupSecurity;
     $gQuery = GetTableData($table, ".sqlquery", null);
     $params = array();
     $params = $options;
     $params['origTName'] = GetTableData($table, ".OriginalTable", '');
     $params['sessionPrefix'] = $strTableName;
     $params['tName'] = $table;
     $params['conn'] =& $conn;
     $params['gPageSize'] = GetTableData($table, ".pageSize", 0);
     $params['gOrderIndexes'] = GetTableData($table, ".orderindexes", array());
     $params['gstrOrderBy'] = GetTableData($table, ".strOrderBy", '');
     $params['gsqlHead'] = GetTableData($table, ".sqlHead", '');
     $params['gsqlFrom'] = GetTableData($table, ".sqlFrom", '');
     $params['gsqlWhereExpr'] = GetTableData($table, ".sqlWhereExpr", '');
     $params['gsqlGroupBy'] = $gQuery->GroupByToSql();
     $oHaving = $gQuery->Having();
     $params['gsqlHaving'] = $oHaving->toSql($gQuery);
     $params['locale_info'] =& $locale_info;
     $params["subQueriesSupp"] = $bSubqueriesSupported;
     $params['nSecOptions'] = GetTableData($table, ".nSecOptions", 0);
     $params['nLoginMethod'] = GetGlobalData("nLoginMethod", 0);
     $params['recsPerRowList'] = GetTableData($table, ".recsPerRowList", 0);
     $params['tableGroupBy'] = GetTableData($table, ".tableGroupBy", '');
     $params['dbType'] = GetGlobalData("dbType", 0);
     $params['mainTableOwnerID'] = GetTableData($table, ".mainTableOwnerID", '');
     $params['moveNext'] = GetTableData($table, ".moveNext", 0);
     $params['exportTo'] = GetTableData($table, ".exportTo", false);
     $params['printFriendly'] = GetTableData($table, ".printFriendly", false);
     $params['deleteRecs'] = GetTableData($table, ".delete", false);
     $params['rowHighlite'] = GetTableData($table, ".rowHighlite", false);
     $params["delFile"] = GetGlobalData("delFile", false);
     $params["isGroupSecurity"] = $isGroupSecurity;
     $params['arrKeyFields'] = GetTableData($table, ".arrKeyFields", array());
     $params["useIbox"] = GetTableData($table, ".useIbox", false);
     $params["isUseInlineAdd"] = GetTableData($table, ".isUseInlineAdd", false);
     $params["isUseInlineEdit"] = GetTableData($table, ".isUseInlineEdit", false);
     $params["isUseInlineJs"] = $params["isUseInlineAdd"] || $params["isUseInlineEdit"];
     $params["globSearchFields"] = GetTableData($table, ".globSearchFields", array());
     $params["panelSearchFields"] = GetTableData($table, ".panelSearchFields", array());
     $params['isVerLayout'] = GetTableData($table, ".isVerLayout", false);
     $params['isDisplayLoading'] = GetTableData($table, ".isDisplayLoading", false);
     $params['createLoginPage'] = GetGlobalData("createLoginPage", false);
     $params['subQueriesSupAccess'] = GetTableData($table, ".subQueriesSupAccess", false);
     $params['noRecordsFirstPage'] = GetTableData($table, ".noRecordsFirstPage", false);
     $params['totalsFields'] = GetTableData($table, ".totalsFields", array());
     $params['listIcons'] = GetTableData($table, ".listIcons", false);
     $params['edit'] = GetTableData($table, ".edit", false);
     $params['inlineEdit'] = GetTableData($table, ".inlineEdit", false);
     $params['iCopy'] = GetTableData($table, ".copy", false);
     $params['iView'] = GetTableData($table, ".view", false);
     $params['listAjax'] = GetTableData($table, ".listAjax", false);
     $params['arrRecsPerPage'] = GetTableData($table, ".arrRecsPerPage", array());
     $params['audit'] = GetAuditObject($table);
     $params['listFields'] = array();
     $allfields = GetFieldsList($table);
     foreach ($allfields as $f) {
         if (!AppearOnListPage($f, $table)) {
             continue;
         }
         $params['listFields'][] = array("fName" => $f, "goodFieldName" => GoodFieldName($f), "valueFieldName" => GoodFieldName($f) . "_value", "viewFormat" => GetFieldData($table, $f, "ViewFormat", ""), "editFormat" => GetFieldData($table, $f, "EditFormat", ""));
     }
     // choose class by mode
     if ($params["mode"] == LIST_SIMPLE) {
         $pageObject = new ListPage_Simple($params);
     } else {
         if ($params["mode"] == LIST_AJAX) {
             $pageObject = new ListPage_Ajax($params);
         } else {
             if ($params["mode"] == LIST_LOOKUP) {
                 $pageObject = new ListPage_Lookup($params);
             } else {
                 if ($params["mode"] == LIST_DETAILS) {
                     $pageObject = new ListPage_DPInline($params);
                 } else {
                     if ($params["mode"] == RIGHTS_PAGE) {
                         $pageObject = new RightsPage($params);
                     } else {
                         if ($params["mode"] == MEMBERS_PAGE) {
                             $pageObject = new MembersPage($params);
                         }
                     }
                 }
             }
         }
     }
     return $pageObject;
 }
function prepare_upload($field, $controltype, $postfilename, $value, $table, $id, &$pageObject)
{
    $abs = GetFieldData($table, $field, "Absolute", false);
    $file =& $_FILES["value_" . GoodFieldName($field) . "_" . $id];
    if ($file["error"] || $value == "") {
        return false;
    }
    if (substr($controltype, 6, 1) == "1") {
        if (strlen($postfilename)) {
            $pageObject->filesToDelete[] = new DeleteFile($postfilename, GetUploadFolder($field, $table), $abs);
            if (GetCreateThumbnail($field, $table)) {
                $pageObject->filesToDelete[] = new DeleteFile(GetThumbnailPrefix($field, $table) . $postfilename, GetUploadFolder($field, $table), $abs);
            }
        }
        return "";
    }
    if (substr($controltype, 6, 1) == "0") {
        return false;
    }
    if (strlen($file['tmp_name'])) {
        if (!ResizeOnUpload($field, $table)) {
            $pageObject->filesToMove[] = new MoveFile($file['tmp_name'], $value, GetUploadFolder($field, $table), $abs);
        } else {
            $contents = myfile_get_contents($file['tmp_name']);
            $ext = CheckImageExtension($file["name"]);
            $thumb = CreateThumbnail($contents, GetNewImageSize($field, $table), $ext);
            $pageObject->filesToSave[] = new SaveFile($thumb, $value, GetUploadFolder($field, $table), $abs);
        }
    }
    return $value;
}
                $fEditFormat = GetFieldData($strTableName, $f, 'EditFormat', '');
                if ($fEditFormat != EDIT_FORMAT_LOOKUP_WIZARD || GoodFieldName($f) != $field) {
                    continue;
                }
                $LookupType = GetFieldData($strTableName, $f, 'LookupType', '');
                if ($LookupType == LT_LOOKUPTABLE) {
                    $LookupSQL = "SELECT ";
                    if (GetFieldData($strTableName, $f, 'LookupUnique', false)) {
                        $LookupSQL .= "DISTINCT ";
                    }
                    $LookupSQL .= GetLWLinkField($f, $strTableName, true);
                    $LookupSQL .= "," . GetLWDisplayField($f, $strTableName, true);
                    $LookupSQL .= " FROM " . AddTableWrappers(GetFieldData($strTableName, $f, 'LookupTable', '')) . " ";
                    $LookupSQL .= " WHERE " . GetLWLinkField($f, $strTableName, true) . "=" . $lookupValue . " AND ";
                    $LookupSQL .= GetLWDisplayField($f, $strTableName, true) . " LIKE " . db_prepare_string($value . "%");
                    if (GetFieldData($strTableName, $f, 'UseCategory', false)) {
                        $cvalue = make_db_value(GetFieldData($strTableName, $f, 'CategoryControl', ''), postvalue("category"));
                        $LookupSQL .= " AND " . AddFieldWrappers(GetFieldData($strTableName, $f, 'CategoryFilter', '')) . "=" . $cvalue;
                    }
                }
            }
            $rs2 = db_query($LookupSQL, $conn);
            if ($data = db_fetch_numarray($rs2)) {
                $response[] = $data[0];
                $response[] = $data[1];
            }
        }
    }
}
$respObj = array('success' => true, 'data' => array_slice($response, 0, 40));
echo my_json_encode($respObj);
 function addGoogleMapData($fName, &$data, $viewLink = '')
 {
     $fieldMap = GetFieldData($this->tName, $fName, "mapData", array());
     $mapData['mapFieldValue'] = $data[$fName];
     $address = $data[$fieldMap['address']] ? $data[$fieldMap['address']] : "";
     $lat = $data[$fieldMap['lat']] ? $data[$fieldMap['lat']] : '';
     $lng = $data[$fieldMap['lng']] ? $data[$fieldMap['lng']] : '';
     $desc = $data[$fieldMap['desc']] ? $data[$fieldMap['desc']] : $address;
     if (isset($fieldMap['zoom'])) {
         $zoom = $fieldMap['zoom'];
     } else {
         $zoom = '';
     }
     $mapData['fName'] = $fName;
     $mapData['zoom'] = $zoom;
     $mapData['type'] = 'FIELD_MAP';
     $mapData['markers'][] = array('address' => $address, 'lat' => $lat, 'lng' => $lng, 'link' => $viewLink, 'desc' => $desc, 'recId' => $this->recId);
     $this->googleMapCfg['mapsData']['littleMap_' . GoodFieldName($fName) . '_' . $this->recId] = $mapData;
     $this->googleMapCfg['fieldMapsIds'][] = 'littleMap_' . GoodFieldName($fName) . '_' . $this->recId;
     return $this->googleMapCfg['mapsData']['littleMap_' . GoodFieldName($fName) . '_' . $this->recId];
 }
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;
}
 function showPage()
 {
     $this->BeforeShowList();
     $this->xt->set_template($this->templatefile);
     if (isMobile()) {
         $bricksExcept = array("grid_mobile", "pagination", "search", "cancelbutton_mobile");
     } else {
         $bricksExcept = array("grid", "pagination", "vsearch1", "vsearch2", "search");
         if (GetFieldData($this->mainTable, $this->mainField, 'AllowToAdd', false)) {
             $bricksExcept[] = "recordcontrols_new";
         }
     }
     $this->xt->hideAllBricksExcept($bricksExcept);
     $this->xt->prepare_template($this->templatefile);
     $this->displayAfterLoadTempl();
 }
 function labelFormat($fieldName, $data)
 {
     $table = $this->sessionPrefix;
     $strViewFormat = GetFieldData($table, $fieldName, "ViewFormat", "");
     $strEditFormat = GetFieldData($table, $fieldName, "EditFormat", "");
     if (($strEditFormat == EDIT_FORMAT_LOOKUP_WIZARD || $strEditFormat == EDIT_FORMAT_RADIO) && GetLookupType($fieldName, $table) == LT_LOOKUPTABLE && GetLWLinkField($fieldName, $table) != GetLWDisplayField($fieldName, $table)) {
         $value = DisplayLookupWizard($fieldName, $data[$fieldName], $data, "", MODE_PRINT);
     } else {
         $value = GetData($data, $fieldName, $strViewFormat);
     }
     if (strlen($value) > 50) {
         $value = substr($value, 0, 47) . "...";
     }
     return $this->chart_xmlencode($value);
 }