/// <summary>
    /// Returns where condition for uniselector. Respects settings of global departments.
    /// </summary>
    public string GetWhereCondition()
    {
        string where = "";
        // Add global items when editing global discount level or site allows global departments
        if ((editedSiteId == 0) || ECommerceSettings.AllowGlobalDepartments(SiteInfoProvider.GetSiteName(editedSiteId)))
        {
            where = SqlHelperClass.AddWhereCondition(where, "DepartmentSiteID IS NULL", "OR");
        }
        // Add site specific items, when editing site specific discount level
        if (editedSiteId > 0)
        {
            where = SqlHelperClass.AddWhereCondition(where, "DepartmentSiteID = " + editedSiteId, "OR");
        }

        // Add items which have to be on the list
        string valuesList = SqlHelperClass.GetSafeQueryString(mCurrentValues, false).Replace(';', ',');

        if (!string.IsNullOrEmpty(valuesList))
        {
            where = SqlHelperClass.AddWhereCondition(where, " DepartmentID IN (" + valuesList + ")", "OR");
        }

        return(where);
    }
Exemplo n.º 2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check the license
        LicenseHelper.CheckFeatureAndRedirect(URLHelper.GetCurrentDomain(), FeatureEnum.Ecommerce);

        bool ecommerceOnSite = ResourceSiteInfoProvider.IsResourceOnSite("CMS.Ecommerce", CMSContext.CurrentSiteName);

        // Check 'ConfigurationRead' permission
        if (!ecommerceOnSite || !CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Ecommerce", "ConfigurationRead"))
        {
            RedirectToAccessDenied("CMS.Ecommerce", "ConfigurationRead");
        }

        // Check 'ConfigurationModify' permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.Ecommerce", "ConfigurationModify"))
        {
            this.uniSelector.Enabled = false;
        }

        userId = QueryHelper.GetInteger("userid", 0);

        // Show contentplaceholder where site selector can be shown
        this.CurrentMaster.DisplaySiteSelectorPanel = true;

        if ((SiteID > 0) && !CMSContext.CurrentUser.IsGlobalAdministrator)
        {
            this.plcSites.Visible = false;
            this.CurrentMaster.DisplaySiteSelectorPanel = false;
        }

        if (userId > 0)
        {
            // Check that only global administrator can edit global administrator's accouns
            UserInfo ui = UserInfoProvider.GetUserInfo(userId);
            EditedObject = ui;

            if (!CheckGlobalAdminEdit(ui))
            {
                plcTable.Visible = false;
                lblError.Text    = GetString("Administration-User_List.ErrorGlobalAdmin");
                lblError.Visible = true;
                return;
            }

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

            // Global departments only for global admin
            if (CMSContext.CurrentUser.UserSiteManagerAdmin)
            {
                siteSelector.AllowGlobal = true;
            }

            // Only sites assigned to user
            siteSelector.UserId           = userId;
            siteSelector.OnlyRunningSites = false;
            siteSelector.UniSelector.OnSelectionChanged += new EventHandler(UniSelector_OnSelectionChanged);

            if (!RequestHelper.IsPostBack())
            {
                siteId = CMSContext.CurrentSiteID;

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

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

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

            DataSet ds = DepartmentInfoProvider.GetUserDepartments(userId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                currentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "DepartmentID"));
            }

            // If not postback or site selection changed
            if (!RequestHelper.IsPostBack() || (siteId != Convert.ToInt32(ViewState["departmentsOldSiteId"])))
            {
                // Set values
                uniSelector.Value = currentValues;
            }

            // Store selected site id
            ViewState["departmentsOldSiteId"] = siteId;
        }
        uniSelector.ButtonAddItems.Text = GetString("general.ok");
        uniSelector.IconPath            = GetImageUrl("Objects/Ecommerce_Department/object.png");
        uniSelector.OnSelectionChanged += usSites_OnSelectionChanged;

        uniSelector.WhereCondition = (siteId <= 0) ? " DepartmentSiteID IS NULL " : " DepartmentSiteID =" + siteId;
        if (siteId > 0)
        {
            string siteName = SiteInfoProvider.GetSiteName(siteId);
            if (ECommerceSettings.AllowGlobalDepartments(siteName))
            {
                uniSelector.WhereCondition += " OR (DepartmentSiteID IS NULL)";
            }
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // Check the license
        LicenseHelper.CheckFeatureAndRedirect(RequestContext.CurrentDomain, FeatureEnum.Ecommerce);

        bool ecommerceOnSite = ResourceSiteInfoProvider.IsResourceOnSite(ModuleName.ECOMMERCE, SiteContext.CurrentSiteName);

        // Check 'ConfigurationRead' permission
        if (!ecommerceOnSite || !MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ModuleName.ECOMMERCE, EcommercePermissions.CONFIGURATION_READ))
        {
            RedirectToAccessDenied(ModuleName.ECOMMERCE, EcommercePermissions.CONFIGURATION_READ);
        }

        // Check 'ConfigurationModify' permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource(ModuleName.ECOMMERCE, EcommercePermissions.CONFIGURATION_MODIFY))
        {
            uniSelector.Enabled = false;
        }

        userId = QueryHelper.GetInteger("userid", 0);

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

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

        if (userId > 0)
        {
            // Check that only global administrator can edit global administrator's accouns
            UserInfo ui = UserInfoProvider.GetUserInfo(userId);
            EditedObject = ui;

            if (!CheckGlobalAdminEdit(ui))
            {
                plcTable.Visible = false;
                // Show error message
                ShowError(GetString("Administration-User_List.ErrorGlobalAdmin"));

                return;
            }

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

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

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

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

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

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

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

            DataSet ds = DepartmentInfoProvider.GetUserDepartments(userId);
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                currentValues = TextHelper.Join(";", DataHelper.GetStringValues(ds.Tables[0], "DepartmentID"));
            }

            // If not postback or site selection changed
            if (!RequestHelper.IsPostBack() || (siteId != Convert.ToInt32(ViewState["departmentsOldSiteId"])))
            {
                // Set values
                uniSelector.Value = currentValues;
            }

            // Store selected site id
            ViewState["departmentsOldSiteId"] = siteId;
        }
        uniSelector.ButtonAddItems.Text = GetString("general.ok");
        uniSelector.OnSelectionChanged += usSites_OnSelectionChanged;

        uniSelector.WhereCondition = (siteId <= 0) ? " DepartmentSiteID IS NULL " : " DepartmentSiteID =" + siteId;
        if (siteId > 0)
        {
            if (ECommerceSettings.AllowGlobalDepartments(siteId))
            {
                uniSelector.WhereCondition += " OR (DepartmentSiteID IS NULL)";
            }
        }
    }