<%@ page import = "com.eg.EgCrypt"%>
<%@ page import = "com.eg.EgConMonHelper"%>

<%@ taglib prefix = "egui" uri="../WEB-INF/eg-taglib.tld"%>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);

	String tool = "decrypttext";
	String encpwd = request.getParameter("encpwd");

	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="+tool+"&tools="+tool);
			}
			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="+tool+"&tools="+tool);
			}
			else
			{
				session.setAttribute("reqFromForTk","decrypttext");
				session.setAttribute("validate_tools","true");
				session.setAttribute("tools",tool);
				String redirectURL = request.getContextPath()+"/toolkit";
				response.sendRedirect(redirectURL);
			}
		}
	}
	else
	{
		// Direct access from the browser address bar and session in use
		if (sessionInUse == null)
		{
			session.setAttribute("validate_tools","true");
			session.setAttribute("tools",tool);
			response.sendRedirect(request.getContextPath()+"/toolkit");
		}
	}

	session.setAttribute("treeViewSrc","decrypttext");
	session.setAttribute("reqFromForTk","decrypttext");
%>

<html>
<head>
<script language="javascript" src="/final/admin/eg_scripts/timeout.js"></script>
<script language="JavaScript">
function decrypt()
{
	var thisForm = document.decryptText;
	var encpwd = thisForm.encpwd.value;
	if (encpwd == '')
	{
		alert("Please provide a encrypted text.");
		document.getElementById("encpwd").focus();
		return;
	}
	else
	{
		thisForm.action="/final/admin/EgDecryptText.jsp?sessionInUse=true";
		thisForm.submit();
	}
}
</script>
<link rel="stylesheet" href="eg_styles\adminstyle_blue.css"/>
</head>

<body style="overflow:auto" id="space6" >
<form name="decryptText" method="POST" style="margin:0px">
<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0">
	<tr>
		<td id="eg_blankspace" height="10" nowrap>&nbsp;</td>
	</tr>
	<tr>
		<td width="100%" height="24" id="eg_title" align="center"> &nbsp;DECRYPT THE ENCRYPTED TEXT</td>
	</tr>
	<tr>
		<td height="20" align="center">
			<table align="center" width="85%" cellspacing="0" cellpadding="4" border="0">
				<tr>
					<td height="24" nowrap align="right" width="35%" class="eg_cellbglits"><img src="/final/admin/eg_images/info2.gif"> </td>
					<td height="24" nowrap align="left" class="eg_cellbglits">This page enables the administrator to decrypt the encrypted text.</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td width="100%" id="eg_whitebg" align="center" height="100%" valign="top">
			<table align="center" width="85%" cellspacing="0" cellpadding="0" border="0">
				<tr>
					<td id="eg_blankspace" height="5" nowrap>&nbsp;</td>
				</tr>

				<tr>
					<td align="center" valign="top">
						<table align="center" width="100%" cellspacing="0" cellpadding="0" border="0" class="eg_subcontentbg">
							<tr>
								<td height="6" id="inner_top_left" width="7" class="eg_subcontentbg"><img src="/final/admin/eg_images/spacer.gif" border="0" width="7" height="6"></td>
								<td height="6" id="eg_subcontentbg" width="100%" colspan="4"><img src="/final/admin/eg_images/spacer.gif" height="6"></td>
								<td height="6" id="inner_top_right" width="7" class="eg_subcontentbg"><img src="/final/admin/eg_images/spacer.gif" border="0" width="7" height="6"></td>
							</tr>
							<tr>
								<td class="form_spacing">&nbsp;</td>
								<td align="center" colspan="3" class="form_spacing" nowrap>Please enter the encrypted text&nbsp;:&nbsp;<input type="text" name="encpwd" id="encpwd" style="width:250px">
								</td>
								<td class="form_spacing">&nbsp;</td>
							</tr>
							<tr>
								<td height="6" id="inner_bott_left" width="7" class="eg_subcontentbg"> <img src="/final/admin/eg_images/spacer.gif" width="7" height="6" border="0"></td>
								<td id="eg_subcontentbg"  width="100%" colspan="4" valign="top" ><img src="/final/admin/eg_images/spacer.gif" height="6" border="0"></td>
								<td height="6" align="right" id="inner_bott_right" width="7" class="eg_subcontentbg"> <img src="/final/admin/eg_images/spacer.gif" width="7px" height="6px" border="0"></td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td id="eg_blankspace" height="5" nowrap>&nbsp;</td>
				</tr>
				<tr>
					<td align="center" valign="top">
						<table align="center" width="100%" cellspacing="0" cellpadding="0" border="0" class="eg_subcontentbg">
							<tr>
								<td colspan="6" align='center' id="eg_whitebg" nowrap>
									<input type="button" name="update" id="eg_back" value="Decrypt" onClick="javascript:decrypt()">
								</td>
							</tr>
						</table>
					</td>
				</tr>

				<tr>
					<td id="eg_blankspace" height="5" nowrap>&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>

<%
	if (encpwd != null && encpwd.length() > 0)
	{
		String value = EgCrypt.decrypt(encpwd);
%>
	<tr>
		<td id="eg_blankspace" height="20" nowrap>&nbsp;</td>
	</tr>
	<tr>
		<td id="txt" align="center">Decrypted text is <%=value%></td>
	</tr>
	<tr>
		<td id="eg_blankspace" height="20" nowrap>&nbsp;</td>
	</tr>
<%
	}
%>
</table>
</form>
</body>
</html>



