<%
/************************************************************************************************
* File				: ErCtxApplicationReport.jsp
* Purpose			: Displays the configured measures and its details for the Citrix Applications
* Author			: Alagu Sundaram. MR.
* Creation Date		: 7/12/05
*************************************************************************************************/
%>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.text.ParseException" %>
<%@ page import ="com.eg.ErDbServer"%>
<%@ page import = "egurkha.*" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import ="com.eg.EgInstallInfo"%>
<%@ page import ="com.eg.IniFile"%>
<%@ page import="com.egurkha.ini.*" %>
<%@ page import="com.eg.EgDateInfo" %>
<%@ page import="com.eg.EgGroupInfo" %>
<%@ page import="com.eg.EgReportInfo" %>
<%@ page import = "com.egurkha.*" %>
<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "java.net.*" %>
<%@ page import="com.eg.EgThresholdInfo" %>
<%@ page import="com.eg.EgTablesInfo" %>
<%@ page import="com.eg.EgMappingInfo" %>
<%@ page import = "java.net.URLEncoder" %>
<%@ page import = "java.net.URLDecoder" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.egurkha.util.ListUtils" %>
<%@ page import = "java.text.*" %>
<%@ page import = "com.eg.EgConfigInfo"%>

<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

<%@ page import = "net.sf.json.*" %>
<%@ page import = "com.egurkha.util.StringUtils" %>
<%@ page import = "com.eg.EgAgentInfo" %>
<%@ page import = "com.eg.EgTopoInfo" %>
<%@ page import = "com.eg.EgServicesInfo"%>

