<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="java.io.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%@ page import="com.eactive.eai.rms.common.login.SessionManager"%>
<%@ page import="com.eactive.eai.common.util.SystemUtil"%>
<%
	response.setHeader("Pragma", "No-cache");
	response.setHeader("Cache-Control", "no-cache");
	response.setHeader("Expires", "0");

%>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="/jsp/common/include/css.jsp"/>
<jsp:include page="/jsp/common/include/script.jsp"/>
<script language="javascript">

var url      ='<c:url value="/onl/admin/adapter/terminalStatusInfo.json" />';
var url_view ='<c:url value="/onl/admin/adapter/terminalStatusInfo.view" />';

function getStartTime() {
	var now = new Date();
	var tm = right("0" + now.getHours(), 2);
	tm += right("0" + now.getMinutes(), 2);

	tm = (Math.floor(tm.substr(0, 2)) * 60) + Math.floor(right(tm, 2)) - 5;
	tm = right("0" + parseInt(tm/60), 2) + right("0" + tm%60, 2);
	return tm + '00';	
}

function getEndTime() {
	var now = new Date();
	var tm = right("0" + now.getHours(), 2);
	tm += right("0" + now.getMinutes(), 2);
	return tm + '59';
}

function toDateString(d) {
	var dateStr = d.replace(/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/ , '$4:$5:$6 $2/$3/$1');
	return dateStr;
}

//10분후 시간셋팅
function setTime(searchTime) {
	var endYYYYMMDD;
	var endHHMM;
	var yy = searchTime.substr(0,4);
	var mm = searchTime.substr(4,2); 
	var dd = searchTime.substr(6,2);
	var hh = searchTime.substr(8,2);
	var MM = searchTime.substr(10,2);
	var ms = Date.UTC(yy,mm-1,dd,hh,MM,00);
	var date = new Date(ms);
	date.setHours( date.getHours() - 9 );
	
	//10분 후 셋팅
	date.setMinutes( date.getMinutes() + 9 );
	
	endYYYYMMDD = date.getFullYear() + right("0" + (date.getMonth() + 1), 2) + right("0" + (date.getDate()), 2);
	endHHMM = right("0" + date.getHours() , 2) + right("0" + date.getMinutes() , 2) + "59";
	
	$("input[name=searchEndYYYYMMDD]").val(endYYYYMMDD);
	$("input[name=searchEndHHMM]").val(endHHMM);
}

