<%@ include file = "ErReporterTracker.jsp" %>
<%@ page import = "com.eg.EgDateInfo" %>
<%@ page import = "egurkha.reporter.*" %>
<%@ page import = "com.eg.EgGroupInfo" %>
<%@ page import = "com.eg.EgDiscInfo" %>
<%@ page import = "com.eg.EgTopoInfo" %>
<%@ page import = "com.eg.EgServicesInfo" %>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import = "com.eg.EgTablesInfo" %>
<%@ page import = "com.eg.EgTesterInfo" %>
<%@ page import = "com.eg.EgURLEncoder" %>
<%@ page import = "com.eg.EgURLDecoder" %>
<%@ page import = "com.egurkha.util.DateTimeTokenizer" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import = "com.eg.IniFile" %>
<%@ page import = "com.egurkha.pdfmaker.*" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "java.util.ListIterator"%>
<%@ page import = "net.sf.json.*"%>
<%@ page import ="com.egurkha.util.StringUtils"%>
<%@ page import = "com.eg.EgTestInfo"%>
<%@ page import = "com.eg.MappingNameSorter"%>
<%@ page import = "com.eg.EgName" %>
<%@ page import = "java.util.Date" %>


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

<%
	String titleToDisplay=request.getParameter("er_RmDispName");
	boolean bottleneck = true;
	int cnt=0;
	boolean isBasedCpu=false;
	boolean isBasedMemory=false;
	boolean hasAllComponentAccess = false;
	EgUserRole userRole    = thisuser.getUserRole();
	hasAllComponentAccess = userRole.hasAllComponentAccess();
	String bottleneckField = "";
	JSONObject rootJson = new JSONObject();
	JSONObject selectedObj = new JSONObject();
	JSONObject hiddens = new JSONObject();
	JSONObject selectionDetails = new JSONObject();
	JSONObject screenLabels = new JSONObject();
	JSONObject backgroundResultObj = new JSONObject();
	JSONObject resultsObj = new JSONObject();
	String skinColor = "";
	skinColor = thisuser.getReporterSkin();

	//Back Button - Start
	String bggroundStr = (String)request.getAttribute("bggroundStr");
	String status = (String)request.getAttribute("status");	
	HashMap backreqMap = (HashMap)session.getAttribute("backQuery");
	String backQnumber = request.getParameter("backQnumber");
	String servlet2 = request.getParameter("backServletName");
	String er_option = request.getParameter("er_option");
	String er_site = request.getParameter("er_site");
	String er_includeZones = request.getParameter("er_includezones");
	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 queryString="";
	String backButtonEnable = request.getParameter("back");
	rootJson.put("ID","backQnumber="+erhelputils.getBackID()+"&"+erhelputils.getQueryString());
	if(backButtonEnable != null && backButtonEnable.equalsIgnoreCase("True"))
	{
		status = (String)request.getParameter("status");
		bggroundStr = (String)request.getParameter("bggroundStr");
		request.setAttribute("VcCapacity_REPORT_RESULT", null);
	}
	String noOfDays="";
	//Back Button - End
%>

<%!
	private static final String BLANK_SPACE = " ";
	private static final String COMA = ",";
	private static final String COLON = ":";
	private static final String UTF_8 = "UTF-8";
	private static final String DD_MM_YYYY = "dd/MM/yyyy";
	private static final String DD_MM_YYYY_HH_MM_SS = DD_MM_YYYY + " HH:mm:ss";
%>

