<%
/**********************************************************************************
	프로그램명		: dept_view.jsp
	프로그램설명	:
	작 성 자			: 조용준
	작 성 일			: 04.07.06
	최신변경일		:
***********************************************************************************/
%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="kr.co.kihyun.beans.user.HttpSSOLogin" %>

<%@ page import="kr.co.kihyun.text.html.ServletUtil" %>
<%@ page import="kr.co.kihyun.lang.Encoder" %>
<%@ page import="kr.co.kihyun.moumi.Moumi" %>
<%@ page import="kr.co.kihyun.lang.MString"%>
<%@ page import="java.net.URLEncoder" %>

<jsp:useBean id="partRegist" class="kr.co.kihyun.beans.totsys.sysadm.part.PartRegist" scope="page"/>
<jsp:useBean id="deptView" class="kr.co.kihyun.beans.totsys.sysadm.dept.DeptView" scope="page"/>

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

<%
	try{
        /***** user Login check *****************/
		if(!HttpSSOLogin.isLogin(request)){
			String connURL="parent.location='/totsys/login/login.jsp';";
			out.println(ServletUtil.getJavaScript(connURL));
			return;
		}

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

		/****** Parameter ******/
		String deptID = "";
		String findOption = "";
		String findWord = "";
		String dirPath = URLEncoder.encode("<a href=\"/totsys/sysadm/dept/dept_list.jsp\" class=\"d11_blue\">부서관리</a>");
		String uri = URLEncoder.encode("./dept_list.jsp?findOption="+findOption+"&findWord="+findWord);

		deptID = clearXSS(Encoder.toJava(request.getParameter("deptID")),"");

		/****** dept modify data get ******/
		String[] distIDList = null;
		String name = "";
		String addr = "";
		String phone = "";
		String passcode = "";
		String recoImg = "";
		String partID = "";
		String upperName = "";
		String location = "";

		partRegist.executeQuery();
		distIDList = partRegist.getDistIDList();
                
                //v2. 13.SQL 삽입 : deptView.executeQuery()에서 prepare SQL 문으로 되어 있다.
		deptView.executeQuery(deptID);
                //================
		name = deptView.getName();
		
		addr = MString.checkNull(deptView.getAddr());
		phone = MString.checkNull(deptView.getPhone());
		passcode = deptView.getPasscode();
		recoImg = MString.checkNull(deptView.getRecoImg());
		upperName = deptView.getUpperDeptName();
		location = MString.checkNull(deptView.getLocation(),"mnd");
		if(location.equals("1")) location="mnd";
		else if(location.equals("2")) location="jcs";
%>

<HTML>
	<HEAD>
		<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/SquareButtons.css" type="text/css">
		<style>
			td { padding: 1 2 1 2; }
		</style>
		<script src="/totsys/common/js/rollover.js"></script>
		<SCRIPT language="javascript">
			function formSubmit(){
				if(deptForm.oldID.value == ''){
					alert('부서ID를 넣어 주세요');
					deptForm.id.focus();
				}else if(deptForm.name.value == ''){
					alert('부서명을 넣어 주세요');
					deptForm.name.focus();
				}else if(!Check_Num(deptForm.priority.value)){
					alert('정렬순위는 숫자만 입력 가능합니다.');
					deptForm.priority.focus();
				}else if(deptForm.upperId.value == ''){
					alert('상위 부서코드를 넣어 주세요');
					deptForm.upperId.focus();
//				}else	if(!Check_Num(deptForm.id.value)){
//						alert('부서ID에 숫자만 넣어 주세요');
//						deptForm.id.focus();
				}else{
					deptForm.submit();
				}
			}

			/************** 숫자 체크 **************/
			function Check_Num(tocheck){
				var isnum = true;

				if (tocheck == null || tocheck == ""){
					isnum = false;
					return isnum;
				}

				for (var j = 0 ; j < tocheck.length; j++){
					if ( tocheck.substring(j, j + 1) != "0"
						&& tocheck.substring(j, j + 1) != "1"
						&& tocheck.substring(j, j + 1) != "2"
						&& tocheck.substring(j, j + 1) != "3"
						&& tocheck.substring(j, j + 1) != "4"
						&& tocheck.substring(j, j + 1) != "5"
						&& tocheck.substring(j, j + 1) != "6"
						&& tocheck.substring(j, j + 1) != "7"
						&& tocheck.substring(j, j + 1) != "8"
						&& tocheck.substring(j, j + 1) != "9" ){
						isnum = false;
					}
				}
				return isnum;
			}

			function partOpen(url){
				window.open(url ,'' ,'width=350 ,height=450 ,toolbar=no, directories=no, status=no, menubar=no, resizable=no');
			}
		</SCRIPT>
	</HEAD>

	<body style='overflow:auto' BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
		<table height="70" border="0" cellpadding="0" cellspacing="0">
			<jsp:include page="/totsys/common/inc/sysadm/top/top.jsp" flush="true">
				<jsp:param name="dirPath" value="<%= dirPath %>"/>
			</jsp:include>
			<tr>
				<td  nowrap width="0"></td>
				<td valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td>
								<jsp:include page="toolbar.jsp" flush="true">
									<jsp:param name="deptID" value="<%= deptID %>"/>
								</jsp:include>
							</td>
						</tr>
						<tr>
							<td height="31" valign="top">
								<FORM name="deptForm" action="/servlet/kr.co.kihyun.tree.HttpDeptModifier" method="post">
								<table border="1px" class="kecttep_list_table" bordercolor="#e3e3e3" cellpadding="0" cellspacing="0">
									<!----  부서 ID  ---->
									<tr>
										<td width="120" height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>부서코드</b></td>
										<td class="kecttep_last_graytd"><input name="oldID" type="hidden" value="<%=deptID%>"/><input name="newID" type="hidden" class="inputtxt" value="<%=deptID%>"/><%=deptID%><%// FIXME: 최상위부서로 설정시 upper_dept=id로 설정하게 되어있어 부서 변경후 최상위부서로 설정할때 오류발생함. 현재는 부서코드 변경 못하도록 함.%></td>
									</tr>
									<!----  부서명  ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>부서명</b></td>
										<td class="kecttep_last_graytd"><input name="name" type="text" class="inputtxt" value="<%=name%>"/></td>
									</tr>
									<!---- 부서전화번호 ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>전화번호</b></td>
										<td class="kecttep_last_graytd">
											<input name="phone" class=inputtxt size="13" maxlength="13" value="<%=phone%>">
										</td>
									</tr>
									<!---- 부서주소 ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>주소</b></td>
										<td class="kecttep_last_graytd"><input name="addr" type="text" class="inputtxt" size="65" value="<%= addr %>"/></td>
									</tr>
									<!---- 상위부서 ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>상위부서</b></td>
										<td class="kecttep_last_graytd">
										<input class=inputtxt name="upperName" readOnly onclick="partOpen('/totsys/sysadm/org/popup_dept_list.jsp?formName=deptForm');" value="<%= upperName%>">
										<input name="upperId" type="hidden" value="<%= deptView.getUpperDeptID() %>">
										</td>
									</tr>
									<!---- 상위기관 ---->
										<input name="partID" type="hidden" value="<%= deptView.getUpperDept() %>">
									
									<!---- 문서수발신단위 ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>문서수발신단위</b></td>
										<td class="kecttep_last_graytd"><input name="selType" type="checkbox"<%=deptView.getSelType() ? " checked=\"yes\"" : ""%>/></td>
									</tr>
									<!---- 정렬순위 ---->
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>정렬순위</b></td>
										<td class="kecttep_last_graytd"><input name="priority" type="text" class="inputtxt" size="10" maxlength="10" value="<%= deptView.getPriority() %>"/></td>
									</tr>
									<tr>
										<td height="31" class="kecttep_tdmenu"><img src="/totsys/common/images/icon.gif" align="middle">&nbsp;&nbsp;<b>소속기관</b></td>
										<td class="kecttep_last_graytd">
										<%if(location.equals("jcs")) {%>
											<INPUT type=radio value="mnd" name="location">국방부
											<INPUT type=radio value="jcs" name="location" checked>합동참모본부
										<%}else{%>
											<INPUT type=radio value="mnd" name="location" checked>국방부
											<INPUT type=radio value="jcs" name="location">합동참모본부
										<%}%>
										</td>
									</tr>
	
									</FORM>
								</table>
								</FORM>
							</td>
						</tr>
						<tr>
							<td>
								<table border="0" cellspacing="0" cellpadding="0" align="center">
									<!----  버튼 (확인, 취소) ---->
									<tr align="center">
										<td height="10" style="padding: 5px;"><a href="#" onclick="javascript:formSubmit();" 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></td>
										<td height="10" style="padding: 5px;"><a href="#" onclick="javascript:history.go(-1);" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('bt_cancel3','','./images/bt_cancel3.gif',1)"><img name="bt_cancel3" border="0" src="./images/bt_cancel3.gif" ></a></td>
									</tr>
								</table>
							</td>
						</tr>
					</table>
				</td>
				<td  nowrap width="10"></td>
			</tr>
			<!------------------------------- top menu start ------------------------------->
			<%@ include file="/totsys/common/inc/buttom/buttom.jsp" %>
			<!------------------------------- top menu end ------------------------------->
		</table>
	</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{
	}
%>
