<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ include file = "ErTracker.jsp"%>
<%@ page import = "egurkha.*" %>
<%@ page import="com.egurkha.ini.*" %>
<%@ page import ="com.eg.IniFile"%>
<%@ page import ="com.eg.EgInstallInfo"%>
<%@ page import="egurkha.reporter.uptime.*" %>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import="com.eg.EgDateInfo" %>
<%@ page import="com.egurkha.pdfmaker.EgPdfData" %>
<%@ page import ="com.eg.EgMappingInfo"%>
<%@ page import="java.util.*" %>
<%@ page import="java.text.*" %>
<%@ page import="com.eg.EgDbInfo" %>
<%@ page import="com.egurkha.ini.IniUI" %>
<%@ page import="java.net.URLEncoder"%>

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

	EgDateInfo egDt = new EgDateInfo();

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

	ErUtils erUtils = new ErUtils();

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

	Hashtable chartParams = new Hashtable();
	String eruserid = request.getParameter("eruserid");
	String pdfPrint = request.getParameter("pdfPrint");
	UserRegistry mregistry = UserRegistry.getInstance();
	User muser = mregistry.getUser(session.getId());
	String er_component=request.getParameter("er_component");
	String imgDivId=request.getParameter("imgDivId");


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

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!Doctype HTML>
	<HEAD>
<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
%>
		<title>&nbsp;eG Reporter&nbsp;&nbsp;<egui:intnl text="reporter.common.Details"/> &nbsp;</title>
<%
	}
	else
	{
%>
	<title>eG Reporter</title>
<%
	}
%>
		<meta name="Author" content="John Williams">
		<link rel="stylesheet" type="text/css" href="/final/styles/eGLightThemeIcons.css" />
		<!-- <link rel=stylesheet href="../reporter/styles/er_reporter.css"> -->
		<!--egui:skin ui="reporter"/-->
		<script language="JavaScript1.2" src="../reporter/scripts/er_reporter.js"></script>
		<script language="JavaScript1.2" src="../reporter/scripts/er_images.js"></script>
		<script language="JavaScript1.2">
			function closeWin()
			{
				if(window.printwin !=null)
				{
					printwin.close();
				}
				if(window.newwin !=null)
				{
					newwin.close();
				}
				if(window.mailwin !=null)
				{
					mailwin.close();
				}
				if(window.datawin !=null)
				{
					datawin.close();
				}
				if(window.savewin != null) {
					savewin.close();
				}
			}
			function closeDetailsDiv()
			{
				var detailsDiv=window.parent.document.getElementById("detailsDiv");
				if(detailsDiv!=null)
				{
					detailsDiv.style.display="none";
				}
			}
			function saveMe()
			{
				var blankPage = "";
				if(location.protocol=="https:") blankPage="/final/blank.html";
				var savewin =window.open("/final/reporter/ErUptimeSave.jsp?report=<%=ErUptimePdfGenerator.UPTIME_REBOOT_REPORT%>","SaveWindow","width=400,height=150,left=300,top=200,scrollbars=no,resizable=no");
			}

			function saveInCSVFormat()
			{
				var reporttype="UptimeReboot";
				window.location.href="../servlet/egurkha.reporter.SaveInCSVFormat?reporttype="+reporttype,"CSVFormat","width=1012,height=603,left=0,top=105,scrollbars=1,scrollbars=yes,resizable=yes";
			}
		</script>
	<style>


@media print {body {-webkit-print-color-adjust: exact;}}

