예제 #1
0
        protected virtual XVar getDbFieldName(dynamic _param_fName)
        {
            #region pass-by-value parameters
            dynamic fName = XVar.Clone(_param_fName);
            #endregion

            return(RunnerPage._getFieldSQLDecrypt((XVar)(fName), (XVar)(this.connection), (XVar)(this.pSet), (XVar)(this.cipherer)));
        }
예제 #2
0
        protected virtual XVar getMultiselectLookupResolvingSQL(dynamic _param_value, dynamic _param_in, dynamic _param_withoutWhere = null)
        {
            #region default values
            if (_param_withoutWhere as Object == null)
            {
                _param_withoutWhere = new XVar(false);
            }
            #endregion

            #region pass-by-value parameters
            dynamic value        = XVar.Clone(_param_value);
            dynamic var_in       = XVar.Clone(_param_in);
            dynamic withoutWhere = XVar.Clone(_param_withoutWhere);
            #endregion

            dynamic LookupSQL = null, where = null;
            if (XVar.Pack(!(XVar)(this.pSet.multiSelect((XVar)(this.field)))))
            {
                return("");
            }
            where = XVar.Clone(CommonFunctions.prepareLookupWhere((XVar)(this.field), (XVar)(this.pSet)));
            if (this.nLookupType == Constants.LT_QUERY)
            {
                dynamic inWhere = null;
                inWhere = XVar.Clone(MVCFunctions.Concat(RunnerPage._getFieldSQLDecrypt((XVar)(this.linkFieldName), (XVar)(this.lookupConnection), (XVar)(this.lookupPSet), (XVar)(this.cipherer)), " in (", var_in, ")"));
                if ((XVar)(!(XVar)(withoutWhere)) && (XVar)(MVCFunctions.strlen((XVar)(where))))
                {
                    inWhere = MVCFunctions.Concat(inWhere, " and (", where, ")");
                }
                LookupSQL = XVar.Clone(this.lookupQueryObj.buildSQL_default((XVar)(inWhere)));
            }
            else
            {
                LookupSQL = XVar.Clone(MVCFunctions.Concat(this.LookupSQL, this.lookupConnection.addFieldWrappers((XVar)(this.pSet.getLinkField((XVar)(this.field)))), " in (", var_in, ")"));
                if ((XVar)(!(XVar)(withoutWhere)) && (XVar)(MVCFunctions.strlen((XVar)(where))))
                {
                    LookupSQL = MVCFunctions.Concat(LookupSQL, " and (", where, ")");
                }
            }
            return(LookupSQL);
        }
예제 #3
0
 public virtual XVar getFieldSQLDecrypt()
 {
     return(RunnerPage._getFieldSQLDecrypt((XVar)(this.field), (XVar)(this.connection), (XVar)(this.pageObject.pSetEdit), (XVar)(this.pageObject.cipherer)));
 }
