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;
namespace edu.jhu.Cas.Web {
    public class GroupsIndex : System.Web.UI.Page {
        protected string lmessage = null;
        protected long wsid;
        protected bool loggedin;
        protected ArrayList allGroups, adminGroups;
        protected DataSet inviteDataSet;
        protected DataGrid inviteGrid;
        protected CasGroups cGroups;
        private void Page_Load(object sender, System.EventArgs e) {
            loggedin = Session["USER"] != null;
            if (loggedin)
                wsid = (long)Session["USER"];
            cGroups = new CasGroups();
            adminGroups = GetAdminGroups(wsid);
            allGroups = new ArrayList();
            allGroups.AddRange(adminGroups);
            allGroups.AddRange(GetGroups());
        }
        protected ArrayList GetGroups() {
            DataSet ds = cGroups.FindGroupsDataSet(wsid, " status = 2 and owner != " + wsid);
            ArrayList rst = new ArrayList();
            foreach (DataRow row in ds.Tables[0].Rows)
                rst.Add(row[0]);
            return rst;
        }
        public static ArrayList GetAdminGroups(long wsid) {
            DataSet ds = (new CasGroups()).FindGroupsDataSet(wsid, " owner = " + wsid,false);
            ArrayList rst = new ArrayList();
            foreach (DataRow row in ds.Tables[0].Rows)
                rst.Add(row[0]);
            return rst;
        }
        protected void LoadInvite() {
            inviteDataSet = cGroups.FindGroupsDataSet(wsid, " status = 1");
            inviteGrid.DataSource = inviteDataSet.Tables[0];
            inviteGrid.DataBind();
        }
        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e) {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent() {
            this.Load += new System.EventHandler(this.Page_Load);
        }
        #endregion
    }
}