<%@ page import = "java.util.*"%>
<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.eg.EgMemCheck"%>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "net.sf.json.JSONObject"%>
<%@ page import = "net.sf.json.JSONArray"%>
<%@ taglib prefix = "egui" uri = "../../../WEB-INF/eg-taglib.tld"%>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="../../../admin/EgTrackerAJSON.jsp" %>

<%
try
{
	User user = registry.getUser(session.getId());
	String userId = user.getLoginID();

	String newWindow = request.getParameter("newwindow");
	String moduleEntry = null;
	if (StringUtils.isNull(newWindow))
	{
		moduleEntry = (String) session.getAttribute("egEntryMain");
	}
	else
	{
		moduleEntry = (String) session.getAttribute("egEntryChild");
	}

	if (moduleEntry == null || moduleEntry.equalsIgnoreCase("null"))
	{
		moduleEntry = "admin";
	}
	
	EgMemCheck memCheck = new EgMemCheck();
	boolean isIntegrationConsoleEnabled = memCheck.isExtensible();
	IniFile uiIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");
	IniFile serIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_services.ini");
	IniUI iniUI = IniUI.getInstance();
	String userLanguage = iniUI.getDefaultLanguage();
	if (user != null)
	{
		userLanguage = user.getLanguage();
	}
	JSONObject rootJson = new JSONObject();

	EgMappingInfo mappingInfo = new EgMappingInfo(userLanguage);

	String modules_A[] = {"admin","monitor","reporter","configmgmt"};

	IniFile QMIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_quickmenu.ini");

	String strModule = request.getParameter("moduleName");
	
	String strModule_A = "";
	String strSubject = "";
	if (strModule.equalsIgnoreCase("Admin"))
	{
		strSubject = "ADMIN_QUICK_MENU";
		strModule_A = modules_A[0];
	}
	else if (strModule.equalsIgnoreCase("Monitor"))
	{
		strSubject = "MONITOR_QUICK_MENU";
		strModule_A = modules_A[1];
	}
	else if (strModule.equalsIgnoreCase("Reporter"))
	{
		strSubject = "REPORTER_QUICK_MENU";
		strModule_A = modules_A[2];
	}
	else if (strModule.equalsIgnoreCase("Configuration"))
	{
		strSubject = "CONFIG_QUICK_MENU";
		strModule_A = modules_A[3];
	}

	String strQuickMenuItems = QMIni.getValue(user.getLoginID(),strModule);
	ArrayList aListQuickMenuItems = new ArrayList();
	if (strQuickMenuItems != null && strQuickMenuItems.length() > 0)
	{
		StringTokenizer strTokens = new StringTokenizer(strQuickMenuItems,",");
		while (strTokens.hasMoreTokens())
		{
			String strToken = strTokens.nextToken();
			aListQuickMenuItems.add(strToken);
		}
	}

	String entry = request.getParameter("entry");
	StringBuffer enabledList = new StringBuffer(500);
	String chCkcomp = serIni.getValue("MISC_ARGS","DisableTrendComputation");
	if (aListQuickMenuItems != null && !aListQuickMenuItems.isEmpty())
	{
		for (int j=0;j<aListQuickMenuItems.size();j++)
		{
			String strMenuVar = (String)aListQuickMenuItems.get(j);
			if(chCkcomp != null && (chCkcomp.equalsIgnoreCase("YES") || chCkcomp.equalsIgnoreCase("TRUE")))
			{
				if(strMenuVar != null && (strMenuVar.equalsIgnoreCase("TrendGraph") || strMenuVar.equalsIgnoreCase("SummaryGraph")))
					continue;
			}
			if (!isIntegrationConsoleEnabled && (strMenuVar.equalsIgnoreCase("BackupAndRevertConfig") || 
			strMenuVar.equalsIgnoreCase("ICComponent") || strMenuVar.equalsIgnoreCase("ICLayer") || strMenuVar.equalsIgnoreCase("ICTest")))
			{
				continue;
			}
			String strQuery = "/final/admin/EgChangeModule.jsp?moduleName="+strModule+"&menuItem="+strMenuVar+"&newwindow="+newWindow;
			if (!StringUtils.isNull(moduleEntry) && moduleEntry.equalsIgnoreCase(strModule) && moduleEntry.equalsIgnoreCase("reporter"))
			{
					String menuItemValue = uiIni.getValue(strSubject,strMenuVar);
					strQuery = menuItemValue;
					enabledList.append("<a href='javascript:void(0)' onClick='javascript:goToReporterUrl(\""+strQuery+"\",this)' class='quickmenuHoverStyle'><div>"+mappingInfo.getQuickLinkDescription(strModule_A+".quickmenu."+strMenuVar)+"</div></a>");
			}
			else if (!StringUtils.isNull(moduleEntry) && moduleEntry.equalsIgnoreCase(strModule))
			{
				String menuItemValue = uiIni.getValue(strSubject,strMenuVar);
				strQuery = menuItemValue;
				enabledList.append("<a href='"+strQuery+"' class='quickmenuHoverStyle'><div>"+mappingInfo.getQuickLinkDescription(strModule_A+".quickmenu."+strMenuVar)+"</div></a>");
			}
			else
			{
				enabledList.append("<a href='javascript:void(0)' onClick='javascript:goToUrl(\""+strQuery+"\")' class='quickmenuHoverStyle'><div>"+mappingInfo.getQuickLinkDescription(strModule_A+".quickmenu."+strMenuVar)+"</div></a>");

			}
			rootJson.put("enabledQuickLinks",strMenuVar);
		}
		rootJson.put("enabledList",enabledList.toString());
	}
	
	session.setAttribute("globalSearchLastSessionval","");

	response.getWriter().write(rootJson.toString());
}
catch(Exception e)
{
	e.printStackTrace();
}
%>