<%
	try
	{
		long t1 = System.currentTimeMillis();
		String isSubmit = request.getParameter("isSubmit");

		response.setHeader("Cache-Control","no-store");
		response.setHeader("Pragma","no-cache");
		response.setDateHeader("Expires", -1);
		
		EgDiscInfo discInfo = new EgDiscInfo("manager");
		EgReportInfo reportInfo = new EgReportInfo("manager");
		EgTopoInfo topoInfo = new EgTopoInfo("manager");
		EgTablesInfo tablesInfo = new EgTablesInfo ("manager");
		EgTesterInfo testerInfo = new EgTesterInfo ("manager");
		UBean = new ErUserData(urs,false);
		ErUserData erdata = new ErUserData(UBean.getUserId(),false); //boolean arg given to check Ent or asplite
		User this_user = UserRegistry.getInstance().getUser(session.getId());
		com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();
		UserRegistry mregistry = UserRegistry.getInstance();
		User muser = mregistry.getUser(session.getId());
		EgDateInfo egDt = new EgDateInfo();
		ErUtils erUtils = new ErUtils();
		EgGroupInfo gpinfo = new EgGroupInfo();
		ErEsxVMutils erEsxUtils = new ErEsxVMutils();
		IniFile eg_report = new IniFile(EgInstallInfo.getInstallDir() +"/manager/config/eg_report.ini");
		String thisLanguage = ui.getDefaultLanguage();
		if (muser!=null)
		{
			String userLang = muser.getLanguage();
			if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
			{
				thisLanguage=userLang;
			}
		}
		EgMappingInfo intlmap = new EgMappingInfo(thisuser.getLanguage());
		String mngrIProc = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
		ErComponentsUtils compUtil = new ErComponentsUtils(thisuser.getLoginID());
		String font = ui.getFontName();
		String userid = UBean.getUserId();
		long msecsPerHour = (long) 1000 * 60 * 60;
		String uiFile = "eg_ui.ini";
		String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
		com.eg.IniFile egUI = new com.eg.IniFile(s_iniFile_dir + uiFile);
		String currentDateFormat = strUserDateFormat;
		SimpleDateFormat sd_currentDateFormat = new SimpleDateFormat(currentDateFormat + " HH:mm:ss");
		HashMap resultMap = (HashMap)session.getAttribute("CITRIX_CAPACITY_PREDICTION_REPORT_RESULT");


		//Back Button - Start
		queryString = null;
		//Back Button - End
		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 er_time     = request.getParameter("er_time");
		String s_inidate   = request.getParameter("inidate");
		String fromDash    = request.getParameter("isDash");
		String schedule_id = request.getParameter("schedule_id");
		String reqFromSchedule = request.getParameter("fromSchedule");	
		String fromScheduleModify = request.getParameter("fromScheduleModify");
		String fromFavoriteModify = request.getParameter("fromFavoriteModify");
		String favorite_id = request.getParameter("id");
		String er_favorite = request.getParameter("er_favorite");
		String divStatus = request.getParameter("divStatus");
	
		String dispCsvStartDate = s_st_time+" "+s_st_hr+":"+strmin;
		String dispCsvEndDate = s_en_time+" "+s_en_hr+":"+enmin;
		
		String drillStartDate = s_st_time+" 00:00";
		String drillEndDate = s_en_time+" 00:00";
		EgTimeZoneConverter converterStart=null;
		EgTimeZoneConverter converterEnd=null;
		String dispDate = null;
		String comFormat = null;
		String st_dateTime="";
		String en_dateTime="";
		if(s_st_time!=null)
		{
			if(DateUtil.isDate(s_st_time,"MM/dd/yyyy"))
			{
				comFormat = "MM/dd/yyyy";
			}
			else
			{
				comFormat = currentDateFormat;
			}
			dispDate = 	DateUtil.changeDateFormat(s_st_time,comFormat,currentDateFormat);
			converterStart = new EgTimeZoneConverter(dispDate+" "+s_st_hr+":"+strmin,thisuser);
			st_dateTime=converterStart.getDateTime();
		}
		if(s_en_time!=null)
		{
			if(DateUtil.isDate(s_en_time,"MM/dd/yyyy"))
			{
				comFormat = "MM/dd/yyyy";
			}
			else
			{
				comFormat = currentDateFormat;
			}
			dispDate = 	DateUtil.changeDateFormat(s_en_time,comFormat,currentDateFormat);
			converterEnd = new EgTimeZoneConverter(dispDate+" "+s_en_hr+":"+enmin,thisuser);
			en_dateTime=converterEnd.getDateTime();
		}
		if(er_timeline!=null&&er_timeline.equals("Any"))
		{
			try {
				if(s_st_time!=null && s_en_time!=null&& currentDateFormat!=null)
				{
					SimpleDateFormat myFormat = new SimpleDateFormat(currentDateFormat);
					java.util.Date date1 = myFormat.parse(s_st_time);
					java.util.Date date2 = myFormat.parse(s_en_time);
					long diff = date2.getTime() - date1.getTime();
					int dayss= (int)( (date2.getTime() - date1.getTime()) / (1000 * 60 * 60 * 24));
					if(dayss==0 || dayss==1)
						noOfDays=dayss+" day";
					else
						noOfDays=dayss+" days";
				}

			} catch (Exception e) {}
		}
		ErReportHelper erh = new ErReportHelper();
		if(er_timeline == null)
		{
			String strUsrTimelines = erh.getUserTimeline(thisuser.getLoginID());
			if(strUsrTimelines.equals("-1"))
			{
				er_timeline="1 month";
			}
			else
			{
				er_timeline=strUsrTimelines;
			}
		}
		List v_site=new ArrayList();
		Vector v_component	= new Vector();
		Vector temp_component = new Vector();
		Vector v_comptype = new Vector();
		List compList = new ArrayList();
		Vector v_zones = new Vector();
		ArrayList listCompTypes =reportInfo.getComponent("CITRIX_CAPACITY_PREDICTION",false);
		Vector v_componentName = new Vector();
		EgTestInfo tokInfo = new EgTestInfo("manager");
		MappingNameSorter sorter = new MappingNameSorter(thisLanguage);
		ErInfo erInfo = new ErInfo();
		String selectedComp[] = request.getParameterValues("er_component");
		String isFavorite = request.getParameter("isFavorite");
		EgCrawler crawlerBean = new EgCrawler(new IniFile(s_iniFile_dir + "eg_topology.ini"));
		String comp_type=request.getParameter("er_comptype");
		String comp_name=request.getParameter("er_component");
		String fromMenu = request.getParameter("fromMenu");
		String strcompname = "";
		Hashtable htAllGroups=erEsxUtils.getGroups(null,listCompTypes, thisuser, thisuser.getLoginID(), "Yes",true);
		ArrayList v_options = erEsxUtils.getOptions(htAllGroups);
		ArrayList aListComponentTemp = null;
		if(v_options!=null)
		{
			if(v_options.contains("Service"))
			{
				v_options.remove("Service");
			}
			if(v_options.contains("Segment"))
			{
				v_options.remove("Segment");
			}
			if(v_options.contains("Zone"))
			{
				if (er_option == null)
				{
					er_option = "Zone";
				}
			}
		}
		if (er_option == null)
		{
			er_option = (String)v_options.get(0);
		}

		ArrayList removeList = new ArrayList();
		JSONArray comboArray =  new JSONArray();
		JSONObject loopJsonObj = new JSONObject();
		comboArray =  new JSONArray();
		for (int i=0; i<v_options.size();i++)
		{
			String tempStr = (String) v_options.get(i);
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common."+tempStr));
			loopJsonObj.put("valueField",tempStr);
			comboArray.add(loopJsonObj);
			if(er_option.equals(tempStr))
			{
				selectedObj.put("er_option",er_option);
			}
		}
		rootJson.put("anlyzeCombo",comboArray);
		selectionDetails.put(intlmap.getTextDescription("reporter.thin.Analysis By"),intlmap.getTextDescription("reporter.thin."+er_option));
		if(er_option!=null && !er_option.equalsIgnoreCase("Component"))
		{
			v_site = erEsxUtils.getGroupsName(htAllGroups,er_option);
			if(er_option.equalsIgnoreCase("Zone"))
			{
				ArrayList defaultZoneCompList = erEsxUtils.getComponentForGroup(htAllGroups,er_option,"--Default--");
				if(!hasAllComponentAccess)
				{
					defaultZoneCompList = null;
				}
				if(defaultZoneCompList==null || defaultZoneCompList.size()==0)
				{
					if(v_site!=null && v_site.contains("--Default--"))
					{
						v_site.remove("--Default--");
					}
				}
			}
			if(er_site==null || (er_site != null && er_site.equalsIgnoreCase("null")))
			{
				if(v_site!=null && v_site.size()>0)
				{
					er_site = (String)v_site.get(0);
				}
				else
				{
					er_site = "";
				}
			}
			comboArray =  new JSONArray();
			if (v_site!=null && v_site.size() > 0)
			{
				for (int i=0; i<v_site.size(); i++)
				{
					String tempStr = (String)v_site.get(i);
					loopJsonObj = new JSONObject();
					if(tempStr.equalsIgnoreCase("--Default--"))
					{
						loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.--Default--"));
					}
					else
					{
						loopJsonObj.put("displayField",tempStr);
					}
					loopJsonObj.put("valueField",tempStr);
					comboArray.add(loopJsonObj);
					if (tempStr.equalsIgnoreCase(er_site))
					{
						selectedObj.put("er_site", er_site);
					}
				}
			}
			else
			{
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
				loopJsonObj.put("valueField", "-1");
				comboArray.add(loopJsonObj);
				selectedObj.put("er_site", "-1");
			}
			if(er_site!=null && er_site.length()>0)
			{
				aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,er_site);
			}
			selectionDetails.put(intlmap.getTextDescription("reporter.thin."+er_option),er_site);
			rootJson.put("siteCombo",comboArray);
		}
		else
		{
			aListComponentTemp = erEsxUtils.getComponentForGroup(htAllGroups,er_option,null);
		}
		screenLabels.put("reporter.common.siteLabel",intlmap.getTextDescription("reporter.common."+er_option));
		comboArray =  new JSONArray();
		if(aListComponentTemp!=null)
		{
			for(int n=0;n<aListComponentTemp.size();n++)
			{
				String comp = (String)aListComponentTemp.get(n);
				int index=comp.lastIndexOf(":");
				if(index>-1)
				{ 
					String  v_componentType = comp.substring(index+1,comp.length()); 
					if(!v_comptype.contains(v_componentType))
					{
						v_comptype.add(v_componentType);
						if(comp_type == null || comp_type.equals("-1") || comp_type.equals("")) // it will comes very first time only
						{
							comp_type = (String) v_comptype.get(0);
						}
					}
					if(comp_type!=null && comp_type.equalsIgnoreCase(v_componentType))
					{
						compList.add(comp);
					}
				}
			}
		}
		if (v_comptype.size() > 0)
		{
			v_comptype=compUtil.getIntnlSupportCompType(v_comptype,"#");
			for (int i=0 ; i< v_comptype.size(); i++)
			{
				String s=(String)v_comptype.get(i);
				ArrayList aListData = tokInfo.egTokenizer(s,"#");
				String CompTypeDisp=(String)aListData.get(0);
				String CompTypeValue=(String)aListData.get(1);
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",CompTypeDisp);
				loopJsonObj.put("valueField",CompTypeValue);
				comboArray.add(loopJsonObj);
				if (!StringUtils.isNull(CompTypeValue) && CompTypeValue.equalsIgnoreCase(comp_type))
				{
					selectedObj.put("er_comptype", comp_type);
					selectionDetails.put(intlmap.getTextDescription("reporter.thin.Component Type"),CompTypeDisp);
				}
			}
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			selectedObj.put("er_comptype", "-1");
			comboArray.add(loopJsonObj);
		}
		rootJson.put("compTypeCombo",comboArray);
		
		selectionDetails.put(intlmap.getTextDescription("reporter.thin.Analysis By"),intlmap.getTextDescription("reporter.thin."+er_option));
		comboArray =  new JSONArray();
		if (compList!=null && compList.size() > 0)
		{
			if(comp_name==null)
			{
				comp_name = (String)compList.get(0);
			}
			for (int i=0; i<compList.size(); i++)
			{
				String tempStr = (String)compList.get(i);
				String dispStr = tempStr;
				if(dispStr.indexOf(":")>-1)
				{
					dispStr = dispStr.substring(0,dispStr.indexOf(":"));
				}
				loopJsonObj = new JSONObject();
				loopJsonObj.put("displayField",dispStr);
				loopJsonObj.put("valueField",tempStr);
				comboArray.add(loopJsonObj);
				if (tempStr.equalsIgnoreCase(comp_name))
				{
					selectedObj.put("er_componentname", comp_name);
				}
			}
		}
		else
		{
			loopJsonObj = new JSONObject();
			loopJsonObj.put("displayField",intlmap.getTextDescription("reporter.common.Not Applicable"));
			loopJsonObj.put("valueField", "-1");
			comboArray.add(loopJsonObj);
			selectedObj.put("er_componentname", "-1");
		}
		rootJson.put("componentCombo",comboArray);
		
		Vector v_time = new Vector();
		v_time.add("00");
		v_time.add("01");
		v_time.add("02");
		v_time.add("03");
		v_time.add("04");
		v_time.add("05");
		v_time.add("06");
		v_time.add("07");
		v_time.add("08");
		v_time.add("09");
		v_time.add("10");
		v_time.add("11");
		v_time.add("12");
		v_time.add("13");
		v_time.add("14");
		v_time.add("15");
		v_time.add("16");
		v_time.add("17");
		v_time.add("18");
		v_time.add("19");
		v_time.add("20");
		v_time.add("21");
		v_time.add("22");
		v_time.add("23");

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

		String timefrom1=(erh.getTimeFrame("TIMEFRAME","From")==null) ? "00:00" :erh.getTimeFrame("TIMEFRAME","From");
		String timeto1=(erh.getTimeFrame("TIMEFRAME","To")==null) ? "23:59" :erh.getTimeFrame("TIMEFRAME","To");
		timefrom1 = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","startTime");
		timeto1 = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","endTime");
		String timefrom="";
		String minfrom="";
		String timeto="";
		String minto="";
		StringTokenizer st;
		if(timefrom1 != null)
		{
			st = new StringTokenizer(timefrom1,":");
			if(st.hasMoreTokens())
			{
				timefrom=st.nextToken();
				minfrom=st.nextToken();
			}
		}
		if(timeto1 != null)
		{
			st=new StringTokenizer(timeto1,":");
			if(st.hasMoreTokens())
			{
				timeto=st.nextToken();
				minto=st.nextToken();
			}
		}
		String timefrom2 = request.getParameter("timefrom");
		String minfrom2 = request.getParameter("minfrom");
		String timeto2 = request.getParameter("timeto");
		String minto2 = request.getParameter("minto");

		if (timefrom2!=null)
			timefrom = timefrom2;
		if (minfrom2!=null)
			minfrom = minfrom2;
		if (timeto2!=null)
			timeto = timeto2;
		if (minto2!=null)
			minto = minto2;

		//Date calculation according to time select
		String[] options = {"Any","1 week","2 weeks","3 weeks","4 weeks","1 month", "2 months",
					"3 months", "6 months", "12 months", "18 months", "24 months", "30 months", "36 months"};

		String startDateTime = "";
		String endDateTime = "";
		
		if(er_timeline!=null&&!er_timeline.equals("Any"))
		{
			int blankSpaceIndex = er_timeline.indexOf(DateTimeTokenizer.BLANK_SPACE);
			if (blankSpaceIndex > 0)
			{
				SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm");
				java.util.Date today =  egDt.egetRealDate();
				endDateTime = sdf.format(today);

				long value = Integer.parseInt(er_timeline.substring(0, blankSpaceIndex));
				String unit = er_timeline.substring(blankSpaceIndex+1).toLowerCase();
				if (unit.startsWith("h"))
				{//hours
					value *= 3600;
				}
				else if (unit.startsWith("d"))
				{//days
					value *= (24 * 3600);
				}
				else if (unit.startsWith("w"))
				{
					if(unit.endsWith("last"))
					{
						//last week
						int weekCount = (int) value;
						SimpleDateFormat simpledf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
						java.util.Date currDateTime = egDt.egetRealDate();
						String currentDateTime = simpledf.format(currDateTime);
						String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
						String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
						String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.lastIndexOf(":"));
						String userFormat = thisuser.getUserDateFormat();
						String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy", userFormat); 
						EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin,thisuser);
						java.util.Date realDate=new SimpleDateFormat(userFormat).parse((String) realDateTime.getDate(false));
						Calendar c = Calendar.getInstance();
						c.setTime(realDate);
						int i = c.get(Calendar.DAY_OF_WEEK) - c.getFirstDayOfWeek() * weekCount;
						int startDayCount = 7 * weekCount + (1 * (weekCount - 1));
						int lastDayCount = 6 * weekCount + (1 * (weekCount - 1));
						c.add(Calendar.DATE, - i - startDayCount);
						c.set(Calendar.HOUR, 00);
						c.set(Calendar.MINUTE, 00);
						java.util.Date start = c.getTime();
						startDateTime = new SimpleDateFormat(userFormat).format(start);
						c.add(Calendar.DATE, lastDayCount);	
						c.set(Calendar.HOUR, 23);
						c.set(Calendar.MINUTE, 00);
						java.util.Date end = c.getTime();
						endDateTime = new SimpleDateFormat(userFormat).format(end);
					}
					else
					{
						//weeks
						value *= (7 * 24 * 3600);
					}
				}
				else if (unit.startsWith("mo"))
				{
					if(unit.endsWith("last"))
					{//last month
						int monthCount = (int) value;
						SimpleDateFormat simpledf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
						java.util.Date currDateTime = egDt.egetRealDate();
						String currentDateTime = simpledf.format(currDateTime);
						String currentDate = currentDateTime.substring(0, currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE));
						String currentHr = currentDateTime.substring(currentDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, currentDateTime.indexOf(":"));
						String currentMin = currentDateTime.substring(currentDateTime.indexOf(":")+1, currentDateTime.lastIndexOf(":"));
						String userFormat = thisuser.getUserDateFormat();
						String curFormatDate = DateUtil.changeDateFormat(currentDate,"MM/dd/yyyy", userFormat); 
						EgTimeZoneConverter realDateTime = new EgTimeZoneConverter(curFormatDate+" "+currentHr+":"+currentMin,thisuser);
						java.util.Date realDate=new SimpleDateFormat(userFormat).parse((String) realDateTime.getDate(false));
						Calendar c = Calendar.getInstance();
						c.setTime(realDate);
						c.add(Calendar.MONTH, -monthCount);
						c.set(Calendar.DATE, 1);
						c.set(Calendar.HOUR, 00);
						c.set(Calendar.MINUTE, 00);
						java.util.Date start = c.getTime();
						startDateTime = new SimpleDateFormat(userFormat).format(start);
						Calendar c1 = Calendar.getInstance();
						c1.setTime(realDate);
						c1.add(Calendar.MONTH, -1);
						c1.set(Calendar.DAY_OF_MONTH, c1.getActualMaximum(Calendar.DAY_OF_MONTH));
						c1.set(Calendar.HOUR, 23);
						c1.set(Calendar.MINUTE, 59);
						java.util.Date end = c1.getTime();
						endDateTime = new SimpleDateFormat(userFormat).format(end);
					}
					else
					{
						//months
						java.util.Date dt_temp = egDt.egetRealDate();
						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")&& !unit.endsWith("last"))
				{
					java.util.Date start = new java.util.Date();
					java.util.Date startTmp=new java.util.Date(endDateTime);
					start.setTime(startTmp.getTime() - (value * 1000));
					startDateTime = sdf.format(start);
				}
			}
			if ((startDateTime != null) && (endDateTime != null))
			{
				s_inidate="MM/dd/yyyy";
				try
				{
					int shr=Integer.parseInt(startDateTime.substring(startDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, startDateTime.indexOf(":")));
					int en_hr=Integer.parseInt(endDateTime.substring(endDateTime.indexOf(DateTimeTokenizer.BLANK_SPACE)+1, endDateTime.indexOf(":")));
					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 = "0";
					s_en_hr = "0";
					strmin="0";
					enmin="0";
				}
				catch(Exception e)
				{
					System.out.println("Eception caught :"+e);
					e.printStackTrace();
				}
			}
		}

		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(new java.util.Date());
			}
			catch(Exception ee)
			{
				System.out.println("Exception is"+ee);
			}
			String SDate =StrDate.substring(0,StrDate.indexOf(" "));
			String shour =StrDate.substring(StrDate.indexOf(" "),StrDate.lastIndexOf(""));
			shour = shour.substring(0,3);
			if(s_st_time==null)
			{
				s_st_time=SDate;
				s_inidate="MM/dd/yyyy";
			}
			if(s_en_time==null)
			{
				s_en_time=SDate;
			}
			if(s_st_hr==null)
			{
				shour =shour.trim();
				int starthr = Integer.parseInt(shour);
				starthr = starthr-1;
				s_st_hr=String.valueOf(starthr);
			}
			if(s_en_hr==null)
			{
				shour =shour.trim();
				s_en_hr =shour;
			}
		}
		String s_title = "";	
		boolean noDataFound = false;
		if(resultMap != null && isSubmit != null && isSubmit.equalsIgnoreCase("true"))
		{
			String noData = (String) resultMap.get("NO_DATA_FOUND");
			if(noData != null && noData.equalsIgnoreCase("yes"))
				noDataFound = true;
		}
		String confirmation = reportInfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
		String strbgrepportName = reportInfo.getValue("BACKGROUND_PROCESS","EnableBackgroundReport");
		String limitforbg = reportInfo.getValue("BACKGROUND_PROCESS","MinDurationForReport");
		boolean isBackgroundProcess = false;
		
		String er_type = request.getParameter("er_type");
		if(er_type == null) {
			er_type="Yes";
		}

		String excludeweekend = request.getParameter("er_excwe");
		if (excludeweekend == null || excludeweekend.equals("")) {
			excludeweekend = "Yes";
		}
		String Days = (erh.getExcludeWeekends("EXCLUDE_WEEKEND","Days") == null) ? 
				"Saturday,Sunday" : erh.getExcludeWeekends("EXCLUDE_WEEKEND","Days");
		request.setAttribute("Weekends",Days);
		EgDbInfo dbInfo = new EgDbInfo("manager");
		String pdfPrint = request.getParameter("pdfPrint");
		String sample = request.getParameter("sample");
		hiddens.put("currTime", "");
		hiddens.put("er_rtype", "Citrix Server");
		hiddens.put("er_trgttype", "Citrix_Capacity_Prediction");
		hiddens.put("font", font);
		hiddens.put("reporttype", request.getParameter("reporttype"));
		hiddens.put("eruserid", userid);
		hiddens.put("er_combination", "");
		hiddens.put("fromSchedule", reqFromSchedule);
		if(fromScheduleModify!=null)
			hiddens.put("fromScheduleModify",fromScheduleModify);
		else
			hiddens.put("fromScheduleModify","null");
		if(fromFavoriteModify!=null)
			hiddens.put("fromFavoriteModify",fromFavoriteModify);
		else
			hiddens.put("fromFavoriteModify","null");
		hiddens.put("favorite_id", favorite_id);
		hiddens.put("er_favorite", er_favorite);

		hiddens.put("schedule_id", schedule_id);
		hiddens.put("er_ViewName", "ErCitrixCapacityPredictionReport.jsp");
		hiddens.put("er_trenddata", "");
		hiddens.put("inidate", currentDateFormat);
		hiddens.put("getMaxDaysInMonth", String.valueOf(ErUtils.getMaxDaysInMonth()));
		hiddens.put("isSchedule", "false");
		hiddens.put("isFavorite", "false");
		hiddens.put("er_flag", "true");
		hiddens.put("userID", urs);
		hiddens.put("forwardto", "ErCitrixCapacityPredictionReport");
		hiddens.put("er_bgreportfrom", "Citrix_CapacityPrediction");
		hiddens.put("bgenabled", strbgrepportName);
		hiddens.put("limitforbg", limitforbg);
		hiddens.put("savereport", "save");
		hiddens.put("servletName", "com.eg.ErCitrixCapacityPredictionReportC");
		hiddens.put("fromMenu", "false");
		hiddens.put("divStatus", divStatus);
		screenLabels.put("reporter.common.reportType", intlmap.getTextDescription("reporter.common.Report Type"));
		String strGraphChecked="";
		String strDataChecked="";
	
		JSONArray reportTypeArr = new JSONArray();
		JSONObject reportTypeObj = new JSONObject();
		reportTypeObj.put("displayField", intlmap.getTextDescription("reporter.common.Graph"));
		reportTypeObj.put("valueField", "Yes");
		reportTypeArr.add(reportTypeObj);
		reportTypeObj = new JSONObject();
		reportTypeObj.put("displayField", intlmap.getTextDescription("reporter.common.Data"));
		reportTypeObj.put("valueField", "No");
		reportTypeArr.add(reportTypeObj);
		rootJson.put("reportTypeCombo", reportTypeArr);

		if(er_type == null || er_type.equals("Yes"))
		{
			strGraphChecked = "checked";
			strDataChecked = "";
			selectedObj.put("reportTypeSelected", "Yes");
		}
		else
		{
			strGraphChecked = "";
			strDataChecked = "checked";
			selectedObj.put("reportTypeSelected", "No");
		}
		screenLabels.put("reporter.common.excludeweekends", intlmap.getTextDescription("reporter.common.Exclude weekends"));

		JSONArray excludeWeekArr = new JSONArray();
		JSONObject excludeWeekObj = new JSONObject();
		excludeWeekObj.put("valueField", "Yes");
		excludeWeekObj.put("displayField", intlmap.getTextDescription("reporter.common.Yes")+" ("+Days+") ");
		excludeWeekArr.add(excludeWeekObj);
		excludeWeekObj = new JSONObject();
		excludeWeekObj.put("valueField", "No");
		excludeWeekObj.put("displayField", intlmap.getTextDescription("reporter.common.No"));
		excludeWeekArr.add(excludeWeekObj);
		rootJson.put("excludeWeekCombo", excludeWeekArr);
		Vector v_selection = new Vector();	
		if(excludeweekend.equalsIgnoreCase("Yes") )
		{
			selectedObj.put("excludeWeekSelected", "Yes");
			rootJson.put("excludeWeekEndMsg",intlmap.getTextDescription("reporter.common.Excludes")+ " " +Days);
		}
		else
		{
			selectedObj.put("excludeWeekSelected", "No");
			rootJson.put("excludeWeekEndMsg",intlmap.getTextDescription("reporter.common.Excludes")+ " " +Days);
		}
		screenLabels.put("reporter.common.Timeperiod", intlmap.getTextDescription("reporter.common.Time period"));
		screenLabels.put("reporter.common.From", intlmap.getTextDescription("reporter.common.From"));
		screenLabels.put("reporter.common.To", intlmap.getTextDescription("reporter.common.To"));
		screenLabels.put("reporter.common.Hrs", intlmap.getTextDescription("reporter.common.Hrs"));
		screenLabels.put("reporter.common.Mins", intlmap.getTextDescription("reporter.common.Mins"));
		selectedObj.put("timePeriodFromHrSelected", timefrom);
		selectedObj.put("timePeriodFromMinSelected", minfrom);

		selectedObj.put("timePeriodToHrSelected", timeto);
		selectedObj.put("timePeriodToMinSelected", minto);

		screenLabels.put("reporter.common.Timeline", intlmap.getTextDescription("reporter.common.Timeline"));
	%>
	
	<%@include file ="ErTimeFormatJSON.jsp"%>
	
	<%
		screenLabels.put("timelineHr", intlmap.getTextDescription("reporter.common.Hr"));
		hiddens.put("er_usertimeline", strUsrTimeline);
		screenLabels.put("reporter.common.Timeline", intlmap.getTextDescription("reporter.common.Timeline"));
		screenLabels.put("reporter.common.From", intlmap.getTextDescription("reporter.common.From"));
		screenLabels.put("reporter.common.To", intlmap.getTextDescription("reporter.common.To"));
		screenLabels.put("reporter.common.Hr", intlmap.getTextDescription("reporter.common.Hr"));
		screenLabels.put("reporter.common.Graph", intlmap.getTextDescription("reporter.common.Graph"));
		rootJson.put("timelineCombo",timelineComboArray);
		rootJson.put("timelineHourCombo",timelineHourComboArray);
		selectedObj.put("selectedTimeline",er_timeline);
		selectedObj.put("startDate",startDateJSON);
		selectedObj.put("endDate",endDateJSON);
		selectedObj.put("startHour",startHourJSON);
		selectedObj.put("endHour",endHourJSON);
		selectedObj.put("startmin", strmin);
		selectedObj.put("endmin", enmin);
		selectedObj.put("selectedGraphMode",selectedGraphMode);

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

		screenLabels.put("reporter.consolidated.reportGeneration", intlmap.getTextDescription("reporter.consolidated.Report Generation"));
		screenLabels.put("reporter.consolidated.reportName", intlmap.getTextDescription("reporter.consolidated.Report Name"));

		String er_reportgenration = request.getParameter("er_reportgenration");
		String er_background ="";
		String er_foreground ="";
		JSONArray reportGenArr = new JSONArray();
		JSONObject reportGenObj = new JSONObject();
		reportGenObj.put("valueField", "background");
		reportGenObj.put("displayField", strbackground);
		reportGenArr.add(reportGenObj);

		reportGenObj = new JSONObject();
		reportGenObj.put("valueField", "foreground");
		reportGenObj.put("displayField", strforeground);
		reportGenArr.add(reportGenObj);

		rootJson.put("reportGenCombo", reportGenArr);

		if (er_reportgenration != null && er_reportgenration.equals("background"))
		{
			er_background = "selected";
			er_foreground = "";
			selectedObj.put("reportGenSelected", "background");
		}
		else if (er_reportgenration != null && er_reportgenration.equals("background-csv"))
		{
			er_background = "selected";
			er_foreground = "";
			selectedObj.put("reportGenSelected", "background-csv");
		}
		else
		{
			er_background = "";
			er_foreground = "selected";
			selectedObj.put("reportGenSelected", "foreground");
		}
		String bg_reportname = request.getParameter("bg_reportname");
		if(bg_reportname == null)
		{
			bg_reportname = "";
		}
		if(strbgrepportName != null && strbgrepportName.equalsIgnoreCase("Yes"))
		{
			if (er_reportgenration != null && er_reportgenration.equals("background"))
			{
				selectedObj.put("reportName",bg_reportname); 
			}
		}
		if(fromScheduleModify!=null && fromScheduleModify.equalsIgnoreCase("Yes"))
		{
			screenLabels.put("reporter.common.SUBMIT", intlmap.getTextDescription("reporter.common.Save"));
		}
		else
		{
			screenLabels.put("reporter.common.SUBMIT", intlmap.getTextDescription("reporter.common.SUBMIT"));
		}
		if(bggroundStr != null && !bggroundStr.equals(""))
		{
			String strreportName = "Citrix_CapacityPrediction";
			isBackgroundProcess = true;
			backgroundResultObj.put("status", status);
			String bgroundResponseTxt=bggroundStr;
			if(status != null && !status.equalsIgnoreCase("exceedLimit"))
			{
				bgroundResponseTxt=erbgreport.getlangsupportedString(bggroundStr,bgString,urs);
			}
			if(status != null && (status.equalsIgnoreCase("duplicate") || status.equalsIgnoreCase("exceedLimit")))
			{
				strreportName ="All Report Types";
			}
			if(strreportName!=null && strreportName.indexOf(" ") > -1)
			{
				strreportName = com.eg.EgURLEncoder.encode(strreportName, "UTF-8");
			}
			backgroundResultObj.put("backgroundResponseText", bgroundResponseTxt);
			backgroundResultObj.put("backgroundResponseURLLink", "/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");
			backgroundResultObj.put("backgroundResponseURLText", intlmap.getTextDescription("reporter.common.Click here to see a list of generated and processing reports"));
		}
		if(isSubmit != null && isSubmit.equalsIgnoreCase("true") && !isBackgroundProcess ) 
		{
			System.out.println("resultMap_____________ "+resultMap);
			HashMap resultDataMap = (HashMap)resultMap.get("RESULT_DATA");
			if(resultDataMap!=null)
			{
				JSONObject resultObj = new JSONObject();
				String SESSION_CONSUMED_CPU_UTIL=(String)resultDataMap.get("SESSION_CONSUMED_CPU_UTIL");
				if(SESSION_CONSUMED_CPU_UTIL==null)
					SESSION_CONSUMED_CPU_UTIL = "0";
				String SESSION_CONSUMED_DISK_USAGE=(String)resultDataMap.get("SESSION_CONSUMED_DISK_USAGE");
				if(SESSION_CONSUMED_DISK_USAGE==null)
					SESSION_CONSUMED_DISK_USAGE = "0";
				String SESSION_CONSUMED_NETWORK_USAGE=(String)resultDataMap.get("SESSION_CONSUMED_NETWORK_USAGE");
				if(SESSION_CONSUMED_NETWORK_USAGE==null)
					SESSION_CONSUMED_NETWORK_USAGE = "0";
				String SESSION_CONSUMED_MEM_UTIL=(String)resultDataMap.get("SESSION_CONSUMED_MEM_UTIL");
				if(SESSION_CONSUMED_MEM_UTIL==null)
					SESSION_CONSUMED_MEM_UTIL = "0";
				String TOTAL_SERVERS=(String)resultDataMap.get("TOTAL_SERVERS");
				if(TOTAL_SERVERS==null)
					TOTAL_SERVERS = "0";
				String CONCURRENT_SESSIONS=(String)resultDataMap.get("CONCURRENT_SESSIONS");
				if(CONCURRENT_SESSIONS==null)
					CONCURRENT_SESSIONS = "0";
				String UNIQUE_USER=(String)resultDataMap.get("UNIQUE_USER");
				if(UNIQUE_USER==null)
					UNIQUE_USER = "0";

				double CPU_UTIL=Double.parseDouble(SESSION_CONSUMED_CPU_UTIL);
				double DISK_USAGE=Double.parseDouble(SESSION_CONSUMED_DISK_USAGE);
				double NETWORK_USAGE=Double.parseDouble(SESSION_CONSUMED_NETWORK_USAGE);
				double MEM_UTIL=Double.parseDouble(SESSION_CONSUMED_MEM_UTIL);
				double SERVERS=Double.parseDouble(TOTAL_SERVERS);
				double SESSIONS=Double.parseDouble(CONCURRENT_SESSIONS);
				double USER=Double.parseDouble(UNIQUE_USER);
				double ADDITIONAL_SERVER=0.0;
				
				if(!noDataFound)
				{
					
					resultObj.put("UNIQUE_USER_ORIGINAL",erUtils.roundOffDigit(USER,0));
					resultObj.put("SESSIONS_ORIGINAL",erUtils.roundOffDigit(SESSIONS,0));
					resultObj.put("TOTAL_SERVERS_ORIGINAL",erUtils.roundOffDigit(SERVERS,0));
					
					String incresaseFactor = request.getParameter("increaseBy");
					String ChartMaxValue= reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","ChartMaxValue");
					double incresaseFactorVal = 0.0;
					double chartMaxValueVal = 100.0;
					System.out.println("incresaseFactor_________ "+incresaseFactor);
					if(incresaseFactor!=null && incresaseFactor.length()>0)
					{
						try
						{
							incresaseFactorVal = Double.parseDouble(incresaseFactor);
						}
						catch (Exception ex) 
						{
						}
					}
					if(ChartMaxValue!=null && ChartMaxValue.length()>0)
					{
						try
						{
							chartMaxValueVal = Double.parseDouble(ChartMaxValue);
						}
						catch (Exception ex) 
						{
						}
					}
					System.out.println("incresaseFactorVal____________ "+incresaseFactorVal);
					if(incresaseFactorVal>0)
					{
						double factorVal = USER/SESSIONS;
						long increaseUserby = (Math.round((incresaseFactorVal/100)*USER));
						USER = Math.round(USER+increaseUserby); // updated User
						SESSIONS = Math.round(USER/factorVal); //updated Session
					}
					// Calculate Merer Gauge Chart Value
					double maxValue = 0;
					String maxValStr = null;
					double CPU_UTIL_TEMP = (SESSIONS * CPU_UTIL)/SERVERS;
					if(maxValue<CPU_UTIL_TEMP)
					{
						maxValue = CPU_UTIL_TEMP;
						maxValStr = "SESSION_CONSUMED_CPU_UTIL";
					}
					double DISK_USAGE_TEMP = (SESSIONS * DISK_USAGE)/SERVERS;
					if(maxValue<DISK_USAGE_TEMP)
					{
						maxValue = DISK_USAGE_TEMP;
						maxValStr = "SESSION_CONSUMED_DISK_USAGE";
					}
					double NETWORK_USAGE_TEMP = (SESSIONS * NETWORK_USAGE)/SERVERS;
					if(maxValue<NETWORK_USAGE_TEMP)
					{
						maxValue = NETWORK_USAGE_TEMP;
						maxValStr = "SESSION_CONSUMED_NETWORK_USAGE";
					}
					double MEM_UTIL_TEMP = (SESSIONS * MEM_UTIL)/SERVERS;
					if(maxValue<MEM_UTIL_TEMP)
					{
						maxValue = MEM_UTIL_TEMP;
						maxValStr = "SESSION_CONSUMED_MEM_UTIL";
					}
					System.out.println("DISK_USAGE_TEMP______ "+DISK_USAGE_TEMP);
					System.out.println("maxValue______ "+maxValue);
					System.out.println("chartMaxValueVal______ "+chartMaxValueVal);
					System.out.println("maxValStrl______ "+maxValStr);
					if(maxValue>chartMaxValueVal)
					{
						// now Re-calculation is based on maxValStr
						ADDITIONAL_SERVER = maxValue/chartMaxValueVal;
						ADDITIONAL_SERVER = Math.ceil((SERVERS*ADDITIONAL_SERVER)-SERVERS); // additional server percentage
						System.out.println("SESSIONS______ "+SESSIONS);
						System.out.println("CPU_UTIL______ "+CPU_UTIL);
						System.out.println("ADDITIONAL_SERVER______ "+ADDITIONAL_SERVER);

						CPU_UTIL_TEMP = (SESSIONS * CPU_UTIL)/(SERVERS+ADDITIONAL_SERVER);
						DISK_USAGE_TEMP = (SESSIONS * DISK_USAGE)/(SERVERS+ADDITIONAL_SERVER);
						NETWORK_USAGE_TEMP = (SESSIONS * NETWORK_USAGE)/(SERVERS+ADDITIONAL_SERVER);
						MEM_UTIL_TEMP = (SESSIONS * MEM_UTIL)/(SERVERS+ADDITIONAL_SERVER);
					}
					resultObj.put("UNIQUE_USER",erUtils.roundOffDigit(USER,0));
					resultObj.put("SESSIONS",erUtils.roundOffDigit(SESSIONS,0));
					resultObj.put("TOTAL_SERVERS",erUtils.roundOffDigit(SERVERS+ADDITIONAL_SERVER,0));
					resultObj.put("ADDITIONAL_SERVER",erUtils.roundOffDigit(ADDITIONAL_SERVER,0));
					
					resultObj.put("MEM_UTIL",erUtils.roundOffDigit(MEM_UTIL_TEMP,2));
					resultObj.put("DISK_USAGE",erUtils.roundOffDigit(DISK_USAGE_TEMP,2));
					resultObj.put("NETWORK_USAGE",erUtils.roundOffDigit(NETWORK_USAGE_TEMP,2));
					resultObj.put("CPU_UTIL",erUtils.roundOffDigit(CPU_UTIL_TEMP,2));

					String darkStr = "";
					if(reporter_Skin!=null && reporter_Skin.equalsIgnoreCase("dark"))
					{
						darkStr = "_dark";
					}

					String cupColor = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","cupColor"+darkStr);
					String memoryColor = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","memoryColor"+darkStr);
					String diskColor = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","diskColor"+darkStr);
					String networkColor = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","networkColor"+darkStr);

					resultObj.put("CPU_UTIL_CHART",this.getGaugeChartData(erUtils.roundOffDigit(CPU_UTIL_TEMP,2),intlmap.getTextDescription("reporter.common.CPU Usage"),cupColor,reporter_Skin));
					resultObj.put("MEM_UTIL_CHART",this.getGaugeChartData(erUtils.roundOffDigit(MEM_UTIL_TEMP,2),intlmap.getTextDescription("reporter.common.Memory Usage"),memoryColor,reporter_Skin));
					resultObj.put("DISK_USAGE_CHART",this.getGaugeChartData(erUtils.roundOffDigit(DISK_USAGE_TEMP,2),intlmap.getTextDescription("reporter.common.Disk Usage"),diskColor,reporter_Skin));
					resultObj.put("NETWORK_USAGE_CHART",this.getGaugeChartData(erUtils.roundOffDigit(NETWORK_USAGE_TEMP,2),intlmap.getTextDescription("reporter.common.Network Usage"),networkColor,reporter_Skin));
					
					resultObj.put("factorValue",erUtils.roundOffDigit(incresaseFactorVal,0));

					String SliderRangeStr = reportInfo.getValue("CITRIX_CAPACITY_PREDICTION","SliderRange");
					int SliderRange = 5;
					try
					{
						SliderRange = Integer.parseInt(SliderRangeStr);
					}
					catch(Exception ex) 
					{}
					resultObj.put("SliderRange",SliderRange);
					rootJson.put("RESULT_DATA",resultObj);
				}
				else
				{
					rootJson.put("NO_DATA","yes");
				}
			}
			else
			{
				rootJson.put("NO_DATA","yes");
				// No Measure data
			}
		}// er_submit block
		String strEncodeer_timeline = er_timeline;
		if(er_timeline != null)
			strEncodeer_timeline = EgURLEncoder.encode(er_timeline,"UTF-8");
		s_st_time  = request.getParameter("startdate");
		s_en_time  = request.getParameter("enddate");
		if(s_st_time != null && s_en_time != null && s_inidate != null)
		{
			s_st_time = EgURLEncoder.encode(s_st_time,"UTF-8");
			s_en_time = EgURLEncoder.encode(s_en_time,"UTF-8");
			s_inidate = EgURLEncoder.encode(s_inidate,"UTF-8");
		}
		String dataProcess = mngrIProc+"/final/reporter/ErCitrixCapacityPredictionReportPrint.jsp;jsessionid="+ session.getId()+"?er_comptype="+comp_type+"&er_type="+er_type+"&startdate="+s_st_time+"&enddate="+s_en_time+"&timefrom="+timefrom2+"&minfrom="+minfrom2+"&timeto="+timeto2+"&minto="+minto2+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&er_timeline="+strEncodeer_timeline+"&startmin="+strmin+"&endmin="+enmin+"&inidate="+s_inidate+"&pageWidthProces=400"+"&er_option="+er_option+"&er_site="+er_site+"&increaseBy="+request.getParameter("increaseBy");
		String selcComp="";
		if(selectedComp != null) 
		{
			for(int l=0;l<selectedComp.length;l++)
				selcComp +="&er_component=" + EgURLEncoder.encode(selectedComp[l],"UTF-8");
		}
		session.setAttribute("MAIL_URL",dataProcess);
		session.setAttribute("PDF_URL", mngrIProc+"/final/reporter/ErCitrixCapacityPredictionReportPrint.jsp");
		rootJson.put("PDF_URL", "../reporter/ErHtmlToSavePdf.jsp?er_type="+er_type+"&startdate="+request.getParameter("startdate")+"&enddate="+request.getParameter("enddate")+"&timefrom="+timefrom2+"&minfrom="+minfrom2+"&timeto="+timeto2+"&minto="+minto2+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&er_timeline="+er_timeline+"&startmin="+strmin+"&endmin="+enmin+"&inidate="+request.getParameter("inidate")+"&pageWidthProces=700&er_comptype="+comp_type+"&er_option="+er_option+"&er_site="+er_site+"&er_excwe="+excludeweekend+selcComp+"&increaseBy="+request.getParameter("increaseBy"));
		queryString=(String)ErUtils.prepareQueryString(request.getParameterMap());
		String qString="";
		String qStringBackUrl = "";
		if(queryString!=null)
		{
			StringTokenizer strtok = new StringTokenizer(queryString,"&");
			while(strtok.hasMoreTokens())
			{
				String parameter = strtok.nextToken();
				int ind = parameter.indexOf("=");
				if (ind < 0)
					continue;
				String reqparam =parameter.substring(0,ind);
				String value = parameter.substring(ind+1);
				if(reqparam!=null) 
				{
					if ( reqparam.equals("call") )
					{
						continue;
					}
					if(reqparam.equals("er_component"))
					{
						value=com.eg.EgURLEncoder.encode(value, "UTF-8");
						//continue;
					} else if(reqparam.equals("startdate"))
					{
						value=com.eg.EgURLEncoder.encode(value, "UTF-8");
					} else if(reqparam.equals("enddate"))
					{
						value=com.eg.EgURLEncoder.encode(value, "UTF-8");
					} else if(reqparam.equals("inidate"))
					{
						value=com.eg.EgURLEncoder.encode(value, "UTF-8");
					} 
					qString += reqparam+"="+value+"&";
				}
			}
			if(request.getParameter("isSubmit")!=null)
			{
				session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixCapacityPredictionReport.jsp?"+ qString);
			}
			else 
			{
				session.setAttribute("reportLastAccessedURL","/final/reporter/ErCitrixCapacityPredictionReport.jsp?" + qString);
			}
			rootJson.put("PRINT_URL", "/final/reporter/ErCitrixCapacityPredictionReportPrint.jsp?"+qString+"&pdfPrint=yes");
		}
	}
	catch(Throwable t)
	{
		t.printStackTrace();
	}
	//For Setting the PDf File Name
	HashMap paramVal =new HashMap();
	paramVal.put("fileName","CitrixCapacityPredictionReport");
	session.setAttribute("parameters", paramVal);
	//Back Button - Start
	ArrayList listbackvar = new  ArrayList();
	if(request.getParameter("isSubmit")!=null)
	{
		listbackvar.add("ErCitrixCapacityPredictionReport.jsp");
		listbackvar.add("status="+status+"&bggroundStr="+bggroundStr+"&"+queryString);
		session.setAttribute("favSchBackDisplay","Yes");
	}
	else 
	{
		listbackvar.add("ErCitrixCapacityPredictionReport.jsp");
		listbackvar.add(queryString);
		session.setAttribute("favSchBackDisplay","No");
	}
	String backadded = erhelputils.getBackID();
	backreqMap = erhelputils.setBackQueryMap(backreqMap,backadded,listbackvar);
	session.setAttribute("backQuery",backreqMap);
	//Back Button - End

	
	rootJson.put("selectedValues", selectedObj);
	rootJson.put("selectionDetails", selectionDetails);
	rootJson.put("screenLabels", screenLabels);
	rootJson.put("hiddens", hiddens);


	if ( !backgroundResultObj.isEmpty() )
	{
		rootJson.put("backgroundResults", backgroundResultObj);
	}
	if ( !resultsObj.isEmpty() )
	{
		rootJson.put("RESULTS", resultsObj);
	}
	out.println(rootJson.toString());
