Exemplo n.º 1
0
    /// <summary>
    /// Returns where condition filtering ShippingAddress, Country and State.
    /// </summary>
    private void AddCountryWhereCondition(WhereCondition where)
    {
        var addressWhere = new IDQuery <AddressInfo>();

        string[] split = ShippingCountry.Split(';');

        if ((split.Length >= 1) && (split.Length <= 2))
        {
            // Country filter
            var country = CountryInfoProvider.GetCountryInfo(split[0]);
            if (country != null)
            {
                addressWhere.WhereEquals("AddressCountryID", country.CountryID);

                if (split.Length == 2)
                {
                    // State filter
                    var state = StateInfoProvider.GetStateInfo(split[1]);
                    if (state != null)
                    {
                        addressWhere.WhereEquals("AddressStateID", state.StateID);
                    }
                }
            }
        }

        where.WhereIn("OrderShippingAddressID", addressWhere);
    }
    /// <summary>
    /// Get where condition for unigrid
    /// </summary>
    /// <returns>Where condition</returns>
    private WhereCondition GetWhereCondition()
    {
        string productNameFilter = txtProductName.Text;

        // To display ONLY product - not product options
        var where = new WhereCondition().WhereTrue("SKUEnabled").And().WhereNull("SKUOptionCategoryID");

        if (!string.IsNullOrEmpty(productNameFilter))
        {
            // Alias for COM_SKU
            var variants = new QuerySourceTable("COM_SKU", "variants");

            // Get IDs of products containing filter text; search among variants too
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(variants, "COM_SKU.SKUID", "variants.SKUParentSKUID",
                                              new WhereCondition()
                                              .WhereContains("variants.SKUName", productNameFilter)
                                              .Or()
                                              .WhereContains("variants.SKUNumber", productNameFilter)))
                      .Where(
                new WhereCondition()
                .WhereContains("COM_SKU.SKUName", productNameFilter)
                .Or()
                .WhereContains("COM_SKU.SKUNumber", productNameFilter));

            // Add the condition
            where.Where(w => w.WhereIn("SKUID", ids));
        }

        where.Where(GetSiteWhereCondition(SiteContext.CurrentSiteID));

        return(where);
    }
        /// <summary>
        /// Gets number of total pages waiting for the approval.
        /// </summary>
        /// <param name="siteInfo">Site the pages belongs to</param>
        /// <param name="userInfo">The user providing the approval</param>
        /// <returns>Total number of waiting pages</returns>
        private int GetNumberOfPendingPages(SiteInfo siteInfo, UserInfo userInfo)
        {
            int siteId = siteInfo.SiteID;

            // Get correct pending steps which may current user manage
            var steps = new IDQuery<WorkflowStepInfo>().Where(WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(userInfo, siteId));

            var docs = new IDQuery<TreeNode>()
                    .OnSite(siteId)
                    .WhereIn("DocumentWorkflowStepID", steps);

            return docs.Count;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets number of total pages waiting for the approval.
        /// </summary>
        /// <param name="siteInfo">Site the pages belongs to</param>
        /// <param name="userInfo">The user providing the approval</param>
        /// <returns>Total number of waiting pages</returns>
        private int GetNumberOfPendingPages(SiteInfo siteInfo, UserInfo userInfo)
        {
            int siteId = siteInfo.SiteID;

            // Get correct pending steps which may current user manage
            var steps = new IDQuery <WorkflowStepInfo>().Where(WorkflowStepInfoProvider.GetWorkflowPendingStepsWhereCondition(userInfo, siteId));

            var docs = new IDQuery <TreeNode>()
                       .OnSite(siteId)
                       .WhereIn("DocumentWorkflowStepID", steps);

            return(docs.Count);
        }
    /// <summary>
    /// Reloads the data in the selector.
    /// </summary>
    public void ReloadData()
    {
        uniSelector.IsLiveSite = IsLiveSite;
        if (!DisplayNoDataMessage)
        {
            uniSelector.ZeroRowsText = string.Empty;
        }

        // Need to set uni-selector value again after basic form reload
        if (AllowMultipleChoice)
        {
            uniSelector.Value = mMultipleChoiceValue;
        }

        var where = new WhereCondition();

        if (ProductOptionCategoryID > 0)
        {
            where.WhereEquals("SKUOptionCategoryID", ProductOptionCategoryID);
        }
        else
        {
            var productSiteWhere = new WhereCondition();

            // Add global products
            if (DisplayGlobalProducts)
            {
                productSiteWhere.Where(w => w.WhereNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific products
            if (DisplaySiteProducts)
            {
                productSiteWhere.Or().Where(w => w.WhereNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Where(productSiteWhere);
        }

        // Exclude standard products if needed
        if (!DisplayStandardProducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Product.ToStringRepresentation());
        }

        // Exclude memberships if needed
        if (!DisplayMemberships)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Membership.ToStringRepresentation());
        }

        // Exclude e-products if needed
        if (!DisplayEproducts)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.EProduct.ToStringRepresentation());
        }

        // Exclude bundles if needed
        if (!DisplayBundles)
        {
            where.WhereNotEquals("SKUProductType", SKUProductTypeEnum.Bundle.ToStringRepresentation());
        }

        // Exclude products with product options if needed
        if (DisplayOnlyProductsWithoutOptions)
        {
            where.WhereNotIn("SKUID", new IDQuery <SKUOptionCategoryInfo>("SKUID"));
        }

        if (DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            var optionsSiteWhere = new WhereCondition();

            // Add global options
            if (DisplayGlobalOptions)
            {
                optionsSiteWhere.Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                       .WhereNull("SKUSiteID"));
            }

            // Add site specific options
            if (DisplaySiteOptions)
            {
                optionsSiteWhere.Or().Where(w => w.WhereNotNull("SKUOptionCategoryID")
                                            .WhereEquals("SKUSiteID", SiteID));
            }

            where.Or().Where(optionsSiteWhere);
            where = new WhereCondition().Where(where);
        }

        // Filter out only enabled items
        if (DisplayOnlyEnabled)
        {
            where.WhereTrue("SKUEnabled");
        }

        if (!DisplayProductOptions && (ProductOptionCategoryID <= 0))
        {
            where.WhereNull("SKUOptionCategoryID");
        }

        if (DisplayProductVariants)
        {
            // Alias for COM_SKU
            var parents = new QuerySourceTable("COM_SKU", "parentIDs");

            // Select IDs of all products that are not parents of variants
            var ids = new IDQuery <SKUInfo>()
                      .Columns(new QueryColumn("COM_SKU.SKUID"))
                      .Source(s => s.LeftJoin(parents, "COM_SKU.SKUID", "parentIDs.SKUParentSKUID"))
                      .Where(new WhereCondition().WhereNull("parentIDs.SKUID"));

            where.WhereIn("SKUID", ids);
        }
        else
        {
            // Do not display variants
            where.WhereNull("SKUParentSKUID");
        }

        // Add items which have to be on the list
        var additionalList = AdditionalItems.Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

        if (additionalList.Length > 0)
        {
            var ids = ValidationHelper.GetIntegers(additionalList, 0);
            where.Or().WhereIn("SKUID", ids);
        }

        // Selected value must be on the list
        if (SKUID > 0)
        {
            where.Or().WhereEquals("SKUID", SKUID);
        }

        uniSelector.WhereCondition = where.ToString(true);
    }
