<!DOCTYPE html>
<%
/**
/***********************************************************************************
 *		Name				:	EgAlarmHistoryView.jsp
 *		Version				:	5.0
 *		CreationDate		:	9/03/2010
 *		Author				:	Nehru.C
 ***********************************************************************************/
 %>


<!-- 17.07.2007 added the jsp:include tag instantof iframe by Saravanan.A-->
<%@ include file="EgLoginTracker.jsp" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page import = "com.eg.IniFile" %>
<%@ page import = "com.eg.EgInstallInfo" %>
<%@ page import = "com.eg.EgURLEncoder"%>
<%@ page import ="com.egurkha.util.StringUtils"%>
<%@ page import = "com.eg.EgDbAdapterTypeUI" %>
<%@ page import = "egurkha.EgDbAdapterUI" %>
<%@ page import = "com.eg.EgDateInfo"%>
<%@ page import = "java.util.*" %>
<%@ page import = "com.egurkha.User"%>
<%@ page import = "com.egurkha.UserRegistry"%>
<%@ page import = "com.egurkha.ini.IniUI"%>
<%@ page import = "com.eg.EgMappingInfo"%>

<%
	EgDateInfo egDt = new EgDateInfo();
	java.util.Date local_date = new java.util.Date(egDt.egetUTCDate());
	Calendar cal = Calendar.getInstance();
	cal.setTime(local_date);
	cal.setTimeZone(egDt.getRealTimeZone());
	String uiFile = "eg_ui.ini";
	String s_iniFile_dir = EgInstallInfo.getInstallDir()+ "/manager/config/";
	IniFile egUI = new IniFile(s_iniFile_dir + uiFile);
	String loadByDefault = egUI.getValue("ALARM_HISTORY","LoadByDefault");
	String loadbydefault = "";
	if(loadByDefault != null && loadByDefault.trim().length() > 0){
		if(loadByDefault.equalsIgnoreCase("yes") || loadByDefault.equalsIgnoreCase("true") || request.getParameter("fromDashBoard") != null)
			loadbydefault = "<table width='100%' height='300px'><tr><td align='center' valign='middle'><div class='iconNoalarms'></div>No alarms found</td></tr></table>";
		else
			loadbydefault = "";
	}

	String eventHistFlag = egUI.getValue("ALARM_HISTORY","ShowEventHistory");
	boolean showEventHistory = true;
	if(eventHistFlag != null && eventHistFlag.trim().length() > 0 && (eventHistFlag.equalsIgnoreCase("yes") || eventHistFlag.equalsIgnoreCase("true") || eventHistFlag.equalsIgnoreCase("y") ))
		showEventHistory = true;
	else
		showEventHistory = false;

	UserRegistry registry = UserRegistry.getInstance();
	User user = registry.getUser(session.getId());
	EgUserRole userRole = EgUserRole.getRoleObject(user.getLoginType());

	IniUI iniUI = IniUI.getInstance();
	String thisLanguage = iniUI.getDefaultLanguage();
	if (user!=null)
	{
		user.setUserLanguageAndSkins();
		String userLang = user.getLanguage();
		if (userLang!=null && !userLang.equalsIgnoreCase("NULL"))
		{
			thisLanguage=userLang;
		}
	}
	EgMappingInfo mappingInfo = new EgMappingInfo(thisLanguage);
	String currentDateFormat = egUI.getValue("CURRENT_DATE_FORMAT","selectedDateFormat");
	String fromePage=request.getParameter("fromePage");
	String analysisBy=request.getParameter("analysisBy");
	String analysis=request.getParameter("analysis");
	String subevent=request.getParameter("subevent");
	String compstate=request.getParameter("compstate");
	String startTimeUrl=request.getParameter("startTimeUrl");
	String endTimeUrl=request.getParameter("endTimeUrl");
	String alertTest=request.getParameter("alertTest");
	String showEventHistoryFlag=request.getParameter("showEventHistory");
	if(showEventHistoryFlag != null && showEventHistoryFlag.trim().length() > 0)
	{
		if(showEventHistoryFlag.equalsIgnoreCase("yes") || showEventHistoryFlag.equalsIgnoreCase("true") || showEventHistoryFlag.equalsIgnoreCase("y") )
			showEventHistory = true;
		else
			showEventHistory = false;
	}
	String queryString= request.getQueryString();
	String defaultQueryString ="";
	String fromDashboard="";
	String qSfromDashboard="";
	String newAlarms = request.getParameter("newAlarms");
	
	

	String skin = user.getMonitorSkin();
	boolean hasVMs = false;
	boolean isAllComp = userRole.hasAllComponentAccess();
	if (user!=null)
	{
		if(!isAllComp)
		{
			List a_userVMs = user.getOnlyVMs();
			if(a_userVMs!=null && a_userVMs.size() > 0)
			{
				hasVMs = true;
			}
		}
	}


	
	if(queryString!=null){
		defaultQueryString=queryString.substring(queryString.indexOf("?")+1);
		String[] splitStr = StringUtils.getTokens(defaultQueryString, "&");
		if ( splitStr != null )
			{
				for (int i = 0;i < splitStr.length; i++ )
				{
					String val = splitStr[i];
					String paramName = val.substring(0, val.indexOf("="));
					String paramValue = val.substring(val.indexOf("=") + 1);
					if ( paramName.equalsIgnoreCase("fromDashboard") )
					{
						fromDashboard = paramValue;
					}
				}
			}
	}
	if(fromDashboard.equals("true"))
	{
		qSfromDashboard=queryString;
	}
	else
	{
		qSfromDashboard = "null";
	}

	String backNavDashboard = request.getParameter("backNav");
	String backDashboardURL="";
	String insideViewURL="";
	String fromPage = request.getParameter("fromPage");
	String from_page = request.getParameter("from_page");
	String hostName=request.getParameter("compNameList");
	String compType=request.getParameter("compTypeList");
	String isVM=request.getParameter("isVM");
	String fromHomePage=request.getParameter("fromHomePage");
	String source=request.getParameter("source");
	String dashboardcomptype=request.getParameter("dashboardcomptype");
	String Layer=request.getParameter("Layer");
	String subsystem = request.getParameter("subsystem");
	 subsystem = subsystem !=null ? subsystem :"Overview";
	String insideview_info = request.getParameter("insideview_info");
	String tab = request.getParameter("tab");
	String selectedsubzone = request.getParameter("selectedsubzone");
	if(backNavDashboard!=null && backNavDashboard.equalsIgnoreCase("cmpDashboard") )
	{
		
		if(fromPage!=null && fromPage.equalsIgnoreCase("cisco_Dashboard"))
		{
			backDashboardURL="/final/monitor/EgCiscoDashboardJSON.jsp?tab=Network&hostName="+EgURLEncoder.encode(hostName,"UTF-8")+"&comptype="+EgURLEncoder.encode(compType,"UTF-8")+"&ciscoSelectedType="+subsystem+"&screenWidth=1012&screenHeight=570";
		}
		else if(fromPage!=null && fromPage.equalsIgnoreCase("cluster"))
		{
			backDashboardURL="/final/monitor/EgClusterDashboard.jsp?tab=cluster&host="+EgURLEncoder.encode(hostName,"UTF-8")+"&comptype="+EgURLEncoder.encode(compType,"UTF-8")+"&screenWidth=1012&screenHeight=570";
		}
	}
	else if(fromPage!=null && fromPage.equalsIgnoreCase("MyDashboard"))
	{
		String profileName = request.getParameter("profileName");	
		if(!StringUtils.isNull(profileName))
		{
			profileName=StringUtils.decodeSecurityChar(profileName);
		}
		backDashboardURL="/final/monitor/MyDashboard.jsp?comesFrom=myDashboard&action=showMyDashboard&profileName="+EgURLEncoder.encode(profileName,"UTF-8");		 
	}
	if(from_page!=null && from_page.equalsIgnoreCase("insideviewDashboard"))
	{
		insideViewURL="/final/monitor/egInsideviewDashboard.jsp?getFor=measure&comp="+EgURLEncoder.encode(hostName,"UTF-8")+"&comptype="+EgURLEncoder.encode(dashboardcomptype,"UTF-8")+"&defaultSelectedTab=System&Layer="+EgURLEncoder.encode(Layer,"UTF-8")+"&info="+EgURLEncoder.encode(insideview_info,"UTF-8")+"&subsystem="+subsystem+"&tab=System&hostName="+EgURLEncoder.encode(hostName,"UTF-8")+"&compType="+EgURLEncoder.encode(dashboardcomptype,"UTF-8")+"&subsystem="+subsystem+"&from_page="+from_page+"&Layer="+EgURLEncoder.encode(Layer,"UTF-8")+"&allComps=&isVM="+isVM+"&source="+source+"&info="+EgURLEncoder.encode(insideview_info,"UTF-8")+"&subsystem="+subsystem+"&fromHomePage="+fromHomePage;
		if(isVM != null && isVM.equalsIgnoreCase("true"))
			insideViewURL += "&from=MainDashboard&check=uservms&stateName=all";
	}

	if(analysisBy != null && analysisBy.equalsIgnoreCase("Components")){
		analysisBy = "Component";
		if(analysis != null){
			if(analysis.indexOf(",") == -1){
				hostName = analysis.substring(analysis.indexOf(":")+1);
			}
			analysis = analysis.substring(0,analysis.indexOf(":"));
		}
	}
