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

<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="edu.jhu.Cas.Util" %>
<%@ Import Namespace="edu.jhu.Cas.Jobs" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Pragma" content="no-cache" />
    <base target="content" />
    <title>MyDB Index</title>
    <link href="cjobs.css" rel="stylesheet" />
    <style type="text/css">
    input{
        margin:0;width:13px;height:13px;overflow:hidden;
    }
    </style>
</head>
<body onload="window.parent.resizeLeft();" >
<div class="message"><%=lmessage %></div>
    <table id="outer" style="margin:5 0 0 0; padding: 0 0 0 0;width:0;" cellpadding="0" cellspacing="0"><tr><td>
        <form style="padding: 0 0 0 0; margin: 0 0 0 0;" target="index" runat="server">
            <div style="white-space:nowrap;">
                <asp:DropDownList ID="targetDDL" runat="server" AutoPostBack="true" />
                <%if (dbobjtype == CasDBObjType.TABLE && context.ToLower() == "mydb") { %>
                <asp:DropDownList CssClass="group" ID="groupDDL" runat="server" AutoPostBack="true" />
                <%}%>
                <!--<a href="mydbcontent.aspx" onmouseover="return escape('<%=key%>');">Key</a>-->
            </div>
        </form>
        <div class="<%=GetSelectionClass(CasDBObjType.VIEW)%>">
            <a class="<%=GetSelectionClass(CasDBObjType.VIEW)%>" target="index" href="mydbindex.aspx?objtype=<%=CasDBObjType.VIEW %>">
                Views</a></div>
        <div class="<%=GetSelectionClass(CasDBObjType.TABLE)%>">
            <a class="<%=GetSelectionClass(CasDBObjType.TABLE)%>" target="index" href="mydbindex.aspx">Tables</a></div>
        <div class="<%=GetSelectionClass(CasDBObjType.FUNCTION)%>">
            <a class="<%=GetSelectionClass(CasDBObjType.FUNCTION)%>" target="index" href="mydbindex.aspx?objtype=<%=CasDBObjType.FUNCTION %>">
                Functions</a></div>
        <div class="<%=GetSelectionClass(CasDBObjType.PROCEDURE)%>">
            <a class="<%=GetSelectionClass(CasDBObjType.PROCEDURE)%>" target="index" href="mydbindex.aspx?objtype=<%=CasDBObjType.PROCEDURE %>">
                Procedures</a></div>
        <div style="height: 5;">
            &nbsp;</div>
        <table id="datable" cellpadding="0" cellspacing="0">
            <tr id="ignore">
                <th style="font-weight: normal;" colspan="4">
                    <table cellpadding="0" cellspacing="0">
                        <tr id="ignore2">
                            <th>
                                <select id="sortSelect" onchange="SelectSort();" style="margin-right: 5">
                                    <option>Sort by...</option>
                                    <option value="n">Name</option>
                                    <%if (dbobjtype == CasDBObjType.TABLE) {%>
                                    <option value="r">Rows</option>
                                    <option value="s">Size</option>
                                    <option value="t">Type</option>
                                    <%}%>
                                </select>
                            </th>
                            <th>
                                <select id="actionSelect" onchange="SelectAction();" enableviewstate="false">
                                    <%if (context == "MyDB" && dbobjtype == CasDBObjType.TABLE) { %>
                                    <option selected="selected">All selected...</option>
                                    <option value="d" style="color: Red;">Drop</option>
                                    <%}
                                      else {%>
                                    <option selected="selected">No actions...</option>
                                    <%}%>
                                </select>
                            </th>
                        </tr>
                    </table>
                </th>
            </tr>
            <%if (dbobjtype == CasDBObjType.FUNCTION) {%>
            <%if (functions.Count == 0) {%>
            <tr>
                <td class="message" style="padding: 1 1 1 2">
                    No functions found
                </td>
            </tr>
            <%}
              else foreach (object o in functions) {%>
            <tr>
                <td style="text-align: center;">
                    <%if (context.ToUpper() == "MYDB" && dbobjtype == CasDBObjType.TABLE) { %>
                    <input type="checkbox" style="padding: 0 0 0 0; margin: 0 0 0 0; border-style: none;"
                        value="<%=o.ToString()%>" /><%} %></td>
                <td>
                    <a href="mydbcontent.aspx?ObjName=<%=o.ToString()%>&objtype=<%=CasDBObjType.FUNCTION%>&context=<%=context%>"
                        target="content">
                        <%=o.ToString()%>
                    </a>
                </td>
            </tr>
            <%}%>
            <%}
              else if (dbobjtype == CasDBObjType.PROCEDURE) {%>
            <%if (procedures.Count == 0) {%>
            <tr>
                <td class="message" style="padding: 1 1 1 2">
                    No procedures found
                </td>
            </tr>
            <%}
              else foreach (object o in procedures) {%>
            <tr>
                <td style="text-align: center;">
                    <%if (context == "MyDB" && dbobjtype == CasDBObjType.TABLE) { %>
                    <input type="checkbox" style="padding: 0 0 0 0; margin: 0 0 0 0; border-style: none;"
                        value="<%=o.ToString()%>" /><%} %></td>
                <td>
                    <a href="mydbcontent.aspx?ObjName=<%=o.ToString()%>&ObjType=<%=CasDBObjType.PROCEDURE%>&context=<%=context%>"
                        target="content">
                        <%=o.ToString()%>
                    </a>
                </td>
            </tr>
            <%}%>
            <%}
              else {%>
            <%	if (allTables.Count == 0) {%>
            <tr>
                <td class="message" style="padding: 1 1 1 2">
                    Nothing found
                </td>
            </tr>
            <%}
              else { %>
            <tr id="ignore1">
                <th>
                    &nbsp;
                </th>
                <th>
                    Rows</th>
                <th>
                    kB</th>
                <th>
                    Name</th>
            </tr>
            <% foreach (object o in allTables) {
                   string css = "normal";
                   if (group != ALL_GROUPS && group != LOCAL_TABS && context.ToUpper() == "MYDB" && dbobjtype == CasDBObjType.TABLE) {
                       css = "group";
                   }
                   else if (publishedTables.Contains(o)) {
                       css = "published";
                   }
                   else if (groupTables != null && groupTables.Contains(o)) {
                       css = "group";
                   }
                   else if (pendingTables.Contains(o)) {
                       css = "pending";
                   }
                   else if (failedTables.Contains(o)) {
                       css = "bad_table";
                   }
            %>
            <tr>
                <td style="text-align: center;">
                    <%if (context == "MyDB" && dbobjtype == CasDBObjType.TABLE) { %>
                    <input type="checkbox" style="padding: 0 0 0 0; margin: 0 0 0 0; border-style: none;"
                        value="<%=o.ToString()%>" /><%} %></td>
                <td style="text-align: right">
                    <%=tinfo.Contains(o) ? ((CasTable)tinfo[o]).Rows == 0?"0":String.Format("{0:#,###}", ((CasTable)tinfo[o]).Rows) : "NA"%>
                </td>
                <td style="text-align: right">
                    <%=tinfo.Contains(o) ? ((CasTable)tinfo[o]).Size == 0 ? "0" : String.Format("{0:#,###}", ((CasTable)tinfo[o]).Size) : "NA"%>
                </td>
                <td>
                    <a class="<%=css %>" href="mydbcontent.aspx?ObjName=<%=o.ToString()%>&ObjType=<%=dbobjtype%>&context=<%=context%>&type=<%=css%>"
                        target="content">
                        <%=o.ToString()%>
                    </a>
                </td>
            </tr>
            <%}
          }%>
            <%}%>
        </table>
        <form style="display: none;" target="_top" name="maform" id="maform">
            <input type="hidden" name="maction" id="maction" value="" />
            <input type="hidden" name="maobjs" id="maobjs" value="" />
        </form>
        <script language="JavaScript" type="text/javascript" src="scripts/wz_tooltip.js"></script>
        <script type="text/javascript" src="scripts/mydbindex.js"></script>
    </td></tr></table>
</body>
</html>
