<!DOCTYPE html>
<%
	/**
	 ********************************************************************************************
	 * File Name	: ErPrintReport.jsp
	 * vesion		: eG6.0.x
	 * purpose		: collect data for print.
	 ********************************************************************************************
	*/
%>

<%@ include file="ErTracker.jsp"%>
<%@ page import="egurkha.reporter.*"%>
<%@ page import="com.eg.EgDateInfo"%>
<%@ page import="com.eg.EgThresholdInfo"%>
<%@ page import="com.eg.EgReportInfo"%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>
<%@ page import="com.egurkha.util.DateUtil"%>
<%@ page import="com.eg.* "%>
<%@ page import="com.eg.EgURLEncoder"%>
<%@ page import="com.egurkha.User"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgConfigInfo"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld"%>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="net.sf.json.*"%>

<%

	
	ErReqData erd =  null;
	String v_qry_String="";
	EgMappingInfo intlmap = null;	
	EgDateInfo egDt = new EgDateInfo();
	EgReportInfo reportInfo = new EgReportInfo("manager");
	ErUtils erUtils=new ErUtils();
	String qryString= ErUtils.prepareQueryString(request.getParameterMap());
	String titleToDisplay=request.getParameter("er_RmDispName");
	String pdfPrint = request.getParameter("pdfPrint");
	String isPdf = request.getParameter("isPdf");
	String req_er_graphtype = (String)request.getParameter("er_gtype");
	String reportPeriod = request.getParameter("er_period");
	String er_Selection1=request.getParameter("er_Selection1");
	String er_Selection2=request.getParameter("er_Selection2");
	ErReportHelper er_helper = new ErReportHelper();

	String[] er_comb=request.getParameterValues("er_comb");
	
	JSONArray firstOutputJsonArray = new JSONArray();
	JSONArray secondOutputJsonArray = new JSONArray();
	
	if(req_er_graphtype.equalsIgnoreCase("Measure"))
		reportPeriod="";
	
	erd = new ErReqData(request);	
	if(thisuser !=null)
	{
			intlmap = new EgMappingInfo(thisuser.getLanguage());
	}
	
	String strCombinedGraphValue = reportInfo.getValue("MISC","CombinedGraph");
	boolean isCombinedGraph = true;
	if(strCombinedGraphValue!=null && (strCombinedGraphValue.equalsIgnoreCase("False") || strCombinedGraphValue.equalsIgnoreCase("No")))
		isCombinedGraph = false;

%>

<!Doctype html>
<!-- <pd4ml:page.header areaHeight="40">
<img src="../reporter/images/logo.gif"  width="48" height="40"/>
</pd4ml:page.header> -->
<head>
<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
%>
		<title><egui:intnl text="reporter.common.Reporter" />&nbsp;<egui:intnl text="reporter.common.Print" /> &nbsp;</title>
<%
	}
	else
	{
%>
		<title>eG Reporter</title>
<%
	}
%>
<meta name="Author" content="">
<meta  charset="UTF-8">
 
<link rel="stylesheet" type="text/css" href="/final/styles/eGLightThemeIcons.css" />
<link rel="stylesheet" type="text/css" href="/final/reporter/styles/printpagestyle.css" />
<style>
</style>


<style type="text/css" media="print">
#printbt{ display:none}
</style>

<script language="JavaScript1.2" src="../reporter/scripts/er_imagesLite.js"></script>
<script src="/final/scripts/DD_roundies_0.0.2a-min.js"  type='text/javascript'></script>

<script>
	DD_roundies.addRule('.box', 5, true);
</script>

</head>
<body  style="padding:10px;background-color:#ffffff">

<%

