
<%
	/************************************************************************************************
	 *	File				: ErErCitrixMachineReportJson.jsp
	 *	Version				: 6.3
	 *	Author				: Ganesh P
	 *	Creation Date		: 05/02/18
	 *
	 *************************************************************************************************/
%>
<%@ include file="ErReporterTracker.jsp"%>

<%@ page import="com.eg.EgReportInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>

<%@ page import="com.egurkha.User"%>
<%@ page import="com.egurkha.UserRegistry"%>
<%@ page import="egurkha.reporter.ErBackgroundReportGenerator"%>
<%@ page import="egurkha.reporter.ErEsxVMutils"%>
<%@ page import="net.sf.json.JSONObject"%>
<%@ page import="net.sf.json.JSONArray"%>
<%@ page import="com.eg.MappingNameSorter"%>
<%@ page import="com.eg.EgName"%>
<%@ page import="com.eg.EgConfigInfo"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="com.egurkha.util.DateUtil"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>	
<%@ page import="com.eg.EgDateInfo"%>
<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.text.ParseException"%>

<%@ page import="java.util.List"%>
<%@ page import="java.util.Set"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Iterator"%>
<%@ page import = "net.sf.json.*" %>

<%@ page import="java.util.Vector"%>
<%@ page import="java.util.Hashtable"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="java.util.HashMap"%>
<%@ page import="java.util.Collections"%>
<%
	try 
	{
		response.setContentType("application/json;charset=UTF-8");
		JSONObject rootJson=  new JSONObject();
		Map allData = (Map)request.getAttribute("allData");
		User this_user= UserRegistry.getInstance().getUser(session.getId());
		String thisUserLang= this_user.getLanguage();
		String loginid= this_user.getLoginID();
		ErComponentsUtils compUtil = new ErComponentsUtils(loginid);
		EgReportInfo reportInfo= new EgReportInfo("manager");
		ErInfo erInfo= new ErInfo();
		EgMappingInfo intlmap= new EgMappingInfo(thisUserLang);
		MappingNameSorter sorter= new MappingNameSorter(thisUserLang);
		ErEsxVMutils erEsxUtils= new ErEsxVMutils();
		IniUI ui= IniUI.getInstance();
		Vector v_components = compUtil.getAllUserComponents1();
		String mngrIProc= new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
		String limitforbg= reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
		int maxDays= ErUtils.getMaxDaysInMonth();		
		boolean isFromC= ("true".equals(request.getParameter("fromC")))? true:false;			
		Map htSelectData = (Map)request.getAttribute("htSelectData");
		String reportBy= request.getParameter("reportBy");
		String er_deliverGrup= request.getParameter("er_deliverGrup");
		String er_dataFor= request.getParameter("er_dataFor");
		String erOsMachine_type= request.getParameter("erOsMachine_type");
		String reportBySubType= request.getParameter("reportBySubType");
		String component[]= request.getParameterValues("component");
		String er_comptype= request.getParameter("er_comptype");
		String er_timeline= request.getParameter("er_timeline");
		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 startmin = request.getParameter("startmin");
		String endmin = request.getParameter("endmin");
		String er_view = request.getParameter("isSubmitData");
		String strmin = startmin;
		String enmin = endmin;
		String fromDrillHead ="";
		String currentDateFormat = strUserDateFormat;
		String reportIniName = "";
		//prakash for exclude weekend
		String inifile = "eg_report.ini";
		String inifileDir = EgInstallInfo.getInstallDir()+"/manager/config/";
		IniFile inifiles = new IniFile(inifileDir+inifile);
		String Days = inifiles.getValue("EXCLUDE_WEEKEND","Days");
		//end		
		String strReportFor = request.getParameter("er_reportFor");
		if(strReportFor !=null && strReportFor.equalsIgnoreCase("unregistered"))
		{
			reportIniName = "CITRIX_MACHINE_REPORT";
		}
		else if(strReportFor !=null && strReportFor.equalsIgnoreCase("maintenance"))
		{
			reportIniName = "CITRIX_MACHINE_MAINTENANCE_REPORT";
		}
		String noFailMSG= reportInfo.getValue(reportIniName, "msg_no_error");
		String starttimeformat = null;
		String endtimeformat= null;
		String dispDate= null;
		String comFormat= null;
		ArrayList componentList= new ArrayList();
		ArrayList aListCompType= new ArrayList();
		JSONObject loopJsonObj= new JSONObject();
		Vector v_application= new Vector();
		JSONObject screenLabelJson = new JSONObject();
			if (component == null)
		{
			component = new String[1];
			component[0] = "All";
		}
			componentList = new ArrayList(Arrays.asList(component));
		if (reportBy == null || (reportBy != null && reportBy.isEmpty()) || reportBy.equals("-1"))
		{
			reportBy = "Component";
		}
		List v_option = new ArrayList();
		Hashtable htAllGroups = new Hashtable();
		ArrayList aListSupportedComponentType = reportInfo.getComponentsList(reportIniName, false);				
		htAllGroups = erEsxUtils.getGroups(null, aListSupportedComponentType, this_user, loginid, "Yes", true);
		ArrayList aListOption = erEsxUtils.getOptions(htAllGroups);
		if (aListOption != null && aListOption.size() > 0)
		{
			v_option.addAll(aListOption);
		}
		JSONArray reportByArray = new JSONArray();
		JSONObject reportByObj = null;
		if (v_option != null && v_option.size() > 0)
		{
			rootJson.put("selectedAnalysisByCombo", reportBy);
			for (int i = 0; i < v_option.size(); i++) 
			{
				reportByObj = new JSONObject();
				reportByObj.put("displayField",intlmap.getTextDescription("reporter.common." + v_option.get(i)));
				reportByObj.put("valueField", v_option.get(i));
				reportByArray.add(reportByObj);
			}
		} 
		else
		{
			reportByObj = new JSONObject();
			reportByObj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
			reportByObj.put("valueField", "-1");
			reportByArray.add(reportByObj);
			rootJson.put("selectedAnalysisByCombo", "-1");
		}
		rootJson.put("reportBy", reportByArray);
		Vector dispzone = new Vector();
		List v_site = new ArrayList();
		if (reportBy != null)
		{
			List aListComponentTemp = null;
			v_site = erEsxUtils.getGroupsName(htAllGroups, reportBy);
			if (v_site != null && v_site.size() > 0)
			{
				Collections.sort(v_site, String.CASE_INSENSITIVE_ORDER);
				if (!reportBy.equalsIgnoreCase("Component"))
				{
					dispzone.addAll(v_site);
					if ((reportBySubType == null && v_site != null && v_site.size() > 0) || (reportBySubType != null && !v_site.contains(reportBySubType) && v_site != null && v_site.size() > 0 && !reportBySubType.equalsIgnoreCase("-1"))) 
					{
						reportBySubType = (String) v_site.get(0);
					}					
					aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups, reportBy, reportBySubType);
				}
				else
				{
					aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups, reportBy, null);
				}
			}
			else
			{
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups, reportBy, null);
			}
			if (aListComponentTemp != null && aListComponentTemp.size() > 0)
			{
				v_components = new Vector();
				v_components.addAll(aListComponentTemp);
			}
			if (v_components != null && v_components.size() > 0)
			{
				aListCompType = new ArrayList();
				for (int i = 0; i < v_components.size(); i++)
				{
					String loopComponent = (String) v_components.get(i);
					if (loopComponent.lastIndexOf(":") > -1) {
						String loopComp = loopComponent.substring(0, loopComponent.lastIndexOf(":"));
						String loopType = loopComponent.substring(loopComponent.lastIndexOf(":") + 1);
						if (!aListCompType.contains(loopType) && aListSupportedComponentType.contains(loopType))
						{
							aListCompType.add(loopType);
						}
					}
				}
			}
		}
		Collections.sort(v_components,String.CASE_INSENSITIVE_ORDER);
		if (dispzone != null)
			Collections.sort(dispzone, String.CASE_INSENSITIVE_ORDER);
		JSONArray zoneArray = new JSONArray();

		if (dispzone == null || dispzone.isEmpty())
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			zoneArray.add(loopJsonObj);
		}
		for (int n = 0; n < dispzone.size(); n++)
		{
			String s = (String) dispzone.get(n);
			loopJsonObj = new JSONObject();
			String subzoneDispVal = s;
			if(s.equalsIgnoreCase("--Default--"))
				subzoneDispVal = intlmap.getTextDescription("reporter.common."+s);
			loopJsonObj.put("displayField", subzoneDispVal);
			loopJsonObj.put("valueField", s);
			zoneArray.add(loopJsonObj);
			if (reportBySubType != null && reportBySubType.equalsIgnoreCase(s))
			{
				rootJson.put("selectedZone", reportBySubType);
			}
		}
		rootJson.put("zoneCombo", zoneArray); 

		rootJson.put("reportTitle",reportInfo.getValue(reportIniName, strReportFor));
		JSONArray comptypeArray = new JSONArray();
		if (aListCompType != null)
			Collections.sort(aListCompType, String.CASE_INSENSITIVE_ORDER);
		if (aListCompType != null && aListCompType.size() > 0)
		{
			if(er_comptype==null)
			{
				er_comptype = (String) aListCompType.get(0);
			}
			for (int n = 0; n < aListCompType.size(); n++)
			{
				String sCompType = (String) aListCompType.get(n);
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField", intlmap.getComponentTypeDescription(sCompType));
				loopJsonObj.put("valueField", sCompType);
				comptypeArray.add(loopJsonObj);
			}
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
		}
		rootJson.put("compType", er_comptype);
		rootJson.put("compTypeCombo", comptypeArray);

		JSONArray serverArray = new JSONArray();
		ArrayList selectedServerArray = new ArrayList();
		ArrayList selectedServerArryTemp = new ArrayList();
		if (er_comptype != null && er_comptype.equalsIgnoreCase("-1"))
			v_components = null;
		if (v_components != null && !v_components.isEmpty())
		{
			loopJsonObj = new JSONObject();
			if(v_components.size()>0)
			{
				loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.common.All Components"));
				loopJsonObj.put("valueField", "All");
				serverArray.add(loopJsonObj);
			}
			for (int n = 0; n < v_components.size(); n++) 
			{
				String s = (String) v_components.get(n);
				String loopComp = s.substring(0, s.lastIndexOf(":"));
				String loopType = s.substring(s.lastIndexOf(":") + 1);
				if(!loopType.equalsIgnoreCase(er_comptype))
				{
					continue;
				}
				if (loopComp.indexOf(":NULL") > -1)
					loopComp = loopComp.substring(0, loopComp.indexOf(":"));					
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField", loopComp);
				loopJsonObj.put("valueField", s);
				selectedServerArryTemp.add(s);
				serverArray.add(loopJsonObj);
			}
			selectedServerArray.addAll(componentList);
		}
		else 
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			serverArray.add(loopJsonObj);
			selectedServerArray.add("1");
		}

		rootJson.put("selectedServer", selectedServerArray);
		rootJson.put("serverCombo", serverArray);
		
		if(!selectedServerArray.contains("All") && !selectedServerArray.contains("-1"))
		{
			selectedServerArryTemp = new ArrayList();
			selectedServerArryTemp.addAll(selectedServerArray);
		}
		JSONArray infoArray=new JSONArray();
		loopJsonObj=new JSONObject();	
		loopJsonObj.put("displayField", intlmap.getTextDescription("reporter.common.Desktop"));
		loopJsonObj.put("valueField","Desktop OS Machines");
		infoArray.add(loopJsonObj);
		loopJsonObj=new JSONObject();	
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Server"));
		loopJsonObj.put("valueField","Server OS Machines");
		infoArray.add(loopJsonObj);
		if(strReportFor !=null && strReportFor.equalsIgnoreCase("unregistered"))
		{
			loopJsonObj=new JSONObject();	
			loopJsonObj.put("displayField","All");
			loopJsonObj.put("valueField","All");
			infoArray.add(loopJsonObj);
		}
		rootJson.put("MachineTypeTypeArry",infoArray);
		if(erOsMachine_type==null && infoArray.size()>0)
		{
			JSONObject obj=(JSONObject)infoArray.get(0);
			erOsMachine_type=(String)obj.get("valueField");
		}
		rootJson.put("selectedMachineType",erOsMachine_type);
		
		infoArray=new JSONArray();
		loopJsonObj=new JSONObject();	
		String dispCurrentVal = intlmap.getTextDescription("reporter.common.Current");
		loopJsonObj.put("displayField",dispCurrentVal);
		loopJsonObj.put("valueField","Current");
		infoArray.add(loopJsonObj);
		loopJsonObj=new JSONObject();	
		String dispHistoricalVal = intlmap.getTextDescription("reporter.common.Historical");
		loopJsonObj.put("displayField",dispHistoricalVal);
		loopJsonObj.put("valueField","Historical");
		infoArray.add(loopJsonObj);
		rootJson.put("dataForCombo",infoArray);
		if(er_dataFor==null && infoArray.size()>0)
		{
			JSONObject obj=(JSONObject)infoArray.get(0);
			er_dataFor=(String)obj.get("valueField");
		}
		rootJson.put("selectedDataFor",er_dataFor);

		infoArray=new JSONArray();
		ArrayList info_list = new ArrayList();
		boolean isMachineTypeAll=false;
		if(erOsMachine_type.equalsIgnoreCase("All"))
			isMachineTypeAll=true;
		if(selectedServerArryTemp!=null && selectedServerArryTemp.size()>0)
		{
			String machineType = "";
			if(erOsMachine_type.indexOf(" ")>-1)
			{
				machineType = erOsMachine_type.substring(0, erOsMachine_type.indexOf(" "));
			}
			for(int i=0;i<selectedServerArryTemp.size();i++)
			{
				String singleServer = (String)selectedServerArryTemp.get(i);
				Vector info_list_temp = null;
				if(singleServer!=null && !singleServer.equals("-1") && !singleServer.equalsIgnoreCase("all"))
				{
					String testNameKey = singleServer.substring(singleServer.lastIndexOf(":")+1, singleServer.length());			
					if(strReportFor !=null && strReportFor.equalsIgnoreCase("maintenance"))	
						testNameKey += "_" + machineType;
					String testName = reportInfo.getTimeFrame(reportIniName, testNameKey);
					info_list_temp = erInfo.getInfosForTest("NONE", testName, singleServer);
				}
				if(info_list_temp!=null)
				{
					for(int j=0;j<info_list_temp.size();j++)
					{
						String info_name = (String)info_list_temp.get(j);
						if(info_name != null && info_name.startsWith("+"))
						{
							info_name=(String)info_name.substring(1);
						}
						if(strReportFor !=null && strReportFor.equalsIgnoreCase("unregistered"))
						{
							if(isMachineTypeAll)
							{
								if(!info_list.contains(info_name))
									info_list.add(info_name);
							}
							else if(info_name.indexOf(":")>-1 && info_name.startsWith(erOsMachine_type))
							{
								info_name = info_name.substring(info_name.indexOf(":")+1);
								if(!info_list.contains(info_name))
									info_list.add(info_name);
							}
						}
						else
						{
							if(info_name.indexOf(":")>-1)
							{
								info_name = info_name.substring(0, info_name.indexOf(":"));
							}
							if(!info_list.contains(info_name))
							{
								info_list.add(info_name);
							}
						}
					}
				}
			}
		}				
		if(info_list!=null && info_list.size()>0)
		{
			if(!info_list.contains("All") && !isMachineTypeAll)
			{
				info_list.add(0, "All");
			}
			for(int i=0;i<info_list.size();i++)
			{
				String eachInfo=(String)info_list.get(i);
				loopJsonObj=new JSONObject();
				loopJsonObj.put("displayField",eachInfo);
				loopJsonObj.put("valueField",eachInfo);	
				infoArray.add(loopJsonObj);
			}
		}
		else
		{
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField","-1");	
			infoArray.add(loopJsonObj);
			er_deliverGrup = "-1";
		}

		rootJson.put("deliveryGroupArrry",infoArray);
		if(er_deliverGrup==null && infoArray.size()>0)
		{
			JSONObject obj=(JSONObject)infoArray.get(0);
			er_deliverGrup=(String)obj.get("valueField");
		}
		rootJson.put("selectedDeliveryGroup",er_deliverGrup);
		if (er_timeline == null || er_timeline.equals(" ")) 
		{
			er_timeline = "1 hour";
		}
		EgDateInfo egDt = new EgDateInfo();
		long msecsPerHour = (long) 1000 * 60 * 60;
		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")) 
				{//weeks
					value *= (7 * 24 * 3600);
				} 
				else if (unit.startsWith("mo")) 
				{//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.HOUR_OF_DAY, 0);
					java.util.Date dt_temp1 = cal_temp.getTime();
					long l_temp = dt_temp1.getTime();
					int totalDays = 24 * (maxDays);
					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;
			}
			strmin = "00";
			enmin = "00";
		}
		String hourFrom = "";
		String minFrom = "";
		String hourTo = "";
		String minTo = "";
		String fromTime = reportInfo.getTimeFrame(reportIniName, "FROM");
		String toTime = reportInfo.getTimeFrame(reportIniName, "TO");
		StringTokenizer	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 hourFromUI= request.getParameter("hourFromUI");
		String minFromUI= request.getParameter("minFromUI");
		String hourToUI= request.getParameter("hourToUI");
		String minToUI= request.getParameter("minToUI");

		String exclweekUI= request.getParameter("exclweek");
		String durationTypeUI = request.getParameter("durationType");
		String durationUI= request.getParameter("duration");
		String unitsUI= request.getParameter("units");
		String reportGenerationType = request.getParameter("repGenType");
		if(hourFromUI == null) hourFromUI = hourFrom;
		if(minFromUI== null) minFromUI= minFrom;
		if(hourToUI== null) hourToUI= hourTo;
		if(minToUI== null) minToUI= minTo;
		if(exclweekUI== null) 
			exclweekUI= "No";
		if (reportGenerationType==null) 
			reportGenerationType = "foreground";
		rootJson.put("sHrForSetting",hourFromUI);
		rootJson.put("sMinForSetting",minFromUI);
		rootJson.put("eHourForSetting",hourToUI);
		rootJson.put("eMinForSetting",minToUI);
		rootJson.put("sExclweekUI",exclweekUI);
		rootJson.put("sRepGenType",reportGenerationType);
		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);

		//prakash for exclude weekend
		rootJson.put("excludeMessage",intlmap.getTextDescription("reporter.common.Excludes")+" "+Days);
		//	end

		JSONArray durationArray  =  new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.greater than"));
		loopJsonObj.put("valueField", "g");
		durationArray.add(loopJsonObj);
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.lesser than"));
		loopJsonObj.put("valueField", "l");
		durationArray.add(loopJsonObj);

		rootJson.put("durationCombo",durationArray);

		JSONArray unitsArray  =  new JSONArray();
		loopJsonObj = new JSONObject();
		loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.seconds"));
		loopJsonObj.put("valueField", "seconds");
		unitsArray.add(loopJsonObj);

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

		rootJson.put("unitCombo",unitsArray);

		JSONArray reportGenerationComboArray =  new JSONArray();
		JSONObject tmpobj=new JSONObject();

		tmpobj.put("displayField", strforeground);
		tmpobj.put("valueField", "foreground");
		reportGenerationComboArray.add(tmpobj);
		tmpobj=new JSONObject();
		tmpobj.put("displayField", strbackground);
		tmpobj.put("valueField", "background");
		reportGenerationComboArray.add(tmpobj);
		tmpobj=new JSONObject();
		tmpobj.put("displayField","Background Save - CSV");
		tmpobj.put("valueField","background-csv");
		reportGenerationComboArray.add(tmpobj);

		rootJson.put("reportGenerationCombo",reportGenerationComboArray);
