<%@  include file = "EgMonitorTracker.jsp" %>
<%@  page import= "java.util.Vector"%>
<%@  page import= "java.util.Hashtable"%>
<%@  page import= "java.util.HashMap"%>
<%@  page import= "java.util.StringTokenizer"%>
<%@  page import= "com.eg.IniFile" %>
<%@  page import= "com.eg.EgInstallInfo" %>
<%@  page import= "java.net.URLEncoder" %>
<%@  page import="com.egurkha.monitor.EgCtxUserBean" %>
<%@  page import = "com.egurkha.User" %>
<%@  page import = "com.egurkha.UserRegistry" %>
<%@  page import = "com.egurkha.EgUserRole" %>
<%@  page import = "com.egurkha.ini.IniUI" %>
<%@  page import= "com.eg.EgDateInfo" %>
<%@  page import= "com.eg.EgTablesInfo" %>
<%@  page import = "com.eg.EgMemInfo" %>
<%@  page import= "java.util.*" %>
<%@  page import = "com.eg.EgMappingInfo" %>
<%@  page import = "com.eg.EgURLEncoder"%>
<%@  page import= "com.egurkha.util.DateUtil" %>
<%@  page import = "com.egurkha.monitor.VMDesktopBean"%>
<%@  page import="com.egurkha.monitor.*"%>
<%@  page import= "com.eg.EgExternalInfo" %>
<%@  page import= "com.eg.EgSpecsInfo" %>
<%@  page import= "com.eg.EgAgentInfo" %>
<%@  page import= "com.eg.EgTesterInfo" %>
<%@  page import="net.sf.json.*"%>
<%@  page import="java.text.SimpleDateFormat"%> 
<%@  page import= "com.eg.EgFormatInfo" %>
<%@  page import= "com.eg.EgDbInfo" %>

