<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="ct" tagdir="/WEB-INF/tags" %>
<script type="text/javaScript" defer="defer">
	<!--
	
	$(document).ready(function(){
		
		if (document.searchForm.ordercode && document.searchForm.ordercode.value.length > 0) {
			$('.order[value=' + document.searchForm.ordercode.value + '] img')
				.attr('src', (document.searchForm.ordertype.value == '1') ? '/images/cmmn/order_desc.gif' : '/images/cmmn/order_asc.gif');
		}
		
		$('.order').click(function(){
			var ordercode = $(this).attr('value');
			if (document.searchForm.ordercode.value == ordercode) {
				if (document.searchForm.ordertype.value == 1) {
					document.searchForm.ordertype.value = 0;
				} else {
					document.searchForm.ordertype.value = 1;
				}
			} else {
				document.searchForm.ordertype.value = 0;
			}
			document.searchForm.ordercode.value = ordercode;
			fn_searchList();
		});
		
		$("#name").keydown(function(e){
			if (e.keyCode == 13) {
				fn_link_page(1);	
			}
		})
	});
	
	/* 접속 해제 */
	function releaseConnection(userid) {
		console.log();
		$.ajax({
			url: '/admin/releaseConnection.json',
			type: 'post',
			data: {userid:userid},
			dataType: 'json',
			success: function (data) {
				if (data.result == '1') {
					alert('접속이 해제되었습니다.');
				} else {
					alert('접속해제가 실패하였습니다.');
				}
				fn_link_page(document.searchForm.pageIndex.value);
			}
		});
	}
	
	/* 제한 해제 */
	function releaseRestriction(userid) {
		$.ajax({
			url: '/admin/releaseRestriction.json',
			type: 'post',
			data: {userid:userid, usertype:document.listForm.usertype.value},
			dataType: 'json',
			success: function (data) {
				if (data.result == '1') {
					alert('접속제한이 해제되었습니다.');
				} else {
					alert('접속제한 해제에 실패하였습니다.');
				}
				fn_link_page(document.searchForm.pageIndex.value);
			}
		});
	}
	/* 선택 초기화 */
	function initPassword() {
		$.ajax({
			url: '/admin/initPw.json',
			type: 'post',
			data: $('#listForm').serialize(),
			dataType: 'json',
			success: function (data) {
				if (data.result == '1') {
					alert('초기화 되었습니다.');
					$('#listForm input[name=targetId]').attr('checked', false);
				} else {
					alert('변경에 실패하였습니다. 다시 시도해주세요.');	
				}
				hideInitPwMenu();
			}
		});
		
	}
	
	function showInitPwMenu(){
		if ($('#listForm input[name=targetId]:checked').length > 0) {
			$('#initPwMenu').show();
			
			var modalBack = $('#modalBack');
			if (modalBack.length == 0) {
				modalBack = $('<div>')
				.show()
				.attr('id', 'modalBack')
				.css({
					'display' : 'none',
					'position' : 'absolute',
					'width' : $(window).outerWidth(),
					'height' : $(window).outerHeight(),
					'overflow' : 'hidden',
					'top' : '0px'
				});
				$('body').append(modalBack);
			}
			modalBack.show();
		} else {
			alert('비밀번호를 초기화할 사용자를 선택하세요');
		}
		
		
	}
	function hideInitPwMenu(){
		$('#initPwMenu').hide();
		$('#modalBack').hide();
	}
	
	/* 글 목록 화면 function */
    function fn_searchList() {
       	document.searchForm.action = "<c:url value='/admin/memberManage.do'/>";
       	document.searchForm.pageIndex.value = 1;
       	document.searchForm.submit();
    }
	
	/* 검색초기화 function */
    function fn_selectList() {
       	location.href = "/admin/memberManage.do";
    }
	
	/* pagination 페이지 링크 function */
	function fn_link_page(pageNo) {
		document.searchForm.pageIndex.value = pageNo;
		document.searchForm.action = "<c:url value='/admin/memberManage.do'/>";
		document.searchForm.submit();
	}
	//-->
</script>
<form:form commandName="memberSearchVO" name="searchForm" method="get">
<div class="search2">
	<ul>
		<li><b>소속</b> 　</li>
		<li class="form_search margin-left">
			<form:select path="place1" cssClass="use">
     				<form:option value="" label="전체" />
				<c:forEach var="item" items="${place1List}">
	    		<form:option value="${item.code2}">${item.codenm}</form:option>
	    		</c:forEach>
 			</form:select>
	 	</li>
	 	<li class="margin-left"><b>이름</b> 　</li>
	 	<li class="margin-left"><form:input path="name"/></li>	 
	 	<li class="form_radio">
	 		<form:radiobutton path="usertype" value="f"/>외사경찰
			<form:radiobutton path="usertype" value="g"/>일반경찰
	 	</li>
		<li class="margin-left">
			<span class="btn_blue"> 
				<a href="javascript:fn_link_page(1);"><spring:message code="button.goSearch" /></a>
			</span>
		</li>
		<li>
			<span class="btn_gray"> 
				<a href="javascript:fn_selectList();"><spring:message code="button.initSearch" /></a>
			</span>
		</li>
	</ul>	       	       