%>
<%@  include file="ErTimeFormatJSON.jsp"%>
<%
		JSONArray array = new JSONArray();
		JSONObject obj;
		obj = new JSONObject();
		obj.put("displayField", "Background");
		obj.put("valueField", "background");
		array.add(obj);
		/*obj = new JSONObject();
		obj.put("displayField", "Background Save - CSV");
		obj.put("valueField", "background-csv");
		array.add(obj);*/
		obj = new JSONObject();
		obj.put("displayField", "Foreground");
		obj.put("valueField", "foreground");
		array.add(obj);
		String lblAnalysisBy = intlmap.getTextDescription("reporter.uptime.Analyze by");
		String lblAnalysisBySub = intlmap.getTextDescription("reporter.common."+reportBy);
		String lblDeliveryGrp = intlmap.getTextDescription("reporter.common.Delivery Groups");
		String lblMachineType = intlmap.getTextDescription("reporter.common.Machine Type");
		String lblCompType = intlmap.getTextDescription("reporter.common.Component Type");
		String lblComponent = intlmap.getTextDescription("reporter.common.Component");
		String lblMeasureType = intlmap.getTextDescription("reporter.common.Report For");
		
		screenLabelJson.put("compTypeLabel",intlmap.getTextDescription("reporter.consolidated.Component Type"));
		screenLabelJson.put("reportByLabel", lblAnalysisBy);
		screenLabelJson.put("lblAnalysisBySub", lblAnalysisBySub);
		screenLabelJson.put("lblDeliveryGrp", lblDeliveryGrp);
		screenLabelJson.put("lblMachineType", lblMachineType);
		screenLabelJson.put("lblCompType", lblCompType);
		screenLabelJson.put("lblComponent", lblComponent);
		screenLabelJson.put("lblMeasureType", lblMeasureType);
		rootJson.put("screenLabelJson", screenLabelJson);

		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("inidate",currentDateFormat);
		chartTypeForUI=ErHighchartUtils.getChartType(startDateForHighchart,endDateForHighchart,currentDateFormat+" HH:mm");

		rootJson.put("startDateForDisplay",startDateForDisplay);
		rootJson.put("startHourForDisplay",startHourForDisplay);
		rootJson.put("startMinForDisplay",startMinForDisplay);
		rootJson.put("endDateForDisplay",endDateForDisplay);
		rootJson.put("endHourForDisplay",endHourForDisplay);
		rootJson.put("endMinForDisplay",endMinForDisplay);

		String userStDateTime  = startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay+" hrs";
		String userEndDateTime = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay+" hrs";
		rootJson.put("userStDateTime",userStDateTime);
		rootJson.put("userEndDateTime",userEndDateTime);
		rootJson.put("selectedreportBy", reportBy);
		rootJson.put("selectedreportBySubType", reportBySubType);
		rootJson.put("selectedCompType", er_comptype);
		rootJson.put("rGenration", array);
		rootJson.put("loginid", loginid);
		rootJson.put("limitforbg", limitforbg);
		rootJson.put("maxDays", maxDays);
		rootJson.put("noFailMSG", noFailMSG);
		String qStr=request.getQueryString();
		String qStrTmp = "";
		if(qStr!=null)
		{
			qStrTmp = qStr;
		}
		session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErCitrixMachineReportPrint.jsp");
		session.setAttribute("MAIL_URL",mngrIProc+"/final/reporter/ErCitrixMachineReportPrint.jsp;jsessionid="+ session.getId()+"?er_RmDispName="+strReportFor);
		HashMap paramval =new HashMap();
		paramval.put("filename","userlogonsummarycc");
		session.setAttribute("parameters", paramval);

		//Back Button - Start
		HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
		String bggroundStr  = (String)request.getAttribute("bggroundStr");
		String status       = (String)request.getAttribute("status");
		String backQnumber = request.getParameter("backQnumber");
		String servlet2 = request.getParameter("backServletName");
		String reqFromFavorite = request.getParameter("fromFavorite");
		String favorite_id = request.getParameter("FavoriteId");
		String queryString =(String)ErUtils.prepareQueryString(request.getParameterMap());
		ErHelperUtils erhelputils = null;
		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"))
		{
			request.setAttribute("htdata",null);
			request.setAttribute("app_topusers",null);
			request.setAttribute("appChartData",null);
		}
		//Back Button - End
		ArrayList listbackvar = new  ArrayList();
		System.out.println("queryString-->"+queryString);
		if(request.getParameter("isSubmit")!=null)
		{
			if(er_view != null && er_view.equalsIgnoreCase("submit"))
				session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixMachineReport.jsp?"+queryString+"&isSubmit=true");
			else
				session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixMachineReport.jsp?"+queryString);
			listbackvar.add("/servlet/com.eg.ErCitrixMachineReportC?");
			listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
			session.setAttribute("favSchBackDisplay","Yes");
		}
		else
		{
			if(er_view != null && er_view.equalsIgnoreCase("submit"))
				session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixMachineReport.jsp?"+queryString+"&isSubmit=true");
			else
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixMachineReport.jsp?"+queryString);
			listbackvar.add("ErCitrixMachineReport.jsp");
			listbackvar.add(queryString);
			session.setAttribute("favSchBackDisplay","No");
		}
		String backadded = erhelputils.getBackID();
		backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
		session.setAttribute("backQuery",backreqMap);
