<%@ include file = "ErTracker.jsp" %>
<%@ page import = "com.eg.EgInstallInfo"%>
<%@ page import = "egurkha.reporter.ErUtils" %>
<%@ page import ="com.eg.EgReportInfo" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>

<%
	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> ");
	EgReportInfo reportinfo = new EgReportInfo("manager");
	String confrimation = reportinfo.getValue("BACKGROUND_PROCESS","NeedConfirmation");
	String unknownState = request.getParameter("unknownState");
	if(unknownState !=null && unknownState.equals("UNKNOWN"))
	{
		session.setAttribute("Source","UnknownAlarmHistory"); // for eg help
	}
	else if(unknownState !=null && unknownState.equals("ACKNOWLEDGEMENT"))
	{
		session.setAttribute("Source","AlarmAcknowledgement"); // for eg help
	}
	else
	{
		session.setAttribute("Source","AlarmHistory"); // for eg help
	}
	Map variableMap = request.getParameterMap();
	String aa="";
	String queryStringForMap="";
	HashMap parameterMap = new HashMap();	
	parameterMap.putAll(variableMap);
	if(parameterMap!=null && parameterMap.size()>0)
	{
		Object reportObj = 	parameterMap.get("er_reportgenration");
		String er_reportgenration = null;
		if(reportObj!=null)
		{
			if(reportObj instanceof String[])
			{
				String [] er_reportgenrationAry = (String[])reportObj;
				er_reportgenration =  er_reportgenrationAry[0];
			}
			else
			{
				er_reportgenration = reportObj.toString();
			}
		}
		if(er_reportgenration!=null && er_reportgenration.equalsIgnoreCase("background"))
		{
			if(parameterMap.get("isSubmit")!=null)
				parameterMap.put("isSubmit","false");
			if(parameterMap.get("isForceSubmit")!=null)
				parameterMap.put("isForceSubmit","false");
			parameterMap.put("er_reportgenration","foreground");

		} 
	}
	//..
	if(parameterMap.get("fromOverviewReport") != null && parameterMap.get("compNameList") != null  && parameterMap.get("needCompInSession") != null)
	{
		HashMap paramMap1 = new HashMap(parameterMap);
		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=null;		
			er_Component=(String[])session.getAttribute("er_componentXenApp");
			if(er_Component != null)
			{
				String[] er_componentTemp=new String[er_Component.length];
				for(int e=0;e<er_Component.length;e++)
				{
					String eachComp=er_Component[e];
					if(eachComp != null && eachComp.indexOf(":") != -1)
					{
						eachComp=eachComp.substring(0,eachComp.lastIndexOf(":"));
					}
					er_componentTemp[e]=eachComp;
				}
				er_Component=er_componentTemp;
			}			
			paramMap1.put("compNameList",er_Component);
		}
		parameterMap=paramMap1;
	}
	//..
	queryStringForMap = ErUtils.prepareQueryString(parameterMap);
