
<%
/************************************************************@@
  * Program Name	: group_dept_list.jsp
  * Description		: 사용자정의 그룹변경
  * Author			: 기현테크
  * Create Date		: 2010-11-27
  * History			:
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.lang.MString" import="kr.co.kihyun.lang.MInteger"
	import="kr.co.kihyun.lang.MLong" import="kr.co.kihyun.moumi.Moumi"
	import="java.net.URLDecoder" import="kr.co.kihyun.lang.Encoder"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.beans.user.UserGroup"
	import="kr.co.kihyun.beans.user.UserGroupList"
	import="kr.co.kihyun.beans.user.Dept"
	import="kr.co.kihyun.beans.user.User"%>

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

<%
	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);

	/****** Parameter ******/
	String groupID = request.getParameter("groupID");
        //28.크로스사이트 스크립트(Reflected)_CWE-80 : Add by KWON,HAN
        if (groupID !=null) {
            groupID = groupID.replaceAll("<","&lt");
            groupID = groupID.replaceAll(">","&gt");     
        }
        //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++          
        
	String groupName = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("groupName"))),"");


        //LJH
        //String groupName=clearXSS(URLDecoder.decode(request.getParameter("groupName"), "UTF-8"),"");

        
  
	/****** 해당 그룹의 부서 사용자 가져오기 ******/
	String deptIDs = "";
	String deptNames = "";
	String userIDs = "";
	String userNames = "";
	String deptTypes = "";
	String validTypes = "";
	
	//부서리스트 가져오기
	UserGroup ugroup = new UserGroup();
	String[] idList = ugroup.getDeptID(groupID);
	String[] nameList = ugroup.getDeptName(groupID);

	String dTypes = "";
	if(idList != null){	
		for(int i=0; i < idList.length; i++){
			if( i == 0 ){
				deptIDs = deptIDs + idList[i];
				//deptNames = deptNames + nameList[i];
				deptNames = deptNames + new Dept().getPartName(idList[i])+"-"+new Dept().getUpperDeptName(idList[i])+"-"+new Dept().getName(idList[i]);
				dTypes = "dept";
				validTypes = "1"+"@@@@"+idList[i];
			}else{
				deptIDs = deptIDs + "," + idList[i] ;
				//deptNames = deptNames + "," + nameList[i] ;
				deptNames = deptNames + "," + new Dept().getPartName(idList[i])+"-"+new Dept().getUpperDeptName(idList[i])+"-"+new Dept().getName(idList[i]);
				dTypes = dTypes + ",dept";
				validTypes = validTypes+","+"1"+"@@@@"+idList[i];
			}
		}
	}

	//개인리스트 가져오기
	ugroup.userSetting(groupID);
	String[] userUserID = ugroup.getUserUserID();
	String[] userUserName = ugroup.getUserUserName();
	String[] userDeptID = ugroup.getUserDeptID();
	String uTypes = "";
	
	if(userUserID != null){
		for(int i=0; i<userUserID.length; i++){ 
			if(i==0){
				userIDs = userUserID[i]+"/"+userDeptID[i];
				//userNames = userUserName[i];
				userNames = new Dept().getPartName(userDeptID[i])+"-"+new Dept().getUpperDeptName(userDeptID[i])+"-"+new Dept().getName(userDeptID[i])+"/"+new User().getName(userUserID[i]);
				uTypes = "user";
				if(validTypes.length() == 0){
					validTypes = new UserGroupList().getVaild(groupID,userUserID[i])+"/"+userUserID[i]+"/"+userDeptID[i];
				}else{
					validTypes = validTypes+","+new UserGroupList().getVaild(groupID,userUserID[i])+"@@@@"+userUserID[i]+"/"+userDeptID[i];
				}
			}else{
				userIDs += ","+ userUserID[i]+"/"+userDeptID[i];
				//userNames += ","+userUserName[i];
				userNames += ","+new Dept().getPartName(userDeptID[i])+"-"+new Dept().getUpperDeptName(userDeptID[i])+"-"+new Dept().getName(userDeptID[i])+"/"+new User().getName(userUserID[i]);
				uTypes = uTypes + ",user";
				validTypes = validTypes+","+new UserGroupList().getVaild(groupID,userUserID[i])+"@@@@"+userUserID[i]+"/"+userDeptID[i]; 
			}
		}
	}

	if(!deptIDs.equals("") && !userIDs.equals("")){
		deptIDs = deptIDs + "," + userIDs;
		deptNames = deptNames + "," + userNames;
		deptTypes = dTypes + "," + uTypes;
	}else{
		deptIDs = deptIDs + userIDs;
		deptNames = deptNames + userNames;
		deptTypes = dTypes + uTypes;
	}

%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>제출부서 선택</TITLE>

<style>
a:link {
	font-style: none;
	line-height: normal;
	color: #004080;
	text-decoration: none;
}