<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<jsp:useBean id="dd" scope="page" class="com.egurkha.monitor.EgDiagnosisBean" />
<jsp:useBean id="trans" scope="page" class="egurkha.TransactionBean"/>
<%
		String uiFile11 = "eg_ui.ini";
		String s_iniFile_dir11 = EgInstallInfo.getInstallDir()+ "/manager/config/";
		IniFile egUI = new IniFile(s_iniFile_dir11 + uiFile11);
		EgAgentInfo agentInfo = new EgAgentInfo(EgConstants.MANAGER);
		EgTesterInfo tt = new EgTesterInfo(EgConstants.MANAGER);
		EgTablesInfo tablesInfo = new EgTablesInfo("manager");
		EgSpecsInfo specsInfo = new EgSpecsInfo("manager");
		EgDbInfo dbInfo = new EgDbInfo("manager");
		boolean ddEnabled = EgMemInfo.ddEnabled;
		EgFormatInfo formatInfo = new EgFormatInfo ("manager");
		ArrayList excludeDDTestList = formatInfo.getHideDDTestList();
		trans.createFile("eg_format.ini");
		String strVarArr[] = trans.getVariables("FORMAT");
		String dummyTestArr[] = trans.getVariables("COMMON_DD_MAPPING");

		String	defaulttimelinevalue="";
		String search_type = request.getParameter("searchtype"); 
		search_type = (search_type==null||search_type.equalsIgnoreCase("null")||search_type.trim().length()==0)?"":search_type;
		String search_value = request.getParameter("searchvalue");
		search_value = (search_value==null||search_value.equalsIgnoreCase("null")||search_value.trim().length()==0)?"":search_value;
		String s_timeline=request.getParameter("eg_timeline");  //"&searchuser="+search_type+" "+search_value
		String eg_tbound=request.getParameter("eg_tbound");  
		eg_tbound = (eg_tbound==null||eg_tbound.equalsIgnoreCase("null")||eg_tbound.trim().length()==0)?"":eg_tbound;
		String eg_stdate = request.getParameter("eg_stdate");
		String eg_enddate = request.getParameter("eg_enddate");
		String start_hr = request.getParameter("starthr");
		String end_hr = request.getParameter("endhr");
		String startmin_h = request.getParameter("startmin_h");
		String endmin_h = request.getParameter("endmin_h");
		String isFromLayers = request.getParameter("isFromLayers");
		boolean isFromLayersFlag = false;
		isFromLayersFlag = (isFromLayers==null||isFromLayers.equalsIgnoreCase("null")||isFromLayers.trim().length()==0)?false:true;
		String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
		if(isFromLayersFlag)
		{
			String comFormat = "";
			String userFormat = u_ser.getUserDateFormat();
			if(eg_stdate!=null && !eg_stdate.equalsIgnoreCase("null") && eg_stdate.trim().length()>0)
			{
				if(DateUtil.isDate(eg_stdate,"MM/dd/yyyy"))
				{
					comFormat = "MM/dd/yyyy";
				}
				else
				{
					comFormat = currentDateFormat;
				}
				eg_stdate = DateUtil.changeDateFormat(eg_stdate,comFormat,userFormat);
			}
			if(eg_enddate!=null && !eg_enddate.equalsIgnoreCase("null") && eg_enddate.trim().length()>0)
			{
				if(DateUtil.isDate(eg_enddate,"MM/dd/yyyy"))
				{
					comFormat = "MM/dd/yyyy";
				}
				else
				{
					comFormat = currentDateFormat;
				}
				eg_enddate = DateUtil.changeDateFormat(eg_enddate,comFormat,userFormat);
			}
		}
		if(s_timeline==null)
		{
			defaulttimelinevalue = egUI.getValue("SEARCH_DISPLAY","Timeline");
		}
		
		StringBuffer buf = new StringBuffer();
		buf.append("<!Doctype html>");
		buf.append("<head>");
		buf.append("<title> eG Manager </title>");
		buf.append("<meta name=\"Author\" content=''>");
		buf.append("<meta  charset=\"UTF-8\">");
		buf.append("<link rel='stylesheet' type='text/css' href='/final/styles/eGLightThemeIcons.css' />");
		buf.append("<link rel='stylesheet' type='text/css' href='/final/reporter/styles/printpagestyle.css' />");		
		buf.append("<style type=\"text/css\" media=\"print\">");
		buf.append("#printbt{ display:none}");
		buf.append("</style>");
		buf.append("</head>");
		buf.append("<body marginwidth=\"20\" marginheight=\"20\" bgcolor=\"#FFFFFF\">");
		//buf.append("<link rel='stylesheet' type='text/css' href='/final/styles/eGLightThemeIcons.css' />");
		//buf.append("<link rel='stylesheet' type='text/css' href='/final/reporter/styles/printpagestyle.css' />");
		//buf.append("<style>@media print {body {-webkit-print-color-adjust: exact;}}");
		////buf.append("@font-face{font-family:'LucidaGrandeRegular';src:url('/final/fonts/6216/6216.woff') format('woff')}");
		////buf.append("@font-face{font-family:'LucidaGrandeBold';src:url('/final/fonts/6215/6215.woff') format('woff')}");
		//buf.append(".formValue{font-family:LucidaGrandeRegular;font-size:12px;line-height:14px;} b{font-family:'LucidaGrandeBold';font-size:11px;}");
		////buf.append("body{font-family:'LucidaGrandeRegular';font-size:11px;line-height:1.5em;color:#2a292a;}");
		////buf.append("header{font-family:'LucidaGrandeRegular';font-size:15px;}");
		//buf.append(".formLabel{font-family:'LucidaGrandeRegular';font-size:12px;line-height:14px;}");
		////buf.append("table tr td{font-family:'LucidaGrandeRegular';font-size:11px;padding:4px;}");
		//buf.append(".printTable{border: 1px solid #c3c3c3; border-collapse:collapse;word-break:break-all;}");
		//buf.append(".printTableHeader{font-family:'LucidaGrandeBold';border: 1px solid #c3c3c3;text-align:center;background-color:#cdcdcd;padding:4px;}");
		//buf.append(".printTable tr td{border: 1px solid #c3c3c3;}");
		//buf.append(".printTable tbody tr td{border: 1px solid #c3c3c3;}");
		//buf.append(".printTable tbody tr td table tr td{border: 0px solid #c3c3c3 !important;}");
		//buf.append(".printTable div{word-break:break-all;	}");
		//buf.append(".printTable thead{font-family:'LucidaGrandeBold';border: 1px solid #c3c3c3;text-align:center;background-color:#cdcdcd;padding:4px;}");
		//buf.append(".printTable thead th{font-family:'LucidaGrandeBold';border: 1px solid #c3c3c3;text-align:center;background-color:#cdcdcd;padding:4px;}");
		//buf.append(".printTableHeader2{font-family:'LucidaGrandeBold';border: 1px solid #c3c3c3;text-align:center;background-color:#dcdcdc;padding:4px;}</style>");

		List listData = new LinkedList();
		Vector csvHeaders = new Vector();
		IniUI img1=IniUI.getInstance();
		String logo=img1.getMonitorHomeLogo();
		if(img1.isHKTThemeEnabled())
		{
			logo = img1.getHKTReporterLogo();
		}
		String searchValue = "";
		searchValue = request.getParameter("searchuser");
		searchValue = com.egurkha.util.StringUtils.decodeSecurityChar(searchValue);
		String mainTitle = mappingInfo.getTextDescription("monitor.vmsearch.Search results for - "+searchValue);
		buf.append("<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" \">");
		buf.append("<tr><td width=\"100%\" align=\"center\" height=\"100%\" valign=\"top\">");
		if(logo!=null && logo.trim().length()>0)
		{
			buf.append("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" width=\"100%\" align=\"center\">");
			buf.append("<tr><td style=\"padding:5px 10px 10px 10px\">");
			buf.append("<img src="+logo+" border=\"0\" /></td></tr></table>");
		}
		buf.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" align=\"center\"  style=\"border-bottom:1px solid #999;\">");
		buf.append("<tr><td style=\"padding:2px\"><div style=\"float:left\" ><header>"+mainTitle+"</header></div></td></tr></table>");
		buf.append("</td></tr></table>");
		listData.add(mainTitle);
		listData.add("");
		
		buf.append("<div class=\"printHeaderBox\">");
		buf.append("<div class=\"newTable\">");

		buf.append("<table width=\"100%x\" class=\"printTable\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"  valign=\"top\" >");
		buf.append("<thead><tr>");

		buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.User")+"</span></th>");
		buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Server")+"</span></th>");
		buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Session Start time")+"</span></th>");
		buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Logout")+"</span></th>");
		buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Duration")+"</span></th>");
		
		csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.User"));
		csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Server"));
		csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Session Start time"));
		csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Logout"));
		csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Duration"));

		boolean includeMeasureHeaders = false;
		try
		{
			EgExternalInfo egExternalInfo=new EgExternalInfo("manager");
			MonitorDAOFactory monitorDaoFactory = MonitorDAOFactory.getInstance();
			EgServerDashBoardDAO dashboardDAO=monitorDaoFactory.getServerDashBoardDAO();
			EgTablesInfo tables=new EgTablesInfo("manager");
			IniFile formatIniFile = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_format.ini");

			String usersdetailsperpage = egUI.getValue("SEARCH_DISPLAY","UserDetails_PerPage");
			String dispDate = null;
			String mode = null;
			ErUtils erUtils = new ErUtils();
			EgDateInfo egDt = new EgDateInfo();
			java.util.Date local_date = new java.util.Date(egDt.egetUTCDate());
			Calendar cal = Calendar.getInstance();
			cal.setTime(local_date);
			cal.setTimeZone(egDt.getRealTimeZone());

			String start_date="";
			String end_date="";
			String hidden="Measure";
			String s_user="";
			Vector v_data=null;
			StringBuffer printQS=new StringBuffer();
			String title="";
			Vector v_columns = new Vector();
		
			s_user=request.getParameter("searchuser");
			s_user=com.egurkha.util.StringUtils.replace(s_user,"|quots|","'");
			s_user=com.egurkha.util.StringUtils.replace(s_user,"|hash|","#");
			if(s_user!=null)
			{
				String s_temp_user = com.egurkha.util.StringUtils.decodeSecurityChar(s_user);
			}
			if(s_user==null)
				s_user = "";

			IniFile extIni = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_external.ini");
			com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();

			boolean isShowInsideview = false;
			String strShownInsideview = extIni.getValue("User_VM_Search","shownInsideview");
			if(strShownInsideview!=null && strShownInsideview.trim().length()>0 && (strShownInsideview.equalsIgnoreCase("true") || strShownInsideview.equalsIgnoreCase("yes")))
			{
				isShowInsideview = true;
			}

			IniFile egEndIni = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_endUserDetails.ini");
			boolean isLinkFromThin=false;
			String strLinkFromThin = egEndIni.getValue("END_USER_DASHBOARD_SETTINGS","LinkFromThinClient");
			if(strLinkFromThin!=null && strLinkFromThin.trim().length()>0 && (strLinkFromThin.equalsIgnoreCase("true") || strLinkFromThin.equalsIgnoreCase("yes")))
			{
				isLinkFromThin=true;
			}

			List vdiList=new LinkedList();
			List vdiUserList=new LinkedList();
			if(isLinkFromThin || isShowInsideview)
			{
				String[] iniVdiList = extIni.getVariables("Virtual_Desktops");
				if(iniVdiList!=null && iniVdiList.length>0)
				{
					vdiList = Arrays.asList(iniVdiList);
				}
				String[] iniVdiUserList = extIni.getVariables("VdiUser_Search_Types");
				if(iniVdiUserList!=null && iniVdiUserList.length>0)
				{
					vdiUserList = Arrays.asList(iniVdiUserList);
				}
			}

			JSONArray  selectOptions = new JSONArray();
			Hashtable msmt_hash=new Hashtable();
			String mHostForDD = "";
			ArrayList locColumnsList = new ArrayList();
			Hashtable ht_server = (Hashtable)session.getAttribute("CitrixUser");
			if(ht_server!=null && ht_server.size()>0)
			{
				List serverTypes = (LinkedList)u_ser.getServerTypes();
				String componentType = (String)ht_server.get("Type");
				
				boolean isVM = ((Boolean)ht_server.get("isVm")).booleanValue();
				if(isVM)
				{
					buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Client Address")+"</span></th>");
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Address"));
				}
				else if(!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("VMWareView_RDS"))
				{
					buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Client Name")+"</span></th>");
					buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Client Address")+"</span></th>");
					buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.thinclients.Client Version")+"</span></th>");
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Name"));
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Address"));
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Version"));
				}
				String enableLocDetails = extIni.getValue("USER_SESSION_DETAILS","enableLocDetails");
				boolean isLocDetailsEnabled = false;
				if(enableLocDetails!=null && enableLocDetails.trim().length()>0 && (enableLocDetails.equalsIgnoreCase("true") ||enableLocDetails.equalsIgnoreCase("yes")))
					isLocDetailsEnabled = true;
				if(isLocDetailsEnabled)
				{
					String locSupportTypes = extIni.getValue("USER_SESSION_DETAILS","LocSupportTypes");
					ArrayList locSupportTypesList = null;
					if(locSupportTypes!=null && locSupportTypes.trim().length()>0 && !locSupportTypes.equalsIgnoreCase("NULL"))
						locSupportTypesList = com.egurkha.util.StringUtils.egTokenizer(locSupportTypes,",",false,true,true);	//param 3-->includeEmpty,4-->unique,5-->trim
					if(locSupportTypesList!=null && locSupportTypesList.size()>0 && componentType!=null && locSupportTypesList.contains(componentType))
					{
						String clientLocDetails = extIni.getValue("USER_SESSION_DETAILS","ClientLocDetails");
						StringTokenizer clientLocTok = null;
						if(clientLocDetails!=null && clientLocDetails.trim().length()>0 && !clientLocDetails.equalsIgnoreCase("NULL"))
							clientLocTok = new StringTokenizer(clientLocDetails,",");
						while(clientLocTok.hasMoreTokens())
						{
							String locDetailsStr = clientLocTok.nextToken();
							if(locDetailsStr != null && locDetailsStr.trim().length()>0 && !locDetailsStr.equalsIgnoreCase("NULL"))
							{
								ArrayList locDetailsList = com.egurkha.util.StringUtils.egTokenizer(locDetailsStr,"~#~",false,true,true);	//param 3-->includeEmpty,4-->unique,5-->trim
								String loc_session_test = "";
								String loc_columns = "";
								if(locDetailsList!=null && locDetailsList.size()>0)
								{
									loc_session_test = (String)locDetailsList.get(0);
									loc_columns = (String)locDetailsList.get(1);
								}
								if(loc_columns!=null && loc_columns.trim().length()>0 && !loc_columns.equalsIgnoreCase("NULL"))
								{
									StringTokenizer loc_columns_tok = new StringTokenizer(loc_columns,"^$^");
									while(loc_columns_tok.hasMoreTokens())
									{
										String loc_col = loc_columns_tok.nextToken();
										if(loc_col!=null && loc_col.trim().length()>0 && !loc_col.equalsIgnoreCase("NULL") && loc_col.indexOf(":")>-1)
										{
											String loc_col_str = loc_col.substring(0,loc_col.indexOf(":"));
											String loc_header_str = loc_col.substring(loc_col.indexOf(":")+1);

											if(loc_header_str!=null && loc_header_str.trim().length()>0 && !loc_header_str.equalsIgnoreCase("NULL"))
											{
											
												buf.append("<th><span class=\"formValue\">"+mappingInfo.getTextDescription("monitor.common."+loc_header_str)+"</span></th>");
												csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients."+loc_header_str));
											}
											if(loc_col_str!=null && locColumnsList!=null && !locColumnsList.contains(loc_col_str))
												locColumnsList.add(loc_col_str);
										} else {
											if(loc_col!=null && locColumnsList!=null && !locColumnsList.contains(loc_col))
												locColumnsList.add(loc_col);
										}
									}
								}
							}
						}
					}
				}
				buf.append("</tr></thead>");
				buf.append("<tbody>");
				String test = "", layer = "", testForDD = "", ddMeasure = "",measureList = "";
				String testWithGraphMeasure = extIni.getValue("VirtualDesktops_Measure",componentType);
				String testWithDDMeasure = extIni.getValue("VirtualDesktops_Measure",componentType+":DD");
				if(testWithGraphMeasure!=null && !testWithGraphMeasure.trim().equals("") && testWithGraphMeasure.indexOf(":")>-1)
				{
					test = testWithGraphMeasure.substring(0,testWithGraphMeasure.indexOf(":"));
					measureList = testWithGraphMeasure.substring(testWithGraphMeasure.indexOf(":")+1);
				}

				if(testWithDDMeasure!=null && !testWithDDMeasure.trim().equals("") && testWithDDMeasure.indexOf(":")>-1)
				{
					testForDD = testWithDDMeasure.substring(0,testWithDDMeasure.indexOf(":"));
					ddMeasure = testWithDDMeasure.substring(testWithDDMeasure.indexOf(":")+1);
				}

				if(test!=null && !test.trim().equals(""))
				{
					layer=tables.getLayerForTest(test);
					if(layer!=null && !layer.trim().equals("") && layer.indexOf(",")>-1)
					{
						layer=layer.substring(0,layer.indexOf(","));
					}
				}

				List agents=new LinkedList();
				ArrayList insideview_vm_list=new ArrayList();
				Hashtable state_hash=new Hashtable();
				String layer_for_url=extIni.getValue("VMSearch_InsideviewLayer",componentType);
				layer_for_url=(layer_for_url==null || layer_for_url.trim().length()==0)?"VIRTUAL_DESKTOP":layer_for_url;
				String userType=(String)egEndIni.getValue("COMP_TYPE_TYPES",componentType);

				JSONObject compLink = new JSONObject();
				ArrayList data=new ArrayList();
				HashMap clientData = new HashMap();
				Hashtable serverDuration = new Hashtable();
				Hashtable perfData = new Hashtable();
				Hashtable metrics = null;
				String user = "", server = "", loginTime = "", logoutTime = "", duration = "", cName = "", cIP = "", cType = "",testName = "", measure ="", func = "", value = "", mHost = "", guestname = "", session_key = "" ;
				int user_int=0;

				data = (ArrayList)ht_server.get("ClientData");
				serverDuration = (Hashtable)ht_server.get("Duration");
				perfData = (Hashtable)ht_server.get("MetricsData");

				if(data != null && data.size() > 0)
				{
					listData.add(csvHeaders);
					for(int k=0;k<data.size();k++)
					{
						buf.append("<tr style=\"background:none !important\">");
						Vector csvData = new Vector();

						clientData = (HashMap)data.get(k);
						if(clientData != null && clientData.size() > 0)
						{
							user = (String)clientData.get("user");
							server = (String)clientData.get("trgt_host");
							duration = (String)clientData.get("duration");
							if(isVM){
								guestname = (String)clientData.get("guestname");
								cIP = (String)clientData.get("Client_IP_Address");
							}
							else if(!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("VMWareView_RDS")){
								cName = (String)clientData.get("Client_name");
								cIP = (String)clientData.get("Client_ip_address");
								cType = (String)clientData.get("Client_version");
							}
							session_key = (String)clientData.get("sessionKey");
							session_key = (session_key==null || session_key.trim().length()==0 || session_key.equalsIgnoreCase("NULL") || session_key.equals("-"))?"":session_key;

							String key = "";
							String ltime = (String)clientData.get("login_time");
							if(duration != null && duration.equals("-"))
								key = user+"$"+ltime+"$"+server;
							else
								key = user+"$"+ltime+"$"+server+"$"+duration;
							if(serverDuration != null && serverDuration.containsKey(key))
							{
								String durValue = (String)serverDuration.get(key);
								if(durValue != null && durValue.trim().length() > 0 && durValue.indexOf("$") > 0)
								{
									String sDate = durValue.substring(0,durValue.indexOf("$"));
									if(sDate != null)
									{
										sDate = DateUtil.changeDateFormat(sDate,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
										EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(sDate , u_ser);
										loginTime = timeZoneConverter.getDateTime();
									}

									String eDate = durValue.substring(durValue.indexOf("$")+1);
									if(eDate != null && !eDate.equals("-"))
									{
										eDate = DateUtil.changeDateFormat(eDate,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
										EgTimeZoneConverter timeZoneConverter1 = new EgTimeZoneConverter(eDate , u_ser);
										logoutTime = timeZoneConverter1.getDateTime();
									}
									else
										logoutTime = "-";
								}
							}

							String orgDate = logoutTime;
							if(logoutTime.equals("-"))
								orgDate = loginTime;

							if(isVM)
								user = user+"_on_"+guestname;

							String componentName=server;
							if(componentName.endsWith("NULL") && componentName.indexOf(":")>-1)
								componentName=componentName.substring(0,componentName.lastIndexOf(":"));

							agents=new LinkedList();
							List agentsForDD=new LinkedList();
							String nick_name = server.substring(0,server.lastIndexOf(":"));
							agents=egExternalInfo.getAgentsFor(test,componentType,nick_name);
							agentsForDD=egExternalInfo.getAgentsFor(testForDD,componentType,nick_name);
							if (agents!=null && agents.size()>0)
							{
								mHost = (String) agents.get(0);
							}
							else
							{
								mHost=nick_name;
							}

							if (agentsForDD!=null && agentsForDD.size()>0)
							{
								mHostForDD = (String) agentsForDD.get(0);
							}
							else
							{
								mHostForDD=nick_name;
							}

							boolean isEndDash=false;
							boolean isEndDashXenApp=false;
							if(isLinkFromThin && vdiList!=null && vdiList.size()>0 && vdiList.contains(componentType))
							{
								isEndDash=true;
							}
							else if(isLinkFromThin && vdiUserList!=null && vdiUserList.size()>0 && vdiUserList.contains(componentType))
							{
								if(userType!=null && userType.trim().length()>0)
								{
									isEndDashXenApp=true;
								}
							}
							insideview_vm_list=new ArrayList();
							if((isLinkFromThin && isEndDash) || (componentType.indexOf("VmVdi")>-1) || (isShowInsideview && vdiList!=null && vdiList.size()>0 && vdiList.contains(componentType)))
							{
								String key_for_hash=componentType+"^eg^"+server+"^eg^"+layer_for_url;
								if(state_hash!=null && state_hash.size()>0 && state_hash.containsKey(key_for_hash))
								{
									insideview_vm_list=(ArrayList)state_hash.get(key_for_hash);
								}
								else
								{
									Hashtable Valid_info=new Hashtable();

									VMDesktopBean vmdeskBean=new VMDesktopBean(componentType,server,layer_for_url);
									Valid_info=vmdeskBean.getInfoForTest();
									if(Valid_info!=null && Valid_info.size()>0)
									{
										Enumeration vm_keys=Valid_info.keys();
										while(vm_keys.hasMoreElements())
										{
											String key1 = (String)vm_keys.nextElement();
											insideview_vm_list.add(key1.toLowerCase());
										}
									}

									if(insideview_vm_list!=null)
									{
										state_hash.put(key_for_hash,(ArrayList)insideview_vm_list);
									}
								}
							}

							String org_user_name=user;
							if(user!=null && user.indexOf("_on_")>-1)
							{
								ArrayList tokUserList = com.egurkha.util.StringUtils.egTokenizer(user, "_on_",true,false,true);//param 3-->includeEmpty,4-->unique,5-->trim
								if(tokUserList!=null && tokUserList.size()==2)
								{
									org_user_name=(String)tokUserList.get(1);
								}
							}
						
						buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+user+"</td>");
						csvData.add(user);
						
						int c = 0;
							
						buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;\"><div style=\"width:100px;word-wrap: break-word; overflow-x:auto;\">"+componentName+"</div></td>");
						csvData.add(componentName);
						
						buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+loginTime+"</td>");
						csvData.add(loginTime);

						buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+logoutTime+"</td>");
						csvData.add(logoutTime);
						
						buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+duration+"</td>");
						csvData.add(duration);
						
							if(isVM){
								buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+cIP+"</td>");
								csvData.add(cIP);
							}
							else if(!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("VMWareView_RDS")){
								buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+cName+"</td>");
								csvData.add(cName);
								buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+cIP+"</td>");
								csvData.add(cIP);
								buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+cType+"</td>");
								csvData.add(cType);
							}

							if(isLocDetailsEnabled && locColumnsList!=null && locColumnsList.size()>0)
							{
								Iterator locColItr = locColumnsList.iterator();
								while(locColItr.hasNext())
								{
									String locColStr = (String) locColItr.next();
									if(locColStr!=null && locColStr.trim().length()>0 && !locColStr.equalsIgnoreCase("NULL"))
									{
										String locDetVal = (String)clientData.get(locColStr);
										if(locDetVal != null && locDetVal.trim().length() > 0)
										{
											csvData.add(locDetVal);
											buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+locDetVal+"</td>");
										}
										else
										{
											csvData.add("-");
											buf.append("<td style=\"text-align:center;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">-</td>");
										}									
									}
								}
							}

							if(perfData != null && perfData.containsKey(key))
							{
								metrics = new Hashtable();
								metrics = (Hashtable)perfData.get(key);
								if(metrics != null && metrics.size() > 0)
								{
									Enumeration m_keys = metrics.keys();
									while(m_keys.hasMoreElements())
									{
										String displayName = (String)m_keys.nextElement();
										String measVal = (String)metrics.get(displayName);
										StringTokenizer tokens = new StringTokenizer(measVal,"$");
										while(tokens.hasMoreTokens())
										{
											testName = tokens.nextToken();
											measure = tokens.nextToken();
											func = tokens.nextToken();
											value = tokens.nextToken();
											if(!includeMeasureHeaders)
											{
												String unit = tablesInfo.getUnitForMeasure(testName,measure);
												if(unit==null || unit.equals(""))
												{
													String str_measureName = dbInfo.getMeasureForColumn(testName,measure);
													unit = tablesInfo.getUnitForMeasure(testName,str_measureName);
												}
											}
											buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+value+"</td>");
											csvData.add(value);
										}
									}
									includeMeasureHeaders = true;
								}
							}

							boolean showDDIcon = false;
							String hostName=server.substring(0,server.lastIndexOf(":"));
							Hashtable allMsmtHosts = new Hashtable();
							String msmt_key=componentType+":"+server;
							if(msmt_hash!=null && msmt_hash.size()>0 && msmt_hash.containsKey(msmt_key))
							{
								allMsmtHosts=(Hashtable)msmt_hash.get(msmt_key);
							}
							else
							{
								Hashtable tmp_allMsmtHosts=(Hashtable)dashboardDAO.getMsmtHostForAllTest(server,componentType,"custom");
								allMsmtHosts = new Hashtable();
								allMsmtHosts.putAll(tmp_allMsmtHosts);
								msmt_hash.put(msmt_key,(Hashtable)tmp_allMsmtHosts);
							}

							String msmtHost=null;
							if(allMsmtHosts!=null && allMsmtHosts.size()>0)
								msmtHost=(String)allMsmtHosts.get(testForDD);

							if(msmtHost == null)
								msmtHost = mHostForDD;

							String s_info_to_db = null;
							String ddWithoutInfo = formatIniFile.getValue("Tests_For_DDWithoutInfos", testForDD + ":" + ddMeasure);
							boolean lookforActualDes = false;

							if(ddWithoutInfo!=null && ddWithoutInfo.equalsIgnoreCase("yes"))
							{
								lookforActualDes = true;
								s_info_to_db = "+";
							}
							else
							{
								s_info_to_db = "+"+user;
							}

							if(ddEnabled)
							{
								Vector measures = new Vector();
								if(strVarArr!=null && strVarArr.length>0)
								{
									for(int sva=0; sva<strVarArr.length; sva++)
									{
										if(strVarArr[sva].startsWith(testForDD))
										{
											String meas = strVarArr[sva].substring(strVarArr[sva].indexOf(":")+1,strVarArr[sva].length());
											if(!measures.contains(meas))
											{
												measures.add(meas);
											}
										}
									}
								}
								
								if(dummyTestArr!=null && dummyTestArr.length>0)
								{
									for(int dta=0; dta<dummyTestArr.length; dta++)
									{
										if(dummyTestArr[dta].startsWith(testForDD))
										{
											String meas = dummyTestArr[dta].substring(dummyTestArr[dta].indexOf(":")+1,dummyTestArr[dta].length());
											if(!measures.contains(meas))
											{
												measures.add(meas);
											}
										}
									}
								}

								if(measures.contains(ddMeasure))
								{
									ArrayList DDEnabledList = tt.DefaultDDEnabledTypes();
									boolean isRemoteDetailed = false;
									if(DDEnabledList!=null && DDEnabledList.size()>0 && DDEnabledList.contains(componentType))
									{
										isRemoteDetailed=true;
									}
									else
									{
										isRemoteDetailed = tt.getRemoteDetailed();
									}

									boolean isAgentlessServer = false;
									if(!isRemoteDetailed)
											isAgentlessServer = agentInfo.isAgentlessServer(hostName, componentType);

									//Fix to hide DD icon based on Ini entry
									if(excludeDDTestList != null && excludeDDTestList.size() > 0 && excludeDDTestList.contains(testForDD))
									{
										showDDIcon = false;
									}
									else if (ui.getVirtualServerTypes().contains(componentType)|| !isAgentlessServer || specsInfo.isTestExternal(testForDD))
									{
										showDDIcon = true; //dd.ShowDDData("NULL",hostName,testForDD,ddMeasure,s_info_to_db,msmtHost);
										if(lookforActualDes && !showDDIcon)
										{
											showDDIcon = true; //dd.ShowDDData("NULL",hostName,testForDD,ddMeasure,"+"+user,msmtHost);
										}
									}
								}
							}
							String et_dispDate = logoutTime;
							String st_dispDate = "",sthr = "",endhr = "";
							st_dispDate = loginTime.substring(0,loginTime.indexOf(" "));
							sthr = loginTime.substring(loginTime.indexOf(" "),loginTime.indexOf(":"));
							if(et_dispDate.equals("-"))
							{
								SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
								java.util.Date tmpday = egDt.egetRealDate();
								String en_date = sdf.format(tmpday);
								en_date = DateUtil.changeDateFormat(en_date,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
								EgTimeZoneConverter timeZoneConverter2 = new EgTimeZoneConverter(en_date , u_ser);
								String temp_et_dispDate = timeZoneConverter2.getDateTime();
								et_dispDate = temp_et_dispDate.substring(0,temp_et_dispDate.indexOf(" "));
								endhr = temp_et_dispDate.substring(temp_et_dispDate.indexOf(" "),temp_et_dispDate.indexOf(":"));
							}

							String hostname=EgURLEncoder.encode(server.substring(0,server.lastIndexOf(":")),"UTF-8");
							String port = server.substring(server.lastIndexOf(":")+1);
							String portForMsmtTime="NULL";
							String keyValue=componentName+":"+portForMsmtTime+":"+test+":"+mHost;
							if(componentName!=null && componentName.indexOf(":")>0)
							{
								keyValue = componentName+":"+test+":"+mHost;
							}
							String msmtTimeStr = dashboardDAO.getMeasureLastMsmtTime(keyValue,user);
							String msmtTimeStr2="";
							try
							{
								SimpleDateFormat df=new SimpleDateFormat("MM/dd/yyyy*HH:mm:ss");
								SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
								if(msmtTimeStr!=null && msmtTimeStr!="")
								{
									java.util.Date msd=sdf2.parse(msmtTimeStr);
									msmtTimeStr2 =df.format(msd);
								}
							}
							catch(Exception eexx)
							{
								System.out.println("Exception--->"+eexx.getMessage());
								eexx.printStackTrace();
							}

							c++;
							if(showDDIcon)
							{
								c++;
							}
						}
						buf.append("</tr>");
						listData.add(csvData);
					}
				}
				else
				{
					buf.append("<tr style=\"background:none !important\">");
						buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+mappingInfo.getTextDescription("monitor.vmsearch.No data available for the current search")+"</td>");
					buf.append("</tr>");
				}
				session.setAttribute("userSearchCsvData",listData);
			}
			else
			{
				buf.append("<tr style=\"background:none !important\">");
					buf.append("<td style=\"text-align:left;padding:4px 4px 1px 4px;white-space:nowrap;width:400px\">"+mappingInfo.getTextDescription("monitor.vmsearch.No data available for the current search")+"</td>");
				buf.append("</tr>");
			}
			buf.append("</tbody>");
			buf.append("</table>");
			buf.append("</div>");
			buf.append("</div>");
			buf.append("</body>");
			buf.append("</html>");
			response.getWriter().write(buf.toString());
		}
		catch(Exception e)
		{
			System.out.println("EXCEPTION CITRIXUSER---->"+e);
			e.printStackTrace();
		}
%>