%>
<!DOCTYPE html>
	<head>
		<title><egui:intnl text="reporter.Operation.Reporter"/></title>
		<egui:skin ui="reporter"/>
		<meta charset="utf-8">
		<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/utilities/ResizePopup.js"></script>
		<script src="../scripts/<%=script_src%>"></script>
		<script src="/final/Highcharts/js/highcharts.js"></script>
		<script src="/final/Highcharts/js/modules/exporting.js"></script>
		<script src="../reporter/scripts/ErHighChartBar.js"></script>
		<script >
			var mgrDateFormat=getExtjsDateFormat('<%=strUserDateFormat%>');
				var hideBackButton=true;
			if('<%=request.getParameter("enableBack")%>' == 'true')
				hideBackButton=false;
				var appConstants = new Object();
			
		</script>
		<egui:loadApp baseDir="/final/reporter/scripts" appName="OperationAlarmsHistoryApp" appFile="app.js"/>
		<script>
			//--------session based timeline variables-------------------------
			var appConstants = new Object();
			//appConstants.QueryStringFromURL='<%=ErUtils.prepareQueryString(request.getParameterMap())%>'; 
			appConstants.QueryStringFromURL='<%=queryStringForMap%>'; 
			appConstants.confirmationValidation = '<%=confrimation%>'; 
			appConstants.menuForVM='<%=request.getParameter("menuForVM")%>';
			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")%>';//update saved components from reporter settings for the corresponding component type
			appConstants.rmComponentType='<%=request.getParameter("rmComponentType")%>';
			appConstants.isForceSubmit='<%=request.getParameter("isForceSubmit")%>';
			appConstants.er_RmDispName='<%=request.getParameter("er_RmDispName")%>';
			appConstants.rm_treeTest='<%=request.getParameter("treeTest")%>';
			appConstants.rm_treeMeasure='<%=request.getParameter("treeMeasure")%>';
			appConstants.appObj;
			appConstants.appController;	 
			appConstants.queryString="";
			appConstants.globalScreenLabels="";
			appConstants.mgrDateFormForUI = '<%=mgrDateFormat%>';
			appConstants.publicjsonData;
			appConstants.drillDownParams = '';
			//appConstants.QueryStringFromURL='<%=ErUtils.prepareQueryString(request.getParameterMap())%>';//..
			appConstants.isSubmit='<%=request.getParameter("isSubmit")%>';
			appConstants.frmSch='<%=request.getParameter("fromScheduleView")%>';
			appConstants.frmSchModify='<%=request.getParameter("fromScheduleModify")%>';
			appConstants.reportGeneration='<%=request.getParameter("er_reportgenration")%>';
			if((appConstants.frmSch!=null && appConstants.frmSch=="Yes")|| (appConstants.frmSchModify!=null && appConstants.frmSchModify=="Yes"))
				appConstants.isSubmit  = "false";
			if(appConstants.reportGeneration!=null && appConstants.reportGeneration=='background')
			{
				appConstants.isSubmit  = "false";
				appConstants.isForceSubmit = "false";
			}
			appConstants.executeFavorite='<%=request.getParameter("executeFavorite")%>';
			defaultParams='&er_type=Operation&er_gtype=Citrix&reporttype=operation&er_tbound=Fixed';
			appConstants.fromTimeGrtThanToTimeMsg='<egui:intnl text="reporter.common.From time should be less than To time"/>';
			appConstants.minuteSelectionNotAllowedfor24H='<egui:intnl text="reporter.common.Minute selection is not allowed for 24 hrs "/>';
			appConstants.startDateGrtThanEndDateMsg  ='<egui:intnl text="reporter.common.From date should not be greater than To date"/>';
			//appConstants._invalidDateTime  ='<egui:intnl text="reporter.common.startDate should not be greater than endDate"/>';
			appConstants.userTimelineErrorMsg = '<egui:intnl text="reporter.common.The specified timeline should not be greater than the maximum timeline set in your profile"/>';
			appConstants.forGrdReportConfirmMsg  = '<egui:intnl text="reporter.common.Foreground report generation will take some time Do you want to proceed"/>'+'?';
			appConstants.AlluserSelected;
			appConstants.initLdgMask=null;
			appConstants.fromJvm='<%=request.getParameter("fromJvm")%>';
			appConstants.measureName='<%=request.getParameter("measureName")%>';
			appConstants.testName='<%=request.getParameter("testName")%>';
			appConstants.infoName='<%=request.getParameter("infoName")%>';
			function loadUrlInDrillDown(urlQStr)
			{
				var QString='/final/reporter/ErMeasureDrillDown.jsp?'+urlQStr;
               			 QString +="&er_RmDispName="+appConstants.er_RmDispName;
				if (appConstants.menuForVM=='true')
				{
					maximizeWindowLightBox(QString);
				}
				else
				{
					 parent.maximizeWindowLightBox(QString); 
				} 
			}
			
			function loadPopup(urlQStr) {
          	     	 urlQStr +="&er_RmDispName="+appConstants.er_RmDispName;
				ddwin = window.open(urlQStr,"<%=session.getId()%>DDWindow","width=1012,height=603,left=0,top=105,scrollbars=1,scrollbars=yes,resizable");
				ddwin.focus()
			}
			
			function openScreenShot(ScreenshotID){
				if(Ext.isEmpty(ScreenshotID) || ScreenshotID == null || ScreenshotID == undefined)
					return;
				
				try
				{
					Ext.create('Ext.window.Window',{
						title:'Failure Screenshot',
						height:'80%',
						cls:'logonWindowShadow',
						modal:true,
						shadow:'sides',
						shadowOffset:50,
						resizable:false,
						width:'80%',
						items:[
							{
								xtype: 'component',
								style:{'align':'center'},
								listeners:{
									'render':function(panel){
										Ext.EventManager.onWindowResize(function(w, h){
												panel.doComponentLayout();
											});
									}
								},
								autoEl: {
									tag: 'iframe',
									width:'100%',
									height:'100%',
									style:{'align':'center'},
									//src: '/final/monitor/SEUM/screenshots/'+encodeURI(ScreenshotID)+".jpg"
									src: '/final/monitor/screenshotDisplay.jsp?imageID='+encodeURI(ScreenshotID)+".jpg"
								}
							}	
						]
					}).show();
				}
				catch (e)
				{
				}
			}





			function getResultType(startDate, endDate, format)
			{
				var resulrType = 'hour';
				console.log('startDate-->'+startDate+'  end_ms-->'+startDate);
				format = getExtjsDateFormat(format);
				format += " H:i";
				var one_day=1000*60*60*24;
				var startDateobj=new Date(Ext.Date.parse(startDate, format));
				var endDateobj=new Date(Ext.Date.parse(endDate, format));
				var start_ms = startDateobj.getTime();
				var end_ms = endDateobj.getTime();
				console.log('start_ms-->'+start_ms+'  end_ms-->'+end_ms);
				var difference_ms = end_ms - start_ms;				
				var dateDiff  = Math.round(difference_ms/one_day); 
				if(dateDiff >1 && dateDiff <= 30)
				{
					resulrType = 'day';
				}
				else if(dateDiff > 30)
				{
					resulrType = 'month';
				}
				if(isSettingsEnabled)
				{
					Ext.getCmp('timelineType').setValue(resulrType);
				}
				else
				{
					//appConstants.timelineType = resulrType;
					appConstants.publicjsonData.selectecTimeLineType=resulrType;
				}
			}
			Ext.onReady(function(){
				appConstants.initLdgMask = new Ext.LoadMask(Ext.getBody(),{msg : "Loading ..."});

				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>