<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "com.eg.EgGroupInfo" %>
<%@ page import = "com.eg.EgURLDecoder" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgTestInfo"%>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "java.awt.Color"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page import = "net.sf.json.*" %>
<%@ page import = "com.eg.EgAgentInfo" %>

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

	JSONObject rootJson = new JSONObject();
	JSONObject screenLabelJson = new JSONObject();
	JSONObject hiddenfieldsJson=new JSONObject();
	JSONObject loopJsonObj = new JSONObject();
	//Back Button - Start
	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");
	HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
	String backQnumber = request.getParameter("backQnumber");
	String servlet2 = request.getParameter("backServletName");
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	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 queryString="";

	String backButtonEnable = request.getParameter("back");
	if(backButtonEnable != null && backButtonEnable.equalsIgnoreCase("True"))
	{
		status = (String)request.getParameter("status");
		bggroundStr = (String)request.getParameter("bggroundStr");
		request.setAttribute("APPLICATION_USAGE_REPORT", null);
	}
		//Back Button - End
	try
	{
		String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
		String uiFile = "eg_ui.ini";
		ErUtils erUtils = new ErUtils();
		ErReportHelper erh = new ErReportHelper();
		com.eg.IniFile egUI = new com.eg.IniFile(s_iniFile_dir + uiFile);
		com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();
		EgDateInfo egDt = new EgDateInfo();
		EgReportInfo reportInfo = new EgReportInfo("manager");
		EgGroupInfo gpinfo = new EgGroupInfo();
		ErInfo erInfo = new ErInfo();
		EgDiscInfo discInfo = new EgDiscInfo("manager");
		ErComponentsUtils compUtil = new ErComponentsUtils(thisuser.getLoginID());
		EgTestInfo tokInfo = new EgTestInfo("manager");
		EgMappingInfo intlmap = new EgMappingInfo(thisuser.getLanguage());
	
		String reqFromSchedule = request.getParameter("fromSchedule");
		String fromScheduleModify = request.getParameter("fromScheduleModify");
		String er_favorite = request.getParameter("er_favorite");
		String fromFavoriteModify = request.getParameter("fromFavoriteModify");
		String favorite_id = request.getParameter("id");
		String showLegend = request.getParameter("showLegend");
		String erServer = request.getParameter("er_server");
		String er_graphViews = request.getParameter("er_graphViews");
		
		boolean isBackgroundProcess = false;
		String BLANK_SPACE = " ";
		String COMA = ",";
		String COLON = ":";
		String UTF_8 = "UTF-8";
		String timefrom="";
		String minfrom="";
		String timeto="";
		String minto="";
		String dispDate = null;
		String comFormat = null;
		String er_timeline = request.getParameter("er_timeline");
		String s_st_time = request.getParameter("er_stdate");
		String s_en_time = request.getParameter("er_enddate");

		if(s_st_time == null)
			s_st_time = request.getParameter("startdate");
		if(s_en_time == null)
			s_en_time = request.getParameter("enddate");
		String s_st_time_graph = null;
		if(s_st_time != null)
		{
			s_st_time_graph = new String(s_st_time);
		}
		String s_en_time_graph = null;
		if(s_en_time != null)
		{
			s_en_time_graph = new String(s_en_time);
		}
		if(er_timeline==null  || er_timeline.equals(" "))
		{
			er_timeline="1 day";
		}
		String s_st_hr = request.getParameter("starthr");
		String s_en_hr = request.getParameter("endhr");
		String s_inidate = request.getParameter("inidate");
		String strmin = request.getParameter("startmin");
		String enmin = request.getParameter("endmin");
		String s_farmserver = request.getParameter("er_zone");
		String s_compType = request.getParameter("er_compType");
		String[] s_application = request.getParameterValues("er_application");
		String applicationName = request.getParameter("er_application");
		String strWorkgrpName = request.getParameter("er_workgrpname");
		String[] selectedCompArray = request.getParameterValues("er_component");
		String isSubmit = request.getParameter("isSubmit");
		String schedule_id = request.getParameter("schedule_id");
		List selectedApplication = new ArrayList();
		List selectedComponent = new ArrayList();
		String isBackUrlClick = request.getParameter("backUrlClick");
		String fromMenu = request.getParameter("from_menu");
		String tempMode = request.getParameter("er_mode");
		String tempOption = request.getParameter("option");
		ArrayList singleColors = (ArrayList)request.getAttribute("singleColors");
		ArrayList singleSelection = (ArrayList)request.getAttribute("singleSelection");
		List nwDevices = discInfo.getAllNetworkDevices();
		Vector v_comp_popup = new Vector();
		Vector v_comp_popup_disp = new Vector();
		String divStatus = request.getParameter("divStatus");
		String srcForImg="";
		List v_serverName=new ArrayList();
		//check
		if(applicationName!=null)
			applicationName = erUtils.specialCharDecode(applicationName);
		//
		if(divStatus==null)
		{
			divStatus="none";
		}
		if(divStatus.equals("none"))
		{
			srcForImg="/final/images/moreoption.png";
		}
		else if(divStatus.equals("block"))
		{
			srcForImg="/final/images/lessoption.png";
		}
		if(s_application != null)
			selectedApplication = Arrays.asList(s_application);
		if(selectedCompArray != null)
			selectedComponent  = Arrays.asList(selectedCompArray);
		List selectedCompList = new ArrayList();
		String excludeweekend ="";
		boolean noDataFound = true;
		Map resultMap = (Map) session.getAttribute("APPLICATION_USAGE_REPORT");
		if(resultMap != null && isSubmit != null && isSubmit.equalsIgnoreCase("true"))
		{
			Boolean noData = ((Boolean) resultMap.get("NO_DATA_FOUND"));
			if(noData != null)
				noDataFound = noData.booleanValue();
		}
		String dispCsvStartDate = s_st_time+" "+s_st_hr+" : "+strmin;
		String dispCsvEndDate = s_en_time+" "+s_en_hr+" : "+enmin;
		if(selectedCompArray != null) 
		{
			for (int i = 0; i < selectedCompArray.length; i++) 
			{
				try 
				{
					selectedCompList.add(EgURLDecoder.decode(selectedCompArray[i], "UTF-8"));
				}
				catch (Exception e1) {}
			}
		}
		String startDateTime="";
		String endDateTime="";
		String disable="";
		long msecsPerHour = (long) 1000 * 60 * 60;
		String currentDateFormat =strUserDateFormat;
		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"))
				{//weeks
					value *= (7 * 24 * 3600);
				}
				else if (unit.startsWith("mo"))
				{//months
					java.util.Date dt_temp = egDt.egetRealDate();
					Calendar cal_temp = new GregorianCalendar();
					cal_temp.setTime(dt_temp);
					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 = new java.util.Date();
					java.util.Date startTmp=new java.util.Date(endDateTime);
					start.setTime(startTmp.getTime() - (value * 1000));
					startDateTime = sdf.format(start);
				}
			}
			if ((startDateTime != null) && (endDateTime != null))
			{
				s_inidate="MM/dd/yyyy";
				try
				{
					int shr=Integer.parseInt(startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, startDateTime.indexOf(COLON)));
					strmin=startDateTime.substring(startDateTime.indexOf(COLON)+1);
					int en_hr=Integer.parseInt(endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, endDateTime.indexOf(COLON)));
					enmin=endDateTime.substring(endDateTime.indexOf(COLON)+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);
				}
				catch(Exception e)
				{
					e.printStackTrace();
				}
			}
		}
		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(new java.util.Date());
			}
			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;
				s_inidate="MM/dd/yyyy";
			}
			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[] 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"};
		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("25");
		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 timefrom1=(erh.getTimeFrame("TIMEFRAME","From")==null) ? "00:00" :erh.getTimeFrame("TIMEFRAME","From");
		String timeto1=(erh.getTimeFrame("TIMEFRAME","To")==null) ? "23:59" :erh.getTimeFrame("TIMEFRAME","To");
		timefrom1 = reportInfo.getValue("APPLICATION_USAGE_REPORT","FROM");
		timeto1 = reportInfo.getValue("APPLICATION_USAGE_REPORT","TO");
		StringTokenizer st;
		if(timefrom1 != null)
		{
			 st = new StringTokenizer(timefrom1,":");
			if(st.hasMoreTokens())
			{
				timefrom=st.nextToken();
				minfrom=st.nextToken();
			}
		}
		if(timeto1 != null)
		{
			st=new StringTokenizer(timeto1,":");
			if(st.hasMoreTokens())
			{
				timeto=st.nextToken();
				minto=st.nextToken();
			}
		}
		String timefrom2 = request.getParameter("timefrom");
		String minfrom2 = request.getParameter("minfrom");
		String timeto2 = request.getParameter("timeto");
		String minto2 = request.getParameter("minto");
		String stmin = "00";
		if (timefrom2!=null)
			timefrom = timefrom2;
		if (minfrom2!=null)
			minfrom = minfrom2;
		if (timeto2!=null)
			timeto = timeto2;
		if (minto2!=null)
			minto = minto2;
		ArrayList aListSupportedComponentType = reportInfo.getComponentsList("APPLICATION_USAGE_REPORT",false);
		ArrayList aListAlltype = new ArrayList();
		for(int kk=0;kk<aListSupportedComponentType.size();kk++)
		{
			aListAlltype.add(aListSupportedComponentType.get(kk));
		}
		String er_option =request.getParameter("er_option");
		String er_site = request.getParameter("er_site");
		if(er_option == null || er_option.isEmpty())
		{
			 er_option = "Zone";
		}
		User this_user = UserRegistry.getInstance().getUser(session.getId());
		String loginid = this_user.getLoginID();
		List v_option = new ArrayList();
		Hashtable htAllGroups=erEsxUtils.getGroups(null,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);
		List aListComponentTemp=null;
		String confrimation = reportInfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
		String strbgrepportName = reportInfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
		String limitforbg = reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
		status = (String)request.getAttribute("status");
		List v_site=new ArrayList();
		Vector v_zone = new Vector();
		Vector v_componentType = new Vector();
		Vector v_component = compUtil.getAllUserComponents1();
		List aTemp = compUtil.getUserZones();
		if(aTemp != null && aTemp.contains("--Default--"))
			aTemp.remove("--Default--");
		String zones[] = new String[aTemp.size()];
		for(int l=0;l<aTemp.size();l++)
		{
			zones[l] = (String)aTemp.get(l);
		}
		List zonelist = aTemp;
		Vector v_zonelist = new Vector();
		ArrayList listSupportedComponentType = new ArrayList();
		v_zonelist.addAll(zonelist);
		String componentTypes = reportInfo.getValue("APPLICATION_USAGE_REPORT","ComponentsWithTest");
		StringTokenizer stk = new StringTokenizer(componentTypes,",");
		while(stk.hasMoreTokens())
		{
			String tempStr = stk.nextToken();
			tempStr = tempStr.substring(0,tempStr.indexOf(COLON));
			listSupportedComponentType.add(tempStr);
		}
		v_zone = erUtils.getAllThinClientZones(zones,v_zonelist,v_component,listSupportedComponentType);
		if((v_zone != null) && v_zone.size() > 1)
		{
			Collections.sort(v_zone);
		}
		if(v_zone != null && !v_zone.isEmpty() && s_farmserver == null)
		{
			s_farmserver = (String)v_zone.get(0);
		}
		//-report by combo for zone, segment, service & component
		if (er_option!=null)
		{
			v_site = erEsxUtils.getGroupsName(htAllGroups,er_option);
			if(v_site!=null )
				Collections.sort(v_site,String.CASE_INSENSITIVE_ORDER);
			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);
				rootJson.put("siteCombo",getJSONComboFromList(v_site,"",intlmap));
				rootJson.put("siteComboLabel",er_option);
				rootJson.put("selectedSiteCombo",er_site);
			}
			else if(er_option.equals("Zone"))
			{
				v_site = erEsxUtils.getGroupsName(htAllGroups,er_option);
				if(v_site!=null)
					v_zonelist.addAll(v_site);
				if(s_farmserver==null && v_site!=null && v_site.size()>0)
				{
					s_farmserver=(String)v_site.get(0);
				}
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,s_farmserver);
				rootJson.put("selectedZone",s_farmserver);
			}
			else if(er_option.equals("Component"))
			{
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,null);
			}
		}
		if(aListComponentTemp!=null && aListComponentTemp.size()>0)
		{
			v_serverName = 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(v_serverName!=null && !v_serverName.contains(loopType))
						v_serverName.add(loopType);
						
				}
			}
		}
		Collections.sort(v_serverName,String.CASE_INSENSITIVE_ORDER);
			// for component types [Component Type Combo]
		JSONArray comptypeArray = new JSONArray();
		if(er_option.equals("Zone"))
		{
			aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,s_farmserver);
		}
		else if (er_option.equals("Group")||er_option.equals("Segment")||er_option.equals("Service"))
		{
			aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,er_site);
		}
		else
		{
			aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,null);
		}
		if(aListComponentTemp != null)
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Please choose a Component Type"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
		}
		if(aListComponentTemp!=null && !aListComponentTemp.isEmpty())
		{
			for(int n=0;n<aListComponentTemp.size();n++)
			{
				String comp = (String)aListComponentTemp.get(n);
				int index=comp.lastIndexOf(":");
				if(index>-1)
				{ 
					String  ctype = comp.substring(index+1); 
					if(!v_serverName.contains(ctype))
					{
						v_serverName.add(ctype);
					}
				}
			}
			for(int n=0;n<v_serverName.size();n++)
			{
				String ctype = (String) v_serverName.get(n);
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getComponentTypeDescription(ctype));
				loopJsonObj.put("valueField",ctype);
				comptypeArray.add(loopJsonObj);
			}
			if(s_compType==null && v_serverName!=null && v_serverName.size()>0)
			{
				s_compType=(String)v_serverName.get(0);
				rootJson.put("selectedCompType",s_compType);
			}
			else
			{
				rootJson.put("selectedCompType",s_compType);
			}
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
		}
		rootJson.put("compTypeCombo",comptypeArray);
		JSONArray compArray = new JSONArray();
		JSONArray selectedComponents = new JSONArray();
		Collections.sort(v_serverName,String.CASE_INSENSITIVE_ORDER);
		List componentsList=new ArrayList();
		if(aListComponentTemp!=null && !aListComponentTemp.isEmpty())
		{
			for(int n=0;n<aListComponentTemp.size();n++)
			{
				String comp = (String) aListComponentTemp.get(n);
				if(comp!=null && comp.lastIndexOf(":")>-1)
				{
					String strTempType = comp.substring(comp.lastIndexOf(":")+1);
					if(!strTempType.equalsIgnoreCase(s_compType))
						continue;
				}
				if(comp.endsWith(s_compType))
				{
					componentsList.add(comp);
				}
			}
		}
		if(componentsList!= null && componentsList.size() >0)
		{
			for(int n=0;n<componentsList.size();n++)
			{
				String loopComponent = (String) componentsList.get(n);
				if(loopComponent.lastIndexOf(":")>-1)
				{
					String loopComp = loopComponent.substring(0,loopComponent.lastIndexOf(":"));
					String tempComp = loopComp.substring(0,loopComp.indexOf(":"));
					String tempPort = loopComp.substring(loopComp.indexOf(":")+1);
					if(tempPort.equalsIgnoreCase("null"))
					loopComp = tempComp;
					String selected = "";
					if(selectedCompList.size() == 0 || selectedCompList.contains("-1") || selectedCompList.contains(componentsList.get(n)))
					{
						selectedComponents.add(componentsList.get(n));
						selected = " selected ";
					}
					v_comp_popup.add(loopComponent);
					v_comp_popup_disp.add(loopComp);
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",loopComp);
					loopJsonObj.put("valueField",loopComponent);
					compArray.add(loopJsonObj);
					rootJson.put("selectedComponents",selectedComponents);
				}
			}
		}
		else
		{
			v_comp_popup.add("-1");
			v_comp_popup_disp.add("Not Applicable");
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			compArray.add(loopJsonObj);
		}
		rootJson.put("componentCombo",compArray);
		ArrayList v_Workgroupcomponents = new ArrayList();
		ArrayList aListworkGrp = new ArrayList();
		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_component!=null && v_component.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_component.size();aa++)
					{
						String strVar =  agentInfo.getValueForVar(strTestName+"::"+v_component.get(aa));
						if(strVar!=null && strVar.length()>0)
						{
							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)
		{
			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);
		}
		if(v_appgrp!=null && v_appgrp.size()>0)
		{
			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";
		}  
		// for component name
		v_component = new Vector();
		if(s_compType != null && !s_compType.equalsIgnoreCase("-1"))
		{
			if(!s_compType.equals("Host_system")) 
			{
				List removeList = new ArrayList();
				for(int i=0; i<v_component.size(); i++) 
				{
					String temp_component = (String)v_component.get(i);
					if(-1 == temp_component.indexOf(s_compType)) 
					{
						removeList.add(temp_component);
					}
				}
				v_component.removeAll(removeList);
			}
				// added for component selection based on zone
			Vector temp_Component = new Vector();
			String includezone = "yes";
			List listCompTypes =reportInfo.getComponent("APPLICATION_USAGE_REPORT",false);
			Vector tempComponent = new Vector();
			tempComponent.addAll(v_component);
			for(int i=0; i<tempComponent.size(); i++)
			{
				String loopComponent = (String) tempComponent.get(i);
				String loopType = loopComponent.substring(0, loopComponent.indexOf(":"));
				if(!listCompTypes.contains(loopType))
				{
					v_component.remove(loopComponent);
				}
			}
			tempComponent = new Vector();
			Vector newComponent = new Vector();
			tempComponent.addAll(v_component);
			for(int i=0; i<tempComponent.size(); i++)
			{
				String loopComponent = (String) tempComponent.get(i);
				String type = loopComponent.substring(0,loopComponent.indexOf(":"));
				String comp = loopComponent.substring(loopComponent.indexOf(":")+1);
				loopComponent = comp+":"+type;
				newComponent.add(loopComponent);
			}
			v_component.removeAllElements();
			v_component.addAll(newComponent);
		}
		//Application combo
		Vector v_application=new Vector();
		if(selectedComponent!=null && selectedComponent.size()>0)
		{
			selectedCompList=selectedComponent;
		}
		else if(componentsList  != null && componentsList.size() >0)
		{
			 selectedCompList=componentsList;
		}
		if (s_compType!= null && !selectedCompList.isEmpty())
		{
			if (selectedCompList !=null)
			{
				v_application=new Vector();
				for (int i=0;i<selectedCompList.size();i++)
				{
					Vector v_app=new Vector();
					String server=(String)selectedCompList.get(i);
					String strComponentType = s_compType;
					String strTest = "";
					String compWithTest = reportInfo.getValue("APPLICATION_USAGE_REPORT","ComponentsWithTest");
					StringTokenizer testTK = new StringTokenizer(compWithTest,",");
					while(testTK.hasMoreTokens())
					{
						String tempStr = testTK.nextToken();
						String tempTest = tempStr.substring(tempStr.indexOf(COLON)+1);
						tempStr= tempStr.substring(0,tempStr.indexOf(COLON));
						if(tempStr.equalsIgnoreCase(s_compType))
						strTest = tempTest;
					}
					if(listSupportedComponentType!=null && listSupportedComponentType.contains(strComponentType))
					{
						if(erServer!=null)
							server =erServer;
						//..split the server with comma for selected servers
						ArrayList serverArry=ErUtils.egTokenizer(server,",");
						for(int s=0;s<serverArry.size();s++)
						{
							String eachServer=(String)serverArry.get(s);
							v_app.addAll(erInfo.getInfosForTest("NULL",strTest,eachServer));
						}						
					}
					v_app = ErUtils.formatString(v_app,"$0+$1","$1");
					for (int j=0;j<v_app.size();j++)
					{
						String app=(String)v_app.get(j);
						if (!v_application.contains(app))
							v_application.add(app);
					}
				}
			}
		}
		if(s_compType != null && !s_compType.equals("-1") &&!s_compType.equals("NotApplicable") && aListComponentTemp.contains(s_compType)) 
		{
			if(!s_compType.equals("Host_system")) 
			{
				List removeList = new ArrayList();
				for(int i=0; i<v_component.size(); i++) 
				{
					String v_comp = (String)v_component.get(i);
					if(-1 == v_comp.indexOf(s_compType)) 
					{
						removeList.add(v_comp);
					}
				}
				v_component.removeAll(removeList);
			}
		}
		if(strWorkgrpName != null && !strWorkgrpName.equalsIgnoreCase("Any"))
		{
			v_component = new Vector();
			String strTest = reportInfo.getTestName("APPLICATION_REPORT",s_compType,false);
			ArrayList aListCompGrp = erInfo.getServersForWorkGroup(strTest,strWorkgrpName,true);
			if(aListCompGrp!=null && aListCompGrp.size()>0)
			{
				Vector v_UserComponent = compUtil.getAllUserComponents1();
				for(int i=0; i<v_UserComponent.size(); i++) 
				{
					String loopComponent = (String) v_UserComponent.get(i);
					if(aListCompGrp.contains(loopComponent))
						v_Workgroupcomponents.add(loopComponent);
				}
			}
		}
		if(v_Workgroupcomponents!=null && v_Workgroupcomponents.size()>0)
		{
			if(strWorkgrpName != null && !strWorkgrpName.equalsIgnoreCase("Any"))
			{
				v_component.addAll(v_Workgroupcomponents);
				if(selectedCompArray == null || selectedCompArray.length ==0 )
				{
					selectedCompList = new ArrayList();
					selectedCompList.addAll(v_Workgroupcomponents);
					selectedCompArray = new String[selectedCompList.size()];
					selectedCompArray = (String[])selectedCompList.toArray((new String[selectedCompList.size()]));
				}
			}
		}
		if(aListworkGrp!=null && aListworkGrp.size()>0)
		{
			if(strWorkgrpName != null && !strWorkgrpName.equalsIgnoreCase("Any"))
			{
				v_application=new Vector();
				Vector v_app=new Vector();
				if(selectedCompArray!=null && selectedCompArray.length>0)
				{
					for(int ii=0;ii<selectedCompArray.length;ii++)
					{
						String strComp = selectedCompArray[ii];
						String strComponentType = s_compType;
						if(strComp!=null && strComp.lastIndexOf(":")>-1)
						{
							strComp = strComp.substring(0,strComp.lastIndexOf(":"));
							strComponentType = strComp.substring(strComp.lastIndexOf(":")+1);
						}
						String strTest = reportInfo.getTestName("APPLICATION_REPORT",strComponentType,false);
						ArrayList aListCompGrp = erInfo.getApplicationForWorkgroup(strTest,strWorkgrpName,strComp);
						if(aListCompGrp!=null)
							v_app.addAll(aListCompGrp);
					}
				}
				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);
				}
			}
		}
		hiddenfieldsJson.put("inidate",currentDateFormat);
		hiddenfieldsJson.put("currTime","");
		hiddenfieldsJson.put("er_ViewName","ErThinClientApplication.jsp");
		if(reqFromSchedule!=null)
			hiddenfieldsJson.put("fromSchedule",reqFromSchedule);
		else
			hiddenfieldsJson.put("fromSchedule","null");

		if(fromScheduleModify!=null)
			hiddenfieldsJson.put("fromScheduleModify",fromScheduleModify);
		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("showLegend", showLegend);
		hiddenfieldsJson.put("er_graphViews", er_graphViews);
		hiddenfieldsJson.put("uid",EgURLEncoder.encode(loginid,"UTF-8"));
		hiddenfieldsJson.put("userID",EgURLEncoder.encode(loginid,"UTF-8"));
		hiddenfieldsJson.put("getMaxDaysInMonth",String.valueOf(ErUtils.getMaxDaysInMonth()));
		hiddenfieldsJson.put("forwardto","ErAppUsageReportJson");
		hiddenfieldsJson.put("bgenabled",strbgrepportName);
		hiddenfieldsJson.put("limitforbg",limitforbg);
		hiddenfieldsJson.put("savereport","save");
		hiddenfieldsJson.put("servletName","com.eg.ErAppUsageReportC");
		hiddenfieldsJson.put("singleselection",singleSelection);
		hiddenfieldsJson.put("singlecolors",singleColors);

		if(singleSelection!=null)
			hiddenfieldsJson.put("singleselection",singleSelection);
		else
			hiddenfieldsJson.put("singleselection","null");

		if(singleColors!=null)
			hiddenfieldsJson.put("singlecolors",singleColors);
		else
			hiddenfieldsJson.put("singlecolors","null");

		hiddenfieldsJson.put("er_rtype","Thin Client");
		hiddenfieldsJson.put("er_trgttype","Application Usage");
		hiddenfieldsJson.put("isFavorite","false");
		hiddenfieldsJson.put("isSchedule","false");
		hiddenfieldsJson.put("er_bgreportfrom","Thin_Client_Applicaion_Usage");
		hiddenfieldsJson.put("er_trenddata","No");
		hiddenfieldsJson.put("er_gtype","Application Usage");
		hiddenfieldsJson.put("divStatus",divStatus);
		if(er_graphViews==null)
			er_graphViews="Area";
		rootJson.put("selectedGraph",er_graphViews);
		String isSubmitted =request.getParameter("isSubmit");
		rootJson.put("isSubmit",isSubmitted);

		rootJson.put("reportTitle",intlmap.getTextDescription("reporter.common.THIN CLIENT REPORTS")+" - "+intlmap.getTextDescription("reporter.common.APPLICATION INSTANCE"));
		String strwidth = "90%";
		if(backreqMap == null || backreqMap != null && backreqMap.size() == 0)
			strwidth="100%";
		String fromFavSch = request.getParameter("fromFavSch");
		if(backreqMap != null && backreqMap.size() > 0 && request.getParameter("enableBack")!=null && request.getParameter("enableBack").equalsIgnoreCase("true") || (fromFavSch!=null && fromFavSch.equalsIgnoreCase("true")))
		{
			rootJson.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
		}
		queryString = request.getQueryString();	
		screenLabelJson.put("reporter.thin.Report By",intlmap.getTextDescription("reporter.uptime.Analyze by"));
		screenLabelJson.put("reporter.common.Zone",intlmap.getTextDescription("reporter.common.Zone"));
		JSONArray zoneArray = new JSONArray();
		if(v_zone != null && v_zone.size()>0)
		{
			loopJsonObj = new JSONObject();
			zoneArray.add(loopJsonObj);
			for(int n=0;n<v_zone.size();n++)
			{
				String s=(String)v_zone.get(n);
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",s);
				loopJsonObj.put("valueField",s);
				zoneArray.add(loopJsonObj);
				if(s_farmserver!=null && s_farmserver.equalsIgnoreCase(s))
				{
					rootJson.put("selectedZone",s_farmserver);
				}
			}
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			zoneArray.add(loopJsonObj);
		}
		rootJson.put("zoneCombo",zoneArray);
		screenLabelJson.put("reporter.common.Component Type",intlmap.getTextDescription("reporter.common.Component Type"));
		//added for worker group
		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.common.Component",intlmap.getTextDescription("reporter.common.Component"));
		Collections.sort(v_application,String.CASE_INSENSITIVE_ORDER);
		screenLabelJson.put("reporter.common.Application",intlmap.getTextDescription("reporter.common.Application"));
		JSONArray applnArray = new JSONArray();
		if(v_application != null && v_application.size() >0)
		{
		   if(selectedApplication.size() > 0)
			{
				for(int n=0;n<v_application.size();n++)
				{
					String s=(String)v_application.get(n);
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",s);
					loopJsonObj.put("valueField",s);
					applnArray.add(loopJsonObj);
					if(selectedApplication!=null && selectedApplication.contains(s))
					{
						rootJson.put("selectedAppln",s);
					}
				}
			}
			else
			{
				for(int n=0;n<v_application.size();n++)
				{
					String s=(String)v_application.get(n);
					loopJsonObj = new JSONObject();
					loopJsonObj.put("displayField",s);
					loopJsonObj.put("valueField",s);
					applnArray.add(loopJsonObj);
					if(n ==0)
					{
						rootJson.put("selectedAppln",s);
					}
				}
			 }
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			applnArray.add(loopJsonObj);
			rootJson.put("selectedAppln","-1");
		}
		rootJson.put("applnCombo",applnArray);
