<%@	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"/>
<%
		UserRegistry registry = UserRegistry.getInstance();
		User userObj = registry.getUser(session.getId());
        String uiFile11 = "eg_ui.ini";
	    String s_iniFile_dir11 = EgInstallInfo.getInstallDir()+ "/manager/config/";
	    IniFile egUI = new IniFile(s_iniFile_dir11 + uiFile11);  
		String timelineOptions = egUI.getValue("SEARCH_DISPLAY","TimeLine_Options");
		ArrayList timelineOptionsList = new ArrayList();
		if(timelineOptions==null || timelineOptions.trim().length()==0)
			timelineOptions = "Any,1 hour,3 hours,6 hours,9 hours,12 hours,15 hours,18 hours,21 hours,24 hours,2 days,3 days,4 days,5 days,6 days,1 week,2 weeks,3 weeks,4 weeks,1 month,2 months";
		timelineOptionsList = com.egurkha.util.StringUtils.egTokenizer(timelineOptions, ",",true,false,true);
        //String[] options = {"Any","1 hour", "3 hours", "6 hours", "9 hours", "12 hours","15 hours", "18 hours","21 hours","24 hours", "2 days", "3 days", "4 days", "5 days", "6 days","1 week","2 weeks","3 weeks","4 weeks","1 month","2 months"};   
        JSONObject gridObj=new JSONObject();
		JSONArray gridData = new JSONArray();
		JSONObject columnDetails = new JSONObject();
		JSONObject rootJson = new JSONObject();
		JSONObject screenLabels = new JSONObject();
		JSONObject dateTime = new JSONObject();
		TreeMap linksMap = new TreeMap();

		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");
		startmin_h=(startmin_h==null || startmin_h.trim().length()==0 || startmin_h.equals("null"))?"00":startmin_h;
		String endmin_h = request.getParameter("endmin_h");
		endmin_h=(endmin_h==null || endmin_h.trim().length()==0|| endmin_h.equals("null"))?"59":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");
		List listData = new LinkedList();
		Vector csvHeaders = new Vector();
		if(isFromLayersFlag)
		{
			gridObj.put("isFromLayers",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);
				
				dateTime.put("eg_stdate",eg_stdate);
				dateTime.put("start_hr",start_hr);
			}
			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);

				dateTime.put("eg_enddate",eg_enddate);
				dateTime.put("end_hr",end_hr);
			}
		}
		if(s_timeline==null)
		{
		  defaulttimelinevalue=egUI.getValue("SEARCH_DISPLAY","Timeline");
		  s_timeline = defaulttimelinevalue;
          	  gridObj.put("defaulttimelinevalue",defaulttimelinevalue);
	    }
	   else
	   {
           gridObj.put("defaulttimelinevalue",s_timeline);
	   }
		columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.User"),"");
		columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Server"),"");
		columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Session Start time"),"");
		//columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Logout / Disconnect time"),"");
		columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Logout"),"");
		//columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Duration of Access"),"(Mins)");
		columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Duration"),"(Mins)");

		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;
		//ArrayList timlinelist = new ArrayList(Arrays.asList(options));
		JSONArray historyTmeLineList = new JSONArray();
		ListIterator itr = timelineOptionsList.listIterator();
		String tempStr = "";
		while(itr.hasNext())
		{
			tempStr = (String)itr.next();
			JSONObject temp = new JSONObject();
			temp.put("displayField",tempStr);
			temp.put("valueField",tempStr);
			historyTmeLineList.add(temp);
		}
		String timeLineLbl = mappingInfo.getTextDescription("monitor.common.Timeline");
		String fromLbl = mappingInfo.getTextDescription("monitor.common.From");
		String toLbl = mappingInfo.getTextDescription("monitor.common.To");
		screenLabels.put("monitor.common.State",mappingInfo.getTextDescription("monitor.common.State"));
		screenLabels.put("monitor.common.Timeline",timeLineLbl);
		screenLabels.put("monitor.common.From",fromLbl);
		screenLabels.put("monitor.common.To",toLbl);
		screenLabels.put("monitor.common.Hr",mappingInfo.getTextDescription("monitor.common.Hr"));
		gridObj.put("defaulttimelineopt",mappingInfo.getTextDescription("monitor.common.1 hour"));
        try
        {   
			StringBuffer s_title = new StringBuffer();
			String ftitle="";
			s_title.append(mappingInfo.getTextDescription("monitor.search.Search results for"));
			s_title.append(" - ");
			s_title.append(mappingInfo.getTextDescription("monitor.search.user"));
			s_title.append(" ");

			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("searchvalue");
			if(s_user!=null && s_user.trim().length()>0 && !s_user.equalsIgnoreCase("NULL"))
			{
				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);
				s_title.append(s_temp_user);
				s_title.append(" ");
			}
			if(s_user==null)
				s_user="";
			String mainTitle = mappingInfo.getTextDescription("monitor.vmsearch.Search results for - "+s_user);
			listData.add(mainTitle);
			listData.add("");
			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;
			}

			boolean isLinkFromThinHistory=false;
			String strLinkFromThinHistory = egEndIni.getValue("END_USER_DASHBOARD_SETTINGS","LinkFromThinClientHistory");
			if(strLinkFromThinHistory!=null && strLinkFromThinHistory.trim().length()>0 && (strLinkFromThinHistory.equalsIgnoreCase("true") || strLinkFromThinHistory.equalsIgnoreCase("yes")))
			{
				isLinkFromThinHistory=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);
				}
			}

			JSONObject componentTypeOptions  = new JSONObject();
			JSONArray  selectOptions = new JSONArray();
			Hashtable msmt_hash=new Hashtable();
			String mHostForDD = "";
			Hashtable ht_server=(Hashtable)request.getAttribute("CitrixUser");
			ArrayList locColumnsList = new ArrayList();
			if(ht_server!=null && ht_server.size()>0)
				session.setAttribute("CitrixUser",ht_server);
			if(ht_server!=null && ht_server.size() > 0)
			{
				List serverTypes = (LinkedList)u_ser.getServerTypes();
				List vmTypes = (LinkedList)u_ser.getOnlyVMTypes();
				String componentType = (String)ht_server.get("Type");
				Vector compOptions = (Vector)ht_server.get("Options");
				if(compOptions != null && compOptions.size() > 0)
				{
					for(int c=0;c<compOptions.size();c++)
					{
						String comptype = (String)compOptions.get(c);
						if((comptype != null && comptype.trim().length() > 0 && serverTypes != null && serverTypes.contains(comptype) ) || (vmTypes != null  && vmTypes.contains(comptype)))
						{
							JSONObject option  = new JSONObject();
							option.put("value",comptype);
							option.put("name",mappingInfo.getComponentTypeDescription(comptype));
							selectOptions.add(option);
						}
					}
					if(selectOptions.size() > 1)
					{
						componentTypeOptions.put("selectOptions",selectOptions);
						//componentTypeOptions.put("selectedValue",mappingInfo.getComponentTypeDescription(componentType));
						componentTypeOptions.put("selectedValue",componentType);
					}
				}

				boolean isVM = ((Boolean)ht_server.get("isVm")).booleanValue(); // this flag is to identify VDI/Esx servers only.

				boolean userHasVM = false;
				if(userObj.isOnlyVMAssigned() || userObj.isVMAssigned())
					userHasVM = true;
				if(isVM)
				{
					columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Client Address"),"");
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Address"));
				}
				else if(!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("VMWareView_RDS"))
				{
					columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Client Name"),"");
					columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Client Address"),"");
					columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients.Client Version"),"");

					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Name"));
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Address"));
					csvHeaders.add(mappingInfo.getTextDescription("monitor.thinclients.Client Version"));
				}
				listData.add(csvHeaders);
				String test = "", layer = "", testForDD = "", ddMeasure = "",measureList = "";
				String testWithGraphMeasure = extIni.getValue("VirtualDesktops_Measure",componentType);
				String testWithDDMeasure = extIni.getValue("VirtualDesktops_Measure",componentType+":DD");
				if(userHasVM)
				{
					testWithGraphMeasure = extIni.getValue("VirtualDesktops_Measure",componentType+":VM");
					testWithDDMeasure = extIni.getValue("VirtualDesktops_Measure",componentType+":DD:VM");
				}

				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(","));
						}
				}

				String enableLocDetails = extIni.getValue("USER_SESSION_DETAILS","enableLocDetails");
				boolean isLocDetailsEnabled = false;
				if(enableLocDetails!=null && enableLocDetails.trim().length()>0 && enableLocDetails.equalsIgnoreCase("true"))
					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(isLocDetailsEnabled && 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"))
											{
												columnDetails.put(mappingInfo.getTextDescription("monitor.common."+loc_header_str),"");
												csvHeaders.add(mappingInfo.getTextDescription("monitor.common."+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);
										}
									}
								}
							}
						}
					}
				}
				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)
				{
					for(int k=0;k<data.size();k++)
					{
						Vector csvData = new Vector();
						JSONObject rowData = new JSONObject();
						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 start_dispDate="",end_dispDate="";
							String key = "";
							String ltime = (String)clientData.get("login_time");
							if(duration != null && duration.equals("-"))
								key = user+"$"+ltime+"$"+server;
							else
								key = user+"$"+ltime+"$"+server+"$"+duration;

							String startDateValue=eg_stdate+" "+start_hr+":"+startmin_h+":00";
							String enddateValue=eg_enddate+" "+end_hr+":"+endmin_h+":59";
							if(eg_enddate==null || eg_enddate.trim().length()==0 || eg_enddate.equalsIgnoreCase("null"))
							{
								enddateValue=null;
							}
							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)
									{
										try
										{
											if(sDate.indexOf("PM") > 0)
											{
												sDate = sDate.substring(0,sDate.indexOf("PM"));

												if(sDate!=null)
												{
													sDate=sDate.trim();
													sDate=sDate+":00";
												}

												startDateValue = sDate;

												sDate=DateUtil.changeDateFormat(sDate,"MM/dd/yyyy HH:mm:ss","dd/MM/yyyy HH:mm:ss");
												start_dispDate = sDate;
												sDate = DateUtil.changeDateFormat(sDate,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
												EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(sDate , u_ser);
												loginTime = timeZoneConverter.getDateTime();
											}
											else if(sDate.indexOf("AM") > 0)
											{
												sDate = sDate.substring(0,sDate.indexOf("AM"));

												if(sDate!=null)
												{
													sDate=sDate.trim();
													sDate=sDate+":00";
												}

												startDateValue = sDate;

												sDate=DateUtil.changeDateFormat(sDate,"MM/dd/yyyy HH:mm:ss","dd/MM/yyyy HH:mm:ss");
												start_dispDate = sDate;
												sDate = DateUtil.changeDateFormat(sDate,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
												EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(sDate , u_ser);
												loginTime = timeZoneConverter.getDateTime();
											}
											else
											{
												startDateValue=DateUtil.changeDateFormat(sDate,"dd/MM/yyyy HH:mm:ss","MM/dd/yyyy HH:mm:ss");
												start_dispDate =sDate;
												sDate = DateUtil.changeDateFormat(sDate,"dd/MM/yyyy HH:mm:ss",currentDateFormat +" HH:mm:ss");
												EgTimeZoneConverter timeZoneConverter = new EgTimeZoneConverter(sDate , u_ser);
												loginTime = timeZoneConverter.getDateTime();
											}
										}
										catch(Throwable thee)
										{
											startDateValue=eg_stdate+" "+start_hr+":"+startmin_h+":00";
											start_dispDate =sDate;
											loginTime = sDate;
										}
									}

									String eDate = durValue.substring(durValue.indexOf("$")+1);
									if(eDate != null && !eDate.equals("-"))
									{
										enddateValue=DateUtil.changeDateFormat(eDate,"dd/MM/yyyy HH:mm:ss","MM/dd/yyyy HH:mm:ss");
										end_dispDate=eDate;
										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 starttime = "";
							String endtime = "";
							String sthr="";
							String endhr="";
							if ((s_timeline==null || s_timeline!=null) && ltime!=null)
							{
								Date startdateObj = new Date(startDateValue);
								Date dateObj=null;
								starttime = startDateValue;
								Calendar cal_temp = new GregorianCalendar();
								cal_temp.setTime(startdateObj);
								cal_temp.add(Calendar.HOUR_OF_DAY,-1);
								//calendar.add(Calendar.HOUR,-4);

								dateObj = cal_temp.getTime();
								long l_starttime = dateObj.getTime();
								String startDate = egDt.egetDateUS(l_starttime);
								sthr=startDate.substring(startDate.indexOf(" ")+1,startDate.indexOf(":"));
								starttime=startDate.substring(0,startDate.indexOf(" "));

								if(enddateValue!=null && enddateValue.trim().length()>0 && !enddateValue.equals("-"))
								{
									Date enddateObj = new Date(enddateValue);
									cal_temp = new GregorianCalendar();
									cal_temp.setTime(enddateObj);
									cal_temp.add(Calendar.HOUR_OF_DAY,1);

									dateObj = cal_temp.getTime();
									long l_endtime = dateObj.getTime();
									endtime = egDt.egetDateUS(l_endtime);
									endhr=endtime.substring(endtime.indexOf(" ")+1,endtime.indexOf(":"));
									endtime=endtime.substring(0,endtime.indexOf(" "));
									s_timeline="24 hours";
								}
								else
								{
									Date enddateObj = new Date(startDateValue);
									cal_temp = new GregorianCalendar();
									cal_temp.setTime(enddateObj);
									cal_temp.add(Calendar.HOUR_OF_DAY,1);

									dateObj = cal_temp.getTime();
									long l_endtime = dateObj.getTime();
									endtime = egDt.egetDateUS(l_endtime);
									endhr=endtime.substring(endtime.indexOf(" ")+1,endtime.indexOf(":"));
									endtime=endtime.substring(0,endtime.indexOf(" "));
									s_timeline="24 hours";
								}
							}

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

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

							boolean isUserWithDesktop=false;
							if(user!=null && user.indexOf("\\") > -1 && user.indexOf("_on_") > -1 && (user.indexOf("\\") < user.indexOf("_on_")))
								isUserWithDesktop=true;

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

							String insideQs="/final/monitor/egInsideviewDashboard.jsp?getFor="+ddMeasure+"&comp="+EgURLEncoder.encode(server,"UTF-8")+"&comptype="+componentType+"&Layer=VIRTUAL_DESKTOP&info="+user.trim()+"&compName="+EgURLEncoder.encode(server+componentType,"UTF-8")+"&fromThinClients=yes&componentName="+EgURLEncoder.encode(componentName,"UTF-8");

							String showInsideQs="";
							if(isShowInsideview)
							{
								showInsideQs="/final/monitor/egInsideviewDashboard.jsp?getFor=measure&comp="+EgURLEncoder.encode(server,"UTF-8")+"&comptype="+componentType+"&Layer="+layer_for_url+"&info="+EgURLEncoder.encode(user,"UTF-8")+"&compName="+EgURLEncoder.encode(server+componentType,"UTF-8")+"&searchuser="+EgURLEncoder.encode(search_type+" "+search_value,"UTF-8");
							}

							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;
							}

							String start_Date="",end_Date="";
							String org_end_Date="";
							String sessionLogout = "true";
							if(start_dispDate!=null && !start_dispDate.equalsIgnoreCase("null") && start_dispDate.trim().length()>0 && start_dispDate.indexOf("PM")==-1 && start_dispDate.indexOf("AM")==-1)
							{
								start_Date = start_dispDate;
								SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
								Date date = sdf.parse(start_Date);
								long millis = date.getTime()-(10*60*1000);
								
								Calendar calendar = Calendar.getInstance();
								calendar.setTimeInMillis(millis);
								start_Date = sdf.format(calendar.getTime());
							}
							else if(start_dispDate!=null && !start_dispDate.equalsIgnoreCase("null") && start_dispDate.trim().length()>0 && (start_dispDate.indexOf("PM")>0 || start_dispDate.indexOf("AM")>0))
							{
								start_Date = start_dispDate;
							}

							if(end_dispDate!=null && !end_dispDate.equalsIgnoreCase("null") && end_dispDate.trim().length()>0)
							{
								if(end_dispDate.equals("-"))
								{
									SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
									java.util.Date tmpday = egDt.egetRealDate();
									String en_date = sdf.format(tmpday);
									end_Date = en_date;
									org_end_Date = en_date;
									sessionLogout = "false";
								}
								else
								{
									
									end_Date = end_dispDate;
									SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
									Date date = sdf.parse(end_Date);
									long millis = date.getTime()+(10*60*1000);
									
									Calendar calendar = Calendar.getInstance();
									calendar.setTimeInMillis(millis);
									end_Date = sdf.format(calendar.getTime());
									org_end_Date = sdf.format(calendar.getTime());
									sessionLogout = "true";

								}
							}
							boolean isEndDash=false;
							boolean isEndDashXenApp=false;
							if(isLinkFromThin && vdiList!=null && vdiList.size()>0 && vdiList.contains(componentType))
							{
								String temp_url_desktopName=com.egurkha.util.StringUtils.replace(user, "\\", "\\");
								insideQs = "/final/monitor/endUserDashboardDetailsData.jsp?comp="+EgURLEncoder.encode(server,"UTF-8")+"&comptype="+componentType+"&info=*"+EgURLEncoder.encode(temp_url_desktopName.trim(),"UTF-8")+"&compName="+EgURLEncoder.encode(server+":"+componentType,"UTF-8")+"&componentName="+EgURLEncoder.encode(componentName,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&user="+EgURLEncoder.encode(u_rs,"UTF-8")+"&usersearch=true&userType=VDI"+"&searchuser="+EgURLEncoder.encode(search_type+" "+search_value,"UTF-8")+"&sessionKey="+session_key+"&comesFromSearch=yes";
								if(end_Date!=null && !end_Date.equalsIgnoreCase("null") && end_Date.trim().length()>0 && !end_Date.equals("-"))
								{
									insideQs =insideQs+"&loginTime="+EgURLEncoder.encode(start_Date,"UTF-8")+"&logoutTime="+EgURLEncoder.encode(end_Date,"UTF-8")+"&orgloginTime="+EgURLEncoder.encode(start_dispDate,"UTF-8")+"&orglogoutTime="+EgURLEncoder.encode(end_dispDate,"UTF-8")+"&sessionLogout="+EgURLEncoder.encode(sessionLogout,"UTF-8")+"&isSessionDetails=true";
								}
								if((s_timeline!=null && !s_timeline.equalsIgnoreCase("null") && s_timeline.trim().length()>0) && (eg_stdate!=null && !eg_stdate.equalsIgnoreCase("null") && eg_stdate.trim().length()>0))
								{
									insideQs = insideQs + "&eg_timeline="+EgURLEncoder.encode(s_timeline,"UTF-8")+"&eg_stdate="+EgURLEncoder.encode(eg_stdate,"UTF-8")+"&eg_enddate="+EgURLEncoder.encode(eg_enddate,"UTF-8")+"&starthr="+EgURLEncoder.encode(start_hr,"UTF-8")+"&endhr="+EgURLEncoder.encode(end_hr,"UTF-8")+"&startmin_h="+EgURLEncoder.encode(startmin_h,"UTF-8")+"&endmin_h="+EgURLEncoder.encode(endmin_h,"UTF-8");
									if(!s_timeline.equals("Recent"))
										insideQs = insideQs+"&eg_tbound="+EgURLEncoder.encode(eg_tbound,"UTF-8");
								}
								isEndDash=true;
							}
							else if(isLinkFromThin && vdiUserList!=null && vdiUserList.size()>0 && vdiUserList.contains(componentType))
							{
								if(userType!=null && userType.trim().length()>0)
								{
									String temp_url_desktopName=com.egurkha.util.StringUtils.replace(user, "\\", "\\");

									insideQs = "/final/monitor/endUserDashboardDetailsData.jsp?comp="+EgURLEncoder.encode(server,"UTF-8")+"&comptype="+componentType+"&info=*"+EgURLEncoder.encode(temp_url_desktopName.trim(),"UTF-8")+"&compName="+EgURLEncoder.encode(server+":"+componentType,"UTF-8")+"&componentName="+EgURLEncoder.encode(componentName,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&user="+EgURLEncoder.encode(u_rs,"UTF-8")+"&usersearch=true&userType="+userType+"&searchuser="+EgURLEncoder.encode(search_type+" "+search_value,"UTF-8")+"&sessionKey="+session_key+"&comesFromSearch=yes";

									if(end_Date!=null && !end_Date.equalsIgnoreCase("null") && end_Date.trim().length()>0 && !end_Date.equals("-"))
									{
										insideQs =insideQs+"&loginTime="+EgURLEncoder.encode(start_Date,"UTF-8")+"&logoutTime="+EgURLEncoder.encode(end_Date,"UTF-8")+"&orgloginTime="+EgURLEncoder.encode(start_dispDate,"UTF-8")+"&orglogoutTime="+EgURLEncoder.encode(end_dispDate,"UTF-8")+"&sessionLogout="+EgURLEncoder.encode(sessionLogout,"UTF-8")+"&isSessionDetails=true";
									}
									if((s_timeline!=null && !s_timeline.equalsIgnoreCase("null") && s_timeline.trim().length()>0) && (eg_stdate!=null && !eg_stdate.equalsIgnoreCase("null") && eg_stdate.trim().length()>0))
									{
										insideQs = insideQs + "&eg_timeline="+EgURLEncoder.encode(s_timeline,"UTF-8")+"&eg_stdate="+EgURLEncoder.encode(eg_stdate,"UTF-8")+"&eg_enddate="+EgURLEncoder.encode(eg_enddate,"UTF-8")+"&starthr="+EgURLEncoder.encode(start_hr,"UTF-8")+"&endhr="+EgURLEncoder.encode(end_hr,"UTF-8")+"&startmin_h="+EgURLEncoder.encode(startmin_h,"UTF-8")+"&endmin_h="+EgURLEncoder.encode(endmin_h,"UTF-8");
										if(!s_timeline.equals("Recent"))
											insideQs = insideQs+"&eg_tbound="+EgURLEncoder.encode(eg_tbound,"UTF-8");
									}
									isEndDashXenApp=true;
								}
							}

							String userinfo=com.egurkha.util.StringUtils.replace(user,"\\","\\\\");
							userinfo=com.egurkha.util.StringUtils.replace(userinfo,"#","|hash|");
							userinfo=com.egurkha.util.StringUtils.replace(userinfo,"%","|percent|");
							userinfo=com.egurkha.util.StringUtils.replace(userinfo,"&","|amp|");
							String userurl="/final/monitor/eGUserDetails.jsp?comp="+EgURLEncoder.encode(server,"UTF-8")+"&comptype="+componentType+"&info=*"+EgURLEncoder.encode(userinfo, "UTF-8")+"&compName="+EgURLEncoder.encode(server+":"+componentType,"UTF-8")+"&componentName="+EgURLEncoder.encode(componentName,"UTF-8")+"&username="+EgURLEncoder.encode(s_user, "UTF-8")+"&searchval="+EgURLEncoder.encode(s_user, "UTF-8")+"&searchtype="+EgURLEncoder.encode("user", "UTF-8")+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&searchuser="+EgURLEncoder.encode(search_type+" "+search_value,"UTF-8");
							if((s_timeline!=null && !s_timeline.equalsIgnoreCase("null") && s_timeline.trim().length()>0) && (starttime!=null && !starttime.equalsIgnoreCase("null") && starttime.trim().length()>0))
							{
								//userurl = userurl + "&eg_timeline="+EgURLEncoder.encode(s_timeline,"UTF-8")+"&eg_stdate="+EgURLEncoder.encode(eg_stdate,"UTF-8")+"&eg_enddate="+EgURLEncoder.encode(eg_enddate,"UTF-8")+"&starthr="+EgURLEncoder.encode(start_hr,"UTF-8")+"&endhr="+EgURLEncoder.encode(end_hr,"UTF-8")+"&startmin_h="+EgURLEncoder.encode(startmin_h,"UTF-8")+"&endmin_h="+EgURLEncoder.encode(endmin_h,"UTF-8");

								userurl = userurl + "&eg_timeline="+EgURLEncoder.encode(s_timeline,"UTF-8")+"&eg_stdate="+EgURLEncoder.encode(starttime,"UTF-8")+"&eg_enddate="+EgURLEncoder.encode(endtime,"UTF-8")+"&starthr="+EgURLEncoder.encode(sthr,"UTF-8")+"&endhr="+EgURLEncoder.encode(endhr,"UTF-8")+"&startmin_h="+EgURLEncoder.encode(startmin_h,"UTF-8")+"&endmin_h="+EgURLEncoder.encode(endmin_h,"UTF-8");

								if(!s_timeline.equals("Recent"))
									userurl = userurl+"&eg_tbound="+EgURLEncoder.encode(eg_tbound,"UTF-8");
							}

							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);
								}
							}

							String userlayerQs="/final/monitor/EgSiteInfraView.jsp?site=NULL&qctr=2&fromalarm=1&fromPage=vm&newWindow=false&comptype="+EgURLEncoder.encode(componentType,"UTF-8")+"&host="+EgURLEncoder.encode(server,"UTF-8")+"&layer="+EgURLEncoder.encode(layer,"UTF-8")+"&test="+EgURLEncoder.encode(test,"UTF-8")+"-"+user+"&msmt_host=&isFromVmHost=true&gotoLayerModel=true&tab=LayerModel&toDashBoardLayer=true&isTotalVm=null&poweredOnVMs=null&tstate=GOOD&priority=10";

							boolean isLinkToInsideview=true;
							if(componentType.equalsIgnoreCase("Citrix_server") || componentType.equalsIgnoreCase("Terminal_server") || componentType.equalsIgnoreCase("Citrix_XcXenApp_server"))
							{
								if(!isLinkFromThin || !isEndDashXenApp)
								{
									insideQs = userlayerQs;
								}
								isLinkToInsideview=false;
							}
							else if(insideview_vm_list!=null && insideview_vm_list.size()>0 && !insideview_vm_list.contains(user.toLowerCase()))
							{
								if(!insideview_vm_list.contains(org_user_name.toLowerCase()))
								{
									insideQs = userlayerQs;
									isLinkToInsideview=false;
								}
								else
									isLinkToInsideview=false;
							}

							JSONObject linkObj = new JSONObject();
							linkObj.put("USER_LINK_TEXT",user);
							csvData.add(user);
							//if(insideview_vm_list!=null && (insideview_vm_list.contains(user.toLowerCase()) || insideview_vm_list.contains(org_user_name.toLowerCase())))
							if(!logoutTime.equals("-") && (!isLinkFromThinHistory) && (!isShowInsideview || !isLinkToInsideview))
								linkObj.put("USER_LINK_URL",userurl);
							else if(isUserWithDesktop || (insideview_vm_list!=null && (insideview_vm_list.contains(user.toLowerCase()) || insideview_vm_list.contains(org_user_name.toLowerCase()))))
							{
								if(isShowInsideview && showInsideQs!=null && showInsideQs.trim().length()>0)
								{
									linkObj.put("USER_LINK_URL",showInsideQs);
								}
								else
								{
									linkObj.put("USER_LINK_URL",insideQs);
								}
							}
							//else if(isLinkFromThin && (!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("Citrix_XcXenApp_server")) && ((vdiList!=null && vdiList.size()>0 && vdiList.contains(componentType)) || (vdiUserList!=null && vdiUserList.size()>0 && vdiUserList.contains(componentType))) && insideview_vm_list!=null && (insideview_vm_list.contains(user.toLowerCase()) || insideview_vm_list.contains(org_user_name.toLowerCase())) )
							else if(isLinkFromThin && (!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("Citrix_XcXenApp_server")) && ((vdiList!=null && vdiList.size()>0 && vdiList.contains(componentType)) || (vdiUserList!=null && vdiUserList.size()>0 && vdiUserList.contains(componentType))) && insideview_vm_list!=null && insideview_vm_list.size()>0 && (insideview_vm_list.contains(user.toLowerCase())) )
							{
								if(isShowInsideview && showInsideQs!=null && showInsideQs.trim().length()>0)
								{
									linkObj.put("USER_LINK_URL",showInsideQs);
								}
								else
								{
									linkObj.put("USER_LINK_URL",insideQs);
								}
							}
							else if(isLinkFromThin && isEndDashXenApp)
							{
								linkObj.put("USER_LINK_URL",insideQs);
							}
							else
							{
								linkObj.put("USER_LINK_URL",userurl);
							}

							int c = 0;
							rowData.put("COLUMN_"+c,linkObj);
							c++;

							compLink = new JSONObject();
							//String tlayerQs="site=NULL^qctr=2^fromalarm=1^fromPage=vm^newWindow=false^comptype="+EgURLEncoder.encode(componentType,"UTF-8")+"^host="+EgURLEncoder.encode(server,"UTF-8")+"^layer="+EgURLEncoder.encode(layer,"UTF-8")+"^test="+EgURLEncoder.encode(test,"UTF-8")+"-"+EgURLEncoder.encode(user,"UTF-8")+"^msmt_host=^isFromVmHost=true^gotoLayerModel=true^tab=LayerModel^toDashBoardLayer=true^isTotalVm=null^poweredOnVMs=null^tstate=GOOD^priority=10^searchValueandType="+EgURLEncoder.encode("user"+" "+s_user,"UTF-8");

							String tlayerQs="site|eq|NULL^qctr|eq|2^fromalarm|eq|1^fromPage|eq|vm^newWindow|eq|false^comptype|eq|"+componentType+"^host|eq|"+server+"^test|eq|"+test+"-+"+user+"^layer|eq|"+layer+"^msmt_host|eq|^isFromVmHost|eq|true^gotoLayerModel|eq|true^tab|eq|LayerModel^toDashBoardLayer|eq|true^isTotalVm|eq|null^poweredOnVMs|eq|null^tstate|eq|GOOD^priority|eq|10^searchValueandType|eq|"+"user"+" "+s_user+"^searchString|eq|"+search_type+" "+search_value;

							compLink.put("USERCOMPNAME_LINK_TEXT",componentName);
							csvData.add(componentName);
							if(!userHasVM)
								compLink.put("USERCOMPNAME_LINK_URL",EgURLEncoder.encode(tlayerQs,"UTF-8"));
							rowData.put("COLUMN_"+c,compLink);
							c++;

							rowData.put("COLUMN_"+c,loginTime);
							csvData.add(loginTime);
							c++;
							rowData.put("COLUMN_"+c,logoutTime);
							csvData.add(logoutTime);
							c++;
							rowData.put("COLUMN_"+c,duration);
							csvData.add(duration);
							c++;
							if(isVM){
								rowData.put("COLUMN_"+c,cIP);
								csvData.add(cIP);
								c++;
							}
							else if(!componentType.equalsIgnoreCase("Terminal_server") && !componentType.equalsIgnoreCase("VMWareView_RDS")){
								rowData.put("COLUMN_"+c,cName);
								csvData.add(cName);
								c++;
								rowData.put("COLUMN_"+c,cIP);
								csvData.add(cIP);
								c++;
								rowData.put("COLUMN_"+c,cType);
								csvData.add(cType);
								c++;
							}

							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)
											rowData.put("COLUMN_"+c,locDetVal);
										else
											rowData.put("COLUMN_"+c,"-");
										csvData.add(locDetVal);
										c++;
									}
								}
							}

							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);
												}
												columnDetails.put(mappingInfo.getTextDescription("monitor.thinclients."+displayName),func+" ("+unit+")");
											}
											rowData.put("COLUMN_"+c,value);
											csvData.add(value);
											c++;
										}
									}
									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 ddQs="/final/monitor/EgDiagnosis.jsp?site=NULL&host="+EgURLEncoder.encode(server.substring(0,server.lastIndexOf(":")),"UTF-8")+"&comptype="+EgURLEncoder.encode(componentType,"UTF-8")+"&port="+server.substring(server.lastIndexOf(":")+1)+"&test="+EgURLEncoder.encode(testForDD,"UTF-8")+"&info=*"+EgURLEncoder.encode(user,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(mHostForDD,"UTF-8")+"&from=0&newWindow=true&measure="+ddMeasure+"&firsttime=true&flag=0 &starttime="+EgURLEncoder.encode(loginTime,"UTF-8")+"&endtime="+EgURLEncoder.encode(et_dispDate,"UTF-8")+"&starthr="+sthr+"&endhr="+endhr+"&timeline="+s_timeline;

							String graphQs="";
							String hostname=EgURLEncoder.encode(server.substring(0,server.lastIndexOf(":")),"UTF-8");
							String port = server.substring(server.lastIndexOf(":")+1);

							String dLink = "/final/monitor/EgDiagnosis.jsp?site=NULL&host="+hostname+"&port="+port+"&test="+testForDD+"&isPopUp=true";

							String compddLink = dLink + "&info=*"+EgURLEncoder.encode(user,"UTF-8")+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&from=0&measure="+ddMeasure+"&flag=1&firsttime=true&comptype="+EgURLEncoder.encode(componentType,"UTF-8");

							String histLink="/final/monitor/dispComponentHistory.jsp?site=NULL&info=" + EgURLEncoder.encode(user,"UTF-8") + "&test=" + test + "&component=" +EgURLEncoder.encode(server+":"+componentType,"UTF-8");

							String ddLink = response.encodeURL("/final/monitor/componentMeasureTabSet.jsp?")+"type="+EgURLEncoder.encode(componentType,"UTF-8")+"&site=NULL&host="+hostname+"&port="+port+"&info="+EgURLEncoder.encode(user,"UTF-8")+"&state=any&messy="+measureList+"&test="+test+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&clicked=dd&from=measurespage&isVM="+userHasVM;

							String compgraphLink = "/final/monitor/dispComponentGraphs.jsp?site=NULL&host=" +hostname+"&port="+port+"&layer="+layer+"&test="+test+"&comptype="+EgURLEncoder.encode(componentType,"UTF-8");


							String  graphLink = compgraphLink + "&info=*"+EgURLEncoder.encode(user,"UTF-8")+ "&gtype=1&measure="+measureList+ "&msmt_host="+	EgURLEncoder.encode(mHost,"UTF-8")+"&state=any";

							String compsummarygraphLink ="/final/monitor/dispComponentSummaryGraphs.jsp?site=NULL&host=" +EgURLEncoder.encode(hostname,"UTF-8")+ "&port=" + port + "&layer=" +EgURLEncoder.encode(layer,"UTF-8")+ "&test=" + test + "&comptype="+EgURLEncoder.encode(componentType,"UTF-8");
							
							String summarygraphLink = compsummarygraphLink + "&info=*"+EgURLEncoder.encode(user,"UTF-8")+ "&gtype=1&measure="+measureList+ "&msmt_host="+	EgURLEncoder.encode(mHost,"UTF-8")+"&state=any";

							String comptrendgraphLink ="/final/monitor/dispComponentTrendGraphs.jsp?site=NULL&host=" +EgURLEncoder.encode(hostname,"UTF-8")+ "&port=" + port + "&layer=" +EgURLEncoder.encode(layer,"UTF-8")+ "&test=" + test + "&comptype="+EgURLEncoder.encode(componentType,"UTF-8");

							String trendgraphLink = comptrendgraphLink + "&info=*"+EgURLEncoder.encode(user,"UTF-8")+ "&gtype=1&measure="+measureList+ "&msmt_host="+	EgURLEncoder.encode(mHost,"UTF-8")+"&state=any";

							String  aggLink="/final/monitor/dispAggComponentGraphs.jsp?site=NULL&host=" +EgURLEncoder.encode(hostname,"UTF-8")+ "&port=" + port + "&layer=" +EgURLEncoder.encode(layer,"UTF-8")+ "&test=" + test + "&comptype="+EgURLEncoder.encode(componentType,"UTF-8");

							String historyLink = histLink+"&measure="+measureList;

							String feedLink="/final/monitor/dispComponentFeedback.jsp?site=NULL&trgthost="+hostname+"&port="+port+"&test="+test+"&comptype="+EgURLEncoder.encode(componentType,"UTF-8");

							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();
							}

							String feedbackLink =  feedLink+"&info=*"+EgURLEncoder.encode(user,"UTF-8")+ "&measure="+measureList+ "&msmttime="+msmtTimeStr2 +"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8");

							String aggregateLink=aggLink + "&info=*"+EgURLEncoder.encode(user,"UTF-8")+ "&gtype=1&measure="+measureList+ "&msmt_host="+	EgURLEncoder.encode(mHost,"UTF-8")+"&state=any";

							String measureLink = response.encodeURL("/final/monitor/componentMeasureTabSet.jsp?")+"type="+EgURLEncoder.encode(componentType,"UTF-8")+"&site=NULL&host="+hostname+"&port="+port+"&info="+EgURLEncoder.encode(user,"UTF-8")+"&state=any&messy="+measureList+"&from=measurespage&dd_disp=yes&test="+test+"&msmt_host="+EgURLEncoder.encode(mHost,"UTF-8")+"&isVM="+userHasVM;

							graphQs = measureLink; 
							ddQs = ddLink;

							StringTokenizer st2=new StringTokenizer(measureList,",");
							if(measureList!=null && st2.countTokens()>0 && st2.countTokens()==1)
							{
								graphQs=graphQs+"&showRange=Range";
							}
							graphQs=graphQs+"&time=Any&gtype=0&draw=1&gformat=graph&from=test&mode=3D&qctr=5&search=&thisIs=event&showRange=Range&newWindow=true";

							JSONObject graphlinkObj = new JSONObject();
							graphlinkObj.put("USERGRAPH_LINK_IMAGE","graphicon");
							if(orgDate!=null && orgDate.trim().length()>0)
							{
								orgDate = orgDate.trim();
								String temDate= orgDate;

								if(orgDate.indexOf(":")>-1)
								{
									int colonCountCheck = orgDate.length() - com.egurkha.util.StringUtils.replace(orgDate,":","").length();
									if(colonCountCheck == 2)
										temDate = orgDate.substring(0,orgDate.lastIndexOf(":"));
								}

								graphQs += "&fromSearch=true&latime="+temDate;
								ddQs += "&fromSearch=true&latime="+temDate;
								if(tempLogoutTime!=null && tempLogoutTime.trim().length()>0 && !tempLogoutTime.equalsIgnoreCase("NULL") && !tempLogoutTime.equals("-"))
								{
									if(tempLogoutTime.indexOf(":")>-1)
									{
										int colonCountCheck = tempLogoutTime.length() - com.egurkha.util.StringUtils.replace(tempLogoutTime,":","").length();
										if(colonCountCheck == 2)
											tempLogoutTime = tempLogoutTime.substring(0,tempLogoutTime.lastIndexOf(":"));
										
										//graphQs += "&louttime="+tempLogoutTime;
										//ddQs += "&louttime="+tempLogoutTime;
									}
								}
								else if(tempLogoutTime!=null && tempLogoutTime.equals("-"))
								{
									SimpleDateFormat loutsdf = new SimpleDateFormat(currentDateFormat+" HH:mm");
									java.util.Date tmpday = egDt.egetRealDate();
									tempLogoutTime = loutsdf.format(tmpday);
								}
								graphQs += "&louttime="+tempLogoutTime;
								ddQs += "&louttime="+tempLogoutTime;
							}
							
							graphlinkObj.put("USERGRAPH_LINK_URL",graphQs);
							rowData.put("COLUMN_"+c,graphlinkObj); 
							c++;

							if(showDDIcon)
							{ 
								linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"compddlink", compddLink);
								JSONObject ddlinkObj3 = new JSONObject();
								ddlinkObj3.put("USERDD_LINK_IMAGE","ddicon");
								ddlinkObj3.put("USERDD_LINK_URL",ddQs);
								rowData.put("COLUMN_"+c,ddlinkObj3);
								c++;
							}

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"compfeedbacklink", aggregateLink+"&isVM="+userHasVM);

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"compgraphlink", graphLink+"&isVM="+userHasVM);

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"compsummarygraphlink", summarygraphLink+"&isVM="+userHasVM);

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"comptrendgraphlink", trendgraphLink+"&isVM="+userHasVM);

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"comphistorylink", historyLink+"&isVM="+userHasVM);

							linksMap.put(test+"#"+measureList+"#"+user+"#"+mHost+"compfeedbacklink", feedbackLink+"&isVM="+userHasVM);

							gridData.add(rowData);
						}
						listData.add(csvData);
					}
				}
				else
				{
					rootJson.put("noDataErrorMsg",mappingInfo.getTextDescription("monitor.vmsearch.No data available"));
				}
				if(listData!=null)
					session.setAttribute("userSearchCsvData",listData);
			}
			else
			{
				rootJson.put("noDataErrorMsg",mappingInfo.getTextDescription("monitor.vmsearch.No data available"));
			}
			String mngrIProc = new IniFile(new com.eg.EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
			String htmlFileName = mngrIProc + "/final/monitor/eGSessionDetailsPrint.jsp;jsessionid="+session.getId()+"?";
			String csvFilePath = "/final/monitor/eGSessionDetailsPrint.jsp;jsessionid="+session.getId()+"?";
			session.setAttribute("USERSEARCH_PDF_URL",htmlFileName);
			session.setAttribute("REPORT_NAME","userSearch");
			session.setAttribute("title","User Search Details");
			session.setAttribute("frmPage","userSearch");

			int increment = Integer.parseInt(usersdetailsperpage);
			int optionCount = 5;
			String rowsPerPage[] = new String[optionCount];
			for(int i=0;i<optionCount;i++)
			{
				int j=i+1;
				rowsPerPage[i] = "" + j* increment;
			}
			JSONArray eventsPerPageJson = new JSONArray();
			String rowCount = request.getParameter("eventsPerPage");
			if(rowCount == null || rowCount.equals("null"))
				rowCount = rowsPerPage[0];
			for(int i=0;i<rowsPerPage.length;i++)
			{
				JSONObject eventsPerPageJsonObj = new JSONObject();
				eventsPerPageJsonObj.put("displayField",rowsPerPage[i]);
				eventsPerPageJsonObj.put("valueField",rowsPerPage[i]);
				eventsPerPageJson.add(eventsPerPageJsonObj);
			}
			gridObj.put("eventsPerPage",eventsPerPageJson);
			gridObj.put("eventsPerPageValue",rowCount);
			columnDetails.put(mappingInfo.getTextDescription("monitor.common.Graph"),"");
			columnDetails.put(mappingInfo.getTextDescription("monitor.common.DD"),"");
			//columnDetailsWidth.add(new Integer(user_int));
			ftitle=s_title.toString();
			gridObj.put("searchmessage",mappingInfo.getTextDescription("monitor.vmsearch.No data available for the current search"));
			gridObj.put("searchtitle",ftitle);
			gridObj.put("searchtype","usersearch");
			gridObj.put("screenLabels",screenLabels);
			if(dateTime!=null && dateTime.size()>0)
				gridObj.put("dateTime",dateTime);
			gridObj.put("usersdetailsperpage",rowCount);
			gridObj.put("timeLineList",historyTmeLineList);
			gridObj.put("COLUMNS",columnDetails);
			gridObj.put("TOTAL_COLUMNS",columnDetails.size());
			//gridObj.put("COLUMNSWIDTH",columnDetailsWidth);
			gridObj.put("DATA",gridData);
			gridObj.put("componentTypeOptions",componentTypeOptions);
			rootJson.put("SEARCH_DATA",gridObj);
			rootJson.put("csvFilePath",csvFilePath);
			session.setAttribute("Tablinks", linksMap);

			out.println(rootJson.toString());
        }
        catch(Throwable e)
        {
	       System.out.println("EXCEPTION CITRIXUSER---->"+e);
		   e.printStackTrace();
        } 
		


%>