%>

<html class="content-frame">
	<head>
		<title>Alarm History</title>
		<script>
		var backDashboardURL = '<%=backDashboardURL%>';
		var insideViewURL = '<%=insideViewURL%>';
		var descriptionSearch='<%= mappingInfo.getTextDescription("monitor.common.Description Search")%>';
		var showAlarms='<%=mappingInfo.getTextDescription("monitor.common.Show Alarms")%>';
		var backLbl='<%=mappingInfo.getTextDescription("monitor.common.Back")%>';
		var pageNameLbl='<%=mappingInfo.getTextDescription("monitor.common.Page")%>';
		var pageLbl='<%=mappingInfo.getTextDescription("monitor.common.HISTORY OF ALARMS")%>';
		var settings='<%=mappingInfo.getTextDescription("monitor.common.Settings")%>';
		var save='<%=mappingInfo.getTextDescription("monitor.common.Save")%>';
		var update='<%=mappingInfo.getTextDescription("monitor.common.Update")%>';
		var compSearch='<%=mappingInfo.getTextDescription("monitor.common.Component Search")%>';
		var csv='<%=mappingInfo.getTextDescription("monitor.common.CSV")%>';
		var historyDockedDisplaying='<%=mappingInfo.getTextDescription("monitor.common.Displaying")%>';
		var historyDockedOf='<%=mappingInfo.getTextDescription("monitor.common.of")%>';
		var fildata ="<%=loadbydefault%>";
		var skin = "<%=skin%>";
		var mgrDateFormat = "";
		var currentDateFormat = "";
		var qSfromDashboard = "<%=qSfromDashboard%>";
		var fromePage = '<%=fromePage%>';
		var analysisBy = '<%=analysisBy%>';
		var analysis = '<%=analysis%>';
		var compstate = '<%=compstate%>';
		var startTimeUrl = '<%=startTimeUrl%>';
		var endTimeUrl = '<%=endTimeUrl%>';
		var alertTest = '<%=alertTest%>';
		var newAlarms = '<%=newAlarms%>';
		var comptype = '<%=compType%>';
		var hostName = '<%=hostName%>';
		var subevent = '<%=subevent%>';
		var selectedsubzone = '<%=selectedsubzone%>';
		var s_mon = <%=cal.get(cal.MONTH)%>;
		s_mon=s_mon+1;
		var s_day = <%=cal.get(cal.DAY_OF_MONTH)%>;
		var  s_yr = <%=cal.get(cal.YEAR)%>;
		var backHidden = (fromePage =='null' || fromePage ==null)?true:false;
		var showEventHistory = <%=showEventHistory%>;
		var hasVMs = <%=hasVMs%>;
		//backHidden = (newAlarms=='true')?false:true;
		</script>
		<egui:skin ui="monitor"/>
		<egui:loadApp baseDir="/final/monitor/eg_scripts" appName="historyApp" appFile="historyApp.js"/>
		<meta charset="utf-8" http-equiv="X-UA-Compatible" content="IE=8,9,10" >
		

		<script src="/final/jquery/jquery.js"></script>
		<script language="JavaScript1.2" src="eg_scripts/eg_date.js"></script>
		<script language="JavaScript1.2" src="eg_scripts/eg_validate.js"></script>
		<!-- <script src="/final/styles/jscrollpane/jquery.jscrollpane.min.js" ></script>
		<link rel="stylesheet" href="/final/styles/jscrollpane/jquery.jscrollpane.css"/>
		<script src="/final/styles/jscrollpane/jquery.mousewheel.js" ></script>
		<script src="/final/styles/jscrollpane/mwheelIntent.js" ></script> -->
		<script src="/final/scripts/eg_DateUtil.js" type='text/javascript'></script>
		<script src="/final/Highcharts/js/highcharts.js"></script>
		<script src="/final/monitor/eg_scripts/EgHighChart.js"></script>
		<!-- <script type="text/javascript" src="/final/FusionCharts/scripts/FusionCharts.js"></script> -->
		<script src="/final/monitor/eg_scripts/ajaxutils.js" type="text/javascript"></script>
		<script>
			
			function openScreenShot(ScreenshotID){
				if(Ext.isEmpty(ScreenshotID) || ScreenshotID == null || ScreenshotID == undefined)
					return;
				
				var mgr_id='-';
				if(ScreenshotID.indexOf('|')>0)
				{
					mgr_id=ScreenshotID.substring(ScreenshotID.indexOf('|')+1);
					ScreenshotID=ScreenshotID.substring(0,ScreenshotID.indexOf('|'));
				}
				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?managerId='+encodeURI(mgr_id)+'&imageID='+encodeURI(ScreenshotID)+".jpg"
								}
							}	
						]
					}).show();
				}
				catch (e)
				{
				}
			}

			function parseScript(_source)
			{
				var source = _source;
				var scripts = new Array();
				
				// Strip out tags
				while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {

					var s = source.indexOf("<script");
					var s_e = source.indexOf(">", s);
					var e = source.indexOf("</script", s);
					var e_e = source.indexOf(">", e);			
					// Add to scripts array
					scripts.push(source.substring(s_e+1, e));
					// Strip from source
					source = source.substring(0, s) + source.substring(e_e+1);
				}
				// Loop through every script collected and eval it
				for(var i=0; i<scripts.length; i++) {
					try {
						eval(scripts[i]);
					}
					catch(ex) {
						return;
					}
				}
				// Return the cleaned source
				return source;
			}
			Ext.onReady(function(){
				 Ext.Ajax.on('requestexception', function (conn, response, options) {
						var errorStr = response.responseText;

						if(errorStr!=null && errorStr!=undefined)
							parseScript(errorStr);

						if (errorStr != undefined && errorStr != 'undefined' && errorStr.indexOf("customerror") != -1)
						{
							if (errorStr.indexOf("user-session-invalid") != -1)
							{
								callWindow(1);
							}
							else if (errorStr.indexOf("user-deleted") != -1)
							{
								callWindow(2);
							}
							else if (errorStr.indexOf("user-timedout") != -1)
							{
								callWindow(3);
							}
						}
					});
				initLdgMask = new Ext.LoadMask(Ext.getBody(),{msg : "Loading ..."});
			});

			function HelpWin()
			{
				Ext.onReady(function(){


				 /*Ext.widget("window", {
										title: "Help",
										resizable: false,
										width: 1000,
										frame: false,
										constrain: true,
										height: 550,
										scroll: false,
										autoScroll: false,
										border: false,
										layout: "fit",
										padding: "0 0 0 0",
										margin: "0 10 0 0",
										html: '<iframe width="100%" height="100%" scrolling="no" frameborder="0" src="/final/eghelp/EgHelpApp.jsp?forwardPage=EgMHelp.jsp"></iframe>'
									}).show();*/

			 if (Ext.getBody().getViewSize().width < 1100)
			 {
			     var cwidth1=Ext.getBody().getViewSize().width-64; 
				 var leftPosition = 25;
				 var left = (Ext.getBody().getViewSize().width/2)-(cwidth1/2);						    
			 }
			 else
			 {
				 var cwidth1=Ext.getBody().getViewSize().width-154;
				 var leftPosition = 78;
				 var left = (Ext.getBody().getViewSize().width/2)-(cwidth1/2);
			 }
			 var cwidth2=(cwidth1/2);						
			 var cheight=Ext.getBody().getViewSize().height-240;
			 var top = (Ext.getBody().getViewSize().height/2)-(cheight/2);
			 HelpWinOth("/final/eghelp/EgHelpApp.jsp?forwardPage=EgMHelp.jsp", cwidth1, cheight+100, left, top, left, top);
			 /*var helpWin=window.open("/final/eghelp/EgHelpApp.jsp?forwardPage=EgMHelp.jsp", "HelpWindow", "toolbar=no,location=no,status=no,menubar=no,width="+cwidth1+",height="+(cheight+100)+",left="+left+",top="+top+",screenx="+left+",screeny="+top+",resizable=yes");
			 helpwin.focus();*/

				});
			}

		//	var mgrDateFormat=getExtjsDateFormat('<%=currentDateFormat%>');
			mgrDateFormat=getExtjsDateFormat('<%=dateFormatForDatePicker%>');
			currentDateFormat = '<%=currentDateFormat%>';
			
		</script>
		<script src="../scripts/utilities/ScrollPanel.js"></script>
	</head>
	<body style="overflow:hidden" scrolling="no" class="content-frame">
		<div id="alarmsTableDiv" class="x-hidden"></div>
		<div id="alarmDetail" class="x-hidden"></div>
		<%
			session.setAttribute("monitorLastSession","/final/monitor/EgAlarmHistoryView.jsp?"+request.getQueryString());
		%>
	</body>
</html>
