<%
/**********************************************************************************
	프로그램명		: part_list.jsp
	프로그램설명	:
	작 성 자			: 조용준
	작 성 일			: 04.06.10
	최신변경일		:
***********************************************************************************/
%>

<%@ 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="java.net.URLEncoder"%>
<%@ page import="kr.co.kihyun.beans.totsys.sysadm.part.PartUtil"%>

<jsp:useBean id="partList"
	class="kr.co.kihyun.beans.totsys.sysadm.part.PartList" scope="page" />

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

<%
	try{
		/********** session내의 userId **********/
		String ptID = HttpSSOLogin.getOrganID(request);
		String usID = HttpSSOLogin.getLoginID(request);
		int sysAuth = HttpSSOLogin.getSysAuth(request);

		/****** Parameter 1******/
		String strPage = "";
		String findOption = "";
		String findWord = "";
		String dirPath = URLEncoder.encode("<a href=\"/totsys/sysadm/part/part_list.jsp\" class=\"d11_blue\">기관관리</a>", "UTF-8");
		String uri = URLEncoder.encode("./part_list.jsp?findOption="+findOption+"&findWord="+findWord, "UTF-8");

		strPage  = clearXSS(request.getParameter("strPage"),"");
		findOption = clearXSS(request.getParameter("findOption"),"");
		findWord = clearXSS(Encoder.toJava(request.getParameter("findWord")),"");

		/****** part list data get ******/
                //v2. 13.SQL 삽입 : JDO형식이므로 해결책에 따른 prepare SQL 문으로 변경할 수 없음
		if(sysAuth == Moumi.SYSADM){
			partList.executeQuery(findOption, findWord);
		}else{
			partList.executeQuery(ptID, findOption, findWord);
		}
                //================

		int count = partList.getCount();
		String[] idList = partList.getIDList();
		String[] nameList = partList.getNameList();
		String[] sysAuthList = partList.getSysAuthList();
		String[] desList = partList.getDesList();
		String[] upperIDList = partList.getUpperIDList();

		/************ 리스트 페이지 구성 2************/
		int endPage = 0;
		int pageSize =0 ;
		int currentPage = 0;
		int absolutePage = 0;
		int currentPageSetUp = 0;
		int recordSize = 15;

		if(strPage == null || strPage.length()<=0){
			currentPage = 1;
		}else if(strPage.equals("null")){
			currentPage = 1;
		}else{
			try{
				currentPage=Integer.parseInt(strPage);
			}catch(NumberFormatException ex){
				System.err.println(ex);
			}
		}

		if((count%recordSize) == 0){
			pageSize = (int)(count/recordSize);
		}else{
			pageSize = (int)(count/recordSize)+1;
		}

		currentPageSetUp = (int)(currentPage/10)*10;
		if (currentPage%10 == 0){
			currentPageSetUp-=10;
		}
%>

<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">
<script src="/totsys/common/js/rollover.js"></script>
<SCRIPT language="JAVASCRIPT">
			function searchList(){
				var searchForm = document.search;
//				var word = document.search.findWord.value.length;

				if(searchForm.findWord.value == ""){
					alert("검색 단어를 입력해 주세요");
					return;
				}

//				if(searchForm.findOption.value!="sys_auth" && word < 2){
//					alert("검색어는 2글자 이상이어야 합니다.!");
//					return;
//				}
				searchForm.submit();
			}
		</SCRIPT>
</HEAD>

<body style='' BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0
	MARGINHEIGHT=0>
<table width="100%" height="70" border="0" cellpadding="0"
	cellspacing="0">
	<!---- top menu 시작 --->
	<jsp:include page="/totsys/common/inc/sysadm/top/top.jsp" flush="true">
		<jsp:param name="dirPath" value="<%= dirPath %>" />
	</jsp:include>
	<!---- top menu  끝 ---->
	<tr>
		<td nowrap width="0"></td>
		<td>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
			<!-- 뉴타이틀 -->
			<jsp:include page="/totsys/common/inc/title/title.jsp" flush="true" />
			<!-- 뉴타이틀 -->
			<!----  topbar  버튼  시작 ---->

			<tr>
				<td>
				<table border="0" cellpadding="0" cellspacing="0">
					<tr class="toolbar">
						<td valign="top" width="40%">
						<table width="100%" border="0" cellpadding="0" cellspacing="0">
							<tr>
								<FORM name="search" action="./part_list.jsp" method="post">
								<td valign="top" width="40%"><select name="findOption"
									class="inputtxt" onchange="showMSG()">
									<OPTION value="all" selected>전체</OPTION>
									<OPTION value="id">기관ID</OPTION>
									<OPTION value="partName">기관명</OPTION>
									<option value="sys_auth">기관권한</option>
								</select> <input name="findWord" type="text" class="inputtxt" size="30"
									maxlength="30" value="<%=findWord%>"> <!---- 검색 끝 ---->
								<a href="#" onclick="javascript:searchList();"><img
									src="/totsys/common/images/bt_search.gif" align="absmiddle"
									style="MARGIN: 2px 0px 0px 0px"></a> <font color="#3c64ab"><span
									id="msg" style='display: none; padding-top: 5'>&nbsp;&nbsp;&nbsp;권한검색은
								0~9 까지의 숫자입력</span></font></td>
								<td width="56%"></td>
								<td align="right"><!--a href="/totsys/sysadm/part/part_list.jsp"><img src="/totsys/common/images/bt_doc_list.gif"></a-->&nbsp;<a
									href="./part_regist.jsp"><img
									src="/totsys/common/images/bt_part_regist.gif"></a></td>
								</FORM>
							</tr>
						</table>
						</td>
					</tr>
				</table>
				</td>
			</tr>


			<tr>
				<td height="31" valign="top">
				<table border="1px" class="kecttep_list_table" bordercolor="#e3e3e3"
					width="100%" cellpadding="0" cellspacing="0">
					<tr style="padding-top: 3">
						<td width="160" align="center" valign="middle" nowrap
							class="kecttep_tdmenu">기관 ID</td>
						<td align="center" valign="middle" nowrap class="kecttep_tdmenu">기관명</td>
						<td width="150" align="center" valign="middle" nowrap
							class="kecttep_last_tdmenu">기관권한</td>
					</tr>
					<%	//3
										//[이전][이후]의 페이지별 이동을 위해 구해진 PAGE값에 1 값을 빼주고 10을 곱한 결과에
										//1을 더해 줌으로서 10개의 레코드에 대한 부분을 리스트로 보여줍니다.
										int nextCount = 0;
										int index = 0;

										if(currentPage > 1){
												nextCount = ((currentPage-1)*recordSize);
										}
												//<!-- start part list 목록 4-->
										for(int i=0; (i<recordSize) && ((nextCount+i)<count); i++){
												index = nextCount+i;
								%>
					<tr style="padding-top: 3"
						onmouseover="this.style.backgroundColor='F9F9F9'"
						onmouseout="this.style.backgroundColor='white'" bgColor=#ffffff>
						<td height="25" align="center" valign="middle" nowrap
							class="kecttep_graytd"><%=idList[index]%></td>
						<td valign="middle" nowrap class="kecttep_graytd">&nbsp;&nbsp;<a
							href="./part_view.jsp?partID=<%=idList[index]%>"><%=nameList[index]%></a></td>
						<td align="center" valign="middle" style="padding-top: 3" nowrap
							class="kecttep_last_graytd">&nbsp;<%=PartUtil.getPartAuth(sysAuthList[index])%></td>
					</tr>
					<%	}	%>

				</table>
				</td>
			</tr>
			<!----  리스트 끝  ---->

			<tr>
				<td height="15"></td>
			</tr>
			<%if(count > 0){%>
			<tr style="padding-top: 3">
				<td class="kecttep_board" colspan="3" align="center" valign="middle">
				<!---- 페이지수 나오는 부분 시작 ---->
				<table width="25%" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<jsp:include page="/totsys/common/inc/board/page.jsp" flush="true">
							<jsp:param name="uri" value="<%= uri %>" />
							<jsp:param name="pageSize" value="<%= pageSize %>" />
							<jsp:param name="currentPage" value="<%= currentPage %>" />
							<jsp:param name="currentPageSetUp"
								value="<%= currentPageSetUp %>" />
						</jsp:include>
					</tr>
					<%}else{%>
					<tr>
						<td class="kecttep_none_tdmenu" colspan="3" height="25"
							align="center">등록된 기관정보가 없습니다.</td>
						<%	}	%>
						<!---- 페이지수 나오는 부분 끝 ---->
						</td>
					</tr>

					<!--1픽셀 띄우기-->
					<tr>
						<td height="3"></td>
					</tr>

					<script>
	function showMSG(){
		if(search.findOption.value == "sys_auth"){
			msg.style.display="block";
		}else{
			msg.style.display="none";
		}
	}
</script>
				</table>
				</td>
				<td nowrap width="10"></td>
			</tr>

			<!--검색후 검색조건 선택하기위한 스크립트(히든값포함)-->
			<input type="hidden" name="tmpFind" value="<%=findOption%>">
			<script>
	if(tmpFind.value == "id"){
		search.findOption.selectedIndex=1;
	}else if(tmpFind.value == "partName"){
		search.findOption.selectedIndex=2;
	}else if(tmpFind.value == "sys_auth"){
		search.findOption.selectedIndex=3;
	}
</script>
			<!--검색후 검색조건 선택하기위한 스크립트 끝-->

			<!------------------------------- 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{
	}
%>
