<!DOCTYPE html>

<%@ include file = "ErTracker.jsp" %>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.eg.EgDbInfo" %>
<%@ page import = "com.eg.EgMappingInfo"%>
<%@ page import = "com.eg.EgReportInfo"%>
<%@ page import = "com.egurkha.util.DateUtil"%>

<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ page import="com.egurkha.util.StringUtils"%>
<%
// karthikeyan 
   String titleToDisplay=request.getParameter("er_RmDispName");
try{
	String strManagerURL = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
	EgDbInfo dbInfo = new EgDbInfo("manager");
	com.egurkha.ini.IniUI ui = (com.egurkha.ini.IniUI)com.egurkha.ini.IniUI.getInstance();
	EgReportInfo reportInfo = new EgReportInfo("manager");

	String BLANK_SPACE = " ";
	String COMA = ",";
	String COLON = ":";
	String UTF_8 = "UTF-8";
	EgTimeZoneConverter timeZoneConverterStart = null;
	EgTimeZoneConverter timeZoneConverterEnd = null;
	String startDateForDisplay = null;
	String startHourForDisplay = null;
	String endDateForDisplay = null;
	String endHourForDisplay = null;
	String startMinForDisplay = null;
	String endMinForDisplay = null;
	User userName=UserRegistry.getInstance().getUser(session.getId());
	List selectedApplication = new ArrayList();
	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 s_farmserver = request.getParameter("er_zone");
	String s_compType = request.getParameter("er_compType");
	String[] s_application = request.getParameterValues("er_application");
	String applicationName = request.getParameter("er_application");
	String[] selectedCompArray = request.getParameterValues("er_component");
	String pdfPrint = request.getParameter("pdfPrint");
	String isPdf = request.getParameter("isPdf");
	String sample = request.getParameter("sample");
	String drilldownenabled = request.getParameter("drilldownenabled");
	String timefrom = request.getParameter("timefrom");
	String minfrom = request.getParameter("minfrom");
	String timeto = request.getParameter("timeto");
	String minto = request.getParameter("minto");
	String iniDate = request.getParameter("inidate");
	String er_graphViews = request.getParameter("er_graphViews");
	String s_option = "graph";
	String chartApplication = request.getParameter("chartApplication");
	String strShowLegend = request.getParameter("showLegend");
	EgMappingInfo intlmap = null;
	if(thisuser !=null)
	{
		intlmap = new EgMappingInfo(thisuser.getLanguage());
	}
	String er_option =request.getParameter("er_option");
	String er_site = request.getParameter("er_site");
	String headerKeyName="";
	if(er_option!=null && er_option.equalsIgnoreCase("Segment"))
	{
		headerKeyName=er_option+" : "+er_site;
	}
	else if(er_option!=null && er_option.equalsIgnoreCase("Service"))
	{
		headerKeyName=er_option+" : "+er_site;
	}
	else if(er_option!=null && er_option.equalsIgnoreCase("Group"))
	{
		headerKeyName=er_option+" : "+er_site;
	}
	else if(er_option!=null && er_option.equalsIgnoreCase("Component"))
	{
		if(request.getParameter("er_compType")!=null)
			headerKeyName=er_option+" : "+intlmap.getComponentTypeDescription(request.getParameter("er_compType"));
		else if(request.getParameter("er_server")!=null)
			headerKeyName=er_option+" : "+request.getParameter("er_server");
		else
			headerKeyName=er_option;
	}
	else
	{
		headerKeyName="Zone"+" : "+request.getParameter("er_zone");
	}
	if(strShowLegend==null)
		strShowLegend = "false";
	String s_st_time_graph = null;
	if(s_st_time != null) {
		s_st_time_graph = new String(s_st_time);
	}
	String s_en_time_graph = null;
	if(s_en_time != null) {
		s_en_time_graph = new String(s_en_time);
	}
	ArrayList singleSelection = new ArrayList();
	ArrayList singleColors = new ArrayList();
	Map resultMap = (Map) session.getAttribute("APPLICATION_USAGE_REPORT");
	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;
	String fontStyleDblSingl = "";
	if((dbInfo.doubleByteEnabled || !thisuser.getLanguage().equals("en_US")) && !(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes") || (sample != null && !sample.equalsIgnoreCase("yes") && drilldownenabled !=null && drilldownenabled.equalsIgnoreCase("yes"))))
	{
		fontStyleDblSingl = "multi_font";
	}
	else
	{
		fontStyleDblSingl = "";
	}
	if(s_application != null)
		selectedApplication = Arrays.asList(s_application);
%>
<!Doctype html>
<head>
<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
%>
	<title>&nbsp; <egui:intnl text="reporter.common.Reporter" />
	&nbsp; &nbsp; <egui:intnl text="reporter.common.Print" /> &nbsp;</title>
<%
	}
	else
	{
%>
	<title>&nbsp; <egui:intnl text="reporter.common.Reporter" />
	&nbsp; &nbsp;</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.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>
<%
	}
%>
			<!-- <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"  style="border-bottom:1px solid #999;">
				<tr>
					<td style="padding:2px"> -->
					<div class="printHeaderBox" >
<%

	if (!StringUtils.isNull(titleToDisplay))
	{
%>
				
						 <div class="printHeaderBoxTitle"><%=titleToDisplay%>&nbsp;For <%=headerKeyName%>&nbsp;</div>
<%
	}
	else
	{
%>
						<div class="printHeaderBoxTitle"><egui:intnl text="reporter.common.Thin Client Application Usage Report -"/>&nbsp;<%=headerKeyName%></div>
<%
	}

	if(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>
<%
		String dispStart="";
		String dispEnd="";
		dispStart = s_st_time + " " + s_st_hr+COLON+strmin ;
		dispEnd = s_en_time + " " + s_en_hr+COLON+enmin ;
		timeZoneConverterStart = new EgTimeZoneConverter(dispStart ,userName);
		startDateForDisplay = (String) timeZoneConverterStart.getDate(false);
		startHourForDisplay = timeZoneConverterStart.getHour();
		startMinForDisplay = timeZoneConverterStart.getMinute();
		timeZoneConverterEnd = new EgTimeZoneConverter(dispEnd ,userName);
		endDateForDisplay = (String) timeZoneConverterEnd.getDate(false);
		endHourForDisplay = timeZoneConverterEnd.getHour();
		endMinForDisplay = timeZoneConverterEnd.getMinute();
		String pdfStartDate=startDateForDisplay+" "+startHourForDisplay+":"+startMinForDisplay;
		String pdfEndDate = endDateForDisplay+" "+endHourForDisplay+":"+endMinForDisplay;
		Vector dvec = new Vector();
		String stimefmt = pdfStartDate+ " hrs";
		String etimefmt = pdfEndDate+ " hrs";

%>
				<div class="printOuterBoxNoBorder">
					<div class="printSelectionFields">
						<egui:intnl text="reporter.common.Timeline"/> - 
						<span class="bold"><%=stimefmt%>&nbsp;to&nbsp;<%=etimefmt%></span>
					</div>
				</div>

					<!-- 	<div style="float:right;padding:4px;">
							<div style="float:left" class="formLabel"></div>
							<div style="float:left;width:10px" align="center" ></div>
							<div style="float:left;" class="formValue"><%=stimefmt%></div>
						</div>
						<div style="clear:both;float:right;padding:4px;">
							<div style="float:left" class="formLabel"></div>
							<div style="float:left;width:10px" align="center"></div>
							<div style="float:left;" class="formValue"><%=etimefmt%></div>
						</div>
					</td>
				</tr>
			</table> -->
		<!-- </td>
	</tr>
</table><br/> -->
<div class="printOuterBox">
<!-- <table align="center" cellspacing="0" cellpadding="0" width="100%" border="0" >
	<tr> -->
<%
			String mngrIP = new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
			String servlet = "/final/servlet/com.eg.ErAppUsageReportC;jsessionid=" + session.getId() + "?er_option=graph&inidate="+com.eg.EgURLEncoder.encode(currentDateFormat,UTF_8)+"&startdate="+com.eg.EgURLEncoder.encode(s_st_time,UTF_8)+"&enddate="+com.eg.EgURLEncoder.encode(s_en_time,UTF_8)+"&starthr="+s_st_hr+"&endhr="+s_en_hr+"&startmin="+strmin+"&endmin="+enmin+"&timefrom="+timefrom+"&minfrom="+minfrom+"&timeto="+timeto+"&minto="+minto+"&er_compType="+s_compType+"&showLegend="+com.eg.EgURLEncoder.encode(strShowLegend,UTF_8)+"&er_graphViews="+er_graphViews+"&userID="+com.eg.EgURLEncoder.encode(userName.getLoginID(),UTF_8);
			
			HashMap map=(HashMap)ui.getReporterGraphParams();
			StringTokenizer stc = new StringTokenizer((String)map.get("samplecolors"),",");
			String [] cols = new String[stc.countTokens()];
			
			for(int i=0;i<cols.length;i++)
			{
				String strstc = stc.nextToken().trim();
				cols[i] = strstc;
			}
			singleSelection = new ArrayList();
			singleColors = new ArrayList();
			String tempApplication = applicationName;
			Map tempMap = (Map)resultMap.get(tempApplication);
			if(tempMap != null)
			{
				Set keySet = tempMap.keySet();
				Iterator itr = keySet.iterator();
				int i = 0;
				while(itr.hasNext())
				{
					singleSelection.add(itr.next());
					singleColors.add(cols[i]);
					i++;
					if(i >= cols.length)
						i = 0;
				}
			}
%>
		<div class="printOuterBoxHeader" ><egui:intnl text="reporter.common.Application Usage Report -"/>&nbsp;<%= intlmap.getComponentTypeDescription(s_compType) %> - <%= tempApplication %> </div>
	<!-- </tr> -->
<table align="center" cellspacing="0" cellpadding="0" width="100%" border="0" >

	<tr>
		<td align="center" ><div width="100%"><img  hspace="0" border="0" vspace="0" align="center" src="<%= strManagerURL + servlet + "&chartApplication="+com.eg.EgURLEncoder.encode(tempApplication,"UTF-8") %>"/></div></td>
	</tr>
<%
			String strselectioncount = reportInfo.getValue("MISC","RightDisplaySelectioncount");
			int selectioncount=10;
			if(strselectioncount !=null && !strselectioncount.equals(""))
			{
				try
				{
					selectioncount = Integer.parseInt(strselectioncount);
				}
				catch (Exception e)
				{
					selectioncount = 10;
				}
			}
			if (singleSelection != null && singleSelection.size() >selectioncount && false)
			 {
%>
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="0" style="table-layout:auto"><col 	width="10px"><col width="440px"><col width="10px"><col width="440px">
<%
				int count1=0;
				for (int k=0; k <singleSelection.size();k++)
				{
					String st_key = (String)singleColors.get(k);
					String value = (String)singleSelection.get(k);
					st_key = st_key.substring(1,st_key.length());
					if(k%2 ==0)
					{
						String dispValue="";
						int n=0;
						int h=0;
						int charval=value.length();
						for (int y=0;y <charval ;y++ )
						{
							if(n==60)
							{
							  dispValue += value.substring(h,y)+"<br>";
							  h=y;
							  n=0;
							}
							n++;
						}
						if(n < 60)
						{
							dispValue += value.substring(h,charval)+"<br>";
						}
						if(value.indexOf(" ")>-1)
						{
							dispValue = value;
						}
%>
				<tr>
					<td align="right" id="cellbgwhite" valign="top" class="padding4"><img src="/final/servlet/com.eg.ErImageDrawC?req=<%=st_key%>"/></td>
					<td align="left" id="cellbgwhite"  valign="top" wrap ><%=dispValue%></td>
				</tr>
<%
					}
					else if(k%2 !=0)
					{
						String dispValue="";
						int n=0;
						int h=0;
						int charval=value.length();
						for (int y=0;y <charval ;y++ )
						{
							if(n==60)
							{
							  dispValue += value.substring(h,y)+"<br>";
							  h=y;
							  n=0;
							}
							n++;
						}
						if(n < 60)
						{
							dispValue += value.substring(h,charval)+"<br>";
						}
						if(value.indexOf(" ")>-1)
						{
							dispValue = value;
						}
%>
				<tr>
					<td align="right" id="cellbgwhite" valign="top" class="padding4"><img src="/final/servlet/com.eg.ErImageDrawC?req=<%=st_key%>"/></td>
					<td align="left"  id="cellbgwhite" valign="top" wrap ><%=dispValue%></td>
				</tr>
<%
					}
					else
					{
%>
				<tr>
					<td align="right" id="cellbgwhite" valign="top" class="padding4"><img src="/final/servlet/com.eg.ErImageDrawC?req=<%=st_key%>"/></td>
					<td align="left"  id="cellbgwhite"  valign="top" wrap ><%=value%></td>
				</tr>
<%
					}
				}
				if(singleSelection.size()%2 !=0)
				{
%>
				<tr>
					<td width="50%"align="right" id="cellbgwhite" colspan="2">&nbsp;</td>
				</tr>
<%
				}
%>
				<tr>
					<td width="50%"align="right" id="cellbgwhite" colspan="4">&nbsp;</td>
				</tr>
			</table>
		</td>
	</tr>
<%
			}
	// graph image ends edward
			session.setAttribute("singleColors",singleColors);
			session.setAttribute("singleSelection",singleSelection);
%>
</table>
</div>			  
<%
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes") && isPdf == null)
	{
%>
		<div class="printFooterText"><%=strPrintFooterText%></div>
<%
	}
}
catch(Throwable t)
{
	t.printStackTrace();
}
%>


</body>
</html>
<%@ include file = "ErRemoveUser.jsp" %>
<%
// karthikeyan 
	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);
	}
%>
<%!
	// karthikeyan 
	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;
	}
%>
