<!DOCTYPE html>

<%
/************************************************************************************************
*	File			: ErCtxSessionUsageReportPrint.jsp
*	Version			:	6.3.1
*	Author			:	Ganesh P
*	Creation Date	:	31-07-2018
*
*************************************************************************************************/
%>


<%@ include file="ErTracker.jsp"%>
<%@ page import="com.eg.EgDbInfo"%>
<%@ page import="com.eg.EgMappingInfo"%>
<%@ page import="com.eg.EgReportInfo"%>
<%@ page import="com.eg.EgTablesInfo"%>
<%@ page import = "com.eg.EgConfigInfo"%>
<%@ page import = "com.egurkha.util.DateUtil" %>
<%@ page import="egurkha.reporter.*"%>
<%@ page import="com.eg.EgDateInfo"%>
<%@ page import="com.eg.* "%>
<%@ page import="java.net.*"%>
<%@ page import="java.util.*"%>
<%@ page import="com.egurkha.User"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>
<%@ page import="com.egurkha.util.DateUtil"%>
<%@ page import="net.sf.json.*" %>
<%@ page import = "java.text.SimpleDateFormat" %>

<%@ 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"%>

<%@ page import="com.eg.EgReportInfo" %>

<%!
	private static final String BLANK_SPACE = " ";
	private static final String COMA = ",";
	private static final String COLON = ":";
	private static final String PIE = "|";
	private static final String BSLASH = "/";
	private static final String UTF_8 = "UTF-8";	
%>
<%
	String SESSION_USAGE_REPORT = "SESSION_USAGE_REPORT";
	String pdfPrint = request.getParameter("pdfPrint");
	String titleToDisplay=request.getParameter("er_RmDispName");
	String s_st_date = request.getParameter("startdate");
	String s_en_date = 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 rtype =request.getParameter("er_type");
	String er_mode = request.getParameter("er_mode");
	String timefrom2=request.getParameter("timefrom");
	String minfrom2=request.getParameter("minfrom");
	String timeto2=request.getParameter("timeto");
	String minto2=request.getParameter("minto");
	String fontStyleDblSingl = "";
	String s_comptype = request.getParameter("er_compType");
	String er_component[] = request
				.getParameterValues("er_component");
	String sample = request.getParameter("sample");
	String er_componentType=request.getParameter("er_compType");
		EgReportInfo reportInfo=new EgReportInfo("manager");
//
	String er_option =request.getParameter("er_option");
	String er_site = request.getParameter("er_site");
	String isDomainWithUser = request.getParameter("isUserDomain");
	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("Component"))
		{
			headerKeyName=er_option;
		}
		else
		{
			headerKeyName="Zone"+" : "+request.getParameter("select_farm");
		}


//
	try {

		String isVmCompSt = request.getParameter("isVmComp");
		boolean isVmComp=false;
		if(isVmCompSt!=null && isVmCompSt.equalsIgnoreCase("true"))
		{
			isVmComp=true;
		}


		//For Time Zone Conversion
	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());

	String mngrIP= new IniFile(new EgConfigInfo("manager").getDbFile()).getValue("DB_PROPERTIES","ManagerUrl");
	String strManagerURL = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort();
		EgDbInfo dbInfo = new EgDbInfo("manager");
		EgMappingInfo intlmap = null;
		if (thisuser != null) {
			intlmap = new EgMappingInfo(thisuser.getLanguage());
		}
		if ((dbInfo.doubleByteEnabled || !thisuser.getLanguage()
				.equals("en_US"))
				&& !(pdfPrint != null
						&& pdfPrint.equalsIgnoreCase("yes") || (sample != null && !sample
						.equalsIgnoreCase("yes")))) {
			fontStyleDblSingl = "multi_font";
		} else {
			fontStyleDblSingl = "";
		}
		EgTablesInfo tablesInfo = new EgTablesInfo("manager");
		ErUtils erUtils = new ErUtils();
		//
	
	List lst = new LinkedList();
	Vector v_measure_csv = new Vector();
	List lst_dat1 = new LinkedList();
