<%@ page contentType="text/html; charset=UTF-8"
	import="kr.co.kihyun.beans.user.HttpSSOLogin"
	import="kr.co.kihyun.text.html.ServletUtil"
	import="java.net.URLEncoder" import="kr.co.kihyun.moumi.Moumi"
	import="kr.co.kihyun.lang.Encoder" import="kr.co.kihyun.lang.MString"
	import="kr.co.kihyun.beans.entity.Category"%>

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

<%
try{
	/*********** User HttpSSOLogin check ***********/
	if(!HttpSSOLogin.isLogin(request)){
		//login 성공후 되돌아올 주소
		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);

	/****** Parameter ******/
	String boardGroupID = clearXSS(request.getParameter("boardGroupID"),"");
	String strPage = clearXSS(request.getParameter("strPage"),"");
	String findOption = clearXSS(request.getParameter("findOption"),"");
	String findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")),"");

	String usrFilenames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("usrFilenames"))),"");
	String svrFilenames = clearXSS(Encoder.toJava(MString.checkNull(request.getParameter("svrFilenames"))),"");

	String[] usrFileNameList = usrFilenames.split(";");
	String[] svrFileNameList = svrFilenames.split(";");

	session.setAttribute("writeTargetURI","location='/totsys/sysadm/board/board_list.jsp?boardGroupID=" + boardGroupID + "&findOption=" +findOption+ "&findWord=" + findWord +"'");

	String boardType = "";
	if("ID_SYSTEM_NOTICE".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.notice");
	}else if("ID_FAQ".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.faq");
	}else if("ID_QNA".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.qna");
	}else if("ID_PDS".equals(boardGroupID)){
		boardType = Moumi.getMessageBundle().getString("moumi.message.board.pds");
	}
%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title><%=Moumi.getTitle()%></title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<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/contentStyle.css" type="text/css">
<link rel="stylesheet" href="/totsys/common/css/basic.css" type="text/css">
<script src="/totsys/common/js/rollover.js"></script>
<script src="/totsys/common/js/util.js"></script>
<script src="/totsys/common/js/jquery-1.12.4.min.js"></script>
<script src="/totsys/common/js/jquery.custom.indicator.js"></script>
<script>
        num = 0;
        usrFilenames = "";
        svrFilenames = "";
        fileInfos = "";
        userFilePath = "";

        function checkFile(Filename, Filename2){
                frm = document.multiUpload;
                mkFileList(Filename, Filename2, 'add');
                num++;
                frm.fileCount.value = num;
        }

        function mkFileList(Filename, Filename2, size, mode) {
                var tmpSvrFilenames = "";
                var tmpUsrFilenames = "";
                var tmpFileInfos = "";
                //var nList4 = "";

                if (!mode){
                        mode = "add";
                }

                subFilename = Filename;
                subFilename2 = cut_str( 1, Filename2, "/");
                subinfo = size;

                usrFilenameList = usrFilenames.split(";", num);
                svrFilenameList = svrFilenames.split(";", num);
                fileInfoList = fileInfos.split(";", num);

                if (mode == "add") {
                        if (svrFilenames && usrFilenames) {
                                for (i=0; i<num; i++) {
                                        tmpSvrFilenames += svrFilenameList[i] + ";";
                                        tmpUsrFilenames += usrFilenameList[i] + ";";
                                        tmpFileInfos += fileInfoList[i] + ";";
                                }
                                tmpSvrFilenames += subFilename;
                                tmpUsrFilenames += subFilename2;
                                tmpFileInfos += subinfo;
                        } else {
                                tmpSvrFilenames = subFilename;
                                tmpUsrFilenames = subFilename2;
                                tmpFileInfos = subinfo;
                        }
                } else {
                        for (i=0; i<num; i++) {
                                if (subFilename == svrFilenameList[i])
                                        continue;
                                else {
                                        tmpSvrFilenames += svrFilenameList[i] + ";";
                                        tmpUsrFilenames += usrFilenameList[i] + ";";
                                        tmpFileInfos += fileInfoList[i] + ";";
                                }
                        }
                }

                usrFilenames = tmpUsrFilenames;
                svrFilenames = tmpSvrFilenames;
                fileInfos = tmpFileInfos;
        }

        function cut_str( state, value, separator ) {
                if (!separator){
                        separator = ".";
                }

                if ( state == 0 ){
                        return value.substring(0, value.lastIndexOf(separator));
                }

                if ( state == 1 ){
                        return value.substring(value.lastIndexOf(separator)+1, value.length );
                }
        }

        function delFrm() {
                var list = document.subUpload.delFrm.fileList;
                var a = list.options[list.selectedIndex].value;
                var no = -1;

                usrFilenameList = usrFilenames.split(";", num);
                svrFilenameList = svrFilenames.split(";", num);

                for(i=0; i<num; i++) {
                        if (a == svrFilenameList[i]) {
                                no = i;
                                mkFileList(svrFilenameList[i], usrFilenameList[i], 0,"delete");
                        }
                }

                if (no != -1) {
                        frm = document.multiUpload;

                        dname = "uForm_" + no;

                        if (num > 0){
                                num--;
                        }

                        frm2 = document.subUpload.delFrm;
                        frm2.submit();
                }
        }

        function ProcKeyDown() {
                keyPressed = String.fromCharCode(window.event.keyCode);
                if ((keyPressed == "/r") || (keyPressed == "/n")){
                }
        }

        function checkForm(){
                var frm = document.multiUpload;
                if(frm.title.value == ""){
                        alert("제목을 입력해 주세요.");
                        frm.title.focus();
                        return;
                }

                if(getByteSize(frm.title.value) > 200) {
                    alert("제목의 길이는 한글기준 66자 이내여야 합니다.");
                    frm.title.focus();
                    return;
                }

                if (frm.title.value.indexOf("\\") > -1) {
                    alert("제목에는 특수기호 역슬래시(\\) 문자를 사용할 수 없습니다.");
                    frm.title.focus();
                    return;
                }

                if(frm.contents.value == ""){
                        alert("내용을 입력해 주세요.");
                        frm.contents.focus();
                        return;
                }

                //}else if(frm.passwd.value == ""){
                //alert("비밀번호를 입력해 주세요.");
                //frm.passwd.focus();
                //return;

                 /*frm.fileCount.value = num;
                 frm.usrFilenames.value = usrFilenames;
                 frm.svrFilenames.value = svrFilenames;
                 frm.fileInfos.value = fileInfos;
                 */
                $.customIndicator.show(window.self);
                frm.target = "hiddenFrame";
                frm.submit();
        }

        /*
        * 목록페이지로 이동처리하는 함수
        * @returns {undefined}
        */
        function fn_goToList() {
            document.f_list.submit();
        }
