<%@ Import Namespace="edu.jhu.Cas" %>
<%@ Import Namespace="System.IO" %>
<%@ Register TagPrefix="uc1" TagName="Trailer" Src="Trailer.ascx" %>

<%@ Page Language="c#" Codebehind="Admin.aspx.cs" AutoEventWireup="false" Inherits="edu.jhu.Cas.Web.Admin" %>

<%@ Register TagPrefix="uc2" TagName="Header" Src="top.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Admin</title>
    <link href="cjobs.css" rel="stylesheet" />

    <script type="text/javascript" src="scripts\autosuggest.js"></script>

    <style type="text/css">
	.suggestion_list{
	    border: 1px solid;
	    padding: 4px;
	}
	.suggestion_list ul{
	    padding: 0;
	    margin: 0;
	    list-style-type: none;
	}	
	#autosuggest{
	    display: none;
	}
    </style>
</head>
<body>
    <uc2:Header ID="Header" runat="server" />
    <div style="margin-top:5px;" class="message">
        <%=lmessage%>
    </div>
    <h4>
        Active Queues</h4>
    <form id="Admin" method="post" runat="server">
        <asp:DataGrid ID="dg" runat="server" DataSource="<%# ds %>" BorderStyle="None" AutoGenerateColumns="False">
            <HeaderStyle Font-Bold="True" />
            <Columns>
                <asp:BoundColumn DataField="Target" HeaderText="Context" />
                <asp:BoundColumn DataField="Queue" HeaderText="Queue" />
                <asp:BoundColumn DataField="Userid" HeaderText="Owner" />
                <asp:BoundColumn DataField="TimeSubmit" HeaderText="TimeSubmit" />
                <asp:BoundColumn DataField="TimeStart" HeaderText="TimeStart" />
                <asp:BoundColumn DataField="html" HeaderText="Status" />
                <asp:HyperLinkColumn HeaderText="jobid" DataNavigateUrlField="jobid" DataNavigateUrlFormatString="jobdetails.aspx?id={0}&message=Details of {0}"
                    DataTextField="jobid" Target="" />
            </Columns>
        </asp:DataGrid>
        <% if (ds.Tables[0].Rows.Count == 0) { %>
        <i>No active queues.</i>
        <%}%>
        <h4>
            Active Output</h4>
        <p>
            <asp:DataGrid ID="og" runat="server" DataSource="<%# ods %>" BorderStyle="None"
                AutoGenerateColumns="False">
                <HeaderStyle Font-Bold="True" />
                <Columns>
                    <asp:BoundColumn DataField="Userid" HeaderText="Owner" />
                    <asp:BoundColumn DataField="OutputType" HeaderText="OutputType" />
                    
                    <asp:BoundColumn DataField="TimeSubmit" HeaderText="TimeSubmit" />
                    <asp:BoundColumn DataField="TimeStart" HeaderText="TimeStart" />
                    <asp:BoundColumn DataField="html" HeaderText="Status" />
                    <asp:HyperLinkColumn HeaderText="jobid" DataNavigateUrlField="jobid" DataNavigateUrlFormatString="jobdetails.aspx?id={0}&message=Details of {0}"
                        DataTextField="jobid" Target="" />
                </Columns>
            </asp:DataGrid></p>
        <% if (ods.Tables[0].Rows.Count == 0) { %>
        <i>No active output</i>
        <%}%>
        
        <%if (isadmin) {%>
        <h4>
            Admin Tools</h4>
        <div id="sdswsdiv">
            <%=sdsws %>
        </div>
        <p><a href="webtest/cjobstest.aspx">Regression Tests</a></p>
        <div id="userList" style="display: none">
            <%for (int x = 0; x < users.Tables[0].Rows.Count; x++) {%>
            <input type="hidden" value="<%=users.Tables[0].Rows[x][1]+", ["+users.Tables[0].Rows[x][0].ToString().Trim()+ "]"%>" />
            <%}%>
        </div>
        <div id="groupList" style="display: none">
            <%for (int x = 0; x < groups.Tables[0].Rows.Count; x++) {%>
            <input type="hidden" value="<%=groups.Tables[0].Rows[x][0]%>" />
            <%}%>
        </div>
        <div>
            <input type="text" id="userField" name="userField" />
            <input type="button" value="Load User" onclick="window.open('admin.aspx?userid='+document.getElementById('userField').value,'_top','');" />
            <span style="font-style: italic">Enter a user's name or userid. Use ']' to see all users.</span>
        </div>
         <div>
            <input type="text" id="groupField" name="groupField" />
            <input type="button" value="Load Group" onclick="window.open('admin.aspx?groupName='+document.getElementById('groupField').value,'_top','');" />
            <span style="font-style: italic">Enter a group's name.  Use ']' to see all groups.</span>
        </div>
        <div id="autosuggest">
            <ul>
            </ul>
        </div>
        <%if (userid != null && userid != "" && isadmin) {%>
        <h4>
            <a href="mailto:<%=currentUser.Email%>"><span style="">
                <%=currentUser.Name%>
            </span></a>
        </h4>
        <asp:Button ID="loginButton" ToolTip="" OnClick="Login" Text="Login" runat="server" />
        <asp:Button ID="deleteuserbutton" ToolTip="" OnClick="DeleteUser" Text="delete" runat="server" />
        <p>
            <span>WSID:&nbsp;</span><span><%=currentUser.WebServicesID%></span>
        </p>
        <p>
            <span>EMail:&nbsp;</span><span><%=currentUser.Email%></span></p>
        <p>
            <span>MyDB Location:&nbsp;</span><span><%=currentUser.MyDBHost != null?currentUser.MyDBHost:"Has No MyDB"%></span></p>
        <p>
            <span>Privs</span><asp:TextBox ID="PrivsBox" Columns="80" runat="server" /><br />
            <br />
            <span>MyDBMaxSize</span><asp:TextBox ID="MaxSizeBox" Columns="5" runat="server" />
        </p>
        <p>
            New Password
            <asp:TextBox ID="NewPassBox" runat="server" Columns="12" Width="126px"></asp:TextBox>(only
            fill in to change the users password - blank means no change)</p>
        <asp:Button ID="Button1" ToolTip="" OnClick="ApplyUserChanges" Text="Apply" runat="server" />
        <%}%>
        <%if (groupName != null && groupName != "" && isadmin) {%>
        <h4>
            <%=groupName %>
        </h4>
        <p>
            <span>GID:&nbsp;</span><span><%=group.Tables[0].Rows[0]["gid"]%></span>
        </p>
        <p>
            <span>Description:&nbsp;</span><span><%=group.Tables[0].Rows[0]["description"]%></span>
        </p>
        <p>
            <span>Group Admin:&nbsp;</span><span><%=group.Tables[0].Rows[0]["userid"]%> [<%=group.Tables[0].Rows[0]["oname"]%>]</span></p>
        <p>
            <span>Admin's Mail\WSID:&nbsp;</span><span><%=group.Tables[0].Rows[0]["email"]%> [<%=group.Tables[0].Rows[0]["owner"]%>]</span></p>
        <p>
            <span>Privs</span><asp:TextBox ID="GPrivsBox" Columns="80" runat="server" /><br />
        </p>
        <asp:Button ID="Button4" ToolTip="" OnClick="ApplyGroupChanges" Text="Apply" runat="server" />
        <%}%>
        <%}%>

        <script type="text/javascript">
	function confirm_delete(asdf){
		if(confirm("This will delete both all entries related to this user's wsid (including jobs) and their MyDB."+
			"\nAre you sure you want to delete "+asdf+"?")==true)
			return true;
		else		
			return false;
	}
	function bindEvents(){
		var tags = document.getElementById('userList').getElementsByTagName('INPUT');
		var userList = new Array(tags.Length);
		for(i=0;i<tags.length;i++)
			userList[i] = tags[i].value;
		new AutoSuggest(document.getElementById('userField'),userList);
		
		tags = document.getElementById('groupList').getElementsByTagName('INPUT');
		var groupList = new Array(tags.Length);
		for(i=0;i<tags.length;i++)
			groupList[i] = tags[i].value;
		new AutoSuggest(document.getElementById('groupField'),groupList);
	}
	window.onload = bindEvents;
        </script>

    </form>
    <uc1:Trailer ID="Trailer1" runat="server" cvsTag="$Name: v3_5_18 $" cvsRev="$Revision: 1.31 $">
    </uc1:Trailer>
</body>
</html>
