<%
/**
*  File         : EgConfigFileEdit.jsp
*  Purpose      : To edit ini entries
*  Version      : 1.0
*  Creation Date: 21/11/2006
*  Author       : Antony, Nagarajan
*/
%>

<%@ page import="com.eg.IniFile" %>
<%@ page import="com.eg.EgInstallInfo" %>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="com.eg.EgCrypt" %>
<%@ page import="egurkha.EgUIUtils" %>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>

<%
	String cpwd = "";
	String tempCpwd = request.getParameter("cpwd");
	if (tempCpwd != null && tempCpwd.length() > 0)
	{
		cpwd = EgCrypt.encrypt(tempCpwd);
	}

	String s_inifile=request.getParameter("ini_list");
	String sel_subject= request.getParameter("subject_list");
	String s_subject= EgUIUtils.decodeSecurityChar(sel_subject);
	String option=request.getParameter("op");
	String sub=request.getParameter("subject");
	String sel_var= request.getParameter("variable");
	if(sel_var!=null)
		sel_var = EgUIUtils.decodeSecurityChar(sel_var.trim());
	String value=request.getParameter("value");
	if(value!=null)
		value = EgUIUtils.decodeSecurityChar(value.trim());

	String newVar=request.getParameter("Newvariable");
	String installdir=EgInstallInfo.getInstallDir();
	String[] subjects=null;
	if(s_inifile!=null)
	{
		IniFile fi=new IniFile(installdir+ "/manager/config/"+s_inifile);
		subjects=fi.getSubjects();
	}
	String[] s_vars = null;
	if(option != null && (option.equalsIgnoreCase("addVariable")))
	{
		IniFile fi=new IniFile(installdir+ "/manager/config/"+s_inifile);
		s_vars = fi.getVariables(sel_subject);
	}
%>

<html>
<head>
<title>Configuration File Updation</title>
<meta name="created" content="09/04/2001">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<Link REL = "StyleSheet" href = "eg_styles\adminstyle_blue.css" type="text/css"/>
<script language="javascript" src="/final/admin/eg_scripts/timeout.js"></script>
<script language="JavaScript" src="/final/scripts/utilities/EncodeDecodeParams.js"></script>
<script language="JavaScript">
function save()
{
	var op='<%=option%>';
	var isVarExists = false;
	if(op=='newSubject')
	{
		if(document.form1.subject.value.length==0)
		{
			alert("Please Enter a subject ");
			document.form1.subject.focus();
			return false;
		}
		var exists=false;
<%
	for(int i=0;i<subjects.length;i++)
	{
		String ex_subject = egurkha.EgUIUtils.encodeSecurityChar(subjects[i]);
%>
		var ex_sub='<%=ex_subject%>';
		if(filterDecode(ex_sub) == document.form1.subject.value)
			exists=true;
<%
	}
%>
	}
	if(document.form1.variable.value.length==0)
	{
		alert("Please Enter a variable");
		document.form1.variable.focus();
		return false;
	}
<%
	if(option != null && (option.equalsIgnoreCase("addVariable")))
	{
		for(int i=0;i<s_vars.length;i++)
		{
%>
			if('<%=s_vars[i]%>' == document.form1.variable.value)
			{
				isVarExists = true;
			}
<%
		}
	}
%>

	/*if(document.form1.value.value="")
	{
		
		alert("Please  Enter a value");
		document.form1.value.focus();
		return false;
		
	}
	*/

	if(exists==true)
	{
		alert("subject already exists");
		document.form1.subject.focus();
		return false;
	}
	if(isVarExists)
	{
		alert("variable already exists");
		document.form1.variable.focus();
		return false;
	}
	var sel_ini_file = '<%=s_inifile%>';
	if(form1.subject != undefined)
	{
		form1.subject.value = filterEncode(form1.subject.value);
	}
	document.form1.variable.value = filterEncode(document.form1.variable.value);
	document.form1.value.value = filterEncode(document.form1.value.value);
	document.form1.action = "EgConfigFile.jsp?sessionInUse=true&op=<%=option%>&ini_list=" + encodeURIComponent(sel_ini_file);
	document.form1.submit();
	return true;
}

