<%
/************************************************************************************************
*	File			: ErApplicationBillingReportJson.jsp
*	Purpose			:	Displays the configured measures and its details for the Citrix Applications
*	Version			:	Reporter v6.0.1
*	Author			:	karthikeyan R
*	Creation Date	:	01-02-2016 
*
*************************************************************************************************/
%>

<%@ 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.StringUtils" %>
<%@ page import = "java.text.*" %>
<%@ page import="net.sf.json.*" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.EgAgentInfo" %>


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

<%
try
{	
	JSONObject combo=new JSONObject();
	JSONObject urlFields=new JSONObject();
	JSONObject labelFields=new JSONObject();
    JSONObject hiddenFields = new JSONObject();
	JSONObject selectedFields = new JSONObject();
	JSONObject selectionDetails = new JSONObject();
	JSONObject data = new JSONObject();
	JSONObject graph = new JSONObject();
	JSONObject iterateJObject;
	JSONArray iterateJArray;
	JSONArray selectedComboJArray=null;
 	JSONObject applicationLaunch=new JSONObject();
	JSONObject loopJsonObj = new JSONObject();
	boolean needLogonDetails =false;

	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");

	String strTestt="";
	//Back Button - Start

	HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
	String backQnumber = request.getParameter("backQnumber");
	String servlet2 = request.getParameter("backServletName");
	String reqFromFavorite = request.getParameter("fromFavorite");
	String favorite_id = request.getParameter("FavoriteId");
	 List tListt=null;
	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");
	applicationLaunch.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
	String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	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();
	Vector v_measure_csv = new Vector();
	List list_data = new LinkedList();

	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;

	ErComponentsUtils compUtils = new ErComponentsUtils(thisuser.getLoginID());
	EgMappingInfo intlmap=new EgMappingInfo(thisuser.getLanguage());
	ErUtils erUtils = new ErUtils();
	ErInfo erInfo = new ErInfo();
	EgReportInfo reportInfo=new EgReportInfo("manager");
	String confrimation = reportInfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
	String strLogonDetailsValue= reportInfo.getValue("APPLICATION_BILLING","NeedLogonDetails");
	if(strLogonDetailsValue!=null && (strLogonDetailsValue.equalsIgnoreCase("True") || strLogonDetailsValue.equalsIgnoreCase("Yes")))
		needLogonDetails = true;

	String strbgrepportName = reportInfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
	String limitforbg = reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
	EgThresholdInfo hreshholdInfo = new EgThresholdInfo("manager");
	EgTablesInfo tablesInfo = new EgTablesInfo("manager");
	EgDbInfo dbInfo = new EgDbInfo("manager");
	String er_detailsBasedOn = request.getParameter("er_detailsBasedOn");
	String s_compType = request.getParameter("er_compType");
	String selected_CompType = request.getParameter("er_compType");
	int pageWith=1024;
	
	if(selected_CompType==null)
		selected_CompType="";
	Hashtable htt=new Hashtable();
	htt=(Hashtable)request.getAttribute("htdata");
	Vector v_components = compUtils.getAllUserComponents1();
	Vector v_component = new Vector();
	ArrayList v_Workgroupcomponents = new ArrayList();

	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;
	List v_application=new ArrayList();
	ArrayList aListworkGrp = new ArrayList();
	Vector v_comp_popup = new Vector();
	Vector v_comp_popup_disp = new Vector();
	String isVmCompSt = request.getParameter("isVmComp");
	boolean isVmComp=false;

	if(isVmCompSt!=null && isVmCompSt.equalsIgnoreCase("true"))
	{
		isVmComp=true;
	}
	//
	String er_option =request.getParameter("er_option");
	String er_site = request.getParameter("er_site");
	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"))
		{
			headerKeyName=er_option;
		}
		else
		{
			headerKeyName="Zone"+" : "+request.getParameter("select_farm");
		}
//

	List topList = new ArrayList();
	String maxStr = reportInfo.getValue("APPLICATION_BILLING","Showtop");
	int maxInfo = 10;
	try {
		maxInfo = Integer.parseInt(maxStr);
	} catch(Exception e) {
		maxInfo = 10;
	}
	topList.add("TOP  - " +maxInfo/4);
	topList.add("TOP  - " +maxInfo/2);
	topList.add("TOP  - " +maxInfo);
	topList.add("ALL");
	topList.add("LAST  - " +maxInfo);
	topList.add("LAST  - " +maxInfo/2);
	topList.add("LAST  - " +maxInfo/4);
	

	List groupByList = new ArrayList();
	groupByList.add("Component");
	if (er_detailsBasedOn != null && er_detailsBasedOn.equalsIgnoreCase("User"))
		groupByList.add("Application");
	else 
		groupByList.add("User");


	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 reqFromSchedule = request.getParameter("fromSchedule");
	String schedule_id = request.getParameter("schedule_id");
	String divStatus = request.getParameter("divStatus");
	String er_groupby = request.getParameter("er_groupBy");
	String isSubmit = request.getParameter("isSubmit");

	String s_application = request.getParameter("er_application");
	
	String er_top = request.getParameter("er_top");
	String er_topString = request.getParameter("er_top");
	if(er_topString!=null && er_topString.indexOf("-")>-1)
		er_topString=er_topString.substring(0,er_topString.indexOf("-"));
	String er_mode = request.getParameter("er_mode");
	String er_zone = request.getParameter("er_zone");
	String[] er_component = request.getParameterValues("er_component");
	String eruserid = request.getParameter("eruserid");
	String er_workerGroup = request.getParameter("er_workerGroup");
	String er_adGroup = request.getParameter("er_adGroup");
	String er_usertxt = request.getParameter("er_usertxt");
	if (er_usertxt == null)
		er_usertxt = "";
	String srcForImg="";
	if (er_groupby == null) {
		if (er_detailsBasedOn != null && er_detailsBasedOn.equalsIgnoreCase("User"))
			er_groupby = "Application";
		else 
			er_groupby = "User";
	}
	if (er_detailsBasedOn != null && er_detailsBasedOn.equalsIgnoreCase("User")){
		if (er_groupby != null && er_groupby.equalsIgnoreCase("User")) 
			er_groupby = "Application";
	} else 
	if (er_detailsBasedOn != null && er_detailsBasedOn.equalsIgnoreCase("Application")){
		if (er_groupby != null && er_groupby.equalsIgnoreCase("Application")) 
			er_groupby = "User";
	}
	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 (er_top == null)
		er_top = (String)topList.get(2);
	ArrayList aListSupportedComponentType = reportInfo.getComponentsList("APPLICATION_BILLING",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();
	HashMap htHeading = new HashMap();
	ArrayList aList1 = new ArrayList();
	ArrayList aList2 = new ArrayList();
	ArrayList aList3 = new ArrayList();


	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_BILLING");
	String numTopUsers = reportInfo.getTop("APPLICATION_BILLING");
	Vector v_sort=new Vector();


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

	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_BILLING","FROM");
	toTime = reportInfo.getTimeFrame("APPLICATION_BILLING","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_BILLING");
	String NoofServers = reportInfo.getNoOfBars("APPLICATION_BILLING","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;

		//-Report By Combo
		if(er_option == null || (er_option!=null && er_option.isEmpty()) || er_option.equalsIgnoreCase("null"))
		{
			 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;
			}

		//
		
		User this_user = UserRegistry.getInstance().getUser(session.getId());
		String loginid = this_user.getLoginID();
		List v_option = new ArrayList();
		List v_site=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 obj1=null;
		if(v_option!=null && v_option.size()>0 )
		{
			selectedFields.put("selectedAnalysisByCombo",er_option);
		for(int i=0; i<v_option.size(); i++)
		{
			obj1 = new JSONObject();
			obj1.put("displayField", intlmap.getTextDescription("reporter.common."+v_option.get(i)));
			obj1.put("valueField",v_option.get(i));
			arr.add(obj1);
			}
		}
		else
		{
				obj1 = new JSONObject();
				obj1.put("displayField", intlmap.getTextDescription("reporter.common.Not Applicable"));
				obj1.put("valueField","-1");
				arr.add(obj1);
		}
		combo.put("analysisByCombo",arr);
		//end
	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);
	}
	List aListComponentTemp =new ArrayList();
	List v_serverName=new ArrayList();
	String show_timeinuse = request.getParameter("sh_timeinuse");
	String s_farmserver = request.getParameter("select_farm");
	String[] selectedAppArrays = null;
	selectedAppArrays = request.getParameterValues("er_application");
	String s_server = request.getParameter("er_server");
	String strFromBack = request.getParameter("fromBack");
	String[] selectedCompArrays = null;
	selectedCompArrays = request.getParameterValues("er_component");
	//---testin
	EgGroupInfo gpinfo = new EgGroupInfo();
	String tmpComponent="";
	Vector v_comp = compUtils.getAllUserComponents1();
	boolean present=false;
	Vector dispzone = new Vector();
	List zonelist = compUtils.getUserZones();
	if(zonelist != null && zonelist.contains("--Default--"))
		zonelist.remove("--Default--");
	ArrayList getComponent=new ArrayList();
	Vector v_zonelist = new Vector();
	v_zonelist.addAll(zonelist);
	List selectedCompList = new ArrayList();
	for(int k1=0;k1<zonelist.size();k1++)
	{
		String vali=(String)zonelist.get(k1);
		getComponent = compUtils.getTypeModifyComponents(compUtils.getZoneComponents(vali,true),2);
		for(int i=0;i<getComponent.size();i++)
		{
			String getcomp=(String)getComponent.get(i);
			String strComponentType = "";
			if(getcomp!=null && getcomp.indexOf(":")>-1)
				strComponentType = getcomp.substring(0,getcomp.indexOf(":"));
			if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(strComponentType))
			{
				if(!dispzone.contains(vali))
					dispzone.add(vali);
				if(getcomp.indexOf(":")>-1)
				{
					String strCompType = getcomp.substring(0,getcomp.indexOf(":"));
					if(aListCompType!=null && !aListCompType.contains(strCompType))
						aListCompType.add(strCompType);
				}
			}
		}
		vali="";
	}
	int countTerminal=0,countCitrix=0;
	for(int i=0;i<v_component.size();i++)
	{
		String s_tmp = (String)v_component.get(i);
		if(!v_zonelist.contains(s_tmp))
		{
			continue;
		}
		ArrayList al = compUtils.getTypeModifyComponents(compUtils.getZoneComponents(s_tmp,true),2);
		if(value1==null || value1.equals(""))
		{
			String strComponentType = "";
			if(s_tmp!=null && s_tmp.indexOf(":")>-1)
				strComponentType = s_tmp.substring(s_tmp.lastIndexOf(":")+1);
			if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(strComponentType))
			{
				v_tmp.add(s_tmp);
				if(s_tmp.indexOf(":")>-1)
				{
					String strCompType = s_tmp.substring(s_tmp.lastIndexOf(":")+1);
					if(aListCompType!=null && !aListCompType.contains(strCompType))
						aListCompType.add(strCompType);
				}
			}
		}
		else
		{
			st=new StringTokenizer(value1,",");
			while (st.hasMoreTokens())
			{
				 String comp=st.nextToken();
				if(s_tmp.endsWith(comp))
				{
					v_tmp.add(s_tmp);
					if(s_tmp.indexOf(":")>-1)
					{
						String strCompType = s_tmp.substring(s_tmp.indexOf(":")+1);
						if(aListCompType!=null && !aListCompType.contains(strCompType))
							aListCompType.add(strCompType);
					}
				}
			}
		}
		for(int m=0;m<al.size();m++)
		{
			String comp = (String)al.get(m);
			StringTokenizer token1 = new StringTokenizer(comp,":");
			String sid="";
			while(token1.hasMoreTokens())
			{
				String comptype=token1.nextToken();
				String component = token1.nextToken();
				String port=token1.nextToken();

				if (comptype.equalsIgnoreCase("Oracle_server"))
				{
					sid=token1.nextToken();
				}
				if(sid.equals(""))
				{
					tmpComponent=component+":"+port+":"+comptype;
				}
				else
				{
					tmpComponent=component+":"+port+":" + sid + ":"+comptype;
				}
				if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(comptype))
				{
					if(aListCompType!=null && !aListCompType.contains(comptype))
						aListCompType.add(comptype);
				}
			}
			if(s_tmp!=null)
			{
				if (v_comp.contains(tmpComponent) && (present || termpresent))
				{
					if (!v_temp.contains(s_tmp))
						v_temp.add(s_tmp);
				}
			}
			if(!colZoneComps.contains(tmpComponent))
			{
				colZoneComps.add(tmpComponent);
			}
		}
	}
	if(v_comp!=null && v_comp.size() > 0)
	{
		for(int vc =0; vc < v_comp.size(); vc++)
		{
			String s_comp = (String)v_comp.get(vc);
			if(!colZoneComps.contains(s_comp))
			{
				//If there are only citrix
				String strComponentType = "";
				if(s_comp!=null && s_comp.indexOf(":")>-1)
					strComponentType = s_comp.substring(s_comp.lastIndexOf(":")+1);
				if(!defComps.contains(s_comp) && (aListSupportedComponentType!=null && aListSupportedComponentType.contains(strComponentType)))
				{
					defComps.add(s_comp);
					if(s_comp.indexOf(":")>-1)
					{
						String strCompType = s_comp.substring(s_comp.lastIndexOf(":")+1);
						if(aListCompType!=null && !aListCompType.contains(strCompType))
							aListCompType.add(strCompType);
					}
				}
			}
		}
		if(!defComps.isEmpty())
		{
			if(!dispzone.contains("--Default--"))
				dispzone.insertElementAt("--Default--",0);
		}
	}
	if(s_farmserver == null && dispzone != null && dispzone.size() > 0)
	{
		s_farmserver = (String)dispzone.get(0);
	}
	List userZoneNames = compUtils.getUserZones();
	if(userZoneNames != null && userZoneNames.contains("--Default--"))
		userZoneNames.remove("--Default--");
	String zones[] = new String[userZoneNames.size()];
	for(int l=0;l<userZoneNames.size();l++)
	{
		zones[l] = (String)userZoneNames.get(l);
	}
	Vector aListCompType_value = new Vector();
	aListCompType_value=erUtils.getAllComponentTypeForZone(s_farmserver,zones,v_zonelist,v_comp,aListSupportedComponentType);

	if(v_comp!=null&&v_comp.size()>0)
	{
		String strcomptype="";
		if(v_temp.isEmpty()||v_temp.size()==0)
		{
			int  compsize = v_comp.size();
			for(int v=0;v<compsize;v++)
			{
				boolean b_val = false;
				String st_comp =(String) v_comp.get(v);
				StringTokenizer strtok = new StringTokenizer(st_comp,":");
				int cttok = strtok.countTokens();
				if(cttok==4)
					b_val = true;
				if(cttok>=3)
				{
					strtok.nextToken();
					strtok.nextToken();
					if(b_val)
					{
						strtok.nextToken();
					}
					strcomptype = strtok.nextToken();
				}
				if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(strcomptype))
				{
					if(!dispzone.contains("--Default--"))
						dispzone.insertElementAt("--Default--",0);
					v_comptype.add(strcomptype);
				}
			}
		}
	}

		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);
			selectionDetails.put(intlmap.getTextDescription("reporter.thin."+er_option),er_site);
			combo.put("siteCombo",getJSONComboFromList(v_site,"",intlmap));
			labelFields.put("siteComboLabel",er_option);
			selectedFields.put("selectedSiteCombo",er_site);
			}
			else if(er_option.equals("Zone"))
			{
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,s_farmserver);
				if(rtype!=null)
				{
					iterateJArray=new JSONArray();
					if(dispzone!=null && dispzone.size()>0)
					{
					for(int n=0;n<dispzone.size();n++)
					{
						String s=(String)dispzone.get(n);
						iterateJObject=new JSONObject();
						iterateJObject.put("displayField",s);
						iterateJObject.put("valueField",s);
						iterateJArray.add(iterateJObject);
						if(s_farmserver!=null && s_farmserver.equalsIgnoreCase(s))
						{
							selectedFields.put("zoneSelected",s);
							selectionDetails.put(intlmap.getTextDescription("reporter.thin.Zone"),s);
						}
					}
					}
					else
					{
							iterateJObject=new JSONObject();
							iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
							iterateJObject.put("valueField","-1");
							iterateJArray.add(iterateJObject);
					}
					combo.put("zoneCombo",iterateJArray);
				}
			}
			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);
		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);
		}
		JSONArray comptypeArray = new JSONArray();
        if(aListComponentTemp!=null && !aListComponentTemp.isEmpty())
		{
			
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Please choose a Component Type"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
			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);
						
					}
						if(v_serverName !=null && rtype.equalsIgnoreCase("no") && ctype.equalsIgnoreCase("all"))
					{
							v_serverName.addAll(aListComponentTemp);
					}
				}
			}
			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(rtype!=null && rtype.equalsIgnoreCase("no") && v_serverName.size()>1)
			{
				loopJsonObj = new JSONObject();
				comptypeArray.add(loopJsonObj);
			}
			if(v_serverName!=null && v_serverName.size()>0)
			{
				if(s_compType==null)
			{
				s_compType=(String)v_serverName.get(0);
				selectedFields.put("componentTypeSelected",s_compType);
			}
			else
			{
				selectedFields.put("componentTypeSelected",s_compType);
			}
		selectionDetails.put(intlmap.getTextDescription("reporter.thin.Component Type"),intlmap.getComponentTypeDescription(s_compType));
		combo.put("componentTypeCombo",comptypeArray);
			}
		}
        else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			comptypeArray.add(loopJsonObj);
		}
		List componentsForSpecificCompType=new ArrayList();
		if(aListComponentTemp!=null)
		for(int n=0;n<aListComponentTemp.size();n++)
		{
			String comp = (String)aListComponentTemp.get(n);
			if(comp.endsWith(s_compType))
			{
				componentsForSpecificCompType.add(comp);
			}
		}
		aListComponentTemp=componentsForSpecificCompType;
		 if(selectedCompArrays == null || selectedCompArrays.length==0)
		{
			selectedCompArrays = new String[aListComponentTemp.size()];
			selectedCompArrays = (String[])aListComponentTemp.toArray(new String[aListComponentTemp.size()]);
		}
		if(rtype!=null && rtype.equals("No"))
		{
			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 )
			{
				if(s_compType!=null && !s_compType.equalsIgnoreCase("All"))
				{
						List vecAll = new Vector();
						for(int m=0;m< aListComponentTemp.size();m++)
						{
							String tempcomp=(String)aListComponentTemp.get(m);
							StringTokenizer t_token= new StringTokenizer(tempcomp,":");
							while(t_token.hasMoreTokens())
							{
								String tempcomptype=t_token.nextToken();
								if(s_compType.equalsIgnoreCase(tempcomptype))
								{
									vecAll.add(tempcomp);
								}
							}
						}
						aListComponentTemp=vecAll;
				}
			}
			 if(aListComponentTemp !=null && !aListComponentTemp.isEmpty())
			{
				Collections.sort(aListComponentTemp,String.CASE_INSENSITIVE_ORDER);
				iterateJArray=new JSONArray(); 
				selectedComboJArray=new JSONArray(); 
				ArrayList aListSelectedList = new ArrayList();
				if(selectedCompArrays!=null && selectedCompArrays.length>0)
					aListSelectedList.addAll(Arrays.asList(selectedCompArrays));
				StringBuffer str=new StringBuffer();
				StringBuffer strVal=new StringBuffer();
				for(int n=0;n<aListComponentTemp.size();n++)
				{
					String s=(String)aListComponentTemp.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)
						{
							strTemp = s1.substring(0,s1.indexOf(":"));
							strTemp1 = s.substring(s.lastIndexOf(":")+1);
						}
						if(s_compType!=null)
						{
							strDipServer = strTemp;
						}
					}
					iterateJObject=new JSONObject();
					iterateJObject.put("displayField",strDipServer);
					iterateJObject.put("valueField",s);
					iterateJArray.add(iterateJObject);
					if(aListSelectedList!=null && !aListSelectedList.isEmpty()&& aListSelectedList.contains(s))
					{
						v_comp_popup.add(s);
						v_comp_popup_disp.add(strDipServer);
						strVal.append(s).append(",");
						str.append(strDipServer).append(",");
						selectedComboJArray.add(s);
					}else
					{
						v_comp_popup.add(s);
						v_comp_popup_disp.add(strDipServer);
					}
					}
				if(str.length()>0 && strVal.length()>0)
				{
					str.deleteCharAt(str.length() - 1);
					strVal.deleteCharAt(strVal.length() - 1);
					if(str.length()>66)
					{
						strVal.append("...");
						str.append("...");
					}
				}
			}
			else
			{
				iterateJArray=new JSONArray();
				iterateJObject=new JSONObject();
				iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				iterateJObject.put("valueField","-1");
				iterateJArray.add(iterateJObject);			
				v_comp_popup.add("-1");
				v_comp_popup_disp.add("Not Applicable");
			}
			selectedFields.put("componentSelected",selectedComboJArray);
			combo.put("componentCombo",iterateJArray);
		}
		
	String serverForSorting=null;
	String s_perserver=request.getParameter("er_perserver");
	if (s_perserver==null || s_perserver.equals(""))
		s_perserver="Yes";
	if(s_application==null)
		s_application = request.getParameter("er_user");
	ArrayList aListSelectedList_temp = null;
	ArrayList aListSelectedCompList_temp = null;
	String fromToplink = request.getParameter("fromToplink");
	if(fromToplink!=null && fromToplink.equalsIgnoreCase("Yes")){
	if(aListSelectedCompList_temp!=null && aListSelectedCompList_temp.size()>0)
		selectedCompArrays = (String[])aListSelectedCompList_temp.toArray(new String[aListSelectedCompList_temp.size()]);
	if(aListSelectedList_temp!=null && aListSelectedList_temp.size()>0)
		selectedAppArrays = (String[])aListSelectedList_temp.toArray(new String[aListSelectedList_temp.size()]);
	}
	if(strFromBack!=null && strFromBack.equalsIgnoreCase("Yes"))
	{
		session.removeAttribute("SelectedApplication");
		session.removeAttribute("SelectedComponent");
	}
	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");

	String sub1 = "MISC";
	String var1 = "CtxServer";
	Vector v_server=new Vector();

	if(s_compType == null )
	{
		if(aListCompType_value!=null && aListCompType_value.size()>0)
		{
			s_compType = (String)aListCompType_value.get(0);
		}
	}
	if (s_farmserver!=null && !s_farmserver.equals(""))
	{
		if(s_farmserver.equalsIgnoreCase("--Default--"))
		{
			if(!defComps.isEmpty())
			{
				countTerminal=0;
				countCitrix=0;
				for(int dc=0; dc < defComps.size(); dc++)
				{
					String s_comp = (String)defComps.get(dc);
					StringTokenizer st_colon = new StringTokenizer(s_comp,":");
					String comp  = st_colon.nextToken();
					String port =  st_colon.nextToken();
					String sid = "";
					if(st_colon.countTokens() >1)
					{
						sid = st_colon.nextToken();
					}
					String s_type = st_colon.nextToken();

					if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(s_type))
					{
						if(s_compType!=null && (s_compType.equalsIgnoreCase("ALL") || s_compType.equals(s_type)))
							v_server.add(comp+":"+port+":"+s_type);
						if(aListCompType_value!=null && !aListCompType_value.contains(s_type))
							aListCompType_value.add(s_type);
					}
				}
			}
		}
		ArrayList al = compUtils.getTypeModifyComponents(compUtils.getZoneComponents(s_farmserver,true),2);
		for (int k=0;k<al.size();k++)
		{
			String server = (String)al.get(k);
			StringTokenizer st_server = new StringTokenizer(server,":");
			String sid="";
			while(st_server.hasMoreTokens())
			{
				String server_comptype=st_server.nextToken();
				String server_component = st_server.nextToken();
				String server_port=st_server.nextToken();
				if (server_comptype.equalsIgnoreCase("Oracle_server"))
					sid=st_server.nextToken();
				if(aListSupportedComponentType!=null && aListSupportedComponentType.contains(server_comptype))
				{
					if(s_compType!=null && (s_compType.equalsIgnoreCase("ALL") || s_compType.equals(server_comptype)))
						v_server.add(server_component+":"+server_port+":"+server_comptype);
					if(aListCompType_value!=null && !aListCompType_value.contains(server_comptype))
						aListCompType_value.add(server_comptype);
				}
				break;
			}
		}
	}

	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();
	if(s_compType == null )
	{
		if(aListCompType_value!=null && aListCompType_value.size()>0)
		{
			s_compType = (String)aListCompType_value.get(0);
		}
	}
	if(aListCompType_value!=null && aListCompType_value.size()>0)
	{
		if(aListCompType_value.size()>1)
		{
			if(rtype !=null && rtype.equalsIgnoreCase("No"))
				aListCompType_value.add(0,"ALL");
			allServerPresent = true;
		}
	}


	int v_componentSize = 0;
	if(v_components!=null && v_components.size()>0)
	{
		v_componentSize=v_components.size();
		if(selectedCompArrays == null || selectedCompArrays.length==0)
		{
			selectedCompArrays = new String[v_components.size()];
			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);
		}
	}
	String testStr = reportInfo.getValue("APPLICATION_BILLING",s_compType);
	/*List v_user = new Vector();
	if (rtype!= null && er_option!=null)
	{
		if(er_option.equalsIgnoreCase("Zone"))
		{
			v_user = erUtils.getAllUsersForComponents(s_compType,s_farmserver,aListSupportedComponentType,zones,v_zonelist,v_components,new ArrayList(v_components));
		}
		else
		{
			v_user = erUtils.getAllUsersForComponentName(er_option,er_site,s_compType,aListSupportedComponentType,loginid);
		}
	}
	*/

	v_application=new ArrayList();
	String strTest ="";
	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(":"));
			}

				strTest = reportInfo.getValue("APPLICATION_BILLING",strTempCompType+"_app");
				ArrayList aListCompGrp =  null;
				Vector v_apps = erInfo.getInfosForTest("NULL",strTest,strComp);
				v_app.addAll(v_apps);
		}
		for (int m=0;m<v_app.size();m++)
		{
			String app=(String)v_app.get(m);
			if(app!=null && app.lastIndexOf(".exe")>-1)
			{
					app=app.substring(0,app.lastIndexOf(".exe"));
			}
			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++)
	{
		tok1 = new StringTokenizer(s_variable,":");
		String displayname="";
		String s_test="";
		String s_measure="";
		while(tok1.hasMoreTokens())
		{
			String com=tok1.nextToken();
			if(aListCompType_value !=null && !aListCompType_value.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_BILLING",s_variable);
					StringTokenizer cols=new StringTokenizer(st_value,",");
					while (cols.hasMoreTokens())
					{
						v_sort.add(displayname+"_"+cols.nextToken());
					}
				}
			}
		}
	}
	if(testmes == null && v_testmes != null && v_testmes.size() >0)
	{
		testmes = (String)v_testmes.get(0);
	}

	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	String currentDateFormat = strUserDateFormat;//egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");

	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 = "Application Report "+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"))
			{//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.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;
		}
		strmin="00";
		enmin="00";
	}
	String strServergroupQs = "";
	String strUserLinkServerQs="";
	if(selectedCompArrays!=null && selectedCompArrays.length>0)
	{
		for (int i=0;i<selectedCompArrays.length;i++)
		{
			try{
				strServergroupQs += "&er_component="+EgURLEncoder.encode(selectedCompArrays[i],"UTF-8");
				String strComp = selectedCompArrays[i];
				if(strComp!=null && strComp.lastIndexOf(":")>-1)
					strComp = strComp.substring(0,strComp.lastIndexOf(":"));
				strUserLinkServerQs += "&er_componentserver="+EgURLEncoder.encode(strComp,"UTF-8");
			}catch(Exception e){}
		}
	}
	session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErApplicationBillingReportPrint.jsp");
	urlFields.put("PDF_URL",mngrIProc+"/final/reporter/ErApplicationBillingReportPrint.jsp");

	String excludeweekend=request.getParameter("er_excwe");
	if (excludeweekend==null ||	excludeweekend.equals(""))
		excludeweekend="No";

	hiddenFields.put("option","Citrix");
	hiddenFields.put("inidate",currentDateFormat);
	hiddenFields.put("currTime","");
	hiddenFields.put("er_rtype","CtxApplication");
	hiddenFields.put("er_trgttype","Application Billing Report");
	hiddenFields.put("er_gtype","Citrix");
	hiddenFields.put("pdfTime",pdfTime);
	hiddenFields.put("uid",EgURLEncoder.encode(loginid,"UTF-8"));
	hiddenFields.put("userID",EgURLEncoder.encode(loginid,"UTF-8"));
	hiddenFields.put("eruserid",EgURLEncoder.encode(loginid,"UTF-8"));
	hiddenFields.put("er_trenddata","No");
	hiddenFields.put("servers",request.getParameter("servers"));
	hiddenFields.put("er_check",request.getParameter("er_check"));
	hiddenFields.put("er_application1",request.getParameter("er_application1"));
	hiddenFields.put("schedule_id",schedule_id);
	hiddenFields.put("er_ViewName","ErApplicationBillingReport.jsp");
	hiddenFields.put("getMaxDaysInMonth",ErUtils.getMaxDaysInMonth());
	hiddenFields.put("forwardto","ErApplicationBillingReportJson");
	hiddenFields.put("er_bgreportfrom","Application_Billing");
	hiddenFields.put("bgenabled",strbgrepportName);
	hiddenFields.put("limitforbg",limitforbg);
	hiddenFields.put("savereport","save");
	hiddenFields.put("servletName","com.eg.ErApplicationBillingReportC");
	if(reqFromFavorite!=null)
	{
		hiddenFields.put("fromFavorite",reqFromFavorite);
	}
	else
	{
		hiddenFields.put("fromFavorite","null");
	}
	if(reqFromSchedule!=null)
	{
		hiddenFields.put("fromSchedule",reqFromSchedule);
	}
	else
	{
		hiddenFields.put("fromSchedule","null");
	}
	hiddenFields.put("FavoriteId",favorite_id);
	if(rtype!=null&&rtype.equals("Yes"))
	{
		hiddenFields.put("opt","chart");
	}
	else
	{
		hiddenFields.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")))
			{
				hiddenFields.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
			}
	if(s_compType!=null)
	{
	lst.add(intlmap.getTextDescription("reporter.common.Application Billing")+" for "+headerKeyName);
	lst.add(intlmap.getTextDescription("reporter.thin.Component Type")+" : "+intlmap.getComponentTypeDescription(s_compType));
	}

 	if (dispzone != null)
	Collections.sort(dispzone,String.CASE_INSENSITIVE_ORDER);
	labelFields.put("zoneLabel",intlmap.getTextDescription("reporter.thin.Zone"));
	labelFields.put("componentTypeLabel",intlmap.getTextDescription("reporter.thin.Component Type"));
	if(rtype == null || (rtype!=null && rtype.equals("No")))
	{
		labelFields.put("componentLabel",intlmap.getTextDescription("reporter.thin.Components"));
		String strColSpan="";
		for(int n=0;n<v_comp_popup.size();n++)
		{
			String s=(String)v_comp_popup.get(n);
			String ss=(String)v_comp_popup_disp.get(n);
		}
	}
	labelFields.put("reportTypeLabel",intlmap.getTextDescription("reporter.thin.Report Type"));
	iterateJArray=new JSONArray();
	
	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.thin.Graph"));
	iterateJObject.put("valueField","Yes");
	iterateJArray.add(iterateJObject);

	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.thin.Data"));
	iterateJObject.put("valueField","No");
	iterateJArray.add(iterateJObject);
	combo.put("reportTypeCombo",iterateJArray);
	if(rtype!=null&&rtype.equals("Yes"))
	{
		selectedFields.put("reportTypeSelected","Yes");
	}
	else
	{
		if (s_farmserver!=null && !s_farmserver.equals("-1") && s_server!=null && !s_server.equalsIgnoreCase("All") &&  !s_server.equalsIgnoreCase("-1") || v_comptype.size()==1)
		{
			selectedFields.put("reportTypeSelected","No");
		}
		else
		{
			selectedFields.put("reportTypeSelected","No");
		}
	}
	labelFields.put("detailsBasedOnLabel",intlmap.getTextDescription("reporter.thin.Details based on"));
	iterateJArray=new JSONArray();

	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.thin.User"));
	iterateJObject.put("valueField","user");
	iterateJArray.add(iterateJObject);

	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.thin.Application"));
	iterateJObject.put("valueField","application");
	iterateJArray.add(iterateJObject);
	combo.put("detailsBasedOnCombo",iterateJArray);

	if(er_detailsBasedOn!=null && er_detailsBasedOn.equals("user"))
	{
		selectedFields.put("detailsBasedOnSelected","user");
	}else
	{
		selectedFields.put("detailsBasedOnSelected","application");	
	}



	labelFields.put("applicationLabel",intlmap.getTextDescription("reporter.thin.Applications"));
				
			 
		String str_select="";
		ArrayList aListSelectedList = new ArrayList();
		if(selectedAppArrays!=null && selectedAppArrays.length>0)
			aListSelectedList.addAll(Arrays.asList(selectedAppArrays));
		if(v_application!=null && v_application.size()>0 && selected_CompType!=null && !selected_CompType.equalsIgnoreCase("-1"))
		{
			iterateJArray=new JSONArray();
			iterateJObject=new JSONObject();
			iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.All Applications"));
			iterateJObject.put("valueField","all");
			iterateJArray.add(iterateJObject);
			if (aListSelectedList.contains("all") || v_application.contains("all") || aListSelectedList.contains("Not Applicable") || aListSelectedList.size() == 0)
			{
				selectedFields.put("applicationSelected","all");	
				selectionDetails.put(intlmap.getTextDescription("reporter.thin.Applications"),"all");
			} 
			Collections.sort(v_application,String.CASE_INSENSITIVE_ORDER);
			StringBuffer str=new StringBuffer();
			for(int n=0;n<v_application.size();n++)
			{
				String s=(String)v_application.get(n);
				if(s.startsWith("+"))
					s = s.substring(1);
				iterateJObject=new JSONObject();
				iterateJObject.put("displayField",s);
				iterateJObject.put("valueField",s);
				iterateJArray.add(iterateJObject);
				if(aListSelectedList!=null && aListSelectedList.contains(s))
				{
					str.append(s).append(",");
 				}
			}
			if(str.length()>0)
			{
				str.deleteCharAt(str.length() - 1);
				selectedFields.put("applicationSelected",str.toString());
				selectionDetails.put(intlmap.getTextDescription("reporter.thin.Applications"),str.toString());
			}
			combo.put("applicationCombo",iterateJArray);
		}
		else
		{
			iterateJArray=new JSONArray();
			iterateJObject=new JSONObject();
			iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			iterateJObject.put("valueField","-1");
			iterateJArray.add(iterateJObject);
			selectedFields.put("applicationSelected","-1");	
			combo.put("applicationCombo",iterateJArray);
		}
	if (v_application!=null && v_application.size()>0)
	{
		if (v_application.contains("all") || aListSelectedList.contains("Not Applicable") || aListSelectedList.size() == 0){
		} 
		for(int n=0;n<v_application.size();n++)
		{
			String s=(String)v_application.get(n);
			String ss=(String)v_application.get(n);
		}
	}

	iterateJArray=new JSONArray();
	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.Yes")+" ("+Days+") ");
	iterateJObject.put("valueField","Yes");
	iterateJArray.add(iterateJObject);
	iterateJObject=new JSONObject();
	iterateJObject.put("displayField",intlmap.getTextDescription("reporter.common.No"));
	iterateJObject.put("valueField","No");
	iterateJArray.add(iterateJObject);
	combo.put("excludeWeekendsCombo",iterateJArray);
	labelFields.put("excludeWeekendsLabel",intlmap.getTextDescription("reporter.thin.Exclude weekends"));
	labelFields.put("excludeDaysLabel",intlmap.getTextDescription("reporter.thin.Excludes")+" "+Days);
	if(excludeweekend.equalsIgnoreCase("Yes") )
	{
		selectedFields.put("excludeWeekendsSelected","Yes");
		//selectionDetails.put(intlmap.getTextDescription("reporter.thin.Exclude weekends"),"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
	{
		selectedFields.put("excludeWeekendsSelected","No");
		//selectionDetails.put(intlmap.getTextDescription("reporter.thin.Exclude weekends"),"No");

		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"));
		
	}
	if (rtype != null && rtype.equalsIgnoreCase("yes")) {
		labelFields.put("showLabel",intlmap.getTextDescription("reporter.common.Show"));
		iterateJArray=new JSONArray();

			String selected = "";
			for (int i=0; i<topList.size(); i++) {
				String topStr = (String) topList.get(i);
				selected = "";
				iterateJObject=new JSONObject();
				iterateJObject.put("displayField",topStr);
				iterateJObject.put("valueField",topStr);
				iterateJArray.add(iterateJObject);

				if (er_top.equals(topStr)){
					selectedFields.put("showSelected",topStr);
					selected = "selected";		
				}
			}
			combo.put("showCombo",iterateJArray);		
	} else {
			labelFields.put("groupByLabel",intlmap.getTextDescription("reporter.common.Group by"));
			iterateJArray=new JSONArray();	
				for (int g=0; g<groupByList.size(); g++) {
				String groupStr = (String) groupByList.get(g);
				String display=groupStr;
				iterateJObject=new JSONObject();
				iterateJObject.put("displayField",display);
				iterateJObject.put("valueField",groupStr);
				iterateJArray.add(iterateJObject);
				if (er_groupby.equals(groupStr)) {
					selectedFields.put("groupBySelected",groupStr);		
				}
			}
			combo.put("groupByCombo",iterateJArray);		
	}
	String select_yes = "";
	String select_no = "";
	if(show_timeinuse != null && show_timeinuse.equalsIgnoreCase("Yes"))
	{
		select_yes = "checked";
		select_no="";
	}
	else
	{
		select_yes="";
		select_no = "checked";
	}
	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);
				
			}
		}
	}
 
	selectedFields.put("selectedTimeFrom",Hourfrom);
	selectedFields.put("selectedMinsFrom",Minfrom);
	selectedFields.put("selectedTimeTo",Hourto);
	selectedFields.put("selectedMinsTo",Minto);
