<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgConMonHelper"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ taglib prefix = "egui" uri = "../WEB-INF/eg-taglib.tld" %>
<jsp:useBean id="managerOutputBean" scope="page" class="egurkha.TransactionBean"/>
<%
	String sessionInUse = request.getParameter("sessionInUse");
	String pwd = request.getParameter("pwd");
	String authenticated = (String)session.getAttribute("authenticated");
	String resultMsg = request.getParameter("resultMsg");
	String outErrMode = request.getParameter("val");
	resultMsg = resultMsg == null || resultMsg.equalsIgnoreCase("null") ? "" : resultMsg;
	int h = resultMsg.equals("") ? 10 : 50;
	String form_border = resultMsg.equals("") ? "" : "form_border";

	String manager_label = EgInstallInfo.isSuperManager ? "SuperManager" : "Manager";
	String restart_label = "admin.settings.Restart the "+manager_label+" now";
	String output_label = "admin.settings."+manager_label+" Output and Error";

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

	managerOutputBean.createFile("eg_outputstatus.ini");
	String disableDebug = managerOutputBean.getStrValue("MANAGER_DEBUG_STATUS","Manual");
	disableDebug = (disableDebug == null || disableDebug.trim().length() == 0 || disableDebug.equalsIgnoreCase("no")) ? "no" : "yes";
	String managerOutput = managerOutputBean.getStrValue("MANAGER_OUTPUT_STATUS","output");
	String preManagerOutput = "";
	String mgrOutputOverWirte = managerOutputBean.getStrValue("MANAGER_OUTPUT_STATUS","manager_output_overwrite");
	if(managerOutput != null && (managerOutput.equalsIgnoreCase("yes") || managerOutput.equalsIgnoreCase("y") || managerOutput.equalsIgnoreCase("true") || managerOutput.equalsIgnoreCase("t")))
	{
		managerOutput="yes";
		preManagerOutput = "Yes";
	}
	else
	{
		managerOutput="no";
		preManagerOutput = "No";
	}
	if(mgrOutputOverWirte != null &&( mgrOutputOverWirte.equalsIgnoreCase("yes") || mgrOutputOverWirte.equalsIgnoreCase("y") || mgrOutputOverWirte.equalsIgnoreCase("true") || mgrOutputOverWirte.equalsIgnoreCase("t")))
	{
		mgrOutputOverWirte="yes";
	}
	else
	{
		mgrOutputOverWirte="no";
	}
	if(outErrMode != null)
	{
		if(outErrMode.equalsIgnoreCase("Yes"))
			managerOutput = "yes";
		else if(outErrMode.equalsIgnoreCase("No"))
			managerOutput = "no";
	}
%>
<html>
<title>Manager Restart</title>
<head>
<link REL = "StyleSheet" href = "/final/admin/eg_styles/adminstyle_blue.css"/>
<script language="javascript" src="/final/admin/eg_scripts/timeout.js"></script>
<script language="javascript">
var isDasableDebug = '<%=disableDebug%>' == 'yes' ? true : false;
function enableOutErrMode(val)
{
	if(isDasableDebug)
	{
		document.getElementById('mgrOutputYes').checked = false;
		document.getElementById('mgrOutputNo').checked = true;
		return;
	}
	window.location.href = "ManagerRestart.jsp?sessionInUse=true&val="+val;
}

function updateProcess()
{
	var queryString ="";
	var formObj = document.mgrfrm;
	var isRestart = "No";
<%
	if(!EgInstallInfo.isClusterSupported)
	{
%>
		var stlnMgr = formObj.stlnMgrRestart.value;
		queryString +="stlnMgr="+stlnMgr;
		if(stlnMgr == "yes")
			isRestart = "Yes";
<%
	}
	else
	{
%>
		var priMgr = formObj.priMgrRestart.value;
		var secMgr = formObj.secMgrRestart.value;
		queryString +="priMgr="+priMgr+"&secMgr="+secMgr;
		if(priMgr == "yes" || secMgr == "yes")
			isRestart = "Yes";
<%
	}
%>
	var pre_err_mode = "";
	var out_err_mode = "";
	var mgrOut_Err = "";
	var pre_mgrOut = "";
	if(!isDasableDebug)
	{
		var mgrOut_Err = formObj.mgrOutput.value;
		var pre_mgrOut = formObj.$_mgrOutput.value;
		if(mgrOut_Err == "Yes")
		{
			out_err_mode = formObj.mgrOutputOverWirte.value;
			pre_err_mode = formObj.$_mgrOutputOverWirte.value;
		}
	}

	if(isRestart == "Yes" || (!isDasableDebug && pre_mgrOut != mgrOut_Err || pre_err_mode != out_err_mode))
	{
		var message = 'Are you sure you want to proceed with your changes?';
		if(confirm(message))
		{
			queryString +="&mgrOut_Err="+mgrOut_Err+"&out_err_mode="+out_err_mode;
			formObj.action = "ManagerRestartp.jsp?"+queryString;
			formObj.submit();
		}
		else
		{
			formObj.action = "ManagerRestart.jsp?sessionInUse=true";
			formObj.submit();
		}
	}
}
</script>
</head>
<body >
<form name="mgrfrm" 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;RESTART <%=manager_label.toUpperCase()%> / ENABLE DEBUGS</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="30%" 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 restart the <%=manager_label%> and enable the debugs.</td>
				</tr>
			</table>
		</td>
	</tr>
