<!DOCTYPE html>
<%@ include file = "ErTracker.jsp" %>
<%@ page import = "com.eg.EgReportInfo" %>
<%@ page import = "egurkha.reporter.ErUtils" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%
		ErUtils erUtils = new ErUtils();
		Map ParamMap = request.getParameterMap();
		EgReportInfo reportInfo = new EgReportInfo("manager");
		HashMap tmp_map = new HashMap();
		String er_applicationVal=(String) request.getParameter("er_application");
		String er_guestname=(String) request.getParameter("er_guestname");
		String client_Version=(String) request.getParameter("client_Version");
		String usrName=(String) request.getParameter("user_name");
		boolean wildcardSearch=false;
		boolean needDesktopSearch=false;
		//if(usrName != null && usrName.contains("|slash|"))
		//	usrName=com.egurkha.util.StringUtils.replace(usrName,"|slash|", "\\");
		boolean clientVersnFiltr=false;
		if(client_Version != null)
			clientVersnFiltr=true;
		String showLegend  =request.getParameter("showLegend");
		if(showLegend == null){
			String enableShowLegend=reportInfo.getValue("MISC","enableShowLegend");
			if(enableShowLegend != null && enableShowLegend.equalsIgnoreCase("true")){
				showLegend="true";
			}
		}
		String wildcardSearchStr=reportInfo.getValue("CITRIX_USER_REPORT","wildcardSearch");
		String needDesktopSearchStr=reportInfo.getValue("CITRIX_USER_REPORT","needDesktopSearch");
		if(er_guestname!=null || (needDesktopSearchStr!=null && needDesktopSearchStr.equalsIgnoreCase("yes")))
		{
			needDesktopSearch = true;
		}
		if(wildcardSearchStr != null && wildcardSearchStr.length()>0 && (request.getParameter("er_trgttype")!=null && request.getParameter("er_trgttype").equalsIgnoreCase("User Session Report") || client_Version != null))
		{
			wildcardSearch=true;
		}
		String favorite_id=(String) request.getParameter("FavoriteId");
		String schedule_id=(String) request.getParameter("schedule_id");
		if(er_applicationVal!=null)
			er_applicationVal = com.eg.EgURLEncoder.encode(er_applicationVal, "UTF-8");
		if((ParamMap.get("fromOverviewReport") != null || ParamMap.get("ComingfromOverview") != null)&& (ParamMap.get("er_workgroupserver") != null || ParamMap.get("er_componentserver") != null) && ParamMap.get("needCompInSession") != null)
		{
			Map paramMap1 = new HashMap(ParamMap);
			Object needCompInSession=paramMap1.get("needCompInSession");
			String needCompInSessionStr="";
			if(needCompInSession instanceof String[])
			{
				String[] needCompArry=(String[])needCompInSession;
				needCompInSessionStr=needCompArry[0];
			}
			else
			{
				needCompInSessionStr=(String)needCompInSession;
			}
			if(needCompInSessionStr.equalsIgnoreCase("yes"))
			{
				String[] er_Component=(String[])session.getAttribute("er_componentXenApp");
				if(paramMap1.get("er_workgroupserver") != null)
					paramMap1.put("er_workgroupserver",er_Component);
				if(paramMap1.get("er_server") != null)
					paramMap1.put("er_server",er_Component);
				if(paramMap1.get("er_componentserver") != null)
					paramMap1.put("er_componentserver",er_Component);
				if(paramMap1.get("select_server1") != null)
					paramMap1.put("select_server1",er_Component);
			}
			ParamMap=paramMap1;
		}
		if(ParamMap.get("builderLink") != null)//for receiver usage report
		{
			Map paramMap1=new HashMap(ParamMap);
			String builderLinkStr="false";
			Object builderLink=paramMap1.get("builderLink");
			if(builderLink instanceof String[])
			{
				String[] allComp=(String[])builderLink;
				builderLinkStr=allComp[0];
			}
			else if(builderLink instanceof String)
			{
				builderLinkStr=(String)builderLink;		
			}
			if(builderLinkStr.equalsIgnoreCase("true"))
			{
				String[] er_Component=(String[])session.getAttribute("builderSelectedComponents");
				if(paramMap1.get("er_componentserver") != null)
				{
					paramMap1.put("er_componentserver",er_Component);
				}
				if(paramMap1.get("select_server1") != null)
				{
					paramMap1.put("select_server1",er_Component);
				}
			}
			ParamMap=paramMap1;
		}
		//..
		if(ParamMap!=null && ParamMap.size()>0){			
			Iterator itr = ParamMap.keySet().iterator();
			while(itr.hasNext()){
				String map_key = (String)itr.next();
				String map_value ="";
				
					Object obj_val = ParamMap.get(map_key);
					if(obj_val instanceof String[]){
						String val_arr[] = (String[])ParamMap.get(map_key);
						String tempArr[]=new String[val_arr.length];
						for(int k=0;k<val_arr.length;k++)
						{
							map_value = val_arr[k];
							if((map_key!=null && map_key.equalsIgnoreCase("er_user")) || 
							(map_key!=null && map_key.equalsIgnoreCase("er_application"))||(map_key!=null && map_key.equalsIgnoreCase("er_aduser"))||(map_key!=null && map_key.equalsIgnoreCase("er_adGroup")))
							{
							//map_value=com.egurkha.util.StringUtils.replace(map_value,"\\", "\\\\");
//								if((map_key!=null && map_key.equalsIgnoreCase("er_user")) || map_key.equalsIgnoreCase("er_application"))
//								{
									if(map_value!=null && !map_value.equals("-1"))
									{
										map_value = erUtils.specialCharEncode(map_value);
									}
//								}
							}
							else if(map_key.equalsIgnoreCase("user_name"))
							{
								if(map_value!=null && map_value.indexOf("|slash|")>-1)
								{
									//map_value=com.egurkha.util.StringUtils.replace(map_value,"|slash|", "\\");
									map_value = com.eg.EgURLEncoder.encode(map_value, "UTF-8");
								}
							} 
								tempArr[k]=map_value;
						}
						tmp_map.put(map_key,tempArr);
					}
					else
					{
						map_value = (String)ParamMap.get(map_key);

						if((map_key!=null && map_key.equalsIgnoreCase("er_user")) || 
						(map_key!=null && map_key.equalsIgnoreCase("er_application"))||(map_key!=null && map_key.equalsIgnoreCase("er_aduser"))||(map_key!=null && map_key.equalsIgnoreCase("er_adGroup")) || (map_key!=null && map_key.equalsIgnoreCase("er_tuser")) ) {
							//Extra Param (er_tuser) is added to this condition to resolve encoding issue in favorite/Schedule Options(Please check this scenario(slash In descriptor) before removing er_tuser Value)
							map_value = com.eg.EgURLEncoder.encode(map_value, "UTF-8");
							//map_value=com.egurkha.util.StringUtils.replace(map_value,"\\","\\\\");
//							if((map_key!=null && map_key.equalsIgnoreCase("er_user")) || map_key.equalsIgnoreCase("er_application"))
//							{
//								map_value = erUtils.specialCharEncode(map_value);
//							}
						}
						tmp_map.put(map_key,map_value);
					}
			}
		}
		session.removeAttribute("USER_SESSION_DETAILS_POD");
		String showFrom=request.getParameter("showFrom");
		if(showFrom==null)
		{
			showFrom = reportInfo.getValue("CITRIX_USER_REPORT","showFrom");
		}
		if(showFrom==null || showFrom.length()==0)
		{
			showFrom = "Outside view";
		}
		String queryStringForNewUI =(String)ErUtils.prepareQueryString(tmp_map);
		String getBackQuery=request.getParameter("getBckQuery");
		String usrBckQuery="";
		if(getBackQuery != null && getBackQuery.equalsIgnoreCase("yes")){
			usrBckQuery=(String)session.getAttribute("userDetailsBckQuery");
		}
		String isSubmit = request.getParameter("isSubmit"); 
		boolean fromOverviewReport=false;
		String er_durationValue = request.getParameter("er_duration");
		String er_duration = request.getParameter("fromOverviewReport");
		if(er_duration != null && er_duration.equalsIgnoreCase("true"))
			fromOverviewReport=true;
		String fromScheduleView = request.getParameter("fromScheduleView");
		if(fromScheduleView!=null && fromScheduleView.equals("Yes")){
			isSubmit="true";
		}
		String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
		String servicesFile = "eg_services.ini";
		com.eg.IniFile servicesInfo = new com.eg.IniFile(s_iniFile_dir + servicesFile);
		String discoverUsersforADXenUserReport = servicesInfo.getValue("AD_XENUSER_REPORT","DiscoverUsersforADXenUserReport");
		if(request.getParameter("er_trgttype")!=null && request.getParameter("er_trgttype").equalsIgnoreCase("User Activity Report"))
		{
			session.setAttribute("Source","Activity");
		}
		else if(request.getParameter("er_trgttype")!=null && request.getParameter("er_trgttype").equalsIgnoreCase("User Session Report"))
		{
			session.setAttribute("Source","User Session Report");
		}
		else if(request.getParameter("er_trgttype")!=null && request.getParameter("er_trgttype").equalsIgnoreCase("User Channel Report"))
		{
			session.setAttribute("Source","User Channel Report");
		}
		else
			session.setAttribute("Source","");

		out.println("<div id=\"loadmask\" class=\"x-mask-msg x-layer x-mask-msg-default\" style=\"z-index: 19001;left:45%;top:35%;\"><div class=\"x-mask-loading\" style=\"position:relative\">Loading ...</div></div> ");
