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.Community; using CMS.GlobalHelper; using CMS.Polls; using CMS.PortalControls; using CMS.WebAnalytics; public partial class CMSWebParts_Community_Polls_GroupPoll : CMSAbstractWebPart { #region "Properties" /// /// Gets or sets the code name of the poll, which should be displayed. /// public string PollCodeName { get { return ValidationHelper.GetString(GetValue("PollCodeName"), ""); } set { SetValue("PollCodeName", value); } } /// /// Gets or sets the community group name. /// public string GroupName { get { string groupName = ValidationHelper.GetString(GetValue("GroupName"), ""); if ((string.IsNullOrEmpty(groupName) || groupName == GroupInfoProvider.CURRENT_GROUP) && (CommunityContext.CurrentGroup != null)) { return CommunityContext.CurrentGroup.GroupName; } return groupName; } set { SetValue("GroupName", value); } } /// /// Gets or sets the value that indicates whether the graph of the poll is displayed. /// public bool ShowGraph { get { return ValidationHelper.GetBoolean(GetValue("ShowGraph"), viewPoll.ShowGraph); } set { SetValue("ShowGraph", value); } } /// /// Gets or sets the type of the representation of the answers’ count in the graph. /// public CountTypeEnum CountType { get { int countTypeInt = ValidationHelper.GetInteger(GetValue("CountType"), 0); if (countTypeInt == 1) { return CountTypeEnum.Absolute; } else if (countTypeInt == 2) { return CountTypeEnum.Percentage; } else { return CountTypeEnum.None; } } set { if (value == CountTypeEnum.Absolute) { SetValue("CountType", 1); } else if (value == CountTypeEnum.Percentage) { SetValue("CountType", 2); } else { SetValue("CountType", 0); } } } /// /// Gets or sets the value that indicates whether the graph is displayed after answering the poll. /// public bool ShowResultsAfterVote { get { return ValidationHelper.GetBoolean(GetValue("ShowResultsAfterVote"), viewPoll.ShowResultsAfterVote); } set { SetValue("ShowResultsAfterVote", value); } } /// /// Gets or sets the value that indicates whether check if current user has voted. /// public bool CheckVoted { get { return ValidationHelper.GetBoolean(GetValue("CheckVoted"), viewPoll.CheckVoted); } set { SetValue("CheckVoted", value); } } /// /// Gets or sets the value that indicates whether the permissions are checked. /// public bool CheckPermissions { get { return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), viewPoll.CheckPermissions); } set { SetValue("CheckPermissions", value); viewPoll.CheckPermissions = value; } } /// /// Gets or sets the value that indicates whether the control hides when not authorized, /// otherwise the control displays the message and does not allow to vote. /// public bool HideWhenNotAuthorized { get { return ValidationHelper.GetBoolean(GetValue("HideWhenNotAuthorized"), viewPoll.HideWhenNotAuthorized); } set { SetValue("HideWhenNotAuthorized", value); } } /// /// Gets or sets the value that indicates whether the control hides when not opened, /// otherwise the control does not allow to vote. /// public bool HideWhenNotOpened { get { return ValidationHelper.GetBoolean(GetValue("HideWhenNotOpened"), viewPoll.HideWhenNotOpened); } set { SetValue("HideWhenNotOpened", value); } } /// /// Gets or sets the text of the vote button. /// public string ButtonText { get { return DataHelper.GetNotEmpty(GetValue("ButtonText"), viewPoll.ButtonText); } set { SetValue("ButtonText", value); } } /// /// Gets or sets the conversion track name used after successful registration. /// public string TrackConversionName { get { return ValidationHelper.GetString(GetValue("TrackConversionName"), ""); } set { if (value.Length > 400) { value = value.Substring(0, 400); } SetValue("TrackConversionName", value); } } /// /// Gets or sets the conversion value used after successful registration. /// public double ConversionValue { get { return ValidationHelper.GetDoubleSystem(GetValue("ConversionValue"), 0); } set { SetValue("ConversionValue", value); } } #endregion /// /// Content loaded event handler. /// public override void OnContentLoaded() { base.OnContentLoaded(); SetupControl(); } /// /// Initializes the control properties. /// protected void SetupControl() { if (StopProcessing) { // Do nothing viewPoll.Visible = false; } else { GroupInfo gi = GroupInfoProvider.GetGroupInfo(GroupName, CMSContext.CurrentSiteName); if (gi != null) { viewPoll.ControlContext = ControlContext; viewPoll.PollCodeName = PollCodeName; viewPoll.CheckPermissions = CheckPermissions; viewPoll.CheckVoted = CheckVoted; viewPoll.CountType = CountType; viewPoll.CacheMinutes = CacheMinutes; viewPoll.HideWhenNotAuthorized = HideWhenNotAuthorized; viewPoll.ShowGraph = ShowGraph; viewPoll.ShowResultsAfterVote = ShowResultsAfterVote; viewPoll.HideWhenNotOpened = HideWhenNotOpened; viewPoll.ButtonText = ButtonText; viewPoll.OnAfterVoted += viewPoll_OnAfterVoted; viewPoll.PollSiteID = CMSContext.CurrentSiteID; viewPoll.PollGroupID = gi.GroupID; } else { viewPoll.Visible = false; } } } /// /// After voted event. /// private void viewPoll_OnAfterVoted(object sender, EventArgs e) { // Log track conversion if (!String.IsNullOrEmpty(TrackConversionName)) { string siteName = CMSContext.CurrentSiteName; if (AnalyticsHelper.AnalyticsEnabled(siteName) && AnalyticsHelper.TrackConversionsEnabled(siteName) && !AnalyticsHelper.IsIPExcluded(siteName, HTTPHelper.UserHostAddress)) { HitLogProvider.LogConversions(siteName, CMSContext.PreferredCultureCode, TrackConversionName, 0, ConversionValue); } } } /// /// OnPrerender override (Set visibility). /// protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Visible = viewPoll.Visible; } /// /// Reloads the control data. /// public override void ReloadData() { base.ReloadData(); SetupControl(); viewPoll.ReloadData(true); } }