<%
	response.setContentType("application/json");

	JSONObject rootJson = new JSONObject();
	JSONObject screenLabelJson = new JSONObject();
	JSONObject hiddenfieldsJson=new JSONObject();
	JSONObject loopJsonObj = new JSONObject();
	JSONArray geoColArray = new JSONArray();

	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");
	String titleToDisplay=request.getParameter("er_RmDispName");

	//Back Button - Start

	HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
	String backQnumber = request.getParameter("backQnumber");
	String servlet2 = request.getParameter("backServletName");

	ErHelperUtils erhelputils = null;
	ErEsxVMutils erEsxUtils = new ErEsxVMutils();
	erEsxUtils.setNeedGroupTire(true);

	if( servlet2!=null && !servlet2.equals(""))
		erhelputils = new ErHelperUtils(backreqMap,backQnumber,servlet2);
	else
		erhelputils = new ErHelperUtils(backreqMap,backQnumber);

	boolean enableBack=erhelputils.isBackButtonEnable();
	String backButtonEnable = request.getParameter("back");
	rootJson.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
	if(backButtonEnable != null && backButtonEnable.equalsIgnoreCase("True"))
	{
		status = (String)request.getParameter("status");
		request.setAttribute("htdata",null);
		request.setAttribute("app_topusers",null);
		request.setAttribute("appChartData",null);
		bggroundStr = (String)request.getParameter("bggroundStr");
	}
	//Back Button - End
	// for application user details report.
	String isApplicationsUserReport=request.getParameter("application_user_details_report");
	String groupByComponent=request.getParameter("group_by_component");
	String csvNameByRow=request.getParameter("csvNameByRow");// for display multiple user name in csv file true->next row, false->same column
	String reportType="Application Report";
	String targetType=request.getParameter("er_trgttype");
	String backGroundReportType="Thin_Client_Application_Activity";
	if(targetType!=null && targetType.equalsIgnoreCase("Application User Details"))
	{
		reportType=targetType;
		backGroundReportType="Application_User_Details";
	}
	try
	{
		String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
		ArrayList aListworkGrp = new ArrayList();
		String s_tit1= "";
		Hashtable ht1 = new Hashtable();
		List lst_dat1 = new LinkedList();
		Hashtable sen1 = new Hashtable();
		Vector vec1 = new Vector();
		List lst_dat2 = new LinkedList();
		Vector v_val1 = new Vector();
		List lst = new LinkedList();
		String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
		IniUI ui = IniUI.getInstance();
		EgDateInfo egDt = new EgDateInfo();
		String Hourfrom="";
		String Minfrom="";
		String Hourto="";
		String Minto="";
		String fromTime,toTime;
		String variable;
		String s_QSGraph="";
		StringTokenizer st;
		EgMappingInfo intlmap=new EgMappingInfo(thisuser.getLanguage());
		ErComponentsUtils compUtils = new ErComponentsUtils(thisuser.getLoginID());
		ErUtils erUtils = new ErUtils();
		ErInfo erInfo = new ErInfo();
		EgReportInfo reportInfo=new EgReportInfo("manager");
		String confrimation = reportInfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
		String strbgrepportName = reportInfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
		String limitforbg = reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
		EgThresholdInfo hreshholdInfo = new EgThresholdInfo("manager");
		EgTablesInfo tablesInfo = new EgTablesInfo("manager");
		String s_user = request.getParameter("er_user");
		ErUserData erdata = new ErUserData(UBean.getUserId(),false);
		EgTopoInfo topoInfo = new EgTopoInfo("manager");
		EgCrawler crawlerBean = new EgCrawler(new IniFile(s_iniFile_dir + "eg_topology.ini"));
		Hashtable htt=new Hashtable();
		htt=(Hashtable)request.getAttribute("htdata");
		Vector v_iconData = (Vector)request.getAttribute("v_iconData");
		if(v_iconData!=null)
			session.setAttribute("v_iconData",v_iconData);
		Vector v_components = compUtils.getAllUserComponents1();
		Vector v_component = new Vector();
		Vector v_temp = new Vector();
		Vector defComps = new Vector();
		Vector colZoneComps = new Vector();
		Vector v_comptype=new Vector();
		ArrayList aListCompType = new ArrayList();
		Vector v_tmp = new Vector();
		Vector v_infos=null;
		Vector v_application=new Vector();
		List v_site = new ArrayList();
		Vector temp_component = new Vector();
		String installDir = EgInstallInfo.getInstallDir();
		IniFile inifile = new IniFile(installDir +"/manager/config/eg_report.ini");
		String sub = "MISC";
		String var = "CtxServer";
		String values = inifile.getValue(sub,var);
		String val="";
		String s_component = "";
		String s_qryString	="";
		String timeline =request.getParameter("er_timeline");
		String testmes = request.getParameter("select_testmes");
		String rtype =request.getParameter("er_type");
		String s_comptype = request.getParameter("er_comptype");
		String sel_ComType = request.getParameter("er_compType") ;
		String reqFromSchedule = request.getParameter("fromSchedule");
		String reqFromScheduleModify = request.getParameter("fromScheduleModify");
		String schedule_id = request.getParameter("schedule_id");
		String fromFavoriteModify = request.getParameter("fromFavoriteModify");
		String favorite_id = request.getParameter("id");
		String er_favorite = request.getParameter("er_favorite");
		String divStatus = request.getParameter("divStatus"); 
		String srcForImg="";

		if(divStatus==null)
		{
			divStatus="none";
		}
		if(divStatus.equals("none"))
		{
			srcForImg="/final/images/moreoption.png";
		}
		else if(divStatus.equals("block"))
		{
			srcForImg="/final/images/lessoption.png";
		}
		ArrayList aListSupportedComponentType = reportInfo.getComponentsList("APPLICATION_REPORT",false);
		ArrayList aListAlltype = new ArrayList();

		for(int kk=0;kk<aListSupportedComponentType.size();kk++)
		{
			aListAlltype.add("All "+aListSupportedComponentType.get(kk));
		}

		if (rtype==null)
		{
			rtype="Yes";
		}
		boolean termpresent=false;
		Vector v_testmes = new Vector();
		String isNeedGeo = reportInfo.getValue("APPLICATION_REPORT","needGeoDetails");
		String columnIncluded = reportInfo.getValue("APPLICATION_REPORT","GeoDetailsColumn");
		for(int i=0;i<v_components.size();i++)
		{
			String s_tmp = (String)v_components.get(i);
			StringTokenizer tk = new StringTokenizer(values,",");
			while(tk.hasMoreTokens())
			{
				val = tk.nextToken();
				if(val==null || val.equals(""))
				{
					if (s_tmp.endsWith(val))
					{
						v_tmp.add(s_tmp);
					}
				}
				else
				{
					if(s_tmp.endsWith(val))
					{
						v_tmp.add(s_tmp);
					}
				}
			}
		}
		Hashtable ht_data = (Hashtable)request.getAttribute("Report_data");
		Vector app_data = (Vector)request.getAttribute("App_data");
		ArrayList app_topusers = (ArrayList)request.getAttribute("app_topusers");
		Vector v_qry_string = (Vector)request.getAttribute("appChartData");
		Vector pdfQuery = (Vector)request.getAttribute("appPdfData");
		String backQS = (String)session.getAttribute("topBackQuery");
		String backQSserver = (String)session.getAttribute("topBackQuery_server");
	
		session.setAttribute("ApplicationReport",app_data);
		session.setAttribute("appForPrint",app_topusers);
		session.removeAttribute("topBackQuery");
		session.removeAttribute("backQSserver");

		HashMap Report_data=null;
		Hashtable h_data = new Hashtable();
		Hashtable h_rep = new Hashtable();
		Vector v_data1 = new Vector();
		Vector  v_add = new Vector();

		ArrayList subjects = (ArrayList)reportInfo.getVariables("APPLICATION_REPORT");
		String numTopUsers = reportInfo.getTop("APPLICATION_REPORT");
		Vector v_sort=new Vector();
		v_sort.add("% Time in use");
		v_sort.add("Number of unique users");

		String s_variable="";
		StringTokenizer tok1=null;
		String type="";
		String mes="";
	
		String s_sort=request.getParameter("er_sortby");
		String tbound = request.getParameter("er_tbound");
		String cTime = request.getParameter("currTime");
		String s_application1 = request.getParameter("er_application1");
	
		if(tbound==null)
			tbound="Fixed";
		String key="";
		ErReqData erd = new ErReqData(request);
		EgDateInfo egDate = new EgDateInfo();
		String stdate="";
		String enddate="";
		String sthr="";
		String endhr="";
		String sthr1 = "";
		String endhr1 = "";
		long msecsPerHour = (long) 1000 * 60 * 60;
		fromTime = reportInfo.getTimeFrame("APPLICATION_REPORT","FROM");
		toTime = reportInfo.getTimeFrame("APPLICATION_REPORT","TO");
		st = new StringTokenizer(fromTime,":");
		if(st.hasMoreTokens())
		{
			Hourfrom = st.nextToken();
			Minfrom = st.nextToken();
		}
		st=new StringTokenizer(toTime,":");
		if(st.hasMoreTokens())
		{
			Hourto = st.nextToken();
			Minto = st.nextToken();
		}
		String Days = reportInfo.getExcludeWeekend("APPLICATION_REPORT");
		String NoofServers = reportInfo.getNoOfBars("APPLICATION_REPORT","top");
		Vector v_time=new Vector();
		v_time.add("00");
		v_time.add("01");
		v_time.add("02");
		v_time.add("03");
		v_time.add("04");
		v_time.add("05");
		v_time.add("06");
		v_time.add("07");
		v_time.add("08");
		v_time.add("09");
		v_time.add("10");
		v_time.add("11");
		v_time.add("12");
		v_time.add("13");
		v_time.add("14");
		v_time.add("15");
		v_time.add("16");
		v_time.add("17");
		v_time.add("18");
		v_time.add("19");
		v_time.add("20");
		v_time.add("21");
		v_time.add("22");
		v_time.add("23");

		Vector v_min=new Vector();
		v_min.add("00");
		v_min.add("05");
		v_min.add("10");
		v_min.add("15");
		v_min.add("20");
		v_min.add("30");
		v_min.add("35");
		v_min.add("40");
		v_min.add("45");
		v_min.add("50");
		v_min.add("55");
		v_min.add("59");

		String timefrom2=request.getParameter("timefrom");
		String minfrom2=request.getParameter("minfrom");
		String timeto2=request.getParameter("timeto");
		String minto2=request.getParameter("minto");
		if (timefrom2!=null)
			Hourfrom=timefrom2;
		if (minfrom2!=null)
			Minfrom=minfrom2;
		if (timeto2!=null)
			Hourto=timeto2;
		if (minto2!=null)
			Minto=minto2;
		String er_option =request.getParameter("er_option");
		String er_site = request.getParameter("er_site");
		if(er_option == null || (er_option!=null && er_option.isEmpty()))
		{
			er_option = "Zone";
		}
		//  for - reports by segment,Service default loading setup
		String er_dataFrom =request.getParameter("er_dataFrom");
		String er_service = request.getParameter("er_service");
		if(er_dataFrom!=null && (er_dataFrom.equalsIgnoreCase("Group")||er_dataFrom.equalsIgnoreCase("Segment")||er_dataFrom.equalsIgnoreCase("Service")||er_dataFrom.equalsIgnoreCase("Zone")))
		{
			if(er_service!=null)
			{
				er_option=er_dataFrom;
				er_site=er_service;
			}
		}
		//for - reports by Component default loading setup
		else if(er_dataFrom!=null && er_dataFrom.equalsIgnoreCase("Component"))
		{
			er_option=er_dataFrom;
			er_site=null;
		}
		String headerKeyName="";
		if(er_option!=null && er_option.equalsIgnoreCase("Segment"))
		{
			headerKeyName=er_option+" : "+er_site;
		}
		else if(er_option!=null && er_option.equalsIgnoreCase("Service"))
		{
			headerKeyName=er_option+" : "+er_site;
		}
		else if(er_option!=null && er_option.equalsIgnoreCase("Group"))
		{
			headerKeyName=er_option+" : "+er_site;
		}
		else if(er_option!=null && er_option.equalsIgnoreCase("Component"))
		{
			if(request.getParameter("er_compType")!=null)
				headerKeyName=er_option+" : "+request.getParameter("er_compType");
			else if(request.getParameter("er_select_server")!=null)
				headerKeyName=er_option+" : "+request.getParameter("er_select_server");
			else
				headerKeyName=er_option;
			headerKeyName="";
		}
		else
		{
			headerKeyName="Zone"+" : "+request.getParameter("select_farm");
		}
		User this_user = UserRegistry.getInstance().getUser(session.getId());
		String loginid = this_user.getLoginID();
		List v_option = new ArrayList();
		Hashtable htAllGroups=new Hashtable();
		// for - reports by segment,Service default loading setup
		if(er_dataFrom!=null && (er_dataFrom.equalsIgnoreCase("Group")||er_dataFrom.equalsIgnoreCase("Segment")||er_dataFrom.equalsIgnoreCase("Service")||er_dataFrom.equalsIgnoreCase("Zone")))
		{
			htAllGroups = erEsxUtils.getGroups(null, aListSupportedComponentType, thisuser, loginid, "Yes",true);
		}
		else
		{
			htAllGroups = erEsxUtils.getGroups(s_comptype, aListSupportedComponentType, thisuser, loginid, "Yes",true);
		}
		ArrayList aListOption = erEsxUtils.getOptions(htAllGroups);
		if(aListOption!=null && aListOption.size()>0)
			v_option.addAll(aListOption);
		JSONArray arr = new JSONArray();
		JSONObject obj=null;
		if(v_option!=null && v_option.size()>0)
		{
			rootJson.put("selectedAnalysisByCombo",er_option);
			for(int i=0; i<v_option.size(); i++)
			{
				obj = new JSONObject();
				obj.put("displayField", intlmap.getTextDescription("reporter.common."+v_option.get(i)));
				obj.put("valueField",v_option.get(i));
				arr.add(obj);
			}
		}
		else
		{
			obj = new JSONObject();
			obj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
			obj.put("valueField","-1");
			arr.add(obj);
		}
		rootJson.put("analysisByCombo",arr);
		screenLabelJson.put("reporter.thin.Sort By",intlmap.getTextDescription("reporter.thin.Sort By"));
		JSONArray sortArr = new JSONArray();
		obj = new JSONObject();
		obj.put("displayField", intlmap.getTextDescription("reporter.thin.% Time in use"));
		obj.put("valueField","1");
		sortArr.add(obj);
		obj = new JSONObject();
		obj.put("displayField", intlmap.getTextDescription("reporter.thin.Number of unique users"));
		obj.put("valueField","2");
		sortArr.add(obj);
		obj = new JSONObject();
		rootJson.put("sortComboArr",sortArr);
		if(s_sort!=null && !s_sort.equals("")&& !s_sort.equals("-1"))
			rootJson.put("selectedSort",s_sort);

		String value1 = inifile.getValue(sub,var);
		sub ="LIST_OF_ZONES";
		inifile = new IniFile(installDir +"/manager/config/eg_group.ini");
		String vari[] = inifile.getVariables(sub);
		for(int i=0;i<vari.length;i++)
		{
			variable = vari[i];
			v_component.add(variable);
		}
		String show_timeinuse = request.getParameter("sh_timeinuse");
		String s_farmserver = request.getParameter("select_farm");
		String s_application = request.getParameter("er_application");
		String [] s_appl = request.getParameterValues("er_application");
		String s_server = request.getParameter("er_server");
		String strWorkgrpName = request.getParameter("er_workgrpname");
		String s_compType = request.getParameter("er_compType");
		String[] selectedCompArrays = null;	 //...
		selectedCompArrays = request.getParameterValues("er_workgroupserver");//...
		String serverForSorting=null;
		String s_perserver=request.getParameter("er_perserver");
		if (s_perserver==null || s_perserver.equals(""))
			s_perserver="Yes";

		String strEncodeFarmserver = s_farmserver;
		String strEncodeServer = s_server;
		if(strEncodeFarmserver!=null)
			strEncodeFarmserver = EgURLEncoder.encode(strEncodeFarmserver,"UTF-8");
		if(strEncodeServer!=null)
			strEncodeServer = EgURLEncoder.encode(strEncodeServer,"UTF-8");
		ArrayList v_Workgroupcomponents = new ArrayList();//...
		EgGroupInfo gpinfo = new EgGroupInfo();
		String tmpComponent="";
		Vector v_comp = compUtils.getAllUserComponents1();
		String sub1 = "MISC";
		String var1 = "CtxServer";
		Vector v_server=new Vector();
		boolean present=false;
		Vector dispzone=new Vector();
		List aListselectedAppln = null;
		if(s_appl!=null)
		{
			aListselectedAppln = Arrays.asList(s_appl);
			String tmpString   = aListselectedAppln.toString().replace("[","").replace("]","");
			if(tmpString.length()>=30)
			{
				s_application = tmpString.substring(0,29)+"...";
			}
			else
			{
				s_application =tmpString;
			}
		}
		//---- Report By Combo for Segment,Service & Components.
		screenLabelJson.put("reporter.thin.Report By",intlmap.getTextDescription("reporter.uptime.Analyze by"));
		if (er_option!=null &&  !er_option.equalsIgnoreCase("null"))
		{
			v_site = erEsxUtils.getGroupsName(htAllGroups,er_option);
			if(v_site!=null && v_site.size()>0)
				Collections.sort(v_site,String.CASE_INSENSITIVE_ORDER);
			List aListComponentTemp=null;
			if(er_option.equals("Group") || er_option.equals("Segment") || er_option.equals("Service"))
			{
				if(er_site==null && v_site!=null && v_site.size()>0)
				{
					er_site=(String)v_site.get(0);
				}
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,er_site);
			}
			else if(er_option.equals("Zone"))
			{
				if(v_site!=null && v_site.size()>0)
				{
					dispzone.addAll(v_site);
					if(s_farmserver==null)
					{
						s_farmserver=(String)v_site.get(0);
					}
				}
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,s_farmserver);
			}
			else if(er_option.equals("Component"))
			{
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,null);
			}
			if(aListComponentTemp!=null && aListComponentTemp.size()>0)
			{
				v_components = new Vector();
				v_components.addAll(aListComponentTemp);
			}
			if(aListComponentTemp!=null && aListComponentTemp.size()>0)
			{
				aListCompType = new ArrayList();
				for(int i=0; i<aListComponentTemp.size(); i++) 
				{
					String loopComponent = (String) aListComponentTemp.get(i);
					if(loopComponent.lastIndexOf(":")>-1)
					{
						String loopComp = loopComponent.substring(0,loopComponent.lastIndexOf(":"));
						String  loopType = loopComponent.substring(loopComponent.lastIndexOf(":")+1);
						{
							if(aListCompType!=null && !aListCompType.contains(loopType))
							aListCompType.add(loopType);
						}
					}
				}
			}
			if(er_option.equalsIgnoreCase("Component"))
			{
				if(aListComponentTemp!=null && aListComponentTemp.size()>0)
				{
					v_components = new Vector();
					v_components.addAll(aListComponentTemp);
				}
				List compTypes = compUtils.getAllComponentType();
				if(compTypes!=null && compTypes.size()>0)
				{
					for(int aa=0;aa<compTypes.size();aa++)
					{
						if(aListSupportedComponentType.contains(compTypes.get(aa)))
						{
							if(aListCompType!=null && !aListCompType.contains(compTypes.get(aa)))
								aListCompType.add(compTypes.get(aa));
						}
					}
				}
			}
			Collections.sort(aListCompType,String.CASE_INSENSITIVE_ORDER);
			if(s_compType==null&& aListCompType!=null && aListCompType.size()>0)
			{
				s_compType=(String)aListCompType.get(0);
			}
			if(s_compType != null && aListComponentTemp!=null)
			{
				v_components = new Vector();
				if(s_compType.equalsIgnoreCase("all"))
				{
					v_components.addAll(aListComponentTemp);
				}
				else
				{
					for(int ii=0;ii<aListComponentTemp.size();ii++)
					{
						String ccmp=(String)aListComponentTemp.get(ii);
						String loopComp = ccmp.substring(0,ccmp.lastIndexOf(":"));
						String loopType = ccmp.substring(ccmp.lastIndexOf(":")+1);
						if(loopType!=null&& loopType.equalsIgnoreCase(s_compType))
						{
							v_components.add(ccmp);
						}
					}
				}
			}
			rootJson.put("siteCombo",getJSONComboFromList(v_site,"",intlmap));
			String siteComboLabel = intlmap.getTextDescription("reporter.common."+er_option);
			rootJson.put("siteComboLabel",siteComboLabel);
			rootJson.put("selectedSiteCombo",er_site);
		}
		Collections.sort(v_components,String.CASE_INSENSITIVE_ORDER);
		Collections.sort(v_tmp,String.CASE_INSENSITIVE_ORDER);
		Collections.sort(v_temp,String.CASE_INSENSITIVE_ORDER);
		boolean allServerPresent=false;
		Hashtable htComponentcount = new Hashtable();
		Vector vecAll = new Vector(); 
		boolean isVmComp=reportInfo.isVmComponent(s_compType);
		if(aListCompType!=null && aListCompType.size()>0)
		{
			if(aListCompType.size()>1)
			{
				if(rtype !=null && rtype.equalsIgnoreCase("No"))
				{
					if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
					{
						// comp type all not add for application user report
					}
					else
					 aListCompType.add("ALL");
				}
				allServerPresent = true;
			}
		}   
		if(s_compType == null )
		{
			if(aListCompType!=null && aListCompType.size()>0)
			{
				s_compType = (String)aListCompType.get(0);
			}
		}
		Vector v_appgrp =new Vector();
			// karthikeyan 
		boolean wrkGrouper = false;
		if(s_compType!=null && s_compType.length()>0)
		{
			String strTestt = reportInfo.getTestName("CITRIX_USER_REPORT",s_compType,false);
			String strTestName = strTestt;
			strTestt= strTestt+"_DDD";
			EgAgentInfo agentInfo = new EgAgentInfo("manager");
			if(v_components!=null && v_components.size()>0 && strTestName!=null && strTestName.length()>0)
			{
				boolean found = false;
				String showUserWorkGroup = reportInfo.getValue("MISC","ShowUserWorkGroup");
				if(showUserWorkGroup!=""&&"yes".equalsIgnoreCase(showUserWorkGroup))
				{
					for(int aa=0;aa<v_components.size();aa++)
					{
						String strVar =  agentInfo.getValueForVar(strTestName+"::"+v_components.get(aa));
						if(strVar!=null && strVar.length()>0 && strVar.indexOf("Show_worker_groups")>-1)
						{
							int srt=strVar.indexOf("Show_worker_groups");
							int end=strVar.indexOf("-",srt)+1;
							strVar=strVar.substring(srt,end);
							if(strVar!=null && strVar.length()>0)
							{
								strVar=strVar.substring(strVar.indexOf(" "),strVar.indexOf("-"));
								if(strVar!=null && strVar.length()>0)
								{
									strVar=strVar.trim();
									if(strVar.equalsIgnoreCase("true"))
									{
										found=true;
										wrkGrouper = true;
										break;
									}
								}
							}
						}
					}
				}
				if(!found)
					wrkGrouper = false;
			}
			else
				wrkGrouper = false;
		}
		if(s_compType!=null && s_compType.length()>0)
		{
			if(!s_compType.equalsIgnoreCase("ALL"))
			{
				String strTest = reportInfo.getTestName("APPLICATION_REPORT",s_compType,false);
				ArrayList aListGrupNames=null;
				if(wrkGrouper)
				{
					aListGrupNames = erUtils.getAllCtirixWorkGroup(strTest);
				}
				if(aListGrupNames!=null)
					v_appgrp.addAll(aListGrupNames);
			}
			else
			{
				for (int kk=1;kk<aListCompType.size();kk++)
				{
					String strTempCompType = (String) aListCompType.get(kk);
					String strTest = reportInfo.getTestName("APPLICATION_REPORT",strTempCompType,false);
					ArrayList aListGrupNames=null;
					if(wrkGrouper)
					{
						aListGrupNames = erUtils.getAllCtirixWorkGroup(strTest);
					}
					if(aListGrupNames!=null)
						v_appgrp.addAll(aListGrupNames);
				}
			}
		}
		for (int m=0;m<v_appgrp.size();m++)
		{
			String app=(String)v_appgrp.get(m);
			if (!aListworkGrp.contains(app))
				aListworkGrp.add(app);
		}
		Collections.sort(aListworkGrp,String.CASE_INSENSITIVE_ORDER);
		if(aListworkGrp!=null && aListworkGrp.size()>0)
			aListworkGrp.add(0,"Any");
		if(strWorkgrpName == null || strWorkgrpName.equals(""))
		{
			if(aListworkGrp!=null && aListworkGrp.size()>0)
				strWorkgrpName = "Any";
		}
		if(strWorkgrpName != null && !strWorkgrpName.equalsIgnoreCase("Any"))
		{
			ArrayList aListCompGrp = new ArrayList();
			if(!s_compType.equalsIgnoreCase("ALL"))
			{
				String strTest = reportInfo.getTestName("APPLICATION_REPORT",s_compType,false);
				aListCompGrp = erInfo.getServersForWorkGroup(strTest,strWorkgrpName,true);
			}
			else
			{
				for (int kk=1;kk<aListCompType.size();kk++)
				{
					String strTempCompType = (String) aListCompType.get(kk);
					String strTest = reportInfo.getTestName("APPLICATION_REPORT",strTempCompType,false);
					ArrayList aListGrupserver = erInfo.getServersForWorkGroup(strTest,strWorkgrpName,true);
					if(aListGrupserver!=null)
						aListCompGrp.addAll(aListGrupserver);
				}
			}
			if(aListCompGrp!=null && aListCompGrp.size()>0)
			{
				for(int i=0; i<v_components.size(); i++) 
				{
					String loopComponent = (String) v_components.get(i);
					String strComp = loopComponent;
					if(aListCompGrp.contains(strComp))
						v_Workgroupcomponents.add(strComp);
				}
			}
			if(v_Workgroupcomponents!=null && v_Workgroupcomponents.size()==0)
			{
				v_components = new Vector();
			}
		}
		if(selectedCompArrays != null && selectedCompArrays.length>0)
		{
			if(v_Workgroupcomponents!=null && v_Workgroupcomponents.size()>0)
			{
				v_components = new Vector();
				v_components.addAll(v_Workgroupcomponents);
			}
		}
		int v_componentSize = 0;
		if(v_components!=null && v_components.size()>0)
		{
			v_componentSize=v_components.size();
			if(selectedCompArrays == null || selectedCompArrays.length==0)
			{
				selectedCompArrays = (String[])v_components.toArray(new String[v_components.size()]);
			}
		}
		if(v_componentSize>0)
		{
			if(s_server==null)
			{
				s_server=(String)v_components.get(0);
			}
		}
		v_application=new Vector();
		if(selectedCompArrays!=null && selectedCompArrays.length>0)
		{
			Vector v_app=new Vector();
			for(int ii=0;ii<selectedCompArrays.length;ii++)
			{
				String strComp = selectedCompArrays[ii];
				String strTempCompType = strComp;
				String strCompNameTemp = strComp; 
				if(strComp.lastIndexOf(":")>-1)
				{
					strTempCompType = strComp.substring(strComp.lastIndexOf(":")+1);
					strCompNameTemp = strComp.substring(0,strComp.lastIndexOf(":"));
				}
				String strTest = reportInfo.getTestName("APPLICATION_REPORT",strTempCompType,false);
						if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
						{
							strTest = reportInfo.getTestName("APPLICATION_USER_DETAILS",strTempCompType,false);
						}
				ArrayList aListCompGrp =  null;
				if(strWorkgrpName != null && !strWorkgrpName.equalsIgnoreCase("Any"))
				{
					aListCompGrp = erInfo.getApplicationForWorkgroup(strTest,strWorkgrpName,strCompNameTemp);
					if(aListCompGrp!=null)
						v_app.addAll(aListCompGrp);
				}
				else
					v_app.addAll(erInfo.getInfosForTest("NULL",strTest,strComp));
			}
			if(strWorkgrpName == null || strWorkgrpName.equalsIgnoreCase("Any"))
				v_app = ErUtils.formatString(v_app,"$0+$1","$1");
			for (int m=0;m<v_app.size();m++)
			{
				String app=(String)v_app.get(m);
				if (!v_application.contains(app))
				{
					v_application.add(app);
				}
			}
		}
		Collections.sort(v_application,String.CASE_INSENSITIVE_ORDER);
		serverForSorting=s_server;
		for(int m=0;m<subjects.size();m++)
		{
			s_variable = (String)subjects.get(m);
			tok1 = new StringTokenizer(s_variable,":");
			String displayname="";
			String s_test="";
			String s_measure="";
			while(tok1.hasMoreTokens())
			{
				String com=tok1.nextToken();
				if(aListCompType !=null && !aListCompType.contains(com))
					continue;
				if(s_compType!=null && !s_compType.equalsIgnoreCase("ALL") && !s_compType.equalsIgnoreCase(com))
					continue;
				s_test = tok1.nextToken();
				String val2=tok1.nextToken();
				StringTokenizer meas=new StringTokenizer(val2,"#");
				if(meas.hasMoreTokens())
					 mes=meas.nextToken();
				else
					 mes=val2;
				if(meas.hasMoreTokens())
					displayname=meas.nextToken();
				else
					displayname=val2;
				if (!v_testmes.contains(s_test+"/"+mes))
					v_testmes.add(s_test+"/"+mes);
			}
			if(serverForSorting!=null && !serverForSorting.equals("All") && !serverForSorting.equals("-1"))
			{
				if(serverForSorting.indexOf(":")>-1)
				{
					serverForSorting=serverForSorting.substring(serverForSorting.lastIndexOf(":")+1,serverForSorting.length());
				}
				else if(serverForSorting.indexOf("All")>-1 && serverForSorting.indexOf(" ")>-1)
				{
					serverForSorting=serverForSorting.substring(serverForSorting.indexOf("All")+4,serverForSorting.length());
				}
				if(s_variable.indexOf(":")>-1)
				{
					String str_temp=s_variable.substring(0,s_variable.indexOf(":"));
					if(str_temp.equalsIgnoreCase(serverForSorting))
					{
						String st_value=reportInfo.getValue("APPLICATION_REPORT",s_variable);
						StringTokenizer cols=new StringTokenizer(st_value,",");
						while (cols.hasMoreTokens())
						{
							v_sort.add(displayname+"_"+cols.nextToken());
						}
					}
				}
			}
		}
		v_testmes.add("Number of unique users");
		if(testmes == null && v_testmes != null && v_testmes.size() >0)
		{
			testmes = (String)v_testmes.get(0);
		}
		String uiFile = "eg_ui.ini";
		IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
		String currentDateFormat = strUserDateFormat;
		String starttimeformat="";
		String endtimeformat="";
		String dispDate = null;
		String comFormat = null;
		String  s_st_time = request.getParameter("startdate");
		String s_en_time = request.getParameter("enddate");
		String s_st_hr = request.getParameter("starthr");
		String s_en_hr = request.getParameter("endhr");
		String strmin = request.getParameter("startmin");
		String enmin = request.getParameter("endmin");
		String  er_timeline = request.getParameter("er_timeline");
		String start_date = request.getParameter("startdate");
		String end_date = request.getParameter("enddate");

		String  pdfStartDate = s_st_time+" "+s_st_hr+":"+strmin;
		String  pdfEndDate   = s_en_time+" "+s_en_hr+":"+enmin;
		String pdfTime = "From "+pdfStartDate+" hrs "+" "+" To "+pdfEndDate+" hrs";

		Vector applnPdfData = new Vector();
		applnPdfData = (Vector)request.getAttribute("applnPdfData");
		pdfTime = reportType+pdfTime;
		if(applnPdfData!=null && !applnPdfData.isEmpty())
		{
			Vector forTime = (Vector)applnPdfData.get(1);
			forTime.removeElementAt(0);
			forTime.insertElementAt(pdfTime,0);
			applnPdfData.removeElementAt(1);
			applnPdfData.insertElementAt(forTime,1);
		}
		if(er_timeline==null  || er_timeline.equals(" "))
		{
			er_timeline="1 day";
		}
		//Date calculation according to time select
		String[] options = {"Any","1 hour", "3 hours", "6 hours", "9 hours", "12 hours", "15 hours", "18 hours", "21 hours","1 day", "2 days", "3 days", "4 days", "5 days", "6 days","1 week","2 weeks","3 weeks","4 weeks","1 month","2 months","3 months"};
		String startDateTime="";
		String endDateTime="";
		if(er_timeline!=null&&!er_timeline.equals("Any"))
		{
			int blankSpaceIndex = er_timeline.indexOf(DateTimeTokenizer.BLANK_SPACE);
			if (blankSpaceIndex > 0)
			{
				SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
				java.util.Date today =egDt.egetRealDate();
				endDateTime = sdf.format(today);
				long value = Integer.parseInt(er_timeline.substring(0, blankSpaceIndex));
				String unit = er_timeline.substring(blankSpaceIndex+1).toLowerCase();
				if (unit.startsWith("h"))
				{//hours
					value *= 3600;
				}
				else if (unit.startsWith("d"))
				{//days
					value *= (24 * 3600);
				}
				else if (unit.startsWith("w"))
				{
					if(unit.endsWith("last"))
					{
						//last week
						int weekCount = (int) value;
						String currentDateTime = endDateTime;
						String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
						String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
						String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.length());
						String userFormat = this_user.getUserDateFormat();
						String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy",userFormat);						
						EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin, this_user);
						java.text.SimpleDateFormat userSDF = new java.text.SimpleDateFormat(userFormat);
						java.util.Date realDate = null;
						try{
							realDate = userSDF.parse((String) realDateTime.getDate(false));
						}catch(Exception e){
							e.printStackTrace();
						}
						Calendar c = Calendar.getInstance();
						c.setTime(realDate);
						int i = c.get(Calendar.DAY_OF_WEEK) - c.getFirstDayOfWeek() * weekCount;
						int startDayCount = 7 * weekCount + (1 * (weekCount - 1));
						int lastDayCount = 6 * weekCount + (1 * (weekCount - 1));
						c.add(Calendar.DATE, - i - startDayCount);	
						java.util.Date start = c.getTime();
						startDateTime = userSDF.format(start);
						c.add(Calendar.DATE, lastDayCount);	
						java.util.Date end = c.getTime();
						endDateTime = userSDF.format(end);
						EgTimeZoneConverter timeZoneConverterStartM = new EgTimeZoneConverter(startDateTime+" 00:00:00",this_user,true);
						EgTimeZoneConverter timeZoneConverterEndM = new EgTimeZoneConverter(endDateTime+" 23:59:59",this_user,true);
						String curStartTimeM  = DateUtil.changeDateFormat((String) timeZoneConverterStartM.getDate(false),userFormat,"MM/dd/yyyy");
						String curEndTimeM = DateUtil.changeDateFormat((String) timeZoneConverterEndM.getDate(false),userFormat,"MM/dd/yyyy");
						startDateTime = curStartTimeM + " " + timeZoneConverterStartM.getHour() + ":" + timeZoneConverterStartM.getMinute()+ ":" + timeZoneConverterStartM.getSecond();
						endDateTime = curEndTimeM + " " + timeZoneConverterEndM.getHour() + ":" + timeZoneConverterEndM.getMinute()+ ":" + timeZoneConverterEndM.getSecond();
					}
					else
					{
						//weeks
						value *= (7 * 24 * 3600);
					}
				}
				else if (unit.startsWith("mo"))
				{
					if(unit.endsWith("last"))
					{
						//last month
						int monthCount = (int) value;						
						String currentDateTime = endDateTime;
						String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
						String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
						String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.length());
						String userFormat = this_user.getUserDateFormat();
						String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy",userFormat); 
						EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin, this_user);
						java.text.SimpleDateFormat userSDF = new java.text.SimpleDateFormat(userFormat);
						java.util.Date realDate = null;
						try{
							realDate = userSDF.parse((String) realDateTime.getDate(false));
						}catch(Exception e){
							e.printStackTrace();
						}
						Calendar c = Calendar.getInstance();
						c.setTime(realDate);
						c.add(Calendar.MONTH, -monthCount);
						c.set(Calendar.DATE, 1);
						java.util.Date start = c.getTime();
						startDateTime = userSDF.format(start);
						Calendar c1 = Calendar.getInstance();
						c1.setTime(realDate);
						c1.add(Calendar.MONTH, -1);
						c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
						java.util.Date end = c1.getTime();
						endDateTime = userSDF.format(end);
						EgTimeZoneConverter timeZoneConverterStartM = new EgTimeZoneConverter(startDateTime+" 00:00:00",this_user,true);
						EgTimeZoneConverter timeZoneConverterEndM = new EgTimeZoneConverter(endDateTime+" 23:59:59",this_user,true);
						String curStartTimeM  = DateUtil.changeDateFormat((String) timeZoneConverterStartM.getDate(false),userFormat,"MM/dd/yyyy");
						String curEndTimeM = DateUtil.changeDateFormat((String) timeZoneConverterEndM.getDate(false),userFormat,"MM/dd/yyyy");
						startDateTime = curStartTimeM + " " + timeZoneConverterStartM.getHour() + ":" + timeZoneConverterStartM.getMinute()+ ":" + timeZoneConverterStartM.getSecond();
						endDateTime = curEndTimeM + " " + timeZoneConverterEndM.getHour() + ":" + timeZoneConverterEndM.getMinute()+ ":" + timeZoneConverterEndM.getSecond();
					}
					else
					{
						//months
						java.util.Date dt_temp = new java.util.Date(egDt.egetUTCDate());
						Calendar cal_temp = new GregorianCalendar();
						cal_temp.setTime(dt_temp);
						//cal_temp.add(Calendar.DATE,-1);
						cal_temp.add(Calendar.HOUR_OF_DAY,0);
						java.util.Date dt_temp1 = cal_temp.getTime();
						long l_temp = dt_temp1.getTime();
						int  totalDays=24*(ErUtils.getMaxDaysInMonth());
						startDateTime = egDt.egetDate(l_temp -(long)( (value*totalDays * msecsPerHour)));
						startDateTime = DateUtil.changeDateFormat(startDateTime,
						"dd/MM/yyyy HH:mm","MM/dd/yyyy HH:mm");
					}
				}
				if (unit!=null&&!unit.startsWith("mo"))
				{
					java.util.Date start = egDt.egetRealDate();
					start.setTime(today.getTime() - (value * 1000));
					startDateTime = sdf.format(start);
				}
			}
			if ((startDateTime != null) && (endDateTime != null))
			{
				int shr = Integer.parseInt(startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, startDateTime.indexOf(":")));
				strmin=startDateTime.substring(startDateTime.indexOf(":")+1);
				int en_hr = Integer.parseInt(endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, endDateTime.indexOf(":")));
				enmin=endDateTime.substring(endDateTime.indexOf(":")+1);
				s_en_time=endDateTime.substring(0, endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
				s_st_time=startDateTime.substring(0, startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
				s_st_hr = String.valueOf(shr);
				s_en_hr = String.valueOf(en_hr);
			}
		}
		String disable="";
		if(er_timeline!=null&&!er_timeline.equals("Any"))
		{
			disable ="disabled";
		}
		if(er_timeline!=null&&er_timeline.equals("Any"))
		{
			String StrDate="";
			try
			{
				java.text.SimpleDateFormat df=new java.text.SimpleDateFormat("MM/dd/yyyy k 'at' hh:mm");
				StrDate =df.format(egDt.egetRealDate());
			}
			catch(Exception ee)
			{
				//System.out.println("Exception is"+ee);
			}
			String SDate =StrDate.substring(0,StrDate.indexOf(" "));
			String shour =StrDate.substring(StrDate.indexOf(" "),StrDate.lastIndexOf(""));
			shour = shour.substring(0,3);
			if(s_st_time==null)
			{
				s_st_time=SDate;
			}
			if(s_en_time==null)
			{
				s_en_time=SDate;
			}
			if(s_st_hr==null)
			{
				shour =shour.trim();
				int starthr = Integer.parseInt(shour);
				starthr = starthr-1;
				s_st_hr=String.valueOf(starthr);
			}
			if(s_en_hr==null)
			{
				shour =shour.trim();
				s_en_hr =shour;
			}
		}
		String excludeweekend=request.getParameter("er_excwe");
		if (excludeweekend==null ||	excludeweekend.equals(""))
			excludeweekend="No";

		hiddenfieldsJson.put("option","Citrix");
		hiddenfieldsJson.put("inidate",currentDateFormat);
		hiddenfieldsJson.put("currTime","");
		hiddenfieldsJson.put("er_rtype","CtxApplication");
		hiddenfieldsJson.put("er_trgttype",reportType);
		hiddenfieldsJson.put("er_gtype","Citrix");
		hiddenfieldsJson.put("pdfTime",pdfTime);
		hiddenfieldsJson.put("uid",EgURLEncoder.encode(loginid,"UTF-8"));
		hiddenfieldsJson.put("userID",EgURLEncoder.encode(loginid,"UTF-8"));
		hiddenfieldsJson.put("er_trenddata","No");
		if(request.getParameter("servers")!=null)
			hiddenfieldsJson.put("servers",request.getParameter("servers"));
		else
			hiddenfieldsJson.put("servers","null");
		if(request.getParameter("er_check")!=null)
			hiddenfieldsJson.put("er_check",request.getParameter("er_check"));
		else
			hiddenfieldsJson.put("er_check","null");
		if(request.getParameter("er_application1")!=null)
			hiddenfieldsJson.put("er_application1",request.getParameter("er_application1"));
		else
			hiddenfieldsJson.put("er_application1","null");
		if(reqFromSchedule!=null)
			hiddenfieldsJson.put("fromSchedule",reqFromSchedule);
		else
			hiddenfieldsJson.put("fromSchedule","null");
		if(reqFromSchedule!=null)
			hiddenfieldsJson.put("fromScheduleModify",reqFromScheduleModify);
		else
			hiddenfieldsJson.put("fromScheduleModify","null");

		if(schedule_id!=null)
			hiddenfieldsJson.put("schedule_id",schedule_id);
		else
			hiddenfieldsJson.put("schedule_id","null");
		if(fromFavoriteModify!=null)
			hiddenfieldsJson.put("fromFavoriteModify",fromFavoriteModify);
		else
			hiddenfieldsJson.put("fromFavoriteModify","null");
			hiddenfieldsJson.put("favorite_id", favorite_id);
			hiddenfieldsJson.put("er_favorite", er_favorite);

		hiddenfieldsJson.put("er_ViewName","ErThinClientApplication.jsp");
		hiddenfieldsJson.put("getMaxDaysInMonth",String.valueOf(ErUtils.getMaxDaysInMonth()));
		hiddenfieldsJson.put("forwardto","ErCtxApplicationReportJson");
		hiddenfieldsJson.put("er_bgreportfrom",backGroundReportType);
		hiddenfieldsJson.put("bgenabled",strbgrepportName);
		hiddenfieldsJson.put("limitforbg",limitforbg);
		hiddenfieldsJson.put("savereport","save");
		hiddenfieldsJson.put("servletName","com.eg.ErCtxServerReportC");

		String isSubmitted =request.getParameter("isSubmit");
		rootJson.put("isSubmit",isSubmitted);
		String showtopuser = request.getParameter("showTopusers");
		if(showtopuser!=null)
			rootJson.put("showTopusers",showtopuser);
		else
			rootJson.put("showTopusers","null");

		rootJson.put("reportTitle",intlmap.getTextDescription("reporter.thin.THIN CLIENT REPORTS")+" - "+intlmap.getTextDescription("reporter.thin.APPLICATION ACTIVITY"));
		if(rtype!=null&&rtype.equals("Yes"))
		{
			hiddenfieldsJson.put("opt","chart");
		}
		else
		{
			hiddenfieldsJson.put("opt","data");
		}
		String strwidth = "90%";
		if(backreqMap == null || backreqMap != null && backreqMap.size() == 0)
			strwidth="100%";
		String fromFavSch = request.getParameter("fromFavSch");
		if(backreqMap != null && backreqMap.size() > 0 &&  enableBack && request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true") && (fromFavSch!=null && fromFavSch.equalsIgnoreCase("true")))
		{
			rootJson.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
		}
		if (!StringUtils.isNull(titleToDisplay))
		{ 
			lst.add(titleToDisplay);
		}
		else
		{
			lst.add(intlmap.getTextDescription("reporter.thin.THIN CLIENT REPORTS")+" - "+intlmap.getTextDescription("reporter.common.APPLICATION ACTIVITY"));
		}
		if (dispzone != null)
			Collections.sort(dispzone,String.CASE_INSENSITIVE_ORDER);

		screenLabelJson.put("reporter.consolidated.Zone",intlmap.getTextDescription("reporter.consolidated.Zone"));
		JSONArray zoneArray = new JSONArray();
		if(rtype == null || (rtype!=null && rtype.equals("No")))
		{
			if((s_farmserver!=null && !s_farmserver.equals("-1"))|| (dispzone != null && !dispzone.isEmpty()))
			{
				loopJsonObj = new JSONObject();
				zoneArray.add(loopJsonObj);
			}
			else
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField", "-1");
				zoneArray.add(loopJsonObj);
			}
			if (dispzone != null && dispzone.size()>0 )
			{
				for(int n=0;n<dispzone.size();n++)
				{
					String s=(String)dispzone.get(n);
					String strZone=s;
					if(strZone!=null && strZone.equalsIgnoreCase("--Default--"))
					{
						strZone = intlmap.getTextDescription("reporter.common.--Default--");
					}
					loopJsonObj = new JSONObject();
					//loopJsonObj.put("displayField",s);
					loopJsonObj.put("displayField",strZone);
					loopJsonObj.put("valueField",s);
					zoneArray.add(loopJsonObj);
					if(s_farmserver!=null && s_farmserver.equalsIgnoreCase(s))
					{
						rootJson.put("selectedZone",s_farmserver);
					}                       
				}
			}
			else
			{
				if(zoneArray!=null && zoneArray.size()==0)
				{
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
					loopJsonObj.put("valueField", "-1");
					zoneArray.add(loopJsonObj);
				}
			}
			rootJson.put("zoneCombo",zoneArray);
		}
		else
		{
			if((s_farmserver!=null && !s_farmserver.equals("-1") )|| (dispzone != null && !dispzone.isEmpty()))
			{
				loopJsonObj = new JSONObject();
				zoneArray.add(loopJsonObj);
			}
			else
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField", "-1");
				zoneArray.add(loopJsonObj);
			}
			if (dispzone != null && dispzone.size()>0 )
			{
				for(int n=0;n<dispzone.size();n++)
				{
					String s=(String)dispzone.get(n);
					String strZone=s;
					if(strZone!=null && strZone.equalsIgnoreCase("--Default--"))
					{
						strZone = intlmap.getTextDescription("reporter.common.--Default--");
					}
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",strZone);
					loopJsonObj.put("valueField",s);
					zoneArray.add(loopJsonObj);
					if(s_farmserver!=null && s_farmserver.equalsIgnoreCase(s))
					{
						rootJson.put("selectedZone",s_farmserver);
					}
				}
			}
			else
			{
				if(zoneArray!=null && zoneArray.size()==0)
				{
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
					loopJsonObj.put("valueField", "-1");
					zoneArray.add(loopJsonObj);
				}
			}
			rootJson.put("zoneCombo",zoneArray);
		}
		//added for component type
		screenLabelJson.put("reporter.common.Component Type",intlmap.getTextDescription("reporter.common.Component Type"));
		JSONObject componentTypeComboObject;
		JSONArray  componentTypeComboArray=new JSONArray();
		if(s_compType!=null)
		{
			if(s_compType.equalsIgnoreCase("all") && rtype!=null && rtype.equalsIgnoreCase("yes"))
			{
				s_compType="";
			}
			rootJson.put("selectedComponentType",s_compType); 
		}
		if(aListCompType!=null && aListCompType.size()>0)
		{
			componentTypeComboObject=new JSONObject();
			for(int n=0;n<aListCompType.size();n++)
			{
				String sCompType = (String)aListCompType.get(n);
				componentTypeComboObject=new JSONObject();
				componentTypeComboObject.put("displayField",intlmap.getComponentTypeDescription(sCompType));
				componentTypeComboObject.put("valueField",sCompType);
				componentTypeComboArray.add(componentTypeComboObject);
			}
		}
		else
		{
			componentTypeComboObject=new JSONObject();
			componentTypeComboObject.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			componentTypeComboObject.put("valueField","-1");
			componentTypeComboArray.add(componentTypeComboObject);
		}
		rootJson.put("componentTypeCombo",componentTypeComboArray);
	if(isNeedGeo!=null && isNeedGeo.equalsIgnoreCase("yes"))
	{
		String[] filterValue = request.getParameterValues("filterValue");
		if(filterValue==null || filterValue.length==0)
		{
			filterValue = new String[]{"all"};
		}
		List filterValLst = Arrays.asList(filterValue);
		String screachStr = reportInfo.getValue("APPLICATION_REPORT","searchBasedOn");
		ErGeoDetailsBean geoBean = new ErGeoDetailsBean();
		ArrayList filterList = geoBean.getList(screachStr);
		JSONArray filterAry = new JSONArray();
		if(filterList!=null && filterList.size()>0)
		{
			filterList.add(0,"all");
			for(int i=0;i<filterList.size();i++)
			{
				String tempStr = (String)filterList.get(i);
				loopJsonObj = new JSONObject();
				if(tempStr.equalsIgnoreCase("all"))
				{
					loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.All")+" "+intlmap.getTextDescription("reporter.common."+screachStr));
				}
				else
				{
					loopJsonObj.put("displayField",tempStr);
				}
				loopJsonObj.put("valueField", tempStr);
				filterAry.add(loopJsonObj);
			}
		}
		rootJson.put("geoFilterCombo",filterAry);
		rootJson.put("selectedgeoFilter",filterValLst);
		screenLabelJson.put("geoFilterLabel",intlmap.getTextDescription("reporter.common.Search by")+" "+intlmap.getTextDescription("reporter.common."+screachStr));
	}
		//added for worker group
		screenLabelJson.put("reporter.thin.Worker Group",intlmap.getTextDescription("reporter.thin.Worker Group"));
		if(rtype == null || (rtype!=null && rtype.equals("No")))
		{
			if(aListworkGrp!=null && aListworkGrp.size()>0 )
			{
				JSONObject workGroupObj;
				JSONArray  workGroupArray=new JSONArray();	
				for(int n=0;n<aListworkGrp.size();n++)
				{
					String sCompType = (String)aListworkGrp.get(n);
					workGroupObj = new JSONObject();
					workGroupObj.put("displayField",sCompType);
					workGroupObj.put("valueField",sCompType);
					workGroupArray.add(workGroupObj);
					if(strWorkgrpName!=null && strWorkgrpName.equals(sCompType))
					{
						rootJson.put("selectedWorkergroup",sCompType);
					}
				}
				rootJson.put("workerGroupCombo",workGroupArray);
			}
			screenLabelJson.put("reporter.common.Server",intlmap.getTextDescription("reporter.common.Components"));
			JSONArray serverArray =  new JSONArray();
			JSONArray selectedServerArray =  new JSONArray();
			if(s_compType==null || s_compType.equals("-1"))
				v_components=new Vector();
			if(v_components !=null && !v_components.isEmpty())
			{
				ArrayList aListSelectedList = new ArrayList();
				if(selectedCompArrays!=null && selectedCompArrays.length>0)
					aListSelectedList.addAll(Arrays.asList(selectedCompArrays));
				for(int n=0;n<v_components.size();n++)
				{
					String s=(String)v_components.get(n);
					String s1 = s;
					if(s1.indexOf(":NULL")>-1)
						s1 = s1.substring(0,s1.indexOf(":NULL"))+s1.substring(s1.indexOf(":NULL")+5);
					String strDipServer = s1;
					if(s.indexOf(":")>-1)
					{
						String strTemp="";
						String strTemp1="";
						if(s.indexOf(":")>-1)
						{
							if(s1.indexOf(":")>-1)
							{
								strTemp = s1.substring(0,s1.lastIndexOf(":"));
							}
							else
							{
								strTemp = s1;
							}
							strTemp1 = s.substring(s.lastIndexOf(":")+1);
						}
						if(s_compType!=null && s_compType.equalsIgnoreCase("ALL"))
							strDipServer = strTemp;
						else
							strDipServer = strTemp;
					}
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",strDipServer);
					loopJsonObj.put("valueField",s);
					serverArray.add(loopJsonObj);
					if(aListSelectedList!=null && aListSelectedList.contains(s))
					{
						selectedServerArray.add(s);
					}
					else
					{
						if(s_compType!=null && s_compType.equalsIgnoreCase("ALL"))
						{
							selectedServerArray.add(s);
						}
					}
				}
				rootJson.put("selectedServer",selectedServerArray);
			}
			else
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField", "-1");
				serverArray.add(loopJsonObj);
			}
			rootJson.put("serverCombo",serverArray);
		}
		else
		{
			screenLabelJson.put("reporter.thin.Worker Group",intlmap.getTextDescription("reporter.thin.Worker Group"));
			if(aListworkGrp!=null && aListworkGrp.size()>0 )
			{
				JSONObject workGroupObj;
				JSONArray  workGroupArray=new JSONArray();	
				for(int n=0;n<aListworkGrp.size();n++)
				{
					String sCompType = (String)aListworkGrp.get(n);
					workGroupObj = new JSONObject();
					workGroupObj.put("displayField",sCompType);
					workGroupObj.put("valueField",sCompType);
					workGroupArray.add(workGroupObj);
					if(strWorkgrpName!=null && strWorkgrpName.equals(sCompType))
					{
						rootJson.put("selectedWorkergroup",sCompType);
					}
				}
				rootJson.put("workerGroupCombo",workGroupArray);
			}
		}
		screenLabelJson.put("reporter.thin.Report Type",intlmap.getTextDescription("reporter.thin.Report Type"));
		JSONArray reporttypeArray =  new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.thin.Graph"));
		loopJsonObj.put("valueField", "Yes");
		reporttypeArray.add(loopJsonObj);
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.thin.Data"));
		loopJsonObj.put("valueField", "No");
		reporttypeArray.add(loopJsonObj);	

		rootJson.put("reportTypeCombo",reporttypeArray);
		rootJson.put("selectedreportType",rtype);
		//
		ArrayList er_excludeAppList=null;
		String desktopOSProcesses=null;
		IniFile testIniFile = new IniFile(installDir +"/manager/config/eg_tests.ini");
		desktopOSProcesses = testIniFile.getValue("EXCLUDE_APPLICATIONS","DesktopOSProcesses");
		if(desktopOSProcesses != null && desktopOSProcesses.length()>0)
		{
			er_excludeAppList=new ArrayList(Arrays.asList(desktopOSProcesses.split(",")));
		}
		String er_excludeApp=request.getParameter("er_excludeApp");
	//	System.out.println("er_excludeApp----->>>>>"+er_excludeApp);
		ArrayList excludeAppList=er_excludeAppList;
		if(er_excludeApp != null && er_excludeApp.indexOf("All") == -1){
			excludeAppList=ErUtils.egTokenizer(er_excludeApp, ",");
		}
	//	System.out.println("excludeAppList----->>>>>"+excludeAppList);
		//
		if(rtype == null || (rtype!=null && rtype.equals("No")))
		{
			JSONArray applnArray = new JSONArray();
			screenLabelJson.put("reporter.thin.Application",intlmap.getTextDescription("reporter.thin.Application"));
			if(s_application==null || s_application.equals("-1"))
			{
				rootJson.put("selectedAppln","-1");
			}
			if(v_application!=null && v_application.size()>0)
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.All Applications"));
				loopJsonObj.put("valueField", "-1");
				applnArray.add(loopJsonObj);
				JSONArray selectedApplnArray =  new JSONArray();
				for(int n=0;n<v_application.size();n++)
				{
					String s=(String)v_application.get(n);
					String applnName="";
					if(s != null && s.endsWith(".exe"))
						applnName=s.substring(0,s.lastIndexOf(".exe"));
					if(excludeAppList != null && excludeAppList.contains(applnName))
						continue;
					loopJsonObj = new JSONObject();
					if(s.endsWith(".exe"))
					{
						loopJsonObj.put("displayField",s.substring(0,s.lastIndexOf(".exe")));
					}
					else
					{
						loopJsonObj.put("displayField",s);
					}
					loopJsonObj.put("valueField",s);
					applnArray.add(loopJsonObj);

					if(aListselectedAppln!=null && aListselectedAppln.contains(s))
					{
						selectedApplnArray.add(s);
					}                               
				}
				if(aListselectedAppln == null || aListselectedAppln.size() == 0 || aListselectedAppln.contains("-1"))
				{
					rootJson.put("selectedAppln","-1");
				}else
				{
					rootJson.put("selectedAppln",selectedApplnArray);
				}
			}
			else
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField", "-1");
				applnArray.add(loopJsonObj);
			}
			rootJson.put("applnCombo",applnArray);
		}
		else if(rtype!=null && rtype.equals("Yes"))
		{
			screenLabelJson.put("reporter.thin.Criteria",intlmap.getTextDescription("reporter.thin.Criteria"));
			JSONArray measureArray = new JSONArray();
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Please choose a Criteria"));
			loopJsonObj.put("valueField", "-1");
			measureArray.add(loopJsonObj);
			rootJson.put("selectedMeasure",testmes);
			
			for(int n=0;n<v_testmes.size();n++)
			{
				String s=(String)v_testmes.get(n);
				if(s.indexOf("/")>-1)
				{
					String testdisp=s.substring(0,s.indexOf("/"));
					String mesdisp =s.substring(s.indexOf("/")+1);
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",intlmap.getMeasureDescription(testdisp,mesdisp));
					loopJsonObj.put("valueField",s);
					measureArray.add(loopJsonObj);
				}
				else
				{
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",intlmap.getTestDescription("reporter.common."+s));
					loopJsonObj.put("valueField",s);
					measureArray.add(loopJsonObj);
				}
			}
			if(aListCompType==null || aListCompType.size()==0)
			{
				measureArray = new JSONArray();
				loopJsonObj=new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField","-1");
				measureArray.add(loopJsonObj);
				rootJson.put("selectedMeasure","-1");
			}
			rootJson.put("measureCombo",measureArray);
		}
		screenLabelJson.put("reporter.common.Time period", intlmap.getTextDescription("reporter.common.Time period"));
		screenLabelJson.put("reporter.common.Hrs", intlmap.getTextDescription("reporter.common.Hrs"));
		screenLabelJson.put("reporter.common.Mins", intlmap.getTextDescription("reporter.common.Mins"));
		rootJson.put("selectedTimeFrom",Hourfrom);
		rootJson.put("selectedMinsFrom",Minfrom);
		rootJson.put("selectedTimeTo",Hourto);
		rootJson.put("selectedMinsTo",Minto);

		screenLabelJson.put("reporter.common.Exclude weekends",intlmap.getTextDescription("reporter.common.Exclude weekends"));
	screenLabelJson.put("reporter.common.Exclude Applications",intlmap.getTextDescription("reporter.common.Exclude Applications"));
		JSONArray exclweekArray  =  new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Yes")+" ("+Days+") ");
		loopJsonObj.put("valueField", "Yes");
		exclweekArray.add(loopJsonObj);
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.No"));
		loopJsonObj.put("valueField", "No");
		exclweekArray.add(loopJsonObj);
		rootJson.put("excludeWeekCombo",exclweekArray);
		rootJson.put("excludeWeek",excludeweekend);
		screenLabelJson.put("MappedExcludeDays", intlmap.getTextDescription("reporter.common.Excludes")+" "+Days);
		screenLabelJson.put("reporter.comparison.Weighted Average",intlmap.getTextDescription("reporter.comparison.Weighted Average"));
		//..for exclude Application
	/*	ArrayList er_excludeAppList=null;
		String desktopOSProcesses=null;
		IniFile testIniFile = new IniFile(installDir +"/manager/config/eg_tests.ini");
		desktopOSProcesses = testIniFile.getValue("EXCLUDE_APPLICATIONS","DesktopOSProcesses");
		if(desktopOSProcesses != null && desktopOSProcesses.length()>0)
		{
			er_excludeAppList=new ArrayList(Arrays.asList(desktopOSProcesses.split(",")));
		}
		String er_excludeApp=request.getParameter("er_excludeApp");
	*/	
		screenLabelJson.put("reporter.thin.Exclude Applications",intlmap.getTextDescription("reporter.thin.Exclude Applications"));
		JSONArray excludeAppArry=new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.thin.All"));
		loopJsonObj.put("valueField","all");
		excludeAppArry.add(loopJsonObj);
		String showProcessDescription=testIniFile.getValue("AGENT_SETTINGS","ShowProcessDescription");
		if(er_excludeAppList != null)
		{
			for(int i=0;i<er_excludeAppList.size();i++)
			{
				loopJsonObj = new JSONObject();
				String eachApp=(String)er_excludeAppList.get(i);
				if(showProcessDescription != null && "yes".equalsIgnoreCase(showProcessDescription)){
					String newProcessName=testIniFile.getValue("PROCESS_DESCRIPTIONS",eachApp);
					if(newProcessName != null && newProcessName.trim().length() > 0){
						eachApp = newProcessName;
					}
				}
				loopJsonObj.put("displayField",eachApp);
				loopJsonObj.put("valueField",eachApp);
				excludeAppArry.add(loopJsonObj);
			}
		}
		//
		Collections.sort( excludeAppArry, new Comparator() {
			public int compare(Object valueOneObj, Object valueTwoObj) {
			   String valueOneString="";
			   String valueTwoString="";
				String KEY_NAME = "displayField";
				try {
					JSONObject obj1 = (JSONObject)valueOneObj;
					JSONObject obj2 = (JSONObject)valueTwoObj;
					valueOneString = (String) obj1.get(KEY_NAME);
					valueTwoString = (String)obj2.get(KEY_NAME);
				} 
				catch (Exception e) {
					e.printStackTrace();
				}
				if("All".equalsIgnoreCase(valueOneString)){
					return -1;
				}
				return valueOneString.compareTo(valueTwoString);
			}
		});
		rootJson.put("excludeAppArry",excludeAppArry);
		if(er_excludeApp == null && excludeAppArry.size() > 0)
		{
			er_excludeApp="all";
		}
		rootJson.put("selectedExcludeApp",er_excludeApp);
		//..
		JSONArray weightedArray =  new JSONArray();

		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Yes"));
		loopJsonObj.put("valueField", "Yes");
		weightedArray.add(loopJsonObj);

		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.No"));
		loopJsonObj.put("valueField", "No");
		weightedArray.add(loopJsonObj);	

		rootJson.put("weightedAvgCombo",weightedArray);

		//screenLabelJson.put("reporter.thin.Aggregate based on",intlmap.getTextDescription("reporter.thin.Aggregate based on"));
		screenLabelJson.put("reporter.thin.Aggregate across servers",intlmap.getTextDescription("reporter.thin.Aggregate across servers"));
		JSONArray aggbasedon  =  new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.thin.Yes"));
		loopJsonObj.put("valueField", "Yes");
		aggbasedon.add(loopJsonObj);
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.thin.No"));
		loopJsonObj.put("valueField", "No");
		aggbasedon.add(loopJsonObj);
		rootJson.put("aggbasedOn",aggbasedon);
		rootJson.put("selectedAgg",s_perserver);
		if(excludeweekend.equalsIgnoreCase("Yes"))
		{
			lst.add('"'+intlmap.getTextDescription("reporter.common.Time period")+":"+intlmap.getTextDescription("reporter.common.From")+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+intlmap.getTextDescription("reporter.common.To")+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs")+'"'+","+'"'+
			intlmap.getTextDescription("reporter.common.Exclude weekends")+":"+Days+'"');
		}
		else
		{
			lst.add(intlmap.getTextDescription("reporter.common.Time period")+":"+intlmap.getTextDescription("reporter.common.From")+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+intlmap.getTextDescription("reporter.common.To")+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs"));
		}
		String select_yes = "";
		String select_no = "";
		if(show_timeinuse != null && show_timeinuse.equalsIgnoreCase("Yes"))
		{
			select_yes = "checked";
			select_no="";
			rootJson.put("weightedAvg","Yes");
		}
		else
		{
			select_yes="";
			select_no = "checked";
			rootJson.put("weightedAvg","No");
		}
		if(rtype == null || (rtype!=null && rtype.equals("No")))
		{
			if (v_sort.isEmpty()){}
			else
			{
				for (int i =0;i<v_sort.size();i++)
				{
					String strsort=String.valueOf(i+1);
				}
			}
		}
%>
<%@  include file ="ErTimeFormatJSON.jsp"%>
<%
		String sdate = request.getParameter("startdate");
		String edate = request.getParameter("enddate");
		String shr = request.getParameter("starthr");
		String ehr = request.getParameter("endhr");
		String smin = request.getParameter("startmin");
		String emin = request.getParameter("endmin");
		starttimeformat = sdate+ " " +shr+":"+smin+" "+"Hrs ";
		endtimeformat   = edate+ " " +ehr+":"+emin+" Hrs ";
		pdfStartDate = startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
		pdfEndDate = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;
		Vector dvec = new Vector();
		String stimefmt = "Start Date : "+pdfStartDate;
		String etimefmt = "End Date : "+pdfEndDate;
		dvec.add('"'+stimefmt+'"');
		dvec.add('"'+etimefmt+'"');
		lst.add(dvec);
		hiddenfieldsJson.put("userTimeline",strUsrTimeline);
		screenLabelJson.put("reporter.common.Timeline", intlmap.getTextDescription("reporter.common.Timeline"));
		screenLabelJson.put("reporter.common.From", intlmap.getTextDescription("reporter.common.From"));
		screenLabelJson.put("reporter.common.To", intlmap.getTextDescription("reporter.common.To"));
		screenLabelJson.put("reporter.common.Hr", intlmap.getTextDescription("reporter.common.Hr"));
		screenLabelJson.put("reporter.common.Graph", intlmap.getTextDescription("reporter.common.Graph"));

		rootJson.put("timelineCombo",timelineComboArray);
		rootJson.put("selectedTimeline",er_timeline);
		rootJson.put("startDate",startDateJSON);
		rootJson.put("endDate",endDateJSON);
		rootJson.put("startHour",startHourJSON);
		rootJson.put("endHour",endHourJSON);
		rootJson.put("startmin",startMin);
		rootJson.put("endmin",endMin);
		rootJson.put("selectedGraphMode",selectedGraphMode);

		//User TimeZone changes
		rootJson.put("startDateForDisplay",startDateForDisplay);
		rootJson.put("startHourForDisplay",startHourForDisplay);
		rootJson.put("startMinForDisplay",startMinForDisplay);
		rootJson.put("endDateForDisplay",endDateForDisplay);
		rootJson.put("endHourForDisplay",endHourForDisplay);
		rootJson.put("endMinForDisplay",endMinForDisplay);

		screenLabelJson.put("reporter.common.Report Generation", intlmap.getTextDescription("reporter.common.Report Generation"));
		screenLabelJson.put("reporter.common.SUBMIT", intlmap.getTextDescription("reporter.common.SUBMIT"));
		screenLabelJson.put("reporter.common.Report Name", intlmap.getTextDescription("reporter.common.Report Name"));
		JSONArray reportGenerationComboArray =  new JSONArray();
		JSONObject tmpobj=new JSONObject();
		tmpobj.put("displayField", strbackground);
		tmpobj.put("valueField", "background");
		reportGenerationComboArray.add(tmpobj);
		if(rtype!=null && rtype.equals("No"))
		{
			tmpobj=new JSONObject();
			tmpobj.put("displayField", intlmap.getTextDescription("reporter.thin.Background Save - CSV"));
			tmpobj.put("valueField", "background-csv");
			reportGenerationComboArray.add(tmpobj);
		}
		tmpobj=new JSONObject();
		tmpobj.put("displayField", strforeground);
		tmpobj.put("valueField", "foreground");
		reportGenerationComboArray.add(tmpobj);
		rootJson.put("reportGenerationCombo",reportGenerationComboArray);

		screenLabelJson.put("reporter.common.View Application", intlmap.getTextDescription("reporter.common.View Application"));
		JSONArray viewApplnCombo =  new JSONArray();
		tmpobj=new JSONObject();
		tmpobj.put("displayField", intlmap.getTextDescription("reporter.common.Application Activity"));
		tmpobj.put("valueField", "application_activity");
		viewApplnCombo.add(tmpobj);
		tmpobj=new JSONObject();
		tmpobj.put("displayField", intlmap.getTextDescription("reporter.common.Application Usage"));
		tmpobj.put("valueField", "application_usage");
		viewApplnCombo.add(tmpobj);
		rootJson.put("viewApplnCombo",viewApplnCombo);
		rootJson.put("selectedViewAppln","application_activity");

		String er_reportgenration = request.getParameter("er_reportgenration");
		String er_background ="";
		String er_foreground ="";
		if (er_reportgenration != null && er_reportgenration.equals("background"))
		{
			er_background = "selected";
			er_foreground = "";
			rootJson.put("reportGeneration","background");
		}
		else if (er_reportgenration != null && er_reportgenration.equals("background-csv"))
		{
			er_background = "selected";
			er_foreground = "";
			rootJson.put("reportGeneration","background-csv");
		}
		else
		{
			er_background = "";
			er_foreground = "selected";
			rootJson.put("reportGeneration","foreground");
		}
		String bg_reportname = request.getParameter("bg_reportname");
		if(bg_reportname == null)
		{
			bg_reportname = "";
		}
		if(bggroundStr != null && !bggroundStr.equals(""))
		{
			rootJson.put("backgroundReportStatus",status);
			String strreportName = "Thin_Client_Application_Activity";
			if(targetType!=null && targetType.equalsIgnoreCase("Application User Details"))
			{
				strreportName=backGroundReportType;
			}
			if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
			{
			   strreportName = "All Report Types";
			}
			if(strreportName!=null && strreportName.indexOf(" ") > -1)
			{
				strreportName = com.eg.EgURLEncoder.encode(strreportName, "UTF-8");
			}
			/*String strreportName="";
			if(status!=null && status.equalsIgnoreCase("success"))
			{
				//strreportName = "Thin_Client_Application_Activity";
				strreportName = "ThinClientApplication";
			}
			if(targetType!=null && targetType.equalsIgnoreCase("Application User Details"))
			{
				strreportName=backGroundReportType;
			}
			if(status != null && status.equalsIgnoreCase("duplicate") || bggroundStr!=null)
			{
				strreportName ="All Report Types";
				rootJson.put("bgGroundMsg",bggroundStr);
			}
			if(strreportName!=null && strreportName.indexOf(" ") > -1)
			{
				strreportName = com.eg.EgURLEncoder.encode(strreportName, "UTF-8");
			} */
			String bgroundResponseTxt=bggroundStr;
			if(status != null && !status.equalsIgnoreCase("exceedLimit"))
			{
				bgroundResponseTxt=erbgreport.getlangsupportedString(bggroundStr,bgString,urs);
			}
			rootJson.put("bgroundResponseTxt",bgroundResponseTxt);
			rootJson.put("bgroundReportsURL","/final/servlet/com.eg.ErStartBackGroundReportC?back=true&er_bgreportfrom="+strreportName+"&userID="+com.eg.EgURLEncoder.encode(urs, "UTF-8")+"&savereport=search&er_filterby=Report_Name&forwardto=ErBackGoundProcess");
			rootJson.put("backgroundAnchor", intlmap.getTextDescription("reporter.common.Click here to see a list of generated and processing reports"));
		}
		int appValue=0;
		if(htt!=null && !htt.isEmpty())
		{
			for(Enumeration en = htt.keys(); en.hasMoreElements();)
			{
				Vector v_value = (Vector)htt.get((String)en.nextElement());
				if(v_value!=null && !v_value.isEmpty())
					appValue++;
			}
		}
		if((htt!=null && appValue >0) || (app_topusers!=null && app_topusers.size()>0) || (v_qry_string!=null && v_qry_string.size()>0))
		{
			JSONObject selectionDetails=new JSONObject();
			rootJson.put("reporter.common.SelectionDetailsfor", intlmap.getTextDescription("reporter.common.Selection Details for ")+" "+ intlmap.getComponentTypeDescription(s_compType));
			String s_reportType="";
			if(rtype!=null && rtype.equals("Yes"))
			{
				s_reportType="Graph";
			} 
			else
			{
				s_reportType="Data";
			}
			//selectionDetails.put(intlmap.getTextDescription("reporter.common.Report Type"),s_reportType);
			selectionDetails.put(intlmap.getTextDescription("reporter.common.Report Type"),intlmap.getTextDescription("reporter.thin."+s_reportType));
			selectionDetails.put(intlmap.getTextDescription("reporter.common.Component Type"), intlmap.getComponentTypeDescription(s_compType));
			String server = (s_server!=null && s_server.equals("-1")) ? "All Server" : s_server;
			String selectdComponents="";
			StringTokenizer servr = new StringTokenizer(server,",");
			while(servr.hasMoreTokens())
			{
				String ServrValue=servr.nextToken();
				if(ServrValue.indexOf(":NULL")>-1)
					ServrValue = ServrValue.substring(0,ServrValue.indexOf(":NULL"))+ServrValue.substring(ServrValue.indexOf(":NULL")+5);
				if(ServrValue != null && ServrValue.indexOf(":")>-1)
				{
					String comp=ServrValue.substring(0,ServrValue.lastIndexOf(":"));
					String compType=ServrValue.substring(ServrValue.lastIndexOf(":")+1);
					if(compType!= null)
						compType=intlmap.getComponentTypeDescription(compType);
					if(s_compType!=null && s_compType.equalsIgnoreCase("ALL"))
						selectdComponents+=comp+":"+compType+",";
					else
						selectdComponents+=comp+",";
				}
			}
			if(selectdComponents != null && selectdComponents.endsWith(","))
				selectdComponents=selectdComponents.substring(0,selectdComponents.lastIndexOf(","));
			if(rtype!=null && rtype.equals("No") && server!=null && !server.equals("-1"))
			{
				selectionDetails.put(intlmap.getTextDescription("reporter.common.Component"),selectdComponents);
			}
			if(testmes!=null && rtype!= null && rtype.equals("Yes"))
			{
				if(testmes.indexOf("/") >-1)
				{
					String str_test = testmes.substring(0,testmes.indexOf("/"));
					String s_meas = testmes.substring(testmes.indexOf("/")+1);
					selectionDetails.put(intlmap.getTextDescription("reporter.common.Criteria"),intlmap.getMeasureDescription(str_test, s_meas));
				}
				else 
				{
					selectionDetails.put(intlmap.getTextDescription("reporter.common.Criteria"),intlmap.getTextDescription("reporter.common."+testmes));
				}
			}
			String strApp = (s_application!=null && s_application.equals("-1")) ? intlmap.getTextDescription("reporter.thin.All Application") : s_application;
			if(rtype!=null && rtype.equals("No") && strApp!=null && !strApp.equals("-1"))
			{
				selectionDetails.put(intlmap.getTextDescription("reporter.common.Application"),strApp);
			}
			//selectionDetails.put(intlmap.getTextDescription("reporter.common.Exclude weekends"),excludeweekend);
			selectionDetails.put(intlmap.getTextDescription("reporter.common.Exclude weekends"),intlmap.getTextDescription("reporter.thin."+excludeweekend));
			selectionDetails.put(intlmap.getTextDescription("reporter.common.Time Period"),"<span class='font_bold'> </span> "+Hourfrom+":"+Minfrom+"<span class='font_bold'>  "+intlmap.getTextDescription("reporter.common.to")+"  </span>  "+Hourto+":"+Minto);
			selectionDetails.put((String)intlmap.getTextDescription("reporter.common.Timeline"),"<span class='font_bold'> </span> "+pdfStartDate+" "+intlmap.getTextDescription("reporter.common.hrs")+" <span class='font_bold'>  "+intlmap.getTextDescription("reporter.common.to")+"  </span> "+pdfEndDate+" "+intlmap.getTextDescription("reporter.common.hrs"));

			rootJson.put("selectionDetails",selectionDetails);
		}
		ArrayList sublist=(ArrayList)reportInfo.getVariables("APPLICATION_REPORT");
		String s=request.getParameter("er_server");	
		List al=null;
		if(s!=null)
		{
			al=Arrays.asList(s.split(","));
			for(int j=0;j<al.size();j++)
			{
				s=(String)al.get(j);
				for(int i=0; i<sublist.size(); i++)
				{
					String tempsub1=(String)sublist.get(i);
					if(s!=null && !s.equals("All") && !s.equals("-1") && s.lastIndexOf(":")>0)
					{
						s=s.substring(s.lastIndexOf(":")+1,s.length());
						s=s.trim();
						
						if(tempsub1.indexOf(s)==-1)
						{
							if(sublist.contains(s))
							sublist.remove(i);
							i=i-1;
						}
					}
				}
			}
		}
		if(rtype==null)
		{
			rtype="No";
		}
		//Data View starts here
		if(rtype!=null&&rtype.equals("No") || rtype== null)
		{
			if(app_topusers == null || app_topusers.isEmpty() || app_topusers.size() == 0)
			{
				Vector value=new Vector();
				String AddFieldsDisplay="";
				String FieldstoDisplay="$F{title}";
				String Fields="title";
				String addMapping="";
				String pdfKey="";
				String con="yes";
				if (htt!=null)
				{
					JSONObject reportDataJson = new JSONObject();
					JSONArray GridArray = new JSONArray();
					Enumeration enum1 = htt.keys();
					while(enum1.hasMoreElements())
					{
						String key1 = (String)enum1.nextElement();
						value=(Vector)htt.get(key1);
						if(al!=null)
						{
							for(int i=0;i<al.size();i++)
							{
								String alstr=(String)al.get(i);
								String str=alstr.substring(alstr.lastIndexOf(":")+1);
								if(str.equals(key1))
								{
									s_server=alstr;
									break;
								}
							}
						}
						JSONObject gridObj=new JSONObject();
						JSONObject gridColumnsDetails=new JSONObject();
						JSONObject unitForMeasure=new JSONObject();
						JSONArray gridDataArray=new JSONArray();
						int totalColumnCount=0;
						int havingSingleColumn=0;
						if(value.isEmpty() && con.equals("yes"))
						{
							con="no";
						}
						if(!value.isEmpty())
						{
							if(s_server==null || s_server.equals("-1") || s_server.equals("")|| aListAlltype.contains(s_server))
							{
								pdfKey=s_farmserver;
								s_tit1 = intlmap.getTextDescription("reporter.application.Top Application Report")+" - "+intlmap.getComponentTypeDescription(key1)+":"+s_farmserver;
								gridObj.put("gridTitle",s_tit1);
								if (s_perserver!=null && s_perserver.equalsIgnoreCase("No"))
								{
									AddFieldsDisplay="Server / Application";
									gridColumnsDetails.put(intlmap.getTextDescription("reporter.common.Server")+"/"+intlmap.getTextDescription("reporter.common.Application"),new JSONArray());
	
									vec1.add(intlmap.getTextDescription("reporter.common.Server")+" /"+intlmap.getTextDescription("reporter.common.Application"));
								}
								else
								{
									gridColumnsDetails.put(intlmap.getTextDescription("reporter.common.Application"),new JSONArray());
									AddFieldsDisplay="Application";
									vec1.add(intlmap.getTextDescription("reporter.common.Application"));
								}
								FieldstoDisplay+=",-";
							}
							else if ((s_server!=null || !s_server.equals("-1") || !s_server.equals("")) )
							{
								String s_server_sub = s_server;
								if(s_server_sub.indexOf(":NULL")>-1)
								s_server_sub = s_server_sub.substring(0,s_server_sub.indexOf(":NULL"))+s_server_sub.substring(s_server_sub.indexOf(":NULL")+5);
								String t_srv=s_server_sub.substring(0,s_server_sub.lastIndexOf(":"));
								pdfKey=s_server_sub.substring(0,s_server_sub.lastIndexOf(":"));
								AddFieldsDisplay="Application";
								FieldstoDisplay+=",-";
								if(selectedCompArrays!=null && selectedCompArrays.length>1)
								if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
								{
									if(s_compType!=null && s_compType.equalsIgnoreCase("all"))
										s_tit1 = intlmap.getTextDescription("reporter.application.Application User Details For") +headerKeyName+" - "+s_compType;
									else
										s_tit1 = intlmap.getTextDescription("reporter.application.Application User Details For ")+headerKeyName+" - "+intlmap.getComponentTypeDescription(s_server_sub.substring(s_server_sub.lastIndexOf(":")+1));
								}
								else
								{
									if(s_compType!=null && s_compType.equalsIgnoreCase("all"))
									{
										s_tit1 = intlmap.getTextDescription("reporter.application.Top Application Report For") + " " + headerKeyName + " - " + intlmap.getComponentTypeDescription(key1);
									}
									else
									{
										s_tit1 = intlmap.getTextDescription("reporter.application.Top Application Report For") + " " + headerKeyName + " - " + intlmap.getComponentTypeDescription(s_server_sub.substring(s_server_sub.lastIndexOf(":")+1));
									}
								}
								else
								{
									String s_cmpServer = selectedCompArrays[0].substring(0,selectedCompArrays[0].lastIndexOf(":"));
									if(s_cmpServer!= null && s_cmpServer.indexOf(":NULL")>-1)
										s_cmpServer = s_cmpServer.substring(0,s_cmpServer.indexOf(":NULL"));
									if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
									{
										s_tit1 = intlmap.getTextDescription("reporter.application.Application User Details For")+" "+headerKeyName+" - "+s_cmpServer;
									}
									else
									{
										s_tit1 = intlmap.getTextDescription("reporter.application.Top Application Report For") + " " + headerKeyName + " - " + intlmap.getComponentTypeDescription(key1);
									}
								}
								gridObj.put("gridTitle",s_tit1);
								gridColumnsDetails.put(intlmap.getTextDescription("reporter.common.Application"),new JSONArray());
								if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
								{
									rootJson.put("group_by_component",groupByComponent);
									if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("yes"))
									{
										vec1.add(intlmap.getTextDescription("reporter.common.Component"));
									}
								}
								vec1.add(intlmap.getTextDescription("reporter.common.Application"));
							}
							else
							{
									pdfKey=s_application;
									AddFieldsDisplay="Application";
									FieldstoDisplay+=",-";
									s_tit1 = intlmap.getTextDescription("reporter.application.Top Application Report")+" - "+s_application;
									gridObj.put("gridTitle",s_tit1);
							}
							if (AddFieldsDisplay.equals(""))
							{
								AddFieldsDisplay="Time in use,"+"Unique users";
							}
							else
							{
								AddFieldsDisplay+=","+"Time in use,"+"Unique users";
							}
							if (FieldstoDisplay.equals(""))
							{
								FieldstoDisplay="-,-";
							}
							else
							{
								FieldstoDisplay+=",-,-";
							}
							if (s_server==null || s_server.equals("") || s_server.equals("-1")|| aListAlltype.contains(s_server))
							{
								vec1.add("% "+intlmap.getTextDescription("reporter.application.Time in use per server"));
								gridColumnsDetails.put("% "+intlmap.getTextDescription("reporter.application.Time in use per server"),new JSONArray());
							}
							else
							{
								if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
								{
								  vec1.add("Unique User Count ");
								}
								else
								{
									//if(s_compType!=null && !s_compType.startsWith("Agg_"))
									{
									vec1.add("% "+intlmap.getTextDescription("reporter.application.Time in use"));
									gridColumnsDetails.put("% "+intlmap.getTextDescription("reporter.application.Time in use"),new JSONArray());
									}
								}
							}
							if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
							{
								vec1.add("User Name(s)");
								if(csvNameByRow!=null && csvNameByRow.equalsIgnoreCase("true"))
								{
									if(v_iconData!=null && v_iconData.size()>0)
									{
										StringTokenizer stTokens = new StringTokenizer(columnIncluded,",");
										while(stTokens.hasMoreTokens())
										{
											String strColumns = (String)stTokens.nextToken();
											vec1.add(intlmap.getTextDescription("reporter.common."+strColumns));
											geoColArray.add(strColumns);
										}
									}
								}
							}
							else
							{
								if(s_compType!=null && !s_compType.startsWith("Agg_"))
								{
									vec1.add(intlmap.getTextDescription("reporter.thin.unique users"));
									gridColumnsDetails.put(intlmap.getTextDescription("reporter.thin.unique users"),new JSONArray());
								}
							}
							String s_var = "";
							Vector v_val = new Vector();
							if (Fields.equals(""))
							{
								Fields="Application,Timeinuse,Users";
							}
							else
							{
								Fields+=",Application,Timeinuse,Users";
							}
							if (addMapping.equals(""))
							{
								addMapping="Application#Application,Timeinuse#Timeinuse,Users#Users";
							}
							else
							{
								addMapping+=",Application#Application,Timeinuse#Timeinuse,Users#Users";
							}
							Class [] addFieldClassTypes = new Class[sublist.size()+3] ;
							addFieldClassTypes[0]=java.lang.String.class;
							addFieldClassTypes[1]=java.lang.String.class;
							addFieldClassTypes[2]=java.lang.String.class;
							v_val1=new Vector();
							for(int m=0;m<sublist.size();m++)
							{
								JSONArray subheaders=new JSONArray();
								s_var = (String)sublist.get(m);
								if(s_var!=null && s_var.indexOf(":")==-1)
								{
									continue;
								}
								String m_val=s_var.substring(0,s_var.indexOf(":"));
								String stest = s_var.substring(s_var.indexOf(":")+1,s_var.lastIndexOf(":"));
								String smeasure = s_var.substring(s_var.lastIndexOf(":")+1,s_var.indexOf("#")); 
								String data_units = tablesInfo.getUnitForMeasure(stest,smeasure);
								if(key1.equals(m_val))
								{
									String st_value="";
									String displayname="";
									String val2="";
									if ((s_server==null || s_server.equals("-1") || s_server.equals("")) &&  s_farmserver!=null && !s_farmserver.equals("") || aListAlltype.contains(s_server))
									{
										if(s_var.startsWith(key1))
										{
											StringTokenizer tok2 = new StringTokenizer(s_var,":");
											while(tok2.hasMoreTokens())
											{
												tok2.nextToken();
												tok2.nextToken();
												val2=tok2.nextToken();
												StringTokenizer meas=new StringTokenizer(val2,"#");
												if(meas.hasMoreTokens() )
												{
													mes=meas.nextToken();
												}
												else
												{
													mes=val2;
												}
												if(meas.hasMoreTokens())
												{
													displayname=meas.nextToken();
												}
												else
												{
													displayname=val2;
												}
											}
											st_value=reportInfo.getValue("APPLICATION_REPORT",s_var);
										}
										v_val.add(st_value);
									}
									else
									{
										String strCompType = null;
										if(s_server.lastIndexOf(":")>-1)
										strCompType = s_server.substring(s_server.lastIndexOf(":")+1);
										if(strCompType!=null && s_var !=null && !s_var.startsWith(strCompType))
										continue;
										StringTokenizer tok2 = new StringTokenizer(s_var,":");
										while(tok2.hasMoreTokens())
										{
											tok2.nextToken();
											tok2.nextToken();
											val2=tok2.nextToken();
											StringTokenizer meas=new StringTokenizer(val2,"#");
											if(meas.hasMoreTokens())
											{
												mes=meas.nextToken();
											}
											else
											{
												mes=val2;
											}
											if(meas.hasMoreTokens())
											{
												displayname=meas.nextToken();
											}
											else
											{
												displayname=val2;
											}
										}
										st_value=reportInfo.getValue("APPLICATION_REPORT",s_var);
										v_val.add(st_value);
									}
									if (AddFieldsDisplay.equals(""))
									{
										AddFieldsDisplay=displayname;
									}
									else
									{
										AddFieldsDisplay+=","+displayname;
									}
									addFieldClassTypes[m+3]=java.lang.String.class;
									if (st_value.equals(""))
									{
										st_value="Avg";
									}
									String tmp_column=intlmap.getTextDescription("reporter.common."+displayname);
									StringTokenizer st_val=new StringTokenizer(st_value,",");
									int countTokens=st_val.countTokens();
									if(st_value.indexOf("Avg")>-1 && st_value.indexOf("Pct")>-1 && st_value.indexOf("Max")  >-1 )
									{
										for (int l=0;l<countTokens;l++)
										{
											if (Fields.equals(""))
											{
												Fields=mes+(l+1);
											}
											else
											{
												Fields+=","+mes+(l+1);
											}
										}
										if(addMapping.equals(""))
										{
											addMapping=mes+"1#"+mes+countTokens;
										}
										else
										{
											addMapping+=","+mes+"1#"+mes+countTokens;
										}
										for(int k=0;k < v_val.size(); k++)
										{
											String str = (String)v_val.get(k);
											if (str.equals(""))
											{
												str="Avg";
											}
											StringTokenizer st_tok=new StringTokenizer(str,",");
											while (st_tok.hasMoreTokens())
											{
												String tmpaggregate=st_tok.nextToken();
												subheaders.add(tmpaggregate);
												totalColumnCount++;
												vec1.add(intlmap.getTextDescription("reporter.thin."+displayname)+"-"+"("+intlmap.getTextDescription("reporter.common."+tmpaggregate)+")");    
											}
											gridColumnsDetails.put(tmp_column,subheaders);
										}
									}
									else if((st_value.indexOf("Avg")>-1 && st_value.indexOf("Pct")>-1) || (st_value.indexOf("Avg")>-1 && st_value.indexOf("Max")>-1) || (st_value.indexOf("Max")>-1 && st_value.indexOf("Pct")>-1))
									{
										for (int l=0;l<countTokens;l++)
										{
											if (Fields.equals(""))
											{
												Fields=mes+(l+1);
											}
											else
											{
												Fields+=","+mes+(l+1);
											}
										}
										if (addMapping.equals(""))
										{
											addMapping=mes+"1#"+mes+countTokens;
										}
										else
										{
											addMapping+=","+mes+"1#"+mes+countTokens;
										}
										if(!displayname.equals(""))
										{
											for(int k=0;k < v_val.size(); k++)
											{
												String str = (String)v_val.get(k);
												if (str.equals(""))
												{
													str="Avg";
												}
												StringTokenizer st_tok=new StringTokenizer(str,",");
												while (st_tok.hasMoreTokens())
												{
													String tmpaggregate=st_tok.nextToken();
													tmpaggregate = intlmap.getTextDescription("reporter.thin."+tmpaggregate);
													subheaders.add(tmpaggregate);
													totalColumnCount++;
													vec1.add(intlmap.getTextDescription("reporter.thin."+displayname)+"-"+"("+intlmap.getTextDescription("reporter.common."+tmpaggregate)+")");    
													unitForMeasure.put(tmp_column,intlmap.getTextDescription("reporter.thin."+data_units));
												}
											}
											gridColumnsDetails.put(tmp_column,subheaders);
										}
									}
									else
									{
										for (int l=0;l<countTokens;l++)
										{
											if (Fields.equals(""))
											{
												Fields=mes+(l+1);
											}
											else
											{
												Fields+=","+mes+(l+1);
											}
										}
										if (addMapping.equals(""))
										{
											addMapping=mes+"1#"+mes+countTokens;
										}
										else
										{
											addMapping+=","+mes+"1#"+mes+countTokens;
										}
										if(!displayname.equals(""))
										{
											for(int k=0;k < v_val.size(); k++)
											{
												String str = (String)v_val.get(k);
												if (str.equals(""))
												{
													str="Avg";
												}
												StringTokenizer st_tok=new StringTokenizer(str,",");
												while (st_tok.hasMoreTokens())
												{
													String tmpaggregate=st_tok.nextToken();
													tmpaggregate = intlmap.getTextDescription("reporter.thin."+tmpaggregate);
													subheaders.add(tmpaggregate);
													totalColumnCount++;
													vec1.add(intlmap.getTextDescription("reporter.thin."+displayname)+"-"+"("+intlmap.getTextDescription("reporter.common."+tmpaggregate)+")");    
													unitForMeasure.put(tmp_column,intlmap.getTextDescription("reporter.thin."+data_units));
												}
											}
											gridColumnsDetails.put(tmp_column,subheaders);
										}
									}
									for(int x=0;x< v_val.size();x++)
									{
										v_val1.add(v_val.get(x));
									}
									v_val = new Vector();
								}
							}
							if((selectedCompArrays!=null && selectedCompArrays.length>0) || (s_server!=null && s_server.equals("-1")|| aListAlltype.contains(s_server)))
							{
								if(s_compType!=null && !s_compType.startsWith("Agg_"))
								{
									gridColumnsDetails.put(intlmap.getTextDescription("reporter.thin.Top")+" "+intlmap.getTextDescription("reporter.thin."+numTopUsers)+" "+intlmap.getTextDescription("reporter.thin.users"),new JSONArray());
								}
							}
							int fieldsize=3;
							for(int v=0;v<v_val1.size();v++)
							{
								String v_value = (String)v_val1.get(v);
								StringTokenizer tokenizer=new StringTokenizer(v_value,",");
								while(tokenizer.hasMoreTokens())
								{
									String str1=tokenizer.nextToken();
									fieldsize=fieldsize+1;
									if (FieldstoDisplay.equals(""))
									{
										FieldstoDisplay=str1;
									}
									else
									{
										FieldstoDisplay+=","+str1;
									}
								}
							}
							Class [] fieldClassTypes = new Class[fieldsize+1];
							for (int z=0;z<fieldClassTypes.length;z++)
							{
								fieldClassTypes[z]=java.lang.String.class;
							}
							Vector v_pdfdata=new Vector();
							String st_app="";
							String queryForTop = "";
							String queryForAllusers = "";
							if (s_server==null || s_server.equals("-1") || s_server.equals("")|| aListAlltype.contains(s_server))
							{
								app_data=value;
							}
							for (int z=0;z<value.size();z++)
							{
								JSONObject rowOfdata=new JSONObject();
									ArrayList userList = null;
									if(v_iconData!=null && z<=v_iconData.size()-1)
									{
										userList = (ArrayList)v_iconData.get(z);
									}
								Vector v_data=(Vector)value.get(z);
								String st_check="-";
								for (int i=0;i<v_data.size();i++)
								{
									String strdata=v_data.get(i).toString();
									if(i==0)
									{
										st_app = strdata;
									}
									if (i==1)
									{
										if(isApplicationsUserReport==null || isApplicationsUserReport.equalsIgnoreCase("false")||isApplicationsUserReport.length()==0)
										{
                                                                       strdata = (strdata == null || strdata.equals("")||strdata.equals("-5.0")||strdata.equals("-"))? "-" : erUtils.round(Float.parseFloat(strdata),4);
										}
									}
									else if (i==2)
									{
										st_check=strdata;
										if(isApplicationsUserReport==null || isApplicationsUserReport.equalsIgnoreCase("false")||isApplicationsUserReport.length()==0)
										{
											strdata = (strdata == null ||strdata.equals("-")|| strdata.equals("")||strdata.equals("-5.0"))? "-" : erUtils.round(Float.parseFloat(strdata),0);
										}
									}
									else if(i>2)
									{
										if(isApplicationsUserReport==null || isApplicationsUserReport.equalsIgnoreCase("false")||isApplicationsUserReport.length()==0)
										{
                                                                        strdata = (strdata == null || strdata.equals("")||strdata.equals("-5.0")||strdata.equals("-"))? "-" : erUtils.round(Float.parseFloat(strdata),2);
										}
									}
									v_pdfdata.add(strdata);
									queryForTop = "../servlet/com.eg.ErCtxServerReportC?er_rtype=CtxApplication&isSubmit=true&er_gtype=Citrix&er_timeline=" + URLEncoder.encode(timeline) + "&er_trgttype="+reportType+"&timefrom=" + timefrom2 + "&timeto=" + timeto2 + "&minfrom=" +minfrom2 + "&minto=" + minto2 + "&pdfTime="+URLEncoder.encode(pdfTime)+"&startdate=" +URLEncoder.encode(request.getParameter("startdate"))+ "&enddate=" + URLEncoder.encode(request.getParameter("enddate"))+ "&starthr=" + s_st_hr + "&endhr=" + s_en_hr + "&currTime=" + cTime + "&select_farm=" + s_farmserver + "&er_excwe=" + excludeweekend + "&er_tbound=" + tbound+"&er_server="+s_server+"&er_application1="+EgURLEncoder.encode(st_app,"UTF-8")+"&er_application="+s_application+"&uid=" + loginid+"&er_testmes="+testmes+"&servers="+key1+"&er_type=No"
									+"&startmin="+strmin+"&endmin="+enmin+"&inidate="+URLEncoder.encode(currentDateFormat)+"&er_option="+er_option+"&er_site="+er_site;
									if (s_perserver.equalsIgnoreCase("Yes"))
									{
										queryForAllusers = queryForTop+"&showTopusers=true&er_check=true&er_perserver=Yes";
									}
									else
									{
										queryForAllusers = queryForTop+"&showTopusers=true&er_check=true&er_perserver=No&server="+st_app;
									}
									queryForTop =queryForTop+"&showTopusers=true&er_check=true";

									if(s_sort!=null)
									{
										queryForAllusers+="&er_sortby=" + s_sort;
									}
									String strdata_disp = strdata;
									if(strdata_disp!= null && strdata_disp.indexOf(":NULL")>-1)
										strdata_disp = strdata_disp.substring(0,strdata_disp.indexOf(":NULL"))+strdata_disp.substring(strdata_disp.indexOf(":NULL")+5);
									if (i==0)
									{
										rowOfdata.put(rowOfdata.size(),strdata_disp);
										lst_dat1.add("\""+strdata_disp+"\"");
									}
									else if (i==2)
									{
										if(strdata_disp.equals("-"))
										{
											lst_dat1.add("\""+strdata_disp+"\"");
											rowOfdata.put(rowOfdata.size(),strdata_disp);
										}
										else
										{
											if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
											{
												rowOfdata.put(rowOfdata.size(),strdata_disp);
												if(csvNameByRow!=null && csvNameByRow.equalsIgnoreCase("true"))
												{
													if(strdata_disp.indexOf(",")>=0 )
													{
														StringTokenizer tokenizer=new StringTokenizer(strdata_disp,",");
														int k=0;
														while(tokenizer.hasMoreTokens())
														{
															String str1=tokenizer.nextToken();
															 if(k==0)
																lst_dat1.add("\""+str1+"\"");
															else
															{
																lst_dat1.add("");
																lst_dat1.add("");
																lst_dat1.add("\""+str1+"\"");
															}
																HashMap userMap = null;
																if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("no"))
																{
																	if(userList!=null)
																	{
																		userMap = (HashMap)userList.get(k);
																	}
																}
															k++;
																if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("no"))
																{
																	if(userMap!=null)
																	{
																		for(int xy=0;xy<geoColArray.size();xy++)
																		{
																			lst_dat1.add("\""+userMap.get((String)geoColArray.get(xy))+"\"");
																		}
																	}
																}
															 }
														}
													else
													{
														lst_dat1.add("\""+strdata_disp+"\"");
															if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("no"))
															{
																HashMap userMap = null;
																if(userList!=null)
																{
																	userMap = (HashMap)userList.get(0);
																}
																if(userMap!=null)
																{
																	for(int xy=0;xy<geoColArray.size();xy++)
																	{
																		lst_dat1.add("\""+userMap.get((String)geoColArray.get(xy))+"\"");
																	}
																}  
															}
													}
												}
												else
												{
													lst_dat1.add("\""+strdata_disp+"\"");
												}
											}
											else
											{
												lst_dat1.add("\""+strdata_disp+"\"");
												if(s_compType!=null && !s_compType.startsWith("Agg_"))
												{
													rowOfdata.put(rowOfdata.size(),strdata_disp);
												}
												else
												{
													rowOfdata.put(rowOfdata.size(),strdata_disp+"~"+queryForAllusers+"&responseType=json");
												}
											}
										}
									}
									else
									{
										if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
										{
											if(csvNameByRow!=null && csvNameByRow.equalsIgnoreCase("true"))
											{
												if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("yes"))
												{
													if(strdata_disp.indexOf(",")>=0)
													{
														StringTokenizer tokenizer=new StringTokenizer(strdata_disp,",");
														int k=0;
														while(tokenizer.hasMoreTokens())
														{
															String str1=tokenizer.nextToken();
															if(k==0)
																lst_dat1.add("\""+str1+"\"");
															else
															{
																lst_dat1.add("");
																lst_dat1.add("");
																lst_dat1.add("");
																lst_dat1.add("\""+str1+"\"");
															}
																if(i == 3)
																{ 
																	HashMap userMap = null;
																	if(userList!=null)
																	{
																		userMap = (HashMap)userList.get(k);
																	}
																	k++;
																	if(userMap!=null)
																	{
																		for(int xy=0;xy<geoColArray.size();xy++)
																		{
																			lst_dat1.add("\""+userMap.get((String)geoColArray.get(xy))+"\"");
																		}
																	}
																}
															}
														}
													else
													{
														lst_dat1.add("\""+strdata_disp+"\"");
															if(i == 3)
															{
																HashMap userMap = null;
																if(userList!=null)
																{
																	userMap = (HashMap)userList.get(0);
																}
																if(userMap!=null)
																{
																	for(int xy=0;xy<geoColArray.size();xy++)
																	{
																		lst_dat1.add("\""+userMap.get((String)geoColArray.get(xy))+"\"");
																	}
																}
															}
													}
												}
												else
												{
													lst_dat1.add("\""+strdata_disp+"\"");
												}
											}
											else
											{
												lst_dat1.add("\""+strdata_disp+"\"");
											}
										}
										else
										   lst_dat1.add("\""+strdata+"\"");
										rowOfdata.put(rowOfdata.size(),strdata_disp);
									}
								}
								String stg_server = st_app;
								if(s_server!=null&&s_server.equals("-1")&&s_perserver.equals("No"))
								{
									st_app=st_app.substring(st_app.indexOf("/")+2,st_app.length());
								}
								queryForTop = "../servlet/com.eg.ErCtxServerReportC?er_rtype=CtxApplication&isSubmit=true&er_gtype=Citrix&er_timeline=" +URLEncoder.encode(er_timeline) + "&er_trgttype="+URLEncoder.encode(reportType)+"&timefrom=" + timefrom2 + "&timeto=" + timeto2 + "&minfrom=" +minfrom2 + "&minto=" + minto2 +"&startdate=" + URLEncoder.encode(request.getParameter("startdate")) + "&enddate=" + URLEncoder.encode(request.getParameter("enddate")) + "&starthr=" + s_st_hr + "&endhr=" + s_en_hr + "&currTime=" + cTime + "&select_farm=" + EgURLEncoder.encode(s_farmserver,"UTF-8") + "&er_excwe=" + excludeweekend + "&er_tbound=" + tbound+"&er_server="+EgURLEncoder.encode(s_server,"UTF-8")+"&er_application1="+EgURLEncoder.encode(st_app,"UTF-8")+"&er_application="+s_application+"&showTopusers=true&uid="+loginid+"&er_check=null"+"&servers="+key1+"&er_type=No"+"&startmin="+strmin+"&endmin="+enmin+"&er_option="+er_option+"&er_site="+er_site;
								if(s_sort!=null)
								{
									queryForTop+="&er_sortby="+s_sort;
								}
								String qryTopUsers_zone = queryForTop+"&er_perserver="+s_perserver;
								String qryTopUsers_Allserver = queryForTop+"&er_perserver="+s_perserver+"&server="+stg_server;
								String queryTopUsers_perserver = "";
								queryTopUsers_perserver ="../servlet/com.eg.ErCtxServerReportC?er_rtype=CtxApplication&isSubmit=true&er_gtype=Citrix&er_timeline=" + timeline + "&er_trgttype="+reportType+"&timefrom=" + timefrom2 + "&timeto=" + timeto2 + "&minfrom=" +minfrom2 + "&minto=" + minto2 + "&pdfTime="+URLEncoder.encode(pdfTime)+"&startdate=" + URLEncoder.encode(request.getParameter("startdate")) + "&enddate=" + URLEncoder.encode(request.getParameter("enddate")) + "&starthr=" + s_st_hr + "&endhr=" + s_en_hr + "&currTime=" + cTime + "&select_farm=" + EgURLEncoder.encode(s_farmserver,"UTF-8") + "&er_excwe=" + excludeweekend + "&er_tbound=" + tbound+"&er_server="+EgURLEncoder.encode(s_server,"UTF-8")+"&er_application1="+EgURLEncoder.encode(stg_server,"UTF-8")+"&er_application="+s_application+"&showTopusers=true&uid="+ loginid+"&er_check=null"+"&servers="+key1+"&er_type=No"+"&startmin="+strmin+"&endmin="+enmin+"&er_option="+er_option+"&er_site="+er_site;
								if(s_sort!=null)
								{
									queryTopUsers_perserver+="&er_sortby=" + s_sort;
								}
								String qryback_Allserver ="../servlet/com.eg.ErCtxServerReportC?isSubmit=true";
								String qryback_perserver ="../servlet/com.eg.ErCtxServerReportC?isSubmit=true";
								if(s_compType!=null && !s_compType.startsWith("Agg_"))
								{
									if(s_perserver.equals("Yes"))
									{
										if(s_server.equals("-1")|| aListAlltype.contains(s_server))
										{
											if(!st_check.equals("-5.0"))
											{
												rowOfdata.put(rowOfdata.size(),"top.gif"+"~"+qryTopUsers_zone+"&responseType=json");
											}
											else
											{
												rowOfdata.put(rowOfdata.size(),"-");
											}
											session.setAttribute("topBackQuery",qryback_Allserver);
										}
									}
									else if( s_perserver.equals("No"))
									{
										if((selectedCompArrays!=null && selectedCompArrays.length>1) || (s_server!=null && s_server.equals("-1")|| aListAlltype.contains(s_server)))
										{
											if(!st_check.equals("-5.0"))
											{
												rowOfdata.put(rowOfdata.size(),"top.gif"+"~"+queryTopUsers_perserver+"&responseType=json");
											}
											else
											{
												rowOfdata.put(rowOfdata.size(),"-");
											}
											session.setAttribute("topBackQuery",qryback_Allserver);
										}
									}
									if(s_server!=null&&!s_server.equals("-1")&& s_perserver.equals("Yes")&& !aListAlltype.contains(s_server))
									{
										if(!st_check.equals("-5.0"))
										{
											rowOfdata.put(rowOfdata.size(),"top.gif"+"~"+queryTopUsers_perserver+"&responseType=json");
										}
										else
										{
											rowOfdata.put(rowOfdata.size(),"-");
										}
										session.setAttribute("topBackQuery_server",qryback_perserver);
									}
								}
								gridDataArray.add(rowOfdata);
							}
							TreeMap paramMap = new TreeMap();
							TreeMap pdfData=new TreeMap();
							pdfData.put(pdfKey,v_pdfdata);
							boolean fieldWidthInPercentage = false;
							boolean addFieldWidthInPercentage =true;
							StringTokenizer stfields=new StringTokenizer(Fields,",");
							int [] xCoor = new int [stfields.countTokens()];
							int [] yCoor = new int [stfields.countTokens()];
							int coorsize=762/stfields.countTokens();
							for (int k=0;k<xCoor.length;k++)
							{
								if (k==0)
								{
									xCoor[k]=0;
									yCoor[k]=5;
								}
								else
								{
									if (k==1)
									{
										xCoor[k]=0;
										yCoor[k]=35;
									}
									else if (k==2)
									{
										xCoor[k]=120;
										yCoor[k]=35;
									}
									else
									{
										xCoor[k]=xCoor[k-1]+coorsize;
										yCoor[k]=35;
									}
								}
							}
							int size=752/(stfields.countTokens());
							int [] fieldWidth = new int [stfields.countTokens()];
							int [] fieldHeight= new int [stfields.countTokens()];
							for (int l=0;l<fieldWidth.length;l++)
							{
								if (l==0)
								{
									fieldWidth[l]=752;
									fieldHeight[l]=10;
								}
								else
								{
									fieldWidth[l]=size;
									fieldHeight[l]=10;
								}
							}
							// for application user details
							if(isApplicationsUserReport!=null && isApplicationsUserReport.equalsIgnoreCase("true"))
							{
								gridColumnsDetails=new JSONObject();
								gridColumnsDetails=new JSONObject();
								if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("yes"))
								{
									gridColumnsDetails.put("Component",new JSONArray());
								}
								gridColumnsDetails.put("Application",new JSONArray());
								gridColumnsDetails.put("Unique User Count",new JSONArray());
								gridColumnsDetails.put("User Name(s)",new JSONArray());
							}
							StringTokenizer staddfields=new StringTokenizer(AddFieldsDisplay,",");
							int [] addFieldWidth = new int [staddfields.countTokens()] ;
							int [] addFieldHeight= new int [staddfields.countTokens()];
							int [] addXCoor = new int [staddfields.countTokens()] ;
							int [] addYCoor = new int [staddfields.countTokens()] ;
							int addwidth=0;
							int addcoorsize=762/staddfields.countTokens();
							if(staddfields.countTokens()>0)
							{
								addwidth=100/staddfields.countTokens();
							}
							else
							{
								addwidth=10;
							}
							for(int k=0;k<addFieldWidth.length;k++)
							{
								addFieldWidth[k]=addwidth;
								addFieldHeight[k]=10;
							}
							int [] lineXCoor = new int [] {0, 0, 0};
							int [] lineYCoor = new int [] {15, 48, 10};
							int [] bandHeight = new int [] {49, 20, 35};
							paramMap.put("fields", Fields);
							paramMap.put("display", FieldstoDisplay);
							paramMap.put("addDisplay", AddFieldsDisplay);
							paramMap.put("addMapping", addMapping); //must
							paramMap.put("dataBag", pdfData);
							paramMap.put("pageLayout", "Landscape");
							paramMap.put("rowSize", new Integer(xCoor.length-1));//must
							paramMap.put("xCoor", xCoor);
							paramMap.put("lineXCoor", lineXCoor);
							paramMap.put("lineYCoor", lineYCoor);
							paramMap.put("bandHeight", bandHeight);
							paramMap.put("fieldWidth", fieldWidth);//must
							paramMap.put("fieldHeight", fieldHeight);
							paramMap.put("fieldClassTypes", fieldClassTypes);
							paramMap.put("addFieldClassTypes", addFieldClassTypes);
							paramMap.put("fieldWidthInPercentage", new Boolean(fieldWidthInPercentage));
							paramMap.put("addFieldWidthInPercentage", new Boolean(addFieldWidthInPercentage));

							Vector vdata=new Vector();
							Vector extraparam=new Vector();
							extraparam.add(reportType);
							extraparam.add("From "+erd.s_stdate+" hrs "+""+" To "+erd.s_enddate+"  hrs");
							vdata.add(paramMap);
							vdata.add(extraparam);
							Hashtable ht_pdfdata=new Hashtable();
							ht_pdfdata.put("commandName","DynamicTest");
							ht_pdfdata.put("pdfData",applnPdfData);
							ht_pdfdata.put("pdfFileName","APPLICATION_REPORT");
							session.setAttribute("sessionVal", ht_pdfdata);
							HashMap param =new HashMap();
							param.put("REPORT_PARAM",ErUtils.parseQueryString(ErUtils.prepareQueryString(request.getParameterMap())));
							param.put("REPORT_DATA",applnPdfData);
							session.setAttribute("parameters", param);
							gridObj.put("columns",gridColumnsDetails);
							gridObj.put("data_units",unitForMeasure);
							gridObj.put("dataArray",gridDataArray);
							gridObj.put("TOTAL_COLUMN_COUNT",String.valueOf(totalColumnCount));
												//gridObj.put("SINGLE_SUBCOLUMN_COUNT",										havingSingleColumn);
												if(v_iconData!=null && v_iconData.size()>0)
												{
													StringTokenizer stTokens = new StringTokenizer(columnIncluded,",");
													JSONArray colArray = new JSONArray();
													colArray.add("username");
													while(stTokens.hasMoreTokens())
													{
														String strColumns = (String)stTokens.nextToken();
														colArray.add(strColumns);
													} 
													gridObj.put("geoColumns", colArray) ;
													gridObj.put("geoDataArray", v_iconData) ;
													JSONArray tableJson = getAllInformationForUser(gridDataArray, v_iconData,colArray, groupByComponent);
													gridObj.put("tableJson", tableJson);
												}
							GridArray.add(gridObj);
							reportDataJson.put("gridArray",GridArray);
							rootJson.put("reportData",reportDataJson);
						}
						if(lst_dat1!=null && !lst_dat1.isEmpty())
						{
							sen1.put(vec1,lst_dat1);
							ht1=new Hashtable();
							ht1.put(s_tit1,sen1);
							lst.add(ht1);
							sen1 = new Hashtable();
							ht1 = new Hashtable();
							lst_dat1 = new LinkedList();
							vec1 = new Vector();
						}
					}
				}
			}
			else if(app_topusers!=null && app_topusers.size() > 0 || s_server.equals("-1")||app_topusers!=null && app_topusers.size() > 0 ||!s_server.equals("-1"))
			{
				JSONObject DrillDownReportData =  new JSONObject();
				if(app_topusers!=null && app_topusers.size() > 0)
				{
					String req_server = request.getParameter("server");
					String topparam=request.getParameter("er_check");
					session.setAttribute("topparam",topparam);
					String apptoptit="";
					if(s_application1!=null && s_application1.endsWith(".exe"))
						s_application1=s_application1.substring(0,s_application1.indexOf(".exe"));
					if((selectedCompArrays!=null && selectedCompArrays.length>0) || (s_server!=null && s_perserver.equals("No")&& (s_server.equals("-1") || aListAlltype.contains(s_server))))
					{
						String tit = s_farmserver+" "+intlmap.getTextDescription("reporter.thin."+er_option);
						if(er_option!=null && (er_option.equalsIgnoreCase("Group")||er_option.equalsIgnoreCase("Segment")||er_option.equalsIgnoreCase("Service")))
						{
							if(er_option.equalsIgnoreCase("Group")||er_option.equalsIgnoreCase("Segment"))
								tit=er_site+" "+intlmap.getTextDescription("reporter.thin."+er_option);
							else
								tit=er_site+" "+"service with accessing "+s_application1;
						}
						else if(er_option!=null && er_option.equalsIgnoreCase("Component"))
						{
							tit=intlmap.getComponentTypeDescription(s_compType)+" "+intlmap.getTextDescription("reporter.thin."+er_option);
						}
						apptoptit=s_application1;
						if(topparam!=null&&topparam.equals("true"))
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Users")+" "+tit;
						}
						else
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Top")+" "+intlmap.getTextDescription("reporter.thin.Users of")+" "+s_application1+ " "+intlmap.getTextDescription("reporter.thin.in")+" " +tit;
						}
					}
					else if(s_server!=null && s_perserver.equals("Yes")&& (aListAlltype.contains(s_server)))
					{
						String tit = s_server+" "+"of "+s_application1;
						apptoptit=s_application1;
						if(topparam!=null&&topparam.equals("true"))
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Users in")+" "+tit;
						}
						else
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Top")+" "+intlmap.getTextDescription("reporter.thin.Users")+" : "+tit;
						}
					}
					else if(s_server!=null && s_perserver.equals("Yes")&& (s_server.equals("-1")  || aListAlltype.contains(s_server)))
					{
						String tit = "in "+s_application1;
						apptoptit=s_application1;
						if(topparam!=null&&topparam.equals("true"))
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Users")+" "+tit;
						}
						else
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Top")+" "+intlmap.getTextDescription("reporter.thin.Users")+" "+tit;
						}
					}
					else if(s_server!=null&&s_perserver.equals("Yes")&&!s_server.equals("-1"))
					{
						String tit = s_server+" "+"of "+s_application1;
						apptoptit = s_application1;
						if(topparam!=null&&topparam.equals("true"))
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Users in")+" "+s_application1;
						}
						else
						{
							s_tit1 = intlmap.getTextDescription("reporter.thin.Top")+" "+intlmap.getTextDescription("reporter.thin.Users in")+" "+s_application1;
						}
					}
					session.setAttribute("titleapp",apptoptit);
					DrillDownReportData.put("title",s_tit1);
					JSONArray columnArray  =  new JSONArray();
					vec1.add(intlmap.getTextDescription("reporter.thin.Username"));
					columnArray.add(intlmap.getTextDescription("reporter.thin.Username"));
					String checking=request.getParameter("er_check");
					if(isVmComp){
						vec1.add(intlmap.getTextDescription("reporter.thin.VM Name"));
						columnArray.add(intlmap.getTextDescription("reporter.thin.VM Name"));
					}
					if (checking.equalsIgnoreCase("null"))
					{
						vec1.add(intlmap.getTextDescription("reporter.thin.No of measurements with access to ")+" "+s_application1);
						//columnArray.add(intlmap.getTextDescription("reporter.thin.No of measurements with access to ")+" "+s_application1);
						columnArray.add(intlmap.getTextDescription("reporter.thin.% of time accessed to ")+" "+s_application1);
					}
					int numTop = app_topusers.size();
					Vector v_pdf=new Vector();
					JSONArray dataArray =  new JSONArray();
					int count=0;
					for(int n=0; n < numTop; n++)
					{
						JSONArray datajson =  new JSONArray();
						HashMap data = (HashMap)app_topusers.get(n);
						String username = (String)data.get("user");
						String usercount = (String)data.get("usercount");
						String timePercentInDouble = (String)data.get("msmt_count"); 
						double timePerInDou =0.0;
						try{
							timePerInDou = Double.parseDouble(timePercentInDouble);
						}catch(Exception e){}
						if(timePerInDou<0.0)
						{
							count++;
							continue;
						}
						
						v_pdf.add(username);
						v_pdf.add(usercount);
						lst_dat1.add(username);
						datajson.add(username);
						if(isVmComp){
							String vmName = (String)data.get("vmname");
							lst_dat1.add(vmName);
							datajson.add(vmName);
						}
						if(checking==null || checking.equalsIgnoreCase("null"))
						{
							lst_dat1.add(usercount);
							datajson.add(timePerInDou);
						}
						dataArray.add(datajson);
					}
					if(count == numTop)
					{
						DrillDownReportData.put("dataAvailable",false);
					}
					else
					{
						DrillDownReportData.put("dataAvailable",true);
					}
					if(lst_dat1!=null && !lst_dat1.isEmpty())
					{
						sen1.put(vec1,lst_dat1);
						ht1=new Hashtable();
						ht1.put(s_tit1,sen1);
						System.out.println("CSV Map-Drill->"+ht1);
						lst.add(ht1);
			
						sen1 = new Hashtable();
						ht1 = new Hashtable();	
						vec1 = new Vector();
						lst_dat1 = new LinkedList();
					}
					DrillDownReportData.put("columnDetails",columnArray);
					DrillDownReportData.put("dataArray",dataArray);
					checking="";
					HashMap pdfdata=new HashMap();
					pdfdata.put("Top Users  : "+apptoptit,v_pdf);
					int xCoor[]=new int[]{100,100,200};
					int fieldWidth[]=new int[]{100,100,100};
					boolean fieldWidthInPercentage=true;
					TreeMap Map_param = new TreeMap();
					Map_param.put("pageLayout", "portrait");
					Map_param.put("fields","title,username,No of Logins");
					Map_param.put("display","$F{title},Username,No of Logins");
					Map_param.put("dataBag",pdfdata);
					Map_param.put("fieldWidthInPercentage", new Boolean(fieldWidthInPercentage));
					Map_param.put("xCoor", xCoor);
					Map_param.put("fieldWidth", fieldWidth);
					Vector extraparam=new Vector();
					extraparam.add(reportType);
					extraparam.add("From "+erd.s_stdate+" hrs "+""+" To "+erd.s_enddate+"  hrs");
					Vector vdata=new Vector();
					vdata.add(Map_param);
					vdata.add(extraparam);
					Hashtable ht_pdfdata=new Hashtable();
					ht_pdfdata.put("commandName","DynamicTest");
					ht_pdfdata.put("pdfData",applnPdfData);
					ht_pdfdata.put("pdfFileName","APPLICATION_REPORT");
					session.setAttribute("sessionVal", ht_pdfdata);
					HashMap param =new HashMap();
					param.put("REPORT_PARAM",ErUtils.parseQueryString(ErUtils.prepareQueryString(request.getParameterMap())));
					param.put("REPORT_DATA",applnPdfData);
					param.put("fileName","ApplicationActivityReport");
					session.setAttribute("parameters", param);
				}
				rootJson.put("DrillDownData",DrillDownReportData);
			}
		} //Graph View start here
		else if(v_qry_string!=null&&v_qry_string.size()>0)
		{
			JSONObject reportDataJson = new JSONObject();
			JSONArray chartUrls = new JSONArray();
			int count = 0;
			String s_title="";
			int flag=0;
			if(v_qry_string !=null)
			{
				for(int k=0;k<v_qry_string.size();k+=2) //New Fix
				{
					s_title = (String)v_qry_string.get(k);
					if(s_title.length() > 44)
					{
						flag++;
					}
				}
			}
			String Str_test ="";
			String Str_mes ="";
			String Str_units="";
			if(v_qry_string != null && v_qry_string.size() > 2)
			{
				String st_qryString = "";
				Vector  sqry = new Vector();
				sqry.add("opt");
				sqry.add("rtype");
				sqry.add("chartFor");
				for(int i=0;i<v_qry_string.size();i+=4)
				{
					s_title= (String)v_qry_string.get(i);
					if(s_title.indexOf("*")>-1)
						s_title = s_title.replace('*','%');
					st_qryString = (String)v_qry_string.get(i+1);
					//Adding the title and the URL of the image for saving to PDF
					count++;
					String theWidth = "";
					String theHeight = "";
					String isPie = reportInfo.getChartTypeForDist("APPLICATION_REPORT");
					if(isPie!=null && isPie.equalsIgnoreCase("Pie"))
					{
						theWidth = "740";
						theHeight = "250";
					}
					else
					{
						theWidth = "740";
						theHeight = "380";
					}
					st_qryString = st_qryString;
					String queryString = "";
					String 	queryStringdata="";
					String controlfile = st_qryString.substring(0,st_qryString.indexOf("?"));
					st_qryString = st_qryString.substring(st_qryString.indexOf("?")+1);
					HashMap param  = ErUtils.parseQueryString(st_qryString);
					Set s_param = param.keySet();
					Iterator i_param = s_param.iterator();
					while(i_param.hasNext())
					{
						String st_key = (String)i_param.next();
						String value = (String)param.get(st_key);
						if(st_key!=null&&st_key.equals("er_test"))
						{
							Str_test = value;
						}
						else if(st_key!=null&&st_key.equals("er_meas"))
						{
							Str_mes=value;
						}
						if(!sqry.contains(st_key))
						{
							queryStringdata+=st_key+ "=" + URLEncoder.encode(value) + "&";
						}
						if(st_key!=null&&st_key.equals("select_farm"))
						{
							queryString+=st_key+ "=" + EgURLEncoder.encode(value,"UTF-8") + "&";
						}
						else
						{
							queryString+=st_key+ "=" + URLEncoder.encode(value) + "&";
						}
					}
					Str_units = tablesInfo.getUnitForMeasure(Str_test,Str_mes);
					if(s_title!=null && s_title.equals("Number of unique users"))
					{
						s_title = intlmap.getTextDescription("reporter.common."+s_title) + " (Number)";
					}
					else
					{
						s_title = s_title + " ("+Str_units+")";
					}
					queryString = controlfile+"?"+queryString+"&startmin="+strmin+"&endmin="+enmin;
					queryStringdata = queryStringdata+"&startmin="+strmin+"&endmin="+enmin +"er_sortby=-1&optt=data&dataFor=distribution";
					session.setAttribute("distQryData",queryStringdata);
					reportDataJson.put("title",s_title);
					queryString=queryString+"&startdate="+s_st_time+"&enddate="+s_en_time+"&starthr="+s_st_hr+"&endhr="+s_en_hr;
					chartUrls.add(queryString+"&er_width=620&er_height=250&er_align=left&optt=graph&er_view=APPLET");
					if(v_qry_string.size() == (i + 2)){}
					else
					{
						theWidth = "740";
						theHeight = "380";
						s_title=(String)v_qry_string.elementAt(i+2);
						if(s_title.indexOf("*")>-1)
							s_title = s_title.replace('*','%');
						s_qryString = (String)v_qry_string.elementAt(i+3);
						String ertest = request.getParameter("er_test");
						String ermeas = request.getParameter("er_meas");
						String query_String="";
						controlfile = s_qryString.substring(0,s_qryString.indexOf("?"));
						query_String = s_qryString.substring(s_qryString.indexOf("?")+1);
						String qrydata = "";
						param  = ErUtils.parseQueryString(query_String);
						HashMap param1  = ErUtils.parseQueryString(query_String);
						String strSelectFarm = (String)param1.get("select_farm");
						param1.put("select_farm", EgURLEncoder.encode(strSelectFarm,"UTF-8"));
						query_String  = ErUtils.prepareQueryString(param1);
						s_param = param.keySet();
						i_param = s_param.iterator();
						String Tinfos[]=null;
						String er_test="";
						String er_meas="";
						while(i_param.hasNext())
						{
							String st_key = (String)i_param.next();
							String value = (String)param.get(st_key);
							if(st_key.equals("er_test"))
								er_test = value;
							if(st_key.equals("er_meas"))
								er_meas = value;
							if(!sqry.contains(st_key))
							{
								qrydata+=st_key+ "=" + URLEncoder.encode(value) + "&";
							}
						}
						Str_units = tablesInfo.getUnitForMeasure(er_test,er_meas);
						if(s_title!=null && s_title.equals("Number of unique users"))
						{
							s_title = s_title + " (Number)";
						}
						else
						{
							s_title = s_title + " ("+Str_units+")";
						}
						query_String = controlfile+"?"+query_String;
						qrydata = qrydata +"er_sortby=-1&optt=data";
						//Adding the title and the URL of the image for saving to PDF
						count++;
						session.setAttribute("topQryData",qrydata);
						chartUrls.add(query_String+"&startmin="+strmin+"&endmin="+enmin + "&er_width=" + theWidth + "&er_height=" + theHeight + "&er_align=center&optt=graph&er_view=APPLET");
					}
				}
			}
			HashMap param =new HashMap();
			param.put("REPORT_PARAM",ErUtils.parseQueryString(ErUtils.prepareQueryString(request.getParameterMap())));
			param.put("REPORT_DATA",pdfQuery);
			param.put("fileName","ApplicationActivityReport");
			session.setAttribute("parameters", param);
			reportDataJson.put("chartUrls",chartUrls);
			rootJson.put("reportData",reportDataJson);
		}
		session.setAttribute("htdat",htt);
		sen1 = new Hashtable();
		session.setAttribute("list",lst);
		
		String processVal="";
		if(rtype!=null && rtype.equals("Yes"))
		{
			processVal="&printGraph=yes&opt=chart&uid="+EgURLEncoder.encode(loginid,"UTF-8")+ "&select_testmes=" +EgURLEncoder.encode(testmes,"UTF-8")+"&er_type=yes&er_sortby=-1";
		}
		else
		{
			processVal="&er_view=PRINT&";
		}
		String strEncodeselect_farm = request.getParameter("select_farm");
		String strTime = request.getParameter("startdate");
		String enTime = request.getParameter("enddate");
		if(request.getParameter("select_farm") != null)
			strEncodeselect_farm = EgURLEncoder.encode(request.getParameter("select_farm"),"UTF-8");
		String strEncodetimeline = timeline;
		if(timeline != null)
			strEncodetimeline = EgURLEncoder.encode(timeline,"UTF-8");
		String strEncodestrTime = strTime;
		if(strTime != null)
			strEncodestrTime = EgURLEncoder.encode(strTime,"UTF-8");
		String strEncodeenTime = enTime;
		if(enTime != null)
			strEncodeenTime = EgURLEncoder.encode(enTime,"UTF-8");
		String strEncodeer_server = request.getParameter("er_server");
		if(request.getParameter("er_server") != null)
			strEncodeer_server = EgURLEncoder.encode(request.getParameter("er_server"),"UTF-8");
		String strEncodesel_mes = "";
		if(request.getParameter("select_testmes") != null)
			strEncodesel_mes = EgURLEncoder.encode(request.getParameter("select_testmes"),"UTF-8");

		if(strTime !=null && enTime !=null)
		{
			String dataProcess = mngrIProc+"/final/servlet/com.eg.ErCtxServerReportC;jsessionid="+session.getId()+"?er_rtype=CtxApplication&er_gtype=Citrix&er_trgttype="+EgURLEncoder.encode(reportType,"UTF-8")+"&select_farm="+strEncodeselect_farm+"&er_application="+request.getParameter("er_application")+"&er_timeline="+strEncodetimeline+"&startdate="+strEncodestrTime+"&enddate="+strEncodeenTime+"&timefrom="+request.getParameter("timefrom")+"&timeto="+request.getParameter("timeto")+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&startmin="+strmin+"&endmin="+enmin+"&er_compType=" + s_compType+"&er_excwe="+excludeweekend+"&minfrom="+request.getParameter("minfrom")+"&minto="+request.getParameter("minto")+"&currTime="+request.getParameter("currTime")+"&er_perserver="+request.getParameter("er_perserver")+"&sel_mes="+strEncodesel_mes+"&er_mode="+request.getParameter("er_mode")+processVal+"&er_option="+er_option+"&er_site="+er_site+"&application_user_details_report="+isApplicationsUserReport+"&group_by_component="+groupByComponent+"&er_sortby="+s_sort;

			session.setAttribute("MAIL_URL",dataProcess);
		}
		Map parameters = new HashMap();
		parameters= request.getParameterMap();
		String queryString =(String)ErUtils.prepareQueryString(request.getParameterMap());
		String Qstring="";
		String lastaccUrl="";
		if(queryString!=null)
		{
			StringTokenizer strtok = new StringTokenizer(queryString,"&");
			while(strtok.hasMoreTokens())
			{
				String param = strtok.nextToken();
				int ind = param.indexOf("=");
				String reqparam =param.substring(0,ind);
				String value = param.substring(ind+1);
				if(reqparam!=null&&reqparam.equals("select_farm"))
				{
					value=com.eg.EgURLEncoder.encode(value, "UTF-8");
				}
				if(reqparam!=null&&reqparam.equals("userID"))
				{
					value=com.eg.EgURLEncoder.encode(value, "UTF-8");
				}
				if(reqparam!=null&&reqparam.equals("uid"))
				{
					value=com.eg.EgURLEncoder.encode(value, "UTF-8");
				}
				if(reqparam!=null && ( reqparam.equals("startdate") || reqparam.equals("enddate") || reqparam.equals("inidate") || reqparam.equals("pdfTime") || reqparam.equals("select_testmes") ) )
				{
					value=com.eg.EgURLEncoder.encode(value, "UTF-8");
				}
				lastaccUrl=lastaccUrl+reqparam+"="+value+"&";
				if(reqparam!=null&&reqparam.equals("er_application"))
				{
					continue;
				}
				if(reqparam!=null&&reqparam.equals("er_workgroupserver"))
				{
					continue;     
				}
			if(reqparam!=null&&reqparam.equals("filterValue"))
			{
				continue;     
			}
				if(reqparam!=null&&reqparam.equals("er_server"))
				{
					continue;
				}
				Qstring=Qstring+reqparam+"="+value+"&";
			}
		}
		rootJson.put("saveQString",Qstring);
		//Back button - Start
		ArrayList listbackvar = new  ArrayList();
		if(request.getParameter("isSubmit")!=null)
		{
			listbackvar.add("ErThinClientApplication.jsp");
			listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
			session.setAttribute("favSchBackDisplay","Yes");
		}
		else
		{
			listbackvar.add("ErThinClientApplication.jsp");
			listbackvar.add(queryString);
			session.setAttribute("favSchBackDisplay","No");
		}
		session.setAttribute("reportLastAccessedURL","/final/reporter/ErThinClientApplication.jsp?"+lastaccUrl);
		String backadded = erhelputils.getBackID();
		backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
		session.setAttribute("backQuery",backreqMap);
		session.setAttribute("PDF_URL", mngrIProc+"/final/servlet/com.eg.ErCtxServerReportC");

		rootJson.put("hiddenfields",hiddenfieldsJson);
		rootJson.put("screenLabels",screenLabelJson);
		rootJson.put("viewReportFor","application_activity");
		out.println(rootJson.toString());
	}
	catch(Throwable t)
	{
		t.printStackTrace();
	}
