<%@ include file = "../../EgTrackerAJSON.jsp" %>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.eg.EgConfigFilesSync"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "com.egurkha.admin.AuditLogThread"%>
<%@ page import="net.sf.json.*"%>

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

	JSONObject rootJson = new JSONObject();

	IniFile inifile = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_services.ini",true);
	String autoRegisterSm_pre = inifile.getValue("MISC_ARGS","AutoRegisterSm");

	String autoRegisterSm = request.getParameter("autoRegisterSm");
	if(autoRegisterSm == null || autoRegisterSm.trim().length()==0 || autoRegisterSm.trim().equalsIgnoreCase("null"))
	{
		autoRegisterSm="no";
	}
	else
	{
		autoRegisterSm = (autoRegisterSm.equals("true") || autoRegisterSm.equals("yes"))?"yes":"no";
	}
	if(autoRegisterSm_pre != null && autoRegisterSm != null && !autoRegisterSm_pre.equalsIgnoreCase(autoRegisterSm))
	{
		inifile.setValue("MISC_ARGS","AutoRegisterSm",autoRegisterSm);
		inifile.saveFile();

		AuditLogThread auditLogThread = new AuditLogThread();
		auditLogThread.setValue("Category","Admin");
		auditLogThread.setValue("User_id",_user.getLoginID());
		auditLogThread.setValue("Host_ip",_user.getUserIP(session.getId()));
		auditLogThread.setValue("Session_id",session.getId());
		auditLogThread.setValue("Module","Manager Settings");
		auditLogThread.setValue("Activity","Supermanager settings");

		auditLogThread.setPreviousValue("Allow auto registration from eG SuperManager",autoRegisterSm_pre.equalsIgnoreCase("yes")?"Yes":"No");
		auditLogThread.setCurrentValue("Allow auto registration from eG SuperManager",autoRegisterSm.equalsIgnoreCase("yes")?"Yes":"No");

		auditLogThread.setValue("Description","Supermanager settings has been updated");
		auditLogThread.sendItToDB();
	}

	EgConfigFilesSync.releaseInstance(inifile);

	out.println(rootJson.toString());
%>