<!DOCTYPE html>

<%
/************************************************************************************************
*	File			:	ErNetScalerUserReportPrint.jsp
*	Version			:	6.3
*	Author			:	Vengatesan R
*	Creation Date	:	15-09-2017
*
*************************************************************************************************/
%>


<%@ 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="net.sf.json.*" %>
<%@ page import="com.egurkha.User"%>
<%@ page import="com.egurkha.util.DateTimeTokenizer"%>
<%@ 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"%>

<%@ 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 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 needDetailsTable = request.getParameter("needDetailsTable");
	String er_componentType=request.getParameter("er_compType");
	EgReportInfo reportInfo=new EgReportInfo("manager");
	if(needDetailsTable==null || needDetailsTable.length()==0)
	{
		needDetailsTable = reportInfo.getValue("NETSCALER_USERS","needDetailsTable");
	}
	if(needDetailsTable==null || needDetailsTable.length()==0)
	{
		needDetailsTable = "yes";
	}
	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 er_info = request.getParameter("er_info");
	String s_user[] = request.getParameterValues("er_user");
	String user_selected = "";
	String er_componentStr = "";
	if(s_user!=null && s_user.length>0)
	{
		user_selected = s_user[0];
		if(user_selected.equalsIgnoreCase("all"))
		{
			user_selected = intlmap.getTextDescription("reporter.common.All Users");
		}
	}
	if(er_info!=null && er_info.equalsIgnoreCase("all"))
	{
		er_info = intlmap.getTextDescription("reporter.common.All");
	}
	if(er_component!=null && er_component.length==1)
	{
		er_componentStr = er_component[0];
	}
	String headerKeyName="";
	if(er_option!=null && er_option.equalsIgnoreCase("Segment"))
	{
		headerKeyName=intlmap.getTextDescription("reporter.common."+er_option)+" : "+er_site;
	}
	else if(er_option!=null && er_option.equalsIgnoreCase("Service"))
	{
		headerKeyName=intlmap.getTextDescription("reporter.common."+er_option)+" : "+er_site;
	}
	else if(er_option!=null && er_option.equalsIgnoreCase("Component"))
	{
		headerKeyName=intlmap.getTextDescription("reporter.common."+er_option);
	}
	else
	{
		String select_farm = request.getParameter("select_farm");
		if(select_farm!=null && select_farm.equalsIgnoreCase("--Default--"))
		{
			select_farm = intlmap.getTextDescription("reporter.common."+select_farm);
		}
		headerKeyName=intlmap.getTextDescription("reporter.common.Zone")+" : "+select_farm;
	}

	try 
	{
		//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");
		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 list_data = 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/reporter/styles/printpagestyle.css" />
<link rel="stylesheet" type="text/css" href="/final/styles/eGLightThemeIcons.css" />
<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>
<style>

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

</style>


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

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

<%
	String strLogCls = "printHeaderBoxLogo";
	if(pdfPrint !=null && pdfPrint.equalsIgnoreCase("yes"))
	{
		strLogCls = "printHeaderBoxLogo";
	}else
		strLogCls = "printPdfHeaderBoxLogo";
%>
	<div class="<%=strLogCls%>" style="padding-top:10px"><img src="<%=imageName%>" border="0" /></div>
	<div class="printHeaderBox">
<%
	if (!StringUtils.isNull(titleToDisplay))
	{
%>
		<div class="printHeaderBoxTitle"><%=titleToDisplay%> &nbsp;<egui:intnl text="reporter.common.for" /> &nbsp;<%=headerKeyName%>&nbsp;</div>
<%
	}
	else
	{
%>
		<div class="printHeaderBoxTitle"><egui:intnl text="reporter.common.Netscaler User" /> -&nbsp;<%=headerKeyName%>&nbsp;</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>
<%
	}
%>
	</div>
	<div class="printOuterBoxNoBorder"> 
		<div class="printSelectionFields"><%= intlmap.getTextDescription("reporter.thin.Component Type") %> - <span class="bold"><%= intlmap.getComponentTypeDescription(s_comptype) %></span></div>
		
		<div class="printSelectionFields"><%= intlmap.getTextDescription("reporter.thin.Connection Type") %> - <span class="bold"><%= er_info %></span></div>

<%
	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.NetScaler Users")+" "+intlmap.getTextDescription("reporter.common.for")+" "+headerKeyName);
	lst.add(intlmap.getTextDescription("reporter.thin.Component Type")+" : "+intlmap.getComponentTypeDescription(s_comptype));

		String Days = reportInfo.getExcludeWeekend("NETSCALER_USERS");
		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+ " "+intlmap.getTextDescription("reporter.common.hrs");
	String etimefmt =	pdfEndDate+ " "+intlmap.getTextDescription("reporter.common.hrs");


	String ssd=intlmap.getTextDescription("reporter.common.Start Date")+" : "+stimefmt+"  "+intlmap.getTextDescription("reporter.common.End Date")+" : "+etimefmt;
	lst.add('"'+ssd+'"');
	lst.add(er_info);

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

List resultList = (ArrayList)session.getAttribute("NETSCALER_USER_REPORT_RESULT_LIST");
System.out.println("resultList  "+resultList);
List colNameList = (ArrayList)session.getAttribute("NETSCALER_USER_REPORT_COLUMN");
System.out.println("colNameList  "+colNameList);
List summaryList = (ArrayList)session.getAttribute("NETSCALER_USER_REPORT_SUMMARY");
System.out.println("colNameList  "+summaryList);
String eruserid = request.getParameter("eruserid");
if(eruserid==null)
{
	eruserid = request.getParameter("uid");
}
if(eruserid==null)
{
	eruserid = request.getParameter("userID");
}
if(eruserid==null)
{
	eruserid = request.getParameter("er_userid");
}
if(eruserid!=null)
{
	eruserid = EgURLEncoder.encode(eruserid,"UTF-8");
}

JSONObject netScalerObj=new JSONObject();
if(resultList!=null && resultList.size()>0)
{

	JSONObject publicGridData = new JSONObject();
	
	try
	{
		if(summaryList!=null && summaryList.size()>0)
		{
			lst.add(" ");
			Vector v_measure_csv_summary = new Vector();
			v_measure_csv_summary.add("");
			v_measure_csv_summary.add(intlmap.getTextDescription("reporter.common.Connection Type"));
			v_measure_csv_summary.add(intlmap.getTextDescription("reporter.common.Completed Sessions"));
			v_measure_csv_summary.add(intlmap.getTextDescription("reporter.common.Unique Users"));
			List list_data_summary = new LinkedList();
			

			JSONArray summaryInfo = new JSONArray();
			for(int i=0; i<summaryList.size();i++)
			{
				JSONArray summaryRow = new JSONArray();
				ArrayList summaryData = (ArrayList)summaryList.get(i);
				list_data_summary.add("");
				for(int j=0; j<summaryData.size();j++)
				{
					String eachDbData = (String)summaryData.get(j);
					summaryRow.add(eachDbData);
					list_data_summary.add(eachDbData);
				}
				summaryInfo.add(summaryRow);
			}
			String s_title_summary= intlmap.getTextDescription("reporter.common.Summary");
			Hashtable sen1 = new Hashtable();
			Hashtable ht1=new Hashtable();
			sen1.put(v_measure_csv_summary,list_data_summary);
			ht1.put(s_title_summary,sen1);
			lst.add(ht1);

			publicGridData.put("summaryInfo",summaryInfo);

		}
		JSONArray gridColumn = new JSONArray();
		JSONArray gridColumnUI = new JSONArray();
		JSONArray gridData = new JSONArray();
		for(int i=0; i<colNameList.size();i++)
		{
			String columnName = (String)colNameList.get(i);
			gridColumn.add(columnName);
			gridColumnUI.add(intlmap.getTextDescription("reporter.common."+columnName));
			if(columnName!=null && columnName.indexOf("<br/>")>-1)
				columnName = columnName.replace("<br/>","");
			v_measure_csv.add(intlmap.getTextDescription("reporter.common."+columnName));
		}
		for(int i=0; i<resultList.size();i++)
		{
			JSONArray gridRow = new JSONArray();
			ArrayList dbData = (ArrayList)resultList.get(i);
			for(int j=0; j<dbData.size();j++)
			{
				String eachDbData = (String)dbData.get(j);
				gridRow.add(eachDbData);
				list_data.add(eachDbData);
			}
			gridData.add(gridRow);
		}
%>
<div class="printOuterBox">
	<div class="printOuterBoxHeader" style="text-align:center"><egui:intnl text="reporter.common.Summary" /></div>
	<div class="newTable">
		<table align="center" valign="middle" width="500px" cellspacing="0" cellpadding="0" border="0">
		<thead>
			<tr>
				<th style="text-align:left;"><egui:intnl text="reporter.common.Connection Type" /></th>
				<th style="text-align:center;"><egui:intnl text="reporter.common.Completed Sessions" /></th>
				<th style="text-align:center;"><egui:intnl text="reporter.common.Unique Users" /></th>
			</tr>
		</thead>
		<tbody>
<%
		JSONArray summaryInfoData = (JSONArray)publicGridData.get("summaryInfo");
		if(summaryInfoData!=null)
		{
			for(int k=0; k<summaryInfoData.size(); k++)
			{
				JSONArray row = (JSONArray)summaryInfoData.get(k);
%>
				<tr>
<%
				for(int data=0; data<row.size();data++)
				{
					String style = "text-align:center;";
					if(data == 0)
						style = "text-align:left;";
					if(summaryInfoData.size()>1 && k==0)
					{
%>
						<td style="<%=style%>font-weight:bold;font-size:12px"><%=row.get(data)%></td>
<%
					}
					else
					{
%>
						<td style="<%=style%>"><%=row.get(data)%></td>
<%
					}
				}
%>
				</tr>
<%
			}
		}
%>
		</tbody>
		</table>

		<br/>
		<div class="printOuterBoxHeader"><egui:intnl text="reporter.common.Distribution of Unique Users" /></div>
		<table align="center" valign="middle" width="100%" cellspacing="0" cellpadding="0" border="0" class="printTable">
			<tbody>
				<tr>
					<td align="center"><img src="/final/servlet/com.eg.ErNetScalerUserReportC;jsessionid=<%=session.getId()%>?command=IMAGE&eruserid=<%=eruserid%>&er_width=700&er_height=330&er_userid=<%=eruserid%>">
					</td>
				</tr>
			</tbody>
		</table>
<%
		if(needDetailsTable!=null && needDetailsTable.equalsIgnoreCase("yes"))
		{
%>
		<div class="printOuterBoxHeader" style="padding-top:10px"><egui:intnl text="reporter.common.Session Details" />&nbsp;<egui:intnl text="reporter.common.for" /> &nbsp;<%=user_selected%></div>
		<table align="center" valign="middle" width="100%" cellspacing="0" cellpadding="0" border="0">
		<thead>
		<tr>
<%
		List alignIndexList = new ArrayList();
		for(int i=0; i<gridColumn.size(); i++)
		{
			String align = "left";
			String colName = (String)gridColumn.get(i);
			String colNameUI = (String)gridColumnUI.get(i);
			if(colName!=null && (colName.indexOf("Port")>-1 || colName.indexOf("Durations")>-1 ))
			{
				align = "center";
				alignIndexList.add(i+"");
			}
%>
			<th style="text-align:<%=align%>;"><%=colNameUI%></th>
<%
		}
%>
		</tr>
		</thead>
		<tbody>
<%
		for(int i=0; i<gridData.size(); i++)
		{
			JSONArray dispDataAry = (JSONArray)gridData.get(i);
%>
				<tr>
<%
			for(int j=0; j<dispDataAry.size(); j++)
			{
				String align = "left";
				if(alignIndexList.contains(j+""))
				{
					align = "center";
				}
%>
			<td  style="text-align:<%=align%>;"><%=dispDataAry.get(j)%></td>
<%
			}
%>
				</tr>
<%
		}
%>
		</tbody>
		</table>
<%
		}
%>
</div>
</div>
<%		
		publicGridData.put("gridColumn",gridColumn);
		publicGridData.put("gridData",gridData);
	}
	catch (Exception e) 
	{
		e.printStackTrace();
	}
	
	Hashtable h_tabrc = new Hashtable();	//SubTable Data
	Hashtable h_tab = new Hashtable();	//SubTitle with SubTable Data
	String s_title = intlmap.getTextDescription("reporter.thin.Session Details")+" "+intlmap.getTextDescription("reporter.thin.All for")+" "+user_selected;

	h_tabrc.put(v_measure_csv,list_data);
	h_tab.put(s_title,h_tabrc);
	lst.add(h_tab);
	if(lst!= null && !lst.isEmpty())
	{
		session.setAttribute("list",lst);
	}
	session.setAttribute("ScheduleCSVData",lst);
}
else
{
	lst.add(intlmap.getTextDescription("reporter.common.No measures available for the current selection"));
	%>

	<table align="center" width="97%" cellspacing="0" cellpadding="4"   border="0">
		<tr>
			<table width='100%' height='100%'><tr>	<td align='center' valign='middle'><img src='/images/Light/nomeasures_custom.png' /></td></tr></table>
		</tr>
	</table>	
<%
}
%>
</body>
</html>
<%
}
catch(Exception e)
{
	e.printStackTrace();
}
%>

<%@ 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);
}
%>
<%!
	// 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;
    }
%>