</table><br>
<table border="0" align="center" cellspacing="0" cellpadding="0" width="60%" class="eg_cellbglits">
<%
	if(!EgInstallInfo.isClusterSupported)
	{
%>
		<tr>
			<th class="form_border"  nowrap width="50%">
				<egui:intnl text="<%=restart_label%>"/>&nbsp;
			</th>
			<td class="form_border"  nowrap width="4%"> &nbsp;:</td>
			<td class="form_border" nowrap width="50%">
				<table  width="70%" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="stlnMgrRestart" value="yes" name="stlnMgrRestart">
							<egui:intnl text="admin.common.Yes"/>
						</td>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="stlnMgrRestart" checked name="stlnMgrRestart" value="no">
							<egui:intnl text="admin.common.No"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<input type='hidden' name='$_stlnMgrRestart' value='Restart the manager now ?$No'>
<%
	}
	else
	{
%>
		<tr>
			<th class="form_border"  nowrap width="50%">
				<egui:intnl text="admin.settings.Restart the primary manager"/>&nbsp;
			</th>
			<td class="form_border"  nowrap width="4%"> &nbsp;:</td>
			<td class="form_border" nowrap width="50%">
				<table  width="70%" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="priMgrRestart" name="priMgrRestart" value="yes">
							<egui:intnl text="admin.common.Yes"/>
						</td>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="priMgrRestart" name="priMgrRestart" value="no" checked>
							<egui:intnl text="admin.common.No"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<th class="form_border"  nowrap width="50%">
				<egui:intnl text="admin.settings.Restart the secondary manager"/>&nbsp;
			</th>
			<td class="form_border"  nowrap width="4%"> &nbsp;:</td>
			<td class="form_border" nowrap width="50%">
				<table  width="70%" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="secMgrRestart" name="secMgrRestart" value="yes">
							<egui:intnl text="admin.common.Yes"/>
						</td>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="secMgrRestart" name="secMgrRestart" value="no" checked>
							<egui:intnl text="admin.common.No"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
<%
	}
%>
		<tr>
			<th class="form_border"  nowrap width="50%" id="debuglabel">
				<egui:intnl text="<%=output_label%>"/>
			</th>
			<td class="form_border"  nowrap width="4%" id="colId"> &nbsp;:</td>
			<td class="form_border" nowrap width="50%">
				<table  width="70%" cellspacing="0" cellpadding="0" border="0" id="mgrDebug">
					<tr>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="mgrOutputYes" name="mgrOutput" value="Yes" onclick="javascript:enableOutErrMode(this.value)" <%=managerOutput.equalsIgnoreCase("yes")?"checked":""%>>
							<egui:intnl text="admin.common.On"/>
						</td>
						<td class="eg_subcontent" width="35%">
							<input type="radio"class="eg_input" id="mgrOutputNo" name="mgrOutput" value="No" onclick="javascript:enableOutErrMode(this.value)" <%=managerOutput.equalsIgnoreCase("no")?"checked":""%>>
							<egui:intnl text="admin.common.Off"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<input type='hidden' id='$_mgrOutput' name='$_mgrOutput' value='<%=preManagerOutput.equalsIgnoreCase("yes")?"Yes":"No"%>'>
<%
	if(managerOutput.equalsIgnoreCase("yes"))
	{
%>
		<tr>
			<th class="form_border" nowrap width="50%">
				<egui:intnl text="admin.settings.Output and Error mode"/>
			</th>
			<td class="form_border" nowrap width="4%"> &nbsp;:</td>
			<td class="form_border" nowrap width="50%">
				<table  width="70%" cellspacing="0" cellpadding="0" border="0">
					<tr>
						<td class="eg_subcontent" width="35%">
							<input type="radio" class="eg_input" id="mgrOutputOverWirte" name="mgrOutputOverWirte" value="Yes" <%=mgrOutputOverWirte.equalsIgnoreCase("yes")?"checked":""%>>
							<egui:intnl text="admin.common.Overwrite"/>
						</td>
						<td class="eg_subcontent" width="35%">
							<input type="radio"class="eg_input" id="mgrOutputOverWirte" name="mgrOutputOverWirte" value="No" <%=mgrOutputOverWirte.equalsIgnoreCase("no")?"checked":""%>>
							<egui:intnl text="admin.common.Append"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
<%
	}
%>
		<input type='hidden' id='$_mgrOutputOverWirte' name='$_mgrOutputOverWirte' value='<%=mgrOutputOverWirte.equalsIgnoreCase("yes")?"Yes":"No"%>'>
		<tr>
			<td colspan="4">
			<div style="margin-top:30px;margin-bottom:10px;display:none" id="dispDiv" align="center">
				<fieldset align="center">
					<legend>Note</legend>
					<label id="msg" style="font-family:Arial Narrow;font-size:13px"></label>
				</fieldset>
			</div>
			</td>
		</tr>
		<tr>
			<td align="center" colspan="3" class=<%=form_border%>>
				<table align="center" cellspacing="0" cellpadding="2" width="100%" border="0"><br>
					<tr>
						<td colspan="3" align="center" nowrap class=<%=form_border%>>
						<input type="button" value='<egui:intnl text="admin.common.Update"/>' name="update" style="width: 85px;" id="eg_back" onClick="javascript:updateProcess();">
						</td>
					</tr>
					<tr>
						<td style="font-weight:normal;font-size:12px" height="<%=h%>" colspan="3" align="center"><span><%=resultMsg%></span></td>
					</tr>
				</table>
			</td>
		</tr>
</table>
</form>
</body>
</html>
<script>

if(isDasableDebug)
{
	document.getElementById("debuglabel").style.opacity = "0.5";
	document.getElementById("colId").style.opacity = "0.5";
	document.getElementById("mgrDebug").style.opacity = "0.5";
	document.getElementById("dispDiv").style.display = "block";
	document.getElementById("debuglabel").innerHTML = "* <%=manager_label%> Output and Error";
	document.getElementById("msg").innerHTML = "* <%=manager_label%> output and error has been manually enabled.";
}
</script>