예제 #4
0
 public XVar lookupsuggest()
 {
     try
     {
         dynamic LookupSQL = null, LookupSQLTable = null, LookupType = null, contextParams = XVar.Array(), data = XVar.Array(), displayFieldIndex = null, displayFieldName = null, field = null, isExistParent = null, likeConditionField = null, likeField = null, likeWheres = XVar.Array(), linkAndDisplaySame = null, linkFieldIndex = null, linkFieldName = null, lookupCipherer = null, lookupConnection = null, lookupField = null, lookupIndices = XVar.Array(), lookupOrderBy = null, lookupPSet = null, lookupQueryObj = null, lookupTable = null, lwDisplayField = null, masterTable = null, pageType = null, parentCtrlsData = XVar.Array(), qResult = null, respObj = null, searchByLinkField = null, strLookupWhere = null, strUniqueOrderBy = null, table = null, value = null, values = XVar.Array(), var_response = XVar.Array();
         MVCFunctions.Header("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");
         table = XVar.Clone(MVCFunctions.postvalue(new 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);
         pageType = XVar.Clone(MVCFunctions.postvalue(new XVar("pageType")));
         GlobalVars.strTableName = XVar.Clone(CommonFunctions.GetTableByShort((XVar)(table)));
         GlobalVars.cipherer     = XVar.Clone(new RunnerCipherer((XVar)(GlobalVars.strTableName)));
         GlobalVars.gSettings    = XVar.Clone(new ProjectSettings((XVar)(GlobalVars.strTableName), (XVar)(pageType)));
         field = XVar.Clone(MVCFunctions.postvalue(new XVar("searchField")));
         if (GlobalVars.gSettings.getEntityType() == Constants.titDASHBOARD)
         {
             dynamic dashFields = XVar.Array();
             dashFields = XVar.Clone(GlobalVars.gSettings.getDashboardSearchFields());
             table      = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(dashFields[field][0]["table"])));
             GlobalVars.strTableName = XVar.Clone(CommonFunctions.GetTableByShort((XVar)(table)));
             field = XVar.Clone(MVCFunctions.GoodFieldName((XVar)(dashFields[field][0]["field"])));
             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);
             GlobalVars.cipherer  = XVar.Clone(new RunnerCipherer((XVar)(GlobalVars.strTableName)));
             GlobalVars.gSettings = XVar.Clone(new ProjectSettings((XVar)(GlobalVars.strTableName), (XVar)(pageType)));
         }
         masterTable = XVar.Clone(MVCFunctions.postvalue(new XVar("masterTable")));
         if ((XVar)(masterTable != XVar.Pack("")) && (XVar)(XSession.Session.KeyExists(MVCFunctions.Concat(masterTable, "_masterRecordData"))))
         {
             contextParams.InitAndSetArrayItem(XSession.Session[MVCFunctions.Concat(masterTable, "_masterRecordData")], "masterData");
         }
         contextParams.InitAndSetArrayItem(MVCFunctions.my_json_decode((XVar)(MVCFunctions.postvalue(new XVar("data")))), "data");
         RunnerContext.push((XVar)(new RunnerContextItem((XVar)(pageType), (XVar)(contextParams))));
         if (GlobalVars.strTableName != "dbo._ABCSecurity")
         {
             if (XVar.Pack(!(XVar)(CommonFunctions.isLogged())))
             {
                 return(MVCFunctions.GetBuferContentAndClearBufer());
             }
             if ((XVar)((XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Edit")))) && (XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Add"))))) && (XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Search")))))
             {
                 return(MVCFunctions.GetBuferContentAndClearBufer());
             }
         }
         else
         {
             dynamic checkResult = null;
             checkResult = new XVar(true);
             if (field == "username")
             {
                 checkResult = new XVar(false);
             }
             if (field == "password")
             {
                 checkResult = new XVar(false);
             }
             if (XVar.Pack(checkResult))
             {
                 if (XVar.Pack(!(XVar)(CommonFunctions.isLogged())))
                 {
                     return(MVCFunctions.GetBuferContentAndClearBufer());
                 }
                 if ((XVar)((XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Edit")))) && (XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Add"))))) && (XVar)(!(XVar)(CommonFunctions.CheckSecurity((XVar)(XSession.Session[MVCFunctions.Concat("_", GlobalVars.strTableName, "_OwnerID")]), new XVar("Search")))))
                 {
                     return(MVCFunctions.GetBuferContentAndClearBufer());
                 }
             }
         }
         isExistParent     = XVar.Clone(MVCFunctions.postvalue(new XVar("isExistParent")));
         searchByLinkField = XVar.Clone(MVCFunctions.postvalue(new XVar("searchByLinkField")));
         parentCtrlsData   = XVar.Clone(MVCFunctions.my_json_decode((XVar)(MVCFunctions.postvalue(new XVar("parentCtrlsData")))));
         value             = XVar.Clone(MVCFunctions.postvalue(new XVar("searchFor")));
         values            = XVar.Clone((XVar.Pack(MVCFunctions.postvalue(new XVar("multiselection"))) ? XVar.Pack(CommonFunctions.splitvalues((XVar)(value))) : XVar.Pack(new XVar(0, value))));
         lookupField       = new XVar("");
         foreach (KeyValuePair <XVar, dynamic> f in GlobalVars.gSettings.getFieldsList().GetEnumerator())
         {
             if ((XVar)(MVCFunctions.GoodFieldName((XVar)(f.Value)) == field) && (XVar)(GlobalVars.gSettings.getEditFormat((XVar)(f.Value)) == Constants.EDIT_FORMAT_LOOKUP_WIZARD))
             {
                 LookupType = XVar.Clone(GlobalVars.gSettings.getLookupType((XVar)(f.Value)));
                 if ((XVar)(LookupType == Constants.LT_LOOKUPTABLE) || (XVar)(LookupType == Constants.LT_QUERY))
                 {
                     lookupField = XVar.Clone(f.Value);
                     break;
                 }
             }
         }
         if (XVar.Pack(!(XVar)(lookupField)))
         {
             respObj = XVar.Clone(new XVar("success", false, "data", XVar.Array()));
             MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(respObj)));
             MVCFunctions.Echo(new XVar(""));
             return(MVCFunctions.GetBuferContentAndClearBufer());
         }
         lookupTable        = XVar.Clone(GlobalVars.gSettings.getLookupTable((XVar)(lookupField)));
         linkFieldName      = XVar.Clone(GlobalVars.gSettings.getLinkField((XVar)(lookupField)));
         displayFieldName   = XVar.Clone(GlobalVars.gSettings.getDisplayField((XVar)(lookupField)));
         linkAndDisplaySame = XVar.Clone(displayFieldName == linkFieldName);
         if (LookupType == Constants.LT_QUERY)
         {
             lookupConnection = XVar.Clone(GlobalVars.cman.byTable((XVar)(lookupTable)));
         }
         else
         {
             dynamic connId = null;
             connId           = XVar.Clone(GlobalVars.gSettings.getNotProjectLookupTableConnId((XVar)(lookupField)));
             lookupConnection = XVar.Clone((XVar.Pack(MVCFunctions.strlen((XVar)(connId))) ? XVar.Pack(GlobalVars.cman.byId((XVar)(connId))) : XVar.Pack(GlobalVars.cman.getDefault())));
         }
         lookupOrderBy = XVar.Clone(GlobalVars.gSettings.getLookupOrderBy((XVar)(lookupField)));
         if (lookupConnection.dbType == Constants.nDATABASE_MSSQLServer)
         {
             strUniqueOrderBy = XVar.Clone(lookupOrderBy);
         }
         if (LookupType == Constants.LT_QUERY)
         {
             lookupPSet     = XVar.Clone(new ProjectSettings((XVar)(lookupTable), (XVar)(pageType)));
             lookupCipherer = XVar.Clone(new RunnerCipherer((XVar)(lookupTable)));
             lookupQueryObj = XVar.Clone(lookupPSet.getSQLQuery());
             if (XVar.Pack(GlobalVars.gSettings.getCustomDisplay((XVar)(lookupField))))
             {
                 lookupQueryObj.AddCustomExpression((XVar)(displayFieldName), (XVar)(lookupPSet), (XVar)(GlobalVars.strTableName), (XVar)(lookupField));
             }
             lookupQueryObj.ReplaceFieldsWithDummies((XVar)(lookupPSet.getBinaryFieldsIndices()));
         }
         else
         {
             dynamic lwLinkField = null;
             LookupSQLTable = new XVar("SELECT ");
             lwLinkField    = XVar.Clone(lookupConnection.addFieldWrappers((XVar)(GlobalVars.gSettings.getLinkField((XVar)(lookupField)))));
             if (XVar.Pack(GlobalVars.gSettings.isLookupUnique((XVar)(lookupField))))
             {
                 LookupSQLTable = MVCFunctions.Concat(LookupSQLTable, "DISTINCT ");
             }
             LookupSQLTable = MVCFunctions.Concat(LookupSQLTable, GlobalVars.cipherer.GetLookupFieldName((XVar)(lwLinkField), (XVar)(lookupField), new XVar(null), new XVar(true)));
             if (lookupConnection.dbType == Constants.nDATABASE_MSSQLServer)
             {
                 if ((XVar)(strUniqueOrderBy) && (XVar)(GlobalVars.gSettings.isLookupUnique((XVar)(lookupField))))
                 {
                     LookupSQLTable = MVCFunctions.Concat(LookupSQLTable, ",", lookupConnection.addFieldWrappers((XVar)(strUniqueOrderBy)));
                 }
             }
             lwDisplayField = XVar.Clone(RunnerPage.sqlFormattedDisplayField((XVar)(lookupField), (XVar)(lookupConnection), (XVar)(GlobalVars.gSettings)));
             if (XVar.Pack(!(XVar)(linkAndDisplaySame)))
             {
                 LookupSQLTable = MVCFunctions.Concat(LookupSQLTable, ",", (XVar.Pack(lwDisplayField == lwLinkField) ? XVar.Pack(GlobalVars.cipherer.GetFieldName((XVar)(lwDisplayField), (XVar)(lookupField), new XVar(true))) : XVar.Pack(lwDisplayField)));
             }
             LookupSQLTable = MVCFunctions.Concat(LookupSQLTable, " FROM ", lookupConnection.addTableWrappers((XVar)(lookupTable)), " ");
         }
         strLookupWhere = XVar.Clone(CommonFunctions.prepareLookupWhere((XVar)(lookupField), (XVar)(GlobalVars.gSettings)));
         if (LookupType == Constants.LT_QUERY)
         {
             dynamic secOpt = null;
             secOpt = XVar.Clone(lookupPSet.getAdvancedSecurityType());
             if (secOpt == Constants.ADVSECURITY_VIEW_OWN)
             {
                 strLookupWhere = XVar.Clone(CommonFunctions.whereAdd((XVar)(strLookupWhere), (XVar)(CommonFunctions.SecuritySQL(new XVar("Search"), (XVar)(lookupTable)))));
             }
         }
         if (XVar.Pack(strLookupWhere))
         {
             strLookupWhere = XVar.Clone(MVCFunctions.Concat(" (", strLookupWhere, ")  AND "));
         }
         if (LookupType == Constants.LT_QUERY)
         {
             if (XVar.Pack(GlobalVars.gSettings.getCustomDisplay((XVar)(lookupField))))
             {
                 likeField = XVar.Clone((XVar.Pack(searchByLinkField) ? XVar.Pack(linkFieldName) : XVar.Pack(displayFieldName)));
             }
             else
             {
                 likeField = XVar.Clone(RunnerPage._getFieldSQLDecrypt((XVar)((XVar.Pack(searchByLinkField) ? XVar.Pack(linkFieldName) : XVar.Pack(displayFieldName))), (XVar)(lookupConnection), (XVar)(lookupPSet), (XVar)(GlobalVars.cipherer)));
             }
         }
         else
         {
             likeField = XVar.Clone(GlobalVars.cipherer.GetFieldName((XVar)(lwDisplayField), (XVar)(lookupField)));
         }
         if (XVar.Pack(searchByLinkField))
         {
             likeConditionField = XVar.Clone((XVar.Pack(LookupType == Constants.LT_QUERY) ? XVar.Pack(linkFieldName) : XVar.Pack(lookupField)));
         }
         else
         {
             likeConditionField = XVar.Clone((XVar.Pack(LookupType == Constants.LT_QUERY) ? XVar.Pack(displayFieldName) : XVar.Pack(lookupField)));
         }
         likeWheres = XVar.Clone(XVar.Array());
         foreach (KeyValuePair <XVar, dynamic> fieldValue in values.GetEnumerator())
         {
             if (LookupType == Constants.LT_QUERY)
             {
                 likeWheres.InitAndSetArrayItem(MVCFunctions.Concat(likeField, lookupCipherer.GetLikeClause((XVar)(likeConditionField), (XVar)(fieldValue.Value))), null);
             }
             else
             {
                 likeWheres.InitAndSetArrayItem(MVCFunctions.Concat(likeField, GlobalVars.cipherer.GetLikeClause((XVar)(likeConditionField), (XVar)(fieldValue.Value))), null);
             }
         }
         strLookupWhere = MVCFunctions.Concat(strLookupWhere, MVCFunctions.implode(new XVar(" OR "), (XVar)(likeWheres)));
         if ((XVar)(isExistParent) && (XVar)(GlobalVars.gSettings.useCategory((XVar)(lookupField))))
         {
             dynamic parentWhereParts = XVar.Array();
             parentWhereParts = XVar.Clone(XVar.Array());
             foreach (KeyValuePair <XVar, dynamic> cData in GlobalVars.gSettings.getParentFieldsData((XVar)(lookupField)).GetEnumerator())
             {
                 dynamic arLookupWhere = XVar.Array(), category = null, lookupCategory = XVar.Array();
                 arLookupWhere  = XVar.Clone(XVar.Array());
                 category       = XVar.Clone(parentCtrlsData[cData.Value["main"]]);
                 lookupCategory = XVar.Clone((XVar.Pack(category == XVar.Pack("")) ? XVar.Pack(XVar.Array()) : XVar.Pack(CommonFunctions.splitvalues((XVar)(category)))));
                 foreach (KeyValuePair <XVar, dynamic> arLookupCategory in lookupCategory.GetEnumerator())
                 {
                     dynamic catField = null, cvalue = null;
                     cvalue = XVar.Clone(CommonFunctions.make_db_value((XVar)(cData.Value["main"]), (XVar)(arLookupCategory.Value)));
                     if (XVar.Pack(lookupPSet))
                     {
                         catField = XVar.Clone(RunnerPage._getFieldSQLDecrypt((XVar)(cData.Value["lookup"]), (XVar)(lookupConnection), (XVar)(lookupPSet), (XVar)(GlobalVars.cipherer)));
                     }
                     else
                     {
                         catField = XVar.Clone(lookupConnection.addFieldWrappers((XVar)(cData.Value["lookup"])));
                     }
                     arLookupWhere.InitAndSetArrayItem(MVCFunctions.Concat(catField, "=", cvalue), null);
                 }
                 if (XVar.Pack(MVCFunctions.count(arLookupWhere)))
                 {
                     parentWhereParts.InitAndSetArrayItem(MVCFunctions.Concat("(", MVCFunctions.implode(new XVar(" OR "), (XVar)(arLookupWhere)), ")"), null);
                 }
             }
             if (MVCFunctions.count(parentWhereParts) == MVCFunctions.count(GlobalVars.gSettings.getParentFieldsData((XVar)(lookupField))))
             {
                 strLookupWhere = XVar.Clone(CommonFunctions.whereAdd((XVar)(strLookupWhere), (XVar)(MVCFunctions.Concat("(", MVCFunctions.implode(new XVar(" AND "), (XVar)(parentWhereParts)), ")"))));
             }
             else
             {
                 respObj = XVar.Clone(new XVar("success", false, "data", XVar.Array()));
                 MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(respObj)));
                 MVCFunctions.Echo(new XVar(""));
                 return(MVCFunctions.GetBuferContentAndClearBufer());
             }
         }
         if (XVar.Pack(MVCFunctions.strlen((XVar)(lookupOrderBy))))
         {
             lookupOrderBy = XVar.Clone(lookupConnection.addFieldWrappers((XVar)(lookupOrderBy)));
             if (XVar.Pack(GlobalVars.gSettings.isLookupDesc((XVar)(lookupField))))
             {
                 lookupOrderBy = MVCFunctions.Concat(lookupOrderBy, " DESC");
             }
         }
         if (LookupType == Constants.LT_QUERY)
         {
             LookupSQL = XVar.Clone(lookupQueryObj.buildSQL_default((XVar)(strLookupWhere)));
             if (XVar.Pack(MVCFunctions.strlen((XVar)(lookupOrderBy))))
             {
                 LookupSQL = MVCFunctions.Concat(LookupSQL, " ORDER BY ", lookupOrderBy);
             }
         }
         else
         {
             LookupSQL = XVar.Clone(MVCFunctions.Concat(LookupSQLTable, " where ", strLookupWhere));
             if ((XVar)(!(XVar)(GlobalVars.gSettings.isLookupUnique((XVar)(lookupField)))) || (XVar)(Constants.nDATABASE_Access != lookupConnection.dbType))
             {
                 if (XVar.Pack(lookupOrderBy))
                 {
                     LookupSQL = MVCFunctions.Concat(LookupSQL, " ORDER BY ", lookupOrderBy);
                 }
             }
         }
         lookupIndices     = XVar.Clone(CommonFunctions.GetLookupFieldsIndexes((XVar)(GlobalVars.gSettings), (XVar)(lookupField)));
         linkFieldIndex    = XVar.Clone(lookupIndices["linkFieldIndex"]);
         displayFieldIndex = XVar.Clone(lookupIndices["displayFieldIndex"]);
         var_response      = XVar.Clone(XVar.Array());
         qResult           = XVar.Clone(lookupConnection.query((XVar)(LookupSQL)));
         while (XVar.Pack(data = XVar.Clone(qResult.fetchNumeric())))
         {
             if ((XVar)(LookupType == Constants.LT_QUERY) && (XVar)(GlobalVars.gSettings.isLookupUnique((XVar)(lookupField))))
             {
                 dynamic uniqueArray = XVar.Array();
                 if (XVar.Pack(!(XVar)(uniqueArray as object != null)))
                 {
                     uniqueArray = XVar.Clone(XVar.Array());
                 }
                 if (XVar.Pack(MVCFunctions.in_array((XVar)(data[displayFieldIndex]), (XVar)(uniqueArray))))
                 {
                     continue;
                 }
                 uniqueArray.InitAndSetArrayItem(data[displayFieldIndex], null);
             }
             data.InitAndSetArrayItem(GlobalVars.cipherer.DecryptField((XVar)(lookupField), (XVar)(data[linkFieldIndex])), linkFieldIndex);
             if (LookupType == Constants.LT_QUERY)
             {
                 data.InitAndSetArrayItem(GlobalVars.cipherer.DecryptField((XVar)(displayFieldName), (XVar)(data[displayFieldIndex])), displayFieldIndex);
             }
             var_response.InitAndSetArrayItem(data[linkFieldIndex], null);
             var_response.InitAndSetArrayItem(data[displayFieldIndex], null);
         }
         respObj = XVar.Clone(new XVar("success", true, "data", MVCFunctions.array_slice((XVar)(var_response), new XVar(0), new XVar(40))));
         MVCFunctions.Echo(CommonFunctions.printJSON((XVar)(respObj)));
         MVCFunctions.Echo(new XVar(""));
         return(MVCFunctions.GetBuferContentAndClearBufer());
     }
     catch (RunnerRedirectException ex)
     { return(Redirect(ex.Message)); }
 }