%>
		<%@  include file ="ErTimeFormatJSON.jsp"%> 
<%
		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);
		//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);
		chartTypeForUI=ErHighchartUtils.getChartType(startDateForHighchart,endDateForHighchart,currentDateFormat+" HH:mm");
		rootJson.put("chartType",chartTypeForUI);

		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",timefrom);
		rootJson.put("selectedMinsFrom",minfrom);
		rootJson.put("selectedTimeTo",timeto);
		rootJson.put("selectedMinsTo",minto);
		screenLabelJson.put("reporter.common.Report Generation", intlmap.getTextDescription("reporter.common.Report Generation"));
		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);
		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"));

		String pdfStartDate = startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
		String pdfEndDate = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;

		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 Instance"));
		tmpobj.put("valueField", "application_usage");
		viewApplnCombo.add(tmpobj);
		rootJson.put("viewApplnCombo",viewApplnCombo);
		rootJson.put("selectedViewAppln","application_usage");
		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
		{
			er_background = "";
			er_foreground = "selected";
			rootJson.put("reportGeneration","foreground");
		}
		if (er_graphViews == null)
		{
			rootJson.put("er_graphViews","Area");
		}
		else
		{
			rootJson.put("er_graphViews",er_graphViews);
		}
		String bg_reportname = request.getParameter("bg_reportname");
		if(bg_reportname == null)
		{
			bg_reportname = "";
		}
		if(bggroundStr != null && !bggroundStr.equals(""))
		{
			isBackgroundProcess = true;
			rootJson.put("backgroundReportStatus",status);
			String strreportName ="Thin_Client_Applicaion_Usage";
			if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit") ))
			{
				strreportName ="All Report Types";
				rootJson.put("bgGroundMsg",bggroundStr);
			}
			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="+com.eg.EgURLEncoder.encode(strreportName,"UTF-8")+"&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"));
		}
		if(isSubmit != null && isSubmit.equalsIgnoreCase("true") && !isBackgroundProcess)
		{
			JSONObject reportDataJson = new JSONObject();
			JSONObject selectionDetails=new JSONObject();
			rootJson.put("reporter.common.SelectionDetailsfor", intlmap.getTextDescription("reporter.common.Selection Details for ")+" "+ applicationName);
		
			if(er_option.equalsIgnoreCase("Zone"))
			{
				selectionDetails.put(intlmap.getTextDescription("reporter.cpacity.Zone"),s_farmserver);
			}
			else if(er_option.equalsIgnoreCase("Group")||er_option.equalsIgnoreCase("Segment")||er_option.equalsIgnoreCase("Service"))
			{
				selectionDetails.put(intlmap.getTextDescription("reporter.cpacity."+er_option),er_site);
			}
			selectionDetails.put(intlmap.getTextDescription("reporter.cpacity.Component Type"),intlmap.getComponentTypeDescription(s_compType));
			selectionDetails.put(intlmap.getTextDescription("reporter.cpacity.Application"),applicationName);

			selectionDetails.put(intlmap.getTextDescription("reporter.common.Time Period"),"<span class='font_bold'> </span> "+timefrom+":"+minfrom+"<span class='font_bold'>  "+intlmap.getTextDescription("reporter.common.to")+" </span>  "+timeto+":"+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);

			s_st_hr = request.getParameter("starthr");
			s_en_hr = request.getParameter("endhr");
			String mngrIP = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
			String servlet = "/final/servlet/com.eg.ErAppUsageReportC;jsessionid=" + session.getId() + "?&er_option=graph&inidate="+currentDateFormat+"&startdate="+s_st_time_graph+"&enddate="+s_en_time_graph+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&startmin="+strmin+"&endmin="+enmin+"&timefrom="+timefrom+"&minfrom="+minfrom+"&timeto="+timeto+"&minto="+minto+"&er_compType="+s_compType+"&showLegend="+showLegend+"&er_graphViews="+er_graphViews+"&uid="+loginid+"&userID="+loginid;
			HashMap map=(HashMap)ui.getReporterGraphParams();
			StringTokenizer stc = new StringTokenizer((String)map.get("samplecolors"),",");
			String [] cols = new String[stc.countTokens()];
			for(int i=0;i<cols.length;i++)
			{
				String strstc = stc.nextToken().trim();
				cols[i] = strstc;
			}
			singleSelection = new ArrayList();
			singleColors = new ArrayList();
			String tempApplication = applicationName;
			Map tempMap = (Map)resultMap.get(tempApplication);
			if(tempMap != null)
			{
				Set keySet = tempMap.keySet();
				Iterator itr = keySet.iterator();
				int i = 0;
				while(itr.hasNext())
				{
					singleSelection.add(itr.next());
					singleColors.add(cols[i]);
					i++;
					if(i >= cols.length)
						i = 0;
				}
			}
			reportDataJson.put("title",intlmap.getTextDescription("reporter.common.Application Instance Report -")+" "+intlmap.getComponentTypeDescription(s_compType)+"-"+tempApplication);
			reportDataJson.put("imageUrl",servlet + "&chartApplication="+com.eg.EgURLEncoder.encode(tempApplication, "UTF-8"));
			String strselectioncount = reportInfo.getValue("MISC","RightDisplaySelectioncount");
			int selectioncount=10;
			if(strselectioncount !=null && !strselectioncount.equals(""))
			{
				try
				{
					selectioncount = Integer.parseInt(strselectioncount);
				}
				catch (Exception e)
				{
					selectioncount = 10;
				}
			}
			if (singleSelection != null && singleSelection.size() >selectioncount)
			{
				int count1=0;
				JSONObject manualLegends = new JSONObject();
				for (int k=0; k <singleSelection.size();k++)
				{
					String st_key = (String)singleColors.get(k);
					String value = (String)singleSelection.get(k);
					st_key = st_key.substring(1,st_key.length());
					if(k%2 ==0)
					{
						String dispValue="";
						int n=0;
						int h=0;
						int charval=value.length();
						for (int y=0;y <charval ;y++ )
						{
							if(n==60)
							{
							dispValue += value.substring(h,y)+"<br>";
							h=y;
							n=0;
							}
							n++;
						}
						if(n < 60)
						{
							dispValue += value.substring(h,charval)+"<br>";
						}
						if(value.indexOf(" ")>-1)
						{
							dispValue = value;
						}
						manualLegends.put(dispValue,st_key);
					}
					else if(k%2 !=0)
					{
						String dispValue="";
						int n=0;
						int h=0;
						int charval=value.length();
						for (int y=0;y <charval ;y++ )
						{
							if(n==60)
							{
								dispValue += value.substring(h,y)+"<br>";
								h=y;
								n=0;
							}
							n++;
						}
						if(n < 60)
						{
							dispValue += value.substring(h,charval)+"<br>";
						}
						if(value.indexOf(" ")>-1)
						{
							dispValue = value;
						}
						manualLegends.put(dispValue,st_key);
					}
					else
					{
						manualLegends.put(value,st_key);
					}
				}
				reportDataJson.put("manualLagendDetails",manualLegends);
			}
			session.setAttribute("singleColors",singleColors);
			session.setAttribute("singleSelection",singleSelection);
			rootJson.put("reportData",reportDataJson);
		}
		//for mail starts
		String strEncodeer_timeline = er_timeline;
		if(er_timeline != null)
			strEncodeer_timeline = com.eg.EgURLEncoder.encode(er_timeline,UTF_8);
		if(s_st_time_graph != null && s_en_time_graph != null && s_inidate != null)
		{
			s_st_time_graph = com.eg.EgURLEncoder.encode(s_st_time_graph,UTF_8);
			s_en_time_graph = com.eg.EgURLEncoder.encode(s_en_time_graph,UTF_8);
			s_inidate = com.eg.EgURLEncoder.encode(s_inidate,UTF_8);
		}
		String strEncodeApplicationName = applicationName;
		if(applicationName!=null)
			strEncodeApplicationName = com.eg.EgURLEncoder.encode(applicationName,"UTF-8");
		String strEncodecmpType = "";
		if(s_compType!=null)
			strEncodecmpType = EgURLEncoder.encode(s_compType,"UTF-8");

		String strEncodefarmServer = "";
		if(s_farmserver!=null)
			strEncodefarmServer = EgURLEncoder.encode(s_farmserver,"UTF-8");
		String stren_timefrom = "";
		if (timefrom2!=null)
			stren_timefrom = EgURLEncoder.encode(timefrom2,"UTF-8");
		String stren_minfrom = "";
		if (minfrom2!=null)
			stren_minfrom = EgURLEncoder.encode(minfrom2,"UTF-8");
		String stren_timeto = "";
		if (timeto2!=null)
			stren_timeto = EgURLEncoder.encode(timeto2,"UTF-8");
		String stren_minto = "";
		if (minto2!=null)
			stren_minto = EgURLEncoder.encode(minto2,"UTF-8");

		String dataProcess = mngrIProc+"/final/reporter/ErAppUsageReportPrint.jsp;jsessionid="+ session.getId()+"?er_application="+strEncodeApplicationName+"&er_compType="+strEncodecmpType+"&er_zone="+strEncodefarmServer+"&startdate="+s_st_time_graph+"&enddate="+s_en_time_graph+"&timefrom="+stren_timefrom+"&minfrom="+stren_minfrom+"&timeto="+stren_timeto+"&minto="+stren_minto+"&er_timeline="+strEncodeer_timeline+"&inidate="+s_inidate+"&starthr="+com.eg.EgURLEncoder.encode(s_st_hr,UTF_8)+"&endhr="+com.eg.EgURLEncoder.encode(s_en_hr,UTF_8)+"&startmin="+com.eg.EgURLEncoder.encode(strmin,UTF_8)+"&endmin="+com.eg.EgURLEncoder.encode(enmin,UTF_8)+"&er_option="+er_option+"&er_site="+er_site+"&pageWidthProces=400&er_option=graph&pdfPrint=yes&er_graphViews="+er_graphViews;
		String strEncodeusrtime = "";
		String strenuser = "";
		if(strUsrTimeline!=null)
			strEncodeusrtime = EgURLEncoder.encode(strUsrTimeline,"UTF-8");
		if(loginid!=null)
			strenuser = EgURLEncoder.encode(loginid,"UTF-8");

		dataProcess+="&userID="+strenuser+"&userTimeline="+strEncodeusrtime+"&er_trgttype="+EgURLEncoder.encode("Application Usage",UTF_8)+"&er_gtype="+EgURLEncoder.encode("Application Usage",UTF_8)+"&er_rtype="+EgURLEncoder.encode("Thin Client",UTF_8)+"&limitforbg="+EgURLEncoder.encode(limitforbg,UTF_8);
		session.setAttribute("MAIL_URL",dataProcess);
		// for redirecting same page in reporter Starts
		queryString=(String)ErUtils.prepareQueryString(request.getParameterMap());
		String qString="";
		String qStringBackUrl = "";
		if(queryString!=null)
		{
			StringTokenizer strtok = new StringTokenizer(queryString,"&");
			while(strtok.hasMoreTokens())
			{
				String parameter = strtok.nextToken();
				int ind = parameter.indexOf("=");
				if (ind < 0)
					continue;
				String reqparam =parameter.substring(0,ind);
				String value = parameter.substring(ind+1);
				if(reqparam!=null)
				{
					if(reqparam.equals("er_gtype"))
					{
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}
					else if(reqparam.equals("er_zone"))
					{
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}
					else if(reqparam.equals("startdate"))
					{
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}
					else if(reqparam.equals("enddate"))
					{
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}
					else if(reqparam.equals("inidate"))
					{
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}
					/*else if(reqparam.equals("er_trgttype"))
					{
						commented because when giving reload, the error occurs because its not getting decoded after getting from request.
						value=com.eg.EgURLEncoder.encode(value, UTF_8);
					}*/
					else if( reqparam.equals("er_timeline") || reqparam.equals("er_gtype") || reqparam.equals("inidate") || reqparam.equals("pdfTime") || reqparam.equals("er_application")|| reqparam.equals("limitforbg")|| reqparam.equals("er_rtype") ) 
					{
						value=com.eg.EgURLEncoder.encode(value, "UTF-8");
					}
					qStringBackUrl+= reqparam+"="+value+"&";
					if(reqparam.equals("er_component")) {
						continue;
					}
					qString += reqparam+"="+value+"&";
				}
			}
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErThinClientApplication.jsp?"+qStringBackUrl);
		}// redirecting reporter same page ends
		session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErAppUsageReportPrint.jsp");
		rootJson.put("saveQString",qString);
		rootJson.put("hiddenfields",hiddenfieldsJson);
		rootJson.put("screenLabels",screenLabelJson);
		rootJson.put("viewReportFor","application_usage");
		out.println(rootJson.toString());
}
catch(Throwable t)
{
	t.printStackTrace();
}
	//Back Button - Start
	ArrayList listbackvar = new  ArrayList();
	if(request.getParameter("isSubmit")!=null)
	{
		listbackvar.add("/servlet/com.eg.ErAppUsageReportC?");
		listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
		session.setAttribute("favSchBackDisplay","Yes");
	}
	else 
	{
		listbackvar.add("ErAppUsageReport.jsp");
		listbackvar.add(queryString);
		session.setAttribute("favSchBackDisplay","No");
	}
	String backadded = erhelputils.getBackID();
	backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
	session.setAttribute("backQuery",backreqMap);
	//Back Button - End
%>
<%!
 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;
}
%>