Exemplo n.º 6
0
 private Query ProcessFunction(Function root, out Props props)
 {
     props = Props.None;
     Query qy = null;
     switch (root.TypeOfFunction)
     {
         case FT.FuncLast:
             qy = new NodeFunctions(root.TypeOfFunction, null);
             props |= Props.HasLast;
             return qy;
         case FT.FuncPosition:
             qy = new NodeFunctions(root.TypeOfFunction, null);
             props |= Props.HasPosition;
             return qy;
         case FT.FuncCount:
             return new NodeFunctions(FT.FuncCount,
                 ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props)
             );
         case FT.FuncID:
             qy = new IDQuery(ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props));
             props |= Props.NonFlat;
             return qy;
         case FT.FuncLocalName:
         case FT.FuncNameSpaceUri:
         case FT.FuncName:
             if (root.ArgumentList != null && root.ArgumentList.Count > 0)
             {
                 return new NodeFunctions(root.TypeOfFunction,
                     ProcessNode((AstNode)(root.ArgumentList[0]), Flags.None, out props)
                 );
             }
             else
             {
                 return new NodeFunctions(root.TypeOfFunction, null);
             }
         case FT.FuncString:
         case FT.FuncConcat:
         case FT.FuncStartsWith:
         case FT.FuncContains:
         case FT.FuncSubstringBefore:
         case FT.FuncSubstringAfter:
         case FT.FuncSubstring:
         case FT.FuncStringLength:
         case FT.FuncNormalize:
         case FT.FuncTranslate:
             return new StringFunctions(root.TypeOfFunction, ProcessArguments(root.ArgumentList, out props));
         case FT.FuncNumber:
         case FT.FuncSum:
         case FT.FuncFloor:
         case FT.FuncCeiling:
         case FT.FuncRound:
             if (root.ArgumentList != null && root.ArgumentList.Count > 0)
             {
                 return new NumberFunctions(root.TypeOfFunction,
                     ProcessNode((AstNode)root.ArgumentList[0], Flags.None, out props)
                 );
             }
             else
             {
                 return new NumberFunctions(Function.FunctionType.FuncNumber, null);
             }
         case FT.FuncTrue:
         case FT.FuncFalse:
             return new BooleanFunctions(root.TypeOfFunction, null);
         case FT.FuncNot:
         case FT.FuncLang:
         case FT.FuncBoolean:
             return new BooleanFunctions(root.TypeOfFunction,
                 ProcessNode((AstNode)root.ArgumentList[0], Flags.None, out props)
             );
         case FT.FuncUserDefined:
             _needContext = true;
             if (!_allowCurrent && root.Name == "current" && root.Prefix.Length == 0)
             {
                 throw XPathException.Create(SR.Xp_CurrentNotAllowed);
             }
             if (!_allowKey && root.Name == "key" && root.Prefix.Length == 0)
             {
                 throw XPathException.Create(SR.Xp_InvalidKeyPattern, _query);
             }
             qy = new FunctionQuery(root.Prefix, root.Name, ProcessArguments(root.ArgumentList, out props));
             props |= Props.NonFlat;
             return qy;
         default:
             throw XPathException.Create(SR.Xp_NotSupported, _query);
     }
 }
