Exemple #1
0
        public static XVar getIntervalFilterWhere(dynamic _param_fName, dynamic _param_intervalData, dynamic _param_pSet_packed, dynamic _param_cipherer, dynamic _param_tableName, dynamic _param_connection, dynamic _param_sqlFieldName = null)
        {
            #region packeted values
            ProjectSettings _param_pSet = XVar.UnPackProjectSettings(_param_pSet_packed);
            #endregion

            #region default values
            if (_param_sqlFieldName as Object == null)
            {
                _param_sqlFieldName = new XVar("");
            }
            #endregion

            #region pass-by-value parameters
            dynamic         fName        = XVar.Clone(_param_fName);
            dynamic         intervalData = XVar.Clone(_param_intervalData);
            ProjectSettings pSet         = XVar.Clone(_param_pSet);
            dynamic         cipherer     = XVar.Clone(_param_cipherer);
            dynamic         tableName    = XVar.Clone(_param_tableName);
            dynamic         connection   = XVar.Clone(_param_connection);
            dynamic         sqlFieldName = XVar.Clone(_param_sqlFieldName);
            #endregion

            if (sqlFieldName == XVar.Pack(""))
            {
                sqlFieldName = XVar.Clone(RunnerPage._getFieldSQL((XVar)(fName), (XVar)(connection), (XVar)(pSet)));
            }
            if (XVar.Pack(intervalData["remainder"]))
            {
                dynamic conditions = XVar.Array(), index = null, intervalsData = XVar.Array();
                index         = XVar.Clone(intervalData["index"]);
                intervalsData = XVar.Clone(pSet.getFilterIntervals((XVar)(fName)));
                conditions    = XVar.Clone(XVar.Array());
                foreach (KeyValuePair <XVar, dynamic> _intervalData in intervalsData.GetEnumerator())
                {
                    if (XVar.Pack(_intervalData.Value["noLimits"]))
                    {
                        return("1=0");
                    }
                    if (_intervalData.Value["index"] == index)
                    {
                        continue;
                    }
                    conditions.InitAndSetArrayItem(getLimitsConditions((XVar)(fName), (XVar)(sqlFieldName), (XVar)(_intervalData.Value), (XVar)(cipherer), (XVar)(tableName), (XVar)(connection), new XVar(true)), null);
                }
                return(MVCFunctions.implode(new XVar(" AND "), (XVar)(conditions)));
            }
            if (XVar.Pack(intervalData["noLimits"]))
            {
                return(MVCFunctions.Concat(sqlFieldName, " is not NULL AND ", sqlFieldName, " <> '' "));
            }
            return(getLimitsConditions((XVar)(fName), (XVar)(sqlFieldName), (XVar)(intervalData), (XVar)(cipherer), (XVar)(tableName), (XVar)(connection)));
        }