function goBack()
{
	var op='<%=option%>';
	var sel_sub = '<%=sel_subject%>';
	document.form1.variable.value = filterEncode(document.form1.variable.value);
	document.form1.value.value = filterEncode(document.form1.value.value);
	document.form1.action = "EgConfigFile.jsp?sessionInUse=true&ini_list=<%=s_inifile%>&subject_list="+ encodeURIComponent(sel_sub);
	document.form1.submit();
}

</script>
</head>
<body style="overflow:auto" id="space6" >
<form name="form1" method="post" ONSUBMIT="if (this.submitted) return true; else return false;" style="margin:0px">
<input type="hidden" name="cpd" value="<%=cpwd%>">
<input type="hidden" name="subject_list" value="<%=sel_subject%>">
<input type="hidden" name="old_variable" value="<%=egurkha.EgUIUtils.encodeSecurityChar(sel_var)%>">

<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0">
	<tr>
		<td id="eg_blankspace" height="22" nowrap>&nbsp;</td>
	</tr>
	<tr>
		<td height="20" align="center" width="100%">
			<table align="center" width="85%" cellspacing="0" cellpadding="4" border="0">
				<tr>
					<td height="24" nowrap align="left" width="50%">&nbsp;<strong>eG CONFIGURATION FILE UPDATION</strong></td>
					<td height="24" nowrap align="right"><input type="button" name="Back" value="Back" onclick="goBack()" style="width: 80px;" class="eg_lightbutton"></td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td id="eg_blankspace" height="10" nowrap>&nbsp;</td>
	</tr>
	<tr>
		<td height="20" align="center" width="100%">
			<table align="center" width="85%" cellspacing="0" cellpadding="4" border="0">
				<tr>
					<td height="24" nowrap align="right" width="25%" 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 add/modify a subject/variable/value in an INI file.</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td id="eg_blankspace" height="22" nowrap>&nbsp;</td>
	</tr>
	<tr>
		<td width="100%" id="eg_whitebg" align="center" height="100%" valign="top">
			<table align="center" width="85%" cellspacing="0" cellpadding="4" border="0">
				<tr>
					<td align="center" valign="top">
						<table align="center" cellspacing="0" cellpadding="0" width="100%" 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="3"><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_border">&nbsp;</td>
								<td class="form_border" width="250" nowrap> INI file</td>
								<td class="form_border" width="20" align="center" nowrap>:</td>
								<td class="form_border" width="100%" height="21"><%=s_inifile%></td>
								<td class="form_border">&nbsp;</td>
							</tr>
							<tr>
								<td class="form_border">&nbsp;</td>
								<td class="form_border" width="250" nowrap> Subject</td>
								<td class="form_border" width="20" align="center" nowrap>:</td>
								<td class="form_border" width="100%" height="21" >
<%
	if(option.equals("addVariable") || option.equals("modify"))
	{
		out.println(s_subject);
	}
	else
	{
%>
									<input type="text" name="subject" value="" size="85">
<%
	}
%>
								</td>
								<td class="form_border">&nbsp;</td>
							</tr>
							<tr>
								<td class="form_border">&nbsp;</td>
								<td class="form_border" width="250" nowrap> Variable</td>
								<td class="form_border" width="20" align="center" nowrap>:</td>
								<td class="form_border" width="100%" height="21"><input type="text" size="85" name="variable" id="variable" align="left" value="<%=option.equals("modify")?sel_var:""%>" ></td>
								<td class="form_border">&nbsp;</td>
							</tr>
							<tr>
								<td class="form_spacing">&nbsp;</td>
								<td class="form_spacing" width="250" nowrap> Value</td>
								<td class="form_spacing" width="20" align="center" nowrap>:</td>
								<td class="form_spacing" width="100%" height="21" ><textarea  rows="5" cols="85"  name="value" 
								id ="value"><%out.print(option.equals("modify")?value:"");%></textarea></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="3" 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="7" height="6" border="0"></td>
							</tr>
							<tr>
								<td height="30" id="eg_whitebg" valign="bottom" colspan="5" align="center">&nbsp; <input type="button" name = "clear" value="Update" style="width: 80px;" class="eg_back" onClick="javascript:save()">
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
</form>
</body>
</html>



