
<%@ include file = "../../../EgMonitorTracker.jsp"%>

<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.egurkha.*"%>
<%@ page import="com.egurkha.monitor.EgCustomModel"%>
<%@ page import="com.egurkha.monitor.Dashboard"%>
<%@ page import = "com.eg.EgTopoInfo" %>
<%@ page import="com.eg.EgCrypt"%>
<%@ page import="com.eg.IniFile"%>
<%@ page import="com.egurkha.User"%>
<%@ page import="com.egurkha.ini.*"%>
<%@ page import="com.egurkha.util.*"%>
<%@ page import="com.eg.EgInstallInfo"%>
<%@ page import="com.eg.EgServicesInfo"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import = "com.eg.EgSpecsInfo" %>
<%@ page import="com.eg.EgURLEncoder"%>
<%@ page import="com.eg.EgManagersIniForManager"%>
<%@ page import="egurkha.EgDbAdapterUI"%>
<%@ page import="com.eg.EgDbAdapterTypeUI"%>
<%@ page import="com.egurkha.UserRegistry"%>
<%@ page import="com.egurkha.monitor.alarms.*"%>
<%@ page import="com.egurkha.util.DateUtil"%>
<%@ page import="com.egurkha.util.EgSorter"%>
<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="net.sf.json.JSONArray"%>
<%@ page import = "egurkha.reporter.ErFavorite" %>
<%@ page import="com.egurkha.monitor.OneClickDashboardModel"%>
<%@ page import="com.egurkha.monitor.Dashboard"%>
<%@ page import = "com.eg.EgMemCheck"%>
<%@ page import = "com.eg.EgConfigFilesSync"%>
<%@ page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%!
public boolean isCheckPermission(String url_l,EgUserRole userRole)
{
	 String s_resUri=url_l; 
	 String s_resQryStr = "";
	 int idx = s_resUri.indexOf('?');
	 if(idx!=-1)
		 {
		s_resQryStr = s_resUri.substring(idx + 1);
		s_resUri = s_resUri.substring(0,idx);
	 }
	 EgUserPermission userPerm = EgUserPermission.getInstance();
	 boolean accesscontrol=userPerm.checkPermission(s_resUri,s_resQryStr,userRole);
	 return accesscontrol;
}
public String getMonitorBy(String test_name,com.eg.IniFile egDashConfig)
{
	String monitor_by = "";
	String dash_ar[]= egDashConfig.getVariables("ExtTestDashboard");
	if(dash_ar!=null && dash_ar.length>0)
	{
		for(int monT=0;monT<dash_ar.length;monT++)
		{
			String s_support_type = dash_ar[monT];
			String s_support_type_test =egDashConfig.getValue("ExtTestDashboard",s_support_type);
			if(s_support_type_test.equalsIgnoreCase(test_name))
			{
				monitor_by = s_support_type;
				break;
			}
		}
	}
	return monitor_by;
}
%>
<%
	IniFile egUi = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_ui.ini",true);
	IniFile customIniObj=EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_customdashboard.ini",true);
	IniFile citrixConfig = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir() + "/manager/config/eg_citrixdashboard.ini");
	IniFile egDashConfig = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir() + "/manager/config/eg_dashboardConfig.ini");
	IniFile eg_externalIni =  EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir() + "/manager/config/eg_external.ini");
	IniFile serverDashBoardINI = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_serverdashboard.ini");
	IniFile seumINI = EgConfigFilesSync.getInstance(EgInstallInfo.getInstallDir()+"/manager/config/eg_extmondash.ini");
	UserRegistry registry = UserRegistry.getInstance();
	User user = registry.getUser(session.getId());
	String loginID = "";
	List userServerTypes = new LinkedList();
	EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
	if(user != null){
		loginID = user.getLoginID();
		userServerTypes.addAll(user.getServerTypes());
	}
	JSONObject rootJson = new JSONObject();
	String selectedMonitorDomain=customIniObj.getValue("USER_DOMAIN_MAPPING",user.getLoginID());
	String enableServiceHealth = egUi.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;

	boolean login_as_egsm_in_sm=false;
	if(EgInstallInfo.isSuperManager)
	{
		login_as_egsm_in_sm=user.getLoginID().equals("egsm");
	}
    EgUserRole userRole = EgUserRole.getRoleObject(user.getLoginType());
    boolean hasConfigEnabled = EgInstallInfo.isConfigSupported;
	boolean hasReporteEnabled = EgInstallInfo.isReporterSupported;
	boolean mapEnabled = false;
	String mapLicense = egUi.getValue("ZONE_MAP","mapEnabled");
	mapEnabled = (mapLicense != null && mapLicense.equalsIgnoreCase("yes"));
	IniFile userMappingIni = new IniFile(EgInstallInfo.getInstallDir() + "/manager/config/eg_ui.ini");
	boolean isDomainUser = false;
	String userName = user.getLoginID();
	String uname = userName;
	String temp_Usr = userMappingIni.getValue("DBUSER_USER_MAP", uname);
	if (temp_Usr != null && temp_Usr.length() > 0)
	{
		uname = temp_Usr;
	}
	if (uname.indexOf("/Grp/") != -1)
	{
		String grpDelimiter = "/Grp/";
		int idx = uname.indexOf(grpDelimiter);
		String str_uname_A = uname.substring(0, idx);
		int nextIdx = idx + grpDelimiter.length();
		String str_uname_B = uname.substring(nextIdx);
		uname = str_uname_A + "/" + str_uname_B + " (Group)";
	}
	if (userName.indexOf("/") > 0 || userName.indexOf("\\") > 0)
		isDomainUser = true;
    String tempUname = StringUtils.replace(uname, "<", "&lt;");
	tempUname = StringUtils.replace(tempUname, ">", "&gt;");

		if (tempUname.startsWith("samlsso/"))
		{
			String tmp = tempUname;
			int idx = tmp.indexOf("/");
			String str_uname_A = tmp.substring(idx+1);
			tempUname = str_uname_A + " (SAML)";
		}

	
	//***********************TVMode Operation***********************
		
		String timeFrequency = egUi.getValue("Misc_TV_Settings","PlaybackFrequency");

		JSONObject TvModeFreq = new JSONObject();
		JSONArray TvModeArrayListTimeFreq = new JSONArray();
		Object TvFrequency[] =  egUi.getVariables("Playback_Frequency");
		List freqList = Arrays.asList(TvFrequency);
		for(int idx=0;idx<freqList.size();idx++)
		{
			String freqTime = (String)freqList.get(idx);
			String timeInSec = egUi.getValue("Playback_Frequency",freqTime);
			TvModeFreq.put("valueField",freqTime);
			TvModeFreq.put("displayField",mappingInfo.getTextDescription("monitor.common."+timeInSec));
			TvModeArrayListTimeFreq.add(TvModeFreq);
		}
		int timeOnlyInt = Integer.parseInt(timeFrequency)/1000;
		rootJson.put("tvModeTimeFrequency", timeOnlyInt);
		rootJson.put("frequencyCombo",TvModeArrayListTimeFreq);
		boolean tvAvailUser=false;

		ArrayList allRoleName=userRole.getAllRoleNames();
		Vector getAllRoles=userRole.getAllRoles();
		EgUserPermission userPermission = EgUserPermission.getInstance();
		ArrayList monitorPrivilegeList=userPermission.getPrivilegeList(user.getLoginID().toLowerCase(),userRole.getMonitorPerm(),1);
		ArrayList adminPrivilegeList=userPermission.getPrivilegeList(user.getLoginID().toLowerCase(),userRole.getAdminPerm(),0);
		boolean hasMyDash=isCheckPermission("/final/monitor/MyDashboard.jsp?",user.getUserRole());
		TreeSet<String> screenListTree=new TreeSet<String>();
		Hashtable playbackFreq = new Hashtable();
		if (login_as_egsm_in_sm || userRole.getMonitorPerm() > 0 || hasReporteEnabled && userRole.getReporterPerm() > 0 || hasConfigEnabled && userRole.getConfigPerm() > 0)
		{
			Object tvUsers[] =  egUi.getVariables("eG_TVMode_selected_screens");
			if (tvUsers != null && tvUsers.length > 0)
			{
				for (int i = 0; i < tvUsers.length; i++)
				{
					
					String TvUserName = (String) tvUsers[i];
					if(TvUserName.equals(user.getLoginID().toLowerCase()))
					{
						tvAvailUser=true;
					}
				}
			}
			String kio_Frequency=egUi.getValue("Kiosk_Playback_Frequency",user.getLoginID().toLowerCase());
			if(kio_Frequency == null || kio_Frequency.equals(""))
			{
				kio_Frequency=egUi.getValue("Kiosk_Playback_Frequency","Kiosk_Default_Frequency");
			}
			
			StringTokenizer stFreq=new StringTokenizer(kio_Frequency,","); 
			while (stFreq.hasMoreTokens()) { 
				String val = stFreq.nextToken();
				StringTokenizer freq=new StringTokenizer(val,"^"); 
				while (freq.hasMoreTokens()) { 
					String screen_Key = freq.nextToken();
					String screen_Val = freq.nextToken();
					int timeFreq = Integer.parseInt(screen_Val)/1000;
					playbackFreq.put(screen_Key,timeFreq);
				}
			 }
			String MonitorTVModesupportedscreens = egUi.getValue("eG_TVMode_selected_screens",user.getLoginID().toLowerCase());
			StringTokenizer st=new StringTokenizer(MonitorTVModesupportedscreens,","); 
			while (st.hasMoreTokens()) { 
				String val = st.nextToken();
				screenListTree.add(val);
			 } 
		}

		JSONArray TvModeArrayListScrens = new JSONArray();
		JSONObject TvModeMonJson = new JSONObject();
		JSONArray TvModeKioskArrayListScrens = new JSONArray();
		JSONObject TvModeKioskMonJson = new JSONObject();
		boolean hasAlarmHistoryEnabled=isCheckPermission("/monitor/EgSiteInfraView.jsp?disphist=yes",user.getUserRole());
		if (login_as_egsm_in_sm || userRole.getMonitorPerm() > 0)
		{
			Object TvScreens[] =  egUi.getVariables("Monitor_TVMode_supported_screens");
			List screenList = new LinkedList();
			if (TvScreens != null && TvScreens.length > 0)
			{
				for (int i = 0; i < TvScreens.length; i++)
				{
					
					String TvScreenslist = (String) TvScreens[i];
					if (TvScreenslist != null && TvScreenslist.trim().length() > 0)
					{
						screenList.add(TvScreenslist);
					}
				}
			}
		
			boolean userView=userRole.hasAllComponentAccess();
			for(int idx=0;idx<screenList.size();idx++)
			{
				if(!mapEnabled)
				{
					int shIndex1 = screenList.indexOf("Zone Map");
					if (shIndex1 >= 0)
					{
						screenList.remove(shIndex1 + 1);
						screenList.remove(shIndex1);
					}
				}				
				if (!isEnableServiceHealth)
				{
					int shIndex = screenList.indexOf("Service Health");
					if (shIndex >= 0)
					{
						screenList.remove(shIndex + 1);
						screenList.remove(shIndex);
					}
				}
				if (!EgInstallInfo.isAggregationSupported())
				{
					int aggIndex = screenList.indexOf("Aggregates");
					if (aggIndex >= 0)
					{
						screenList.remove(aggIndex + 1);
						screenList.remove(aggIndex);
					}
				}
				if(!userView)
				{
					int aggIndex = screenList.indexOf("User View");
					if (aggIndex >= 0)
					{
						screenList.remove(aggIndex + 1);
						screenList.remove(aggIndex);
					}
				}
				if (!hasAlarmHistoryEnabled)
				{
					int aggIndex = screenList.indexOf("Alarm History");
					
					
					if (aggIndex >= 0)
					{
						screenList.remove(aggIndex + 1);
						screenList.remove(aggIndex);
					}
					int AckIndex = screenList.indexOf("Acknowledgement History");
					if (AckIndex >= 0)
					{
						screenList.remove(AckIndex + 1);
						screenList.remove(AckIndex);
					}
					int delIndex = screenList.indexOf("Deletion History");
					if (delIndex >= 0)
					{
						screenList.remove(delIndex + 1);
						screenList.remove(delIndex);
					}
				}
				String screenName = (String)screenList.get(idx);
				String screenUrl = egUi.getValue("Monitor_TVMode_supported_screens",screenName);
				TvModeKioskMonJson.put("dashbordName",screenName);
				TvModeKioskMonJson.put("displayDashboardName",mappingInfo.getTextDescription("monitor.common."+screenName));
				TvModeKioskMonJson.put("moduleName",mappingInfo.getTextDescription("admin.user.Monitor"));
				TvModeKioskMonJson.put("module","Monitor");
				TvModeKioskMonJson.put("timeFrequency",playbackFreq.get(screenName));
				if(screenName != null && screenName.equals("Services"))
				{
					String screenVal = "Service List"+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					if(tvAvailUser==false)
					{
						selected=true;
					}
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url","Service List"+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",false);
				}
				else if(screenName!=null && screenName.equalsIgnoreCase("Office 365"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);

				}
				else if(screenName!=null && screenName.equalsIgnoreCase("Real User Monitoring"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);
					
				}
				else if(screenName!=null && screenName.equalsIgnoreCase("Service Topology"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);
					
				}
				else if(screenName!=null && screenName.equalsIgnoreCase("My Dashboard"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					if(tvAvailUser==false)
					{
						selected=true;
					}
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);
				}
				else if(screenName!=null && screenName.equalsIgnoreCase("Citrix/VDI Dashboard"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);

				}else if(screenName!=null && screenName.equalsIgnoreCase("SAP ABAP Dashboard"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					if(tvAvailUser==false)
					{
						selected=true;
					}
					
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);
				}
				else if(screenName!=null && screenName.equalsIgnoreCase("Synthetic Monitoring"))
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					if(tvAvailUser==false)
					{
						selected=true;
					}
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",true);

				}
				else
				{
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					if(tvAvailUser==false)
					{
						selected=true;
					}
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskMonJson.put("needFilter",false);
				}
				TvModeKioskArrayListScrens.add(TvModeKioskMonJson);
			}
		}

		
		//Component Based Dashboard Screens.
		JSONObject TvModeCompJson = new JSONObject();
		Vector supportModeKeys=egUi.getVariables("TV_Mode_supported_Dashboards", true);
		if(supportModeKeys!=null && !supportModeKeys.isEmpty())
		{
			Iterator itrSupportModeKeys=supportModeKeys.iterator();
			while(itrSupportModeKeys.hasNext())
			{
				String tvModeKey=(String)itrSupportModeKeys.next();
				String displayName=tvModeKey.substring(0,tvModeKey.indexOf("#"));
				String TVserverType=tvModeKey.substring(tvModeKey.indexOf("#")+1);
				ArrayList serverComp=user.getServersForType(TVserverType);
				String valueField="";
				String screenUrl = egUi.getValue("TV_Mode_supported_Dashboards",tvModeKey);
				boolean selected=screenListTree.contains(displayName+"#"+screenUrl);
				TvModeKioskMonJson.put("dashbordName",displayName);
				TvModeKioskMonJson.put("module","Monitor");
				TvModeKioskMonJson.put("selected",selected);
				TvModeKioskMonJson.put("url",displayName+"#"+screenUrl);
				TvModeKioskArrayListScrens.add(TvModeKioskMonJson);

				TvModeCompJson.put("valueField",valueField);
				TvModeCompJson.put("displayField","Monitor - "+displayName);
				TvModeArrayListScrens.add(TvModeCompJson);
				
			}
		}

		JSONObject TvModeConfJson = new JSONObject();
		if (login_as_egsm_in_sm || hasConfigEnabled && userRole.getConfigPerm() > 0)
		{
			Object TvScreens[] =  egUi.getVariables("Config_TVMode_supported_screens");
			List screenList = Arrays.asList(TvScreens);
				for(int idx=0;idx<screenList.size();idx++)
				{
					String screenName = (String)screenList.get(idx);
					String screenUrl = egUi.getValue("Config_TVMode_supported_screens",screenName);
					
					String screenVal = screenName+"#"+screenUrl;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("dashbordName",screenName);
					TvModeKioskMonJson.put("module","Configuration");
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
					TvModeKioskArrayListScrens.add(TvModeKioskMonJson);
					
					TvModeConfJson.put("valueField",screenName+"#"+screenUrl);
					TvModeConfJson.put("displayField","Configuration - "+screenName);
					TvModeArrayListScrens.add(TvModeConfJson);
				}
		}

		JSONObject TvModeRepJson = new JSONObject();
		ErFavorite[] fav = null ;
		fav = ErFavorite.getFavoriteListForUser(tempUname);
		if (hasReporteEnabled && userRole.getReporterPerm() > 0)
		{
			Object TvScreens[] =  egUi.getVariables("Reporter_TVMode_supported_screens");
			List screenList = Arrays.asList(TvScreens);
			for(int idx=0;idx<screenList.size();idx++)
			{
				String screenName = (String)screenList.get(idx);
				String screenUrl = egUi.getValue("Reporter_TVMode_supported_screens",screenName);
				TvModeRepJson.put("valueField",screenName+"#"+screenUrl);
				TvModeRepJson.put("displayField","Reporter - "+screenName);
				TvModeArrayListScrens.add(TvModeRepJson);

				String screenVal = screenName+"#"+screenUrl;
				boolean selected=screenListTree.contains(screenVal);
				TvModeKioskMonJson.put("dashbordName",screenName);
				TvModeKioskMonJson.put("module","Reporter");
				TvModeKioskMonJson.put("selected",selected);
				TvModeKioskMonJson.put("url",screenName+"#"+screenUrl);
				TvModeKioskArrayListScrens.add(TvModeKioskMonJson);
			}
			if(fav!=null)
			{
				for(int i=0;i<fav.length;i++)
				{
					long fav_id = fav[i].getFavoriteId();
					String fav_name=fav[i].getName();
					String fav_url="/final/servlet/com.eg.ErFavoriteC?cmd=Show&id="+fav_id+"&fromFavSch=true&enableBack=true&backServletName=/servlet/com.eg.ErFavoriteC?&isSubmit=true";					
					TvModeRepJson.put("valueField","FAV-"+fav_name+"#"+fav_url);
					TvModeRepJson.put("displayField","Reporter - FAV-"+fav_name);
					TvModeArrayListScrens.add(TvModeRepJson);

					String screenVal = "FAV-"+fav_name+"#"+fav_url;
					boolean selected=screenListTree.contains(screenVal);
					TvModeKioskMonJson.put("dashbordName","FAV-"+fav_name);
					TvModeKioskMonJson.put("module","Reporter");
					TvModeKioskMonJson.put("selected",selected);
					TvModeKioskMonJson.put("url",screenVal);
					TvModeKioskArrayListScrens.add(TvModeKioskMonJson);
				}
			}
		}
	
		rootJson.put("kioskMode_BeforeSort", TvModeKioskArrayListScrens);
		//*******************************End TvMode*******************************
		int xenapp_Dashboard_CompTypeCount = 0;
		List services =null;
		List serviceList = user.getServices();
		List sites = user.getSites();
		Dashboard dash = new Dashboard(user);
		services = dash.getSiteStatus();
		if(userServerTypes.contains("Citrix_XcXenApp_server") || userServerTypes.contains("VmVdi_i_server") || userServerTypes.contains("Xen_desktop_server"))
			xenapp_Dashboard_CompTypeCount++;
		String enableSapAbapDashboard = serverDashBoardINI.getValue("SAP_ABAP_DASHBOARD_SETTINGS","EnableSapABAPDashboard");
		String enableSapAbapInMenu="false";
		if(enableSapAbapDashboard!=null && (enableSapAbapDashboard.equalsIgnoreCase("yes") || enableSapAbapDashboard.equalsIgnoreCase("true")))
		{
			if(userServerTypes!=null && userServerTypes.contains("SAP_R3_server"))
			{
				enableSapAbapInMenu="true";
			}
		}

		String enableSapPlatformDashboard = serverDashBoardINI.getValue("SAP_PLATFORM_DASHBOARD_SETTINGS","EnableSapPlatformDashboard");

		String enableSapPlatformInMenu="false";
		if(enableSapPlatformDashboard!=null && (enableSapPlatformDashboard.equalsIgnoreCase("yes") || enableSapPlatformDashboard.equalsIgnoreCase("true")))
		{
			String sapPlatformDBServerType = serverDashBoardINI.getValue("SAP_PLATFORM_COMP_TYPES","SapPlatformServerType");

			ArrayList sapCompTypeList = new ArrayList();
			if(sapPlatformDBServerType != null && sapPlatformDBServerType.trim().length() > 0)
			{
				sapCompTypeList =  com.egurkha.util.StringUtils.egTokenizer(sapPlatformDBServerType.trim(),",",true,false,true);
			}

			if(sapCompTypeList != null && sapCompTypeList.size() > 0)
			{
				for(int l=0;l<sapCompTypeList.size();l++)
				{
					String sap_comp_type = (String)sapCompTypeList.get(l);
					if(userServerTypes!=null && userServerTypes.size()>0 && userServerTypes.contains(sap_comp_type))
					{	
						enableSapPlatformInMenu="true";
						break;
					}
				}
			}
		}

		
		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;

		JSONArray jsonValArr=(JSONArray)rootJson.get("kioskMode_BeforeSort");
		String kio_Order=egUi.getValue("Kiosk_Screen_Order",user.getLoginID().toLowerCase());
		if(kio_Order == null || kio_Order.equals(""))
		{
			kio_Order=egUi.getValue("Kiosk_Screen_Order","Kiosk_Default_Order");
		}
		StringTokenizer stKio = new StringTokenizer(kio_Order,",");
		JSONArray kiosk_arr = new JSONArray();
		JSONObject obj = new JSONObject();
		while(stKio.hasMoreTokens())
		{
			String v=stKio.nextToken();
			if(v.equalsIgnoreCase("Office 365") && !userServerTypes.contains("MS_Office_365"))
				continue;
			else if(v.equalsIgnoreCase("Real User Monitoring") && !userServerTypes.contains("Real_user_monitor"))
				continue;
			else if(v.equalsIgnoreCase("SAP ABAP Dashboard") && !enableSapAbapInMenu.equalsIgnoreCase("true"))
				continue;
			else if( v.equalsIgnoreCase("SAP Platform") && !enableSapPlatformInMenu.equalsIgnoreCase("true"))
				continue;
			else if(v.equalsIgnoreCase("Citrix/VDI Dashboard") && !(xenapp_Dashboard_CompTypeCount > 0))
				continue;
			else if(v.equalsIgnoreCase("Synthetic Monitoring") && !isEnableSEUMDashboard)
				continue;
			else if(v.equalsIgnoreCase("Service Topology") && services!=null && services.isEmpty())
				continue;
			else if(v.equalsIgnoreCase("Business Dashboard") && serviceList!=null && serviceList.isEmpty() && sites!=null && sites.isEmpty())
				continue;
			Iterator itrJsonArr=jsonValArr.iterator();
			while(itrJsonArr.hasNext())
			{
				JSONObject jsonObj=(JSONObject)itrJsonArr.next();
				Object valObj=jsonObj.get("dashbordName");
				if(v.equals(valObj.toString()))
				{
					if(valObj.toString().equals("My Dashboard"))
					{
						if(monitorPrivilegeList.contains(valObj.toString()))
						{
							kiosk_arr.add(jsonObj);
						}
					}
					else
					{
						kiosk_arr.add(jsonObj);
					}
				}
				else
				{
				}
				
			}
		}
	rootJson.put("kioskMode", kiosk_arr);

	if(tvAvailUser==false)
	{
		JSONArray jsonValueArr=(JSONArray)rootJson.get("kioskMode");
		Iterator itrJsonValArr=jsonValueArr.iterator();
		String newUserUrl="";
		while(itrJsonValArr.hasNext())
		{
			JSONObject jsonObj=(JSONObject)itrJsonValArr.next();
			Object valObj=jsonObj.get("url");
			String url=valObj.toString();
			newUserUrl=newUserUrl+","+url;
		}
		if(newUserUrl!=null && !newUserUrl.equals(""))
		{
			newUserUrl=newUserUrl.substring(1);
		}
		egUi.setValue("eG_TVMode_selected_screens",loginID.toLowerCase(),newUserUrl);
		egUi.saveFile();
	}
	String eGTVModesupportedscreens = egUi.getValue("eG_TVMode_selected_screens",user.getLoginID().toLowerCase());
	rootJson.put("selectedScreens", eGTVModesupportedscreens);

	EgConfigFilesSync.releaseInstance(egUi);
	EgConfigFilesSync.releaseInstance(customIniObj);
	EgConfigFilesSync.releaseInstance(citrixConfig);
	EgConfigFilesSync.releaseInstance(egDashConfig);
	EgConfigFilesSync.releaseInstance(eg_externalIni);
	EgConfigFilesSync.releaseInstance(serverDashBoardINI);
	EgConfigFilesSync.releaseInstance(seumINI);
	out.println(rootJson.toString());
%>