<!DOCTYPE html>

<%@ include file = "ErTracker.jsp" %>
<%@ page import = "java.util.*" %>
<%@ page import = "java.text.*" %>

<%@ page import= "com.eg.EgDbInfo" %>
<%@ page import= "com.eg.EgTablesInfo" %>
<%@ page import = "com.egurkha.util.DateUtil"%>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.EgReportInfo" %>
<%@ page import = "com.eg.EgMappingInfo" %>
<%@ page import= "com.eg.EgServicesInfo" %>
<%@ page import= "com.eg.EgTesterInfo" %>
<%@ page import="com.egurkha.util.StringUtils"%>
<%@ page import="egurkha.reporter.ErUtils"%>

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

<%
	String strManagerURL = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
	EgTablesInfo tablesInfo = new EgTablesInfo ("manager"); 
	
	Map resultMap = (Map) session.getAttribute("CAPACITY_PREDICTION_REPORT_RESULT");
	List keyList = null;
	List sidList = null;
	ErUtils erUtils = new ErUtils();
	boolean noDataFound = false;
	if(resultMap != null)
	{
		keyList = (List) resultMap.get("RESULT_KEYS");
		sidList = (List) resultMap.get("SID_KEYS");
		if(keyList == null || keyList.isEmpty()) {
			//System.out.println("key list is empty");
			noDataFound = true;
		}
		//System.out.println("resultMap: " + resultMap.keySet());
	} else {
		noDataFound = true;
	}

	EgReportInfo reportInfo = new EgReportInfo("manager");
	String thisLanguage="";
	if (thisuser != null)
	{
		String userLang = thisuser.getLanguage();
		if (userLang != null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage = userLang;
		}
	}

	EgMappingInfo intlmap = new EgMappingInfo(thisuser.getLanguage());

	String s_comptype = request.getParameter("er_comptype");
	String isPdf = request.getParameter("isPdf");
	String s_component = request.getParameter("er_component");
	
	String s_test = request.getParameter("er_test");
	String s_measure = request.getParameter("er_measure");
	
	String s_info = request.getParameter("er_info");
	
	String s_look_forward = request.getParameter("er_look_forward");
	String s_dataoption = request.getParameter("er_dataoption");
	
	String s_type = request.getParameter("er_type");
	
	String showDetails = request.getParameter("er_show_details");
	String er_timeline = request.getParameter("er_timeline");
	String excludeweekend = request.getParameter("er_excwe");
	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_time   =  request.getParameter("er_time");
	String hourFrom = request.getParameter("timefrom");
	String minFrom = request.getParameter("minfrom");
	String hourTo = request.getParameter("timeto");
	String minTo = request.getParameter("minto");
	String iniDate = request.getParameter("inidate");
	

	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	String currentDateFormat = strUserDateFormat;
	
	String dispStartDate = DateUtil.changeDateFormat(s_st_time.trim(),iniDate,currentDateFormat);
	String dispEndDate = DateUtil.changeDateFormat(s_en_time.trim(),iniDate,currentDateFormat);
	String timefrom = hourFrom + ":" + minFrom;
	String timeTo = hourTo + ":" + minTo;
	String stTime = "";
	String enTime = "";
	
	String pdfPrint = request.getParameter("pdfPrint");

	if (er_timeline != null)
	{
		stTime = s_st_hr + " " + intlmap.getTextDescription("reporter.common.hrs");
		enTime = s_en_hr + " " +intlmap.getTextDescription("reporter.common.hrs");
	}
	EgTimeZoneConverter converterStart=null;
	EgTimeZoneConverter converterEnd=null;
	String st_dateTime="";
	String en_dateTime="";
	
	converterStart = new EgTimeZoneConverter(dispStartDate+" "+s_st_hr+":"+strmin,thisuser);
	converterEnd = new EgTimeZoneConverter(dispEndDate+" "+s_en_hr+":"+enmin,thisuser);
	
	stTime = (String)converterStart.getDate(false)+" "+converterStart.getHour()
											+" hrs "+converterStart.getMinute()+" mins ";

	enTime = (String)converterEnd.getDate(false)+" "+converterEnd.getHour()
											+" hrs "+converterEnd.getMinute()+" mins ";

	EgDbInfo dbInfo = new EgDbInfo("manager");
	String fontStyleDblSingl = "";
	if((dbInfo.doubleByteEnabled || !thisuser.getLanguage().equals("en_US")) && (pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes")))
	{
		fontStyleDblSingl = "multi_font";
	}
	else
	{
		fontStyleDblSingl = "";
	}

	//String pdfPrint = request.getParameter("pdfPrint");
	//out.println("fontStyleDblSingl ===>"+fontStyleDblSingl);
	String er_RmDispName = request.getParameter("er_RmDispName");

%>

<!Doctype html>
<head>
<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
%>
	<title>
		<egui:intnl text="reporter.common.eG Reporter"/>
	</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 type="text/css" media="print">
#printbt{ display:none}
</style>

</head>

<body marginwidth="20" marginheight="20" bgcolor="#FFFFFF">
<%
	String strLogCls = "printHeaderBoxLogo";
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
		strLogCls = "printHeaderBoxLogo";
	}
	else
		strLogCls = "printPdfHeaderBoxLogo";

	if(isPdf != null && isPdf.equals("yes"))
	{
%>
		<div class="<%=strLogCls%>" style="padding:-10px"><img src="<%=imageName%>" border="0"/></div>
<%
	}
	else
	{
%> 
		<div class="<%=strLogCls%>" style="padding:10px"><img src="<%=imageName%>" border="0"/></div>
<%
	}
%>
		<div class="printHeaderBox">
<%
	if (!StringUtils.isNull(er_RmDispName))
	{
%>
			<div class="printHeaderBoxTitle"><%= er_RmDispName %></div>
<%
	}
	else
	{
%>
			<div class="printHeaderBoxTitle"><header><egui:intnl text="reporter.common.CAPACITY PLANNING PREDICTION REPORT"/></header></div>
<%
	}
	//if(!(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes")))
	if(pdfPrint!=null && pdfPrint.equalsIgnoreCase("yes") && isPdf == null)
	{
%>
		<!--<div class="printHeaderBoxPrintIcon" style="float:left"><img class="iconPrinter mouse" id="pri ntbt" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border="0" onClick="window.print()" alt='<egui:intnl text="reporter.common.PRINT"/>' title='<egui:intnl text="reporter.common.PRINT"/>'/></div>-->
		<div class="printHeaderBoxPrintIcon" style="float:left"><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>
<%
	}
%>
					<!--</td>
				</tr>
			</table>--> 
		</div>

	<div class="printOuterBoxNoBorder">

			<!--<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-bottom:1px solid #ccc;">
				<tr>
					<td align="right" valign="top">-->
						<!--<div style="float:right;padding:4px;">
							<div style="float:left" class="formLabel"><egui:intnl text="reporter.common.StartDate"/></div>
							<div style="float:left;width:10px" align="center" >:</div>
							<div style="float:left;" class="formValue"><%=stTime%></div>
						</div>-->
						<!--<div style="clear:both;float:right;padding:4px;">
							<div style="float:left" class="formLabel"><egui:intnl text="reporter.common.EndDate"/></div>
							<div style="float:left;width:10px" align="center">:</div>
							<div style="float:left;" class="formValue"><%=enTime%></div>
						</div> -->
						<div class="printSelectionFields">Timeline - <span class="bold"><%=stTime%>&nbsp;<egui:intnl text="reporter.common.hrs" /> to <%=enTime%>&nbsp;<egui:intnl text="reporter.common.hrs" /></span></div>
						<!-- <div class="clearDiv">&nbsp;</div> -->

					<!--</td>
				</tr>
			</table>--> 
		<!--</td>
	</tr>
</table>-->
</div>

<%
	if(resultMap !=null && resultMap.size() != 0 && !noDataFound)
	{
		List selectedTestList = (List) resultMap.get("SELECTED_TESTS");
		List componentList = new ArrayList();
		List sid_List = new ArrayList();
		for(int i=0; i<keyList.size(); i++) {
			String chartKey = (String) keyList.get(i);
			String sids = (String) sidList.get(i);
			String tempComponent = chartKey.substring(0, chartKey.indexOf(":"));
			String tempCompType = chartKey.substring(chartKey.indexOf(":")+1);
			tempCompType = tempCompType.substring(0, tempCompType.indexOf(":"));
			tempComponent += ":" + tempCompType;
			if(!componentList.contains(tempComponent)) {
				componentList.add(tempComponent);
				sid_List.add(sids);
			}
		}
		String xAxisLabel = (String) resultMap.get("xAxisLabel");
	
%>  
	<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0" valign="top">
		<tr>
			<td align="right"><%=xAxisLabel%></td>
		</tr>
	</table>
  <div class="print OuterBox" style="border-top: 1px solid #dedede;padding-top:8px;">
<table align="center" valign="middle" cellspacing="0" cellpadding="0"  width="100%" border="0" >
<%
		for(int l=0; l<selectedTestList.size(); l++)
		{
			String currentTest = (String) selectedTestList.get(l);
			for(int j=0; j<componentList.size(); j++) 
			{
				List currentList = new ArrayList();
				String currentComponent = (String) componentList.get(j);
				String sids = (String) sid_List.get(j);
				if(sids==null || sids.length()==0)
				{
					sids = "";
				}
				else
				{
					sids = ":"+sids;
				}
				currentComponent += ":" + currentTest;
				for(int k=0; k<keyList.size(); k++)
				{
					String chartKey = (String) keyList.get(k);
					if(chartKey.startsWith(currentComponent)) {
						currentList.add(chartKey);
					}
				}
				boolean isSingleGraph = false;
				if(keyList.size() == 1 || currentList.size()==1) {
					isSingleGraph = true;
				}

				if(!currentList.isEmpty())
				{
%>
	<tr>
			<td>
				
						<div width="100%" NOWRAP class="printTableHeader">
							<div class="printOuterBoxHeader" style="float:left"><egui:intnl text="reporter.common.Prediction for Component"/>&nbsp;<%= currentComponent.substring(0, currentComponent.indexOf(":"))+sids%> - <egui:intnl text="reporter.common.Test "/>&nbsp;<%= intlmap.getTestDescription(currentTest) %></div>
						</div>
					<table class="linesquare" align="center" cellspacing="0" cellpadding="0" width="100%" border="0">
	<%
						
						//if(xAxisLabel != null && !isSingleGraph)
//						if(l==0&&j==0)
//						{
	%>
					<!-- <tr>
						<td class="blackcontent" style="float:right"> <b><%=xAxisLabel%> </b></td>
					</tr> -->
	<%
//						}
	%>
					<tr class="newimg">
						<td valign="top" height="100%" >
							<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0">
	<%
						String mngrIP = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
						String servlet = "/final/servlet/com.eg.ErCapacityPredictionReportC;jsessionid=" + session.getId() + "?isChartRequest=true";
						if(!noDataFound) {
							int val=0;
							if(currentList.size() > 0){
								if((currentList.size() % 2) > 0)
									val=(currentList.size() - (currentList.size() % 2));
								else
									val=currentList.size() - 2;
							}
							String borderBottomStyle="border-bottom:1px solid #dedede";
							for(int i=0; i<currentList.size(); i=i+2)
							{
								if(val == i)
									borderBottomStyle="";

								String chartKey = (String) currentList.get(i);
								String chartKeyEncoded = erUtils.specialCharEncode(chartKey);
								Map currentKeyResultMap = (Map) resultMap.get(chartKey);
								
								String tempString = chartKey.substring(chartKey.indexOf(":") +1); 
								tempString = tempString.substring(tempString.indexOf(":") +1);
								tempString = tempString.substring(tempString.indexOf(":") +1);
								String measureString = tempString;
								String descString = null;
								if(tempString.indexOf(":")!= -1) {
									measureString = tempString.substring(0, tempString.indexOf(":"));
									descString = tempString.substring(tempString.indexOf(":")+1);
								}
								String headerString = intlmap.getMeasureDescription(currentTest,measureString) + (descString == null ? "" : " : " + descString) + " (" + tablesInfo.getUnitForMeasure(currentTest, measureString) +")";
								if(descString!=null && descString.equals("-"))
								{
									headerString = intlmap.getMeasureDescription(currentTest,measureString) + " (" + tablesInfo.getUnitForMeasure(currentTest, measureString) +")";
								}
	%>
								<tr class="newimg">
								<td width="<%= isSingleGraph ? 100 : 50 %>%" style="padding:10px 10px 10px 0px;border-right:1px solid #dedede;<%=borderBottomStyle%>;" align="left" height="auto" valign="top">
									<div class="print OuterBox">
										<table align="center" cellspacing="0" width="100%" cellpadding="0" border="0">
											<tr>
												<td width="100%" style="padding:0px 10px 0px 0px;">
											
													<!--<div class="<%= isSingleGraph ? "headWidth2" : "headWidth"%>" style="white-space: nowrap;	width:200px;overflow: hidden;text-overflow: ellipsis;" title="<%= headerString %>">
														<%= headerString %>
													</div>-->
													<div class="printOuterBoxHeader" style="white-space:pre-wrap;padding-top:10px;" ><%= headerString %></div>
												</td>
											</tr>
											<tr>
												<td valign="top" height="auto">
	<%
								int graphWidth = 460;
								int graphHeight = 200;
								if(isSingleGraph)
								{
									if(isPdf != null && isPdf.equals("yes"))
									{
										graphWidth = 1000;
									}
									else
									{
										graphWidth = 950;
									}
									graphHeight = 250;
								}
								String strgraphQuery =  strManagerURL + servlet + "&er_width=" + graphWidth + (isSingleGraph ? "&bigWindow=true" : "") + "&er_height=" + graphHeight + "&chartKey=" + chartKeyEncoded ;
								String showLegend="";
								if(request.getParameter("showLegend")!=null)
								{
									showLegend=request.getParameter("showLegend");
									if(showLegend!=null && showLegend.trim().length()>0){
										String setLegendVal = "&showLegend="+showLegend;
										if(strgraphQuery.indexOf(setLegendVal)==-1)
											strgraphQuery+=setLegendVal;
									}
								}
									
	%> 
													<img src="<%= strgraphQuery %>" border="0" hspace="0" vspace="0" height="auto" align="center" style="vertical-align: middle">
												</td>
											</tr>
										</table>
									</div>
								</td>
	<%
								if(i+1 >= currentList.size()) {
									if(!isSingleGraph) {
	%>
									<td  width="50%" valign="top">&nbsp;</td>
	<%
									}
								}
								else
								{
									chartKey = (String) currentList.get(i+1);
									currentKeyResultMap = (Map) resultMap.get(chartKey);
									chartKeyEncoded = erUtils.specialCharEncode(chartKey);
									
									//System.out.println("My Map: " + myMap.keySet());
									tempString = chartKey.substring(chartKey.indexOf(":") +1); 
									tempString = tempString.substring(tempString.indexOf(":") +1);
									tempString = tempString.substring(tempString.indexOf(":") +1);
									measureString = tempString;
									descString = null;
									if(tempString.indexOf(":")!= -1) {
										measureString = tempString.substring(0, tempString.indexOf(":"));
										descString = tempString.substring(tempString.indexOf(":")+1);
									}
									headerString = intlmap.getMeasureDescription(currentTest,measureString) + (descString == null ? "" : " : " + descString) + " (" + tablesInfo.getUnitForMeasure(currentTest, measureString) +")";
									if(descString!=null && descString.equals("-"))
									{
										headerString = intlmap.getMeasureDescription(currentTest,measureString) + " (" + tablesInfo.getUnitForMeasure(currentTest, measureString) +")";
									}
									
								//for schedule mail legends
								String showLegend1="";
								if(request.getParameter("showLegend")!=null)
								{
									showLegend1=request.getParameter("showLegend");
									if(showLegend1!=null && showLegend1.trim().length()>0){
										String setLegendVal = "&showLegend="+showLegend1;
										if(servlet.indexOf(setLegendVal)==-1)
											servlet+=setLegendVal;
									}
								}
								
									
	%>
								<td width="50%" style="padding:10px 0px 10px 10px;<%=borderBottomStyle%>;" align="left" valign="top">
									<div class="print OuterBox">
										<table align="center" cellspacing="0" width="100%" cellpadding="0" border="0" class="printTable newimg">
											<tr>
												<td nowrap width="100%" align="left" class="printTableHeader2">
													<!--<div class="<%= isSingleGraph ? "headWidth2" : "headWidth"%>" style="white-space: nowrap;	width:200px;overflow: hidden;text-overflow: ellipsis;" title="<%= headerString %>">
														<%=headerString %>
													</div>-->
													<div class="printOuterBoxHeader" style="white-space:pre-wrap;padding-top:10px;"><%=headerString %></div>

												</td>
											</tr>
											<tr>
												<td width="50%" style="padding:0px 0px 10px 10px" height="auto" valign="top"> 
												
													<div style="width:100%;overflow:auto;padding:0px" align="center" style="vertical-align: middle"><img src="<%= strManagerURL + servlet + "&er_width=460&er_height=200&chartKey=" + chartKeyEncoded %>" height="auto" border="0" hspace="0" vspace="0" align="center" style="vertical-align: middle"></div>

												</td>
											</tr>
										</table>
										</div>
									</td>
<%
							}
%>
							</tr>
							
<%
						}
					}
%>
						</table>
					</td>
				</tr>
				<!-- <tr><td>&nbsp;</td></tr> -->
			</table>
		</td>
	</tr>
<%
				}
			}
		}
%>
</table>
</div>

		<%
		}
	  

	if (!StringUtils.isNull(er_RmDispName)){
		//For Setting the PDf File Name
		er_RmDispName = er_RmDispName.replace(" ","_");
		HashMap paramVal =new HashMap();
		paramVal.put("fileName",er_RmDispName);
		session.setAttribute("parameters", paramVal);
	} else {
		//For Setting the PDf File Name
		HashMap paramVal =new HashMap();
		paramVal.put("fileName","capacity_planning_prediction_report");
		session.setAttribute("parameters", paramVal);
	}
%>	 
<%
		if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes") && isPdf == null)
		{
%>
			<div class="printFooterText"><%=strPrintFooterText%></div>
<%
		}
%>
</body>
</html>
<%@ include file="ErRemoveUser.jsp"%>