// Title
String st_comp ="";
String st_comptype ="";
String st_component = erd.s_component;
if(st_component!=null && st_component.indexOf(":")>-1)
{
	st_comp = st_component.substring(0,st_component.lastIndexOf(":"));
	if(st_comp.indexOf(":NULL") >-1) {
		st_comp = st_comp.substring(0,st_comp.indexOf(":"));
	}
	st_comptype = st_component.substring(st_component.lastIndexOf(":")+1);
	st_component = st_comp+":"+intlmap.getComponentTypeDescription(st_comptype);
}
	if(isPdf !=null && isPdf.equalsIgnoreCase("yes"))
	{
%>
		<div class="printHeaderBoxLogo" style="padding:-10px"><img src="<%=imageName%>" border="0" /></div>
<%
	}
	else
	{
%>
		<div class="printHeaderBoxLogo" style="padding:10px"><img src="<%=imageName%>" border="0" /></div>
<%
	}
	if (!StringUtils.isNull(titleToDisplay))
	{
%>
			<div style="float:left" class="printHeaderBox"> <header><div class="printHeaderBoxTitle"><%= titleToDisplay %></div></header>
<%
	} 
	else 
	{
%>
			<div style="float:left" class="printHeaderBox"> <header><div class="printHeaderBoxTitle"><egui:intnl text="reporter.operation.OPERATION REPORTS" /> - <egui:intnl text="<%="reporter.operation."+erd.s_rtype.toUpperCase()%>" /> - <egui:intnl type="<%=st_component%>" /></div></header>
<%
	}
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes") && isPdf == null)
	{
%>
		<div class="printHeaderBoxPrintIcon"><img class="iconPrinter mouse" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border="0"  onClick="javascript:print()" alt='<egui:intnl text="reporter.common.PRINT"/>' title='<egui:intnl text="reporter.common.PRINT"/>'/></div>
<%
	}
%>
			</div>
	<!-- 	</td>
	</tr>
</table>   -->