%>
<%!
public synchronized JSONArray getJSONComboFromList(List list,String infoVal,EgMappingInfo intlmap)
{
	JSONArray arr=new JSONArray();
	JSONObject obj=null;
	if(list !=null && list.size()>0)
	{
		for (int i=0;i<list.size();i++)
		{
			String text=(String)list.get(i);
			obj=new JSONObject();
			obj.put("displayField",text);
			obj.put("valueField",text);
			arr.add(obj);
		}
	}
	else
	{
		obj=new JSONObject();
		obj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
		obj.put("valueField","-1");
		arr.add(obj);
	}
	return arr;
}
protected List getReArrangedComponents(boolean isComponentTypeFirst,List v_comps)
{
	Vector v_componentCorrectFormat = new Vector();
	if (isComponentTypeFirst)
	{
		for(int i=0; i<v_comps.size(); i++) 
		{
			String loopComponent = (String) v_comps.get(i);
			String strcompname = loopComponent.substring(0,loopComponent.lastIndexOf(":"));
			String strcomptype = loopComponent.substring(loopComponent.lastIndexOf(":")+1,loopComponent.length());
			String correctFormat = strcomptype + ":" + strcompname;
			v_componentCorrectFormat.add(correctFormat);
		}
	}
	else
	{
		for(int i=0; i<v_comps.size(); i++) 
		{
			String loopComponent = (String) v_comps.get(i);
			String strcomptype = loopComponent.substring(0,loopComponent.indexOf(":"));
			String strcompname = loopComponent.substring(loopComponent.indexOf(":")+1,loopComponent.length());
			String correctFormat = strcompname + ":" + strcomptype;
			v_componentCorrectFormat.add(correctFormat);
		}
	}
	v_comps = v_componentCorrectFormat;
	return v_comps;
}
	public JSONArray getAllInformationForUser(JSONArray gridDataArray, Vector v_iconData, JSONArray colArray, String groupByComponent)
	{
		JSONArray aListDataArray = new JSONArray();
		try
		{
			int userCount = 2;
			if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("Yes"))
			{
				userCount = 3;
			}
			for(int cnt=0;cnt<gridDataArray.size();cnt++)
			{
				JSONObject aRowObj = new JSONObject();
				JSONArray aColumnArray = new JSONArray();
				JSONObject colObj = new JSONObject();
				JSONObject appObj = (JSONObject)gridDataArray.get(cnt);
				Iterator itr = appObj.keySet().iterator();
				ArrayList vIconData = (ArrayList)v_iconData.get(cnt);
				String tempValue="";
				while(itr.hasNext())
				{
					String rowCount = (String)itr.next();
					if(Integer.parseInt(rowCount) < userCount)
					{
						String value = (String)appObj.get(rowCount);
						if(groupByComponent!=null && groupByComponent.equalsIgnoreCase("Yes") && Integer.parseInt(rowCount) == 0)
						{
							tempValue += value+"\\";
						}
						else if((groupByComponent!=null && groupByComponent.equalsIgnoreCase("Yes") && Integer.parseInt(rowCount) == 2) || (groupByComponent!=null && groupByComponent.equalsIgnoreCase("no") && Integer.parseInt(rowCount) == 1))
						{
							tempValue += " - Unique User : "+value+"&nbsp;&nbsp;";
						}
						else
						{
							tempValue += value+"";
						}
					}
				}
				if(tempValue!=null)
				{
					tempValue = tempValue.trim();
				}
				for(int dataCnt=0;dataCnt<vIconData.size();dataCnt++)
				{
					JSONArray dataArray = new JSONArray();					
					HashMap aListMap = (HashMap)vIconData.get(dataCnt);
					for(int tempCnt=0;tempCnt<colArray.size();tempCnt++)
					{
						String strTempCol = (String)colArray.get(tempCnt);
						String strHashCol = (String)aListMap.get(strTempCol);
						dataArray.add(strHashCol);
					}
					aColumnArray.add(dataArray);
				}
				aRowObj.put("tableTitle",tempValue);
				aRowObj.put("measureColumn",colArray);
				aRowObj.put("measureTable",aColumnArray);
				aListDataArray.add(aRowObj);
			}
		}
		catch(Exception exc)
		{
			System.out.println("Problem in Updating and exception is : "+exc.getMessage());
			exc.printStackTrace();
		}
		return aListDataArray;
	}
%>