<%@ page contentType="text/html;charset=euc-kr" %>
<%@ include file="/include/in_Import.jsp" %>
<%@ include file="/include/in_Function.jsp" %>
<jsp:useBean id="sutil" class="kr.co.slight.jinhae.util.GYUtil" scope="page" />

<%
	String menuId = request.getParameter("menuId");

	if(menuId == null || menuId.equals("")) menuId = "35";
%>

<%!
	static {
        try {
            new kr.co.slight.jinhae.pool.JDCConnectionDriver("org.postgresql.Driver","jdbc:postgresql:hanmaum","postgres","");
        } catch(Exception e) {
           	System.out.println("<br><br>JDCConnectionDriver Error : " + e.toString());
        }
	}
%>

<%
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	SESSION
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
	String spage	= request.getParameter("spage");

	if (spage == null)
		spage = "1";
	
	int iPage = Integer.parseInt(spage);
	
	String keytype	= request.getParameter("keytype");
	String keyword	= request.getParameter("keyword");
	String passkey	= request.getParameter("passkey");

	if ( keytype == null || keytype.equals("") ) {
		keytype = "subject";
	}
	if ( keyword == null || keyword.equals("") ) {
		keyword = "";
	} else {
		keyword = sutil.toEucKr(keyword);
	}
	
	if(passkey == null) passkey = "";

	int totalCnt = 0;	//글의 총 갯수
	int totalPage;		//총 페이지 갯수
	int pageSize = 10;	//한페이지에 보여줄 글의 최대 갯수
	int blockSize = 10;	//한 화면에 보여줄 최대 페이지 갯수
	int blockPage;		//한 화면에 보여지는 페이지 중 첫번째 페이지 번호
	
	int start_no	= (iPage-1)*pageSize + 1;	//해당 페이지의 첫번째 row number
	int end_no		= iPage*pageSize;			//해당 페이지의 마지막 row number(최대값)

	Connection		conn		= null;
	Statement		stmt		= null;
	ResultSet		rs			= null;
	ResultSet		rtList		= null;

	try {
	    StringBuffer	query		= new StringBuffer();
	    StringBuffer	query_cnt	= new StringBuffer();
			
		query_cnt.append("select count(*) from application_installation a, application b where a.no = b.no");
		
		query.append("select * from application_installation a, application b where a.no = b.no");
		query.append(" order by a.no desc ");
		query.append(" limit ").append(pageSize).append(" offset ").append(start_no-1);
		

		conn	= DriverManager.getConnection("jdbc:jdc:jdcpool");
		stmt	= conn.createStatement();
		rs	= stmt.executeQuery(query_cnt.toString());
		
		while ( rs.next() ) {
			totalCnt = rs.getInt(1);
		}
		
		rs.close();
		
		totalPage = ((int) (totalCnt - 1)/pageSize ) + 1;
		blockPage = ((int) (iPage -1)/blockSize ) * blockSize + 1;
		
		rtList = stmt.executeQuery(query.toString());

		int loopSize = Math.min(blockPage + blockSize, totalPage + 1);
		int rowNum = ((loopSize - iPage) * 10) + (totalCnt % 10) - 10;
%>

<%@ page contentType="text/html;charset=euc-kr" %>
<jsp:include page="/hanmaum/top.jsp" flush="false"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ko" xml:lang="ko"> 

<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<link rel="stylesheet" href="/hanmaum/Common/hstyle.css" type="text/css">
<title>무제 문서</title>

<script type="text/javascript">
<!--
	function onPass() {
		if("<%= passkey %>" == "") {
			alert('잘못된경로로 접근하셨습니다.');
			location.href = "http://www.scgoneheart.co.kr/";
		}
	}

	function onViewPage(no) {
		var frm = document.form1;
		
		frm.no.value = no;

		frm.target = "_new";
		frm.action = "accou05_view.jsp";
		frm.submit();
	}

	function bbsList(spage, keytype, keyword) {
		location.href="accou05_list.jsp?spage=" + spage + "&keytype=" + keytype + "&keyword=" + keyword + "&passkey=<%= passkey %>";
		return;
	}

	function onSubmit(cmdCode) {
		var frm = document.form1;
		
		if(confirm("선택된 게시물을 삭제하시겠습니까?")) {
			frm.cmd.value = cmdCode;

			frm.action = "accou05_list_ok.jsp";
			frm.target = "_self";
			frm.submit();
		}
	}

	function onSubmitU(cmdCode) {
		var frm = document.form1;
		
		if(confirm("승인여부를 등록하시겠습니까?")) {
			frm.cmd.value = cmdCode;

			frm.action = "accou05_list_ok.jsp";
			frm.target = "_self";
			frm.submit();
		}
	}
//-->
</script>
</head>

<body onload="mouseOnEvent('<%= menuId %>');onPass();">
<%@ include file="/hanmaum/Cs/04_subimg.jsp" %>
<form name="form1" action="">
	<input type="hidden" name="passkey" value="<%= passkey %>" />
	<input type="hidden" name="cmd" value="" />
	<input type="hidden" name="no" value="" />

<table width="940" border="0" cellspacing="0" cellpadding="0">
	<tr>
		<td width="239" valign="top" id="left">
<!--좌측메뉴-->
	<%@ include file="/hanmaum/Accou/left_menu.jsp" %>
<!--좌측메뉴끝-->
		</td>
		<td width="701" align="center" valign="top">
<!--컨텐츠 시작-->
			<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td height="25" align="right" valign="bottom" id="ma1"><img src="/hanmaum/Image/location.gif" width="51" height="13" align="absmiddle"> 홈 &gt; 이용안내 &gt; 신청서작성</td>
				</tr>
				<tr>
					<td><img src="/hanmaum/Image/03_centop05.gif" alt="" width="701" height="56" /></td>
				</tr>
				<tr>
					<td height="36">&nbsp;</td>
				</tr>
			</table>

			<table width="680" border="0" cellspacing="0" cellpadding="0">
				<tr>
					<td width="14"><img src="/hanmaum/Image/04_cen01.gif" alt="" width="14" height="32" /></td>
					<td width="50" align="center" background="/hanmaum/Image/04_cen03.gif"><img src="/hanmaum/Image/04_cen07.gif" alt="" width="20" height="11" /></td>
					<td width="477" align="center" background="/hanmaum/Image/04_cen03.gif"><img src="/hanmaum/Image/04_cen08.gif" alt="" width="20" height="12" /></td>
					<td width="125" align="center" background="/hanmaum/Image/04_cen03.gif"><img src="/hanmaum/Image/04_cen10.gif" alt="" width="29" height="12" /></td>
					<td width="14"><img src="/hanmaum/Image/04_cen02.gif" alt="" width="14" height="32" /></td>
				</tr>
			</table>

			<table width="680" border="0" cellspacing="0" cellpadding="0" class="fqtable">
<%
	if (totalCnt > 0) {

		int i = totalCnt;
		int no = 0;

		String	subject = "";
		String	regdate = "";
		String appYn = "";

		while (rtList.next()) {			    
			no = rtList.getInt("no");
			subject	= rtList.getString("company_name");								
			regdate	= rtList.getString("reg_dt").toString().substring(0, 10);
			appYn = rtList.getString("app_yn");

			subject = cutoffString(subject, 80);	
			
			if(appYn == null) appYn = "";
%>
				<tr>
					<td width="64" height="26" align="center">
						<input type="checkbox" name="chk" id="ch1" value="<%= no %>" />
						<%= rowNum-- %>
					</td>
					<td width="400" align="left">
						<a href="javascript:onViewPage('<%= no %>')">
							<%= subject %>
						</a>
					</td>
					<td width="77" height="26" align="center">
						<select name="appYn">
							<option value="" <%= appYn.equals("")?"selected":"" %>>선택</option>
							<option value="N" <%= appYn.equals("N")?"selected":"" %>>불가</option>
							<option value="Y" <%= appYn.equals("Y")?"selected":"" %>>승인</option>
							<option value="S" <%= appYn.equals("S")?"selected":"" %>>완료</option>
						</select>
						<input type="hidden" name="seqNo" value="<%= no %>" />
					</td>
					<td width="139" align="center"><%= regdate %></td>
				</tr>
<%
		}
	} else {
%>
				<tr>
					<td colspan="3" align="center">등록된 게시물이 없습니다.</td>
				</tr>
<% 
	} 
%>
				<tr>
					<td height="3" colspan="3" id="gc"></td>
				</tr>
			</table>

			<table width="680" border="0" cellspacing="0" cellpadding="0" border='1'>
				<tr>
					<td height="20" colspan="3" align="center" valign="bottom">
<%
//이전 페이지
		if ( iPage == 1 ) {
%>        
						<img src="/images/ic_spre.gif" width="6" height="8">
<%
		} else {
%>
		                <a href="javascript:bbsList('<%=iPage-1%>', '<%=keytype%>', '<%=keyword%>')";>
							<img src="/images/ic_spre.gif" width="6" height="8" border="0">
						</a>
<%
		}
//	페이지 Loop
	
		for ( int j=blockPage; j<loopSize ; j++ ) {
			if (spage.equals(j+"")) {
%>                      
			<a href="javascript:bbsList('<%=j%>', '<%=keytype%>', '<%=keyword%>')";><strong>[<%=j%>]</strong></a>
<%
			} else {
%>                      
			<a href="javascript:bbsList('<%=j%>', '<%=keytype%>', '<%=keyword%>')";>[<%=j%>]</a>	
<%
			}
		}

/*-----------------------------------------
	다음 페이지
-----------------------------------------*/
		if ( iPage == totalPage ) {
%>
                                <img src="/images/ic_snex.gif" width="6" height="8">
<%
		} else {
%>
			<a href="javascript:bbsList('<%=iPage+1%>', '<%=keytype%>', '<%=keyword%>')";><img src="/images/ic_snex.gif" width="6" height="8" border="0"></a>
<%
		}
%>                                
					</td>
				</tr>
				<tr>
					<td height="20" colspan="3" valign="bottom" align="right">
						<a href="javascript:onSubmit('D');">
							<img src="../Image/04_but17.gif" border="0">
						</a>
						&nbsp;&nbsp;&nbsp;
						<a href="javascript:onSubmitU('U')">
							<img src="../Image/04_but16.gif" border="0">
						</a>
					</td>
				</tr>
			</table>

<!--컨텐츠 끝-->
		</td>
	</tr>
</table>

</form>
<%@ include file="/hanmaum/bottom.jsp" %>

<%
		if ( rs != null ) rs.close();
		if ( stmt != null ) stmt.close();
		if ( conn != null ) conn.close();

	} catch (Exception e) {

		if ( rs != null ) rs.close();
		if ( stmt != null ) stmt.close();
		if ( conn != null ) conn.close();

		// 에러페이지로 이동............
		out.println("JSP >> Slight Exception in /Cs/csnot01.jsp : " + e.toString());
	}
%>