<!DOCTYPE html>

<%@ page import = "com.eg.IniFile"%>
<%@ page import = "com.egurkha.util.DateUtil"%>
<%@ page import = "com.egurkha.util.StringUtils"%>
<%@ page import = "com.eg.EgURLDecoder"%>
<%@ include file="EgTrackerA.jsp" %>
<%@ taglib prefix="egui" uri="../WEB-INF/eg-taglib.tld" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%
	response.setHeader("Cache-Control","no-store");
	response.setHeader("Pragma","no-cache");
	response.setDateHeader("Expires", -1);

	IniFile iniFile = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_ui.ini");
	String userDateFormat = _user.getUserDateFormat();
	if(!StringUtils.isNull(userDateFormat) && userDateFormat.equalsIgnoreCase("default")) {
		userDateFormat = mgrDateFormat;
	}
	boolean isClusterSupported = EgInstallInfo.isClusterSupported;
	IniFile servicesIniFile = new IniFile(EgInstallInfo.getInstallDir()+ "/manager/config/eg_services.ini");
	String auditlogForCLI = servicesIniFile.getValue("MISC_ARGS","AuditlogForCLI");
	boolean auditLogEnabledForCLI = !StringUtils.isNull(auditlogForCLI) && (auditlogForCLI.equalsIgnoreCase("true") || auditlogForCLI.equalsIgnoreCase("yes"))?true:false;
	String category = request.getParameter("category");
	if(category == null || (category=category.trim()).length()==0 || category.equalsIgnoreCase("null")) {
		category = "Admin";
	}
	String queryString = request.getQueryString();
	if(request.getParameter("reqfrom") != null && request.getParameter("reqfrom").equals("navlink")) {
		queryString +="&category="+category;
	}
	String jsppage = request.getParameter("jsppage");
	String thisTimeline = request.getParameter("eg_timeline");
	if(thisTimeline == null || thisTimeline.trim().length()==0) {
		thisTimeline = "24 hours";
	}
	Calendar cal=Calendar.getInstance();
	String sessionUsername = null;
	String sessionHostIp = null;

	String loginTime = null;
	String logoutTime = "Yet To Logout";

	if(jsppage != null && jsppage.equals("loginDetails")) 
	{
		String userName = request.getParameter("userID");
		if(userName!=null) 
		{
			if(userName.indexOf("/RealUser/") != -1) 
			{
				String grpDelimiter = "/RealUser/";
				int id = userName.indexOf(grpDelimiter);
				String ruser=  userName.substring(0,id);
				int nextIdx = id + grpDelimiter.length();
				String str_uname_A = userName.substring(nextIdx);
				String grpID = "";
				if (str_uname_A != null && str_uname_A.indexOf("/Grp/") != -1)
				{
					String temp_Usr = iniFile.getValue("DBUSER_USER_MAP",str_uname_A);
					if (temp_Usr != null && temp_Usr.length() > 0)
					{
						str_uname_A = temp_Usr;
					}
					String grpDelimiter2 = "/Grp/";
					int idx1 = str_uname_A.indexOf(grpDelimiter2);
					String str_grp_A = str_uname_A.substring(0,idx1);
					int nextIdx2 = idx1 + grpDelimiter2.length();
					String str_grp_B = str_uname_A.substring(nextIdx2);
					grpID = str_grp_A + "/" + str_grp_B + " (Group)";
				}
				String tmpUser = ruser + " of " + grpID;
				String tempUserName = StringUtils.replace(tmpUser,"<","&lt;");
				tempUserName = StringUtils.replace(tempUserName,">","&gt;");
				sessionUsername = tempUserName;
			}
			else 
			{
				String tmp_User = request.getParameter("userID");
				String temp_Usr = iniFile.getValue("DBUSER_USER_MAP",tmp_User);
				if (temp_Usr != null && temp_Usr.length() > 0)
				{
					tmp_User = temp_Usr;
				}
				String tempUserName = StringUtils.replace(tmp_User,"<","&lt;");
				tempUserName = StringUtils.replace(tempUserName,">","&gt;");
				sessionUsername = tempUserName;
			}
		}
		else 
		{
			sessionUsername = "-";
		}
		sessionHostIp = egurkha.EgUIUtils.decodeSecurityChar(request.getParameter("hostIp"));
		sessionHostIp = EgURLDecoder.decode(sessionHostIp,"UTF-8");
		String startDate = request.getParameter("startdate");
		String endDate = request.getParameter("enddate");
		if(startDate != null && (startDate=startDate.trim()).length()>0 && !startDate.equalsIgnoreCase("null"))
		{
			StringTokenizer stlogin=new StringTokenizer(DateUtil.formatDateForAuditLog(startDate.trim()));
			while(stlogin.hasMoreTokens())
			{
				String logindat = (String)stlogin.nextToken();
				String loginhr = (String)stlogin.nextToken();
				String comFormat = null;
				if(DateUtil.isDate(logindat.trim(), "MM/dd/yyyy"))
					comFormat = "MM/dd/yyyy";
				else
					comFormat = mgrDateFormat;
				String logindate = DateUtil.changeDateFormat(logindat.trim(),comFormat, mgrDateFormat);
				EgTimeZoneConverter egt = new EgTimeZoneConverter(logindate+" "+loginhr.trim(), _user);
				loginTime = egt.getDate(false)+" "+ egt.getHour() +":"+ egt.getMinute();
			}
		}
		if(endDate !=null && !endDate.equalsIgnoreCase("null") && endDate.trim().length()>0) 
		{
			StringTokenizer stoklogout=new StringTokenizer(DateUtil.formatDateForAuditLog(endDate.trim()));
			while(stoklogout.hasMoreTokens()) 
			{
				String logoutdat = (String) stoklogout.nextToken();
				String logouthr = (String) stoklogout.nextToken();
				String comFormat = null;
				if(DateUtil.isDate(logoutdat.trim(), "MM/dd/yyyy"))
					comFormat = "MM/dd/yyyy";
				else
					comFormat = mgrDateFormat;
				String logoutdate = DateUtil.changeDateFormat(logoutdat.trim(),comFormat, mgrDateFormat);
				EgTimeZoneConverter egt = new EgTimeZoneConverter(logoutdate+" "+logouthr.trim(), _user);
				logoutTime = egt.getDate(false)+" "+ egt.getHour() +":"+ egt.getMinute();
			}
		}
	}
	String forTitle = category;
	if(category.equalsIgnoreCase("Config"))
	{
		forTitle = "configuration";
	}
	String page_title = _mapping.getTextDescription("admin.title."+forTitle.toUpperCase()+" AUDITLOG REPORTS");