a:visited {
	font-style: none;
	line-height: normal;
	color: #3366CC;
	text-decoration: none;
}

a:active {
	font-style: none;
	line-height: normal;
	color: #535353;
	text-decoration: none;
}

a:hover {
	font-style: none;
	line-height: normal;
	color: #FF6600;;
	text-decoration: none;
}

img {
	border: none;
}
</style>
<script Language="javascript">

		var tstate = false;
		var delstate = false;
		var userGroup = false; // 사용자정의 그룹인지 여부지정 변수

		var selid=''; // 지금 선택한 부서
		var selname='';
		var seltype='';
		var idList = ''; // 선택되어진 부서 리스트
		var nameList = '';
		var typeList = '';
		var validList = '';
		var convertValidList = '';

			// 부서 추가
			function setDepts(){
					document.list.idList.value = idList = "<%=deptIDs%>";
					idList=idList+"";
					document.list.nameList.value = nameList = "<%=deptNames%>";
					nameList=nameList+"";
					document.list.typeList.value = typeList = "<%=deptTypes%>";
					typeList=typeList+"";
					document.list.validList.value = "<%=validTypes%>";
					

					if(idList != "")
						document.list.submit();
			}

			// 부서 추가
			function deptConfirm(){
                
				if(selid == '' ){
					alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptConfirm")%>');
				}else if(seltype == "group"){
                            modSelect();

		}
                else{
						id = selid;
						name = selname;
						type = seltype;

						if(	idList == '' )
                        {
							document.list.idList.value = idList = id;
							idList=idList+"";
							document.list.nameList.value = nameList = name;
							nameList=nameList+"";
							document.list.typeList.value = typeList = type;
							typeList=typeList+"";

							document.list.validList.value = validList="<%="1"%>@@@@"+id+"";
						}
                        else
                        {
							var isAdd = listAdd(idList, id, typeList, type);
							document.list.idList.value = idList;
							document.list.typeList.value = typeList;
							if(isAdd){
								listAddn(nameList, name);
						}
							document.list.nameList.value = nameList;
							convertValidList = idList.split(",");
							document.list.validList.value = document.list.validList.value+",<%="1"%>@@@@"+convertValidList[convertValidList.length-1];
					}
					document.list.submit();
				}	
			}

			function listAdd(idList1, idList2, tList, tItem){
				var arrayID1 = idList1.split(",");
				var arrayType = tList.split(",");

				var isEquals = true;
				
				if(idList1 == ''){	
					idList = idList1;
					typeList = tList;
					return false;
				}
				for(var i=0; i < arrayID1.length; i++){
					if(idList2 == arrayID1[i] && tItem == arrayType[i]){
						isEquals = false;
						break;
					}
				}
				if(isEquals){
					idList1 += ","+idList2;
					tList += ","+tItem;
				}				
				idList = idList1;
				typeList = tList;
				return isEquals;
			}

			function listAddn(nameList1, nameList2){
				var arrayName1 = nameList1.split(",");

				if(nameList1 == ''){
					nameList = nameList1;
					return;
				}

				nameList1 += ","+nameList2;
				nameList = nameList1;
				
				return;
			}

			// 부서삭제
			function deptDelete(){
				if(idList != '' ){
					deptFrame.movelist();
					document.list.submit();
				}
			}

			function leftFrameDel(name, id, type){
				name = lastStrDel(name, ",");
				id = lastStrDel(id, ",");
				type = lastStrDel(type, ",");
				if(nameList == '' && idList == ''){
					document.list.nameList.value = nameList = name;					
					document.list.idList.value = idList = id;
					document.list.typeList.value = typeList = type;
					
				}else{
					delList(id, name, type);
					document.list.nameList.value = nameList;	
					document.list.idList.value = idList;
					document.list.typeList.value = typeList;





				}
				
				tstate = true;

				document.list.submit();
				return;
			}
			function leftFrameDel(name, id, type, valid){
				name = lastStrDel(name, ",");
				id = lastStrDel(id, ",");
				type = lastStrDel(type, ",");
				valid = lastStrDel(valid, ",");
				
				if(nameList == '' && idList == ''){
					document.list.nameList.value = nameList = name;					
					document.list.idList.value = idList = id;
					document.list.typeList.value = typeList = type;
					document.list.validList.value = validList = valid;
					
					
				}else{
					delList(id, name, type, valid);
					document.list.nameList.value = nameList;	
					document.list.idList.value = idList;
					document.list.typeList.value = typeList;
					document.list.validList.value = validList = valid;
				}
				
				tstate = true;

				document.list.submit();
				return;
			}	
			function delList(idList1, naList1, tyList1){
				idList = idList1;
				nameList = naList1;	
				typeList = tyList1;
				return;
			}
			function delList(idList1, naList1, tyList1, valList1){
				idList = idList1;
				nameList = naList1;	
				typeList = tyList1;
				validList = valList1;
				return;
			}
			function lastStrDel(str, delStr){
				var lastStr = str.lastIndexOf(delStr);
				return str.substring(0, lastStr);				
			}


			// 부서 선택 시 유저 뽑아내기.
			function userList(id, name, type){
				if(type != '') {
					idAll=id;
					selid = id;
					selname = name;
				} else {
					idAll='';
					selid = '';
					selname = '';
				}
				seltype = type;
				idUpper = false;
				userGroup = false;
/*
				document.userlist.id.value = id;
				document.userlist.target="rightFrame";
				document.userlist.selectType.value="right";
				document.userlist.didList.value = idList;

				document.userlist.submit();
*/
			}
			function groupList(id, name, type){
				idAll=id;
				selid = id;
				selname = name;
				seltype = type;
				idUpper = false;
				userGroup = false;
/*
				document.userlist.id.value = id;
				document.userlist.target="rightFrame";
				document.userlist.selectType.value="right";
				document.userlist.didList.value = idList;

				document.userlist.submit();
*/
			}

			function modSelect() {
				var height = screen.height; 
				var width = screen.width; 
				var leftpos = width / 2 - 235; 
				var toppos = height / 2 - 235; 

				if(seltype != "group"){
					alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.groupSelect")%>');
					return;
				}

				var urlname = "/totsys/common/web/report_dept/modifier.jsp?groupID="+selid;
				post2= window.open(urlname, "post2","width=450, height=465, toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,left=" + leftpos + ",top=" + toppos);
				post2.focus(); 
			}

			function deptComp(){
				if(document.group.groupName.value == null || document.group.groupName.value == ""){
					alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.groupName")%>');
					document.group.groupName.focus();
				}else if(document.list.idList.value=="")
				{
					alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptComp")%>');
					return;
				}
				else{

					document.group.deptIDs.value = document.list.idList.value;
					document.group.deptNames.value = document.list.nameList.value;
					document.group.deptTypes.value = document.list.typeList.value;
					document.group.valid.value = document.list.validList.value;

					var deptTemp = document.list.idList.value.split(",");
					var deptCounter = deptTemp.length;

					document.group.submit();
					//window.close();
				}
			}

			function deptCancel(){
				window.close();
			}

