<%@ page import="com.eg.DbMaintenanceUtil" %>
<%@ page import="com.eg.EgDbInfo" %>
<%@ page import="com.eg.EgConMonHelper"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> DbMaintenanceUtility</TITLE>
<link rel="stylesheet" href="eg_styles/eg_adminstyle.css" />
<script language="javascript" src="/final/admin/eg_scripts/timeout.js"></script>

<script language="javascript">
document.onscroll = function()
{
	clearTimeout(time);
	time = setTimeout(logout,timeoutTime);
}

function executeQuery()
{
	document.dbm.submit();
}
</script>
<style>
.myDiv {
  margin: 10px 10px 10px 10px
}
</style>
</HEAD>
<BODY>
<div class="myDiv">
<%
	String sessionInUse = request.getParameter("sessionInUse");
	String pwd = request.getParameter("pwd");
	String authenticated = (String)session.getAttribute("authenticated");

	if (authenticated == null)
	{
		// Direct access from the browser address bar or from inside the toolkit via the tool
		if (pwd == null)
		{
			if (sessionInUse == null)
			{
				response.sendRedirect(request.getContextPath()+"/toolkitlogin?comeFrom=DBUtility");
			}
			else
			{
%>
				<script>
					window.parent.location.href ="/final/toolkitlogin";
				</script>
<%
			}
		}
		else
		{
			// Direct access from the browser address bar
			if (!pwd.equals(EgConMonHelper.executePwd))
			{
				response.sendRedirect(request.getContextPath()+"/toolkitlogin?comeFrom=DBUtility");
			}
			else
			{
				session.setAttribute("reqFromForTk","DBUtility");
				String redirectURL = request.getContextPath()+"/toolkit";
				response.sendRedirect(redirectURL);
			}
		}
	}
	else
	{ 
		if (sessionInUse == null)
		{
			// Direct access from the browser address bar and session in use
			response.sendRedirect(request.getContextPath()+"/toolkit");
		}
	}

	String comeFrom = request.getParameter("comeFrom");
	if (!StringUtils.isNull(comeFrom) && comeFrom.equals("DBUtil"))
	{
		session.setAttribute("treeViewSrc","DBUtility");
	}

	session.setAttribute("reqFromForTk","DBUtility");
%>

<br><br>

<%
	String do_execute = request.getParameter("do_execute");
	if (do_execute != null && do_execute.equalsIgnoreCase("true"))
	{
		DbMaintenanceUtil dbmu = new DbMaintenanceUtil();
		StringBuffer buf = dbmu.dbStatistics();
		out.println(buf);
	}
	else
	{
%>
<form name="dbm" method="post" action="EgDbUtility.jsp?sessionInUse=true"> 
	<table border="1" align="center" width="50%" cellpadding="4" cellspacing="2">
		<input type="hidden" name="do_execute" value="true">
		<tr align="right"><td align="center" valign="middle"><b>eG Database Maintenance Utility</b></td></tr>
		<tr align="right"><td align="center"><input type="button"  onClick="javaScript:executeQuery()" name="execute" value="Execute"></td></tr>
	</table>
</form>
<%
	}
%>
</div>
</BODY>
</HTML>