Exemplo n.º 7
0
    /// <summary>
    /// Page_load event.
    /// </summary>
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check permissions and UI elements
        var user = MembershipContext.AuthenticatedUser;

        if (user != null)
        {
            if (!user.IsAuthorizedPerUIElement("CMS.Users", "CmsDesk.Roles"))
            {
                RedirectToUIElementAccessDenied("CMS.Users", "CmsDesk.Roles");
            }

            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Roles", "Read"))
            {
                RedirectToAccessDenied("CMS.Roles", "Read");
            }
        }

        ScriptHelper.RegisterJQuery(Page);

        // Get user id and site Id from query
        mUserId = QueryHelper.GetInteger("userid", 0);

        // Show content placeholder where site selector can be shown
        CurrentMaster.DisplaySiteSelectorPanel = true;

        if ((SiteID > 0) && !MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.Admin))
        {
            plcSites.Visible = false;
            CurrentMaster.DisplaySiteSelectorPanel = false;
        }

        if (mUserId > 0)
        {
            // Check that only global administrator can edit global administrator's accounts
            mUserInfo = UserInfoProvider.GetUserInfo(mUserId);
            CheckUserAvaibleOnSite(mUserInfo);
            EditedObject = mUserInfo;

            if (!CheckGlobalAdminEdit(mUserInfo))
            {
                plcTable.Visible = false;
                ShowError(GetString("Administration-User_List.ErrorGlobalAdmin"));
                return;
            }

            // Set site selector
            siteSelector.DropDownSingleSelect.AutoPostBack = true;
            siteSelector.AllowAll   = false;
            siteSelector.AllowEmpty = false;

            // Global roles only for global admin
            if (MembershipContext.AuthenticatedUser.CheckPrivilegeLevel(UserPrivilegeLevelEnum.GlobalAdmin))
            {
                siteSelector.AllowGlobal = true;
            }

            // Only sites assigned to user
            siteSelector.UserId           = mUserId;
            siteSelector.OnlyRunningSites = false;
            siteSelector.UniSelector.OnSelectionChanged += UniSelector_OnSelectionChanged;

            if (!RequestHelper.IsPostBack())
            {
                mSiteId = SiteContext.CurrentSiteID;

                // If user is member of current site
                if (UserSiteInfoProvider.GetUserSiteInfo(mUserId, mSiteId) != null)
                {
                    // Force uniselector to preselect current site
                    siteSelector.Value = mSiteId;
                }

                // Force to load data
                siteSelector.Reload(true);
            }

            // Get truly selected item
            mSiteId = ValidationHelper.GetInteger(siteSelector.Value, 0);
        }

        usRoles.OnSelectionChanged += usRoles_OnSelectionChanged;
        string siteIDWhere = (mSiteId <= 0) ? " SiteID IS NULL " : " SiteID =" + mSiteId;

        usRoles.WhereCondition = siteIDWhere + " AND RoleGroupID IS NULL";

        usRoles.SelectItemPageUrl     = "~/CMSModules/Membership/Pages/Users/User_Edit_Add_Item_Dialog.aspx";
        usRoles.ListingWhereCondition = siteIDWhere + " AND RoleGroupID IS NULL AND UserID=" + mUserId;
        usRoles.ReturnColumnName      = "RoleID";
        usRoles.DynamicColumnName     = false;
        usRoles.GridName               = "User_Role_List.xml";
        usRoles.AdditionalColumns      = "ValidTo";
        usRoles.OnAdditionalDataBound += usMemberships_OnAdditionalDataBound;
        usRoles.DialogWindowHeight     = 760;

        // Exclude generic roles
        string    genericWhere = String.Empty;
        ArrayList genericRoles = RoleInfoProvider.GetGenericRoles();

        if (genericRoles.Count != 0)
        {
            foreach (string role in genericRoles)
            {
                genericWhere += "'" + SqlHelper.EscapeQuotes(role) + "',";
            }

            genericWhere            = genericWhere.TrimEnd(',');
            usRoles.WhereCondition += " AND ( RoleName NOT IN (" + genericWhere + ") )";
        }

        // Get the active roles for this site
        var roleIds = new IDQuery <RoleInfo>().Where(siteIDWhere).Column("RoleID");
        var data    = UserRoleInfoProvider.GetUserRoles().WhereEquals("UserID", mUserId).And().WhereIn("RoleID", roleIds).Columns("RoleID").TypedResult;

        if (data.Any())
        {
            mCurrentValues = TextHelper.Join(";", data.Select(i => i.RoleID));
        }

        // If not postback or site selection changed
        if (!RequestHelper.IsPostBack() || (mSiteId != Convert.ToInt32(ViewState["rolesOldSiteId"])))
        {
            // Set values
            usRoles.Value = mCurrentValues;
        }

        // Store selected site id
        ViewState["rolesOldSiteId"] = mSiteId;

        string script = "function setNewDateTime(date) {$cmsj('#" + hdnDate.ClientID + "').val(date);}";

        ScriptHelper.RegisterClientScriptBlock(Page, typeof(string), "key", ScriptHelper.GetScript(script));

        string eventTarget   = Request[postEventSourceID];
        string eventArgument = Request[postEventArgumentID];

        if (eventTarget == ucCalendar.DateTimeTextBox.UniqueID)
        {
            if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.Users", "ManageUserRoles"))
            {
                RedirectToAccessDenied("CMS.Users", "Manage user roles");
            }

            int id = ValidationHelper.GetInteger(hdnDate.Value, 0);
            if (id != 0)
            {
                DateTime     dt  = ValidationHelper.GetDateTime(eventArgument, DateTimeHelper.ZERO_TIME);
                UserRoleInfo uri = UserRoleInfoProvider.GetUserRoleInfo(mUserId, id);
                if (uri != null)
                {
                    uri.ValidTo = dt;
                    UserRoleInfoProvider.SetUserRoleInfo(uri);

                    // Invalidate user
                    UserInfoProvider.InvalidateUser(mUserId);

                    ShowChangesSaved();
                }
            }
        }
    }