<%
	String sel1=getDisplayTIme(er_Selection1,thisuser,intlmap,req_er_graphtype,reportPeriod);
	String sel2=getDisplayTIme(er_Selection2,thisuser,intlmap,req_er_graphtype,reportPeriod);
	String new_Format=sel2.substring(sel2.indexOf("*")+1);
	String sel1_Timeline=sel1.substring(0,sel1.indexOf("*"));
	String sel2_Timeline=sel2.substring(0,sel2.indexOf("*"));

	String strManagerURL = request.getScheme()+"://"+request.getServerName()+":"+ request.getServerPort();
	v_qry_String= strManagerURL + "/final/servlet/com.eg.ErMicroTimeC?";
	HashMap hmQry = ErUtils.parseQueryString(qryString);
	//String inidateVal=(String) hmQry.get("inidate");
	String limitforbgVal=(String) hmQry.get("limitforbg");
	String er_steVal=(String) hmQry.get("er_stdate");
	String er_endVal=(String) hmQry.get("er_enddate");
	String pdfTimeVal=(String) hmQry.get("pdfTime");
	hmQry.remove("er_Selection2");
	hmQry.remove("er_Selection1");
	hmQry.remove("er_comb");
	
	hmQry.remove("starthr");
	hmQry.remove("uid");
	hmQry.remove("endhr");
	hmQry.remove("startdate");
	hmQry.remove("enddate");
	hmQry.remove("er_timeline");
	hmQry.remove("startmin");
	hmQry.remove("endmin");
	hmQry.remove("s_start_time_days");
	hmQry.remove("s_start_time_months");
	hmQry.remove("s_end_date_forMonth");
	hmQry.remove("s_enddate_fordays");
	hmQry.remove("currentformat");
	hmQry.remove("er_RmDispName");
	hmQry.remove("inidate");
	
	ArrayList encodbleKey=new ArrayList();
	HashMap mpVal=new HashMap();
	encodbleKey.add("limitforbg");
	encodbleKey.add("er_stdate");
	encodbleKey.add("er_enddate");
	encodbleKey.add("pdfTime");
	encodbleKey.add("userID");
	encodbleKey.add("er_userid");
	encodbleKey.add("us_id");
	//encodbleKey.add("inidate");
	//encodbleKey.add("er_RmDispName");
	
	//System.out.println("hmQry::  "+hmQry);
	for(int m=0;m<encodbleKey.size();m++)
	{
		String keys=(String) encodbleKey.get(m);
		String realVal=(String) hmQry.get(keys);
		if(realVal!=null)
		{
			mpVal.put(keys,realVal);
			hmQry.remove(keys);
		}
		
	}
	
	 
	hmQry.remove("er_usertimeline");
	hmQry.remove("er_RmDispName");
	hmQry.remove("selectionName1");
	//hmQry.put("selectionName1",com.eg.EgURLEncoder.encode(selectionName1Key, "UTF-8"));
	hmQry.remove("selectionName2");
	hmQry.remove("ReportName");
	hmQry.remove("bg_reportname");

	//hmQry.put("selectionName2",com.eg.EgURLEncoder.encode(selectionName2Key, "UTF-8"));
	//hmQry.put("er_RmDispName",com.eg.EgURLEncoder.encode(titleToDisplay, "UTF-8"));	

	//prakash encoding for measures coming in background-pdf
	if(hmQry!=null && hmQry.size()>0)
	{
		String values = (String)hmQry.get("strbg_id");
		if(values!=null && values.indexOf("|") > -1)
		{
			hmQry.remove("strbg_id");
			values = com.eg.EgURLEncoder.encode(values, "UTF-8");
			hmQry.put("strbg_id", values);
		}
		String values_temp = (String)hmQry.get("inidateForAny");
		if(values_temp!=null && values_temp.indexOf(" ") > -1)
		{
			hmQry.remove("inidateForAny");
			values_temp = com.eg.EgURLEncoder.encode(values_temp, "UTF-8");
			hmQry.put("inidateForAny", values_temp);
		}
	}
	v_qry_String +=(String)ErUtils.prepareQueryString(hmQry);
	try{
		java.util.Date start = egDt.egetRealDate();
		String startMin = Integer.toString(start.getMinutes());
		String endMin = Integer.toString(start.getMinutes());
		v_qry_String+="&startmin="+startMin+"&endmin="+endMin;
		
		for(int m=0;m<encodbleKey.size();m++)
		{
			String keys=(String) encodbleKey.get(m);
			String realVal=(String) mpVal.get(keys);
			if(realVal!=null)
			{
				v_qry_String+="&"+keys+"="+com.eg.EgURLEncoder.encode(realVal,"UTF-8");
			}
		}
	
	}catch(Exception e)
	{
		e.printStackTrace();
	}
	String pdfThresh="margin-top:2px;";
	if(pdfPrint != null && pdfPrint.equalsIgnoreCase("yes"))
		pdfThresh="";
	if(er_comb!=null)
	{
		String st_format= strUserDateFormat;
		HashMap ymaxVal=getYmaxValue(er_comb,er_Selection1,er_Selection2,intlmap,st_format,er_helper);
		firstOutputJsonArray.addAll(prepareJson(er_comb,er_Selection1,v_qry_String,intlmap,ymaxVal));
		secondOutputJsonArray.addAll(prepareJson(er_comb,er_Selection2,v_qry_String,intlmap,ymaxVal));
	}
	if(firstOutputJsonArray!=null && secondOutputJsonArray!=null)
	{
		JSONObject obj1=(JSONObject)firstOutputJsonArray.get(0);
		JSONObject obj2=(JSONObject)secondOutputJsonArray.get(0);
		String title1=(String)obj1.get("sub_title");
		String title2=(String)obj2.get("sub_title");
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-bottom:0px solid #ccc;">
	<col width="50%"><col width="50%">

	<tr>
		<td>
			<div class="printOuterBoxNoBorder" style="padding-bottom:0px">
				<div>
					<span class="font_bold12"><egui:intnl text="reporter.common.Selection 1" /></span>
				</div>
				<div class="printSelectionFields">
					<egui:intnl text="reporter.common.Component" /> - 
					<span class="bold"><%=title1%></span>
				</div>
				<div class="printSelectionFields">
					<egui:intnl text="reporter.common.Timeline" /> - 
					<span class="bold"><%=sel1_Timeline%></span>
				</div>
			</div>
			<div class="clear" style="height:5px;">&nbsp;</div>
			<div class="printOuterBoxNoBorder" style="padding-top:0px">
				<div>
					<span class="font_bold12"><egui:intnl text="reporter.common.Selection 2" /></span>
				</div>
				<div class="printSelectionFields">
					<egui:intnl text="reporter.common.Component" /> - 
					<span class="bold"><%=title2%></span>
				</div>
				<div class="printSelectionFields">
					<egui:intnl text="reporter.common.Timeline" /> - 
					<span class="bold"><%=sel2_Timeline%></span>
				</div>
			</div>
		</td>
	</tr>
</table>
<!-- <br/> -->

<table align="center" cellspacing="0" cellpadding="4"width="100%" border="0" valign="top">
	<tr>
		<td align="right"><%=new_Format%></td>
	</tr>
	<tr>
		<td align="right" style="padding: 5px 0px 0px 0px;">
			<div style="display:flex;float:right;">
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#7c7e1d" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Max Critical</div>
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#a2a51f" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Max Major</div>
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#ced059" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Max Minor</div>
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#f28a16" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Min Critical</div>
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#f5ba79" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Min Major</div>
				<div style="float:left;<%=pdfThresh%>"><svg height="10" width="10"><circle cx="4" cy="6" r="3" fill="#f8d3bb" stoke-width="0" /></svg></div>
				<div style="float:left;margin-right:10px;margin-left:3px;">Min Minor</div>
			</div>
		</td>
	</tr>
</table>


<%
		String selectionName1=request.getParameter("selectionName1");
		String selectionName2=request.getParameter("selectionName2");
		
		selectionName1=erUtils.findAndReplaceString(selectionName1,"|amp|","&");
		selectionName2=erUtils.findAndReplaceString(selectionName2,"|amp|","&");
		
		
		//System.out.println("selectionName1	"+selectionName1);
		for(int i=0;i<firstOutputJsonArray.size();i++)
		{
			obj1=(JSONObject)firstOutputJsonArray.get(i);
			obj2=(JSONObject)secondOutputJsonArray.get(i);
			//String title=(String)obj1.get("title");
%>
	<!--<tr>
		<td class="printTableHeader" colspan="2"><%//=title%></td>
	</tr>-->
	
<%
			for(int j=0;j<2;j+=2)
			{
%>
			<div class="print OuterBox" style="border-top: 1px solid #dedede;padding-top: 8px;">
<%
				String url=null;
				//String s_title=null;
				//String s_title1=(String)obj1.get("sub_title");
				String s_title1=(String)obj1.get("title");
				String url1=(String)obj1.get("url");

				String s_title2=(String)obj2.get("title");
				String url2=(String)obj2.get("url"); 

				
				if(s_title1.length() > 70 && isCombinedGraph)
					s_title1 = s_title1.substring(0,70)+"...";

				if(s_title2.length() > 70 && isCombinedGraph)
					s_title2 = s_title2.substring(0,70)+"...";
					
				String strImgWidth="400";
				String strGraphWidth="450";
				String strGraphHeight="200";
				if(!isCombinedGraph)
				{
					strGraphWidth="750";
					strGraphHeight="320";
					strImgWidth="750";
				}
%>
			
			<!--<div style="width:100%;margin:0px;">-->
			<div class="printOuterBoxHeader" style="padding-top:10px;"><%=s_title1%></div>
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
					<col width="50%"><col width="50%">
					<tr class="newimg">
						<!-- <td style="padding:5px 8px 12px 10px;background-color:#d9d9d9" > -->
						<td width="50%" style="padding:10px 10px 10px 0px;border-right:1px solid #dedede;" align="left" height="auto" valign="top">
							<div class="print OuterBox">
								<div style="display:block" class="printOuterBoxHeader" ><%=selectionName1%></div>
									<!-- <div style="height:225px;overflow:auto;"> -->
								<div>
									<table width="100%" height="100%"><tr><td valign="middle" align="center">
										<img src="<%=url1%>&print=yes&er_width=<%=strImgWidth%>&er_height=<%=strGraphHeight%>&option=graph"  border="0" hspace="0" vspace="0" alt=" <%=s_title1%>" title=" <%=s_title1%>" align="center" style="vertical-align: middle"></img>
									</td></tr></table>
								</div>
							</div>
						</td>
						<!-- <td style="padding:5px 8px 12px 10px;background-color:#949494"> -->
						<td width="50%" style="padding:10px 0px 10px 10px;" align="left" valign="top">
							<div class="print OuterBox">
								<div style="display:block" class="printOuterBoxHeader" ><%=selectionName2%></div>
								<!-- <div style="height:225px;overflow:auto;"> -->
								<div>
									<table width="100%" height="100%"><tr><td valign="middle" align="center">
										<img src="<%=url2%>&print=yes&er_width=<%=strImgWidth%>&er_height=<%=strGraphHeight%>&option=graph" border="0" hspace="0" vspace="0" alt=" <%=s_title2%>" title=" <%=s_title2%>" align="center" style="vertical-align: middle"></img>
									</td></tr></table>
								</div>
							</div>
						</td>
					</tr>
				</table>
			</div>
			</div>
<%
			}
		}
	}
