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.MessageBoard;
using CMS.PortalControls;
using CMS.SettingsProvider;
public partial class CMSWebParts_Community_MessageBoards_GroupMessageBoard : CMSAbstractWebPart
{
#region "Private fields"
private string mWebPartName = "";
private BoardInfo mBoardObj = null;
private GroupInfo mCurrentGroup = null;
#endregion
#region "Private properties"
///
/// Current web part name.
///
private string BoardDisplayName
{
get
{
return ValidationHelper.GetString(GetValue("BoardDisplayName"), "");
}
set
{
SetValue("BoardDisplayName", value);
}
}
///
/// Current web part name.
///
private string WebPartName
{
get
{
if (mWebPartName == "")
{
mWebPartName = ValidationHelper.GetString(GetValue("WebPartControlID"), "");
}
return mWebPartName;
}
}
///
/// Current group from community context.
///
private GroupInfo CurrentGroup
{
get
{
if (mCurrentGroup == null)
{
mCurrentGroup = CommunityContext.CurrentGroup;
}
return mCurrentGroup;
}
}
///
/// Current message board.
///
private BoardInfo BoardObj
{
get
{
if (mBoardObj == null)
{
// Get the current group info and obtain the related board info
if (CurrentGroup != null)
{
mBoardObj = BoardInfoProvider.GetBoardInfoForGroup(CurrentGroup.GroupID, GetBoardName(WebPartName));
}
}
return mBoardObj;
}
}
#endregion
#region "Public properties"
///
/// Returns true if the control processing should be stopped.
///
public override bool StopProcessing
{
get
{
return base.StopProcessing;
}
set
{
base.StopProcessing = value;
msgBoard.StopProcessing = value;
}
}
///
/// No messages text.
///
public string NoMessagesText
{
get
{
return ValidationHelper.GetString(GetValue("NoMessagesText"), "");
}
set
{
SetValue("NoMessagesText", value);
}
}
///
/// Default board moderators.
///
public string BoardModerators
{
get
{
return ValidationHelper.GetString(GetValue("BoardModerators"), "");
}
set
{
SetValue("BoardModerators", value);
}
}
///
/// Transformation used to display board message text.
///
public string MessageTransformation
{
get
{
return ValidationHelper.GetString(GetValue("MessageTransformation"), "");
}
set
{
SetValue("MessageTransformation", value);
}
}
///
/// Indicates whether the EDIT button should be displayed.
///
public bool ShowEdit
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowEdit"), false);
}
set
{
SetValue("ShowEdit", value);
}
}
///
/// Indicates whether the DELETE button should be displayed.
///
public bool ShowDelete
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowDelete"), false);
}
set
{
SetValue("ShowDelete", value);
}
}
///
/// Indicates whether the APPROVE button should be displayed.
///
public bool ShowApprove
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowApprove"), false);
}
set
{
SetValue("ShowApprove", value);
}
}
///
/// Indicates whether the REJECT button should be displayed.
///
public bool ShowReject
{
get
{
return ValidationHelper.GetBoolean(GetValue("ShowReject"), false);
}
set
{
SetValue("ShowReject", value);
}
}
///
/// Indicates whether the subscriptions should be enabled.
///
public bool BoardEnableSubscriptions
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardEnableSubscriptions"), false);
}
set
{
SetValue("BoardEnableSubscriptions", value);
}
}
///
/// Indicates whether the permissions should be checked.
///
public bool CheckPermissions
{
get
{
return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), false);
}
set
{
SetValue("CheckPermissions", value);
msgBoard.BoardProperties.CheckPermissions = value;
}
}
///
/// Indicates whether the existing messages should be displayed to anonymous user.
///
public bool EnableAnonymousRead
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnableAnonymousRead"), false);
}
set
{
SetValue("EnableAnonymousRead", value);
}
}
///
/// Board unsubscription URL.
///
public string BoardUnsubscriptionUrl
{
get
{
return ValidationHelper.GetString(GetValue("BoardUnsubscriptionUrl"), "");
}
set
{
SetValue("BoardUnsubscriptionUrl", value);
}
}
///
/// Board base URL.
///
public string BoardBaseUrl
{
get
{
return ValidationHelper.GetString(GetValue("BoardBaseUrl"), "");
}
set
{
SetValue("BoardBaseUrl", value);
}
}
///
/// Indicates whether board is opened.
///
public bool BoardOpened
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardOpened"), false);
}
set
{
SetValue("BoardOpened", value);
}
}
///
/// Indicates type of board access.
///
public SecurityAccessEnum BoardAccess
{
get
{
return (SecurityAccessEnum)ValidationHelper.GetInteger(GetValue("BoardAccess"), 0);
}
set
{
SetValue("BoardAccess", value);
}
}
///
/// Indicates the board message post requires e-mail.
///
public bool BoardRequireEmails
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardRequireEmails"), false);
}
set
{
SetValue("BoardRequireEmails", value);
}
}
///
/// Indicates whether the board is moderated.
///
public bool BoardModerated
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardModerated"), false);
}
set
{
SetValue("BoardModerated", value);
}
}
///
/// Indicates whether the CAPTCHA should be used.
///
public bool BoardUseCaptcha
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardUseCaptcha"), false);
}
set
{
SetValue("BoardUseCaptcha", value);
}
}
///
/// Board opened from.
///
public DateTime BoardOpenedFrom
{
get
{
return ValidationHelper.GetDateTimeSystem(GetValue("BoardOpenedFrom"), DateTimeHelper.ZERO_TIME);
}
set
{
SetValue("BoardOpenedFrom", value);
}
}
///
/// Board opened to.
///
public DateTime BoardOpenedTo
{
get
{
return ValidationHelper.GetDateTimeSystem(GetValue("BoardOpenedTo"), DateTimeHelper.ZERO_TIME);
}
set
{
SetValue("BoardOpenedTo", value);
}
}
///
/// Indicates whether logging activity is performed.
///
public bool BoardLogActivity
{
get
{
return ValidationHelper.GetBoolean(GetValue("BoardLogActivity"), false);
}
set
{
SetValue("BoardLogActivity", value);
}
}
///
/// Enables/disables content rating
///
public bool EnableContentRating
{
get
{
return ValidationHelper.GetBoolean(GetValue("EnableContentRating"), false);
}
set
{
SetValue("EnableContentRating", value);
}
}
///
/// Gets or sets type of content rating scale.
///
public string RatingType
{
get
{
return ValidationHelper.GetString(GetValue("RatingType"), "StarsAJAX");
}
set
{
SetValue("RatingType", value);
}
}
///
/// Gets or sets max value/length of content rating scale
///
public int MaxRatingValue
{
get
{
return ValidationHelper.GetInteger(GetValue("MaxRatingValue"), 10);
}
set
{
SetValue("MaxRatingValue", value);
}
}
///
/// Gest or sest the cache item name.
///
public override string CacheItemName
{
get
{
return base.CacheItemName;
}
set
{
base.CacheItemName = value;
msgBoard.CacheItemName = value;
}
}
///
/// Cache dependencies, each cache dependency on a new line.
///
public override string CacheDependencies
{
get
{
return ValidationHelper.GetString(base.CacheDependencies, msgBoard.CacheDependencies);
}
set
{
base.CacheDependencies = value;
msgBoard.CacheDependencies = value;
}
}
///
/// Gets or sets the cache minutes.
///
public override int CacheMinutes
{
get
{
return base.CacheMinutes;
}
set
{
base.CacheMinutes = value;
msgBoard.CacheMinutes = value;
}
}
#endregion
protected void Page_Init(object sender, EventArgs e)
{
// Initialize the controls
SetupControls();
}
///
/// Reload data.
///
public override void ReloadData()
{
base.ReloadData();
SetupControls();
}
#region "Private methods"
///
/// Initializes the controls.
///
private void SetupControls()
{
// If the web part shouldn't proceed further
if (StopProcessing)
{
msgBoard.BoardProperties.StopProcessing = true;
Visible = false;
}
else
{
// Set the message board transformation
msgBoard.MessageTransformation = MessageTransformation;
// Set buttons
msgBoard.BoardProperties.ShowApproveButton = ShowApprove;
msgBoard.BoardProperties.ShowDeleteButton = ShowDelete;
msgBoard.BoardProperties.ShowEditButton = ShowEdit;
msgBoard.BoardProperties.ShowRejectButton = ShowReject;
// Set caching
msgBoard.CacheItemName = CacheItemName;
msgBoard.CacheMinutes = CacheMinutes;
msgBoard.CacheDependencies = CacheDependencies;
// Use board properties
if (BoardObj != null)
{
msgBoard.BoardProperties.BoardAccess = BoardObj.BoardAccess;
msgBoard.BoardProperties.BoardOwner = "group";
msgBoard.BoardProperties.BoardName = BoardObj.BoardName;
msgBoard.BoardProperties.BoardDisplayName = BoardObj.BoardDisplayName;
msgBoard.BoardProperties.BoardUnsubscriptionUrl = BoardInfoProvider.GetUnsubscriptionUrl(BoardObj.BoardUnsubscriptionURL, CMSContext.CurrentSiteName);
msgBoard.BoardProperties.BoardBaseUrl = (string.IsNullOrEmpty(BoardObj.BoardBaseURL)) ? ValidationHelper.GetString(SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSBoardBaseURL"), "") : BoardObj.BoardBaseURL;
msgBoard.BoardProperties.BoardEnableSubscriptions = BoardObj.BoardEnableSubscriptions;
msgBoard.BoardProperties.BoardOpened = BoardObj.BoardOpened;
msgBoard.BoardProperties.BoardRequireEmails = BoardObj.BoardRequireEmails;
msgBoard.BoardProperties.BoardModerated = BoardObj.BoardModerated;
msgBoard.BoardProperties.BoardUseCaptcha = BoardObj.BoardUseCaptcha;
msgBoard.BoardProperties.BoardOpenedFrom = BoardObj.BoardOpenedFrom;
msgBoard.BoardProperties.BoardOpenedTo = BoardObj.BoardOpenedTo;
msgBoard.BoardProperties.BoardEnableAnonymousRead = EnableAnonymousRead;
msgBoard.BoardProperties.EnableContentRating = EnableContentRating;
msgBoard.BoardProperties.CheckPermissions = CheckPermissions;
msgBoard.BoardProperties.RatingType = RatingType;
msgBoard.BoardProperties.MaxRatingValue = MaxRatingValue;
msgBoard.MessageBoardID = BoardObj.BoardID;
msgBoard.NoMessagesText = NoMessagesText;
}
// Use default properties
else
{
// If the board is group and information on current group wasn't supplied hide the web part
if (CurrentGroup == null)
{
Visible = false;
}
else
{
// Default board- document related continue
msgBoard.BoardProperties.BoardAccess = BoardAccess;
msgBoard.BoardProperties.BoardOwner = "group";
msgBoard.BoardProperties.BoardName = GetBoardName(WebPartName);
string boardDisplayName = null;
if (!String.IsNullOrEmpty(BoardDisplayName))
{
boardDisplayName = BoardDisplayName;
}
// Use predefined display name format
else
{
boardDisplayName = CMSContext.CurrentPageInfo.GetDocumentName() + " (" + CMSContext.CurrentPageInfo.DocumentNamePath + ")";
}
// Limit display name length
msgBoard.BoardProperties.BoardDisplayName = TextHelper.LimitLength(boardDisplayName, 250, "");
msgBoard.BoardProperties.BoardUnsubscriptionUrl = BoardInfoProvider.GetUnsubscriptionUrl(BoardUnsubscriptionUrl, CMSContext.CurrentSiteName);
msgBoard.BoardProperties.BoardBaseUrl = (string.IsNullOrEmpty(BoardBaseUrl)) ? ValidationHelper.GetString(SettingsKeyProvider.GetStringValue(CMSContext.CurrentSiteName + ".CMSBoardBaseURL"), "") : BoardBaseUrl;
msgBoard.BoardProperties.BoardEnableSubscriptions = BoardEnableSubscriptions;
msgBoard.BoardProperties.BoardOpened = BoardOpened;
msgBoard.BoardProperties.BoardRequireEmails = BoardRequireEmails;
msgBoard.BoardProperties.BoardModerated = BoardModerated;
msgBoard.BoardProperties.BoardModerators = BoardModerators;
msgBoard.BoardProperties.BoardUseCaptcha = BoardUseCaptcha;
msgBoard.BoardProperties.BoardOpenedFrom = BoardOpenedFrom;
msgBoard.BoardProperties.BoardOpenedTo = BoardOpenedTo;
msgBoard.BoardProperties.BoardEnableAnonymousRead = EnableAnonymousRead;
msgBoard.BoardProperties.BoardLogActivity = BoardLogActivity;
msgBoard.BoardProperties.EnableContentRating = EnableContentRating;
msgBoard.BoardProperties.CheckPermissions = CheckPermissions;
msgBoard.BoardProperties.RatingType = RatingType;
msgBoard.BoardProperties.MaxRatingValue = MaxRatingValue;
msgBoard.MessageBoardID = 0;
msgBoard.NoMessagesText = NoMessagesText;
}
}
}
}
///
/// Returns board name according board type.
///
/// Name of the web part
private string GetBoardName(string webPartName)
{
return BoardInfoProvider.GetMessageBoardName(webPartName, BoardOwnerTypeEnum.Group, CurrentGroup.GroupGUID.ToString());
}
#endregion
}