%>
<head>
<title><egui:intnl text="reporter.Operation.Reporter"/></title>
<meta charset="utf-8">
<egui:skin ui="reporter"/>
<link rel="stylesheet" href="/final/styles/jscrollpane/jquery.jscrollpane.css"/>
<script src="/final/jquery/jquery.js"></script>
<script src="/final/styles/jscrollpane/jquery.jscrollpane.js" ></script>
<script src="/final/styles/jscrollpane/jquery.mousewheel.js" ></script>
<script src="/final/styles/jscrollpane/mwheelIntent.js" ></script>
<script src="/final/reporter/scripts/eg_DateUtil.js"></script>
<script src="/final/reporter/scripts/er_validator.js"></script>
<script src="../scripts/<%=script_src%>"></script>
<script type="text/javascript" src="/final/Highcharts/js/highstock.js"></script>
<script type="text/javascript" src="/final/Highcharts/js/modules/exporting.js"></script>
<script src="../reporter/scripts/ErHighChart.js"></script>
<script src="../scripts/utilities/ResizePopup.js"></script>
<script src="../reporter/scripts/ErHighChartBar.js"></script>
<style>

.x-grid-row .custom-column { 
   	background-color: #d3d3d3 !important; 
}
</style>
<script >
	var mgrDateFormat=getExtjsDateFormat('<%=mgrDateFormat%>');
	var hideBackButton=true;
	var drillDownBackButton=true;
	var userDetailsBackButton=true;
	if('<%=request.getParameter("enableBack")%>' == 'true')
		hideBackButton=false;
	var targetType='<%=request.getParameter("er_trgttype")%>';
	var forwardTo='<%=request.getParameter("forwardTo")%>';
	if(targetType == 'User Report'){
		if(forwardTo!=null && forwardTo=='ErCtxUserReportJson'){
			targetType = 'User Session Report' ;
		}else if(forwardTo!=null && forwardTo=='ErCtxUserActivityReportJson'){
				targetType = 'User Activity Report';
		}
	}
	if('<%=request.getParameter("er_RmDispName")%>' == 'Users - Channel Resource'){
		targetType = 'User Channel Report' ;
	}