%>

<!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/resources/css/ext-eg.css" />
		<link rel="stylesheet" type="text/css" href="../../final/styles/eGLightThemeIcons.css" />
		<!-- <link rel="stylesheet" type="text/css" href="../../final/reporter/styles/printpagestyle.css" /> -->
		<link rel="stylesheet" type="text/css" href="../../final/reporter/styles/printpagestyle.css" />

<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;}
.newFont_bold28{font-size: 24px !important;font-weight:500;color:##2a292a;}
.newFont_normal13{font-size: 13px !important;font-weight:500 !important;color:#2a292a;}
.newFont_normal11{font-size: 11px !important;font-weight:500 !important;color:#2a292a;}
.newimg {page-break-inside: avoid} 
#newimg {page-break-inside: avoid}
.iconTotalSessions, .iconUniquePools, .iconUniqueUsers, .iconUniqueProtocols, .iconDuration{
				background : url('../images/Light/sessionUsageIcons_reporter.png') no-repeat top left;
			}
.iconTotalSessions{background-position:0px 0px !important; width:24px; height:24px;}
.iconUniquePools{background-position:-24px 0px !important; width:24px; height:24px;}
.iconUniqueUsers{background-position:-48px 0px !important; width:24px; height:24px;}
.iconUniqueProtocols{background-position:-72px 0px !important; width:24px; height:24px;}
.iconDuration{background-position:-96px 0px !important; width:24px; height:24px;}
</style>


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

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

<table border="0" cellspacing="0" cellpadding="0" width="100%" style="table-layout:fixed;">
	<tr>
		<td width="100%" align="center" height="100%" valign="top">

			<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center"  style="border-bottom:1px solid #999;">
				<tr>
					<td style="padding:2px"  width="90%">
<%
	if (!StringUtils.isNull(titleToDisplay))
	{
%>
						<div style="float:left" > <header><%=titleToDisplay%> for &nbsp;<%=headerKeyName%>&nbsp;</header></div>
						<% if (pdfPrint != null && pdfPrint.equalsIgnoreCase("yes")) 
							{				
	%>
								<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>
	<%						}
	}
	else
	{
%>
						<div style="float:left" > <header><egui:intnl text="reporter.common.Application Billing " />&nbsp;<%=headerKeyName%>&nbsp;</header></div>
<%
	}
	if (pdfPrint != null && pdfPrint.equalsIgnoreCase("yes")) 
	{
%>
						<div style="float:right"><img class="iconPrinter mouse"  id="printbt" 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>
					<td width="10%">
						<div><img src='<%=imageName%>' border="0" /></div>
					</td>
				</tr>
			</table>

			<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" style="border-bottom:1px solid #ccc;">
				<tr>
					<td align="left" valign="top" width="50%">
						<div style="float:left;padding:4px;">
							<div style="float:left" class="formLabel"><%= intlmap.getTextDescription("reporter.thin.Component Type") %></div>
							<div style="float:left;width:10px" align="center" >:</div>
							<div style="float:left;" class="formValue"><%= intlmap.getComponentTypeDescription(s_comptype) %></div>				
						</div>
						</div>
					</td>
					<td align="right" valign="top">
<%
	String dispStart = "";
	String dispEnd = "";
	//dispStartDate=start_date.trim()+" "+erd.s_sthr+":"+erd.s_startmin;
	dispStart = s_st_date + " " + s_st_hr + COLON + strmin ;
	dispEnd = s_en_date + " " + s_en_hr + COLON + enmin ;
	//Time zone Conversion
		
		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;
//
	lst.add(intlmap.getTextDescription("reporter.common.Application Billing")+" for "+headerKeyName);
	lst.add(intlmap.getTextDescription("reporter.thin.Component Type")+" : "+intlmap.getComponentTypeDescription(s_comptype));

		String Days = reportInfo.getExcludeWeekend("APPLICATION_BILLING");
		String excludeweekend=request.getParameter("er_excwe");
	if (excludeweekend==null ||	excludeweekend.equals(""))
		excludeweekend="No";


	if(excludeweekend.equalsIgnoreCase("Yes") )
	{
		lst.add('"'+intlmap.getTextDescription("reporter.common.Time period")+":"+intlmap.getTextDescription("reporter.common.From")+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+intlmap.getTextDescription("reporter.common.To")+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs")+'"'+","+'"'+
		
		intlmap.getTextDescription("reporter.common.Exclude weekends")+":"+Days+'"');
		
	}
	else
	{
		lst.add(intlmap.getTextDescription("reporter.common.Time period")+":"+intlmap.getTextDescription("reporter.common.From")+" "+request.getParameter("timefrom")+":"+request.getParameter("minfrom")+intlmap.getTextDescription("reporter.common.Hrs")+" "+intlmap.getTextDescription("reporter.common.To")+" "+request.getParameter("timeto")+":"+request.getParameter("minto")+intlmap.getTextDescription("reporter.common.Hrs"));
		
	}

//
	Vector dvec = new Vector();
	String stimefmt =	pdfStartDate+ " hrs";
	String etimefmt =	pdfEndDate+ " hrs";


	String ssd="Start Date : "+stimefmt+"  "+"End Date : "+etimefmt;
			lst.add('"'+ssd+'"');

%>
						<div style="float:right;padding:4px;">
							<div style="float:left" class="formLabel"> <egui:intnl text="reporter.common.Start Date" /></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"><egui:intnl text="reporter.common.End Date" /></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>
<%
	Map resultMap = (Map)session.getAttribute("SESSION_USAGE_RESULT_MAP");
	if(resultMap!=null)
	{
		Boolean boolObj = (Boolean)resultMap.get("isData");
		boolean isData = boolObj.booleanValue();
		if(isData)
		{
			String controllerURL = "../servlet/com.eg.ErCtxSessionUsageReportC;jsessionid=" + session.getId()+"?";
			JSONObject overViewDataObj = (JSONObject)resultMap.get("overViewJson");
			JSONObject stateDataObj = (JSONObject)resultMap.get("stateDataObj");
			JSONObject overViewPieLegend = (JSONObject)resultMap.get("statusJson");
			String overChartURL = controllerURL + "dataKey=statusJson&width=100&height=100&optionType=print";
			
			String poolSessTitleTitle = reportInfo.getValue("CITRIX_SESSION_USAGE_REPORT","deliverySessTitle");
			String poolStateChartURL = controllerURL + "dataKey=deliveryGrpSessChart&width=440&height=260&optionType=print";

			String poolUsesTitleTitle = reportInfo.getValue("CITRIX_SESSION_USAGE_REPORT","deliveryUserTitle");
			String poolSessUserChartURL = controllerURL + "dataKey=deliveryGrpUserChart&width=440&height=260&optionType=print";

			String stateTrendTitle = reportInfo.getValue("CITRIX_SESSION_USAGE_REPORT","stateTrendTitle");
			String stateTrendChartURL = controllerURL + "dataKey=stateTrendChart&width=900&height=300&optionType=print";			
			%>
			<table width="100%"  height="100%" border="0" cellspacing="0">
				
				<tr><td colspan="2">
					<div class="printOuterBox">
					<div class="printOuterBoxHeader">Overview</div>
						<table width = "100%" >
							<tr>
								<td width="18%">
									<table  width="100%" align="center" cellspacing="0" cellpadding="0" border="0" style="align:center;margin:auto auto;">
										<tr><td colspan="1" rowspan="1">
										<table align="center">
											<tr>
												<td align="right"><div class="iconTotalSessions"></div></td>
												<td class="newFont_bold28"><%=overViewDataObj.get("totalSession")%></td>				
											</tr>
											<tr style="text-align: center;">
												<td colspan="2" rowspan="2" class="newFont_normal13">Total Sessions</td>
											</tr>	
										</table></td></tr>											
									</table>
								</td>
								<td width="18%">
									<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
										<tr><td colspan="1" rowspan="1">
										<table align="center" style="align:center;margin:auto auto;">
											<tr>
												<td align="right"><div class="iconUniquePools"></div></td>
												<td class="newFont_bold28"><%=overViewDataObj.get("uniquePool")%></td>				
											</tr>
											<tr style="text-align: center;">
												<!--<td colspan="2" rowspan="2" class="newFont_normal13">Unique Pools</td> -->
												<td colspan="2" rowspan="2" class="newFont_normal13">Unique Delivery Groups</td>
											</tr>
										</table></td></tr>											
									</table>
								</td>
								<td width="18%">
									<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
										<tr><td colspan="1" rowspan="1">
										<table align="center" style="align:center;margin:auto auto;">
											<tr>
												<td align="right"><div class="iconUniqueUsers"></div></td>
												<td class="newFont_bold28"><%=overViewDataObj.get("uniqueUser")%></td>				
											</tr>
											<tr style="text-align: center;">
												<td colspan="2" rowspan="2" class="newFont_normal13">Unique Users</td>
											</tr>
										</table></td></tr>											
									</table>
								</td>
								<td width="23%">
									<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
										<tr><td colspan="1" rowspan="1">
										<table align="center" style="align:center;margin:auto auto;">
											<tr>
												<td align="right"><div class="iconDuration"></div></td>
												<td class="newFont_bold28"><%=overViewDataObj.get("maxDuration")%></td>				
											</tr>
											<tr style="text-align: center;">
												<td colspan="2" rowspan="2" class="newFont_normal13">Max Duration</td>
											</tr>
										</table></td></tr>											
									</table>
								</td>
								<td width="23%">
									<table width="100%" align="center" cellspacing="0" cellpadding="0" border="0">
										<tr><td colspan="1" rowspan="1">
										<table align="center" style="align:center;margin:auto auto;">
											<tr>
												<td align="right"><div class="iconDuration"></div></td>
												<td class="newFont_bold28"><%=overViewDataObj.get("avgDuration")%></td>				
											</tr>
											<tr style="text-align: center;">
												<td colspan="2" rowspan="2" class="newFont_normal13">Avg Duration</td>
											</tr>
										</table></td></tr>											
									</table>
								</td>	
							</tr>								
						</table>
					</div>
				</td></tr>					
				<tr>									
					<td width="50%">						
						<div class="printOuterBox">
							<div class="printOuterBoxHeader"><%=poolSessTitleTitle%></div>
							<div>
								<img src="<%=poolStateChartURL%>"/>
							</div>
						</div>
					</td>
					<td width="50%" align="center">
						<div class="printOuterBox">
							<div class="printOuterBoxHeader"><%=poolUsesTitleTitle%></div>
							<div>
								<img src="<%=poolSessUserChartURL%>"/>
							</div>
						</div>
					</td>					
				</tr>
				<tr>
					<td colspan="2">
						<div class="printOuterBox">
						<div class="printOuterBoxHeader"><%=stateTrendTitle%></div>
							<img src="<%=stateTrendChartURL%>"/>
						</div>
					</td>
				</tr>					
				
			
			<tr class="newimg">
			<td colspan="2">
			<div class="printOuterBox">			
			<div class="printOuterBoxHeader"><egui:intnl text="reporter.common.Session Details "/></div>
			<div class="newTable">
			<table width="100%">
				<thead>
				<tr>
			<%
				List gridColList = (List)resultMap.get("gridColumn");
				for(int i=1;i<gridColList.size();i++)
				{
					String gridCol = (String)gridColList.get(i);										
				%>
					<th><%=gridCol%></th>
				<%					
				}				
			%>
				</tr>
				</thead>
				<tbody>
			<%
			Map dataMap = (Map)resultMap.get("dataMap");
			List dbColList = (List)resultMap.get("DBColumn");
			dbColList.remove("info");		
			Map subDataMap = (Map)resultMap.get("subDataMap");
			List subGridColList = (List)resultMap.get("subGridColumn");
			
			
			String firstCol = (String)dbColList.get(0);
			List firstList = (List)dataMap.get(firstCol);
			List userList = (List)dataMap.get("User_name");
								
			String s = null;
			String uName = null;
			String userDateFormat = userName.getUserDateFormat();
			List msmtTimeList = (List)dataMap.get("MSMT_TIME");
			List startTimeList = (List)dataMap.get("START_TIME");
			List logonList = null;
			if(dbColList.contains("Login_duration"))
			{
				logonList = (List)dataMap.get("Login_duration");
			}
			else
			{
				logonList = (List)dataMap.get("SESSION_START");
			}

			
			for(int i=0;i<firstList.size();i++)
			{
			%>
				<tr>
			<%
				for(int j=0;j<dbColList.size();j++)
				{
					String colKey = (String)dbColList.get(j);
					String gridCol = (String)gridColList.get(j);
					s = (String)((List)dataMap.get(colKey)).get(i);					
					if(colKey.equalsIgnoreCase("MSMT_TIME"))
					{							
						String logonVal = (String)logonList.get(i);
						if(logonVal.indexOf("-")<0)
						{
							String date = s.substring(0, s.indexOf(" "));
							String time = s.substring(s.indexOf(" "));																
							date = 	DateUtil.changeDateFormat(date,"yyyy-MM-dd",userDateFormat);
							timeZoneConverterStart = new EgTimeZoneConverter(date+time, userName);
							s = timeZoneConverterStart.getDateTime();								
						}
						else
						{
							s = "<center>-</center>";
						}
					}
					else if(colKey.equalsIgnoreCase("User_name"))
					{
						if(isDomainWithUser.equalsIgnoreCase("no") && s.indexOf("\\")>-1)
						{
							s = s.substring(s.indexOf("\\")+1);
						}
					}
					else if(colKey.equalsIgnoreCase("START_TIME")&& false)
					{
						String date = s.substring(0, s.indexOf(" "));
						String time = s.substring(s.indexOf(" "));																
						date = 	DateUtil.changeDateFormat(date,"dd/MM/yyyy", userDateFormat);
						timeZoneConverterStart = new EgTimeZoneConverter(date+time, userName);
						s = timeZoneConverterStart.getDateTime();
					}
					else if(colKey.equalsIgnoreCase("Logon_duration") || colKey.equalsIgnoreCase("Login_duration"))
					{
						s = "<center>"+s+"<center>";
					}
					if(!colKey.equalsIgnoreCase("Session_Key"))
					{
					%>
						<td><div style="width: 60px; word-wrap: break-word; overflow-x:auto;"><%=s%></div></td>
					<%	
					}
				}
				%>
					</tr>
				<%
			}
			%>
			</tbody>
			</table>
			</div>
			</div>
			</td>
			</tr>
			</table>
			<%
		}
		else
		{
		%>
		<div class="printOuterBox" style="padding:10px 0px 0px 0px;">
			<div class="printOuterBoxHeader"><egui:intnl text="reporter.common.Session Usage Details"/></div>
			<table width="100%">
				<tr>
					<td align="center"><img src='/final/images/Light/nomeasures_custom.png' /></td>
				</tr>
			</table>
		</div>
		<%
		}

	}
%>

</body>
</html>
<%
//

	
//
} catch(Exception e) {
	e.printStackTrace();
}
%>
<%!
	private List getIniDataList(String data)
	{
		List strList = new ArrayList();
		StringTokenizer keyToken=new StringTokenizer(data,",");
        while(keyToken.hasMoreTokens())
		{
			String s=keyToken.nextToken();
			strList.add(s);
		}
		return strList;
	}
%>
