<!--
whilvydy 新闻发布系统
-->

<%@ page contentType="text/html; charset=GB2312" language="java" import="java.sql.*" errorPage="" %>
<%@ include file = "func/parameter.jsp" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.io.*" %> 
<%@ page import="java.util.*" %>
<jsp:useBean id="BoardBean" scope="page" class="net.jspcn.db.DbConnect" />
<jsp:useBean id='oMD5' scope='page' class='net.jspcn.tool.MD5'/>
<jsp:useBean id='StrTool' scope='page' class='net.jspcn.tool.StringProcess'/>

<%
boolean isedit = false; 	//是否在编辑状态
int board_id;
String sql;
ResultSet rs,rs1;
int intPageCount,intPageSize,intCurrentPage,intRowCount,i;
intPageSize = param[3];
i=0;

if (Integer.parseInt((String) session.getValue("user_power"))<9999)
response.sendRedirect("login.jsp");

if("edit".equalsIgnoreCase(request.getParameter("action")))
    isedit=true;

if(request.getParameter("board_id")==null)
	board_id = 1;
else
	board_id = Integer.parseInt(request.getParameter("board_id").trim());
	//out.println(board_id);

    
BoardBean.openConnection();

//************************************修改用户**************************************
if("modify".equalsIgnoreCase(request.getParameter("action")))
{
	String board_name=request.getParameter("board_name").trim();
	String board_describ=request.getParameter("board_describ").trim();
	int type_id=Integer.parseInt(request.getParameter("type_id").trim());	
	if(board_name.length()>=2)
	{
	sql = "update "+board_table+" set type_id = "+type_id+",board_name = '"+board_name+"',board_describ = '"+board_describ+"' where board_id = "+board_id;
	BoardBean.executeQuery(sql);
	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'update board name to "+board_name+",type_id: "+type_id+" ')";
	BoardBean.executeUpdate(sql_in);
	}
}

if("pass".equals(request.getParameter("action")))
{
	String board_audit=request.getParameter("board_audit").trim();
	sql = "update "+board_table+" set board_audit="+Integer.parseInt(board_audit)+" where board_id="+board_id;
	BoardBean.executeQuery(sql);	
	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'change board status to "+board_audit+" ')";
	BoardBean.executeUpdate(sql_in);	

}

//************************************添加用户**************************************
if("add".equalsIgnoreCase(request.getParameter("action")))
{
	String board_name=request.getParameter("board_name").trim();
	String board_describ=request.getParameter("board_describ").trim();
	int type_id=Integer.parseInt(request.getParameter("type_id").trim());	
	int board_audit=Integer.parseInt(request.getParameter("board_audit").trim());	
	if(board_name.length()>=2)
	{
	sql = "insert into "+board_table+" values('',"+type_id+",'"+board_name+"',"+board_audit+",'"+board_describ+"')";
	BoardBean.executeQuery(sql);
	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'add board name: "+board_name+" type: "+type_id+" ')";
	BoardBean.executeUpdate(sql_in);	
	}
}


//************************************添加用户**************************************
if("delete".equalsIgnoreCase(request.getParameter("action")))
{
	sql = "delete from "+board_table+" where board_id ="+board_id;
	BoardBean.executeQuery(sql);
	
	sql = "delete from "+news_table+" where board_id ="+board_id;
	BoardBean.executeQuery(sql);

	//log process	
	String sql_in = "insert into "+logrecord_table+" (logrecord_id,user_name,operation_time,logrecord_operation) values('','"+session.getValue("user_name")+"',now(),'delete board  id: "+board_id+" ')";
	BoardBean.executeUpdate(sql_in);	
}
%>


<%@ include file = "func/header.jsp" %>

<body>
<div align=center>
子版面管理
<br>
<table width="80%"  border="1" cellspacing="0" cellpadding="0"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
      <tr> 
    <td width="10%"> 
      <div align="center">子版编号</div>
    </td>
    <td width="20%"> 
      <div align="center">版面编号</div>
    </td>
    <td width="20%"> 
      <div align="center">子版名称</div>
    </td>
    <td width="25%"> 
      <div align="center">子版描述</div>
    </td>
    <td width="25%"> 
      <div align="center">操    作</div>
    </td>
   </tr>
