using System; using System.Data; using System.Collections; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using CMS.CMSHelper; using CMS.GlobalHelper; using CMS.SiteProvider; using CMS.UIControls; public partial class CMSModules_Membership_Controls_Roles_RoleList : CMSAdminListControl { #region "Variables" private int mSiteId = 0; private int mGroupId = 0; private int mGlobalRecordValue = UniSelector.US_GLOBAL_RECORD; private bool mIsGroupList = false; #endregion #region "Public properties" /// /// Gets or sets the group ID for which the roles should be displayed (0 means all groups). /// public int GroupID { get { return mGroupId; } set { mGroupId = value; gridElem.WhereCondition = CreateWhereCondition(); } } /// /// Gets or sets global record value (value for global item selected in drop down). /// public int GlobalRecordValue { get { return mGlobalRecordValue; } set { mGlobalRecordValue = value; gridElem.WhereCondition = CreateWhereCondition(); } } /// /// Gets or sets the site ID for which the roles should be displayed. /// public int SiteID { get { return mSiteId; } set { mSiteId = value; gridElem.WhereCondition = CreateWhereCondition(); } } /// /// Gets or sets whether list is showed in group UI. /// public bool IsGroupList { get { return mIsGroupList; } set { mIsGroupList = value; } } #endregion /// /// Creates where condition for unigrid according to the parameters. /// private string CreateWhereCondition() { string where = ""; if (mSiteId > 0) { where += "(SiteID = " + mSiteId + ")"; } else // Global selected if ((mSiteId == GlobalRecordValue) && CMSContext.CurrentUser.UserSiteManagerAdmin) { where += "(SiteID IS NULL)"; } else { where += "(SiteID =" + CMSContext.CurrentSiteID + ")"; } if (!string.IsNullOrEmpty(where)) { where += " AND "; } if (mGroupId > 0 || IsGroupList) { where += "(RoleGroupID = " + mGroupId + ")"; } else { where += "(RoleGroupID IS NULL)"; } return where; } protected void Page_Load(object sender, EventArgs e) { RaiseOnCheckPermissions(PERMISSION_READ, this); if (StopProcessing) { return; } // Unigrid gridElem.IsLiveSite = IsLiveSite; gridElem.OnAction += new OnActionEventHandler(gridElem_OnAction); gridElem.WhereCondition = CreateWhereCondition(); gridElem.ZeroRowsText = GetString("general.nodatafound"); gridElem.GroupObject = (mGroupId > 0); } /// /// Handles the UniGrid's OnAction event. /// /// Name of item (button) that throws event /// ID (value of Primary key) of corresponding data row protected void gridElem_OnAction(string actionName, object actionArgument) { if (actionName == "edit") { SelectedItemID = Convert.ToInt32(actionArgument); RaiseOnEdit(); } else if (actionName == "delete") { if (!CheckPermissions("CMS.Roles", PERMISSION_MODIFY)) { return; } RoleInfoProvider.DeleteRoleInfo(ValidationHelper.GetInteger(actionArgument, 0)); } RaiseOnAction(actionName, actionArgument); } }