<%@ page contentType="text/html; charset=UTF-8"
	import="java.net.URLEncoder"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.text.html.ServletUtil"
	import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.moumi.Moumi" import="kr.co.kihyun.lang.MLong"
	import="javax.jdo.PersistenceManager" import="javax.jdo.Transaction"
	import="kr.co.kihyun.beans.entity.util.*"
	import="kr.co.kihyun.beans.entity.*"%>

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

<%
PersistenceManager pm = new MPersistenceManager(PMF.get().getPersistenceManager());
Transaction tx = pm.currentTransaction();
try{
	/*********** User HttpSSOLogin check ***********/
	if(!HttpSSOLogin.isLogin(request)){
		String connURL="opener.location='/totsys/login/login.jsp';";
		out.println(ServletUtil.getJavaScript(connURL));
		out.println(ServletUtil.getJavaScript("window.close();"));
		return;
	}

	/********** session내의 userId **********/
	String usID = HttpSSOLogin.getLoginID(request);
	String dtID = HttpSSOLogin.getDeptID(request);
	int sysAuth = HttpSSOLogin.getSysAuth(request);
	
	/****** Parameter ******/

        Long docID = MLong.parseLong(request.getParameter("docID"),null);

	Long reportID = MLong.parseLong(request.getParameter("reportID"),null);
	String boxName = clearXSS(request.getParameter("boxName"),"");
	boolean hideUser = MString.isNull(request.getParameter("hideUser")) ? true : new Boolean(request.getParameter("hideUser"));
    String pageFlag = clearXSS(request.getParameter("pageFlag"),"1");

	tx.begin();

	//TotReport totReport = (TotReport)pm.getObjectById(TotReport.class, reportID);
	
	String titleName = Moumi.getMessageBundle().getString("moumi.message.tot_doc.docList")+Moumi.getMessageBundle().getString("moumi.message.tot_doc.name");
	MDept dept = (MDept)pm.getObjectById(MDept.class, dtID);

	String deptID = dtID;

	//while(!dept.isDocUnit()) dept=dept.getUpperDept(pm);
    //deptID = dept.getId();

    if(pageFlag.equals("1"))
    {
        if(dept.getGrade()==null) dept=dept.getUpperDept(pm);
        else dept=dept.getRootDept(pm);
        deptID=dept.getId();
    }
    else if(pageFlag.equals("2"))
    {
        dept=dept.getRootDept(pm);
        deptID=dept.getId();
    }
	tx.rollback();
%>

<html>
<head>
<title><%=Moumi.getTitle()%></title>
<link rel="stylesheet" href="/totsys/common/css/text.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/kecttep.css"
	type="text/css">
<link rel="stylesheet" href="/totsys/common/css/SquareButtons.css"
	type="text/css">
<script src="/totsys/common/js/rollover.js"></script>
<script>
	    	var nodeType;
	    	var userName;
	    	var userID;

			function userList(id, name, type){
				if(type == 'user')
					id = id.split('/')[0];
				nodeType = type;
				userName = name;
				userID = id;
			}

			function onOk() {
				if(nodeType != 'user') {
					alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.selectUser")%>');
				} else if(confirm("<%=Moumi.getMessageBundle().getString("moumi.message.popup.charge")%> '"+userName+"'<%=Moumi.getMessageBundle().getString("moumi.message.popup.chargeChange")%>")) {
					document.transfer.userID.value = userID;
					document.transfer.submit();
				}
			}
	    </script>
</head>

<body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0"
	topmargin="0" marginwidth="0" marginheight="0">

<FORM name="transfer" action="/servlet/kr.co.kihyun.beans.totsys.repoper.HttpTransfer2" method="post">
    <INPUT type="hidden" name="docID" value="<%= docID %>">
    <INPUT type="hidden" name="userID" value="">
</FORM>

<table width="100%" border="0" cellpadding="0" cellspacing="0" bordercolor="#00FFFF"><tr>
    <td  style="padding:10px"> 
	  <!--타이틀 //-->
      <table width="100%" border="0" cellpadding="0" cellspacing="0"><tr>
          <td bgcolor="728ab5" style="padding: 10 20 10 20"><strong><font color="#FFFFFF">담당변경</font></strong></td>
  </tr></table>
  <!--타이틀 //-->
  
  
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
                    
			<%if(sysAuth == Moumi.TOTPER){%>
			<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true">
                            <jsp:param name="title" value='<%=URLEncoder.encode("담당자변경","UTF-8")%>' />
			 <jsp:param name="flag"	value='99' />
                                
                                
			</jsp:include>
			<%}%>
 
			<tr>
				<td  valign="bottom">
				<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
					<tr>
						<td bgcolor="#FFFFFF">
				<div><iframe
					src="/totsys/common/web/report_dept/iframe/part_list.jsp?rootID=<%= deptID %>&hideUser=<%= hideUser %>"
					width="550" height="435" frameborder="0"></iframe></div></td>
					</tr>
				</table>
				<div>
				<table border="0" cellspacing="0" cellpadding="0" align="center" height="50">
					<tr>
						<td><a class="blueButton" href="#"
							onclick="javascript:onOk();"><img src="/totsys/common/images/bt_ok.gif"  border="0" align="absmiddle"></a>
						</td>
						<td><a class="blueButton" href="#"
							onclick="javascript:window.close();"><img src="/totsys/common/images/bt_cancle.gif"  border="0" align="absmiddle"></a>
						</td>
					</tr>
				</table>
				</div>
				</td>
			</tr>
		</table> 
		
</td></tr></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{
	if(tx.isActive())
		tx.rollback();
	pm.close();
}
%>