function openerdeptConfirm(){ //구성원으로 추가
		var gid = document.list.openeridList.value;
		var gname = document.list.openernameList.value;
		var gtype = document.list.openertypeList.value;

		var arrayID = gid.split(",");
		var arrayName = gname.split(",");
		var arrayType = gtype.split(",");

		var isChange = false;

		for(var i=0; i < arrayID.length; i++){
			selid = arrayID[i];
			selname = arrayName[i];
			seltype = arrayType[i];


			if(selid == '' )
            {
				alert("<%=Moumi.getMessageBundle().getString("moumi.message.popup.deptConfirm")%>");
			}else
            {
				id = selid;
				name = selname;
				type = seltype;
				if(	idList == '' )
                {
					document.list.idList.value = idList = id;
					idList=idList+"";
					document.list.typeList.value = typeList = type;
					typeList=typeList+"";

				}
                else
                {
					var isAdd = listAdd(idList, id, typeList, type);
					document.list.idList.value = idList;
					document.list.typeList.value = typeList;
				}
				isChange = true;
			}
		}


		if(isChange){



        var str=document.list.idList.value.split(",");
   
        var strtmp=new Array();
        for(var jj=0;jj<str.length;jj++)
        {
            strtmp[jj]="1@@@@"+str[jj];
        }
               
        document.list.validList.value=strtmp.join(',');
       
        document.list.submit();
		}
	}
	</script>
<link rel="stylesheet" href="/totsys/common/css/kecttep.css" type="text/css">   
</HEAD>

<BODY onload="setDepts();">

<form name="list" method="post"
	action="/servlet/kr.co.kihyun.beans.user.HttpDeptList"
	target="deptFrame"><input type="hidden" name="idList"> <input
	type="hidden" name="nameList"> <input type="hidden"
	name="typeList"><input type="hidden" name="validList"> <input
    type="hidden" name="openeridList"> <input
    type="hidden" name="openernameList"> <input type="hidden"
	name="openertypeList"></form>

<!--
 		<form name="glist" method="post" action="/servlet/kr.co.kihyun.beans.user.HttpGroupList" target="deptFrame">
			<input type="hidden" name="nameList">
			<input type="hidden" name="idList">
		</form>
		-->
<form name="group" method="post"
	action="/servlet/kr.co.kihyun.beans.user.HttpUserGroupModify"><input
	type="hidden" name="deptIDs"> <input type="hidden"
	name="deptNames"> <input type="hidden" name="userIDs">