</script>
</HEAD>
<body>
<form name="f_list" method="post" action="./board_list.jsp">
    <input type="hidden" name="strPage" value="<%= strPage %>">
    <input type="hidden" name="boardGroupID" value="<%= boardGroupID %>">
    <input type="hidden" name="findWord" value="<%= findWord %>">
    <input type="hidden" name="findOption" value="<%= findOption %>">
</form>
<table>
    <jsp:include page="/totsys/common/inc/sysadm/top/top.jsp" flush="true" />
    <tr>
        <td></td>
        <td>
        <table>
                <jsp:include page="/totsys/common/inc/title/title.jsp" flush="true">
                    <jsp:param value='<%= URLEncoder.encode(boardType, "UTF-8")%>' name="title" />
                </jsp:include>
                <tr>
                    <td class="vTop">
                        <FORM name="multiUpload" action="/servlet/kr.co.kihyun.beans.totsys.board.HttpBoardWrite" method="post">
                            <INPUT type="hidden" name="userID" value="<%= usID %>">
                            <INPUT type="hidden" name="boardGroupID" value="<%= boardGroupID %>">
                            <INPUT type="hidden" name="fileCount" value="<%=MString.isNull(usrFileNameList[0]) == true? 0: usrFileNameList.length%>">
                            <INPUT type="hidden" name="usrFilenames" value="<%= usrFilenames %>">
                            <INPUT type="hidden" name="svrFilenames" value="<%= svrFilenames %>">
                            <INPUT type="hidden" name="fileInfos">
                            <input type="hidden" name="callbackFunc" value="parent.fn_goToList()">
                            <table class="kecttep_list_table">
                                <!-- 제목 시작 -->
                                <tr>
                                    <td class="kecttep_tdmenu_middle" style="padding-left:20px; width: 120px; height: 25px;">
                                        제목
                                    </td>
                                    <td class="kecttep_last_graytd" style="padding-left: 5px; text-align: center;">
                                        <input class="inputtxt" name="title" style="width: 99%;ime-mode: active;" />
                                    </td>
                                </tr>
                                <!-- 제목 끝 -->

                                <!-- 내용 시작 -->
                                <tr class="vTop">
                                    <td class="kecttep_tdmenu_middle" style=" width:120px; padding-left:20px; padding-top: 10px;">
                                        내용
                                    </td>
                                    <td class="kecttep_last_graytd">
                                        <textarea class="inputtxt" style="margin: 10px 10px 10px 10px; width: 99%; height: 320px; ime-mode: active;" name="contents"></textarea>
                                    </td>
                                </tr>
                                <!-- 내용 끝 -->

                                <!--- 파일첨부 -->
                                <tr>
                                    <td class="kecttep_tdmenu_middle" style="width: 120px; padding-left:20px;">
                                        관련자료 첨부
                                    </td>
                                    <td class="kecttep_last_graytd vTop">
                                        <iframe
                                            src="/totsys/common/inc/board/doc/write_file_upload.jsp?boardGroupID=<%= boardGroupID %>&execMode=init&mode=sysadm&maxSize=10"
                                            name='subUpload' width="100%" frameborder=0 height="70px"></iframe>
                                    </td>
                                </tr>
                                <!-- 파일첨부 끝 -->

                                <!--- 팝업공지 체크 -->
                    <% if("ID_SYSTEM_NOTICE".equals(boardGroupID)) { %>
                                <tr>
                                    <td class="kecttep_tdmenu" style="padding-left:20px; width: 120px;">
                                        팝업공지
                                    </td>
                                    <td class="kecttep_last_graytd_bottom vMiddle" style="padding-left: 5px;">
                                        <label>
                                            <input type="checkbox" name="checkPopup" />&nbsp;로그인시 팝업으로 공지함
                                        </label>
                                    </td>
                                </tr>
                    <% } %>
                                <!-- 팝업공지 체크 -->
                            </table>
                        </FORM>
                    </td>
                </tr>

                <tr>
                    <td style="height: 10px;"></td>
                </tr>

                <tr>
                    <td>
                        <table>
                            <!--  버튼 (확인, 취소) -->
                            <tr>
                                <td class="tac">