%>

<html>
<head>
	<meta charset="utf-8">

	<script type="text/javascript" src="../extjs/ext-all.js"></script>

	<!-- Fancy Scroll-->
	<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>
	<link rel="stylesheet" href="/final/styles/jscrollpane/jquery.jscrollpane.css"/>

	<script language="JavaScript1.2" src="/final/scripts/eg_DateUtil.js"></script>
	<script language="JavaScript1.2" src="/final/admin/eg_scripts/validate.js"></script>

	<!-- Utilities File -->
	<script language="Javascript1.2" src="/final/admin/utilities/Schedule.js"></script> 
	<script language="JavaScript" src="/final/scripts/utilities/EncodeDecodeParams.js"></script>


	<script language="JavaScript1.2">
		var csrfToken = '<%=strCsrfToken%>';
		var pageTitle = '<%=page_title%>';
		var pageDescc = '<egui:intnl description="auditlog.jsp"/>';
		var isClusterSupported = '<%=isClusterSupported%>';
		var auditLogEnabledForCLI = '<%=auditLogEnabledForCLI%>';
		var mgrDateFormat = getExtjsDateFormat('<%=userDateFormat%>');
		var dateFormatForTimeline = '<%=mgrDateFormat%>';
		var sformattedValue = null;
		var eformattedValue = null;
		var trackerLanguage='<%=trackerLanguage%>';
		var category='<%=category%>';
		var previousTimeLine = '<%=thisTimeline%>';
		var queryString = "<%=queryString%>";
		var currentPageNumber = 0;
		var total_pages = 0;
		var thisjsppage = "<%=jsppage%>";
		var previousPageNumber = 1;
		var sessionUsername = '<%=sessionUsername%>';
		var sessionHostIp = '<%=sessionHostIp%>';
		var page_caption = '<egui:intnl text="admin.common.'+category+' Audit Log"/>';
		var select_user_name = "<egui:intnl text='admin.auditlog.Select a user name'/>";
		var could_not_load = '<egui:intnl text="admin.common.Could not load audit log servlet"/>';
		var dateAlert = '<egui:intnl text="admin.user.End time should be greater than start time"/>';
		var information = '<egui:intnl text="admin.common.Could not load audit log information"/>';
		var information2 = '<egui:intnl text="admin.common.Please enter a page number between 1 to "/>';
		var no_data_found = '<egui:intnl text="admin.auditlog.No data found"/>';
		var loadTipData  = '<egui:intnl text="admin.common.Load Data"/>';
		var pdfURLString = '/final/servlet/com.eg.EgPdfDownloadC';
		var publicJSON = '';
		var isSuperManager = '<%=EgInstallInfo.isSuperManager%>';

		var probsErrorMessage = '<egui:intnl text="admin.error.Problem encountered while loading the user interface"/>';
		var requestTimeOut = '<egui:intnl text="admin.error.Response timed out"/>';
		var errorTitle = '<egui:intnl text="admin.user.Error"/>';
		var printTitle = '<egui:intnl text="admin.auditlog.Print"/>';
		var scheduleTitle = '<egui:intnl text="configmgmt.schedule.SAVE SCHEDULE"/>';
		var hostIpsLabel = '<egui:intnl text="admin.auditlog.Host IPs"/>';
		var modulesLabel = '<egui:intnl text="admin.auditlog.Modules"/>';
		var activitiesLabel = '<egui:intnl text="admin.auditlog.Activities"/>';
		var totalRecordsLabel = '<egui:intnl text="admin.auditlog.Total Records"/>';
		var pageLabel = '<egui:intnl text="admin.common.Page"/>';
		var ofLabel = ' <egui:intnl text="admin.common.of"/> ';
		var waitingMsg = '<egui:intnl text="admin.server.Downloading Please wait"/>';
		var downloadTitle = '<egui:intnl text="admin.server.Downloading"/>';
		var topicsLabel = '<egui:intnl text="admin.common.Displaying records"/> ';
		var timelineLabel = '<egui:intnl text="admin.auditlog.Timeline"/>';
		var startDateLabel = '<egui:intnl text="admin.common.Start Date"/>';
		var endDateLabel = '<egui:intnl text="admin.common.End Date"/>';
		var hourLabel = '<egui:intnl text="admin.auditlog.Hr"/>';
		var minuteLabel = '<egui:intnl text="admin.auditlog.Min"/>';
		var userLabel = '<egui:intnl text="admin.auditlog.User"/>';
		var managerLabel = '<egui:intnl text="admin.auditlog.Manager"/>';
		var interfaceLabel = '<egui:intnl text="admin.auditlog.Interface"/>';

		var loginTimeLabel = '<egui:intnl text="admin.auditlog.Login Time"/>';
		var logoutTimeLabel = '<egui:intnl text="admin.auditlog.Logout Time"/>';
		var hostIPLabel = '<egui:intnl text="admin.auditlog.Host IP"/>';
		var interfaceLabel = '<egui:intnl text="admin.auditlog.Interface"/>';
		var interfaceLabel = '<egui:intnl text="admin.auditlog.Interface"/>';
		var loginTime = '<%=loginTime%>';
		var logoutTime = '<%=logoutTime%>';
		var startRecord = 1;
		var endRecord = 1;
		var totalRecord = 0;
		var rowsPerPage = 25;

	</script>

	<!-- Application folder -->
	<script type="text/javascript" src="Auditlog/app/app.js"></script>

	<egui:skin ui="admin"/>

	<script language="javascript">
		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};

			Ext.Ajax.on('requestexception', function (conn, response, options) {
				var errorStr = response.responseText;
				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);
					}
				}
				else
				{
					if (response.status == 302 || (response.timedout != undefined && response.timedout == true))
					{
						Ext.Msg.show({
							title : errorTitle,
							msg : requestTimeOut,
							buttons : Ext.Msg.OK,
							icon : 'iconError'
						});
					}
					else
					{
						console.log(response.responseText);
						Ext.Msg.show({
							title : errorTitle,
							msg : probsErrorMessage,
							buttons : Ext.Msg.OK,
							icon : 'iconError'
						});
					}
				}
			});
		});
	</script>

</head>
<body>
<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>
</body>
</html>

<%
	session.setAttribute("adminLastAccessedURL","/final/admin/auditlog.jsp?"+request.getQueryString());
%>