%>
	<%@  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 ";
	//Time zone conversion 
	
	pdfStartDate=startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
	pdfEndDate = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;
		


	Vector dvec = new Vector();
	String stimefmt = "Start Date : "+pdfStartDate;
	String etimefmt = "End Date : "+pdfEndDate;

	String ssd=stimefmt+"  "+etimefmt;

	lst.add('"'+ssd+'"');

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

	//User TimeZone changes
	selectedFields.put("startDateForDisplay",startDateForDisplay);
	selectedFields.put("startHourForDisplay",startHourForDisplay);
	selectedFields.put("startMinForDisplay",startMinForDisplay);
	selectedFields.put("endDateForDisplay",endDateForDisplay);
	selectedFields.put("endHourForDisplay",endHourForDisplay);
	selectedFields.put("endMinForDisplay",endMinForDisplay);
	
	selectionDetails.put(intlmap.getTextDescription("reporter.common.Time Period"),Hourfrom+":"+Minfrom+"<span class='font_bold'>  "+intlmap.getTextDescription("reporter.common.to")+" </span> "+Hourto+":"+Minto);
		
	selectionDetails.put((String)intlmap.getTextDescription("reporter.common.Timeline"),pdfStartDate+" "+intlmap.getTextDescription("reporter.common.hrs")+" <span class='font_bold'>"+intlmap.getTextDescription("reporter.common.to")+"</span> "+pdfEndDate+" "+intlmap.getTextDescription("reporter.common.hrs"));
 	
	String er_reportgenration = request.getParameter("er_reportgenration");
	String er_background ="";
	String er_foreground ="";
	if (er_reportgenration != null && er_reportgenration.equals("background"))
	{
		selectedFields.put("reportGenerationSelected","background");
		er_background = "selected";
		er_foreground = "";
	}
		else if(er_reportgenration != null && er_reportgenration.equals("background-csv"))
	{
		selectedFields.put("reportGenerationSelected","background-csv");
		er_background = "selected";
		er_foreground = "";
	}
	else
	{
		selectedFields.put("reportGenerationSelected","foreground");
		er_background = "";
		er_foreground = "selected";
	}
	String bg_reportname = request.getParameter("bg_reportname");
	if(bg_reportname == null)
	{
		bg_reportname = "";
	}
	String reportgenColspan = "5";
	if(rtype != null && rtype.equalsIgnoreCase("No"))
	{
		if(er_reportgenration != null && er_reportgenration.equals("background"))
			reportgenColspan = "2";
		else
			reportgenColspan = "3";
	}
	if(strbgrepportName != null && strbgrepportName.equalsIgnoreCase("Yes"))
	{
		labelFields.put("reportGenerationLabel",intlmap.getTextDescription("reporter.consolidated.Report Generation"));
		labelFields.put("reportNameLabel",intlmap.getTextDescription("reporter.consolidated.Report Name"));
		iterateJArray=new JSONArray();
		iterateJObject=new JSONObject();
		iterateJObject.put("displayField",strbackground);
		iterateJObject.put("valueField","background");
		iterateJArray.add(iterateJObject);

		iterateJObject=new JSONObject();
		iterateJObject.put("displayField","Background Save - CSV");
		iterateJObject.put("valueField","background-csv");
		iterateJArray.add(iterateJObject);


		iterateJObject=new JSONObject();
		iterateJObject.put("displayField",strforeground);
		iterateJObject.put("valueField","foreground");
		iterateJArray.add(iterateJObject);
		combo.put("reportGenerationCombo",iterateJArray);

		if (er_reportgenration != null && er_reportgenration.equals("background"))
		{
			selectedFields.put("reportNameSelected",bg_reportname);
		}
		
	}
		if((reqFromSchedule!=null && reqFromSchedule.equalsIgnoreCase("Yes")) || (reqFromFavorite!=null && reqFromFavorite.equalsIgnoreCase("Yes")))
		{
			labelFields.put("saveButton",intlmap.getTextDescription("reporter.common.SAVE"));
			String fromReq = "schedule";
			if(reqFromFavorite!=null && reqFromFavorite.equalsIgnoreCase("Yes"))
				fromReq = "favorite";
		}
		else
		{
			labelFields.put("submitButton",intlmap.getTextDescription("reporter.common.SUBMIT"));
		}

	if(bggroundStr != null && !bggroundStr.equals(""))
	{
		String strreportName ="Application_Billing";
 		if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
		{
			strreportName ="All Report Types";
			//labelFields.put("bgStatus","success");
		}
		if(status!=null && status.equalsIgnoreCase("success"))
			labelFields.put("bgStatus","success");
		else if(status!=null && status.equalsIgnoreCase("duplicate"))
			labelFields.put("bgStatus","duplicate");
		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);
		}
		labelFields.put("bgResponseText",bgroundResponseTxt);
		urlFields.put("bgUrl","/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");
		labelFields.put("bgAnchor",intlmap.getTextDescription("reporter.common.Click here to see a list of generated and processing reports"));
		
	}


	ArrayList resultList = (ArrayList)session.getAttribute("APPLICATION_BILLING_RESULT_MAP");
	String isAddColumnFnd = (String)session.getAttribute("APPLICATION_BILLING_COLUMNFOUND");

		boolean isAddCmFnd=false;
		if(isAddColumnFnd!=null && isAddColumnFnd=="0")
				isAddCmFnd=true;

		String showSessionStartAndEnd = reportInfo.getValue("APPLICATION_BILLING","ShowSessionStartAndEnd");
		boolean isShowSessionStEnd=false;
		if(showSessionStartAndEnd!=null&&showSessionStartAndEnd.equalsIgnoreCase("yes"))
			isShowSessionStEnd=true;

		String resourceinfo = reportInfo.getValue("APPLICATION_BILLING",s_compType+"_resouce");
		
		String testName = reportInfo.getValue("APPLICATION_BILLING",s_compType+"_app");
		String measureUnit = reportInfo.getValue("APPLICATION_BILLING",s_compType+"_measure_unit");

		List resourceColumnNames=new ArrayList();
		Map measueUnitMap=new HashMap();
		List measueUnitLst=new ArrayList();
		StringTokenizer mToken = new StringTokenizer(measureUnit,",");
			while (mToken.hasMoreTokens())
			{
				String measure = mToken.nextToken();		
				String unitmeasure=tablesInfo.getUnitForMeasure(testName.trim(),measure.trim());

				if(unitmeasure==null || unitmeasure.equals(""))
				{
					String str_measureName = dbInfo.getMeasureForColumn(testName,measure);
					unitmeasure = tablesInfo.getUnitForMeasure(testName,str_measureName);

				}

				if(unitmeasure==null || unitmeasure.equals(""))
					unitmeasure = "-";
				measueUnitLst.add(unitmeasure);
			}
		if(resourceinfo!=null && resourceinfo.length()>0)
		{
			StringTokenizer stToken = new StringTokenizer(resourceinfo,":");
			int t=0;
			while (stToken.hasMoreTokens())
			{
				String unit="";
				if(measueUnitLst.size()>t)
					 unit=(String)measueUnitLst.get(t);
					String strTemp = stToken.nextToken();
					String measure=strTemp.substring(0,strTemp.indexOf("["));
					String colms=strTemp.substring(strTemp.indexOf("[")+1,strTemp.indexOf("]"));
					StringTokenizer cToken = new StringTokenizer(colms,",");
					int f=1;
					List tmp=new ArrayList();
					while (cToken.hasMoreTokens())
						{
						String cms="";
						String tok = cToken.nextToken();					
							cms=measure+"_"+tok;
						resourceColumnNames.add(cms);
						measueUnitMap.put(cms,unit);
						}
				
				t++;
			}
		}

	
	if(isSubmit!=null && resultList!=null && resultList.size()>0)
	{
		JSONObject publicGridData = new JSONObject();

		JSONArray headerObject = new JSONArray();
		JSONArray urlKeyAry = new JSONArray();
		headerObject.add("User");
		headerObject.add("Published Application");
		headerObject.add("Component");
		urlKeyAry.add("er_user");
		urlKeyAry.add("er_info");
		urlKeyAry.add("er_component");
		if(isVmComp)
		{
			headerObject.add("Desktop");
			urlKeyAry.add("er_desktop");
		}
		headerObject.add("Application Launch Time");
		headerObject.add("Application End Time");
		headerObject.add("Duration <br>&nbsp;&nbsp;(Mins)");
		urlKeyAry.add("er_startTime");
		urlKeyAry.add("er_endTime");
		urlKeyAry.add("er_duration");
		if(isShowSessionStEnd)
		{
			headerObject.add("Session Start");
			headerObject.add("Session End");
		}
		urlKeyAry.add("er_sessionStart");
		urlKeyAry.add("er_sessionEnd");
		if(isAddCmFnd)
		{
			headerObject.add("Client Address");
			headerObject.add("Client Name");
			headerObject.add("Client Version");
			urlKeyAry.add("er_clientAddress");
			urlKeyAry.add("er_clientName");
			urlKeyAry.add("er_clientVersion");
		}

		//

	v_measure_csv.add("User");
	v_measure_csv.add("Published Application");
	v_measure_csv.add("Component");
	if(isVmComp)
		v_measure_csv.add("Desktop");
	v_measure_csv.add("Application Launch Time");
	v_measure_csv.add("Application End Time");
	v_measure_csv.add("Duration (Mins)");
	if(isShowSessionStEnd)
	{
		v_measure_csv.add("Session Start");
		v_measure_csv.add("Session End");
	}
	if(isAddCmFnd)
	{
		v_measure_csv.add("Client Address");
		v_measure_csv.add("Client Name");
		v_measure_csv.add("Client Version");
	}



	if(needLogonDetails)
	{
		headerObject.add("Logon Duration <br>&nbsp;&nbsp;(Sec)");
		v_measure_csv.add("Logon Duration(Sec)");
		urlKeyAry.add("er_logonDuration");
	}



		//
		HashMap multiMesUnitMp = new HashMap();
		for(int u=0;u<resourceColumnNames.size();u++)
		{
			String str=(String)resourceColumnNames.get(u);
			String unit=(String)measueUnitMap.get(str);
			if(str!=null&& str.equalsIgnoreCase("CPU_UTIL_avg"))
			{
				str="Cpu Util<br>&nbsp;&nbsp;Avg&nbsp;("+unit+")";
				v_measure_csv.add("Cpu Util-Avg ("+unit+")");
				urlKeyAry.add("Cpu Util-Avg ("+unit+")");
				multiMesUnitMp.put("CPU_UTIL",unit);
			}
			else if(str!=null&& str.equalsIgnoreCase("CPU_UTIL_min"))
			{

				str="Cpu Util<br>&nbsp;&nbsp;Min&nbsp;("+unit+")";
				v_measure_csv.add("Cpu Util-Min ("+unit+")");
				urlKeyAry.add("Cpu Util-Min ("+unit+")");
				multiMesUnitMp.put("CPU_UTIL",unit);
			}
			else if(str!=null&& str.equalsIgnoreCase("CPU_UTIL_max"))
			{
				str="Cpu Util<br>&nbsp;&nbsp;Max&nbsp;("+unit+")";
				v_measure_csv.add("Cpu Util-Max ("+unit+")");
				urlKeyAry.add("Cpu Util-Max ("+unit+")");
				multiMesUnitMp.put("CPU_UTIL",unit);
			}
			else if(str!=null&& str.equalsIgnoreCase("MEMORY_UTIL_avg"))
			{
				str="Memory Util <br>&nbsp;&nbsp;&nbsp;Avg&nbsp;("+unit+")";
				v_measure_csv.add("Memory Util-Avg ("+unit+")");
				urlKeyAry.add("Memory Util-Avg ("+unit+")");
				multiMesUnitMp.put("MEMORY_UTIL",unit);
			}
			else if(str!=null&& str.equalsIgnoreCase("MEMORY_UTIL_min"))
			{
				str="Memory Util <br>&nbsp;&nbsp;&nbsp;Min&nbsp;("+unit+")";
				v_measure_csv.add("Memory Util-Min ("+unit+")");
				urlKeyAry.add("Memory Util-Min ("+unit+")");
				multiMesUnitMp.put("MEMORY_UTIL",unit);
			}
			else if(str!=null&& str.equalsIgnoreCase("MEMORY_UTIL_max"))
			{
				str="Memory Util <br>&nbsp;&nbsp;&nbsp;Max&nbsp;("+unit+")";
				v_measure_csv.add("Memory Util-Max ("+unit+")");
				urlKeyAry.add("Memory Util-Max ("+unit+")");
				multiMesUnitMp.put("MEMORY_UTIL",unit);
			}
			else
			{
				str=customReplaceAll(str,"_"," ");
				str=str+" ("+unit+")";
				v_measure_csv.add(str);
				urlKeyAry.add(str);
			}
			headerObject.add(str);
		}
		headerObject.add("Graph");// added by vengat
		publicGridData.put("title","Application Billing");
		publicGridData.put("columns",headerObject);


		JSONArray gridDataArray=new JSONArray();
		int sSt=6;
		int eSt=7;
		if(isVmComp){
			sSt++;
			eSt++;
		}
		String urlTestName = reportInfo.getValue("APPLICATION_BILLING",selected_CompType);
		String testMeasure = "";
		if(resourceinfo!=null && resourceinfo.length()>0)
		{
			StringTokenizer stToken = new StringTokenizer(resourceinfo,":");
			while (stToken.hasMoreTokens())
			{
				String strTemp = stToken.nextToken();
				String tb=strTemp.substring(0,strTemp.indexOf("["));
				testMeasure+=urlTestName+":"+tb+"|";
			}
		}
		session.setAttribute("multiMesUnit",multiMesUnitMp);
		if(testMeasure.length()>0)
		{
			testMeasure = testMeasure.substring(0,testMeasure.length()-1);
		}

		EgTimeZoneConverter time_converter = new EgTimeZoneConverter();
		for(int x=0;x<resultList.size();x++)
		{
			List vList = (ArrayList) resultList.get(x);
			JSONArray gridDataSubArray=new JSONArray();
			if(vList!=null)
			{
				String url  = "/final/reporter/ErMultiMeasureDrillDown.jsp;jsessionid="+ session.getId()+"?option=Citrix&er_rtype=CtxApplication&er_gtype=Citrix&er_trgttype="+EgURLEncoder.encode("Application Billing Report","UTF-8")+"&er_timeline=Any&timefrom="+request.getParameter("timefrom")+"&timeto="+request.getParameter("timeto")+"&minfrom="+request.getParameter("minfrom")+"&minto="+request.getParameter("minto")+"&er_testMeasure="+EgURLEncoder.encode(testMeasure,"UTF-8")+"&er_compType="+selected_CompType;
				for(int m=0;m<vList.size();m++)
				{
					Object str=(Object)vList.get(m);
					if(!isShowSessionStEnd&&(m==sSt || m==eSt))
						continue;
				
					// create url for graph start_here
					if(urlKeyAry.size()<=m)
						continue;
					String keyS = (String)urlKeyAry.get(m);
					String valueS = (String)str;
					if(keyS.equalsIgnoreCase("er_startTime"))
					{
						String dateS = request.getParameter("startdate");
						String hrS = request.getParameter("starthr");
						String minS = request.getParameter("startmin");
						String secS = "00";
						if(!valueS.equals("-"))
						{
							String time = valueS.substring(valueS.lastIndexOf(" ")+1,valueS.length());
							dateS = valueS.substring(0,valueS.lastIndexOf(" "));
							hrS = time.substring(0,time.indexOf(":"));
							minS = time.substring(time.indexOf(":")+1,time.lastIndexOf(":"));
							secS = time.substring(time.lastIndexOf(":")+1,time.length());
							time_converter.convertProcess(valueS,thisuser,false);
							valueS = time_converter.getDateTime();
						}

						url+="&startdate="+dateS+"&starthr="+hrS+"&startmin="+minS+"&st_sec="+secS;
						str = valueS;
					}
					else if(keyS.equalsIgnoreCase("er_endTime"))
					{
						String dateS = request.getParameter("enddate");
						String hrS = request.getParameter("endhr");
						String minS = request.getParameter("endmin");
						String secS = "00";
						if(!valueS.equals("-"))
						{
							String time = valueS.substring(valueS.lastIndexOf(" ")+1,valueS.length());
							dateS = valueS.substring(0,valueS.lastIndexOf(" "));
							hrS = time.substring(0,time.indexOf(":"));
							minS = time.substring(time.indexOf(":")+1,time.lastIndexOf(":"));
							secS = time.substring(time.lastIndexOf(":")+1,time.length());
							time_converter.convertProcess(valueS,thisuser,false);
							valueS = time_converter.getDateTime();
						}

						url+="&enddate="+dateS+"&endhr="+hrS+"&endmin="+minS+"&end_sec="+secS;
						str = valueS;
					}
					else if(keyS!=null && keyS.equalsIgnoreCase("er_desktop"))
					{
						valueS = erUtils.specialCharEncode(valueS);
						url+="&"+keyS+"="+valueS;
					}
					else
					{
						url+="&"+keyS+"="+EgURLEncoder.encode(valueS,"UTF-8");
					}
					gridDataSubArray.add(str);
					list_data.add("\""+str+"\"");
				}
				url+="&showLegend=true";
				gridDataSubArray.add(url);
				
				// end here
				gridDataArray.add(gridDataSubArray);

				if(gridDataSubArray.size()*100>pageWith)
					pageWith=gridDataSubArray.size()*100;
			}
		}
		publicGridData.put("dataArray",gridDataArray);
		applicationLaunch.put("GridObj",publicGridData);

	applicationLaunch.put("selectionDetails",selectionDetails);
	}
	else
	{
	data.put("noMeasures",intlmap.getTextDescription("reporter.common.No measures available for the current selection"));
			lst.add(intlmap.getTextDescription("reporter.common.No measures available for the current selection"));
		// no measure functionality
	}
	applicationLaunch.put("data",data);
	//

	Hashtable h_tabrc = new Hashtable();	//SubTable Data
	Hashtable h_tab = new Hashtable();	//SubTitle with SubTable Data
	String s_title = "";

		h_tabrc.put(v_measure_csv,list_data);
		h_tab.put(s_title,h_tabrc);
		lst.add(h_tab);
		if(lst!= null && !lst.isEmpty())
		{
			session.setAttribute("list",lst);
		}
		Map parameters = new HashMap();
		parameters= request.getParameterMap();
		String queryString =(String)ErUtils.prepareQueryString(request.getParameterMap());
		String Qstring="";
		String lastAccessQstring="";
		if(queryString!=null)
		{
			StringTokenizer strtok = new StringTokenizer(queryString,"&");
			while(strtok.hasMoreTokens())
			{
				String param = strtok.nextToken();
				int ind = param.indexOf("=");
				if (ind < 0)
					continue;
				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") || reqparam.equals("er_workgrpname") || reqparam.equals("er_trgttype") || reqparam.equals("limitforbg") || reqparam.equals("er_timeline") || reqparam.equals("er_usertimeline") || reqparam.equals("er_top") || reqparam.equals("limitforbg") || reqparam.equals("limitforbg")) )
				{
					value=com.eg.EgURLEncoder.encode(value, "UTF-8");
				}
				
					lastAccessQstring=lastAccessQstring+reqparam+"="+value+"&";
			//
				if(reqparam!=null&&reqparam.equals("er_application"))
				{
				continue;
				}
					if(reqparam!=null&&reqparam.equals("er_component"))
				{
				continue;
				}


			//
				Qstring=Qstring+reqparam+"="+value+"&";
			}
			Qstring=Qstring;
		}
		pageWith += 100;
		Qstring+="&pageWidthProces="+pageWith;
		String dataProcess = mngrIProc+"/final/reporter/ErApplicationBillingReportPrint.jsp;jsessionid="+ session.getId()+"?"+Qstring;

			session.setAttribute("MAIL_URL",dataProcess);
				HashMap hmQry = ErUtils.parseQueryString(Qstring);
				String targetType = "";
				if(hmQry != null && hmQry.get("er_trgttype") instanceof String)
				{
					targetType = (String)hmQry.get("er_trgttype");
				}
				else if(hmQry != null && hmQry.get("er_trgttype") instanceof String[])
				{
					targetType = ((String[])hmQry.get("er_trgttype"))[0];
				}
				if (targetType != null && targetType.equalsIgnoreCase("Application+Launch+Count+Report"))
				{
					hmQry.remove("er_application");
					hmQry.remove("er_component");
				}
				String qString = ErUtils.prepareQueryString(hmQry);
				urlFields.put("saveQueryString",qString);
		//
		ArrayList listbackvar = new  ArrayList();
		if(request.getParameter("isSubmit")!=null)
		{
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErApplicationBillingReport.jsp?"+lastAccessQstring);
			listbackvar.add("/servlet/com.eg.ErApplicationBillingReportC?");
			listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
			session.setAttribute("favSchBackDisplay","Yes");
		}
		else
		{
			session.setAttribute("reportLastAccessedURL","/final/reporter/ErApplicationBillingReport.jsp?"+lastAccessQstring);
			listbackvar.add("ErApplicationBillingReport.jsp");
			listbackvar.add(queryString);
			session.setAttribute("favSchBackDisplay","No");
		}
	session.setAttribute("reportLastAccessedURL","/final/reporter/ErApplicationBillingReport.jsp?"+lastAccessQstring);
		String backadded = erhelputils.getBackID();
		backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
		session.setAttribute("backQuery",backreqMap);

		//Back button - End




		applicationLaunch.put("selectedFields",selectedFields);
		applicationLaunch.put("hiddenFields",hiddenFields);
		applicationLaunch.put("combo",combo);
		applicationLaunch.put("labelFields",labelFields);
		applicationLaunch.put("urlFields",urlFields);
		
		out.println(applicationLaunch.toString());
}catch(Throwable t)
{t.printStackTrace();}

	//For Setting the PDf File Name
	HashMap paramVal =new HashMap();
	paramVal.put("fileName","Application_Billing_Report");
	session.setAttribute("parameters", paramVal);
%>
<%!
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;
 }
 %>

 <%!
    public  String customReplaceAll(String source,String toReplace,String replacement) {
        int idx = source.lastIndexOf(toReplace);
        if (idx != -1) {
            StringBuffer ret = new StringBuffer(source);
            ret.replace(idx, idx + toReplace.length(), replacement);
            while ((idx = source.lastIndexOf(toReplace, idx - 1)) != -1) {
                ret.replace(idx, idx + toReplace.length(), replacement);
            }
            source = ret.toString();
        }
        return source;
    }

%>