using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using edu.jhu.Cas.Jobs;
using edu.jhu.Cas.Users;
using edu.jhu.Cas.Util;
namespace edu.jhu.Cas.Web
{
	public class CreateGroup : System.Web.UI.Page
	{
		protected string lmessage ;
		protected TextBox nameBox;
		protected long wsid;
		protected System.Web.UI.WebControls.Button button;
		protected string description;
		private void Page_Load(object sender, System.EventArgs e)
		{
			description = Request.Params["description"];
			WebUtils.CheckLoggedIn(Session,Response,Request);
			wsid = (long)Session["USER"];
		}
		override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
			base.OnInit(e);
		}
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		protected void Go(Object asdf, EventArgs args)
		{
			if(description ==null || description.Length < 3 || nameBox.Text.Length < 3)
			{
				lmessage = "Please fill out all fields";
				return;
			}
			try
			{
				(new CasGroups()).CreateGroup(wsid,nameBox.Text,description);
	    		lmessage = "New group created called '"+nameBox.Text+"'";
			}
			catch(Exception e)
			{
				lmessage = e.Message;
			}
			Response.Redirect("groups.aspx?lmessage="+lmessage);
		}
	}
}