예제 #5
0
        public virtual XVar getOrderFields()
        {
            dynamic         columns = XVar.Array(), ret = XVar.Array(), saved = XVar.Array();
            ProjectSettings pSet;

            if (!XVar.Equals(XVar.Pack(this._cachedFields), XVar.Pack(null)))
            {
                return(this._cachedFields);
            }
            ret     = XVar.Clone(XVar.Array());
            columns = XVar.Clone(XVar.Array());
            pSet    = XVar.UnPackProjectSettings(this.pSet);
            saved   = XVar.Clone(XSession.Session[MVCFunctions.Concat(this.sessionPrefix, "_orderby")]);
            if (0 != MVCFunctions.strlen((XVar)(saved["orderby"])))
            {
                dynamic fields = XVar.Array();
                fields = XVar.Clone(MVCFunctions.explode(new XVar(";"), (XVar)(saved["orderby"])));
                foreach (KeyValuePair <XVar, dynamic> f in fields.GetEnumerator())
                {
                    dynamic dir = null, fieldName = null, goodField = null, index = null;
                    dir = XVar.Clone(MVCFunctions.substr((XVar)(f.Value), new XVar(0), new XVar(1)));
                    if ((XVar)(dir != "a") && (XVar)(dir != "d"))
                    {
                        continue;
                    }
                    goodField = XVar.Clone(MVCFunctions.substr((XVar)(f.Value), new XVar(1)));
                    fieldName = XVar.Clone(pSet.getFieldByGoodFieldName((XVar)(goodField)));
                    index     = XVar.Clone(pSet.getFieldIndex((XVar)(fieldName)) + 1);
                    if (XVar.Pack(!(XVar)(index)))
                    {
                        continue;
                    }
                    ret.InitAndSetArrayItem(new XVar("column", fieldName, "index", index, "expr", RunnerPage._getFieldSQLDecrypt((XVar)(fieldName), (XVar)(this.connection), (XVar)(this.pSet), (XVar)(this.cipherer)), "dir", (XVar.Pack(dir == "a") ? XVar.Pack("ASC") : XVar.Pack("DESC"))), null);
                    columns.InitAndSetArrayItem(true, fieldName);
                }
            }
            else
            {
                if (0 != MVCFunctions.strlen((XVar)(saved["sortby"])))
                {
                    dynamic sortbySettings = XVar.Array(), var_option = XVar.Array();
                    sortbySettings = getSortBySettings();
                    var_option     = XVar.Clone(sortbySettings[saved["sortby"] - 1]);
                    if (XVar.Pack(var_option))
                    {
                        foreach (KeyValuePair <XVar, dynamic> f in var_option["fields"].GetEnumerator())
                        {
                            ret.InitAndSetArrayItem(new XVar("column", f.Value["field"], "index", pSet.getFieldIndex((XVar)(f.Value["field"])) + 1, "expr", RunnerPage._getFieldSQLDecrypt((XVar)(f.Value["field"]), (XVar)(this.connection), (XVar)(this.pSet), (XVar)(this.cipherer)), "dir", (XVar.Pack(f.Value["desc"]) ? XVar.Pack("DESC") : XVar.Pack("ASC"))), null);
                            columns.InitAndSetArrayItem(true, f.Value);
                        }
                    }
                }
                else
                {
                    dynamic orderInfo = XVar.Array();
                    orderInfo = XVar.Clone(pSet.getOrderIndexes());
                    foreach (KeyValuePair <XVar, dynamic> o in orderInfo.GetEnumerator())
                    {
                        dynamic field = null;
                        field = XVar.Clone(pSet.GetFieldByIndex((XVar)(o.Value[0])));
                        ret.InitAndSetArrayItem(new XVar("column", field, "index", o.Value[0], "expr", o.Value[2], "dir", o.Value[1]), null);
                        columns.InitAndSetArrayItem(true, field);
                    }
                }
            }
            foreach (KeyValuePair <XVar, dynamic> k in pSet.getTableKeys().GetEnumerator())
            {
                if (XVar.Pack(columns.KeyExists(k.Value)))
                {
                    continue;
                }
                ret.InitAndSetArrayItem(new XVar("column", k.Value, "index", pSet.getFieldIndex((XVar)(k.Value)) + 1, "expr", RunnerPage._getFieldSQLDecrypt((XVar)(k.Value), (XVar)(this.connection), (XVar)(this.pSet), (XVar)(this.cipherer)), "dir", "ASC", "hidden", true), null);
            }
            this._cachedFields = XVar.Clone(ret);
            return(ret);
        }
예제 #6
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)); }
 }
예제 #7
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)); }
 }
예제 #8
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)); }
 }