%>
<%!
	public JSONObject getGaugeChartData(String gaugeValue, String title, String color,String skin)
	{
		if(color==null || color.length()==0)
		{
			color = "#7CB5EC";
		}
		JSONObject returnObj = new JSONObject();
		try
		{
			//prakash for round border
			boolean roundBorder = false;
			double gaugeValueDouble = Double.parseDouble(gaugeValue);
			int gaugeValueInt = (int) gaugeValueDouble;
			if(gaugeValueInt > 0)
			{
				roundBorder = true;
			}
			//
			String textColor = "#2a292a";
			String arcColor = "#e0e0e0";
			if(skin!=null && skin.equalsIgnoreCase("dark"))
			{
				textColor = "#FFFFFF";
				arcColor = "#595959";
			}
			JSONArray dataSetAry = new JSONArray();
			JSONArray jsonDataAry = new JSONArray();
			JSONObject dataSetObj = new JSONObject();
			JSONObject dataObj = new JSONObject();
			dataObj.put("color",arcColor); 
			dataObj.put("y",100); // this must be max value
			dataObj.put("radius","112%");
			dataObj.put("innerRadius","88%");
			jsonDataAry.add(dataObj);
			dataSetObj.put("data",jsonDataAry);
			dataSetObj.put("name","");
			dataSetObj.put("dataLabels",false);
			dataSetAry.add(dataSetObj);

			jsonDataAry = new JSONArray();
			dataSetObj = new JSONObject();
			dataObj = new JSONObject();
			dataObj.put("color",color);
			dataObj.put("y",Double.parseDouble(gaugeValue));
			dataObj.put("radius","112%");
			dataObj.put("innerRadius","88%");
			jsonDataAry.add(dataObj);
			JSONObject datalabelobj = new JSONObject();
			datalabelobj.put("format","<div><span style='font-family:Roboto;font-weight:400;font-size:24px;color:"+textColor+";'>"+gaugeValue+"</span><span style='font-family:Roboto;font-weight:400;font-size:14px;color:"+textColor+";'> %</span></div>");
			dataSetObj.put("data",jsonDataAry);
			dataSetObj.put("dataLabels",datalabelobj);
			dataSetObj.put("name","");
			dataSetAry.add(dataSetObj);

			returnObj.put("chartType","solidgauge");
			returnObj.put("maxValueForDial",100); // this must be max value
			returnObj.put("title",title);
			returnObj.put("unit","%");
			returnObj.put("isRoundBorder",roundBorder);
			returnObj.put("startAngle",-160);
			returnObj.put("endAngle",160);
			returnObj.put("DataSet",dataSetAry);
		}
		catch(Exception ee){
			ee.printStackTrace();
		}
		return returnObj;
	}
%>