using System; using System.Collections.Generic; 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.Forums; using CMS.GlobalHelper; using CMS.ExtendedControls; public partial class CMSModules_Forums_Controls_ThreadMove : ForumViewer { #region "Public properties" /// /// Messages placeholder /// public override MessagesPlaceHolder MessagesPlaceHolder { get { return plcMess; } } /// /// Indicates if control is used on live site. /// public override bool IsLiveSite { get { return base.IsLiveSite; } set { plcMess.IsLiveSite = value; base.IsLiveSite = value; } } /// /// Gets the current thread id if ForumCOntext.CurrentThread is not available e.g. in tree layout. /// public int CurrentThread { get { return QueryHelper.GetInteger("moveto", SelectedThreadID); } } /// /// Gets or sets the thread id. /// public int SelectedThreadID { get { return ValidationHelper.GetInteger(GetValue("SelectedThreadID"), 0); } set { SetValue("SelectedThreadID", value); } } /// /// Gets or sets the value that indicates whether controls is in administration mode. /// public bool AdminMode { get { return ValidationHelper.GetBoolean(GetValue("AdminMode"), false); } set { SetValue("AdminMode", value); } } #endregion /// /// Occurs when thread is moved. /// public event EventHandler TopicMoved; protected void Page_Load(object sender, EventArgs e) { if ((ForumContext.CurrentMode == ForumMode.TopicMove) || (AdminMode)) { CopyValuesFromParent(this); btnMove.Click += new EventHandler(btnMove_Click); if (!RequestHelper.IsPostBack()) { LoadMoveTopicDropdown(); } else { // Display message if no forum exists if (drpMoveToForum.Items.Count == 0) { plcMoveInner.Visible = false; ShowInformation(GetString("Forums.NoForumToMoveIn")); } } } } /// /// Topic move action handler. /// protected void btnMove_Click(object sender, EventArgs e) { int forumId = ValidationHelper.GetInteger(drpMoveToForum.SelectedValue, 0); if (forumId > 0) { ForumPostInfo fpi = ForumContext.CurrentThread; if ((fpi == null) && (CurrentThread > 0)) { fpi = ForumPostInfoProvider.GetForumPostInfo(CurrentThread); } if (fpi != null) { // Move the thread ForumPostInfoProvider.MoveThread(fpi, forumId); plcMoveInner.Visible = false; // Generate back button ltlMoveBack.Text = GetLink(null, GetString("general.back"), "ActionLink", ForumActionType.Thread); string targetForumName = drpMoveToForum.SelectedItem.Text.TrimStart(' '); ForumInfo fi = ForumInfoProvider.GetForumInfo(forumId); if (fi != null) { targetForumName = HTMLHelper.HTMLEncode(fi.ForumDisplayName); } // Display info ShowConfirmation(String.Format(GetString("forum.thread.topicmoved"), targetForumName)); SetValue("TopicMoved", true); if (TopicMoved != null) { TopicMoved(this, null); } } } else { ShowError(GetString("forum.thread.movetopic.selectforum")); } } /// /// Loads the forums dropdownlist for topic move. /// private void LoadMoveTopicDropdown() { if (drpMoveToForum.Items.Count > 0) { return; } int currentForumId = 0; ForumPostInfo fpi = ForumContext.CurrentThread; if ((fpi == null) && (CurrentThread > 0)) { fpi = ForumPostInfoProvider.GetForumPostInfo(CurrentThread); } if (fpi != null) { bool isOk = AdminMode ? true : ((ForumContext.CurrentForum != null) && (ForumContext.CurrentForum.ForumID == fpi.PostForumID)); if (isOk) { currentForumId = fpi.PostForumID; ForumInfo fi = ForumInfoProvider.GetForumInfo(currentForumId); if (fi != null) { ForumGroupInfo fgi = ForumGroupInfoProvider.GetForumGroupInfo(fi.ForumGroupID); if (fgi != null) { string where = null; DataSet dsGroups = null; if (fgi.GroupGroupID > 0) { where = "GroupName NOT LIKE 'AdHoc%' AND GroupSiteID = " + SiteID + " AND GroupGroupID = " + fgi.GroupGroupID; } else { where = "GroupName NOT LIKE 'AdHoc%' AND GroupSiteID = " + SiteID + " AND GroupGroupID IS NULL"; } dsGroups = ForumGroupInfoProvider.GetGroups(where, "GroupDisplayName", 0, "GroupID, GroupDisplayName"); if (!DataHelper.DataSourceIsEmpty(dsGroups)) { Hashtable forums = new Hashtable(); // Get all forums for selected groups string groupWhere = "AND ForumGroupID IN (SELECT GroupID FROM Forums_ForumGroup WHERE " + where + ") "; DataSet dsForums = ForumInfoProvider.GetForums(" ForumOpen = 1 " + " AND NOT ForumID = " + currentForumId + groupWhere, "ForumDisplayName", 0, "ForumID, ForumDisplayName, ForumGroupID"); if (!DataHelper.DataSourceIsEmpty(dsForums)) { // Load forums into hash table foreach (DataRow drForum in dsForums.Tables[0].Rows) { int groupId = Convert.ToInt32(drForum["ForumGroupID"]); List forumNames = forums[groupId] as List; if (forumNames == null) { forumNames = new List(); } forumNames.Add(new string[] { Convert.ToString(drForum["ForumDisplayName"]), Convert.ToString(drForum["ForumID"]) }); forums[groupId] = forumNames; } } foreach (DataRow dr in dsGroups.Tables[0].Rows) { int groupId = Convert.ToInt32(dr["GroupId"]); List forumNames = forums[groupId] as List; if (forumNames != null) { // Add forum group item if some forum ListItem li = new ListItem(Convert.ToString(dr["GroupDisplayName"]), "0"); li.Attributes.Add("disabled", "disabled"); drpMoveToForum.Items.Add(li); // Add forum items foreach (string[] forum in forumNames) { // Add forum to DDL drpMoveToForum.Items.Add(new ListItem(" \xA0\xA0\xA0\xA0 " + forum[0], forum[1])); } } } // Display message if no forum exists if (drpMoveToForum.Items.Count == 0) { plcMoveInner.Visible = false; ShowInformation(GetString("Forums.NoForumToMoveIn")); } } } } } } } }