Exemplo n.º 8
0
 private IDQuery(IDQuery other) : base(other) { }
 private IDQuery(IDQuery other) : base((CacheOutputQuery) other)
 {
 }
    /// <summary>
    /// Returns where condition filtering ShippingAddress, Country and State.
    /// </summary>
    private void AddCountryWhereCondition(WhereCondition where)
    {
        var addressWhere = new IDQuery<AddressInfo>();

        string[] split = ShippingCountry.Split(';');

        if ((split.Length >= 1) && (split.Length <= 2))
        {
            // Country filter
            var country = CountryInfoProvider.GetCountryInfo(split[0]);
            if (country != null)
            {
                addressWhere.WhereEquals("AddressCountryID", country.CountryID);

                if (split.Length == 2)
                {
                    // State filter
                    var state = StateInfoProvider.GetStateInfo(split[1]);
                    if (state != null)
                    {
                        addressWhere.WhereEquals("AddressStateID", state.StateID);
                    }
                }
            }
        }

        where.WhereIn("OrderShippingAddressID", addressWhere);
    }
        private Query ProcessFunction(Function root, out Props props)
        {
            props = Props.None;
            Query query = null;
            switch (root.TypeOfFunction)
            {
                case Function.FunctionType.FuncLast:
                    query = new NodeFunctions(root.TypeOfFunction, null);
                    props |= Props.HasLast;
                    return query;

                case Function.FunctionType.FuncPosition:
                    query = new NodeFunctions(root.TypeOfFunction, null);
                    props |= Props.HasPosition;
                    return query;

                case Function.FunctionType.FuncCount:
                    return new NodeFunctions(Function.FunctionType.FuncCount, this.ProcessNode((AstNode) root.ArgumentList[0], Flags.None, out props));

                case Function.FunctionType.FuncID:
                    query = new IDQuery(this.ProcessNode((AstNode) root.ArgumentList[0], Flags.None, out props));
                    props |= Props.NonFlat;
                    return query;

                case Function.FunctionType.FuncLocalName:
                case Function.FunctionType.FuncNameSpaceUri:
                case Function.FunctionType.FuncName:
                    if ((root.ArgumentList == null) || (root.ArgumentList.Count <= 0))
                    {
                        return new NodeFunctions(root.TypeOfFunction, null);
                    }
                    return new NodeFunctions(root.TypeOfFunction, this.ProcessNode((AstNode) root.ArgumentList[0], Flags.None, out props));

                case Function.FunctionType.FuncString:
                case Function.FunctionType.FuncConcat:
                case Function.FunctionType.FuncStartsWith:
                case Function.FunctionType.FuncContains:
                case Function.FunctionType.FuncSubstringBefore:
                case Function.FunctionType.FuncSubstringAfter:
                case Function.FunctionType.FuncSubstring:
                case Function.FunctionType.FuncStringLength:
                case Function.FunctionType.FuncNormalize:
                case Function.FunctionType.FuncTranslate:
                    return new StringFunctions(root.TypeOfFunction, this.ProcessArguments(root.ArgumentList, out props));

                case Function.FunctionType.FuncBoolean:
                case Function.FunctionType.FuncNot:
                case Function.FunctionType.FuncLang:
                    return new BooleanFunctions(root.TypeOfFunction, this.ProcessNode((AstNode) root.ArgumentList[0], Flags.None, out props));

                case Function.FunctionType.FuncNumber:
                case Function.FunctionType.FuncSum:
                case Function.FunctionType.FuncFloor:
                case Function.FunctionType.FuncCeiling:
                case Function.FunctionType.FuncRound:
                    if ((root.ArgumentList == null) || (root.ArgumentList.Count <= 0))
                    {
                        return new NumberFunctions(Function.FunctionType.FuncNumber, null);
                    }
                    return new NumberFunctions(root.TypeOfFunction, this.ProcessNode((AstNode) root.ArgumentList[0], Flags.None, out props));

                case Function.FunctionType.FuncTrue:
                case Function.FunctionType.FuncFalse:
                    return new BooleanFunctions(root.TypeOfFunction, null);

                case Function.FunctionType.FuncUserDefined:
                    this.needContext = true;
                    if ((!this.allowCurrent && (root.Name == "current")) && (root.Prefix.Length == 0))
                    {
                        throw XPathException.Create("Xp_CurrentNotAllowed");
                    }
                    if ((!this.allowKey && (root.Name == "key")) && (root.Prefix.Length == 0))
                    {
                        throw XPathException.Create("Xp_InvalidKeyPattern", this.query);
                    }
                    query = new FunctionQuery(root.Prefix, root.Name, this.ProcessArguments(root.ArgumentList, out props));
                    props |= Props.NonFlat;
                    return query;
            }
            throw XPathException.Create("Xp_NotSupported", this.query);
        }