$(document).ready(function() {
	
	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").inputmask("yyyy-mm-dd",{'autoUnmask':true});
	$("input[name=searchStartHHMM],input[name=searchEndHHMM]").inputmask("hh:mm:ss",{'autoUnmask':true});
	
	$("input[name=searchStartYYYYMMDD],input[name=searchEndYYYYMMDD]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){			
			$(this).val(getToday());
		}
	});
	$("input[name=searchStartHHMM]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			//$(this).val(getStartTime());
			$(this).val("000000");
		}
	});
	$("input[name=searchEndHHMM]").each(function(){
		if ($(this).val() == undefined || $(this).val() == null || $(this).val() == ""){
			//$(this).val(getEndTime());
			$(this).val("235959");
		}
	});
	
	var gridPostData = getSearchForJqgrid("cmd","LIST"); //jqgrid에서는 object 로
	gridPostData['startCreateTime'] = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchStartHHMM]").val();
	gridPostData['endCreateTime'] = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchEndHHMM]").val();
	
	$('#grid').jqGrid({
		datatype : "json",
		mtype : 'POST',
		url : url,
		postData : gridPostData,
		colNames:[	'<%= localeMessage.getString("terStatInfo.userID") %>',
		            '<%= localeMessage.getString("terStatInfo.userNm") %>',
		            '국명',
		            '국코드',
		            '<%= localeMessage.getString("terStatInfo.userSessStat") %>',
		            '<%= localeMessage.getString("terStatInfo.webScktInstNm") %>',
		            '<%= localeMessage.getString("terStatInfo.webScktRemtAddr") %>',
		            '<%= localeMessage.getString("terStatInfo.webScktSessStat") %>',
		            '<%= localeMessage.getString("terStatInfo.sessID") %>',
		            '<%= localeMessage.getString("terStatInfo.crtTm") %>'
            ],
        colModel:[
					{ name:'USERID', 			align:'center', width:90 },
					{ name:'USER_NAME', 		align:'center',	width:100 },
					{ name:'BRN_NAME', 			align:'center',	width:70 },
					{ name:'BRN_CD', 			align:'center',	width:70 },
					{ name:'SESSION_STATUS', 	align:'center',	width:70 },
					{ name:'WSOC_INSTANCE', 	align:'center',	width:70 },
					{ name:'WSOC_REMOTE_ADDR', 	align:'center',	width:170 },
					{ name:'WSOC_SESSION_STATUS',align:'center',width:70 },
					{ name:'SESSION_ID', 		align:'left',	width:180 },
					{ name:'CREATE_TIME', 		align:'center',	width:100 }
				],
		jsonReader: {
             repeatitems:false
        },
		pager : $('#pager'),
		page : '${param.page}',
		rowNum : '${rmsDefaultRowNum}',
	    autoheight: true,
	    height: $("#container").height(),
		autowidth: true,
		viewrecords: true,
		multiselect: false,
		multiboxonly: false,		
		sortname : '${param.sortName}',
		sortorder : '${param.sortOrder}',
		rowList : eval('[${rmsDefaultRowList}]'),
		loadComplete:function (d){
			//$(this).setGridParam({datatype:'local'});
		},
        loadError: function (jqXHR, textStatus, errorThrown) {
        	if(jqXHR.status == 401) {
	    		alert('HTTP status code: ' + jqXHR.status + '\n' +
	                    '에러:  세션이 종료되었습니다. ');
	    		parent.location.href='<%=request.getContextPath()%>/';	
	    	}
    	}, 
    	gridComplete:function (d){
			var colModel = $(this).getGridParam("colModel");
			for(var i = 0 ; i< colModel.length; i++){
				$(this).setColProp(colModel[i].name, {sortable : false});	//그리드 헤더 화살표 삭제(정렬X)		
			}
		},
		ondblClickRow: function(rowId) {
			/* var rowData = $(this).getRowData(rowId); 
            var url2 = url_view;
            url2 += '?cmd=DETAIL';
            url2 += '&page='+$(this).getGridParam("page");
            url2 += '&returnUrl='+getReturnUrl();
            url2 += '&menuId='+'${param.menuId}';
        	url2 += '&sortName='+$("#grid").getGridParam("sortname");
        	url2 += '&sortOrder='+$("#grid").getGridParam("sortorder");            
			//검색값
            url2 += '&'+getSearchUrl();
            
            //key값
            url2 += '&adptrBzwkGroupName='+encodeURIComponent(rowData['ADPTRBZWKGROUPNAME']);
            goNav(url2); */
        },
        onSortCol :function(sidx,colnum,sort_order){
          		 
        }
	});
	
	resizeJqGridWidth('grid','content_middle','1000');
	
	$("#btn_search").click(function(){
		
		var postData = { cmd : 'LIST' };
		
		postData['userId'] = $("input[name=userId]").val();
		postData['userName'] = $("input[name=userName]").val();
		postData['wsocRemoteAddr'] = $("input[name=wsocRemoteAddr]").val();
		postData['sessionId'] = $("input[name=sessionId]").val();
		var startCreateTime = $("input[name=searchStartYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchStartHHMM]").val();
		var endCreateTime = $("input[name=searchEndYYYYMMDD]").val().replace(/-/gi,"") + $("input[name=searchEndHHMM]").val();
		if(startCreateTime > endCreateTime) {
			alert('조회기간을 확인해주세요');
			return;
		}
		postData['startCreateTime'] = startCreateTime;
		postData['endCreateTime'] = endCreateTime;

		$("#grid").setGridParam({ postData : postData, page:1 }).trigger("reloadGrid");
	});
	
	$("input").keydown(function(key){
		if (key.keyCode == 13){
			$("#btn_search").click();
		}
	});
	
	$("#startDatepicker").datepicker();
	$("#endDatepicker").datepicker();
	
	buttonControl();
});
</script>
</head>
<body>
	<div class="right_box">
		<div class="content_top">
			<ul class="path">
				<li><a href="#">${rmsMenuPath}</a></li>					
			</ul>					
		</div><!-- end content_top -->
		<div class="content_middle" id="content_middle">
			<div class="search_wrap">
				<button type="button" class="cssbtn" id="btn_search" level="R"><i class="material-icons">search</i> <%= localeMessage.getString("button.search") %></button>
<%-- 				<img src="<c:url value="/img/btn_search.png"/>" alt="" id="btn_search" level="R" />		 --%>
			</div>
			<div class="title"><%= localeMessage.getString("terStatInfo.title") %></div>
			<form id="ajaxForm">
				<table class="search_condition" cellspacing=0;>
					<tbody>
						<tr>
							<th width=""><%= localeMessage.getString("terStatInfo.userID") %></th>
							<td width=""> <input type="text" name="userId" value="${param.userId}"></td>
							<th width=""><%= localeMessage.getString("terStatInfo.userNm") %></th>
							<td width=""><input type="text" name="userName" value="${param.userName}"></td>
							<th width=""><%= localeMessage.getString("terStatInfo.webScktRemtAddr") %></th>
							<td width=""><input type="text" name="wsocRemoteAddr" value="${param.wsocRemoteAddr}"></td>
							<th width=""><%= localeMessage.getString("terStatInfo.sessID") %></th>
							<td width=""> <input type="text" name="sessionId" value="${param.sessionId}"></td>
							<th width=""><%= localeMessage.getString("terStatInfo.crtTm") %></th>
							<td style="width: 25%;">
								<input type="text" name="searchStartYYYYMMDD" id="startDatepicker" readonly="readonly" value="" size="10" style="width:80px; border:1px solid #ebebec;">
								<input type="text" name="searchStartHHMM" value="" size="8" style="width:80px; border:1px solid #ebebec;">
								~
								<input type="text" name="searchEndYYYYMMDD" value="" id="endDatepicker" size="10" readonly="readonly" style="width:80px; border:1px solid #ebebec;">
								<input type="text" name="searchEndHHMM" value="" size="8" style="width:80px; border:1px solid #ebebec;">
							</td>
							<!-- 
							<td width=""> <input type="text" name="createTime" value="${param.createTime}"></td>
							 -->
						</tr>
					</tbody>
				</table>
			</form>
			<table id="grid" ></table>
			<div id="pager"></div>
		</div>
	</div>
</body>
</html>