<%@page import="java.util.StringTokenizer"%>
<%@page import="kr.co.kihyun.beans.tosys.etc1.TotsysEtc"%>
<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.moumi.Moumi" import="kr.co.kihyun.lang.MLong"
	import="kr.co.kihyun.lang.Encoder"
	import="kr.co.kihyun.beans.user.UserGroup"
	import="kr.co.kihyun.beans.user.Dept"
	import="kr.co.kihyun.beans.user.User"%>

<%@ include file="/totsys/common/inc/sec/secure.inc.jsp"%>

<%
String groupID = request.getParameter("groupID");

	UserGroup deptList = new UserGroup();
	deptList.userSetting(groupID);

	String[] deptIDList = deptList.getDeptID(groupID);
	String[] deptNameList = deptList.getDeptName(groupID);
	String[] userNameList = deptList.getUserUserName();
	String[] userDeptIDList = deptList.getUserDeptID();
	String[] userIDList = deptList.getUserUserID();
	boolean[] userValidList = deptList.getUserValid();
	String[] finalDeptNameList = null;
	String[] finalUserNameList = null;
	String[] valueUserNameList = null;
	int deptCount = deptList.getDeptCount(groupID);
	int userCount = deptList.getUserCount();

	Dept dept = new Dept();
	String deptNames = "";
	String userNames = "";


	for(int dc = 0; dc < deptCount; dc++){
		if(dc == 0){
			if(deptNameList[dc].indexOf("-")==-1){
				deptNames = dept.getPartName(deptIDList[dc])+"-"+deptNameList[dc];

			}else{
				deptNames = deptNameList[dc];
			}
		}else{
			if(deptNameList[dc].indexOf("-")==-1){
				deptNames = deptNames+","+dept.getPartName(deptIDList[dc])+"-"+deptNameList[dc];

			}else{
				deptNames = deptNames+","+deptNameList[dc];
			}
		}
	}

	for(int uc = 0; uc < userCount; uc++){
		if(uc == 0 && deptCount==0){
			if(userNameList[uc].indexOf("-")==-1){
				userNames = dept.getPartName(userDeptIDList[uc])+"-"+userNameList[uc];

			}else{
				userNames = userNameList[uc];
			}
		}else{
			if(userNameList[uc].indexOf("-")==-1){
				userNames = userNames+","+dept.getPartName(userDeptIDList[uc])+"-"+userNameList[uc];

			}else{
				userNames = userNames+","+userNameList[uc];
			}
		}
	}

	if(deptCount!=0){
		if(deptNames.substring(0,1).equals(","))
			deptNames=deptNames.substring(1,deptNames.length());
	}
	if(userCount!=0){
		if(userNames.substring(0,1).equals(","))
			userNames=userNames.substring(1,userNames.length());
	}

	if(deptCount!=0){
		if(deptNames.indexOf(',')!=0){
			finalDeptNameList = deptNames.split(",");
		}else{
			finalDeptNameList[0] = deptNames;
		}
	}

	if(userCount!=0){
		if(userNames.indexOf(',')!=0){
			finalUserNameList = userNames.split(",");
		}else{
			finalUserNameList[0] = userNames;
		}
	}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0032)http://localhost/schoollist.html -->
<HTML>
<HEAD>
<META http-equiv=Content-Type
	content="text/html; charset=UTF-8">
<META content="MSHTML 6.00.2800.1276" name=GENERATOR>
<link rel="stylesheet" href="/totsys/common/css/text.css" type="text/css">




<script type="text/javascript" src="/totsys/common/js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
	jQuery(function(){
		$("[name=allCheck]").click(function() {
			if($("[name=allCheck]").is(":checked")) $("[class=box_class]").attr("checked","checked");
			else $("[class=box_class]").removeAttr("checked");
		});
	});
</script>





<script language="javascript">
//	var idList = parent.opener.document.list.idList.value;
//	var nameList = parent.opener.document.list.nameList.value;
	var deptNameList = "<%=deptNames%>";
	var userNameList = "<%=userNames%>";

	if(userNameList=="" && deptNameList=="")
	{
		alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.notMember")%>');
		parent.window.close();
	}

	function groupSelect(){

		var nameList = "";
		var types = "";
		var ids = "";

		<%if(userCount == 0 && deptCount > 0){%>

			<%for(int i = 0; i <deptCount;  i++){%>
				if(document.AddrList.check_<%=deptIDList[i]%>.checked==true){
					<%if(i==0){%>
						ids = document.AddrList.check_<%=deptIDList[i]%>.value;
						nameList = document.AddrList.hidden_<%=deptIDList[i]%>.value;
						types = "dept";
					<%}else{%>
						ids = ids+","+document.AddrList.check_<%=deptIDList[i]%>.value;
						nameList = nameList+","+document.AddrList.hidden_<%=deptIDList[i]%>.value;
						types = types +",dept";
					<%}%>
				}
			<%}%>

		<%}else if(userCount > 0 && deptCount == 0){%>
			<%for(int i = 0; i <userCount;  i++){%>
				if(document.AddrList.check_<%=i%>.checked==true){
					<%if(i==0){%>
						ids = document.AddrList.check_<%=i%>.value;
						nameList = document.AddrList.hidden_<%=i%>.value;
						types = "user";
					<%}else{%>
						ids = ids+","+document.AddrList.check_<%=i%>.value;
						nameList = nameList+","+document.AddrList.hidden_<%=i%>.value;
						types = types+",user";
					<%}%>
				}
			<%}%>

		<%}else if(userCount > 0 && deptCount > 0){%>
			<%for(int i = 0; i <deptCount;  i++){%>
				if(document.AddrList.check_<%=deptIDList[i]%>.checked==true){
					<%if(i==0){%>
						ids = document.AddrList.check_<%=deptIDList[i]%>.value;
						nameList = document.AddrList.hidden_<%=deptIDList[i]%>.value;
						types = "dept";
					<%}else{%>
						ids = ids+","+document.AddrList.check_<%=deptIDList[i]%>.value;
						nameList = nameList+","+document.AddrList.hidden_<%=deptIDList[i]%>.value;
						types = types+",dept";
					<%}%>
				}
			<%}%>
			<%for(int i = 0; i <userCount;  i++){%>
				if(document.AddrList.check_<%=i%>.checked==true){
					<%if(i==0){%>
						ids = ids+","+document.AddrList.check_<%=i%>.value;
						nameList = nameList+","+document.AddrList.hidden_<%=i%>.value;
						types = types+",user";
					<%}else{%>
						ids = ids+","+document.AddrList.check_<%=i%>.value;
						nameList = nameList+","+document.AddrList.hidden_<%=i%>.value;
						types = types+",user";
					<%}%>
				}
			<%}%>

		<%}%>
		if(ids.substring(0,1)==","){
			ids=ids.substring(1,ids.length);
		}
		if(nameList.substring(0,1)==","){
			nameList=nameList.substring(1,nameList.length);
		}
		if(types.substring(0,1)==","){
			types=types.substring(1,types.length);
		}

		/*alert(ids);
		alert(nameList);
		alert(types);*/

		parent.group.ids.value = ids;
		parent.group.names.value = nameList;
		parent.group.types.value = types;

	}

