using System;
using System.Data; 
using System.Web.UI.WebControls;   
using System.Web.Security;
using System.ComponentModel;
using Meta.Web.Controls;
using Meta.Web.Controls.Template;   
using Meta.Web.Security; 
using Meta.Web;

namespace MetaSite.Components.Controls.Views
{
	/// <summary>
	/// LoginNavigation。
	/// </summary>
	public class LoginNavigation : BaseTemplateControl
	{
		Menubar Leftbar;
		Menubar Rightbar;
		ContextData context;
		Literal Userhi;    
		
		protected override void AttachChildControls()
		{
			Leftbar = (Menubar) FindControl("Leftbar");
			Rightbar = (Menubar) FindControl("Rightbar");
			Userhi = (Literal) FindControl("Userhi");
			
			context = ContextData.Current; 
			User user = context.User;	

			Userhi.Text = "<FONT face='宋体' color='red'>"+
					user.NickName+",您好,你已经成功登录!</FONT>";			
			
		
			Leftbar.Items.Add( CreateMenubarItem("帐户资料","~/user/EditProfile.aspx",true));	
			Rightbar.Items.Add( CreateMenubarItem("更改密码","~/admin/security/password.aspx?userid="+user.UserId,true));		
			
			AdminSettings.FileLocation =  "~/admin.config";

			bool left = false;

			if ( AdminSettings.InAdminRoles())
			{				
				Leftbar.Items.Add( CreateMenubarItem("控制面版","~/admin/default.aspx",true));
				if ( AdminSettings.InAdminRoles("Moderates"))
				{
					Rightbar.Items.Add( CreateMenubarItem("版务管理","~/admin/forums/Moderates.aspx",true));		
					left = true;
				}
			}

			if (left)
		    	Leftbar.Items.Add( CreateMenubarItem("注销登录","~/logout.aspx",false));
			else
				Rightbar.Items.Add( CreateMenubarItem("注销登录","~/logout.aspx",false));
		}

		

		public static MenubarItem CreateMenubarItem(string text,string url, bool terget)
		{
			MenubarItem item = new MenubarItem();
			item.Text = text;
			item.NavigateUrl = url;  
			if ( terget)
				item.Target = "_blank";
		
			return item;
		}
	}
}
