
<%
/************************************************************@@
  * Program Name	: part_list.jsp
  * Description		: 이 페이지를 포함하는 parent페이지는
  					  function userList(id, name, type)를 정의해야 함.
  * Author			: 기현테크
  * Create Date		: 2010-11-24
  * History			:
@@************************************************************/
%>

<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.moumi.Moumi" import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.lang.MLong" import="kr.co.kihyun.beans.user.Dept"
	import="kr.co.kihyun.beans.user.PartList"%>

<%
try{
	boolean hideUser = MString.isNull(request.getParameter("hideUser")) ? true : new Boolean(request.getParameter("hideUser"));
	String rootID = request.getParameter("rootID");

	/********** session내의 userId **********/
	String ptID = HttpSSOLogin.getOrganID(request);
	int sysAuth = HttpSSOLogin.getSysAuth(request);

	/************ PartList **************/
	int partCount;
	String[] partIDList;
	String[] partNameList;
	String[] partUpperDeptList;
	String[] partOrganList;
	boolean[] partSelTypeList;

	PartList partList  = new PartList();
	partList.getTop();
        
        //v2. 13.SQL 삽입 : partList.executeQuery()에서 prepare SQL 문으로 되어 있다.
	if(rootID == null)
		partList.executeQuery();
	else
		partList.executeQuery(rootID);
        //=================
        
	partCount = partList.getCount();
	partIDList = partList.getIDList();
	partNameList = partList.getNameList();
	partUpperDeptList = partList.getUpperDeptList();
	partOrganList = partList.getOrganList();
	partSelTypeList = partList.getSelTypeList();

	StringBuilder stringTree = new StringBuilder()
		.append("<ul class=\"mktree\" id=\"tree1\">")
		.append("<li id=\"root\">")
                .append("<input type='checkbox' name='chk_'>")
		.append("<span id=\"span_root\" style=\"cursor:pointer;\" onclick=\"selectItem('root', 'dept'); parent.detailFrame.location.replace('about:blank');\">")
			.append("<img src=\"/totsys/common/images/open_minus.gif\" id='i_root'>&nbsp;<img src=\"/totsys/common/images/uplus.gif\" id='k_root'>")
		.append("</span>")
		.append("<span id=\"spanA_root\" style=\"cursor:pointer;\" onclick=\"selectItem('root', 'dept'); parent.detailFrame.location.replace('about:blank');\">")
			.append("&nbsp;").append(Moumi.getMessageBundle().getString("moumi.message.tot_doc.deptMap"))
		.append("</span>")
		.append("<input id='h_root' type='hidden' value='open'/>")
		.append("<div id=\"t_root\" style='display:block;'>")
		.append("<ul class=\"mktree_b\">");
	for(int p=0; p<partCount; p++){
		if(partSelTypeList[p]){
			stringTree.append("<li id=\""+partIDList[p]+"\"><input type=\"checkbox\" name=\"chk_\" onclick=\"checkBoxClick('"+partIDList[p]+"', '"+partSelTypeList[p]+"');\"><span id=\"span_"+partIDList[p]+"\" style=\"cursor:pointer;\" onclick=\"toggleF('"+partIDList[p]+"', '"+partSelTypeList[p]+"'); selectItem('"+partIDList[p]+"', 'dept');  parent.userList('"+partIDList[p]+"','"+partNameList[p]+"','dept');\"><img src=\"/totsys/common/images/open_plus.gif\" id='i_"+partIDList[p]+"'>&nbsp;<img src=\"/totsys/common/images/plus.gif\" id='k_"+partIDList[p]+"'></span><span id=\"spanA_"+partIDList[p]+"\" style=\"cursor:pointer;\" onclick=\"selectItem('"+partIDList[p]+"', 'dept'); parent.userList('"+partIDList[p]+"','"+partNameList[p]+"','dept');\">"+partNameList[p]+"</span><input id='h_"+partIDList[p]+"' type='hidden' value='close'/><div id=\"t_"+partIDList[p]+"\" style='display:none;'></div></li>");
		}else{
			stringTree.append("<li id=\""+partIDList[p]+"\"><input type=\"checkbox\" name=\"chk_\" onclick=\"checkBoxClick('"+partIDList[p]+"', '"+partSelTypeList[p]+"');\"><span id=\"span_"+partIDList[p]+"\" style=\"cursor:pointer;\" onclick=\"toggleF('"+partIDList[p]+"', '"+partSelTypeList[p]+"'); selectItem('"+partIDList[p]+"', 'dept'); parent.userList('"+partIDList[p]+"','"+partNameList[p]+"','');\"><img src=\"/totsys/common/images/open_plus.gif\" id='i_"+partIDList[p]+"'>&nbsp;<img src=\"/totsys/common/images/uplus.gif\" id='k_"+partIDList[p]+"'></span><span id=\"spanA_"+partIDList[p]+"\" style=\"cursor:pointer;\" onclick=\"selectItem('"+partIDList[p]+"', 'dept'); parent.userList('"+partIDList[p]+"','"+partNameList[p]+"', '');\">&nbsp;"+partNameList[p]+"</span><input id='h_"+partIDList[p]+"' type='hidden' value='close'/><div id=\"t_"+partIDList[p]+"\" style='display:none;'></div></li>");
		}
	}
	stringTree.append("</ul></div></li>");
	stringTree.append("</ul>");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK REL="stylesheet" HREF="/totsys/common/css/mktree.css">
<SCRIPT LANGUAGE="JavaScript" SRC="/totsys/common/js/mktree.js"></SCRIPT>
<script src="/totsys/common/js/rollover.js"></script>
<script language="javascript">
			parent.userGroup=false;
                        function checkBoxClick(id, sel)
                        {
                            alert(id+"::"+sel);
                            flag=99;
                            subID = id;
			    var hid = "h_"+id;
			    if(document.getElementById("h_"+subID) != undefined && document.getElementById("h_"+subID).value == "open") return;
                            else if(document.getElementById("h_"+subID) != undefined) openF2(subID, sel,flag);
                        }

			function toReportFrame(partID, partName, selectType){
				parent.tstate = true;

				var str = '';
				str = '/servlet/kr.co.kihyun.beans.user.HttpDeptList?partID='+partID+'&selectType='+selectType;
				parent.leftFrame.location.replace(str);
			}

			function init(partID, selectType){
				parent.tstate = true;

				var str = '';
				str = '/servlet/kr.co.kihyun.beans.user.HttpDeptList?partID='+partID+'&selectType='+selectType;
				parent.leftFrame.location.replace(str);
			}
		</script>

<script type="text/javascript">
			var xhr = null;
			var subID = "";
			var selected_id = "";
			var selected_type = "";
			var old_id = "";

			function getXMLHttpRequest() {
				if (window.ActiveXObject) {
			        try {
			            return new ActiveXObject("Msxml2.XMLHTTP");//IE 상위 버젼
			        } catch (e1) {
			            try {
			                return new ActiveXObject("Microsoft.XMLHTTP");//IE 하위 버젼
			            } catch (e2) {
			                return null;
			            }
			        }
			    } else if (window.XMLHttpRequest) {
			        return new XMLHttpRequest();//IE 이외의 브라우저(FireFox 등)
			    } else {
			        return null;
			    }
			}// XMLHttpRequest 객체 얻기

			function requestTree(id) {
				subID = id;
			    URL = "./subtree2.jsp?hideUser=<%= hideUser %>&id=" + id;//한글 처리
			    xhr = getXMLHttpRequest();//XMLHttpRequest 객체 얻기
			    xhr.onreadystatechange = responseTree;//콜백 함수  등록
			    xhr.open("GET", URL, false);//연결
			    xhr.send(null);//전송
			}// 서버에 요청

			function responseTree() {
			    if (xhr.readyState == 4) {//완료
			        if (xhr.status == 200) {//오류없이 OK
			            var str = xhr.responseText;//서버에서 보낸 내용 받기
						document.getElementById("t_"+subID).innerHTML = str;//보여주기
			        } else {
			            alert("Fail : " + httpRequest.status);
			        }
			    }
			}// 응답

			function toggleF(id, sel) {
				subID = id;
				var hid = "h_"+id;
			    if (document.getElementById("h_"+subID) != undefined && document.getElementById("h_"+subID).value == "open") {//폴더열려있음
			    	closeF(subID, sel);
			    } else if(document.getElementById("h_"+subID) != undefined) {
			    	openF(subID, sel);
				}
			}// 응답

			function closeF(id, sel) {
				document.getElementById("h_"+id).value = "close";
				document.getElementById("t_"+id).innerHTML = "";
				document.getElementById("t_"+id).style.display="none";
				document.getElementById("i_"+id).src = "/totsys/common/images/open_plus.gif";

				if(sel==1){
					document.getElementById("k_"+id).src = "/totsys/common/images/plus.gif";
				}else{
					document.getElementById("k_"+id).src = "/totsys/common/images/uplus.gif";
				}
			}

			function openF(id, sel) {
				document.getElementById("h_"+id).value = "open";
				document.getElementById("t_"+id).style.display="block";
				document.getElementById("i_"+id).src = "/totsys/common/images/open_minus.gif";

				if(sel==1){
					document.getElementById("k_"+id).src = "/totsys/common/images/minus.gif";
				}else{
					document.getElementById("k_"+id).src = "/totsys/common/images/uminus.gif";
				}
				requestTree(id);
			}

                        function openF2(id, sel,flag) {
                       
				document.getElementById("h_"+id).value = "open";
				document.getElementById("t_"+id).style.display="block";
				document.getElementById("i_"+id).src = "/totsys/common/images/open_minus.gif";

				if(sel==1){
					document.getElementById("k_"+id).src = "/totsys/common/images/minus.gif";
				}else{
					document.getElementById("k_"+id).src = "/totsys/common/images/uminus.gif";
				}
                                
				requestTree2(id,flag);
			}

                        function requestTree2(id,flag) {
                            
				subID = id;
			    URL = "./subtree2.jsp?hideUser=<%= hideUser %>&id=" + id+"&flag="+flag;//한글 처리
                   
			    xhr = getXMLHttpRequest();//XMLHttpRequest 객체 얻기
			    xhr.onreadystatechange = responseTree2;//콜백 함수  등록
			    xhr.open("GET", URL, false);//연결
			    xhr.send(null);//전송
			}// 서버에 요청

                        function responseTree2() {
			    if (xhr.readyState == 4) {//완료
			        if (xhr.status == 200) {//오류없이 OK
			            var str = xhr.responseText;//서버에서 보낸 내용 받기
						document.getElementById("t_"+subID).innerHTML = str;//보여주기
			        } else {
			            alert("Fail : " + httpRequest.status);
			        }
			    }
			}// 응답

			function selectItem(id, type) {
				old_id = selected_id;
				selected_id = id;
				selected_type = type;
				var old_item = document.getElementById("spanA_"+old_id);
				if(old_item){
					old_item.style.fontWeight="normal";
				}
				document.getElementById("spanA_"+selected_id).style.fontWeight="bold";
				window.scrollTo(0, findOffsetTop(document.getElementById("spanA_"+selected_id))-document.body.offsetHeight/2);
			}// 응답

			function findOffsetTop(obj) {
				var currentTop = 0;
				if(obj.offsetParent) {
					do {
						currentTop += obj.offsetTop;
					} while (obj = obj.offsetParent);
				}
				return currentTop;
			}
		</script>
</head>

<!--<body style='overflow=auto' bgcolor="#CECECE" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" >-->
<body style='' text="#000000" leftmargin="0" topmargin="0"
	marginwidth="0" marginheight="0" onLoad="selectItem('root', 'dept');">
<TABLE width="100%" cellpadding="5" cellspacing="2" border="0"
	style='padding-left: 0px;'>
	<TBODY style='padding-left: 0px;'>
		<TR style='padding-left: 0px;'>
			<TD align="left" style='padding-left: 0px;'><%=stringTree.toString()%>

			</TD>
		</TR>
	</TBODY>
</TABLE>
</body>
</html>
<%
}catch(Exception ex){
	ex.printStackTrace();
	out.println(kr.co.kihyun.text.html.ServletUtil.getJavaScript("location='/servlet/kr.co.kihyun.beans.user.HttpSSOLogin?mode=logout';"));
}finally{
}
%>
