<%@ taglib prefix = "egui" uri = "../../../WEB-INF/eg-taglib.tld"%>
<%@ include file="../../../admin/EgAdminTracker.jsp" %>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.EgUserRole"%>
<%@ page import = "com.egurkha.EgUserPermission"%>
<%@ page import = "com.eg.EgMemCheck"%>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "com.eg.EgCrypt"%>
<%@ page import = "com.eg.EgSpecsInfo"%>
<%@ page import = "com.egurkha.ini.*"%>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.egurkha.EgConstants"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "java.util.Vector"%>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "com.eg.EgConfigConstants"%>
<%@ page import = "com.eg.EgServicesInfo"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import = "java.util.Date"%>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "java.util.Calendar"%>
<%@ page import = "java.util.TimeZone"%>
<%@ page import="com.eg.EgTopoInfo"%>
<%@ page import="com.eg.EgManagersIniForManager"%>
<%@ page import = "com.eg.EgURLEncoder"%>
<%@ page import = "com.eg.EgConfigInfo" %>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.egurkha.monitor.EgServiceMappingBean"%>
<%@ page import = "com.eg.EgDbAdapterTypeUI"%>
<%@ page import = "egurkha.EgDbAdapterUI"%>
<%@ page import = "com.egurkha.util.DateUtil"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "com.eg.EgUsersInfo"%>
<%@ page import = "com.eg.EgManagersInfo"%>
<%@ page import = "com.egurkha.EgTimeZoneConverter"%>
<%@ page import="egurkha.reporter.ErUtils"%>
<%@ page import="net.sf.json.*" %>
<%@ page import = "com.egurkha.monitor.OneClickDashboardModel"%>
<%@ page import = "java.io.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%!
	boolean noManagersConfigured = false;
	EgSpecsInfo specsinfo=new EgSpecsInfo("manager");
	EgCrypt crypt=new EgCrypt();
	IniUI ui = IniUI.getInstance();
	public boolean isValidDomainUser(String l_user)
	{
		l_user = StringUtils.replace(l_user,"\\","/");
		IniFile iniFile=new IniFile(EgInstallInfo.getInstallDir()+"/manager/config/eg_authenticate.ini");
		if (iniFile != null && l_user != null && l_user.indexOf("/") != -1)
		{
			l_user = l_user.substring(0,l_user.indexOf("/")).trim();
			String subjs[]=iniFile.getSubjects();
			if (subjs!=null && subjs.length>0)
			{
				for (int i=0;i<subjs.length ; i++)
				{
					String domainDisName = subjs[i];
					if (domainDisName != null && domainDisName.equalsIgnoreCase(l_user))
					{
						return true;
					}
				}
			}
		}
		return false;
	}

	public String skinStyleSheet(User user,String module)
	{
		return skinStyleSheet(user,module,false);
	}

	public String skinStyleSheet(User user,String module,boolean returnSkin)
	{
		String skin = "";
		String skinStyleSheet="";
		String thisLanguage = ui.getDefaultLanguage();
		String  langSkin="";
		boolean isLangSkin=false;
		boolean isSingleByte=false;

		if (user!=null)
		{
			user.setUserLanguageAndSkins();
			String userLang = user.getLanguage();
			if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
			{
				thisLanguage=userLang;
			}
		}
		if(thisLanguage.equals("ch_CH") ||  thisLanguage.equals("ja_JP") || thisLanguage.equals("ko_KR"))
		{
			isLangSkin=true;
		}
		if(thisLanguage.equals("pt_BR") ||  thisLanguage.equals("it_IT") || thisLanguage.equals("fr_FR") || thisLanguage.equals("es_ES") || thisLanguage.equals("de_DE"))
		{
			isSingleByte=true;
		}
		try
		{
			String result1 = null;
			String result2 = ui.getDefaultSkin(module);
			String result3 = null;
			result1 = "/final";
			result3 = ".css";
			if (user==null)
			{
				//System.out.println("No user logged in. Getting the default skins!");
				/*if (result2!=null)
				{
					result2 = "admin/eg_styles/adminstyle_"+result2;
				}else
				{
					result2 = "admin/eg_styles/adminstyle_gray";
				}*/
				result2 = "styles/eGLightTheme";
			}
			else if(module!=null && module.equalsIgnoreCase("admin"))
			{
				skin = user.getAdminSkin();
				result2 = "/styles/eG"+skin+"Theme";
				/*if(isLangSkin)
					result2 = "/styles/skin_" +skin;
				if(isSingleByte)
					result2 = "/styles/skin_" +skin;*/
			}
			else if(module!=null && module.equalsIgnoreCase("adminindex"))
			{
				skin = user.getAdminSkin();
				result2 = "/styles/eG"+skin+"Theme";
				/*if(isLangSkin)
					result2=result2+"_multi";
				if(isSingleByte)
					result2=result2+"_singlebyte";*/
			}
			else if (module!=null && module.equalsIgnoreCase("monitor"))
			{
				skin = user.getMonitorSkin();
				result2 = "/styles/eG"+skin+"Theme";
	
			}
			else if (module!=null && module.equalsIgnoreCase("reporter"))
			{
				skin = user.getReporterSkin();
				result2 =  "/styles/eG"+skin+"Theme";

			}
			else if (module!=null && module.equalsIgnoreCase("config"))
			{
				skin = user.getConfigSkin();
				result2 ="/styles/eG"+skin+"Theme";
				//result2 = "/config/styles/ec_style_gray";
				/*if(isLangSkin)
					result2=result2+"_multi";
				if(isSingleByte)
					result2=result2+"_singlebyte";*/
			}
			else if (module!=null && module.equalsIgnoreCase("sla"))
			{
				skin = user.getSlaSkin();
				result2 = "/styles/eG"+skin+"Theme";
			}
			else if (module!=null && module.equalsIgnoreCase("configindex"))
			{
				skin = user.getConfigSkin();
				result2 = "/styles/eG"+skin+"Theme";
				//result2 = "/styles/skin_" +skin;
				
			}
			if (result2!=null && result2.equals("admin/eg_styles/adminstyle_"))
				result2="/config/styles/ec_style_gray";

			skinStyleSheet = result1 + result2 + result3;
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		if(returnSkin)
			return skin;
		else
			return skinStyleSheet;
	}
%>

<%
	response.setContentType("application/json;charset=UTF-8");
	response.setHeader("Cache-Control", "no-store");
	response.setHeader("Pragma", "no-cache");
	response.setDateHeader("Expires", -1); 
	String remoteurl="";
	String searchVals = "";
    String globalSearchLastSessionURL = (String) session.getAttribute("globalSearchLastSessionURL");
 	String  selectedSkin="admin";

	if(globalSearchLastSessionURL != null )
	 {
		remoteurl=globalSearchLastSessionURL;
	}
	String action = request.getParameter("action");
	String  globalSearchLastSessionval= (String) session.getAttribute("globalSearchLastSessionval");
	if ( globalSearchLastSessionval != null && action == null )
	{
		searchVals=globalSearchLastSessionval;
	 }  
	 String tabchanging="true";
	 String testing = (String) session.getAttribute("testing");	
	 if(testing != null && testing.equalsIgnoreCase("false"))
	 {
		 tabchanging="false";
	 }
	 String hasNotificationWindow = (String)session.getAttribute("hasNotificationWindow");
	 if (hasNotificationWindow == null || hasNotificationWindow.length() == 0)
	 {
		hasNotificationWindow = "yes";
	 }
%>

<jsp:useBean id = "configmsg" scope = "page" class = "egurkha.TransactionBean"/>
<jsp:useBean id="esmb" scope="page" class="com.egurkha.monitor.EgServiceMappingBean" />

<%
try
{
	boolean isEnableSLA = ui.isSLAEnabled();
	String queryString = request.getQueryString();
	EgConfigInfo configInfo = new EgConfigInfo("manager");
	EgDiscInfo discInfo = new EgDiscInfo("manager");
	String servicesFileName = configInfo.getServicesFile ("manager");
	IniFile servicesFilePtr = new IniFile (servicesFileName);
	String s_showMonitorProfile = servicesFilePtr.getValue("MISC_ARGS","ShowMonitorProfile");	
	s_showMonitorProfile=(s_showMonitorProfile==null || s_showMonitorProfile.trim().length()==0)?"":s_showMonitorProfile;
	//String sessionID = session.getId();
	String integrity = request.getParameter("integritycheckviolated");
	String integrityMessage = "";
	String quickLinksClicked = request.getParameter("quickLinksClicked");
	if (StringUtils.isNull(quickLinksClicked))
	{
		quickLinksClicked = "false";
	}

	EgServicesInfo serviceInfo = new EgServicesInfo("manager");
	UserRegistry ur = UserRegistry.getInstance();
	String hostip=_user.getUserIP(sessionID);
	User user = ur.getUser(sessionID);
	user.setUserLanguageAndSkins();
	String smartAlertValue=request.getParameter("smartAlertValue");
		//-------Print Current year : Vijay 8.1.2008-----------------
		int currYear = 0;

		Calendar cal = Calendar.getInstance();
		currYear = cal.get(cal.YEAR);
		//-------------------------Print Current year------------------
	//String managerIp=specsinfo.getEGServer();
	boolean isIE = true;
	String configHomePage = "/final/servlet/com.eg.EcConfigurationServletNew?cmd=Home";
	String userAgent = request.getHeader("USER-AGENT");
	if (userAgent==null) userAgent="";
	if (userAgent.indexOf("MSIE")==-1)
		isIE=false;
	boolean isChrome=true;
	if(userAgent.indexOf("Chrome")==-1)
	isChrome=false;
	//EgHelpParser egHelp = new EgHelpParser();
	String helpURL = "";
	String url="";
	String entry   = request.getParameter("entry");
	String smartParam = request.getParameter("smartParam");
	String newWindow=request.getParameter("newwindow");
	String fromSm = request.getParameter("fromsuper");
	if(fromSm == null)
		fromSm = (String) session.getAttribute("fromSm");
	String fromQuickLaunch = request.getParameter("fromQuickLaunchPage");
	String access=request.getParameter("access");
	String accessPageName=request.getParameter("accessPageName");
	String layer=request.getParameter("layer");
	String pressed = request.getParameter("pressed");
	String hideMonitoringDomainPopup = request.getParameter("hideMonitoringDomainPopup");
	boolean showMonitoringDomainPopup=false;
	boolean hideMonDomainPopup=(hideMonitoringDomainPopup!=null && hideMonitoringDomainPopup.equalsIgnoreCase("true"));
	String fromPage = request.getParameter("fromPage");//modifed on 24/10/07 stalin to not allow to display the popup of alarm page when go through egNewWindowAlert
	String isDisableMydashboardPopout="false";
	String s_iniFile = EgInstallInfo.getInstallDir()+ "/manager/config/eg_customdashboard.ini";
	IniFile customDashboard = new IniFile(s_iniFile);
	String DisableMydashboardPopout=customDashboard.getValue("DASHBOARD_SETTINGS","DisableMydashboardPopout");
	if(DisableMydashboardPopout!=null && DisableMydashboardPopout.equalsIgnoreCase("no"))
		isDisableMydashboardPopout="true";

	String showMonDomainPopup=customDashboard.getValue("DASHBOARD_SETTINGS","showMonitoringDomainPopup");
	if(showMonDomainPopup!=null && showMonDomainPopup.equalsIgnoreCase("yes"))
	{
		showMonitoringDomainPopup=true;
	}
	if(layer==null)
	{
		layer="";
	}
	String test=request.getParameter("test");
	if(test==null)
	{
		test="";
	}
	String descriptor=request.getParameter("descriptor");
	if(descriptor==null)
	{
		descriptor="";
	}
	else if(descriptor!=null)
	{
		descriptor=descriptor.trim();
	}
	boolean isFromQuickLaunch= (fromQuickLaunch != null && fromQuickLaunch.equalsIgnoreCase("yes"));
	String displayTab = request.getParameter("displayTab");
	if (entry == null)
		throw new IllegalArgumentException("EgError: User access control specification not received");

	boolean javaVersion=crypt.checkJavaVersion();
	/** For zone map changes */
	boolean mapEnabled = false;
	IniFile uiIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");
	String currentDateFormat = uiIni.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	String showAlarmsInLightBox=uiIni.getValue("ALARMS","showAlarmsInLightBox");
	String showSlaAlertsPopup=uiIni.getValue("ALARMS","showSlaAlertsPopup");
	String mapLicense = uiIni.getValue("ZONE_MAP","mapEnabled");
	mapEnabled = (mapLicense != null && mapLicense.equalsIgnoreCase("yes"));
	boolean isShowAlarmsInLightBox = false;
	boolean isShowSlaAlertsPopup = false;
	if(EgInstallInfo.isSuperManager)
	{
		Object firstTimeLogin = session.getAttribute("firstTimeLogin");
		if(firstTimeLogin == null)
		{
			session.setAttribute("firstTimeLogin","no");
		}
		noManagersConfigured = EgManagersInfo.getInstance().getConfiguredManagers().isEmpty();
		if(firstTimeLogin == null && entry.equalsIgnoreCase("monitor") && user.getLoginID().equals("egsm") && noManagersConfigured)
		{
			entry = "admin";
		}
		else if (entry .equalsIgnoreCase("admin") && !user.getLoginID().equals("egsm"))
			entry = "monitor";
	}
	boolean isAdmin   = entry.equalsIgnoreCase("admin");
	boolean isMonitor = entry.equalsIgnoreCase("monitor");
	boolean isReport  = entry.equalsIgnoreCase("reporter");
	boolean isConfig  = entry.equalsIgnoreCase("config");
	boolean isSla  = entry.equalsIgnoreCase("sla");
	
	String indexMegalink = uiIni.getValue("NAVIGATION_MENU_OPTIONS","EnableMegaMenu");
	String indexMenuLink = uiIni.getValue("NAVIGATION_MENU_OPTIONS","EnableMenuBar");
	boolean isIndexMegaLinkEnabled=true;
	boolean isIndexMenuLinkEnabled=true;
	if(indexMegalink!=null && indexMegalink.equalsIgnoreCase("yes"))
		isIndexMegaLinkEnabled = false;

	if(indexMenuLink!=null && indexMenuLink.equalsIgnoreCase("yes"))
		isIndexMenuLinkEnabled = false;

	String stateIcons = uiIni.getValue("STATE_ICONS","Default");
	
	if(isMonitor && (showAlarmsInLightBox!=null && showAlarmsInLightBox.equalsIgnoreCase("yes") ||  showAlarmsInLightBox.equalsIgnoreCase("true")))
	{
		isShowAlarmsInLightBox = true;
	}
	if(isSla && isEnableSLA && (showSlaAlertsPopup!=null && showSlaAlertsPopup.equalsIgnoreCase("yes") ||  showSlaAlertsPopup.equalsIgnoreCase("true")))
	{
		isShowSlaAlertsPopup = true;
	}

	boolean isCustomDashboardEnabled=false;
	String customDashboardFlag=uiIni.getValue("MULTISERVER_CUSTOM_DASHBOARD","ShowCustomDashboard");
	if(customDashboardFlag!=null && customDashboardFlag.equalsIgnoreCase("yes"))
		isCustomDashboardEnabled=true;
	//User License changes
	EgUsersInfo usersInfo = new EgUsersInfo();
	boolean isUserBasedLicense = usersInfo.isUserBasedLicense();
	boolean isUsersLimitCrossed = false;
	boolean alertUserAbtUserCert = false;
	int currCrossing = 0;
	int windowInt = 7;
	String message = "";
	String message2 = "";
	if (isUserBasedLicense)
	{
		isUsersLimitCrossed = usersInfo.isUserViolationOccured();
		windowInt = usersInfo.getWindowValue();
		currCrossing = usersInfo.getNumberOfViolationForLast(windowInt);
		if (!isUsersLimitCrossed && currCrossing > 0)
		{
			alertUserAbtUserCert = true;
		}
		int noOfTotalAvail = usersInfo.getTotalNumberOfDays();
		if (noOfTotalAvail < windowInt)
			windowInt = noOfTotalAvail;
		message = usersInfo.getAlertMessage(windowInt,currCrossing);
		message2 = usersInfo.getAlertMessage2();
	}

	// For find Service Health enabled or disabled
	// By Saravanan.A on 28-2-2012
	String enableServiceHealth = uiIni.getValue("SERVICE_HEALTH","enable_services_health");
	enableServiceHealth=(enableServiceHealth==null || enableServiceHealth.trim().length()==0)?"false":enableServiceHealth.toLowerCase();

	boolean isEnableServiceHealth=false;
	if(enableServiceHealth!=null && (enableServiceHealth.equalsIgnoreCase("yes") || enableServiceHealth.equalsIgnoreCase("true")))
		isEnableServiceHealth=true;
	//---end--

	String installdir = EgInstallInfo.getInstallDir();
	IniFile endUserINI = new IniFile(installdir+"/manager/config/eg_endUserDetails.ini");
	String enableEndUserDashboard = endUserINI.getValue("END_USER_DASHBOARD_SETTINGS","EnableEndUserDashboard");
	enableEndUserDashboard=(enableEndUserDashboard==null || enableEndUserDashboard.trim().length()==0)?"false":enableEndUserDashboard.toLowerCase();

	boolean isEnableEndUserDashboard=false;
	if(enableEndUserDashboard!=null && (enableEndUserDashboard.equalsIgnoreCase("yes") || enableEndUserDashboard.equalsIgnoreCase("true")))
		isEnableEndUserDashboard=true;


	IniFile seumINI = new IniFile(installdir+"/manager/config/eg_extmondash.ini");
	String enableSEUMDashboard = seumINI.getValue("USER_SETTINGS","EnableSEUMDashboard");
	enableSEUMDashboard=(enableSEUMDashboard==null || enableSEUMDashboard.trim().length()==0)?"false":enableSEUMDashboard.toLowerCase();

	boolean isEnableSEUMDashboard=false;
	if(enableSEUMDashboard!=null && (enableSEUMDashboard.equalsIgnoreCase("yes") || enableSEUMDashboard.equalsIgnoreCase("true")))
		isEnableSEUMDashboard=true;

	String enableRUM = uiIni.getValue("RUM_APPLICATIONS","enable_RUM");
	enableRUM=(enableRUM==null || enableRUM.trim().length()==0)?"false":enableRUM.toLowerCase();

	boolean isEnableRUM=false;
	if(enableRUM!=null && (enableRUM.equalsIgnoreCase("yes") || enableRUM.equalsIgnoreCase("true")))
		isEnableRUM=true;

	EgUserPermission userPerm = EgUserPermission.getInstance();
	EgUserRole userRole = user.getUserRole();
	String roleName     = userRole.getRoleName();
	IniFile specsIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_specs.ini");
	boolean hasAdminTab = userRole.hasAnyAdminRole(EgUserPermission.ADMIN);
	boolean hasReporterTab = userRole.hasAnyReporterRole(EgUserPermission.REPORTER);
	boolean hasConfigTab = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);
	boolean hasMonitorTab = userRole.hasAnyMonitorRole(EgUserPermission.MONITOR);
	boolean hasSlaTab = false;//userRole.hasAnySlaRole(EgUserPermission.SLA);
	if(isEnableSLA)
	{
		hasSlaTab = true;
	}
	//******TvMode**
	String eGTVModeSelectedscreens = uiIni.getValue("eG_TVMode_selected_screens",user.getLoginID().toLowerCase());
	boolean isTVModeSelectedscreens=true;
	if (!StringUtils.isNull(eGTVModeSelectedscreens) || user.getLoginID().equalsIgnoreCase("admin")|| user.getLoginID().equalsIgnoreCase("egsm"))
	{
		isTVModeSelectedscreens = false;		
		if (StringUtils.isNull(eGTVModeSelectedscreens))
		{			
			isTVModeSelectedscreens = true;
		}
	}
	//******TvMode End**
	boolean login_as_egsm_in_sm = false;
	if(EgInstallInfo.isSuperManager)
	{
		hasAdminTab = false;//dont show admin tab in supermanager unless user login is egsm
		if(user.getLoginID().equals("egsm"))
		{
			login_as_egsm_in_sm = true;
			hasAdminTab = true;
		}
		hasReporterTab = false;
		hasConfigTab = false;
		hasSlaTab = false;
	}
	boolean hasRemoteControlEnabled=false;
	
	String hasVMs="false";
	String menuForVM = "false";
	if(userRole.hasAllComponentAccess())
	{
		menuForVM = "false";
		hasVMs="false";
	}
	else
	{
		//if(user.isOnlyVMAssigned() && !user.isVMAssigned())
		List u_servers = user.getServers(false);
		if(user.isOnlyVMAssigned() && !user.isVMAssigned() && (u_servers == null || u_servers.size() == 0))
		{
			ArrayList adminPermCheckList = userPerm.getPrivilegeList(roleName,32,0);
			menuForVM = "true";
			//Limited access admin - admin and config tabs will not be shown
			//when monitor or reporter tab is available and only vms assigned.
			if(isAdmin && hasMonitorTab && (adminPermCheckList != null && !adminPermCheckList.contains("Component Management")))
			{
				isAdmin = false;
				isMonitor = true;
				entry = "monitor";
				hasAdminTab = false;
			}
			if(isAdmin && hasReporterTab && (adminPermCheckList != null && !adminPermCheckList.contains("Component Management")))
			{
				isAdmin = false;
				isReport = true;
				entry = "reporter";
				hasAdminTab = false;
			}
		}
		if(user.getOnlyVMs()!=null && user.getOnlyVMs().size()>0)
		{
			hasVMs="true";
		}
	}
		
	//Added on April 10, To take out the admin tab for admin users logging into secondary managers
	boolean isSecondaryManager = false;
	EgManagersIniForManager mi = null;
	if(EgInstallInfo.isClusterSupported)
	{
		mi = EgManagersIniForManager.getInstance();
		if(!mi.isPrimaryManager())
		{
			isSecondaryManager = true;
			if(isAdmin && hasAdminTab && hasMonitorTab)
			{
				isAdmin=false;
				isMonitor=true;
				entry="monitor";
			}
			if(isAdmin && hasAdminTab && hasConfigTab)
			{
				isAdmin=false;
				isConfig=true;
				entry="config";
			}
			if(isAdmin && hasAdminTab && hasReporterTab)
			{
				isAdmin=false;
				isReport=true;
				entry="reporter";
			}
			if(isAdmin && hasAdminTab && hasSlaTab)
			{
				isAdmin=false;
				isSla=true;
				entry="sla";
			}
		}
	}
	if((!isShowAlarmsInLightBox) && isSecondaryManager && isMonitor){
		if(showAlarmsInLightBox!=null && (showAlarmsInLightBox.equalsIgnoreCase("yes") ||  showAlarmsInLightBox.equalsIgnoreCase("true"))){
			isShowAlarmsInLightBox = true;
		}
	}
	
	if(newWindow!=null && newWindow.trim().length()>0 && newWindow.equals("yes"))
	{
		session.setAttribute("entryChild", entry);
	}
	else session.setAttribute("entryMain", entry);
	session.setAttribute("entry", entry);
	String menuItemJSLink="/final/"+entry+"/eg_scripts/menu_item_"+_user.getLanguage()+".js";
	String menuAdminItemJSLink = "/final/admin/eg_scripts/menu_item_"+_user.getLanguage()+".js";
	String menuMonitorItemJSLink = "/final/monitor/eg_scripts/menu_item_"+_user.getLanguage()+".js";
	String menuReporterItemJSLink = "/final/reporter/scripts/menu_item_"+_user.getLanguage()+".js";
	String menuConfigItemJSLink = "/final/config/scripts/menu_item_"+_user.getLanguage()+".js";
	String menuSlaItemJSLink = "/final/SLA/scripts/menu_item_"+_user.getLanguage()+".js";
	//String menuJSLink = "/final/"+entry+"/eg_scripts/navlinks.js";
	String menuJsMegaLink = "/final/"+entry+"/eg_scripts/navlinksAdminMega.js";
	// This was used for grouping mega navlink in admin module 
	//String menuItemJsMegaLink = "/final/"+entry+"/eg_scripts/menu_item_mega_"+_user.getLanguage()+".js";
	boolean fromSmart = smartParam != null && !entry.equals("");
	String tabIMG=null;/*-----------Vijay 6/9/2007 -------------------*/
	String hideAlarmPopup=uiIni.getValue("HIDE_ALARM_POPUP","alarm_popup");

	if(entry.equalsIgnoreCase("config"))
	{
		Map configSetting=(Hashtable)user.getUserConfigSetting();
		if(configSetting!=null && configSetting.size()>0)
			configHomePage=(String)configSetting.get(EgConfigConstants.HOME_PAGE);
	}
	boolean noValidUserRolesForSM = false;
	if(EgInstallInfo.isSuperManager)
	{
		if(login_as_egsm_in_sm)
		{
			if(entry.equals("admin"))
			{
					selectedSkin="admin";
				url= "/final/admin/EgDispManagers.jsp";
				helpURL = "/final/eghelp/EgHelp.jsp";
				session.setAttribute("moduleName","admin");
				tabIMG = _user.getAdminSkin();
				String adminLastAccessedURL  =(String)session.getAttribute("adminLastAccessedURL");
				session.removeAttribute("adminLastAccessedURL");
			}
			else if(entry.equals("monitor"))
			{
				selectedSkin="monitor";
				url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
				helpURL = "/final/eghelp/EgMHelp.jsp";
				//menuJSLink = "/final/monitor/eg_scripts/navlinks.js";
				menuJsMegaLink = "/final/monitor/eg_scripts/navlinksMonitorMega.js";
				menuItemJSLink="/final/monitor/eg_scripts/menu_item_"+_user.getLanguage()+".js";
				session.setAttribute("moduleName","monitor");
				tabIMG = _user.getMonitorSkin();
			}
		}
		else if(isAdmin)
		{
			selectedSkin="monitor";
			url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
			helpURL = "/final/eghelp/EgMHelp.jsp";
			//menuJSLink = "/final/monitor/eg_scripts/navlinks.js";
			menuJsMegaLink = "/final/monitor/eg_scripts/navlinksAdminMega.js";
			menuItemJSLink="/final/monitor/eg_scripts/menu_item_"+_user.getLanguage()+".js";
			session.setAttribute("moduleName","monitor");
			tabIMG = _user.getMonitorSkin();
		}
		else if (isMonitor)
		{
			selectedSkin="monitor";
			url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
			helpURL = "/final/eghelp/EgMHelp.jsp";
			//menuJSLink = "/final/monitor/eg_scripts/navlinks.js";
			menuJsMegaLink = "/final/monitor/eg_scripts/navlinksMonitorMega.js";
			menuItemJSLink="/final/monitor/eg_scripts/menu_item_"+_user.getLanguage()+".js";
			session.setAttribute("moduleName","monitor");
			tabIMG = _user.getMonitorSkin();
		}
		else if (isConfig)
		{
			selectedSkin="configindex";
			isConfig = false;
			noValidUserRolesForSM = true;
			entry = "monitor";
			url = "/final/monitor/forbidden.jsp";
			session.setAttribute("moduleName","monitor");
			tabIMG = _user.getMonitorSkin();
		}
		else if (isReport)
		{
			selectedSkin="reporter";
			isReport = false;
			noValidUserRolesForSM = true;
			entry = "monitor";
			url = "/final/monitor/forbidden.jsp";
			session.setAttribute("moduleName","monitor");
			tabIMG = _user.getMonitorSkin();
		}
		else if (isSla && isEnableSLA)
		{
			selectedSkin="sla";
			isSla = false;
			noValidUserRolesForSM = true;
			entry = "monitor";
			url = "/final/monitor/forbidden.jsp";
			session.setAttribute("moduleName","monitor");
			tabIMG = _user.getMonitorSkin();
		}
	}
	else if(isAdmin)
	{
		String reqFrom = (String)session.getAttribute("clsTrial");
		if (reqFrom!=null && reqFrom.equalsIgnoreCase("yes"))
		{
			String compType = (String)session.getAttribute("compType");
			url = "/final/portal/LogonSimulator.jsp?from=login&compType="+compType;
		}
		else
		{
			selectedSkin="admin";
			url= "/final/admin/EgAdminOperations.jsp?integritycheckviolated="+integrity+"&"+ request.getQueryString();
			String adminLastAccessedURL  =(String)session.getAttribute("adminLastAccessedURL");
			session.removeAttribute("adminLastAccessedURL");
			if(adminLastAccessedURL!=null)
			{
				url= adminLastAccessedURL;
			}
		}
		helpURL = "/final/eghelp/EgHelp.jsp";
		session.setAttribute("moduleName","admin");
		tabIMG = _user.getAdminSkin();
	}
	else if (isMonitor)
	{
		selectedSkin="monitor";
		url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
		helpURL = "/final/eghelp/EgMHelp.jsp";
		//menuJSLink = "/final/monitor/eg_scripts/navlinks.js";
		menuJsMegaLink = "/final/monitor/eg_scripts/navlinksMonitorMega.js";
		menuItemJSLink="/final/monitor/eg_scripts/menu_item_"+_user.getLanguage()+".js";
		session.setAttribute("moduleName","monitor");
		tabIMG = _user.getMonitorSkin();
	}
	else if (isConfig)
	{
		selectedSkin="configindex";

		if (configHomePage != null && configHomePage.indexOf("EcConfigurationServlet?") != -1)
		{
			configHomePage = configHomePage.replace("EcConfigurationServlet?","EcConfigurationServletNew?");
		}

		if (configHomePage != null && 
			!configHomePage.startsWith("/final/servlet/") && 
			!configHomePage.startsWith("/final/config/"))
		{
			IniFile configSettingIni =  new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_configtests.ini");
			configHomePage = (String)configSettingIni.getValue("HOME_PAGE",configHomePage);
		}

		url = configHomePage;
		helpURL="/final/eghelp/EgCHelp.jsp";
		//menuJSLink = "/final/config/scripts/navlinks.js";
		menuJsMegaLink = "/final/config/scripts/navlinksConfigMega.js";
		menuItemJSLink="/final/config/scripts/menu_item_"+_user.getLanguage()+".js";
		session.setAttribute("moduleName","config");
		tabIMG = _user.getConfigSkin();
		String configLastAccessedURL = (String)session.getAttribute("configLastAccessedURL");
		session.removeAttribute("configLastAccessedURL");
		if (configLastAccessedURL != null)
		{
			if (configLastAccessedURL.indexOf("###") != -1)
			{
				configLastAccessedURL = StringUtils.replace(configLastAccessedURL,"###","$$$");
			}
			
			if (configLastAccessedURL.indexOf("#") != -1)
			{
				configLastAccessedURL = StringUtils.replace(configLastAccessedURL,"#","$");
			}

			url = configLastAccessedURL;
		}
	}
	else if (isReport)
	{
		selectedSkin="reporter";
		//menuJSLink = "/final/reporter/scripts/navlinks.js";
		menuJsMegaLink = "/final/reporter/scripts/navlinksReporterMega.js";
		menuItemJSLink="/final/reporter/scripts/menu_item_"+_user.getLanguage()+".js";
		url = "/final/monitor/EgReporter.jsp";
		if(menuForVM.equalsIgnoreCase("true"))
			url = "/final/monitor/EgReporter.jsp?menuForVM=true";
		helpURL = "/final/eghelp/EgMHelp.jsp";
		session.setAttribute("moduleName","reporter");
		tabIMG = _user.getReporterSkin();
		/*String reportLastAccessedURL  =(String)session.getAttribute("reportLastAccessedURL");
		session.removeAttribute("reportLastAccessedURL");
		System.out.println("egindex.jsp reportLastAccessedURL==="+reportLastAccessedURL);
		if(reportLastAccessedURL!=null)
		{
			if(reportLastAccessedURL.indexOf("##")>-1)
			{
				reportLastAccessedURL=StringUtils.replace(reportLastAccessedURL,"##","$$");
			}
			else if(reportLastAccessedURL.indexOf("#")>-1)
			{
				reportLastAccessedURL=StringUtils.replace(reportLastAccessedURL,"#","$");
			}
			
			url= reportLastAccessedURL;
			
		} */
	}
	else if (isSla && isEnableSLA)
	{
		selectedSkin="sla";
		menuJsMegaLink = "/final/SLA/scripts/navlinksSLAMega.js";
		menuItemJSLink="/final/SLA/scripts/menu_item_"+_user.getLanguage()+".js";
		url = "/final/servlet/com.egurkha.SLA.controller.EgSLAController?slaCmd=home";
		helpURL = "/final/eghelp/EgMHelp.jsp";
		session.setAttribute("moduleName","sla");
		tabIMG = _user.getSlaSkin();
	}
	if (user == null)
	{
		Vector errorVector = new Vector();
		errorVector.add("User session expired. please login again.");
	//	session.setAttribute("vec_Errors", errorVector); 
	}
	session.setAttribute("skin", selectedSkin); 
	String id = user.getLoginID();
	String uname = request.getParameter("uname");
	String temp_id = id;
	if (uname != null && uname.length() > 0)
	{
		id = uname;
	}

	boolean changepwd=true;
	if (id.indexOf("/")>-1 && isValidDomainUser(id))
		changepwd=false;
	
	long myPer = userRole.getMonitorPerm();
	boolean isAlarmViewer = (roleName.equals("AlarmViewer") || roleName.equals("SuperAlarmViewer"));

	

	EgMemCheck memCheck = new EgMemCheck();
	hasConfigTab=memCheck.isCMEnabled();
	hasReporterTab=memCheck.isReportEnabled();
	hasSlaTab=memCheck.isSLAEnabled();
	hasRemoteControlEnabled = memCheck.isRemoteControlEnabled();
	
	
	//Added on April 10, To take out the admin tab for admin users logging into secondary managers
	if(EgInstallInfo.isClusterSupported)
	{
		mi = EgManagersIniForManager.getInstance();
		if(mi!=null&&!mi.isPrimaryManager())
		{
			if((!isAdmin) && hasAdminTab)
			{
				hasAdminTab=false;
			}
		}
	}
	 hasMonitorTab = userRole.hasAnyMonitorRole(EgUserPermission.MONITOR);
	List zones = user.getZones();
	List segments = user.getSegments();
	List services = user.getServices();
	List serGroups = user.getServiceGroups();
	if (hasReporterTab)
	{
		hasReporterTab = userRole.hasAnyReporterRole(EgUserPermission.REPORTER);
		if(zones.size() == 0 && segments.size() == 0 && services.size() == 0 && serGroups.size() == 0)
		{
			if(user.isOnlyVMAssigned() && !user.isVMAssigned())
			{
				if(hasReporterTab || hasMonitorTab)
				{
					hasAdminTab = false;
					hasConfigTab = false;
					hasSlaTab=false;
				}
				else
				{
					if(hasConfigTab)
						hasConfigTab = true;
					if(hasSlaTab)
						hasSlaTab = true;	
				}
			}
		}
	}
	if (hasConfigTab)
	{
		if(!userRole.hasAllComponentAccess())
		{
			if(isMonitor && !isAlarmViewer)
			{
				
				if(zones.size() == 0 && segments.size() == 0 && services.size() == 0 && serGroups.size() == 0)
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						hasConfigTab = false;
					}
					else
					{
						hasConfigTab = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);
					}
				}
				else
				{
					hasConfigTab = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);
				}
			}
			else
			{
				hasConfigTab = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);
			}
		}
		else
		{
			hasConfigTab = userRole.hasAnyConfigRole(EgUserPermission.CONFIG);
		}
	}

	if (hasSlaTab && isEnableSLA)
	{
		if(!userRole.hasAllComponentAccess())
		{
			if(isMonitor && !isAlarmViewer)
			{
				if(zones.size() == 0 && segments.size() == 0 && services.size() == 0 && serGroups.size() == 0)
				{
					if(user.isOnlyVMAssigned() && !user.isVMAssigned())
					{
						hasSlaTab = false;
					}
					else
					{
						hasSlaTab = false;//userRole.hasAnySlaRole(EgUserPermission.SLA);
						if(isEnableSLA)
						{
							hasSlaTab = true;
						}
					}
				}
				else
				{
					hasSlaTab = false;//userRole.hasAnySlaRole(EgUserPermission.SLA);
					if(isEnableSLA)
					{
						hasSlaTab = true;
					}
				}
			}
			else
			{
				hasSlaTab = false;//userRole.hasAnySlaRole(EgUserPermission.SLA);
				if(isEnableSLA)
				{
					hasSlaTab = true;
				}
			}
		}
		else
		{
			hasSlaTab = false;//userRole.hasAnySlaRole(EgUserPermission.SLA);
			if(isEnableSLA)
			{
				hasSlaTab = true;
			}
		}
	}
	if (isMonitor && !isAlarmViewer)
	{
		url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
	}
	if (isMonitor && isAlarmViewer)
	{
		url = "/final/monitor/EgAlarms.jsp";
	}
	if (isMonitor && isAlarmViewer && request.getParameter("from") != null && request.getParameter("from").equals("userProfile"))
	{
		if(login_as_egsm_in_sm)
		{
			url = "/final/admin/EgSmUserProfile.jsp?entry="+entry;
		}
		else
		{
		url = "/final/admin/userProfile.jsp?entry=" + entry+"&uname="+EgURLEncoder.encode(id,"UTF-8");
		}
	}

	if (isAdmin)
	{
		if (request.getParameter("from") != null)
		{
			if(login_as_egsm_in_sm)
			{
				url = "/final/admin/EgSmUserProfile.jsp?entry="+entry;
			}
			else
			{
			url = "/final/admin/userProfile.jsp?entry=" + entry+"&uname="+EgURLEncoder.encode(id,"UTF-8");
			}
		}
	}
	boolean isAlarmQView = false; 
	String currentMonitorHomePageURL="";
	String dynamicDashboardURL="";
	boolean isDynamicMonitorHomeDashboard=false;
	if (isMonitor && !isAlarmViewer && !fromSmart)
	{
		String dynamicHome=(String)_user.getMonitorHomePageOption();
		if(StringUtils.isNull(dynamicHome))
			dynamicHome="default";

		if(dynamicHome!=null && dynamicHome.equalsIgnoreCase("dynamic"))
		{
			OneClickDashboardModel oneClickModel=new OneClickDashboardModel(_user);
			dynamicDashboardURL=oneClickModel.getDynamicDashboardURL();
			if(!StringUtils.isNull(dynamicDashboardURL))
			{
				hideMonDomainPopup=true;
				isDynamicMonitorHomeDashboard=true;
			}
		}

		String monitor_home_page_variable=(String)user.getMonitorHomePage();
		if(fromPage != null && fromPage.equals("alarmQView")) 
		{
			String qViewParam = request.getParameter("qViewParam");
			if(qViewParam!=null)
			{
				qViewParam = StringUtils.replace(qViewParam,"^","&");
				//qViewParam = StringUtils.replace(qViewParam,"|eq|","=");
				qViewParam = StringUtils.decodeSecurityChar(qViewParam);
			}
			url= "/final/monitor/EgSiteInfraView.jsp?monCmd=componentDashboard&"+qViewParam+"&toDashBoardLayer=true&gotoLayerModel=true";
			isAlarmQView = true;
		} 
		else if (fromSmart)
		{
			if (smartParam.equals("alarm"))
			{
				url = "/final/monitor/EgAlarms.jsp";
			}
			else
			{
				String [] thisArr = StringUtils.getTokens(smartParam, "^");
				url= "/final/monitor/EgSiteInfraView.jsp?monCmd=componentDashboard&qctr=2&fromalarm=1&host=" + thisArr[0] + "&layer=" + thisArr[1] + "&site=" + thisArr[2] + "&test=" + thisArr[3] + "-"+thisArr[4] + "&comptype="+thisArr[5]+"&tstate=" + thisArr[6]+"&msmt_host=" +thisArr[7]+ "&componentName=" + thisArr[0] + ":" + thisArr[5]+"&toDashBoardLayer=true&gotoLayerModel=true";
			}
		}
		else if(fromSm!=null)
		{
			if((fromSm.equals("yes") || fromSm.equals("home")) && request.getParameter("fromsuperHome")!=null && request.getParameter("fromsuperHome").equals("home"))
			{
				/*if (user.getMonitorHomePage().equalsIgnoreCase("Dashboard"))
				{
					url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
				}
				else if (user.getMonitorHomePage().equalsIgnoreCase("Current Alarms"))
				{
					url = "/final/monitor/EgAlarms.jsp";
				}*/
				if(monitor_home_page_variable!=null && monitor_home_page_variable.trim().length()>0)
				{
					String monitor_home_page_value=uiIni.getValue("MONITOR_HOME_PAGE",monitor_home_page_variable);
					
					if(isEnableServiceHealth && monitor_home_page_variable.trim().equalsIgnoreCase("Service Health"))
					{
						url=monitor_home_page_value;
					}
					else if(isEnableEndUserDashboard && monitor_home_page_variable.trim().equalsIgnoreCase("End User Dashboard"))
					{
						url=monitor_home_page_value;
					}
					else if(isEnableSEUMDashboard && monitor_home_page_variable.trim().equalsIgnoreCase("External Monitors"))
					{
						url=monitor_home_page_value;
					}
					else if(isEnableRUM && monitor_home_page_variable.trim().equalsIgnoreCase("Real User Monitor Dashboard"))
					{
						url=monitor_home_page_value;
					}
					else if(!isEnableServiceHealth && !isEnableSEUMDashboard && !isEnableEndUserDashboard && !isEnableRUM && monitor_home_page_value!=null && monitor_home_page_value.trim().length()>0)
					{
						url=monitor_home_page_value;
					}
					else if(monitor_home_page_variable.trim().equalsIgnoreCase("AlarmViewer"))
					{
						url="/final/monitor/EgAlarms.jsp";
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else
				{
					url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
				}
			}
			else if(fromSm.equals("yes") && request.getParameter("fromsuperHome")==null)
			{
				url = "/final/monitor/EgSiteInfraView.jsp?monCmd=componentDashboard&qctr=2&fromalarm=1&host="+request.getParameter("host")+"&layer=" +request.getParameter("layer")+ "&site=" +request.getParameter("site")+ "&test=" +request.getParameter("test")+ "&comptype=" +request.getParameter("comptype")+"&tstate=" +request.getParameter("tstate")+ "&msmt_host=&componentName=" + request.getParameter("comptype") + ":" +request.getParameter("host")+"&newWindow=true&toDashBoardLayer=true&gotoLayerModel=true";
			}
		}
		else
		{
			if(!isDynamicMonitorHomeDashboard)
			{
				if(monitor_home_page_variable!=null && monitor_home_page_variable.trim().length()>0)
				{
					String monitor_home_page_value=uiIni.getValue("MONITOR_HOME_PAGE",monitor_home_page_variable);
					
					if(isEnableServiceHealth && monitor_home_page_variable.trim().equalsIgnoreCase("Service Health"))
					{
						url=monitor_home_page_value;
					}
					else if(isEnableEndUserDashboard && monitor_home_page_variable.trim().equalsIgnoreCase("End User Dashboard"))
					{
						url=monitor_home_page_value;
					}
					else if(isEnableSEUMDashboard && monitor_home_page_variable.trim().equalsIgnoreCase("External Monitors"))
					{
						url=monitor_home_page_value;
					}
					else if(!isEnableServiceHealth && !isEnableSEUMDashboard  && monitor_home_page_value!=null && monitor_home_page_value.trim().length()>0)
					{
						url=monitor_home_page_value;
					}
					else if(monitor_home_page_variable.trim().equalsIgnoreCase("AlarmViewer"))
					{
						url="/final/monitor/EgAlarms.jsp";
					}
					else if(monitor_home_page_value!=null && monitor_home_page_value.trim().length()>0)
					{
						url=monitor_home_page_value;
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else
				{
					url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
				}
			}
		}
		/*else if (user.getMonitorHomePage().equalsIgnoreCase("Dashboard"))
		{
			url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
		}
		else if (user.getMonitorHomePage().equalsIgnoreCase("Current Alarms"))
		{
			url = "/final/monitor/EgAlarms.jsp";
		}
		else if (user.getMonitorHomePage().equalsIgnoreCase("Live Graph"))
		{
			url = "/final/monitor/livegraph/EgLiveGraphHome.jsp";
		}
		else if (user.getMonitorHomePage().equalsIgnoreCase("Quick Insight"))
		{
			url = "/final/monitor/qinsight/EgQInsightHome.jsp";
		}
		else if (user.getMonitorHomePage().equalsIgnoreCase("Virtual"))
		{
			url = "/final/monitor/vmwareDashboard.jsp";
		}
		else //if(user.getMonitorHomePage().equalsIgnoreCase("Blank"))
		{
			//url = "/final/monitor/blank.jsp";
			url = "/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
		}*/

		if (request.getParameter("from") != null)
		{
			if(login_as_egsm_in_sm)
			{
				url = "/final/admin/EgSmUserProfile.jsp?entry="+entry;
			}
			else
			{
				url = "/final/admin/userProfile.jsp?entry=" + entry+"&uname="+EgURLEncoder.encode(id,"UTF-8");
			}
		}
		currentMonitorHomePageURL=url;

		if(isFromQuickLaunch)
		{
			if(access!=null && access.trim().length()>0)
			{
				if(access.equalsIgnoreCase("segmentList"))
				{
					url ="/final/servlet/com.eg.EgMonitorController?monCmd=segmentList&from=MainDashboard";
					if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
					{
						url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
					}
					else
					{
						url=url+"&action=segment";
					}
				}
				else if(access.equalsIgnoreCase("serviceList"))
				{
					url="/final/servlet/com.eg.EgMonitorController?monCmd=serviceList&from=MainDashboard&fromQuicklaunch=yes";
					if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
					{
						url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
					}
					else
					{
						url=url+"&action=service";
					}
				}
				else if(access.equalsIgnoreCase("componentList"))
				{
					url="/final/servlet/com.eg.EgMonitorController?monCmd=componentList";

					if(accessPageName!=null && accessPageName.trim().length()>0 && !accessPageName.equals("All"))
					{
						url=url+"&action=search&from=componentList&searchIndComps=checked&searchTypeString="+EgURLEncoder.encode(accessPageName,"UTF-8");
					}
					else
					{
						url=url+"&from=TreeMenu&action=component&searchIndComps=checked";
					}
				}
				else if(access.equalsIgnoreCase("systemList"))
				{
					url="/final/servlet/com.eg.EgMonitorController?monCmd=boxList";
					if(accessPageName!=null && accessPageName.trim().length()>0 && !accessPageName.equals("All"))
					{
						url=url+"&action=search&from=boxList&searchNameString="+EgURLEncoder.encode(accessPageName,"UTF-8");
					}
					else
					{
						url=url+"&from=MainDashboard&action=box";
					}
				}
				else if(access.equalsIgnoreCase("zoneList"))
				{
					url="/final/servlet/com.eg.EgMonitorController?monCmd=zoneList&from=MainDashboard";
					if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
					{
						url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
					}
					else
					{
						url=url+"&action=zone";
					}
				}
				else if(access.equalsIgnoreCase("segment"))
				{
					if(accessPageName!=null && accessPageName.trim().length()>0)
					{
						List usr_seg=user.getSegments();
						if(usr_seg!=null && usr_seg.contains(accessPageName))
						{
							url="/final/monitor/EgDispMonSegments.jsp?segment="+EgURLEncoder.encode(accessPageName,"UTF-8");
						}
						else
						{
							url="/final/servlet/com.eg.EgMonitorController?monCmd=segmentList&from=MainDashboard";
							if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
							{
								url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
							}
							else
							{
								url=url+"&action=segment";
							}
						}
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else if(access.equalsIgnoreCase("service"))
				{
					if(accessPageName!=null && accessPageName.trim().length()>0)
					{
						List usr_ser=user.getServices();
						if(usr_ser!=null && usr_ser.contains(accessPageName))
						{
							EgTopoInfo topoInfo=new EgTopoInfo("manager");
							String value = topoInfo.getValue("SERVICE",accessPageName);
							boolean isSite=false;
							if(value!=null && value.trim().equalsIgnoreCase("site"))
							{
								isSite=true;
							}
							url="/final/monitor/EgSiteInfraView.jsp?site="+EgURLEncoder.encode(accessPageName,"UTF-8")+"&isSite="+isSite+"&service="+EgURLEncoder.encode(accessPageName,"UTF-8")+"&serviceName="+EgURLEncoder.encode(accessPageName,"UTF-8");
						}
						else
						{
							url="/final/servlet/com.eg.EgMonitorController?monCmd=serviceList&from=MainDashboard&fromQuicklaunch=yes";
							if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
							{
								url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
							}
							else
							{
								url=url+"&action=service";
							}
						}
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else if(access.equalsIgnoreCase("zone"))
				{
					if(accessPageName!=null && accessPageName.trim().length()>0)
					{
						List usr_zones=user.getZones();
						if(usr_zones!=null && usr_zones.contains(accessPageName))
						{
							url="/final/servlet/com.eg.EgMonitorController?monCmd=zoneDashboard&zoneName="+EgURLEncoder.encode(accessPageName,"UTF-8");
						}
						else
						{
							url="/final/servlet/com.eg.EgMonitorController?monCmd=zoneList&from=MainDashboard";
							if(accessPageName!=null && accessPageName.length()>0 &&!accessPageName.equalsIgnoreCase("all"))
							{
								url=url+"&action=search&searchString="+EgURLEncoder.encode(accessPageName,"UTF-8");
							}
							else
							{
								url=url+"&action=zone";
							}
						}
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else if(access.equalsIgnoreCase("component") || access.equalsIgnoreCase("system"))
				{
					if(accessPageName!=null && accessPageName.trim().length()>0)
					{
						List usr_server=user.getServers(false);
						//saravanan.s, add the host system
						List hostSystem = Server.getHostSystems(usr_server, true);
						if(hostSystem!=null && hostSystem.size()>0)
						{
							for (int r=0; r<hostSystem.size(); r++)
							{
								String s = (String) hostSystem.get(r);
								s =Server.HOST_SYSTEM+":"+s;
								if (!usr_server.contains(s))
								{
									usr_server.add(s);
								}
							}
						}
						if(usr_server!=null && usr_server.contains(accessPageName))
						{
							StringTokenizer st=new StringTokenizer(accessPageName,":");
							String comp_type="";
							String comp_name="";
							String comp_port="";
							String comp_sid="";
							String fakeType="";
							// find the real component type and port then form the url.
							// by Saravanan.A on 18-7-2012
							if(st.countTokens()==3)
							{
								comp_type=st.nextToken();
								comp_name=st.nextToken();
								comp_port=st.nextToken();
								
								if (comp_type!=null && comp_type.equalsIgnoreCase("host_system"))
								{
									fakeType = discInfo.getTypeForHostTest(comp_name,test);
									if (fakeType != null)
									{
										fakeType = fakeType.trim();
									}

									String comp_port_2=(String)discInfo.getPortForHost(comp_name,fakeType);
									if(comp_port_2!=null && comp_port_2.trim().length()>0 && (!comp_port_2.equals(comp_port)))
										comp_port=comp_port_2;
								}
								else
								{
									fakeType=comp_type;
								}

								comp_name=comp_name+":"+comp_port;
							}
							else if(st.countTokens()==4)
							{
								comp_type=st.nextToken();
								comp_name=st.nextToken();
								comp_port=st.nextToken();
								comp_sid=st.nextToken();

								if (comp_type!=null && comp_type.equalsIgnoreCase("host_system"))
								{
									fakeType = discInfo.getTypeForHostTest(comp_name,test);
									if (fakeType != null)
									{
										fakeType = fakeType.trim();
									}

									String comp_port_2=(String)discInfo.getPortForHost(comp_name,fakeType);
									if(comp_port_2!=null && comp_port_2.trim().length()>0 && (!comp_port_2.equals(comp_port)))
										comp_port=comp_port_2;
								}
								else
								{
									fakeType=comp_type;
								}

								comp_name=comp_name+":"+comp_port+":"+comp_sid;
							}//sarav url formed here
							//--end--
							
							String site_name_value="NULL";
							if(layer!=null && (layer.trim().equals("WEB_SITE") || layer.trim().equals("WEB_TRANSACTIONS")))
							{
								Vector site_vect=(Vector)esmb.getServiceNamesForComponent(accessPageName);
								
								if(site_vect!=null && site_vect.size()>0)
								{
									EgTopoInfo topoInfo=new EgTopoInfo("manager");
									for (int r=0; r<site_vect.size(); r++)
									{
										String s = (String) site_vect.get(r);
										String value = topoInfo.getValue("SERVICE",s);
										if(value!=null && value.trim().equalsIgnoreCase("site"))
										{
											site_name_value=s;
											break;
										}
									}
								}
							}

							url="/final/servlet/com.eg.EgDashboardController?site="+EgURLEncoder.encode(site_name_value,"UTF-8")+"&from=list&tab=layers&comptype="+EgURLEncoder.encode(fakeType,"UTF-8")+"&host="+EgURLEncoder.encode(comp_name,"UTF-8")+"&faketype="+EgURLEncoder.encode(fakeType,"UTF-8");

							if(layer!=null && layer.trim().length()>0)
							{
								url=url+"&layer="+EgURLEncoder.encode(layer,"UTF-8");
							}

							if(test!=null && test.trim().length()>0 && (descriptor==null || descriptor.trim().length()==0))
							{
								url=url+"&test="+EgURLEncoder.encode(test,"UTF-8")+"-"+"&qctr=2&tstate=UNKNOWN&msmt_host=&toDashBoardLayer=true&fromalarmWindow=true&findInfo=true";
							}
							else if(test!=null && test.trim().length()>0 && descriptor!=null && descriptor.trim().length()>0)
							{
								// split the msmt_host and descriptor and form the url.
								// by Saravanan.A on 18-7-2012
								ArrayList des_and_msmt =  com.egurkha.util.StringUtils.egTokenizer(descriptor, "~$~",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
								if(des_and_msmt.size()==2)
								{
									String des_info=(String)des_and_msmt.get(0);
									des_info=(des_info==null || des_info.trim().length()==0|| des_info.equals("+"))?"":des_info;

									String m_host=(String)des_and_msmt.get(1);
									m_host=(m_host==null || m_host.trim().length()==0)?"":m_host;

									url=url+"&test="+EgURLEncoder.encode(test,"UTF-8")+"-"+EgURLEncoder.encode(des_info,"UTF-8")+"&qctr=2&tstate=UNKNOWN&msmt_host="+EgURLEncoder.encode(m_host,"UTF-8")+"&toDashBoardLayer=true&fromalarmWindow=true";
								}
								else if(des_and_msmt.size()==1)
								{
									String des_info=(String)des_and_msmt.get(0);
									des_info=(des_info==null || des_info.trim().length()==0 || des_info.equals("+"))?"":des_info;

									url=url+"&test="+EgURLEncoder.encode(test,"UTF-8")+"-"+EgURLEncoder.encode(des_info,"UTF-8")+"&qctr=2&tstate=UNKNOWN&msmt_host=&toDashBoardLayer=true&fromalarmWindow=true";
								}
								//---end--
							}
							else if(layer!=null && layer.trim().length()>0)
							{
								url=url+"&qctr=2&tstate=&msmt_host=&toDashBoardLayer=true&fromalarmWindow=true";
							}
						}
						else
						{
							url="/final/servlet/com.eg.EgMonitorController?monCmd=componentList&from=TreeMenu&action=component&searchIndComps=checked";
						}
					}
					else
					{
						url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
					}
				}
				else
				{
					url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
				}
			}
			else
			{
				url ="/final/servlet/com.eg.EgMonitorController?monCmd=dashboard";
			}
		}
	}
	if (isMonitor && isAlarmViewer)
	{
		if(fromSm!=null)
		{
			//fromSm.equals("hist")
			/*String component=request.getParameter("component");
			component = (component != null)?component:"";
			StringTokenizer st=new StringTokenizer(component,":");
			String  ctype="";
			String cname="";
			String port="";
			while(st.hasMoreTokens())
			{
				cname=st.nextToken();
				port=st.nextToken();
				ctype=st.nextToken();
			}
			url= "/final/monitor/componentMeasureTabSet.jsp?type="+ctype+"&site="+request.getParameter("site")+"&host="+cname+"&port="+port+"&info="+cname+"&state="+request.getParameter("tstate")+"&messy="+request.getParameter("measure");
			*/
			if(fromSm!=null && fromSm.trim().length()>0 && fromSm.equalsIgnoreCase("hist"))
			{
				url= "/final/monitor/EgFixHistory.jsp?component="+request.getParameter("component")+"&site="+request.getParameter("site")+"&test="+request.getParameter("test")+"&measure="+request.getParameter("measure");
			}
			else if(fromSm!=null && fromSm.trim().length()>0 && fromSm.equalsIgnoreCase("feedback"))
			{
				url= "/final/monitor/EgFixFeedBack.jsp?site="+request.getParameter("site")+"&trgthost="+request.getParameter("trgthost")+"&port="+request.getParameter("port")+"&test="+request.getParameter("test")+"&info="+request.getParameter("info")+"&comptype="+request.getParameter("comptype")+"&measure="+request.getParameter("measure")+"&msmttime="+request.getParameter("msmttime");
			}
			else
			{
				url = "/final/monitor/EgAlarms.jsp";
			}
		}
		currentMonitorHomePageURL=url;
	}
	if(isDynamicMonitorHomeDashboard)
	{
		boolean setDynamicDashUrl=true;
		System.out.println("url before !!!!!!!!! "+url);
		if(url!=null && url.indexOf("MyDashboard.jsp?")>-1)
		{
			System.out.println("egindexjson url "+url);
			if(url.indexOf("&setMonitorHome=true")==-1)
			{
				setDynamicDashUrl=false;
			}
		}
		if(setDynamicDashUrl)
		{
			url=dynamicDashboardURL;
			currentMonitorHomePageURL=url;
		}
		hideMonDomainPopup=true;
	}
	boolean isOpenMyDashboard=false;
	String monitorLastSession=null;
	if(isMonitor && !isAlarmViewer && !fromSmart && !isAlarmQView)
	{
		String comeFromValue=request.getParameter("comeFrom");
		monitorLastSession=(String)session.getAttribute("monitorLastSession");
		//session.removeAttribute("monitorLastSession");
		if(monitorLastSession!=null && comeFromValue==null)
		{
			// Based on Service Health enabled or disabled
			// By Saravanan.A on 28-2-2012
			String paramSymbol = (monitorLastSession.indexOf("?")>-1)?"&":"?";
			if(isEnableServiceHealth && monitorLastSession.indexOf("serviceHealthMain.jsp")>0)
			{
				url=monitorLastSession+paramSymbol+"isFromMenu=true";
			}
			else if(isEnableEndUserDashboard && monitorLastSession.indexOf("endUserDashboard")>0)
			{
				url=monitorLastSession+paramSymbol+"isFromMenu=true";
			}
			else if(isEnableSEUMDashboard && monitorLastSession.indexOf("externalMonitorsDashboard")>0)
			{
				url=monitorLastSession+paramSymbol+"isFromMenu=true";
			}
			else if((!isEnableServiceHealth) && monitorLastSession.indexOf("serviceHealthMain.jsp")<0)
			{
				if(monitorLastSession!=null && monitorLastSession.equals("/final/monitor/MyDashboard.jsp?newWindow=true"))
				{
					isOpenMyDashboard=true;
				}
				else
				{
					url=monitorLastSession+paramSymbol+"isFromMenu=true";
				}
			}
			else
			{
				url =monitorLastSession;
			}
			if(EgInstallInfo.isSuperManager)
			{
				url = url +"&sm_session_url=true";
			}
		}
	}
	if (isReport)
	{
	}

	if (isConfig)
	{
	}
	if(isSla && isEnableSLA){
		String slaLastSession=(String)session.getAttribute("slaLastSession");
		session.removeAttribute("slaLastSession");
		if(slaLastSession!=null )
		{
			if(slaLastSession.indexOf("currentTab=")>0){
				String lastViewedTab=(String)session.getAttribute("lastTabViewed");
				String afterViewTab=slaLastSession.substring(slaLastSession.indexOf("currentTab=")+11);
				String beforeViewTab=slaLastSession.substring(0,slaLastSession.indexOf("currentTab=")+11);
				afterViewTab=afterViewTab.substring(afterViewTab.indexOf("&"),afterViewTab.length());
				slaLastSession=beforeViewTab+lastViewedTab+afterViewTab;
			}
			url=slaLastSession;
		}
	}
	if (noValidUserRolesForSM)//if logged in user is of role either REPORTER or CONFIG , use monitor skin
	{
	}
	if (isMonitor && (fromPage!=null && fromPage.equals("GlobalSearch")))
	{		
		String qryString = ErUtils.prepareQueryString(request.getParameterMap());
		if(qryString!=null)
		{
			String fromSearch = request.getParameter("fromSearch");
			if(fromSearch!=null && (fromSearch.equals("user") || fromSearch.equals("vm")))
			{
				//url = "/final/monitor/eGSearch.jsp?"+qryString;
				ArrayList qs_list =  com.egurkha.util.StringUtils.egTokenizer(qryString.trim(),"&",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
				
				if(qs_list != null && qs_list.size() > 0)
				{
					String en_qs = "";
					for(int l=0;l<qs_list.size();l++)
					{
						String el = (String)qs_list.get(l);
						try
						{
						
							String ql_key = el.substring(0,el.indexOf("="));
							String ql_value = el.substring(el.indexOf("=")+1);
							ql_value = EgURLEncoder.encode(ql_value, "UTF-8");
							en_qs +=ql_key+"="+ql_value;
							if(l+1 != qs_list.size())
								en_qs+="&";
						}catch(Exception qwe)
						{
						}
					}
					url = "/final/monitor/eGSearch.jsp?"+en_qs;
				}
			}
			if(fromSearch!=null && (fromSearch.equals("segment") || fromSearch.equals("zone") || fromSearch.equals("server") || fromSearch.equals("service")))
			{				
				url = "/final/servlet/com.eg.EgMonitorController?"+qryString;			
			}
		}
		currentMonitorHomePageURL=url;		
	}
	boolean isAdminNewWindow = false;
	boolean isMonitorNewWindow = false;
	boolean isReporterNewWindow = false;
	boolean isConfigNewWindow=false;
	boolean isSlaNewWindow=false;
	
	boolean isAdminSeperator=false;
	boolean isMonitorSeperator = false;
	boolean isReporterSeperator=false;
	boolean isConfigSeperator=false;
	boolean isSlaSeperator=false;
	
	
	boolean adminPressed=false;
	boolean monitorPressed=false;
	boolean reporterPressed=false;
	boolean configPressed=false;
	boolean slaPressed=false;
	
	if(pressed!=null )
	{
		if(pressed.equals("admin"))
		{
			adminPressed = true;
		}
		if(pressed.equals("monitor"))
		{
			monitorPressed = true;
		}
		if(pressed.equals("reporter"))
		{
			reporterPressed = true;
		}
		if(pressed.equals("config"))
		{
			configPressed = true;
		}
		if(pressed.equals("sla") && isEnableSLA)
		{
			slaPressed = true;
		}

	}
	else
	{
		if(entry.equals("admin"))
		{
			adminPressed=true;
			if(EgInstallInfo.isSuperManager)
			{
				if(!login_as_egsm_in_sm)
				{
					adminPressed=false;
					monitorPressed = true;
				}
			}
		}
		if(entry.equals("monitor"))
		{
			monitorPressed = true;
		}
		if(entry.equals("reporter"))
		{
			reporterPressed = true;
		}
		if(entry.equals("config"))
		{
			configPressed = true;
		}
		if(entry.equals("sla") && isEnableSLA)
		{
			slaPressed = true;
		}
				
	}
	
	if(entry!=null &&  newWindow!=null)
	{
		if(entry.equals("admin") && newWindow.equalsIgnoreCase("yes"))
		{
			isMonitorNewWindow = true;
			isReporterNewWindow = true;
			isConfigNewWindow=true;
			isSlaNewWindow=true;
			
			isAdminSeperator=true;
			isMonitorSeperator = true;
			isReporterSeperator=true;
			isConfigSeperator=true;
			isSlaSeperator=true;
			
			adminPressed=true;
			
			
			
		}
		if(entry.equals("monitor") && newWindow.equalsIgnoreCase("yes"))
		{
			isAdminNewWindow = true;
			isReporterNewWindow = true;
			isConfigNewWindow=true;
			isSlaNewWindow=true;
			
			isAdminSeperator=true;
			isMonitorSeperator = true;
			isReporterSeperator=true;
			isConfigSeperator=true;
			isSlaSeperator=true;
			
			monitorPressed=true;
			
		}
		if(entry.equals("reporter") && newWindow.equalsIgnoreCase("yes"))
		{
			isMonitorNewWindow = true;
			isAdminNewWindow = true;
			isConfigNewWindow=true;
			isSlaNewWindow=true;
			
			isAdminSeperator=true;
			isMonitorSeperator = true;
			isReporterSeperator=true;
			isConfigSeperator=true;
			isSlaSeperator=true;
			
			reporterPressed=true;
		}
		if(entry.equals("config") && newWindow.equalsIgnoreCase("yes"))
		{
			isMonitorNewWindow = true;
			isReporterNewWindow = true;
			isAdminNewWindow=true;
			isSlaNewWindow=true;
			
			isAdminSeperator=true;
			isMonitorSeperator = true;
			isReporterSeperator=true;
			isConfigSeperator=true;
			isSlaSeperator=true;
			
			configPressed=true;
		}
		if(entry.equals("sla") && isEnableSLA && newWindow.equalsIgnoreCase("yes"))
		{
			isMonitorNewWindow = true;
			isReporterNewWindow = true;
			isAdminNewWindow=true;
			isConfigNewWindow=true;
		
			isAdminSeperator=true;
			isMonitorSeperator = true;
			isReporterSeperator=true;
			isConfigSeperator=true;
			isSlaSeperator=true;
			slaPressed=true;
		}
	}
	
	if(hasAdminTab)
	{
		if(!hasMonitorTab && !hasReporterTab && !hasConfigTab && !hasSlaTab)
			isAdminSeperator=true;
	}
	if(hasMonitorTab)
	{

		if(!hasReporterTab && !hasConfigTab && !hasSlaTab)
			isMonitorSeperator=true;
	}
	if(hasReporterTab)
	{
		
		if(!hasConfigTab && !hasSlaTab)
			isReporterSeperator=true;
	}
	if(hasConfigTab)
	{
		if(!hasSlaTab)
			isConfigSeperator=true;
	}
	if(hasSlaTab && isEnableSLA)
	{
			isSlaSeperator=true;
	}
	
	boolean isAdminNewWindowIcon = false;
	boolean isMonitorNewWindowIcon = false;
	boolean isReporterNewWindowIcon = false;
	boolean isConfigNewWindowIcon=false;
	boolean isSlaNewWindowIcon=false;

	
	if(!hasAdminTab)
	{
		isAdminNewWindow = true;
		isAdminNewWindowIcon=true;
		isAdminSeperator=true;
		
	}
	if(!hasMonitorTab)
	{
		isMonitorNewWindow = true;
		isMonitorNewWindowIcon=true;
		isMonitorSeperator=true;
		
	}
	if(!hasReporterTab)
	{
		isReporterNewWindow = true;
		isReporterNewWindowIcon=true;
		isReporterSeperator=true;
	
	}
	
	if(!hasConfigTab)
	{
		isConfigNewWindow=true;
		isConfigNewWindowIcon=true;
		isConfigSeperator=true;
	}
	if(!hasSlaTab)
	{
		isSlaNewWindow=true;
		isSlaNewWindowIcon=true;
		isSlaSeperator=true;
	}
	


	if(newWindow!=null && newWindow.equalsIgnoreCase("yes"))
	{
		isAdminNewWindowIcon = true;
		isMonitorNewWindowIcon = true;
		isReporterNewWindowIcon = true;
		isConfigNewWindowIcon=true;
		isSlaNewWindowIcon=true;
	}

	String smartHome=request.getParameter("SmartHomePage");
	smartHome=(smartHome==null)?"":smartHome;
    EgDateInfo egDate = new EgDateInfo();
    Date local_date = new Date(egDate.egetUTCDate());
    cal.setTime(local_date);
    cal.setTimeZone(egDate.getRealTimeZone());
    String temp1 = (cal.get(cal.MONTH)+1) + "/" + cal.get(cal.DAY_OF_MONTH) + "/" +cal.get(cal.YEAR);
    String mgr_time = cal.get(cal.HOUR_OF_DAY)+":"+cal.get(cal.MINUTE)+":"+cal.get(cal.SECOND);
    String dispDate = DateUtil.changeDateFormat(temp1,"MM/dd/yyyy",currentDateFormat);
    TimeZone tz = egDate.getRealTimeZone();
    String tzName = tz.getDisplayName(tz.inDaylightTime(local_date), TimeZone.SHORT);
    EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(dispDate+" "+mgr_time,user);
    String loginUserDateTime = (String)timeZoneConverter.getDate(false);
    Date loginUserDate = (Date)timeZoneConverter.getDate(true);
    TimeZone user_tz = (TimeZone)timeZoneConverter.getTimeZone();
    if( loginUserDateTime != null && !loginUserDateTime.trim().equals(""))
    {
    	dispDate = loginUserDateTime;
	tzName = user_tz.getDisplayName(user_tz.inDaylightTime(loginUserDate), TimeZone.SHORT);
    }

	ArrayList extensionList = new ArrayList();
	extensionList.add("gif");
	extensionList.add("jpeg");
	extensionList.add("jpg");
	extensionList.add("png");

	configmsg.createFile("eg_services.ini");
	String MailHomeUrl = configmsg.getStrValue("MISC_ARGS","MailHomeUrl");
	
	String imageName = null;
	String tempLogo=user.getUserLogo();

	String userLogo[] = StringUtils.getTokens(tempLogo,"\\");
	if (entry.equalsIgnoreCase("admin") || entry.equalsIgnoreCase("monitor"))
	{
		String temp="";
		if(userLogo!=null && userLogo.length==5)
		{
			temp=userLogo[1];
		}
		if(EgInstallInfo.isSuperManager)
		{
			if(!temp.equals("c"))
			{
				imageName = ui.getMonitorHomeLogo();
			}
			else
			{
				imageName="/final/monitor/eg_images/egsm_monitor.gif";
				for (int ext = 0; ext < extensionList.size(); ext++)
				{
					String strExtension = (String)extensionList.get(ext);
					File sourceFile = new File(EgInstallInfo.getInstallDir()+"/manager/tomcat/webapps/final/monitor/eg_images/egsm_monitor."+strExtension);
					if (sourceFile.exists())
					{
						imageName="/final/monitor/eg_images/egsm_monitor."+strExtension;
						break;
					}
				}
			}
		}
		else if(!temp.equals("c"))
		{
			imageName = ui.getMonitorHomeLogo();
		}
		else
		{
			
			if(temp_id!=null && temp_id.indexOf("/")>-1)
			{
				String domainName=temp_id.substring(0,temp_id.indexOf("/"));
				String userName=temp_id.substring(temp_id.indexOf("/")+1,temp_id.length());

				//MAS/Grp/Domain Users

				if(userName.indexOf("Grp")>-1)
				{
					userName=userName.substring(userName.indexOf("/")+1,userName.length());
				}
				userName = StringUtils.replace(userName," ","");
				temp_id=domainName.toLowerCase()+"_"+userName;
				
			}
			for (int ext = 0; ext < extensionList.size(); ext++)
			{
				String strExtension = (String)extensionList.get(ext);
				File sourceFile = new File(EgInstallInfo.getInstallDir()+"/manager/tomcat/webapps/final/monitor/eg_images/"+temp_id+"_monitor."+strExtension);
				if (sourceFile.exists())
				{
					imageName="/final/monitor/eg_images/"+EgURLEncoder.encode(temp_id,"UTF-8")+"_monitor."+strExtension;
					break;
				}
			}
		}
		
	}
	else if (entry.equalsIgnoreCase("reporter"))
	{
		String temp="";
		if(userLogo!=null && userLogo.length==5)
		{
			temp=userLogo[2];
		}
		if(!temp.equals("c"))
		{
			imageName = ui.getReporterHomeLogo();
		}
		else
		{
			if(temp_id!=null && temp_id.indexOf("/")>-1)
			{
				String domainName=temp_id.substring(0,temp_id.indexOf("/"));
				String userName=temp_id.substring(temp_id.indexOf("/")+1,temp_id.length());
				if(userName.indexOf("Grp")>-1)
				{
					userName=userName.substring(userName.indexOf("/")+1,userName.length());
				}
				userName = StringUtils.replace(userName," ","");
				temp_id=domainName.toLowerCase()+"_"+userName;
				//out.println(temp_id);
				
			}
			for (int ext = 0; ext < extensionList.size(); ext++)
			{
				String strExtension = (String)extensionList.get(ext);
				File sourceFile = new File(EgInstallInfo.getInstallDir()+"/manager/tomcat/webapps/final/reporter/images/"+temp_id+"_reporter."+strExtension);
				if (sourceFile.exists())
				{
					imageName="/final/reporter/images/"+EgURLEncoder.encode(temp_id,"UTF-8")+"_reporter."+strExtension;
					break;
				}
			}
		}
		
	}
	else if (entry.equalsIgnoreCase("config"))
	{
		String temp="";
		if(userLogo!=null && userLogo.length==5)
		{
			temp=userLogo[3];
		}
		if(!temp.equals("c"))
		{
			imageName = ui.getConfigHomeLogo();
		}
		else
		{
			if(temp_id!=null && temp_id.indexOf("/")>-1)
			{
				String domainName=temp_id.substring(0,temp_id.indexOf("/"));
				String userName=temp_id.substring(temp_id.indexOf("/")+1,temp_id.length());
				if(userName.indexOf("Grp")>-1)
				{
					userName=userName.substring(userName.indexOf("/")+1,userName.length());
				}
				userName = StringUtils.replace(userName," ","");
				temp_id=domainName.toLowerCase()+"_"+userName;
				//out.println(temp_id);
			}
			for (int ext = 0; ext < extensionList.size(); ext++)
			{
				String strExtension = (String)extensionList.get(ext);
				File sourceFile = new File(EgInstallInfo.getInstallDir()+"/manager/tomcat/webapps/final/config/images/"+temp_id+"_config."+strExtension);
				if (sourceFile.exists())
				{
					imageName="/final/config/images/"+EgURLEncoder.encode(temp_id,"UTF-8")+"_config."+strExtension;
					break;
				}
			}
		}
	}
	else if (entry.equalsIgnoreCase("sla") && isEnableSLA)
	{
		String temp="";
		if(userLogo!=null && userLogo.length==5)
		{
			temp=userLogo[4];
		}
	
		if(!temp.equals("c"))
		{
			imageName = ui.getSlaHomeLogo();
		}
		else
		{
			if(temp_id!=null && temp_id.indexOf("/")>-1)
			{
				String domainName=temp_id.substring(0,temp_id.indexOf("/"));
				String userName=temp_id.substring(temp_id.indexOf("/")+1,temp_id.length());
				if(userName.indexOf("Grp")>-1)
				{
					userName=userName.substring(userName.indexOf("/")+1,userName.length());
				}
				userName = StringUtils.replace(userName," ","");
				temp_id=domainName.toLowerCase()+"_"+userName;
				//out.println(temp_id);
			}
			for (int ext = 0; ext < extensionList.size(); ext++)
			{
				String strExtension = (String)extensionList.get(ext);
				File sourceFile = new File(EgInstallInfo.getInstallDir()+"/manager/tomcat/webapps/final/SLA/images/"+temp_id+"_sla."+strExtension);
				if (sourceFile.exists())
				{
					imageName="/final/SLA/images/"+EgURLEncoder.encode(temp_id,"UTF-8")+"_sla."+strExtension;
					break;
				}
			}
		}
	}
	String text  = "";
	if (imageName == null)
	{
		//out.print("&nbsp;");
	}
	else
	{
		String title = configmsg.getStrValue("MISC_ARGS", "ManagerTitle");
		if (com.egurkha.util.StringUtils.isNull(title))
		{
			text = "v" + EgInstallInfo.version;
		}
		else
		{
			text = title;
		}
	}
	if(entry.equalsIgnoreCase("admin") && isAdmin)
	{
	}
	else
	{
	}
	String isSM =(String)session.getAttribute("fromSM");
%>

<jsp:useBean id="SiteBean" scope="page" class="egurkha.ConfigSiteBean"/>
<jsp:useBean id="transBean" scope="page" class="egurkha.TransactionBean"/>

<%
	transBean.createFile("eg_ui.ini");
	String enableLicenseAlert = transBean.getStrValue("LICENSE_EXPIRY_ALERT","enable");
	String licenceValidAlert = SiteBean.lcat();
	
	String userExpiryMsg = "";
	transBean.createFile("eg_services.ini");
	String userID = (String)session.getAttribute("sess_userid");
	long noOfDays = 0L;
	if (session.getAttribute("sess_uservalidtill") != null)
		noOfDays = ((Long)session.getAttribute("sess_uservalidtill")).longValue();
	if(userID != null && !userID.equals("admin") && !userID.equals("supermonitor"))
	{
		if(noOfDays <= 7)
		{
			userExpiryMsg = transBean.getStrValue("MISC_ARGS","LicenseExpiryMess");
			if(userExpiryMsg.indexOf("[no_of_days]")>-1)
			{
				userExpiryMsg = userExpiryMsg.substring(0,userExpiryMsg.indexOf("[no_of_days]")) + noOfDays + userExpiryMsg.substring(userExpiryMsg.lastIndexOf("[no_of_days]") + 12,userExpiryMsg.length());
			}
		}
	}
	
	String showAlarmPopUp = "yes";
	if((fromPage != null && fromPage.equals("newAlarmAlert")) || isAlarmQView)
	{
		showAlarmPopUp = "no";
	}
	if(fromSm!=null && (fromSm.equals("yes") || fromSm.equals("home")) && request.getParameter("fromsuperHome")==null)
	{
		showAlarmPopUp = "no";
	}
	//if(monitorLastSession!=null && !monitorLastSession.equalsIgnoreCase("/final/servlet/com.eg.EgMonitorController?monCmd=dashboard"))
	if(monitorLastSession!=null && !monitorLastSession.equalsIgnoreCase(currentMonitorHomePageURL))
	{
		showAlarmPopUp = "no";
	}
	

	if(isFromQuickLaunch)
	{
		showAlarmPopUp = "no";
	}

	if(fromSm!=null)
	{
		session.setAttribute("fromSM", "yes");
	}
	if(fromQuickLaunch!=null)
	{
		//session.setAttribute("fromQuickLaunchPage", "yes");
	}
	String selectedTabTheme="";

	if(entry.equalsIgnoreCase("admin"))
	{
		selectedTabTheme = user.getAdminSkin();
	}
	else if(entry.equalsIgnoreCase("monitor"))
	{
		selectedTabTheme = user.getMonitorSkin();
	}
	else if(entry.equalsIgnoreCase("reporter"))
	{
		selectedTabTheme = user.getReporterSkin();
	}
	else if(entry.equalsIgnoreCase("config"))
	{
		selectedTabTheme = user.getConfigSkin();
	}
	String previousSelectedTabModule=request.getParameter("previousSelectedTabModule");
	boolean hasAllComponentAccess=userRole.hasAllComponentAccess();
	JSONObject rootJson=new JSONObject();
	rootJson.put("isShowAlarmsInLightBox",String.valueOf(isShowAlarmsInLightBox));
	rootJson.put("isShowSlaAlertsPopup",String.valueOf(isShowSlaAlertsPopup));
	rootJson.put("homepage",currentMonitorHomePageURL);
	rootJson.put("smartHomePage",smartHome);
	rootJson.put("url",url);
	rootJson.put("showMonitoringDomainPopup",new Boolean(showMonitoringDomainPopup));
	rootJson.put("adminPressed",adminPressed);
	rootJson.put("monitorPressed",monitorPressed);
	rootJson.put("reporterPressed",reporterPressed);
	rootJson.put("configPressed",configPressed);
	rootJson.put("slaPressed",slaPressed);
	rootJson.put("isUsersLimitCrossed",isUsersLimitCrossed);
	rootJson.put("alertUserAbtUserCert",alertUserAbtUserCert);
	rootJson.put("userExpiryMsg",userExpiryMsg);
	rootJson.put("isLicenceValid",licenceValidAlert);
	rootJson.put("isLicenseEnabled",enableLicenseAlert);
	rootJson.put("helpURL",helpURL);
	rootJson.put("isDisableMydashboardPopout",isDisableMydashboardPopout);
	rootJson.put("LogoImageName",imageName);
	rootJson.put("moduleName",entry);
	rootJson.put("egTheme",tabIMG);
	rootJson.put("hideAlarmPopup",hideAlarmPopup);
	rootJson.put("selectedTabTheme",selectedTabTheme);
	if(hideMonDomainPopup)
		showAlarmPopUp="no";

	rootJson.put("showAlarmPopUp",showAlarmPopUp);
	rootJson.put("hasTVModeSelectedscreens",isTVModeSelectedscreens);
	rootJson.put("hideMonitoringDomainPopup",new Boolean(hideMonDomainPopup));

	String selectedMod=entry;
	String selectedPrevMod=previousSelectedTabModule;
	if(pressed!=null && pressed.equals("config"))
	{
		selectedMod="configindex";
	}
	if(previousSelectedTabModule!=null && previousSelectedTabModule.equals("config"))
	{
		selectedPrevMod="configindex";
	}
	rootJson.put("currentSkin",skinStyleSheet(user,selectedMod));
	rootJson.put("previousSkin",skinStyleSheet(user,selectedPrevMod));

	rootJson.put("currentTheme",skinStyleSheet(user,selectedMod,true));
	rootJson.put("previousTheme",skinStyleSheet(user,selectedPrevMod,true));

	String strLayerUrl = request.getParameter("monLayerUrl");
	if (!StringUtils.isNull(strLayerUrl))
	{
		strLayerUrl=com.egurkha.util.StringUtils.decodeSecurityChar(strLayerUrl);
		strLayerUrl=  com.egurkha.util.StringUtils.replace(strLayerUrl,"|qs|","?");
		strLayerUrl=  com.egurkha.util.StringUtils.replace(strLayerUrl,"|eq|","=");
		strLayerUrl=  com.egurkha.util.StringUtils.replace(strLayerUrl,"|amp|","&");
		//rootJson.put("LayerTestConfigUrl",strLayerUrl);
		String monLayerTestConfigUrl = "";
		if(strLayerUrl != null)
		{
			StringTokenizer strtok = new StringTokenizer(strLayerUrl,"&");
			while(strtok.hasMoreTokens())
			{
				String param = strtok.nextToken();
				String reqparam = param.substring(0,param.indexOf("="));
				String value = param.substring(param.indexOf("=")+1,param.length());
				if(reqparam!=null && reqparam.equalsIgnoreCase("monDescName"))
				{
					value = com.egurkha.util.StringUtils.encodeSecurityChar(value);
					if(value!=null && !value.equalsIgnoreCase("NULL"))
						value = EgURLEncoder.encode(value,"UTF-8");
				}
					
				//if(value!=null && !value.equalsIgnoreCase("NULL"))
				//{
					monLayerTestConfigUrl=monLayerTestConfigUrl+reqparam+"="+value+"&";
				//}
			}
			if(monLayerTestConfigUrl.endsWith("&"))
				monLayerTestConfigUrl=monLayerTestConfigUrl.substring(0,monLayerTestConfigUrl.lastIndexOf("&"));
		}
		rootJson.put("LayerTestConfigUrl",monLayerTestConfigUrl);
		
	}

	out.println(rootJson.toString());

%>

<%
	EgDbAdapterUI egDb;
	String loginFirstTime = (String)session.getAttribute("isLoggingFirstTime");
	String loggedInUser = (String)session.getAttribute("sess_userid");
	IniFile idxControl =  new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");
	String enableChangePassword = (String)idxControl.getValue("USER_SIGN_IN","enableChangePassword");
	boolean isChangePwdEnabled = (enableChangePassword != null && enableChangePassword.equalsIgnoreCase("true"));

	boolean isAdminUser = (loggedInUser != null && loggedInUser.equalsIgnoreCase(EgConstants.DEFAULT_ADMIN_USER));
	boolean isLoginFirstTime = (loginFirstTime != null && loginFirstTime.equalsIgnoreCase("false"));
	ResultSet rs_upass = null;
	String str_conn = "";
	String str_query = "";
	String str_pass = "";
	boolean b_state = false;
	String current_user=_user.getLoginID();
	egDb=EgDbAdapterTypeUI.getObject();
	int x=0;
	try
	{
		if(EgInstallInfo.isSuperManager)
		{
			//simply checking if database is up
			str_conn = egDb.setConnection();
			b_state=egDb.getState();
			egDb.releaseConnection(false);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		else
		{
			str_conn = egDb.setConnection();
			str_query = "SELECT user_pass FROM user_info WHERE user_id='admin'";
			rs_upass = egDb.SelectExec(str_query);
			while(rs_upass.next())
			{
				str_pass=rs_upass.getString("user_pass");
			}
			b_state=egDb.getState();
			rs_upass.close();
			egDb.releaseConnection(false);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
	}
	catch(Exception e)
	{
		if(!str_conn.equals("CONNECTED"))
		{
			out.println("Connection could not be established");
		}
		else if(!b_state==true)
		{
			out.println("Error in sql query");
		}
		else
		{
			out.println("");
		}
		out.println(e.toString());
		if (rs_upass != null)
		{
			try
			{
				rs_upass.close();
			}
			catch (Exception bug123)
			{
			}
		}
		try
		{
			egDb.releaseConnection(true);
			EgDbAdapterTypeUI.releaseObject(egDb);
		}
		catch(Exception e1)
		{}
	}
	str_pass = EgCrypt.decrypt(str_pass);
	session.removeAttribute("isLoggingFirstTime");

	session.setAttribute("hasNotificationWindow","no");
	session.setAttribute("egEntry",entry);
	session.setAttribute("egVersion",text);
	if(newWindow!=null && newWindow.trim().length()>0 && newWindow.equals("yes"))
	{
		if(fromSm != null && (fromSm.equals("yes") || fromSm.equals("home")))
		{
			String reqUrl = request.getRequestURL().toString();
			String qryString = request.getQueryString();
			if(reqUrl != null && reqUrl.endsWith("egIndex.jsp"))
			{
				session.setAttribute("smIndexPage","/final/egIndex.jsp?"+qryString);
			}
			session.setAttribute("fromSm","yes");
		}
		session.setAttribute("egEntryChild", entry);
		session.setAttribute("childWindow","yes");
	}
	else 
		session.setAttribute("egEntryMain", entry);
 
}
catch(Throwable th)
{
	th.printStackTrace();
}
%>



