<%--
  Class Name : EgovAuthorGroupManage.jsp
  Description : EgovAuthorGroupManage List 화면
  Modification Information
 
      수정일         수정자                   수정내용
    -------    --------    ---------------------------
     2009.03.23    lee.m.j              최초 생성
     2011.08.31   JJY       경량환경 버전 생성
 
    author   : 공통서비스 개발팀 lee.m.j
    since    : 2009.03.23
--%>
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Language" content="ko" >
<title>관리자별권한관리</title>
<script type="text/javaScript" language="javascript" defer="defer">
function fncCheckAll() {
    var checkField = document.listForm.delYn;
    if(document.listForm.checkAll.checked) {
        if(checkField) {
            if(checkField.length > 1) {
                for(var i=0; i < checkField.length; i++) {
                    checkField[i].checked = true;
                }
            } else {
                checkField.checked = true;
            }
        }
    } else {
        if(checkField) {
            if(checkField.length > 1) {
                for(var j=0; j < checkField.length; j++) {
                    checkField[j].checked = false;
                }
            } else {
                checkField.checked = false;
            }
        }
    }
}

function fncManageChecked() {
    var resultCheck = false;
    var checkField = document.listForm.delYn;
    var checkId = document.listForm.checkId;
    var selectAuthor = document.listForm.authorManageCombo;
    var booleanRegYn = document.listForm.regYn;
    var listMberTyCode = document.listForm.mberTyCode;
        
    var returnId = "";
    var returnAuthor = "";
    var returnRegYn = "";
    var returnmberTyCode = "";

    var checkedCount = 0;

    if(checkField) {
        if(checkField.length > 1) {
            for(var i=0; i<checkField.length; i++) {
                if(checkField[i].checked) {
                    checkedCount++;
                    checkField[i].value = checkId[i].value;
                    if(returnId == "") {
                        returnId = checkField[i].value;
                        returnAuthor = selectAuthor[i].value;
                        returnRegYn = booleanRegYn[i].value;
                        returnmberTyCode = listMberTyCode[i].value;
                    }
                    else {
                        returnId = returnId + ";" + checkField[i].value;
                        returnAuthor = returnAuthor + ";" + selectAuthor[i].value;
                        returnRegYn = returnRegYn + ";" + booleanRegYn[i].value;
                        returnmberTyCode = returnmberTyCode + ";" + listMberTyCode[i].value;
                        
                    }
                }
            }

            if(checkedCount > 0) 
                resultCheck = true;
            else {
                alert("선택된  항목이 없습니다.");
                resultCheck = false;
            }
            
        } else {
             if(document.listForm.delYn.checked == false) {
                alert("선택 항목이 없습니다.");
                resultCheck = false;
            }
            else {
                returnId = checkId.value;
                returnAuthor = selectAuthor.value;
                returnRegYn = booleanRegYn.value;
                returnmberTyCode = listMberTyCode.value;

                resultCheck = true;
            }
        } 
    } else {
        alert("조회된 결과가 없습니다.");
    }
    
    document.listForm.userIds.value = returnId;
    document.listForm.authorCodes.value = returnAuthor;
    document.listForm.regYns.value = returnRegYn;
    document.listForm.mberTyCodes.value = returnmberTyCode ;
    return resultCheck;
}

function fncSelectAuthorGroupList(){
	<c:if test="${!empty loginId}">
	if(""!= document.listForm.searchKeyword.value){
		updateRecentSearch();//최근검색어 등록	
	}
	</c:if>
	linkPage(1);
}

function fncAddAuthorGroupInsert() {
    if(!fncManageChecked()) return;
    if(confirm("수정하시겠습니까?")) {
        document.listForm.action = "<c:url value='/sec/rgm/EgovAuthorGroupInsert.do'/>";
        document.listForm.submit();
    }
}

function fncAuthorGroupDeleteList() {
    if(!fncManageChecked()) return;
    if(confirm("등록취소 하시겠습니까?")) {
        document.listForm.action = "<c:url value='/sec/rgm/EgovAuthorGroupDelete.do'/>";
        document.listForm.submit(); 
    }
}

function linkPage(pageNo){
	var listForm = document.listForm ;
	listForm.pageIndex.value = pageNo ;
	listForm.searchCondition.value = $('#searchCondition').val();
	if($('#searchConditionSite').length != 0){
		listForm.searchConditionSite.value = $('#searchConditionSite').val();	
	}
	listForm.searchKeyword.value = $('#searchKeyword').val();
	listForm.action = "<c:url value='/sec/rgm/EgovAuthorGroupList.do'/>";
	listForm.submit();
}