</script>
<egui:loadApp baseDir="/final/reporter/scripts" appName="ThinclientUserApp" appFile="app.js"/>
<script>
	var appConstants=new Object();
	var isVm = false;
	var needDesktopSearch = <%=needDesktopSearch%>;
	var wildcardSearch=<%=wildcardSearch%>;
	appConstants.chartType='<%=BarAndPieChartType%>';;
	appConstants.appObj;
	appConstants.appController;	  
	appConstants.formButtonId;
	appConstants.report_for;
	appConstants.publicjsonDataActivity;
	appConstants.publicjsonDataUsage;
	appConstants.rawDataForComponents;
	appConstants.queryStringActivity="";
	appConstants.queryStringActivityForUserDetails="<%=usrBckQuery%>";
	appConstants.queryStringUsage="";
	appConstants.isAdDiscoverEnabled="flase";
	appConstants.isAllUserSelected="flase";
	appConstants.er_application='<%=er_applicationVal%>';
	appConstants.favorite_id='<%=favorite_id%>';
	appConstants.schedule_id='<%=schedule_id%>';
	if('<%=discoverUsersforADXenUserReport%>' == 'yes' || '<%=discoverUsersforADXenUserReport%>' == 'Yes')
		appConstants.isAdDiscoverEnabled="true";
		
	if('<%=er_applicationVal%>' == '-- All --')
		appConstants.isAllUserSelected="true";
	appConstants.mgrDateFormForUI = '<%=mgrDateFormat%>';
	appConstants.QueryStringFromURL= "<%=queryStringForNewUI%>";
	appConstants.isSubmit='<%=isSubmit%>';

	appConstants.frmSch='<%=request.getParameter("fromSchedule")%>';
	if(appConstants.frmSch ==null || appConstants.frmSch=="null" || appConstants.frmSch=="" )
		appConstants.frmSch='<%=fromScheduleView%>';
	appConstants.reqFrmSch='<%=request.getParameter("fromScheduleModify")%>';
	appConstants.forwardTo='<%=request.getParameter("forwardto")%>';
	appConstants.executeFavorite='<%=request.getParameter("executeFavorite")%>';
	appConstants.isLegendEnabled='<%=request.getParameter("isLegendEnabled")%>';
	appConstants.rmTimeline='<%=request.getParameter("rmTimeline")%>';
	appConstants.rmTimelineHrFrom='<%=request.getParameter("rmTimelineHrFrom")%>';
	appConstants.rmTimelineHRTO='<%=request.getParameter("rmTimelineHRTO")%>';
	appConstants.rmTimelineMinFrom='<%=request.getParameter("rmTimelineMinFrom")%>';
	appConstants.rmTimelineMinTo='<%=request.getParameter("rmTimelineMinTo")%>';
	appConstants.rmTimelineStartDate='<%=request.getParameter("rmTimelineStartDate")%>';
	appConstants.rmTimelineEndDate='<%=request.getParameter("rmTimelineEndDate")%>';
	appConstants.rmComponent='<%=request.getParameter("rmComponent")%>';
	appConstants.rmComponentType='<%=request.getParameter("rmComponentType")%>';
	appConstants.rm_treeTest='<%=request.getParameter("treeTest")%>';
	appConstants.rm_treeMeasure='<%=request.getParameter("treeMeasure")%>';
	appConstants.isForceSubmit='<%=request.getParameter("isForceSubmit")%>';
	appConstants.er_RmDispName='<%=request.getParameter("er_RmDispName")%>';
	appConstants.isLegendEnabled='<%=request.getParameter("isLegendEnabled")%>';
	appConstants.menuForVM='<%=request.getParameter("menuForVM")%>';
	appConstants.FilterbyclientVersn='<%=clientVersnFiltr%>';
	appConstants.client_Version='<%=client_Version%>';