%>
</div>
<%
	if(isPdf == null)
	{
%>
		<div class="printFooterText">Powered by eG Enterprise <br>2017 eG Innovations inc. All Rights Reserved.</div>
<%
	}
%>
</body>

</html>
<%@ include file="ErRemoveUser.jsp"%>
<%
	 if(titleToDisplay!=null && !titleToDisplay.isEmpty())
	{
		//For Setting the PDf File Name
		String reportFileName=customReplaceAll(titleToDisplay," ","_");
		HashMap paramVal =new HashMap();
		paramVal.put("fileName",reportFileName);
		session.setAttribute("parameters", paramVal);
	}
%>
<%!
	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;
	}
	public JSONArray prepareJson(String[] er_comb,String er_Selection,String v_qry_String,EgMappingInfo intlmap,HashMap ymaxVal)
	{
	
		EgDbInfo dbInfo = new EgDbInfo("manager");
		JSONArray outputJsonArray = new JSONArray();
		JSONObject outputJsonObj;
		String dbName;
		String[] selectionVal;
		String compTypee=null;
		String comp=null;
		
		ArrayList encodeKeyNames=new ArrayList();
		//encodeKeyNames.add("inidate");
		encodeKeyNames.add("er_timeline");
		encodeKeyNames.add("enddate");
		encodeKeyNames.add("startdate");
		encodeKeyNames.add("limitforbg");
		encodeKeyNames.add("er_stdate");
		encodeKeyNames.add("er_enddate");
		encodeKeyNames.add("pdfTime");
		encodeKeyNames.add("displayStartdate");
		encodeKeyNames.add("displayEnddate");		
		//encodeKeyNames.add("er_RmDispName");
		try
		{		
			if(er_Selection.indexOf("*")>-1)
			{
				selectionVal=er_Selection.split("\\*");
				for(int i=0;i<selectionVal.length;i++)
				{
					String str=selectionVal[i];
					String key=str.substring(0,str.indexOf("="));
					String val=str.substring(str.indexOf("=")+1);
					
					if(key.equalsIgnoreCase("er_component"))
					{ 
						//if(val.indexOf(":")>-1)
						//	val=val.substring(0,val.indexOf(":"));
						comp=val;
					}else if(key.equalsIgnoreCase("er_comptype"))
					{
						compTypee=val;
					}else{
						if(key.equalsIgnoreCase("er_enddate"))
							key="enddate";
						if(key.equalsIgnoreCase("er_sthr"))
							key="starthr";
						if(key.equalsIgnoreCase("er_endhr"))
							key="endhr";
						if(key.equalsIgnoreCase("er_stdate"))
							key="startdate";
						if(key!=null && encodeKeyNames.contains(key))
						{
							val=com.eg.EgURLEncoder.encode(val,"UTF-8");
						}
						v_qry_String+="&"+key+"="+val;
					}
				}
			}
			String str,test,meas;
			String[] measArr;
			for(int i=0;i<er_comb.length;i++)
			{
				str=er_comb[i];
				test=str.substring(0,str.indexOf(":"));
				meas=str.substring(str.indexOf(":")+1);
				if(meas.indexOf(",")>-1 && test.length()!=0)
				{
					measArr=meas.split(",");
					for(int j=0;j<measArr.length;j++)
					{
						String measVal=(String)measArr[j];
						String qryString=v_qry_String;
						outputJsonObj = new JSONObject();
						String s_measure=intlmap.getMeasureDescription(test,measArr[j]);
						dbName = dbInfo.getColumnForMeasure(test,measArr[j]);
						
						String yMaxValue=(String) ymaxVal.get(test+"_"+measVal);
						qryString += "&er_test=" + test+ "&er_disp_meas=" + measArr[j] + "&er_measure=" + dbName+ "&er_component=" + comp+"&er_comptype="+compTypee;
						if(yMaxValue!=null)
						{
							qryString+="&yMaxVal="+yMaxValue;
						}
						outputJsonObj.put("url",qryString);
						String drillDown=qryString.substring(qryString.indexOf("?")+1);
						drillDown="ErReporterMenu.jsp?"+drillDown+"&call=json&er_rtype=Network";
						outputJsonObj.put("drillDown",drillDown);
						String subtitle=comp;
						if(comp.indexOf(":")>-1){
							subtitle=comp.substring(0,comp.lastIndexOf(":"));
						}
						outputJsonObj.put("sub_title",subtitle);
						outputJsonObj.put("title",intlmap.getTestDescription(test)+" / "+s_measure);
						outputJsonArray.add(outputJsonObj);
					}
				}else 
				{
					String qryString=v_qry_String;
					outputJsonObj = new JSONObject();
					String s_measure=intlmap.getMeasureDescription(test,meas);
					dbName = dbInfo.getColumnForMeasure(test,meas);
					String yMaxValue=(String) ymaxVal.get(test+"_"+meas);
					qryString += "&er_test=" + test+ "&er_disp_meas=" + meas + "&er_measure=" + dbName+ "&er_component=" + comp+"&er_comptype="+compTypee+"&er_gtype=Measure";
					if(yMaxValue!=null)
					{
						qryString+="&yMaxVal="+yMaxValue;
					}
					outputJsonObj.put("url",qryString);
					String drillDown=qryString.substring(qryString.indexOf("?")+1);
					drillDown="ErReporterMenu.jsp?"+drillDown+"&call=json&er_rtype=Network";
					outputJsonObj.put("drillDown",drillDown);
					outputJsonObj.put("title",intlmap.getTestDescription(test)+" / "+s_measure);
					if(comp.indexOf(":")>-1){
							comp=comp.substring(0,comp.lastIndexOf(":"));
					}
					outputJsonObj.put("sub_title",comp);
					outputJsonArray.add(outputJsonObj);
				}
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
		return outputJsonArray;
	}
	public String getMaxInfoVal(String[] measArr,String[] testArr,HashMap hm,String st_format,ErReportHelper er_helper)
	{
		String[] components=null;
		String compType=(String)hm.get("er_comptype");
		String comp=(String)hm.get("er_component");
		String strStartTime=(String)hm.get("startdate");
		String strEndTime=(String)hm.get("enddate");
		String starthr=(String)hm.get("starthr");
		String endhr=(String)hm.get("endhr");
		components=comp.split(",");
		strStartTime=DateUtil.changeDateFormat(strStartTime,st_format,"dd/MM/yyyy");
		strStartTime+=" "+starthr+ ":00:00";

		strEndTime=DateUtil.changeDateFormat(strEndTime,st_format,"dd/MM/yyyy");
		strEndTime+=" "+endhr+":00:00";

		String yMax1=er_helper.getMaxValue(testArr,measArr,components,strStartTime,strEndTime,st_format);
		return yMax1;
	}
	public HashMap getSelectionValues(String er_Selection)
	{
		HashMap hm=new HashMap();
		String[] selectionVal;
		if(er_Selection.indexOf("*")>-1)
		{
			selectionVal=er_Selection.split("\\*"); 
			for(int i=0;i<selectionVal.length;i++)
			{
				String str=selectionVal[i];
				String key=str.substring(0,str.indexOf("="));
				String val=str.substring(str.indexOf("=")+1); 
				if(key.equalsIgnoreCase("er_component"))
				{
					if(val.indexOf(":")>-1)
						val=val.substring(0,val.indexOf(":"));
				}else{
					if(key.equalsIgnoreCase("er_enddate"))
						key="enddate";
					if(key.equalsIgnoreCase("er_sthr"))
						key="starthr";
					if(key.equalsIgnoreCase("er_endhr"))
						key="endhr";
					if(key.equalsIgnoreCase("er_stdate"))
						key="startdate";
				}
				hm.put(key,val);
			}
		}
		return hm;
	}
	public synchronized HashMap getYmaxValue(String[] er_comb,String er_Selection1,String er_Selection2,EgMappingInfo intlmap,String st_format,ErReportHelper er_helper)
	{
		HashMap hmVal=new HashMap();
		if(er_Selection1.indexOf("*")>-1 && er_Selection2.indexOf("*")>-1)
		{
			HashMap sel_1Mp=getSelectionValues(er_Selection1);
			HashMap sel_2Mp=getSelectionValues(er_Selection2);

			String str,test,meas;
			String[] measArr=null;
			String[] measArr1=null;
			String[] testArr=null;
			for(int i=0;i<er_comb.length;i++)
			{
				str=er_comb[i];
				test=str.substring(0,str.indexOf(":"));
				meas=str.substring(str.indexOf(":")+1);
				measArr=meas.split(",");
				testArr=test.split(",");
				for(int j=0;j<measArr.length;j++)
				{
					String measVal=(String) measArr[j];
					measArr1=measVal.split(",");
					String y1=getMaxInfoVal(measArr1,testArr,sel_1Mp,st_format,er_helper);
					String y2=getMaxInfoVal(measArr1,testArr,sel_2Mp,st_format,er_helper);

					if(y1!=null && y1.length()>0 && y2!=null && y2.length()>0)
					{
						double d1=(double) Double.parseDouble(y1);
						double d2=(double) Double.parseDouble(y2);
						if(d1<d2)
							d1=d2;
						String aString = Double.toString(d1);
						hmVal.put(test+"_"+measVal,aString);
					}
				}
			}
		}
		return hmVal;
	}

public synchronized String getDisplayTIme(String selection,User thisuser,EgMappingInfo intlmap,String req_er_graphtype,String reportPeriod)
{
	String str=null;
	EgTimeZoneConverter converterStart=null;
	EgTimeZoneConverter converterEnd=null;	
	ErUtils erUtils=new ErUtils();
	String d1 = "";
	String d2 = "";
	String s_sDate=null;
	String s_eDate=null;
	String s_sHr =null;
	String s_eHr=null;
	String s_sMin=null;
	String s_eMin=null;
	HashMap map=null;
	
	if(selection.indexOf("*")>-1)
	{
		selection =erUtils.findAndReplaceString(selection,"*","&");
		map=ErUtils.parseQueryString(selection);
		
		s_sDate=(String)map.get("er_stdate");
		s_eDate=(String)map.get("er_enddate");
		s_sHr=(String)map.get("er_sthr");
		s_eHr=(String)map.get("er_endhr");
		s_sMin=(String)map.get("startmin");
		s_eMin=(String)map.get("endmin");
	}
	s_sHr = (s_sHr==null || s_sHr.equals("")) ? "00" : s_sHr;
	s_eHr = (s_eHr==null || s_eHr.equals("")) ? "00" : s_eHr;
	s_sMin = (s_sMin==null || s_sMin.equals("")) ? "00" : s_sMin;
	s_eMin = (s_eMin==null || s_eMin.equals("")) ? "00" : s_eMin;

	d1 = s_sDate + " " + s_sHr + ":" + s_sMin;
	d2 = s_eDate + " " + s_eHr + ":" + s_eMin;

	converterStart = new EgTimeZoneConverter(s_sDate + " " + s_sHr + ":" + s_sMin,thisuser);
	converterEnd = new EgTimeZoneConverter(s_eDate + " " + s_eHr + ":" + s_eMin,thisuser);
	String s_d1 = converterStart.getDateTime();
	String e_d2 = converterEnd.getDateTime();
	//return intlmap.getTextDescription("reporter.common.Start Date")+"  "+s_d1+intlmap.getTextDescription("reporter.common.hrs")+" - "+intlmap.getTextDescription("reporter.common.End Date")+"  "+e_d2+intlmap.getTextDescription("reporter.common.hrs");
	String new_format=erUtils.getXAxisLabel(req_er_graphtype,s_sDate,s_eDate,s_sHr,s_eHr,s_sMin,s_eMin,reportPeriod,thisuser);	
	
	str=s_d1+" "+intlmap.getTextDescription("reporter.common.hrs")+" to "+e_d2+" "+intlmap.getTextDescription("reporter.common.hrs")+"*"+new_format;

	return str;
}
%>