//// END
		boolean isData = false;
		if(allData!=null && allData.size()>0)		
		{
			isData = ((Boolean)allData.get("isData")).booleanValue();
			if(isData)
			{
				int machineCount = ((Integer)allData.get("machineCount")).intValue();
				int deliveryGrpCount = ((Integer)allData.get("deliveryGrpCount")).intValue();
				JSONObject summaryObject = new JSONObject();
				summaryObject.put("machineCount", machineCount);
				summaryObject.put("deliveryGrpCount", deliveryGrpCount);
				rootJson.put("summaryData", summaryObject);
				List dataList = (List)allData.get("dataList");
				JSONArray gridData = new JSONArray();
				for(int i=0;i<dataList.size();i++)
				{					
					
					JSONArray unRegisterArry = new JSONArray();
					List data = (List)dataList.get(i);
					for(int j=0; j<data.size(); j++)
					{
						unRegisterArry.add((String)data.get(j));
					}
					gridData.add(unRegisterArry);
				}
				rootJson.put("gridData", gridData);
				JSONArray heading = new JSONArray();	
				Vector columnVec = (Vector)allData.get("dispCol");
				Iterator itr = columnVec.iterator();
				while(itr.hasNext())
					heading.add((String)itr.next());				
				rootJson.put("columnData", heading);
			}
		}
		rootJson.put("isData", isData);
		StringTokenizer st1;
		String Hourfrom = "";
		String Minfrom = "";
		String Hourto= "";
		String Minto= "";
		String userFormat = this_user.getUserDateFormat();
		s_st_time = DateUtil.changeDateFormat(s_st_time,"MM/dd/yyyy",userFormat);
		s_en_time = DateUtil.changeDateFormat(s_en_time,"MM/dd/yyyy",userFormat);
		EgTimeZoneConverter usrTimeZoneStart = new EgTimeZoneConverter(s_st_time+" "+s_st_hr+":"+strmin, this_user);
		EgTimeZoneConverter usrTimeZoneEnd = new EgTimeZoneConverter(s_en_time+" "+s_en_hr+":"+enmin, this_user);
		String  pdfStartDate = usrTimeZoneStart.getDateTime();
		String  pdfEndDate   = usrTimeZoneEnd.getDateTime();
		String pdfTime = "From "+pdfStartDate+" hrs "+" "+" To "+pdfEndDate+" hrs";
		st1 = new StringTokenizer(fromTime,":");
		if(st1.hasMoreTokens())
		{
			Hourfrom = st1.nextToken();
			Minfrom = st1.nextToken();
		}
		st1=new StringTokenizer(toTime,":");
		if(st1.hasMoreTokens())
		{
			Hourto = st1.nextToken();
			Minto = st1.nextToken();
		}
		JSONObject selectionDetails      =  new JSONObject();
		selectionDetails.put(intlmap.getTextDescription("reporter.common.Report By"),intlmap.getTextDescription("reporter.common."+reportBy));
		selectionDetails.put(intlmap.getTextDescription("reporter.common.Time Period "),Hourfrom+":"+Minfrom+" <b>"+intlmap.getTextDescription("reporter.common.to")+" </b>"+Hourto+":"+Minto);
		selectionDetails.put((String)intlmap.getTextDescription("reporter.common.TimeLine"),pdfStartDate+" "+intlmap.getTextDescription("reporter.common.hrs")+" <b>  "+intlmap.getTextDescription("reporter.common.to")+" </b>"+pdfEndDate+" "+intlmap.getTextDescription("reporter.common.hrs"));

		rootJson.put("selectionDetails",selectionDetails);
		out.println(rootJson.toString());
	} 
	catch (Exception e) 
	{
		e.printStackTrace();
	}
%>