//	appConstants.QueryStringFromURL='<%=ErUtils.prepareQueryString(request.getParameterMap())%>';
	appConstants.forGrdReportConfirmMsg  = '<egui:intnl text="reporter.common.Foreground report generation will take some time Do you want to proceed"/>'+'?';

		//
	appConstants.us_er_comptype='<%=request.getParameter("er_comptype")%>';
	appConstants.us_select_farm='<%=request.getParameter("select_farm")%>';
	appConstants.us_er_timeline='<%=request.getParameter("er_timeline")%>';
	appConstants.us_user_name='<%=usrName%>';
	//appConstants.us_user_name='<%=request.getParameter("user_name")%>';
	appConstants.us_showFrom='<%=showFrom%>';
	appConstants.isFromDrillDown='<%=request.getParameter("isFromDrillDown")%>';
	appConstants.select_testmes='<%=request.getParameter("select_testmes")%>';
	appConstants.isshowLegend='<%=showLegend%>';
	appConstants.us_er_test='<%=request.getParameter("er_test")%>';
	appConstants.fromOverviewReport='<%=fromOverviewReport%>';
	appConstants.er_durationValue='<%=er_durationValue%>';
	if(appConstants.isFromDrillDown!=null && appConstants.isFromDrillDown!='null'&& appConstants.isFromDrillDown!=undefined && appConstants.isFromDrillDown!='undefined' && appConstants.isFromDrillDown)
	{
	 drillDownBackButton=false;
	}
	if('<%=request.getParameter("enableBackForUserDetails")%>' == 'true')
	{
		userDetailsBackButton=false;
	}

	//
	var showDetailsTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Show Details")%>';
	var showClientDetailsTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Show Client Details")%>';
	var showResourceDetailsTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Show Resource Details")%>';
	var desktopSearchTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Desktop Search")%>';
	var resourceDetailsFromTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Resource Details from")%>';
	var ADgroupTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.AD Group")%>';
	var ADuserTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.AD Users")%>';
	var basedOnCriteriaTxt = '<%=trackerMappingInfo.getTextDescription("reporter.common.Based On Criteria")%>';

	var	initLdgMask = new Ext.LoadMask(Ext.getBody(),{msg : "Loading ..."});
	var chartList = new Array();