<%
	if(request.getParameter("page")==null)
		intCurrentPage = 1;
	else
	{
		intCurrentPage = Integer.parseInt(request.getParameter("page"));
		if(intCurrentPage<1) intCurrentPage = 1;
	}									//得到当前页数
	
	sql = "select * from "+board_table+" a,"+type_table+" b where a.type_id = b.type_id";
	rs = BoardBean.executeQuery(sql);
	rs.last();
	intRowCount = rs.getRow();
	intPageCount = (intRowCount+intPageSize-1)/intPageSize;
	//out.print("intPageCount"+intPageCount);
	if(intCurrentPage>intPageCount) intCurrentPage=intPageCount;		//对当前页数的控制
		
	if(intPageCount>0)
	{	
	rs.absolute((intCurrentPage-1)*intPageSize+1);	
	//for(color=0,i=0;i<intPageSize&&!rs.isAfterLast();color++,i++)

	do {
%>
  <tr> 
    <td width="10%"> 
      <div align="center"><%=rs.getString("board_id")%></div>
    </td>
    <td width="20%"> 
      <div align="center"><%=rs.getString("type_name")%></div>
    </td>    
    <td width="20%"> 
      <div align="center"><%=rs.getString("board_name")%></div>
    </td>
    <td width="25%"> 
      <div align="center"><%=rs.getString("board_describ")%></div>
    </td>
    <td width="25%"> 
      <div align="center">
      <a href="board_man.jsp?action=pass&board_id=<%=rs.getString("board_id")%>&board_audit=<% if(Integer.parseInt(rs.getString("board_audit"))==1) out.print("0"); else out.print("1"); %>&page=<%=intCurrentPage%>"><% if(Integer.parseInt(rs.getString("board_audit"))==1) {%>取消审核<% } else { %>通过审核 <%} %></a>&nbsp;
      <a href="board_man.jsp?action=edit&board_id=<%=rs.getString("board_id")%>&page=<%=intCurrentPage%>">编辑</a>&nbsp;
      <a href="board_man.jsp?action=delete&board_id=<%=rs.getString("board_id")%>&page=<%=intCurrentPage%>">删除</a></div>
    </td>
   </tr>
<%	
	i++;
	}
	while(rs.next()&&i<intPageSize);
	}
%>
</table>
<br>
<%
	if(intCurrentPage == 1) { 
		%> 首页 前页 <% }
	else
		out.println("<a href='board_man.jsp?page=1'>首页</a> <a href='board_man.jsp?page="+(intCurrentPage-1)+"'>前页</a> ");
	
	if(intCurrentPage==intPageCount) {
		%>后页 末页<% }
	else
		out.println("<a href='board_man.jsp?page="+(intCurrentPage+1)+"'>后页</a> <a href='board_man.jsp?page="+intPageCount+"'>末页</a> ");

%>
<hr size=0 width=100%>

<%
if(isedit==true)
	{
	       sql = "select * from "+board_table+" where board_id="+board_id;
	       rs = BoardBean.executeQuery(sql);
	       rs.next();
	}
%>

<form action="board_man.jsp" method=post name=form1 onsubmit="return formCheck()">
    <input type="Hidden" name="action" value="<%if(isedit==true) out.print("modify"); else out.print("add"); %>">
<%if(isedit==true)
     { 
%>
    <input type="Hidden" name="board_id" value="<%=board_id%>">
<%
	}
%>

    <table width="50%"  border="1" cellspacing="0" cellpadding="2"  bordercolor="#00CC66"  borderColorDark="#FFFFFF" borderColorLight="#00CC66">
	<tr> 
        	<td><div align="right">所属版面</div></td>
        	<td><div align="left">
        	<select name="type_id" class=input>
        	<%
        	String sql1 = "select * from "+type_table;
        	rs1 = BoardBean.executeQuery(sql1);
		for(i=0;rs1.next();i++)
        	{        	
        	%>
        	<option value="<%=rs1.getString("type_id")%>"><%=rs1.getString("type_name")%></option>
        	<%
        	}
        	%>
        	</div></td>
	</tr>
	<tr> 
        	<td><div align="right">子版名称</div></td>
        	<td><div align="left"><input name="board_name" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("board_name")); %>"></div></td>
	</tr>
	<tr> 
        	<td><div align="right">子版描述</div></td>
        	<td><div align="left"><input name="board_describ" type="text"  class=input size="12" maxlength=13  value="<% if(isedit==true) out.print(rs.getString("board_describ")); %>">&nbsp;</div></td>
	</tr>
	<tr> 
        	<td><div align="right">子版状态</div></td>
        	<td><div align="left">
        		<input type="radio" name="board_audit" value=1 checked>已审核&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        		<input type="radio" name="board_audit" value=0>未审核  
        	</td>
	</tr>
  </table>
  <br>
  <input type=submit value="确 定" class=button>&nbsp;&nbsp;&nbsp;&nbsp;<input type=reset value="重 置" class=button>
 </div>
</form>

<SCRIPT language=JavaScript>
         function formCheck()
	{
		if(document.form1.board_name.value=="")
            	{
            		alert("请输入子版名称!");
			document.form1.board_name.focus();
			return false;
		}     
         }
</SCRIPT>

<%
BoardBean.close();
%>
<%@ include file = "func/footer.jsp" %>