<%@ include file="../../EgTrackerAJSON.jsp" %>
<%@ page import = "java.io.*"%>
<%@ page import = "java.util.*"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import="com.eg.*"%>
<%@ taglib prefix="egui" uri="../../../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

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

	String domainDisName = request.getParameter("domainDisName");
	domainDisName = StringUtils.decodeSecurityChar(domainDisName);

	String domainName=request.getParameter("domainName");
	String domain_User=request.getParameter("domain_User");
	domain_User = StringUtils.decodeSecurityChar(domain_User);

	String domain_Pwd=request.getParameter("domain_Pwd");
	domain_Pwd = StringUtils.decodeSecurityChar(domain_Pwd);

	String ssl = request.getParameter("ssl");
	String dnsMode=request.getParameter("dnsMode");
	String serverIP=request.getParameter("serverIP");
	String port=request.getParameter("port");
	String frmURI = request.getParameter("opt");
	String domAliasName = request.getParameter("domAliasName");
	boolean autoDiscover = false;
	boolean sslEnabled = false;
	if (ssl != null &&(ssl.equalsIgnoreCase("Yes") || ssl.equalsIgnoreCase("true")))
	{
		sslEnabled = true;
	}

	if (dnsMode != null && (dnsMode.equalsIgnoreCase("Yes") || dnsMode.equalsIgnoreCase("true") ||dnsMode.equalsIgnoreCase("Auto")))
	{
		autoDiscover = true;
	}

	EgDomainAuthenticationFrameWork advalidations = null;
	if (autoDiscover)
	{
		advalidations = new EgDomainAuthenticationFrameWork(domainDisName,domain_User,domain_Pwd,sslEnabled,frmURI);
	}
	else
	{
		advalidations = new EgDomainAuthenticationFrameWork(domainDisName,domain_User,domain_Pwd,sslEnabled,serverIP,port,frmURI);
	}

	if (!com.egurkha.util.StringUtils.isNull(domAliasName))
	{
		advalidations.validateADCredentials(autoDiscover,domainName,domAliasName);
	}
	else
	{
		advalidations.validateADCredentials(autoDiscover,domainName);
	}
%>

	<table border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr><td>&nbsp;</td></tr>
	</table>
	<div class="x-table">
		<table class="x-grid-table border_alt" border="0" cellspacing="0" cellpadding="2" width="96%" align="center" style="width:100%">
			<col width="40%"><col width="60%">
			<thead>
				<tr class="x-grid-row">
					<th class="x-grid-cell" style="padding: 5px;"><div class="custom-grid-cell-inner"><span><egui:intnl text="admin.common.Validation"/></span></div></th>
					<th class="x-grid-cell" style="padding: 5px;"><div class="custom-grid-cell-inner"><span><egui:intnl text="admin.common.Result"/></div></span></th>
				</tr>
			</thead>
			<tbody>
<%
	String msg ="";
	String key = "";
	boolean isAllValidationsOk=true;
	ArrayList res = advalidations.getADResponse();
	if (res != null && res.size() > 0)
	{
		for (int i = 0;i<res.size();i++)
		{
			String val = (String)res.get(i);
			StringTokenizer tokens = new StringTokenizer(val,"$#$");
			key=(String)tokens.nextToken();
			while(tokens.hasMoreTokens())
			{
				msg =(String)tokens.nextToken();
			}

			if(msg!=null && msg.equals("OK") || msg.equalsIgnoreCase("Yes"))
			{
%>
				<tr class="x-grid-row">
					<td class=" x-grid-cell x-grid-cell-first"><div class="x-grid-cell-inner"><%=key%></div></td>
					<td class=" x-grid-cell" style="border-left:0px">
						<div class="x-grid-cell-inner"><div style="float:left;" class="tick" > </div></div>
					</td>
				</tr>
<%
			}
			else
			{
				isAllValidationsOk = false;
%>
				<tr class="x-grid-row">
					<td class=" x-grid-cell x-grid-cell-first"><div class="x-grid-cell-inner"><%=key%></div></td>
					<td class=" x-grid-cell" style="border-left:0px">
						<div class="x-grid-cell-inner"><div style="float:left;" class="fault" > </div></div>
					</td>
				</tr>
<%
			}
		}
	}
%>
	</tbody>
	</table>

	<table border="0" cellspacing="0" cellpadding="0" width="100%">
		<tr><td>&nbsp;</td></tr>
	</table>
<%
	ArrayList error = advalidations.getADErrorResult();
	if(isAllValidationsOk && error.size() == 0)
	{
%>
		<table class="x-grid-table border_alt" border="0" cellspacing="0" cellpadding="0" width="96%" align="center" style="width:100%">
			<col width="5%"><col width="95%">
			<tr class="x-grid-row">
				<td class="x-grid-cell">
					<div class="x-grid-cell-inner"><div style="float:left;" class="tick" ></div></div>
				</td>
				<td class="x-grid-cell" valign="middle">
					<div class="x-grid-cell-inner">&nbsp;<b><egui:intnl text="admin.common.Domain server credentials have been validated successfully"/>!</b></div>
				</td>
			</tr>
		</table>
<%
	}
	else
	{
		if (error != null && error.size() > 0)
		{
%>
			<table class="x-grid-table border_alt" border="0" cellspacing="0" cellpadding="0" width="96%" align="center" style="width:100%">
			<col width="5%"><col width="95%" align="center">
				<thead>
					<tr class="x-grid-row">
						<th colspan="2" class="x-grid-cell">
							<div class="x-grid-cell-inner"><span><egui:intnl text="admin.common.Possible reasons could be "/>&nbsp;:&nbsp;</span></div>
						</th>
					</tr>
				</thead>
				<tbody>
<%
			for (int j = 0;j<error.size();j++)
			{
				String errMsgStr = (String)error.get(j);
%>
				<tr class="x-grid-row">
					<td class="x-grid-cell" align="center" valign="middle"><div class="x-grid-cell-inner"><div style="float:left;" class="fault" > </div></div></td>
					<td class="x-grid-cell" valign="middle" style="border-left:0px"><div class="x-grid-cell-inner"><b><%=errMsgStr%></b></div>
					</td>
				</tr>
<%
			}
%>
			</tbody>
		</table>
<%
		}
	}
%>