body{font-size:11px;line-height:1.5em;color:#2a292a;}
header{font-size:15px;}
.formLabel {font-size:12px;line-height:14px;}
.formValue {font-weight:500;font-size:12px;line-height:14px;}
b{font-weight:500;font-size:11px;}
table tr td{font-size:11px;padding:4px;}

.printTable{border: 1px solid #c3c3c3; border-collapse: collapse;}
.printTable tr td{border: 1px solid #c3c3c3;}

.printTableHeader{font-weight:500;border: 1px solid #c3c3c3;text-align:center;background-color:#cdcdcd;padding:4px;}
.printTableHeader2{font-weight:500;border: 1px solid #c3c3c3;text-align:center;background-color:#dcdcdc;padding:4px;}


body{font-size:100%}
.borderradius{
border-radius: 5px 5px 5px 5px;
-moz-border-radius: 5px 5px 5px 5px;
-khtml-border-radius: 5px 5px 5px 5px;
-o-border-radius: 5px 5px 5px 5px;
-webkit-border-radius: 5px 5px 5px 5px;
border-color:#d2d2d2;
border-style:solid;
border-width:1px;
margin-bottom:5px;
}
#multi_font {font-family:CODE2000;}
.multi_font {font-family:CODE2000;}
</style>
<style type="text/css" media="print">
#header {
background: #000 !important;
} 
#printbt{ display:none}
</style>
	</HEAD>
<%
//	Map resultMap = (Map)session.getAttribute("UPTIME_RESULT");
	Map resultMap = (Map)session.getAttribute(imgDivId);
	List uptimeData = (List)resultMap.get("UPTIME_DATA");
	String comp = request.getParameter("component");
	ErUptimeData data = null;
	boolean compFound = false;
	for(int i=0; i<uptimeData.size(); i++) {
		data = (ErUptimeData)uptimeData.get(i);
		if(data.getTrgtHost().equals(comp)) {
			compFound = true;
			break;
		}
	}
	ErUptimePdfGenerator pdfGenerator = null;
	List detailBeanList = new ArrayList();
	List uptimeList = new ArrayList();
	if(compFound)
	{
		List rebootList = data.getFilteredReboot();
		List shutdownList = data.getFilteredShutdown();
		List durationList = data.getFilteredDuration();

		for(int i=0; i<shutdownList.size(); i++) {
			ErRebootDetailBean detailBean = new ErRebootDetailBean();
			detailBean.setShutdown((Calendar)shutdownList.get(i));
			detailBean.setReboot((Calendar)rebootList.get(i));
			detailBean.setDuration((String)durationList.get(i));
			detailBeanList.add(detailBean);
		}
		Collections.sort(detailBeanList);
	} 
	
	List componentUpDownList = (List)resultMap.get("COMPONENT_LIST");
	uptimeList.add(componentUpDownList);
	ErUptimeDowntimeBean uptimeDowntimeBean = null;
	for(int i=0; i<componentUpDownList.size(); i++)
	{
		uptimeDowntimeBean = (ErUptimeDowntimeBean) componentUpDownList.get(i);
		if(uptimeDowntimeBean.getComponent().equals(comp))
		{
			break;
		}
	}

	String starttimeformat1="";
	String endtimeformat1="";
	String dispStartDate=request.getParameter("startdate");
	String dispEndDate=request.getParameter("enddate");
	String starttimeformat="";
	String endtimeformat="";
	String s_sthr =request.getParameter("starthr");
	String s_endhr =request.getParameter("endhr");
	String strhrmin=request.getParameter("stmin");
	String enhrmin=request.getParameter("enmin");
	if(strhrmin == null || strhrmin.equalsIgnoreCase("NULL"))
		strhrmin="00";
	if(enhrmin == null || enhrmin.equalsIgnoreCase("NULL"))
		enhrmin="00";

	dispStartDate = DateUtil.changeDateFormat(dispStartDate.trim(),"dd/MM/yyyy",currentDateFormat);
	dispEndDate = DateUtil.changeDateFormat(dispEndDate.trim(),"dd/MM/yyyy",currentDateFormat);
	starttimeformat = dispStartDate.trim()+ " " +s_sthr+":"+strhrmin+" "+"Hrs ";
	endtimeformat = dispEndDate.trim()+ " " +s_endhr+":"+enhrmin+" Hrs ";

	EgTimeZoneConverter converterStart =new   EgTimeZoneConverter(dispStartDate+" "+s_sthr+":"+strhrmin,thisuser);
	String st_dateTime = converterStart.getDateTime()+" "+"Hrs ";

	EgTimeZoneConverter converterEnd = new EgTimeZoneConverter(dispEndDate+" "+s_endhr+":"+enhrmin,thisuser);
	String en_dateTime = converterEnd.getDateTime()+" "+"Hrs ";
	
%>

<br>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF">
	<input type="hidden" name="inidate" value = "<%=currentDateFormat%>">
	<input type = "hidden" name="reporttype" value="UptimeReboot">
<%
		if(pdfPrint ==null || !pdfPrint.equalsIgnoreCase("yes"))
	{
%>
<table cellpadding="0" cellspacing="2" border="0" width="97%" align="center">
	<tr>
		<td class="cellbgwhite"><img src="<%=imageName%>" border="0" /></td>
	</tr>
</table>
<%
	}
%>
	<table align="center" cellspacing="0" cellpadding="0" width="97%" border="0">
		<tr>
			<td width="100%" valign="top" id="cellbglight" align="center" style="border-bottom:#000 1px solid">
				<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0">
					<tr>
									<th class="cellbgdark" id="cellborder1" width="100%" nowrap align ="left" colspan="5" height="30"  >
										<b><egui:intnl text="reporter.uptime.Uptime Details for"/></b>&nbsp;<%=er_component%>&nbsp; - &nbsp;<%=comp%>
									</th>
<%
				if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
				{
%>
						<th  width="40" height="22" valign="top" id="traycorner">
							<img src="../reporter/images/spacer.gif" border="0"  width="36" height="22">
						</th>
						<td height="22"  bgcolor="#ffffff">
							<table border="0" width="100%" cellpadding="0" cellspacing="0">
							<tr>
								<td>
									<img id="printbt" class="iconPrinter mouse" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" border="0" alt='<egui:intnl text="reporter.common.PRINT"/>' title='<egui:intnl text="reporter.common.PRINT"/>' onClick="javascript:print();" />
								</td>
							</tr>
							</table>
						</td>
<%
				}
%>

					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td>
				<table border="0" id="tableborder" align="center" cellspacing="0" cellpadding="6" width="100%" >
					<tr>
						<td id="cellbglight" >
							<table id="tableborder" align="center" width="100%" cellspacing="0" cellpadding="0"  border="0">
								<tr>
									<td class="blackcontent" id="tdborder" width="100%" nowrap align ="center" colspan="5" height="28"  style="border-width:0px 0px 0px 0px;
border-style:solid;border-color:#d2d2d2;font-size:13px;font-weight:normal"><span class="<%=fontStyleDblSingl%>">
										&nbsp;<b><egui:intnl text="reporter.common.Start Date:"/></b> &nbsp;<%=st_dateTime%> &nbsp; &nbsp; &nbsp; <b><egui:intnl text="reporter.common.End Date"/></b>  : <%=en_dateTime%>
									</span></td>
								</tr>
<%
								String s_title = intlmap.getTextDescription("reporter.uptime.Uptime Details for ") +er_component +" - "+ comp;
%>
								
									<td rowspan="5" colspan="3" id="tdborder">
									<table border="0"  width="100%" border="0" >
									<tr>
									<td>
									<p> <span style="font-size:12px;"><egui:intnl text="reporter.uptime.y - year, M - month, D - day, h - hour, m - min"/></span> </p>
									</td>

									</tr>
									<tr>
									<td width="50%">
									<table width="100%" cellspacing="0" cellpadding="0" border="1" bordercolor="#d2d2d2" style="font-size:12px;border-collapse:collapse;border:#d2d2d2 1px solid;">

									<tr>
									<th id="tdborder" class="blackcontent" width="25%">
										<span class="<%=fontStyleDblSingl%>"><egui:intnl text="reporter.uptime.Total Uptime"/></span>
									</th>
									<td id="tdborder" class="blackcontent" height="35" width="25%"  align="center">
									<%
										String displayString = "";
										StringTokenizer st = null;
										if(uptimeDowntimeBean.getUpTime().equals("-")) {
											displayString = uptimeDowntimeBean.getUpTime();
										} else {
											st = new StringTokenizer(uptimeDowntimeBean.getUpTime());
											while(st.hasMoreTokens())
											{
												if(displayString.equals(""))
												{
													displayString = st.nextToken();
												}
												else
												{
													displayString += "&nbsp;" + st.nextToken();
												}
												displayString += st.nextToken();
											}
											if(!displayString.equals(""))
											{
												//displayString += "*";
											}
										}

										String userId = request.getParameter("eruserid");
										ErUserData userData = new ErUserData(userId,false);
										com.egurkha.User usr = userData.getUser(userId);
										String thisLang = usr.getLanguage();
										String fontName = IniUI.getInstance().getFontName();
									%>
										&nbsp;<%=displayString %>
									</td>
									<%
										if (EgDbInfo.doubleByteEnabled || !thisLang.equals("en_US")) {
										} else {
											fontName = "Lucida Grande";
										}
										chartParams.put("Chart", "pie");
										String sampleValues = uptimeDowntimeBean.getPerUpTime();
										if(sampleValues.startsWith("100")) {
											sampleValues += ",0";
										} else {
											sampleValues += ", " + uptimeDowntimeBean.getPerDownTime();
										}
										String valueNew = erUtils.specialCharEncode("% ") + intlmap.getTextDescription("reporter.uptime.Uptime") + "," + erUtils.specialCharEncode("% ") + intlmap.getTextDescription("reporter.uptime.Downtime");
										chartParams.put("sampleValues", sampleValues);
										chartParams.put("sampleDecimalCount", "2");
										chartParams.put("antialias", "true");
										chartParams.put("sampleColors", "#007D00,#CC0000");
										chartParams.put("background", "#Ffffff");
										chartParams.put("3DModeOn", "true");
										chartParams.put("valueLabelsOn", "true");
										chartParams.put("valueLabelStyle", "inside");
										chartParams.put("valueLabelPostfix", erUtils.specialCharEncode("%"));
										chartParams.put("legendOn", "true");
										chartParams.put("legendPosition", "right");
										//chartParams.put("legendLabels", "% Uptime, % Downtime");
										chartParams.put("legendLabels", valueNew);
										chartParams.put("titleFont", fontName + ",bold,12");
										chartParams.put("barLabelFont",  fontName + ",Font.PLAIN,12");
										chartParams.put("sampleLabelFont",  fontName + ",Font.PLAIN,12");
										chartParams.put("rangeAxisLabelFont", fontName + ",Font.PLAIN,12");

										String chartUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/final/servlet/com.eg.ErUptimeServletC?ServerDetailsGraph=ServerDetailsGraph&er_width=350&er_height=250&eruserid="+eruserid;
										Iterator itr = chartParams.keySet().iterator();
										while(itr.hasNext())
										{
											String key = (String)itr.next();
											String value = (String)chartParams.get(key);
											chartUrl += "&" + key + "=" + URLEncoder.encode(value);
										}
										chartUrl += "&includeTitle=false&er_width=500&er_height=180";
									%>
									<tr>
									<th id="tdborder" class="blackcontent" height="35">
										<span class="<%=fontStyleDblSingl%>"><egui:intnl text="reporter.uptime.% Uptime"/></span>
									</th>
									<td id="tdborder" class="blackcontent"  align="center">
										&nbsp;<%= uptimeDowntimeBean.getPerUpTime() %>
									</td>
								</tr>
								<tr>
									<th id="tdborder" class="blackcontent" >
										<span class="<%=fontStyleDblSingl%>"><egui:intnl text="reporter.uptime.Total Downtime"/></span>
									</th>
									<td id="tdborder" class="blackcontent"  height="35"  align="center">
									<%
										if(uptimeDowntimeBean.getDownTime().equals("-")) {
											displayString = uptimeDowntimeBean.getDownTime();
										} else {
											st = new StringTokenizer(uptimeDowntimeBean.getDownTime());
											displayString = "";
											while(st.hasMoreTokens()) {
												if(displayString.equals("")) {
													displayString = st.nextToken();
												} else {
													displayString += "&nbsp;" + st.nextToken();
												}
												displayString += st.nextToken();
											}
											if(!displayString.equals("")) {
												//displayString += "*";
											}
										}
									%>
										&nbsp;<%= displayString %>
									</td>
								</tr>
								<tr>
									<th id="tdborder" class="blackcontent" height="35">
										<span class="<%=fontStyleDblSingl%>"><egui:intnl text="reporter.uptime.% Downtime"/></span>
									</th>
									<td id="tdborder" class="blackcontent"  align="center">
										&nbsp;<%= uptimeDowntimeBean.getPerDownTime() %>
									</td>
								</tr>
								
										
									</table>
									</td>
									<td align="center" width="50%" >
									<table width="100%" height="100%" cellpadding="0" cellspacing="0" border="0" style="height:180px;border:1px solid #ccc">
											<tr>
												<td  align="center" height="100%">
													<%--
													<applet code="com.objectplanet.chart.ChartApplet" archive="chart.jar" width="420" height="180" border="0">
													<%
														Iterator itr = chartParams.keySet().iterator();
														while(itr.hasNext())
														{
															String key = (String)itr.next();
															String value = (String)chartParams.get(key);
													%>
													<param name="<%=key%>" value='<%=value%>'>
													<%
														}
													%>
													</applet> 
													--%>
													<%
														String queryStr = (String)session.getAttribute("querygraph");
														queryStr += "&component=" + request.getParameter("component");
														queryStr += "&UptimeServerPrint=true";
													%>
													<img width="500" height="350" src="<%= chartUrl %>"/>
												</td>
											</tr>
										</table>
									</td>
									
									
									</tr>
									
									</table>
										
									</td>
								</tr>
								
<%
								st = new StringTokenizer(uptimeDowntimeBean.getUpTime());
								displayString = "";
								while(st.hasMoreTokens()) {
									if(displayString.equals("")) {
										displayString = st.nextToken();
									} else {
										displayString += " "+st.nextToken();
									}
									displayString += st.nextToken();
								}
								
								if(!displayString.equals("")) {
									displayString += " ";
								}
								st = new StringTokenizer(uptimeDowntimeBean.getDownTime());
								displayString = "";
								while(st.hasMoreTokens()) {
									if(displayString.equals("")) {
										displayString = st.nextToken();
									} else {
										displayString += " "+st.nextToken();
									}
									displayString += st.nextToken();
								}
								
								if(!displayString.equals("")) {
									displayString += " ";
								}
%>
							</table>
							
						</td>
					</tr>
<%
					if(detailBeanList.size()>0)
					{
%>
					<tr>
						<td align="center" id="cellbglight" class="cellborder">
							<table border="0" cellspacing="0" align="center" cellpadding="0" class="printTable" width="40%">
	<tr>
		<td width="100%" nowrap class="printTableHeader" align ="center" style="text-align:center;" colspan="3"><b><egui:intnl text="reporter.common.Downtime Details for"/>&nbsp;<%=comp%></b></td>
	</tr>
	<tr>
		<td align="center" width="15%" class="printTableHeader2"><egui:intnl text="reporter.uptime.Down At"/></td>
		<td align="center" width="15%" class="printTableHeader2"><egui:intnl text="reporter.uptime.Up At"/></td>
		<td align="center" width="10%" class="printTableHeader2"><egui:intnl text="reporter.uptime.Duration"/>&nbsp;(<egui:intnl text="reporter.uptime.mins"/>)</td>
	</tr>
<%
							s_title = intlmap.getTextDescription("reporter.uptime.Reboot Details for ") + comp;
							String s_inidate = request.getParameter("inidate");
							SimpleDateFormat sdf = new SimpleDateFormat(currentDateFormat+" HH:mm:ss");

							for(int i=0; i<detailBeanList.size(); i++) 
							{
								ErRebootDetailBean bean = (ErRebootDetailBean)detailBeanList.get(i);
								String shutTime = sdf.format(bean.getShutdown().getTime());
								String rebootTime = sdf.format(bean.getReboot().getTime());


								String usr_shutTime="";
								String usr_rebootTime="";
								if(shutTime!=null)
								{
									converterStart = new EgTimeZoneConverter(shutTime,thisuser);
									usr_shutTime = converterStart.getDateTime();
								}
								if(rebootTime!=null)
								{
									converterEnd = new EgTimeZoneConverter(rebootTime,thisuser);
									usr_rebootTime = converterEnd.getDateTime();
								}


								//
								Calendar ca=bean.getReboot();
								if(ca!=null)
								{ // for still down
								int year = ca.get(Calendar.YEAR);
								if(year==1900)
								usr_rebootTime="-";
								}
								//

%>
								<tr>
									<td id="tdborder" class="blackcontent" align="center" width="15%" >&nbsp;<%=usr_shutTime%> </td>
									<td id="tdborder" class="blackcontent" align="center" width="15%" >&nbsp;<%=usr_rebootTime%> </td>
									<td id="tdborder" class="blackcontent" align="center" width="10%">&nbsp;<%=bean.getDuration() %> </td>
								</tr>
<%	
							}
%>
							</table>
						</td>
					</tr>
<%
					}
%>
				</table>
				<br>
			</td>
		</tr>
	</table>
	<script language="JavaScript1.2">
		//window.print();
		closeWin();
	</script>
</BODY>
</HTML>
<%@ include file="ErRemoveUser.jsp"%>