<!--                                                    <a href="#" onclick="javascript:checkForm();"
                                        onMouseOut="MM_swapImgRestore()"
                                        onMouseOver="MM_swapImage('bt_enter','','./images/bt_enter.gif',1)"><img
                                        name="bt_enter" border="0" src="./images/bt_enter.gif"></a>-->
                                    <a href="#" onclick="javascript:checkForm();" title="저장">
                                        <img name="bt_enter" border="0" src="/totsys/common/images/bt_save.gif" alt="저장" />
                                    </a>
                                    <!--                                                    <a
                                        href="./board_list.jsp?boardGroupID=<%=boardGroupID%>&strPage=<%= strPage %>&findOption=<%= findOption %>&findWord=<%= findWord %>"
                                        onMouseOut="MM_swapImgRestore()"
                                        onMouseOver="MM_swapImage('bt_cancel3.gif','','./images/bt_cancel3.gif',1)"><img
                                        name="bt_cancel3.gif" border="0" src="./images/bt_cancel3.gif"></a>-->
                                    <a href="javascript:fn_goToList()" title="취소">
                                        <img class="ml_5" name="bt_cancel3.gif" src="/totsys/common/images/bt_cancle.gif" alt="취소" />
                                    </a>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
        </table>
        </td>
        <td style="width: 10px;">&nbsp;</td>
    </tr>
    <!-- top menu start -->
    <%@ include file="/totsys/common/inc/buttom/buttom.jsp"%>
    <!-- top menu end -->
</table>
<iframe name='hiddenFrame' width=0 height=0 style='display:none;'></iframe>
</BODY>
</HTML>
<%
}catch(Exception ex){
        //38.오류메세지를 통한 정보 노출(getMessage)_CWE-209 : Update by YOUNGJUN,CHO
        ex.printStackTrace();
	//out.println(ex);//앤개
	//out.println("<html><body style='overflow=auto' bgcolor='white'><h1>Can't contact servlet runner</h1><br><br>Message : "+ex.getMessage()+"</body></html>");
	//out.println("<META HTTP-EQUIV='refresh' CONTENT='0.1; URL=/error/exception.jsp'>");
        //================================================
}finally{
}
%>
