protected void Page_Load(object sender, EventArgs e) { poll = PollInfoProvider.GetPollInfo(ItemID); if ((ItemID > 0) && !IsLiveSite) { EditedObject = poll; } if (poll != null) { groupId = poll.PollGroupID; } // Roles control settings addRoles.PollID = ItemID; addRoles.IsLiveSite = IsLiveSite; addRoles.Changed += addRoles_Changed; addRoles.GroupID = groupId; addRoles.ShowSiteFilter = false; if (!RequestHelper.IsPostBack() && (poll != null) && !IsLiveSite) { ReloadData(); } else { if (radOnlyRoles.Checked) { addRoles.CurrentSelector.Enabled = true; int currentSiteID = 0; string roles = string.Empty; // Get current site ID using CMSContext if (SiteContext.CurrentSite != null) { currentSiteID = SiteContext.CurrentSiteID; } DataSet ds = PollInfoProvider.GetPollRoles(ItemID, null, null, -1, "CMS_Role.SiteID, CMS_Role.RoleID"); if (!DataHelper.DataSourceIsEmpty(ds)) { foreach (DataRow row in ds.Tables[0].Rows) { // Include roles associated to current site only if ((ValidationHelper.GetInteger(row["SiteID"], 0) == currentSiteID)) { // Insert an item to the listbox roles += ValidationHelper.GetString(row["RoleID"], null) + ";"; } } } addRoles.CurrentValues = roles; } else { addRoles.CurrentSelector.Enabled = false; } } }
/// <summary> /// Loads list of roles authorized for poll access into lstRoles control. /// Lists roles associated to current site. /// </summary> private void ReloadRolesList() { lstRoles.Items.Clear(); // Get allowed roles of the poll DataSet ds = PollInfoProvider.GetPollRoles(ItemID); string roles = string.Empty; if (!DataHelper.DataSourceIsEmpty(ds)) { // Get current site ID using CMSContext int currentSiteID = 0; if (SiteContext.CurrentSite != null) { currentSiteID = SiteContext.CurrentSiteID; } DataRowCollection rows = ds.Tables[0].Rows; foreach (DataRow row in rows) { RoleInfo roleInfo = new RoleInfo(row); // Include roles associated to current site only if ((roleInfo.SiteID == currentSiteID) || (roleInfo.SiteID == 0)) { string roleID = roleInfo.RoleID.ToString(); string name = roleInfo.RoleDisplayName; if (roleInfo.SiteID == 0) { name += " " + GetString("general.global"); } // Insert an item to the listbox lstRoles.Items.Add(new ListItem(name, roleID)); roles += roleID + ";"; } } } btnRemoveRole.Enabled = lstRoles.Enabled; addRoles.CurrentSelector.Enabled = lstRoles.Enabled; addRoles.CurrentSelector.Value = roles; }