</div>
<form:hidden path="pageIndex" />
<form:hidden path="ordertype" />
<form:hidden path="ordercode" />
</form:form>
<form:form id="listForm" name="listForm" method="post">
		<input type="hidden" name="usertype" value="${memberSearchVO.usertype}"/>			
		<div id="initPwMenu">	
			<div class="dimBg"></div>
			<div class="mini_window" id="mini_window_ModifyWindow">  
				<div class="password-pop">
					<h3>비밀번호 초기화</h3>					
					<input name=checkPwd type="hidden" value="N">
					<table class="tbl_add border-style">
					  	<tbody>
							<tr>
							  <td class="coloredTd">초기화 할 비밀번호</td>
							  <td class="w-256">
							  	  <input name="passwd" type="password" value="">
							  </td>
							</tr>
					  </tbody>
					</table>
			  		<div class="boardviewinfo">
						<ul class="right btn-style">
							<li>
								<a href="javascript:initPassword();"><spring:message code="button.save" /></a>				                   
				            </li>
							<li>
								<a href="javascript:hideInitPwMenu();"><spring:message code="button.close" /></a>
				            </li>
					 	</ul>
				 	</div>
			  	</div>
			</div>
		</div>	
       	<!-- List -->
		<div id="table">
			<div class="pageinfo">
				<ct:pageInfo />
				<ul class="right btn-style-text">
					<li><a href="javascript:showInitPwMenu();"><spring:message code="button.initPw" /></a></li>
				</ul>
			</div>
			<table class="tbl_list" width="100%" border="0" cellpadding="0" cellspacing="0">
				<thead>
					<tr>
						<th align="center"><spring:message code="member.view.select" /></th>
						<th align="center"><spring:message code="member.view.seq" /></th>
						<th align="center">
							<span class="order" value="<spring:message code="member.value.order.place1"/>">
								<spring:message code="member.view.place1" />
								<img src="/images/cmmn/blank_1x1.png" />
							</span>
						</th>
						<th align="center">
							<span class="order" value="<spring:message code="member.value.order.position"/>">
								<spring:message code="member.view.position" />
								<img src="/images/cmmn/blank_1x1.png" />
							</span>
						</th>
						<th align="center">
							<span class="order" value="<spring:message code="member.value.order.name"/>">
								<spring:message code="member.view.name" />
								<img src="/images/cmmn/blank_1x1.png" />
							</span>
						</th>
						<th align="center">
							<span class="order" value="<spring:message code="member.value.order.loginchk"/>">
								<spring:message code="member.view.isConnected" />
								<img src="/images/cmmn/blank_1x1.png" />
							</span>
						</th>
						<th align="center">
							<span class="order" value="<spring:message code="member.value.order.chkcnt"/>">
								<spring:message code="member.view.isRestricted" />
								<img src="/images/cmmn/blank_1x1.png" />
							</span>
						</th>
						<th align="center"><spring:message code="member.view.finalDate" /></th>
						<th align="center"><spring:message code="member.view.lastLogin" /></th>
					</tr>
				</thead>
				<c:forEach var="result" items="${resultList}" varStatus="status">
					<tr>
						<td align="center"><input type="checkbox" name="targetId" value="${result.userid}"/></td>
						<td align="center"><c:out value="${result.rnum}" /></td>
						<td align="left"><c:out value="${result.place3Str}" /></td>
						<td align="center"><c:out value="${result.positionStr}" /></td>
						<td align="center"><c:out value="${result.name}" /></td>
						<td align="center">
							<c:choose>
								<c:when test="${result.loginchk == 'Y'}">
									<a href="javascript:releaseConnection('${result.userid}');">[접속중]</a>
								</c:when>
								<c:otherwise>
									-
								</c:otherwise>
							</c:choose>
						</td>
						<td align="center">
							<c:choose>
								<c:when test="${result.chkcnt >= 5}">
									<a href="javascript:releaseRestriction('${result.userid}');">[초기화]</a>
								</c:when>
								<c:otherwise>
									-
								</c:otherwise>
							</c:choose>	
						</td>
						<td align="center">
							<c:choose>
								<c:when test="${result.logindate ne null}">
									<c:out value="${result.logindate}" />
								</c:when>
								<c:otherwise>
									-
								</c:otherwise>
							</c:choose>	
						</td>
						<td align="center"><c:out value="${result.recentdate}" /></td>
					</tr>
				</c:forEach>
			</table>
		</div>
		<!-- /List -->
		<div id="paging">
			<ui:pagination paginationInfo="${paginationInfo}" type="image" jsFunction="fn_link_page" />
		</div>
</form:form>