<input type="hidden" name="userNames"> <input type="hidden"
	name="deptTypes"> <input type="hidden" name="userID"
	value="<%=usID%>"> <input type="hidden" name="partID"
	value="<%=groupID%>"> <input type="hidden" name="valid">
	
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
    <td align="center" >
	<!--//타이틀 -->
	<table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
          <td bgcolor="728ab5" style="padding: 10 20 5 20"><strong><font color="#FFFFFF">제출기관지정</font></strong></td>
  </tr></table>
  <!--타이틀 //-->
 	<!-- //본문 -->
      <table  width="98%" border="0" cellpadding="0" cellspacing="0" bordercolor="#FF00FF">
        <!-- 제목 -->
        <tr > 
          <td colspan="3"> 
		  <table width="100%" height="26" border="0" cellpadding="0" cellspacing="0" style="padding-top:10px ; padding-bottom:10px">
              <tr> 
                <td width="300" ><img src="/totsys/common/images/ico_3.gif"  border="0" align="absmiddle">&nbsp;<b><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.deptMap")%></b></td>
                <td  align="left" width="100" ></td>
                <td width="470"><img src="/totsys/common/images/ico_3.gif"  border="0" align="absmiddle">&nbsp;<b><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.submitDept")%></b></td>
              </tr>
            </table></td>
        </tr>
        <!-- 분류,부서 선택 -->
        <tr> 
          <td width="300"> 
            <!-- 분류 선택 아이프레임 -->
            <table border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td><iframe src="iframe/new_section_list.html" width="230"
					height="21" frameborder="0" scrolling="no"> </iframe></td>
              </tr>
            </table>
            <!-- 부서 선택 아이프레임 -->
            <table border="1px" bordercolor="#e3e3e3" class="kecttep_tdmenu"
			width="300" cellpadding="0" cellspacing="0">
              <tr> 
                <td><iframe name="leftFrame" src="./iframe/group_list.jsp"
					width="300" height="360" frameborder="0"></iframe></td>
              </tr>
            </table></td>
          <!-- 추가,삭제 -->
          <td width="80" align="center" style=" line-height:20px"> <table border="0" cellspacing="0" cellpadding="0" widht=50  >
              <!--추가-->
              <tr> 
                <td height="40" style="padding-left: 10px; padding-right: 10px"><A
					href="javascript:deptConfirm();" border="0"><img
					src="./images/new_dept_add.gif"></a></td>
              </tr>
              <!--삭제-->
              <tr> 
                <td height="40" style="padding-left: 10px; padding-right: 10px"><A
					href="javascript:deptDelete();" border="0"><img
					src="./images/new_dept_del.gif"></a></td>
              </tr>
              <!--구성원-->
              <tr> 
                <td height="40" style="padding-left:10px; padding-right:10px"> <A href="javascript:modSelect();" border="0"><img src="./images/new_modifier.gif"></a> 
                </td>
              </tr>
            </table></td>
          <!-- 선택 된 아이프레임 -->
          <td width="470" style="padding-top: 20px;"> <table border="1px" bordercolor="#e3e3e3" class="kecttep_tdmenu"
			width="470" cellpadding="0" cellspacing="0">
              <tr> 
                <td width="47"><iframe name="deptFrame" src="./iframe/selected_list.jsp"
					width="470" height="365" frameborder="0"></iframe></td>
              </tr>
            </table></td>
        </tr>
        <tr style="padding-top: 20px;" > 
          <td colspan="6" >
          <table border="0" width="100%" cellpadding="0" cellspacing="0">
            <tr> 
              <td style="width: 14"><img src="/totsys/common/images/ico_3.gif"  border="0" align="absmiddle"></td>
              <td class="kecttep_title" style="padding-left: 5" align="left"
					width="355"><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.group")%><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.name")%> 
                : 
                <input name="groupName" type="text" value='<%=groupName%>'
					size="30" maxlength="20" class="inputtxt"></td><td style="width: 14" style="padding-left:13">
              &nbsp;</td> 
            <td class="kecttep_title" style="padding-left: 5" align="left">&nbsp;</td>
            </tr>
            <tr> 
              <td height="3"></td>
            </tr>
          </table>
        </tr>
      </table>

</form>


<!-- 확인, 취소 버튼 -->
<table border=0 cellspacing=0 cellpadding=0 width="100%">
	<tr >
		<td align="center">
		<table width="200" height="0" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="100" align="center"><a href="#" onclick="deptComp()"><img src="/totsys/common/images/bt_ok.gif" border="0" align="absmiddle"></a></td>
          <td width="100" align="center"><a href="#" onClick="deptCancel()"><img src="/totsys/common/images/bt_cancle.gif" border="0" align="absmiddle"></a></td>
        </tr>
      </table>
		</td>
	</tr>
</table>
<!-- 본문 //-->

</td>
  </tr></table>

