//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Membership
{
	/// <summary>
	/// Summary description for MembershipHomePage.
	/// </summary>
	public class MembershipHomePage : BaseMembershipPage
	{

		override protected void OnInit(EventArgs e)
		{
			this.Load += new EventHandler(this.Page_Load);

			base.OnInit(e);

		}
		

		#region Members

		protected Hyperlink linkTopPosters;
		protected Hyperlink linkVisitors;
		protected Hyperlink linkRegistrations;
		protected ControlPanelSelectedNavigation SelectedNavigation1;
		protected Hyperlink linkApproval;

		protected System.Web.UI.WebControls.Panel UserAddedMessagePanel;
		protected StatusMessage AddUserStatus;
		protected Hyperlink EditUserLink;
		protected Hyperlink AddUserLink;

		#endregion

		private void Page_Load(object sender, EventArgs e)
		{

			CSContext csContext = CSContext.Current;
			int userID = csContext.GetIntFromQueryString("UserID", -1);

			if (userID > 0)
			{
				UserAddedMessagePanel.Visible = true;
				AddUserLink.NavigateUrl = SiteUrls.Instance().ControlPanelUserAdd;
				AddUserLink.ResourceName = "CP_Membership_Default_AddUser";

				User user = Users.GetUser(userID, false);
				if (user != null)
				{
					EditUserLink.NavigateUrl = SiteUrls.Instance().ControlPanelUserEdit(userID);
					EditUserLink.ResourceName = "CP_Membership_Default_EditUser";
					AddUserStatus.Text = String.Format(ResourceManager.GetString("CP_Membership_Default_UserAddedMessage"), user.DisplayName);
					AddUserStatus.Success = true;
					AddUserStatus.Visible = true;
				}

			}
			else
			{
				UserAddedMessagePanel.Visible = false;
			}

			DateTime filterDate = DateTime.Now.AddDays(-1.0);

			
			// Users with an account status of ApprovalPending
			this.linkApproval.NavigateUrl = ResolveUrl(String.Format("MemberSearch.aspx?tab=SearchMembers&s={0}", (int)UserAccountStatus.ApprovalPending));

			// Users that joined within the last day
			this.linkRegistrations.NavigateUrl = ResolveUrl(String.Format("MemberSearch.aspx?tab=SearchMembers&jc=1&jd={0}&sb={1}&so={2}", filterDate.ToShortDateString(), (int)SortUsersBy.JoinedDate, (int)SortOrder.Descending));

			// Users that had activity within the last day
			this.linkVisitors.NavigateUrl = ResolveUrl(String.Format("MemberSearch.aspx?tab=SearchMembers&pc=1&pd={0}&sb={1}&so={2}", filterDate.ToShortDateString(), (int)SortUsersBy.LastActiveDate, (int)SortOrder.Descending));

			// Users who posted the most. This isn't a filter yet, so we'll just sort by PostCount desc
			this.linkTopPosters.NavigateUrl = ResolveUrl(String.Format("MemberSearch.aspx?tab=SearchMembers&sb={0}&so={1}", (int)SortUsersBy.Posts, (int)SortOrder.Descending ));

		}



	}
}