function fncSelectAuthorGroupPop() {

    if(document.listForm.searchCondition.value == '3') {
        window.open("<c:url value='/sec/gmt/EgovGroupSearchView.do'/>","notice","height=500, width=800, top=50, left=20, scrollbars=no, resizable=no");
    } else {
        alert("그룹을 선택하세요.");
        return;
    }
}

function onSearchCondition() {
    document.listForm.searchKeyword.value = "";
    if(document.listForm.searchCondition.value == '3') {
        document.listForm.searchKeyword.readOnly = true;
    } else {
        document.listForm.searchKeyword.readOnly = false;
    }
}

function press() {

    if (event.keyCode==13) {
        fncSelectAuthorGroupList();
    }
}
</script>
</head>
<body>
<form:form id="listForm" name="listForm" action="<c:url value='/sec/rgm/EgovAuthorGroupList.do'/>" method="post">
	<input type="hidden" name="userId"/>
	<input type="hidden" name="userIds"/>
	<input type="hidden" name="authorCodes"/>
	<input type="hidden" name="regYns"/>
	<input type="hidden" name="mberTyCodes"/>
	<input type="hidden" name="pageIndex" value="<c:out value='${authorGroup.pageIndex}' default='1' />"/>
	<input type="hidden" name="searchSortCnd" value="<c:out value="${authorGroup.searchSortCnd}" />" />
	<input type="hidden" name="searchSortOrd" value="<c:out value="${authorGroup.searchSortOrd}" />" />
	
	<!-- cont -->
	<div class="contWrap">
		<div class="pageTitle">
			<div class="pageIcon"><img src="/pb/img/pageTitIcon4.png" alt=""></div>
			<h2 class="titType1 c_222222 fwBold">관리자별권한관리</h2>
			<p class="tType6 c_999999">관리자별권한을 현황을 파악할 수 있으며, 권한을 변경할 수 있습니다.</p>
		</div>
		<div class="pageCont">
			<div class="listSerch">
				<c:if test="${siteId eq 'super'}">
					<select name="searchConditionSite" id="searchConditionSite" title="검색조건2-검색어구분">
						<option value="" <c:if test="${empty authorGroup.searchConditionSite }">selected="selected"</c:if> >전체 사이트</option>
	                	<c:forEach var="result" items="${siteManageList}" varStatus="status">
	                		<option value="${result.siteId}" <c:if test="${result.siteId eq authorGroup.searchConditionSite }">selected="selected"</c:if> >${result.siteNm}</option>
	                	</c:forEach>
					</select>
				</c:if>
				<!-- <select id="searchCondition" name="searchCondition" onchange="onSearchCondition()" title="조회조건"> --> <!-- onSearchCondition용도를 모르겠어서 주석 220527 이지우 -->
				<select id="searchCondition" name="searchCondition" title="조회조건">
					 <option value="" <c:if test="${authorGroup.searchCondition == ''}">selected</c:if> >전체</option>
	                 <option value="1" <c:if test="${authorGroup.searchCondition == '1'}">selected</c:if> >아이디</option>
	                 <option value="2" <c:if test="${authorGroup.searchCondition == '2'}">selected</c:if> >관리자명</option>
	            </select>
				<input type="text" id=searchKeyword name="searchKeyword" class="recentSearch" value="<c:out value='${authorGroup.searchKeyword}'/>" size="40" title="검색" onkeydown="press();" />
				<input type="button" class="btnType1" onclick="fncSelectAuthorGroupList(); return false;" value="검색">
			</div>
			<div class="listTop">
				<p class="tType5">총 <span class="tType4 c_456ded fwBold"><fmt:formatNumber value="${paginationInfo.totalRecordCount}" pattern="#,###" /></span>건</p>
				<div class="rightWrap">
					<!-- <input type="button" class="printBtn" > -->
					<select name="pageUnit" id="pageUnit" class="select" title="검색조건선택" onchange="linkPage(1);">
					   <option value='10' <c:if test="${authorGroupVO.pageUnit == '10' or authorGroupVO.pageUnit == ''}">selected</c:if>>10줄</option>
					   <option value='20' <c:if test="${authorGroupVO.pageUnit == '20'}">selected</c:if>>20줄</option>
					   <option value='30' <c:if test="${authorGroupVO.pageUnit == '30'}">selected</c:if>>30줄</option>
					</select>
				</div>
			</div>
			<div class="tableWrap">
				<table class="tbType1">
					<colgroup>
						<col style="width: 10%">
						<col style="width: 18%">
						<col style="width: 30%">
						<col style="width: 10%">
						<col style="width: 25%">
						<col style="width: 10%">
					</colgroup>
					<thead>
						<tr>
							<th><input type="checkbox" name="checkAll" id="checkAll" onclick="fncCheckAll();" /><label for="checkAll"></label></th>
							<th>번호<input type="button" class="sort sortBtn" id="sort_ESNTL_ID"></th>
							<th>아이디<input type="button" class="sort sortBtn" id="sort_USER_ID"></th>
							<th>관리자명<input type="button" class="sort sortBtn" id="sort_USER_NM"></th>
							<th>권한<input type="button" class="sort sortBtn" id="sort_AUTHOR_CODE"></th>
							<th>등록여부<input type="button" class="sort sortBtn" id="sort_REG_YN"></th>
						</tr>
					</thead>
					<tbody>
						<c:forEach var="authorGroup" items="${authorGroupList}" varStatus="status">
						<tr>
							<td>
								<input type="checkbox" name="delYn" id="<c:out value="${authorGroup.userId}"/>"><label for="<c:out value="${authorGroup.userId}"/>"></label>
								<input type="hidden" name="checkId" value="<c:out value="${authorGroup.uniqId}"/>"/>
							</td>
							<td>
								<c:if test="${authorGroupVO.searchSortOrd eq 'desc' }">
		                			<c:out value="${ ( paginationInfo.totalRecordCount - ((authorGroupVO.pageIndex -1)*authorGroupVO.pageUnit) ) - status.index }"/>
			                	</c:if>
			                	<c:if test="${authorGroupVO.searchSortOrd eq 'asc' }">
									<c:out value="${(authorGroupVO.pageIndex - 1) * authorGroupVO.pageUnit + status.count}"/>                		
			                	</c:if>
							</td>
							<c:if test="${siteId eq 'super'}">
								<td>
									<c:forEach var="siteManageList" items="${siteManageList}" varStatus="status">
										<c:if test="${authorGroup.siteId eq siteManageList.siteId}">
											<c:out value="${siteManageList.siteNm}"/>
										</c:if>
									</c:forEach>
								</td>
							</c:if>
							<td><c:out value="${authorGroup.userId}"/></td>
							<td><c:out value="${authorGroup.userNm}"/>
								<input type="hidden" name="mberTyCode" value="${authorGroup.mberTyCode}"/>
							</td>
							<td>
								<select name="authorManageCombo" title="권한">
						            <c:forEach var="authorManage" items="${authorManageList}" varStatus="status">
						            	<c:if test="${authorManage.authorCode ne 'ROLE_CHAIRMAN' }"> <!-- 이사장권한 제외 -->
						            		<option value="<c:out value="${authorManage.authorCode}"/>" <c:if test="${authorManage.authorCode == authorGroup.authorCode}">selected</c:if> ><c:out value="${authorManage.authorNm}"/></option>
						            	</c:if>
						            </c:forEach>
						        </select>
							</td>
							<td>
								<c:out value="${authorGroup.regYn}"/>
		                        <input type="hidden" name="regYn" value="<c:out value="${authorGroup.regYn}"/>">
		                    </td>
						</tr>
						</c:forEach>
						<c:if test="${empty authorGroupList}">
		         			<tr><td colspan="8"><spring:message code="common.nodata.msg" /></td></tr>
		         		</c:if>
					</tbody>
				</table>
			</div>
			<div class="btnWrap">
				<input type="button" class="btnType2"  onclick="fncAuthorGroupDeleteList(); return false;" value="삭제">
				<input type="button" class="btnType1"  onclick="fncAddAuthorGroupInsert(); return false;" value="수정">
			</div>
			<!-- 페이지 네비게이션 시작 -->
			<c:if test="${!empty authorGroupList}">
			<div class="page">
				<ul class="inline">
					<ui:pagination paginationInfo = "${paginationInfo}"  type="image" jsFunction="linkPage" />
				</ul>
			</div>
			</c:if> 
			<!-- //페이지 네비게이션 끝 -->
		</div>
	</div>
	<!-- //cont -->
</form:form>
<c:import url="/uss/umt/IncInfoProtect.do" />    	
</body>
</html>