<%@ 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);
        String docReportType = MString.checkNull(request.getParameter("docReportType"));  //문서 구분(D:집계문서, R:제출문서)
        if (MString.isNull(docReportType)) {
            docReportType = "R";
        }
        String exeFlag = MString.checkNull(request.getParameter("exeFlag"));
        if (MString.isNull(exeFlag)) {
            exeFlag = "form";
        }

        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 userYN = "N";
        if (hideUser == false) {
            userYN = "Y";
        } else {
            userYN = "N";
        }
        String reportType = clearXSS(request.getParameter("reportType"), "");

        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();
        dept = dept.getRootDept(pm);
        deptID = dept.getId();

        tx.rollback();
%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="/totsys/common/js/jquery-1.12.4.min.js"></script>
        <script type="text/javascript" src="/totsys/common/js/jquery.cookie.js"></script>
		<script type="text/javascript" src="/totsys/common/js/jquery.hotkeys.js"></script>
		<script type="text/javascript" src="/totsys/common/js/jquery.jstree.js"></script>

        <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 deptName;
            var userName;
            var userID;

            function fnInit() {
                /* @@@ test
                 document.getElementById('search').value = "손기영";
                */
            }

            function searchWord() {
                var type = $('#findOption').val();
                type = type.toUpperCase();
                //alert("type = " + type);
                var word = $('#search').val();
                word = $.trim(word);
                $('#search').val(word);
                if (word.length < 2) {
                    alert("검색어는 2글자 이상이어야 합니다.");
                    return;
                }
                var $ff = $("#leftFrame");
                $ff[0].contentWindow.$("#searchType").text(type);  //검색유형
                $ff[0].contentWindow.$("#searchWord").text(word);  //검색값
                $ff[0].contentWindow.$("#search").click();
            }

            //조직도에서 검색된 노드로 포커스를 이동시킨다.  strType : down, up
            function focusMove(strType) {
                //alert("strType = " + strType);
                var $ff = $("#leftFrame");
                $ff[0].contentWindow.$("#moveType").text(strType);      //포커스이동타입
                $ff[0].contentWindow.$("#focusMove").click();
            }

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

            function putNodeType(type, id, deptname, name) {
                nodeType = type.toLowerCase();
                userID = id;
                deptName = deptname;
                userName = name;
            }

            function onOk() {
                if (nodeType != 'user') {
                    //사용자를 선택하세요!
                    alert('<%=Moumi.getMessageBundle().getString("moumi.message.popup.selectUser")%>');

                    //deptName / userName 으로 담당자를 변경하시겠습니까?
                } else if (confirm("'" + deptName + " / " + userName + "' \n\n으로 담당자를 변경하시겠습니까?")) {
                    document.transfer.userID.value = userID;
                    document.transfer.submit();
                }
            }

        </script>
    </head>
    <body style='' bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onload="//fnInit();" >
        <FORM name="transfer" action="/servlet/kr.co.kihyun.beans.totsys.repoper.HttpTransfer6" method="post">
            <INPUT type="hidden" name="reportID" value="<%= reportID%>">
            <input type="hidden" name="docReportType" value="<%=docReportType%>">
            <INPUT type="hidden" name="userID" value="">
            <INPUT type="hidden" name="reportType" value="<%= reportType%>">
            <input type="hidden" name="exeFlag"       value="<%=exeFlag%>">
            <input type="hidden" name="callbackFunc"  value="fn_reload()">
        </FORM>

        <table width="95%" border="0" cellspacing="0" cellpadding="0" align="center" style="padding-top:10px">
<!--            <tr>
                <td>
                    <table width="100%" height="29" border="0" cellpadding="0" cellspacing="0" bgcolor="728ab5">
                        <tr>
                            <td class="kecttep_title" style="padding-left:15px"><font color="#FFFFFF"><strong>담당변경</strong></font></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>

                <td valign="top"> <table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top:10px">-->
            <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 && 1==2) {  //2014.09.12 Update by KWON,HAN : && 1==2 추가하여 사용안함 %>
                        <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true">
                            <jsp:param name="title" value='<%=URLEncoder.encode("담당자변경")%>' />
                            <jsp:param name="flag"	value='99' />
                        </jsp:include>
                        <%}%>
                        <tr>
<!--                            <td align="center" valign="top">
                                <div>
                                    <iframe id="leftFrame" src="/totsys/common/web/report_dept/iframe/newTree3.jsp?rootID=<%= deptID%>&userYN=<%= userYN%>" width="550" height="500" frameborder="1"></iframe>
                                </div>-->
                            <td  valign="bottom">
                                <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
                                    <tr>
                                        <td bgcolor="#FFFFFF">
                                            <div>
                                                <iframe id="leftFrame" src="/totsys/common/web/report_dept/iframe/newTree3.jsp?rootID=<%= deptID%>&userYN=<%= userYN%>" width="550" height="500" frameborder="1"></iframe>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <div>
                                    <table height="0" border="0" cellpadding="0" cellspacing="0" >
                                        <tr><td>&nbsp;</td></tr>
                                        <tr>
                                            <td align="left"> 검 색 &nbsp;&nbsp;</td>
                                            <td align="left">
                                                <span style="width: 70px">
                                                    <select id="findOption" name="findOption" class="inputtxt" onchange="$('#search').val('');
                                                        showMSG(this.options[this.selectedIndex].value, msg)" disabled="true">
                                                        <option value="user" selected><%=Moumi.getMessageBundle().getString("moumi.message.tot_doc.user")%></option>
                                                        <option value="dept"><%=Moumi.getMessageBundle().getString("moumi.message.doc.Devision")%><%=Moumi.getMessageBundle().getString("moumi.message.doc.Name")%></option>
                                                    </select>
                                                </span>
                                            </td>
                                            <td><input id="search" name="search" type="text" class="inputtxt" value="" size="50" onkeyDown="if(event.keyCode === 13) { searchWord(); }" style="ime-mode:active;"> </td>
                                            <td>&nbsp;&nbsp;<a href="#" onclick="searchWord()"><img src="/totsys/common/images/bt_search_inquiry2.gif" border="0" align="absmiddle"></a></td>
                                            <td>&nbsp;&nbsp;<a href="#" onclick="focusMove('down');"><img src="/totsys/common/images/bt_down.jpg" border="0" align="absmiddle"></a></td>
                                            <td>&nbsp;&nbsp;<a href="#" onclick="focusMove('up');"><img src="/totsys/common/images/bt_up.jpg" border="0" align="absmiddle"></a></td>
                                            <td align="left">
                                            </td>
                                        </tr>
                                        <tr><td>&nbsp;</td></tr>
                                    </table>

                                    <hr color='$ff0000' />
                                    <table border="0" cellspacing="0" cellpadding="5" align="center">
                                        <tr>
                                            <td><a  href="#" onclick="javascript:onOk();"><img src="/totsys/common/images/bt_ok.gif"  border="0" align="absmiddle" ></a></td>
                                            <td><a  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();
    }
%>