Highcharts.setOptions({
global: {
	useUTC: false
}
});

function openInNewWin(urlQStr) {
	/*var QString = PieDrillDownURLs[urlQStr];
	if(QString == undefined || QString== '')
		QString=urlQStr;*/
	urlQStr +="&er_RmDispName="+appConstants.er_RmDispName;
	if (appConstants.menuForVM=='true')
	{
		maximizeDataWindowLightBox(urlQStr,'REPORTER DATA');//this method is defined in ErReporterMenuDashBoard.jsp for loading drilldown app
	}
	else
	{
	parent.maximizeDataWindowLightBox(urlQStr,'REPORTER DATA');//this method is defined in ErReporterMenuDashBoard.jsp for loading drilldown app
	}
}
function linkURL(urlKey){
	var QString = BarDrillDownURLs[urlKey];
	document.location=QString;
}
function openDDWin(qryString)
{
	ddwin = window.open(qryString,"<%=session.getId()%>DDWindow","width=1012,height=603,left=0,top=105,scrollbars=1,scrollbars=yes,resizable");
	ddwin.focus()
}
function  openDDWindow(qryString)
{ 
	ddwin = window.open(qryString,"<%=session.getId()%>DDWindow","width=1012,height=603,left=0,top=105,scrollbars=1,scrollbars=yes,resizable");
	ddwin.focus()
}
function loadUrlInDrillDown(urlQStr)
{
	if (appConstants.menuForVM=='true')
	{
		maximizeWindowLightBox(urlQStr);
	}
	else
	{
		 parent.maximizeWindowLightBox(urlQStr);//this method is defined in ErReporterMenuDashBoard.jsp for loading drilldown app
	}
}
function reportHighStockChart(url,divId,width,height,drilldownURL)
{
	Ext.onReady(function() 
	{
	var containerId = divId;
	var chartContObj=Ext.get(containerId);
	var myhtml = '<center><img src="/final/images/nomeasures_custom.png" height="100%" width="100%" /></center>';
	if(!Ext.isEmpty(url))
	{
			Ext.Ajax.request(
			{
				url : url,
				scope:this,
				success: function(response){
					var chartData=Ext.decode(response.responseText);

					try
					{
						//createChangeChart(toolTipDateTimeFormat,seriesOptions,containerId,axisTitle,width,height,xmax,xmin,ymax,yaxisTitle);
						var lineChart = {
						};
						lineChart = jQuery.extend(true, {}, getHighChartsInstance(containerId,height,width), lineChart);
						lineChart.setData(chartData,'<%=mgrDateFormat%>',drilldownURL);
						lineChart.drawChart();
					}
					catch (e)
					{
						alert("e::"+e)
					}
				}
			});			
		}
		else
		{
				chartContObj.update(myhtml);
		}
	});
}

function loadCSVWindow(data)
{		
	window.location = data;
}
function loadDataWindow(data)
{	
	if (appConstants.menuForVM=='true')
	{
		maximizeDataWindowLightBox(data,'REPORTER DATA');
	}
	else
	{
	parent.maximizeDataWindowLightBox(data,'REPORTER DATA');//this method is defined in ErReporterMenuDashBoard.jsp for loading drilldown app
	}
}
function matchIgnoreCase(strTerm, strToSearch) 
{ 
	strToSearch = strToSearch.toLowerCase(); 
	strTerm = strTerm.toLowerCase(); 
	if(strToSearch==strTerm) 
	{ 
		return true; 
	} else { 
		return false; 
	} 
}
function loadUsersSessionView(index)
{
	if (appConstants.menuForVM=='true')
	{
		 maximizePlainWindowNewLightBox('/final/reporter/ErSessionAppView.jsp?index='+index,'Session View of User');
	 }
	else
	{
		 parent.maximizePlainWindowNewLightBoxWithFullsize('/final/reporter/ErSessionAppView.jsp?index='+index,'Session View of User');
	}
}
	Ext.onReady(function(){
		Ext.Ajax.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.Connection.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
		Ext.data.ScriptTagProxy.prototype.extraParams = {"com.eg.CSRF_NONCE" : csrfToken};
	});
</script>
</head>
</html>