Exemple #2
0
 public XVar searchsuggest()
 {
     try
     {
         dynamic         _connection = null, allSearchFields = XVar.Array(), controls = null, detailKeys = XVar.Array(), numberOfSuggests = null, query = null, result = XVar.Array(), returnJSON = XVar.Array(), searchClauseObj = null, searchField = null, searchFor = null, searchOpt = null, table = null, var_response = XVar.Array(), whereClauses = XVar.Array();
         ProjectSettings pSet;
         CommonFunctions.add_nocache_headers();
         table = XVar.Clone(MVCFunctions.postvalue(new XVar("table")));
         GlobalVars.strTableName = XVar.Clone(CommonFunctions.GetTableByShort((XVar)(table)));
         if (XVar.Pack(!(XVar)(CommonFunctions.checkTableName((XVar)(table)))))
         {
             MVCFunctions.Echo(new XVar(0));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         Assembly.GetExecutingAssembly().GetType(MVCFunctions.Concat("runnerDotNet.", MVCFunctions.Concat("", table, ""),
                                                                     "_Variables")).InvokeMember("Apply", BindingFlags.InvokeMethod, null, null, null);
         if (XVar.Pack(!(XVar)(CommonFunctions.isLogged())))
         {
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         if (XVar.Pack(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Search")))))
         {
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         searchFor = XVar.Clone(MVCFunctions.trim((XVar)(MVCFunctions.postvalue(new XVar("searchFor")))));
         if (searchFor == XVar.Pack(""))
         {
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(new XVar("success", true, "result", ""))));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         _connection      = XVar.Clone(GlobalVars.cman.byTable((XVar)(GlobalVars.strTableName)));
         var_response     = XVar.Clone(XVar.Array());
         searchOpt        = XVar.Clone((XVar.Pack(MVCFunctions.postvalue(new XVar("start"))) ? XVar.Pack("Starts with") : XVar.Pack("Contains")));
         searchField      = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(MVCFunctions.postvalue(new XVar("searchField")))));
         numberOfSuggests = XVar.Clone(CommonFunctions.GetGlobalData(new XVar("searchSuggestsNumber"), new XVar(10)));
         pSet             = XVar.UnPackProjectSettings(new ProjectSettings((XVar)(GlobalVars.strTableName), new XVar(Constants.PAGE_SEARCH)));
         query            = XVar.Clone(pSet.getSQLQuery());
         if (searchField == XVar.Pack(""))
         {
             allSearchFields = XVar.Clone(pSet.getGoogleLikeFields());
         }
         else
         {
             allSearchFields = XVar.Clone(pSet.getAllSearchFields());
         }
         detailKeys   = XVar.Clone(XVar.Array());
         whereClauses = XVar.Clone(XVar.Array());
         whereClauses.InitAndSetArrayItem(CommonFunctions.SecuritySQL(new XVar("Search"), (XVar)(GlobalVars.strTableName)), null);
         GlobalVars.cipherer = XVar.Clone(new RunnerCipherer((XVar)(GlobalVars.strTableName)));
         controls            = XVar.Clone(new EditControlsContainer(new XVar(null), (XVar)(pSet), new XVar(Constants.PAGE_LIST), (XVar)(GlobalVars.cipherer)));
         if (XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_mastertable")] != "")
         {
             dynamic i = null, j = null, masterTablesInfoArr = XVar.Array(), masterWhere = null, mastervalue = null;
             masterWhere         = new XVar("");
             masterTablesInfoArr = XVar.Clone(pSet.getMasterTablesArr((XVar)(GlobalVars.strTableName)));
             i = new XVar(0);
             for (; i < MVCFunctions.count(masterTablesInfoArr); i++)
             {
                 if (XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_mastertable")] != masterTablesInfoArr[i]["mDataSourceTable"])
                 {
                     continue;
                 }
                 detailKeys = XVar.Clone(masterTablesInfoArr[i]["detailKeys"]);
                 j          = new XVar(0);
                 for (; j < MVCFunctions.count(detailKeys); j++)
                 {
                     mastervalue = XVar.Clone(GlobalVars.cipherer.MakeDBValue((XVar)(detailKeys[j]), (XVar)(XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_masterkey", j + 1)]), new XVar(""), new XVar(true)));
                     if (mastervalue == "null")
                     {
                         masterWhere = MVCFunctions.Concat(masterWhere, RunnerPage._getFieldSQL((XVar)(detailKeys[j]), (XVar)(_connection), (XVar)(pSet)), " is NULL ");
                     }
                     else
                     {
                         masterWhere = MVCFunctions.Concat(masterWhere, RunnerPage._getFieldSQLDecrypt((XVar)(detailKeys[j]), (XVar)(_connection), (XVar)(pSet), (XVar)(GlobalVars.cipherer)), "=", mastervalue);
                     }
                 }
                 break;
             }
             whereClauses.InitAndSetArrayItem(masterWhere, null);
         }
         searchClauseObj = XVar.Clone(SearchClause.getSearchObject((XVar)(GlobalVars.strTableName), new XVar(""), (XVar)(GlobalVars.strTableName), (XVar)(GlobalVars.cipherer)));
         searchClauseObj.processFiltersWhere((XVar)(_connection));
         foreach (KeyValuePair <XVar, dynamic> filteredField in searchClauseObj.filteredFields.GetEnumerator())
         {
             whereClauses.InitAndSetArrayItem(filteredField.Value["where"], null);
         }
         result = XVar.Clone(XVar.Array());
         foreach (KeyValuePair <XVar, dynamic> f in allSearchFields.GetEnumerator())
         {
             dynamic clausesData = XVar.Array(), distinct = null, fType = null, fieldControl = null, having = null, isAggregateField = null, qResult = null, row = XVar.Array(), sql = XVar.Array(), subQuery = null, val = null, where = null;
             fType = XVar.Clone(pSet.getFieldType((XVar)(f.Value)));
             if ((XVar)((XVar)((XVar)(!(XVar)(CommonFunctions.IsCharType((XVar)(fType)))) && (XVar)(!(XVar)(CommonFunctions.IsNumberType((XVar)(fType))))) && (XVar)(!(XVar)(CommonFunctions.IsGuid((XVar)(fType))))) || (XVar)(MVCFunctions.in_array((XVar)(f.Value), (XVar)(detailKeys))))
             {
                 continue;
             }
             if ((XVar)(_connection.dbType == Constants.nDATABASE_Oracle) && (XVar)(CommonFunctions.IsTextType((XVar)(fType))))
             {
                 continue;
             }
             if ((XVar)((XVar)(searchField != XVar.Pack("")) && (XVar)(searchField != MVCFunctions.GoodFieldName((XVar)(f.Value)))) || (XVar)(!(XVar)(pSet.checkFieldPermissions((XVar)(f.Value)))))
             {
                 continue;
             }
             fieldControl     = XVar.Clone(controls.getControl((XVar)(f.Value)));
             isAggregateField = XVar.Clone(pSet.isAggregateField((XVar)(f.Value)));
             where            = XVar.Clone(fieldControl.getSuggestWhere((XVar)(searchOpt), (XVar)(searchFor), (XVar)(isAggregateField)));
             having           = XVar.Clone(fieldControl.getSuggestHaving((XVar)(searchOpt), (XVar)(searchFor), (XVar)(isAggregateField)));
             if ((XVar)(!(XVar)(MVCFunctions.strlen((XVar)(where)))) && (XVar)(!(XVar)(MVCFunctions.strlen((XVar)(having)))))
             {
                 continue;
             }
             distinct = new XVar("DISTINCT");
             if ((XVar)(_connection.dbType == Constants.nDATABASE_MSSQLServer) || (XVar)(_connection.dbType == Constants.nDATABASE_Access))
             {
                 if (XVar.Pack(CommonFunctions.IsTextType((XVar)(fType))))
                 {
                     distinct = new XVar("");
                 }
             }
             sql         = XVar.Clone(query.getSqlComponents());
             clausesData = XVar.Clone(fieldControl.getSelectColumnsAndJoinFromPart((XVar)(searchFor), (XVar)(searchOpt), new XVar(true)));
             if (0 == MVCFunctions.strlen((XVar)(clausesData["joinFromPart"])))
             {
                 subQuery          = XVar.Clone(SQLQuery.buildSQL((XVar)(sql), (XVar)(whereClauses), (XVar)(XVar.Array()), (XVar)(new XVar(0, where)), (XVar)(new XVar(0, having))));
                 GlobalVars.strSQL = XVar.Clone(MVCFunctions.Concat("SELECT ", distinct, " st.", _connection.addFieldWrappers((XVar)(f.Value)), " from (", subQuery, ") st"));
             }
             else
             {
                 sql["from"] = MVCFunctions.Concat(sql["from"], clausesData["joinFromPart"]);
                 sql.InitAndSetArrayItem(MVCFunctions.Concat("SELECT ", distinct, " ", clausesData["selectColumns"], " as ", _connection.addFieldWrappers(new XVar("_srchfld_"))), "head");
                 subQuery          = XVar.Clone(SQLQuery.buildSQL((XVar)(sql), (XVar)(whereClauses), (XVar)(XVar.Array()), (XVar)(new XVar(0, where)), (XVar)(new XVar(0, having))));
                 GlobalVars.strSQL = XVar.Clone(MVCFunctions.Concat("SELECT ", _connection.addFieldWrappers(new XVar("_srchfld_")), " from (", subQuery, ") st"));
             }
             qResult = XVar.Clone(_connection.queryPage((XVar)(GlobalVars.strSQL), new XVar(1), (XVar)(numberOfSuggests), new XVar(true)));
             while ((XVar)(row = XVar.Clone(qResult.fetchNumeric())) && (XVar)(MVCFunctions.count(var_response) < numberOfSuggests))
             {
                 val = XVar.Clone(GlobalVars.cipherer.DecryptField((XVar)(f.Value), (XVar)(row[0])));
                 if (XVar.Pack(CommonFunctions.IsGuid((XVar)(fType))))
                 {
                     val = XVar.Clone(MVCFunctions.substr((XVar)(val), new XVar(1), new XVar(-1)));
                 }
                 fieldControl.suggestValue((XVar)(MVCFunctions.Concat("_", val)), (XVar)(searchFor), (XVar)(var_response), (XVar)(row));
             }
         }
         _connection.close();
         MVCFunctions.ksort(ref var_response, new XVar(Constants.SORT_STRING));
         foreach (KeyValuePair <XVar, dynamic> realValue in var_response.GetEnumerator())
         {
             dynamic pos = null, strRealValue = null, strValue = null;
             if (numberOfSuggests < MVCFunctions.count(result))
             {
                 break;
             }
             strValue     = XVar.Clone((XVar.Pack(realValue.Key[0] == "_") ? XVar.Pack(MVCFunctions.substr((XVar)(realValue.Key), new XVar(1))) : XVar.Pack(realValue.Key)));
             strRealValue = XVar.Clone((XVar.Pack(realValue.Value[0] == "_") ? XVar.Pack(MVCFunctions.substr((XVar)(realValue.Value), new XVar(1))) : XVar.Pack(realValue.Value)));
             pos          = XVar.Clone(CommonFunctions.my_stripos((XVar)(strValue), (XVar)(searchFor), new XVar(0)));
             if (XVar.Equals(XVar.Pack(pos), XVar.Pack(false)))
             {
                 result.InitAndSetArrayItem(new XVar("value", MVCFunctions.runner_htmlspecialchars((XVar)(strValue)), "realValue", strRealValue), null);
             }
             else
             {
                 dynamic highlightedValue = null;
                 highlightedValue = XVar.Clone(MVCFunctions.Concat(MVCFunctions.runner_htmlspecialchars((XVar)(MVCFunctions.substr((XVar)(strValue), new XVar(0), (XVar)(pos)))), "<b>", MVCFunctions.runner_htmlspecialchars((XVar)(MVCFunctions.substr((XVar)(strValue), (XVar)(pos), (XVar)(MVCFunctions.strlen((XVar)(searchFor)))))), "</b>", MVCFunctions.runner_htmlspecialchars((XVar)(MVCFunctions.substr((XVar)(strValue), (XVar)(pos + MVCFunctions.strlen((XVar)(searchFor))))))));
                 result.InitAndSetArrayItem(new XVar("value", highlightedValue, "realValue", strRealValue), null);
             }
         }
         returnJSON = XVar.Clone(XVar.Array());
         returnJSON.InitAndSetArrayItem(true, "success");
         returnJSON.InitAndSetArrayItem(result, "result");
         MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
         MVCFunctions.Echo(new XVar(""));
         return(MVCFunctions.GetBuferContentAndClearBufer());
     }
     catch (RunnerRedirectException ex)
     { return(Redirect(ex.Message)); }
 }
Exemple #3
0
 public XVar searchsuggest()
 {
     try
     {
         dynamic         _connection = null, allSearchFields = null, dashSearchFields = XVar.Array(), dashSettings = null, detailKeys = XVar.Array(), forDashboardSimpleSearch = null, numberOfSuggests = null, pSetList = null, pageType = null, result = XVar.Array(), returnJSON = XVar.Array(), searchClauseObj = null, searchField = null, searchFor = null, searchOpt = null, table = null, whereClauses = XVar.Array();
         ProjectSettings pSet;
         CommonFunctions.add_nocache_headers();
         table = XVar.Clone(MVCFunctions.postvalue(new XVar("table")));
         GlobalVars.strTableName = XVar.Clone(CommonFunctions.GetTableByShort((XVar)(table)));
         if (XVar.Pack(!(XVar)(CommonFunctions.checkTableName((XVar)(table)))))
         {
             MVCFunctions.Echo(new XVar(0));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         Assembly.GetExecutingAssembly().GetType(MVCFunctions.Concat("runnerDotNet.", MVCFunctions.Concat("", table, ""),
                                                                     "_Variables")).InvokeMember("Apply", BindingFlags.InvokeMethod, null, null, null);
         if (XVar.Pack(!(XVar)(CommonFunctions.isLogged())))
         {
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         if (XVar.Pack(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Search")))))
         {
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         searchFor = XVar.Clone(MVCFunctions.trim((XVar)(MVCFunctions.postvalue(new XVar("searchFor")))));
         if (searchFor == XVar.Pack(""))
         {
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(new XVar("success", true, "result", ""))));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         searchOpt        = XVar.Clone((XVar.Pack(MVCFunctions.postvalue(new XVar("start"))) ? XVar.Pack("Starts with") : XVar.Pack("Contains")));
         searchField      = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(MVCFunctions.postvalue(new XVar("searchField")))));
         numberOfSuggests = XVar.Clone(CommonFunctions.GetGlobalData(new XVar("searchSuggestsNumber"), new XVar(10)));
         whereClauses     = XVar.Clone(XVar.Array());
         pageType         = XVar.Clone(MVCFunctions.postvalue(new XVar("pageType")));
         if (XVar.Pack(!(XVar)(pageType)))
         {
             pageType = new XVar(Constants.PAGE_LIST);
         }
         forDashboardSimpleSearch = XVar.Clone((XVar)(!(XVar)(searchField)) && (XVar)(pageType == Constants.PAGE_DASHBOARD));
         if (XVar.Pack(forDashboardSimpleSearch))
         {
             dynamic dashGoogleLikeFields = XVar.Array(), sfdata = XVar.Array();
             dashSettings         = XVar.Clone(new ProjectSettings((XVar)(GlobalVars.strTableName), new XVar(Constants.PAGE_DASHBOARD)));
             dashGoogleLikeFields = XVar.Clone(dashSettings.getGoogleLikeFields());
             dashSearchFields     = XVar.Clone(dashSettings.getDashboardSearchFields());
             sfdata = XVar.Clone(XVar.Array());
             foreach (KeyValuePair <XVar, dynamic> g in dashGoogleLikeFields.GetEnumerator())
             {
                 foreach (KeyValuePair <XVar, dynamic> data in dashSearchFields[g.Value].GetEnumerator())
                 {
                     sfdata.InitAndSetArrayItem(data.Value["field"], data.Value["table"], null);
                 }
             }
             foreach (KeyValuePair <XVar, dynamic> fields in sfdata.GetEnumerator())
             {
                 dynamic _result = XVar.Array();
                 if (numberOfSuggests <= MVCFunctions.count(result))
                 {
                     break;
                 }
                 if (XVar.Pack(!(XVar)(MVCFunctions.count(result))))
                 {
                     result = XVar.Clone(XVar.Array());
                 }
                 _result = XVar.Clone(CommonFunctions.getListOfSuggests((XVar)(fields.Value), (XVar)(fields.Key), (XVar)(whereClauses), (XVar)(numberOfSuggests - MVCFunctions.count(result)), (XVar)(searchOpt), (XVar)(searchFor)));
                 foreach (KeyValuePair <XVar, dynamic> _data in _result.GetEnumerator())
                 {
                     dynamic found = null;
                     found = new XVar(false);
                     foreach (KeyValuePair <XVar, dynamic> data in result.GetEnumerator())
                     {
                         if (data.Value["realValue"] == _data.Value["realValue"])
                         {
                             found = new XVar(true);
                             break;
                         }
                     }
                     if (XVar.Pack(!(XVar)(found)))
                     {
                         result.InitAndSetArrayItem(_data.Value, null);
                     }
                 }
             }
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(new XVar("success", true, "result", result))));
             MVCFunctions.Echo(new XVar(""));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         if (pageType == Constants.PAGE_DASHBOARD)
         {
             dynamic sfData = XVar.Array();
             dashSettings     = XVar.Clone(new ProjectSettings((XVar)(GlobalVars.strTableName), new XVar(Constants.PAGE_DASHBOARD)));
             dashSearchFields = XVar.Clone(dashSettings.getDashboardSearchFields());
             sfData           = XVar.Clone(dashSearchFields[searchField][0]);
             searchField      = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(sfData["field"])));
             table            = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(sfData["table"])));
             if (XVar.Pack(!(XVar)(CommonFunctions.checkTableName((XVar)(table)))))
             {
                 MVCFunctions.Echo(new XVar(0));
                 return(MVCFunctions.GetBuferContentAndClearBufer());
             }
             GlobalVars.strTableName = XVar.Clone(CommonFunctions.GetTableByShort((XVar)(table)));
             Assembly.GetExecutingAssembly().GetType(MVCFunctions.Concat("runnerDotNet.", MVCFunctions.Concat("", table, ""),
                                                                         "_Variables")).InvokeMember("Apply", BindingFlags.InvokeMethod, null, null, null);
             foreach (KeyValuePair <XVar, dynamic> elem in dashSettings.getDashboardElements().GetEnumerator())
             {
                 if (elem.Value["table"] == GlobalVars.strTableName)
                 {
                     pageType = new XVar(Constants.PAGE_LIST);
                     if (elem.Value["type"] == Constants.DASHBOARD_CHART)
                     {
                         pageType = new XVar(Constants.PAGE_CHART);
                     }
                     else
                     {
                         if (elem.Value["type"] == Constants.DASHBOARD_REPORT)
                         {
                             pageType = new XVar(Constants.PAGE_REPORT);
                         }
                     }
                     break;
                 }
             }
         }
         pSetList = XVar.Clone(new ProjectSettings((XVar)(GlobalVars.strTableName), (XVar)(pageType)));
         if (searchField == XVar.Pack(""))
         {
             allSearchFields = XVar.Clone(pSetList.getGoogleLikeFields());
         }
         else
         {
             allSearchFields = XVar.Clone(pSetList.getAllSearchFields());
         }
         pSet = XVar.UnPackProjectSettings(new ProjectSettings((XVar)(GlobalVars.strTableName), new XVar(Constants.PAGE_SEARCH)));
         GlobalVars.cipherer = XVar.Clone(new RunnerCipherer((XVar)(GlobalVars.strTableName)));
         _connection         = XVar.Clone(GlobalVars.cman.byTable((XVar)(GlobalVars.strTableName)));
         detailKeys          = XVar.Clone(XVar.Array());
         if (XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_mastertable")] != "")
         {
             dynamic i = null, j = null, masterTablesInfoArr = XVar.Array(), masterWhere = null, mastervalue = null;
             masterWhere         = new XVar("");
             masterTablesInfoArr = XVar.Clone(pSet.getMasterTablesArr((XVar)(GlobalVars.strTableName)));
             i = new XVar(0);
             for (; i < MVCFunctions.count(masterTablesInfoArr); i++)
             {
                 if (XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_mastertable")] != masterTablesInfoArr[i]["mDataSourceTable"])
                 {
                     continue;
                 }
                 detailKeys = XVar.Clone(masterTablesInfoArr[i]["detailKeys"]);
                 j          = new XVar(0);
                 for (; j < MVCFunctions.count(detailKeys); j++)
                 {
                     mastervalue = XVar.Clone(GlobalVars.cipherer.MakeDBValue((XVar)(detailKeys[j]), (XVar)(XSession.Session[MVCFunctions.Concat(GlobalVars.strTableName, "_masterkey", j + 1)]), new XVar(""), new XVar(true)));
                     if (mastervalue == "null")
                     {
                         masterWhere = MVCFunctions.Concat(masterWhere, RunnerPage._getFieldSQL((XVar)(detailKeys[j]), (XVar)(_connection), (XVar)(pSet)), " is NULL ");
                     }
                     else
                     {
                         masterWhere = MVCFunctions.Concat(masterWhere, RunnerPage._getFieldSQLDecrypt((XVar)(detailKeys[j]), (XVar)(_connection), (XVar)(pSet), (XVar)(GlobalVars.cipherer)), "=", mastervalue);
                     }
                 }
                 break;
             }
             whereClauses.InitAndSetArrayItem(masterWhere, null);
         }
         searchClauseObj = XVar.Clone(SearchClause.getSearchObject((XVar)(GlobalVars.strTableName), new XVar(""), (XVar)(GlobalVars.strTableName), (XVar)(GlobalVars.cipherer)));
         searchClauseObj.processFiltersWhere((XVar)(_connection));
         foreach (KeyValuePair <XVar, dynamic> filteredField in searchClauseObj.filteredFields.GetEnumerator())
         {
             whereClauses.InitAndSetArrayItem(filteredField.Value["where"], null);
         }
         result     = XVar.Clone(CommonFunctions.getListOfSuggests((XVar)(allSearchFields), (XVar)(GlobalVars.strTableName), (XVar)(whereClauses), (XVar)(numberOfSuggests), (XVar)(searchOpt), (XVar)(searchFor), (XVar)(searchField), (XVar)(detailKeys)));
         returnJSON = XVar.Clone(XVar.Array());
         returnJSON.InitAndSetArrayItem(true, "success");
         returnJSON.InitAndSetArrayItem(result, "result");
         MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
         MVCFunctions.Echo(new XVar(""));
         return(MVCFunctions.GetBuferContentAndClearBufer());
     }
     catch (RunnerRedirectException ex)
     { return(Redirect(ex.Message)); }
 }
Exemple #4
0
 public XVar checkduplicates()
 {
     try
     {
         dynamic         _connection = null, data = XVar.Array(), denyChecking = null, fieldControlType = null, fieldName = null, fieldSQL = null, hasDuplicates = null, pageType = null, qResult = null, regEmailMode = null, regUsernameMode = null, returnJSON = null, sql = null, tableName = null, value = null, where = null;
         ProjectSettings pSet;
         tableName        = XVar.Clone(MVCFunctions.postvalue(new XVar("tableName")));
         pageType         = XVar.Clone(MVCFunctions.postvalue(new XVar("pageType")));
         fieldName        = XVar.Clone(MVCFunctions.postvalue(new XVar("fieldName")));
         fieldControlType = XVar.Clone(MVCFunctions.postvalue(new XVar("fieldControlType")));
         value            = XVar.Clone(MVCFunctions.postvalue(new XVar("value")));
         if (XVar.Pack(!(XVar)(CommonFunctions.checkTableName((XVar)(tableName)))))
         {
             MVCFunctions.Echo(new XVar(0));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         Assembly.GetExecutingAssembly().GetType(MVCFunctions.Concat("runnerDotNet.", MVCFunctions.Concat("", tableName, ""),
                                                                     "_Variables")).InvokeMember("Apply", BindingFlags.InvokeMethod, null, null, null);
         if ((XVar)(pageType != Constants.PAGE_REGISTER) && (XVar)((XVar)(!(XVar)(CommonFunctions.isLogged())) || (XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Search"))))))
         {
             returnJSON = XVar.Clone(new XVar("success", false, "error", MVCFunctions.Concat("Error: You have not permissions to read the ", tableName, " table's data")));
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         _connection     = XVar.Clone(GlobalVars.cman.byTable((XVar)(GlobalVars.strTableName)));
         pSet            = XVar.UnPackProjectSettings(new ProjectSettings((XVar)(GlobalVars.strTableName), (XVar)(pageType)));
         denyChecking    = XVar.Clone(pSet.allowDuplicateValues((XVar)(fieldName)));
         regEmailMode    = new XVar(false);
         regUsernameMode = new XVar(false);
         if (XVar.Pack(denyChecking))
         {
             returnJSON = XVar.Clone(new XVar("success", false, "error", "Duplicated values are allowed"));
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         GlobalVars.cipherer = XVar.Clone(new RunnerCipherer((XVar)(GlobalVars.strTableName), (XVar)(pSet)));
         if (XVar.Pack(GlobalVars.cipherer.isFieldEncrypted((XVar)(fieldName))))
         {
             value = XVar.Clone(GlobalVars.cipherer.MakeDBValue((XVar)(fieldName), (XVar)(value), (XVar)(fieldControlType), new XVar(true)));
         }
         else
         {
             value = XVar.Clone(CommonFunctions.make_db_value((XVar)(fieldName), (XVar)(value), (XVar)(fieldControlType), new XVar(""), (XVar)(GlobalVars.strTableName)));
         }
         if (value == "null")
         {
             fieldSQL = XVar.Clone(RunnerPage._getFieldSQL((XVar)(fieldName), (XVar)(_connection), (XVar)(pSet)));
         }
         else
         {
             fieldSQL = XVar.Clone(RunnerPage._getFieldSQLDecrypt((XVar)(fieldName), (XVar)(_connection), (XVar)(pSet), (XVar)(GlobalVars.cipherer)));
         }
         where = XVar.Clone(MVCFunctions.Concat(fieldSQL, (XVar.Pack(value == "null") ? XVar.Pack(" is ") : XVar.Pack("=")), value));
         if (XVar.Pack(regEmailMode))
         {
             where = XVar.Clone(_connection.comparisonSQL((XVar)(fieldSQL), (XVar)(value), new XVar(true)));
         }
         if (XVar.Pack(regUsernameMode))
         {
             where = XVar.Clone(_connection.comparisonSQL((XVar)(fieldSQL), (XVar)(value), (XVar)(pSet.isCaseInsensitiveUsername())));
         }
         sql     = XVar.Clone(MVCFunctions.Concat("SELECT count(*) from ", _connection.addTableWrappers((XVar)(pSet.getOriginalTableName())), " where ", where));
         qResult = XVar.Clone(_connection.query((XVar)(sql)));
         if ((XVar)(!(XVar)(qResult)) || (XVar)(!(XVar)(data = XVar.Clone(qResult.fetchNumeric()))))
         {
             returnJSON = XVar.Clone(new XVar("success", false, "error", "Error: Wrong SQL query"));
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         hasDuplicates = XVar.Clone((XVar.Pack(data[0]) ? XVar.Pack(true) : XVar.Pack(false)));
         returnJSON    = XVar.Clone(new XVar("success", true, "hasDuplicates", hasDuplicates, "error", ""));
         MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(returnJSON)));
         return(MVCFunctions.GetBuferContentAndClearBufer());
     }
     catch (RunnerRedirectException ex)
     { return(Redirect(ex.Message)); }
 }