</script>


</HEAD>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="5" topmargin="5"
	marginwidth="0" marginheight="0">
<form name=AddrList method=Post>
<table border=0 cellpadding=5 cellspacing=2 width=100%>
	<tr>
		<td style="font-family: 돋움; font-size: 12px;"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.setGroup")%>(<script
			language="javascript">
						document.write(<%=deptCount+userCount%>);
					</script>) :</td>
	</tr>
	<tr>
		<td style="font-family: 돋움; font-size: 12px;">
			<input type="checkbox" class="box_class" name="allCheck" checked>전체선택
		</td>
	</tr>
	<tr>





		<td style="font-family: 돋움; font-size: 12px;">
		<%if(userCount == 0 && deptCount > 0)
		{
            String[] tmpArray=null;
            tmpArray=new TotsysEtc().getGroupElement(deptIDList);
            if(tmpArray!=null && tmpArray.length>0)
            {
   %>
		<%for(int i=0; i< tmpArray.length; i++)
			{
                if(tmpArray[i]==null) continue;
                StringTokenizer stkNames = new StringTokenizer(tmpArray[i],"*");
                String tmpStr1=stkNames.nextToken();
                String tmpStr2=stkNames.nextToken();
        %>
		<input type="checkbox" class="box_class" name="check_<%=tmpStr1%>"
			value="<%=tmpStr1%>" checked><%=tmpStr2%><br>
		<input type="hidden" name="hidden_<%=tmpStr1%>"
			value="<%=tmpStr2%>">
          <%}%>
		<%}%>
        <%}











	else if(userCount > 0 && deptCount == 0)
	{%>
		<%for(int i=0; i< userCount; i++)
		{
				String tmpStr=new Dept().getPartName(userDeptIDList[i])+"-"+new Dept().getUpperDeptName(userDeptIDList[i])+"-"+new Dept().getName(userDeptIDList[i]);
			%>
			<input type="checkbox" class="box_class" name="check_<%=i%>" value="<%=userIDList[i]%>/<%=userDeptIDList[i]%>"
			<%if(userValidList[i]){%> checked <%}%>><font
			color="<%if(userValidList[i]){%>black<%}else{%>red<%}%>"><%=tmpStr%>/<%= new User().getName(userIDList[i]) %></font><br>
		<input type="hidden" name="hidden_<%=i%>"
			value="<%=tmpStr%>/<%= new User().getName(userIDList[i]) %>">
		<%}%> <
		%}else if(userCount > 0 && deptCount > 0){%> <%for(int i=0; i< deptCount; i++)
			{
				String tmpStr=new Dept().getPartName(deptIDList[i])+"-"+new Dept().getUpperDeptName(deptIDList[i])+"-"+new Dept().getName(deptIDList[i]);
				%>
		<input type="checkbox" class="box_class" name="check_<%=deptIDList[i]%>"
			value="<%=deptIDList[i]%>" checked><%=tmpStr%><br>
		<input type="hidden" name="hidden_<%=deptIDList[i]%>"
			value="<%=tmpStr%>">
		<%}%>
		<%for(int i=0; i< userCount; i++)
		{
			String tmpStr=new Dept().getPartName(userDeptIDList[i])+"-"+new Dept().getUpperDeptName(userDeptIDList[i])+"-"+new Dept().getName(userDeptIDList[i]);
			%> <input type="checkbox" class="box_class" name="check_<%=i%>" value="<%=userIDList[i]%>/<%=userDeptIDList[i]%>"
			<%if(userValidList[i]){%> checked <%}%>><font
			color="<%if(userValidList[i]){%>black<%}else{%>red<%}%>"><%=tmpStr%>/<%= new User().getName(userIDList[i]) %></font><br>
		<input type="hidden" name="hidden_<%=i%>"
			value="<%=tmpStr%>/<%= new User().getName(userIDList[i]) %>">
		<%}%> <%}%>
		</td>


	</tr>
</table>
</form>
</body>
</HTML>

